Commit 58a9bbaa authored by atom0s's avatar atom0s

Added embedded disassembler file into the project/exe.

Added code to load embedded files from memory rather then extract to disk.
Added support for SteamStub Variant 2.
Added a few comments for variant 3.
Fixed a non-issue bug with double disposing of streams.
parent 65610236
......@@ -35,6 +35,9 @@ namespace Steamless.NET
/// <param name="args"></param>
private static void Main(string[] args)
{
// Override the assembly resolve event for this application..
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
// Print the application header..
PrintHeader();
......@@ -81,6 +84,34 @@ namespace Steamless.NET
Console.ReadKey();
}
/// <summary>
/// Resolves embedded resources to not load from disk.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
// Obtain the DLL name from the assembly..
var dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(",", StringComparison.InvariantCultureIgnoreCase)) : args.Name.Replace(".dll", "");
if (dllName.ToLower().EndsWith(".resources"))
return null;
// Build full path to the possible embedded resource..
var fullName = $"{Assembly.GetExecutingAssembly().EntryPoint.DeclaringType?.Namespace}.Embedded.{new AssemblyName(args.Name).Name}.dll";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(fullName))
{
// Return null if we are not valid..
if (stream == null)
return null;
// Read and load the embedded resource..
var data = new byte[stream.Length];
stream.Read(data, 0, (int)stream.Length);
return Assembly.Load(data);
}
}
/// <summary>
/// Prints the header of this application.
/// </summary>
......
......@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7f509628-ca55-412d-8bac-38dd26151b04")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
......@@ -22,6 +22,10 @@
<OutputPath>bin\x86\Release\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpDisasm">
<HintPath>Embedded\SharpDisasm.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -49,6 +53,9 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Embedded\SharpDisasm.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
......@@ -312,7 +312,7 @@ namespace Steamless.NET.Unpackers
// Write the dos header back to the file..
fStream.WriteBytes(Helpers.GetStructureBytes(this.File.DosHeader));
// Write the dos stub back to the file exists..
// Write the dos stub back to the file if it exists..
if (this.File.DosStubSize > 0)
fStream.WriteBytes(this.File.DosStubData);
......@@ -353,7 +353,8 @@ namespace Steamless.NET.Unpackers
fStream.WriteBytes(this.TextSectionData ?? sectionData);
else
fStream.WriteBytes(sectionData);
// Reset the file offset..
fStream.Position = sectionOffset;
}
......@@ -372,7 +373,6 @@ namespace Steamless.NET.Unpackers
}
finally
{
fStream?.Close();
fStream?.Dispose();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment