diff --git a/README.md b/README.md index 75d0193..dfc47d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,24 @@ # netcrypt -A proof-of-concept packer for .NET executables +A proof-of-concept packer for .NET executables, designed to provide a starting point to explain the basic principles of runtime packing. + +# Implementation + +The packer is implemented in a shared library called netcrypt.dll. If you reference this library you can just use the following code to pack a file: + + byte[] arrayOfUnpackedExeBytes; + // ... perform file loading/generation logic + byte[] packedExe = Packer.Pack(arrayOfUnpackedExeBytes); + +A sample GUI has been created in the SimplePacker project to demonstrate this principle. + +# Sample files + +In the /sample firectory you can find two files: input.exe and output.exe. The naming should indicate which one is packed and which one is not. + +# Warning + +This is a proof-of-concept code sample; it is possible that it will not work on your set up or does not work at all on your system. +This packer is also considered to be highly insecure (as with all obfuscators/packers which provide security by obscurity), since an unpacker can be easily constructed. # License Licensed under the GNU GPLv3 license. diff --git a/netcrypt/SimplePacker/Form1.Designer.cs b/netcrypt/SimplePacker/Form1.Designer.cs new file mode 100644 index 0000000..9e4751f --- /dev/null +++ b/netcrypt/SimplePacker/Form1.Designer.cs @@ -0,0 +1,190 @@ +namespace SimplePacker +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.twitterLink = new System.Windows.Forms.LinkLabel(); + this.sourceCodeLink = new System.Windows.Forms.LinkLabel(); + this.madeByLabel = new System.Windows.Forms.Label(); + this.inputFileLabel = new System.Windows.Forms.Label(); + this.outputFileLabel = new System.Windows.Forms.Label(); + this.inputFileLocationLabel = new System.Windows.Forms.Label(); + this.outputFileLocationLabel = new System.Windows.Forms.Label(); + this.chooseInputButton = new System.Windows.Forms.Button(); + this.chooseOutputButton = new System.Windows.Forms.Button(); + this.packExecButton = new System.Windows.Forms.Button(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.SuspendLayout(); + // + // twitterLink + // + this.twitterLink.AutoSize = true; + this.twitterLink.Location = new System.Drawing.Point(70, 71); + this.twitterLink.Name = "twitterLink"; + this.twitterLink.Size = new System.Drawing.Size(56, 13); + this.twitterLink.TabIndex = 0; + this.twitterLink.TabStop = true; + this.twitterLink.Text = "@friedkiwi"; + this.twitterLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.twitterLink_LinkClicked); + // + // sourceCodeLink + // + this.sourceCodeLink.AutoSize = true; + this.sourceCodeLink.Location = new System.Drawing.Point(132, 71); + this.sourceCodeLink.Name = "sourceCodeLink"; + this.sourceCodeLink.Size = new System.Drawing.Size(66, 13); + this.sourceCodeLink.TabIndex = 1; + this.sourceCodeLink.TabStop = true; + this.sourceCodeLink.Text = "source code"; + this.sourceCodeLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.sourceCodeLink_LinkClicked); + // + // madeByLabel + // + this.madeByLabel.AutoSize = true; + this.madeByLabel.Location = new System.Drawing.Point(13, 71); + this.madeByLabel.Name = "madeByLabel"; + this.madeByLabel.Size = new System.Drawing.Size(51, 13); + this.madeByLabel.TabIndex = 2; + this.madeByLabel.Text = "Made by "; + // + // inputFileLabel + // + this.inputFileLabel.AutoSize = true; + this.inputFileLabel.Location = new System.Drawing.Point(13, 13); + this.inputFileLabel.Name = "inputFileLabel"; + this.inputFileLabel.Size = new System.Drawing.Size(47, 13); + this.inputFileLabel.TabIndex = 3; + this.inputFileLabel.Text = "Input file"; + // + // outputFileLabel + // + this.outputFileLabel.AutoSize = true; + this.outputFileLabel.Location = new System.Drawing.Point(13, 37); + this.outputFileLabel.Name = "outputFileLabel"; + this.outputFileLabel.Size = new System.Drawing.Size(55, 13); + this.outputFileLabel.TabIndex = 4; + this.outputFileLabel.Text = "Output file"; + // + // inputFileLocationLabel + // + this.inputFileLocationLabel.Location = new System.Drawing.Point(75, 13); + this.inputFileLocationLabel.Name = "inputFileLocationLabel"; + this.inputFileLocationLabel.Size = new System.Drawing.Size(245, 13); + this.inputFileLocationLabel.TabIndex = 5; + this.inputFileLocationLabel.Text = "(choose)"; + // + // outputFileLocationLabel + // + this.outputFileLocationLabel.Location = new System.Drawing.Point(75, 37); + this.outputFileLocationLabel.Name = "outputFileLocationLabel"; + this.outputFileLocationLabel.Size = new System.Drawing.Size(245, 13); + this.outputFileLocationLabel.TabIndex = 6; + this.outputFileLocationLabel.Text = "(choose)"; + // + // chooseInputButton + // + this.chooseInputButton.Location = new System.Drawing.Point(344, 8); + this.chooseInputButton.Name = "chooseInputButton"; + this.chooseInputButton.Size = new System.Drawing.Size(48, 23); + this.chooseInputButton.TabIndex = 7; + this.chooseInputButton.Text = "..."; + this.chooseInputButton.UseVisualStyleBackColor = true; + this.chooseInputButton.Click += new System.EventHandler(this.chooseInputButton_Click); + // + // chooseOutputButton + // + this.chooseOutputButton.Location = new System.Drawing.Point(344, 37); + this.chooseOutputButton.Name = "chooseOutputButton"; + this.chooseOutputButton.Size = new System.Drawing.Size(48, 23); + this.chooseOutputButton.TabIndex = 8; + this.chooseOutputButton.Text = "..."; + this.chooseOutputButton.UseVisualStyleBackColor = true; + this.chooseOutputButton.Click += new System.EventHandler(this.chooseOutputButton_Click); + // + // packExecButton + // + this.packExecButton.Location = new System.Drawing.Point(317, 66); + this.packExecButton.Name = "packExecButton"; + this.packExecButton.Size = new System.Drawing.Size(75, 23); + this.packExecButton.TabIndex = 9; + this.packExecButton.Text = "Pack!"; + this.packExecButton.UseVisualStyleBackColor = true; + this.packExecButton.Click += new System.EventHandler(this.packExecButton_Click); + // + // openFileDialog + // + this.openFileDialog.FileName = "openFileDialog"; + this.openFileDialog.Filter = ".NET executables (*.exe) |*.exe"; + // + // saveFileDialog + // + this.saveFileDialog.Filter = ".NET executables (*.exe) |*.exe"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(404, 98); + this.Controls.Add(this.packExecButton); + this.Controls.Add(this.chooseOutputButton); + this.Controls.Add(this.chooseInputButton); + this.Controls.Add(this.outputFileLocationLabel); + this.Controls.Add(this.inputFileLocationLabel); + this.Controls.Add(this.outputFileLabel); + this.Controls.Add(this.inputFileLabel); + this.Controls.Add(this.madeByLabel); + this.Controls.Add(this.sourceCodeLink); + this.Controls.Add(this.twitterLink); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Form1"; + this.Text = "SimplePacker (netcrypt sample)"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.LinkLabel twitterLink; + private System.Windows.Forms.LinkLabel sourceCodeLink; + private System.Windows.Forms.Label madeByLabel; + private System.Windows.Forms.Label inputFileLabel; + private System.Windows.Forms.Label outputFileLabel; + private System.Windows.Forms.Label inputFileLocationLabel; + private System.Windows.Forms.Label outputFileLocationLabel; + private System.Windows.Forms.Button chooseInputButton; + private System.Windows.Forms.Button chooseOutputButton; + private System.Windows.Forms.Button packExecButton; + private System.Windows.Forms.OpenFileDialog openFileDialog; + private System.Windows.Forms.SaveFileDialog saveFileDialog; + } +} + diff --git a/netcrypt/SimplePacker/Form1.cs b/netcrypt/SimplePacker/Form1.cs new file mode 100644 index 0000000..94c7264 --- /dev/null +++ b/netcrypt/SimplePacker/Form1.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Diagnostics; +using System.IO; +using Netcrypt; + +namespace SimplePacker +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void twitterLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start("http://bit.ly/168dEqY"); + } + + private void sourceCodeLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start("http://bit.ly/1gIe8pZ"); + } + + private void packExecButton_Click(object sender, EventArgs e) + { + if (inputFileLocationLabel.Text == "(choose)") + { + MessageBox.Show("Please choose an input file first."); + return; + } + + if (outputFileLocationLabel.Text == "(choose)") + { + MessageBox.Show("Please choose an output file first."); + return; + } + + try + { + File.WriteAllBytes(outputFileLocationLabel.Text, Packer.Pack(File.ReadAllBytes(inputFileLocationLabel.Text))); + MessageBox.Show("Packing completed succesfully.\n\nCross your fingers and try to execute the output file..."); + } + catch (Exception ex) + { + MessageBox.Show("An error has occured while packing the executable.\nPlease note:\n* Only .NET executables will work\n* This is a proof-of-concept packer, designed as a learning aid for .NET developers. It might just not work on your executable.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void chooseInputButton_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + inputFileLocationLabel.Text = openFileDialog.FileName; + } + } + + private void chooseOutputButton_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + outputFileLocationLabel.Text = saveFileDialog.FileName; + } + } + } +} diff --git a/netcrypt/SimplePacker/Form1.resx b/netcrypt/SimplePacker/Form1.resx new file mode 100644 index 0000000..816f18b --- /dev/null +++ b/netcrypt/SimplePacker/Form1.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 157, 17 + + \ No newline at end of file diff --git a/netcrypt/SimplePacker/Program.cs b/netcrypt/SimplePacker/Program.cs new file mode 100644 index 0000000..b340cbb --- /dev/null +++ b/netcrypt/SimplePacker/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace SimplePacker +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/netcrypt/SimplePacker/Properties/AssemblyInfo.cs b/netcrypt/SimplePacker/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..588fdb6 --- /dev/null +++ b/netcrypt/SimplePacker/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SimplePacker")] +[assembly: AssemblyDescription("A sample on how to use the netcrypt library.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("@friedkiwi")] +[assembly: AssemblyProduct("netcrypt C# library")] +[assembly: AssemblyCopyright("Copyright © friedkiwi 2013 - Licensed under the GNU GPLv3")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b9da217b-997e-4f15-a7ee-4927e541557f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/netcrypt/SimplePacker/Properties/Resources.Designer.cs b/netcrypt/SimplePacker/Properties/Resources.Designer.cs new file mode 100644 index 0000000..284aeeb --- /dev/null +++ b/netcrypt/SimplePacker/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18052 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SimplePacker.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SimplePacker.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/netcrypt/SimplePacker/Properties/Resources.resx b/netcrypt/SimplePacker/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/netcrypt/SimplePacker/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/netcrypt/SimplePacker/Properties/Settings.Designer.cs b/netcrypt/SimplePacker/Properties/Settings.Designer.cs new file mode 100644 index 0000000..ceb82c5 --- /dev/null +++ b/netcrypt/SimplePacker/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18052 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SimplePacker.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/netcrypt/SimplePacker/Properties/Settings.settings b/netcrypt/SimplePacker/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/netcrypt/SimplePacker/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/netcrypt/SimplePacker/SimplePacker.csproj b/netcrypt/SimplePacker/SimplePacker.csproj new file mode 100644 index 0000000..dc16e3b --- /dev/null +++ b/netcrypt/SimplePacker/SimplePacker.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {4E860FED-781B-4060-865E-54594C9BEAC3} + WinExe + Properties + SimplePacker + SimplePacker + v4.0 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {6d18501b-2516-4fc3-816e-775d71ab923a} + netcrypt + + + + + \ No newline at end of file diff --git a/netcrypt/SimplePacker/bin/Debug/SimplePacker.vshost.exe.manifest b/netcrypt/SimplePacker/bin/Debug/SimplePacker.vshost.exe.manifest new file mode 100644 index 0000000..f96b1d6 --- /dev/null +++ b/netcrypt/SimplePacker/bin/Debug/SimplePacker.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/netcrypt/SimplePacker/bin/Debug/netcrypt.dll b/netcrypt/SimplePacker/bin/Debug/netcrypt.dll new file mode 100644 index 0000000..0e65581 Binary files /dev/null and b/netcrypt/SimplePacker/bin/Debug/netcrypt.dll differ diff --git a/netcrypt/SimplePacker/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/netcrypt/SimplePacker/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..c98bf17 Binary files /dev/null and b/netcrypt/SimplePacker/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/netcrypt/SimplePacker/obj/Debug/SimplePacker.Form1.resources b/netcrypt/SimplePacker/obj/Debug/SimplePacker.Form1.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/netcrypt/SimplePacker/obj/Debug/SimplePacker.Form1.resources differ diff --git a/netcrypt/SimplePacker/obj/Debug/SimplePacker.Properties.Resources.resources b/netcrypt/SimplePacker/obj/Debug/SimplePacker.Properties.Resources.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/netcrypt/SimplePacker/obj/Debug/SimplePacker.Properties.Resources.resources differ diff --git a/netcrypt/SimplePacker/obj/Debug/SimplePacker.csproj.FileListAbsolute.txt b/netcrypt/SimplePacker/obj/Debug/SimplePacker.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..f1442c3 --- /dev/null +++ b/netcrypt/SimplePacker/obj/Debug/SimplePacker.csproj.FileListAbsolute.txt @@ -0,0 +1,10 @@ +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\bin\Debug\SimplePacker.exe +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\bin\Debug\SimplePacker.pdb +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\bin\Debug\netcrypt.dll +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\bin\Debug\netcrypt.pdb +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\obj\Debug\SimplePacker.csprojResolveAssemblyReference.cache +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\obj\Debug\SimplePacker.Form1.resources +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\obj\Debug\SimplePacker.Properties.Resources.resources +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\obj\Debug\SimplePacker.csproj.GenerateResource.Cache +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\obj\Debug\SimplePacker.exe +D:\Users\axqix\Documents\GitHub\netcrypt\netcrypt\SimplePacker\obj\Debug\SimplePacker.pdb diff --git a/netcrypt/SimplePacker/obj/Debug/SimplePacker.csproj.GenerateResource.Cache b/netcrypt/SimplePacker/obj/Debug/SimplePacker.csproj.GenerateResource.Cache new file mode 100644 index 0000000..917527f Binary files /dev/null and b/netcrypt/SimplePacker/obj/Debug/SimplePacker.csproj.GenerateResource.Cache differ diff --git a/netcrypt/SimplePacker/obj/Debug/SimplePacker.csprojResolveAssemblyReference.cache b/netcrypt/SimplePacker/obj/Debug/SimplePacker.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..95d9fa0 Binary files /dev/null and b/netcrypt/SimplePacker/obj/Debug/SimplePacker.csprojResolveAssemblyReference.cache differ diff --git a/netcrypt/netcrypt.sln b/netcrypt/netcrypt.sln index be6cfcf..94c430a 100644 --- a/netcrypt/netcrypt.sln +++ b/netcrypt/netcrypt.sln @@ -1,24 +1,24 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "stub", "stub\stub.csproj", "{B1FA79EA-6C5A-422F-BD84-C7F96AEFFCA9}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "netcrypt", "netcrypt\netcrypt.csproj", "{6D18501B-2516-4FC3-816E-775D71AB923A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplePacker", "SimplePacker\SimplePacker.csproj", "{4E860FED-781B-4060-865E-54594C9BEAC3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B1FA79EA-6C5A-422F-BD84-C7F96AEFFCA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B1FA79EA-6C5A-422F-BD84-C7F96AEFFCA9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B1FA79EA-6C5A-422F-BD84-C7F96AEFFCA9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B1FA79EA-6C5A-422F-BD84-C7F96AEFFCA9}.Release|Any CPU.Build.0 = Release|Any CPU {6D18501B-2516-4FC3-816E-775D71AB923A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D18501B-2516-4FC3-816E-775D71AB923A}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D18501B-2516-4FC3-816E-775D71AB923A}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D18501B-2516-4FC3-816E-775D71AB923A}.Release|Any CPU.Build.0 = Release|Any CPU + {4E860FED-781B-4060-865E-54594C9BEAC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E860FED-781B-4060-865E-54594C9BEAC3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E860FED-781B-4060-865E-54594C9BEAC3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E860FED-781B-4060-865E-54594C9BEAC3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/netcrypt/netcrypt.v11.suo b/netcrypt/netcrypt.v11.suo index 7132a76..fd0a9b1 100644 Binary files a/netcrypt/netcrypt.v11.suo and b/netcrypt/netcrypt.v11.suo differ diff --git a/netcrypt/netcrypt/Packer.cs b/netcrypt/netcrypt/Packer.cs index 757b5ed..9c15281 100644 --- a/netcrypt/netcrypt/Packer.cs +++ b/netcrypt/netcrypt/Packer.cs @@ -3,7 +3,9 @@ using Microsoft.CSharp; using System.IO; using System.Security.Cryptography; +using System.Reflection; using System.CodeDom.Compiler; +using System.Collections.Generic; namespace Netcrypt { @@ -29,8 +31,12 @@ public static byte[] Pack(byte[] assembly) string app = ""; MemoryStream memoryStream = new MemoryStream(); + + rijndael.Padding = PaddingMode.ISO10126; + CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndael.CreateEncryptor(), CryptoStreamMode.Write); cryptoStream.Write(assembly, 0, assembly.Length); + cryptoStream.FlushFinalBlock(); cryptoStream.Flush(); memoryStream.Seek(0, SeekOrigin.Begin); app = Convert.ToBase64String(memoryStream.ToArray()); @@ -39,24 +45,47 @@ public static byte[] Pack(byte[] assembly) string csharpcode = netcrypt.Properties.Resources.StubCode; - csharpcode.Replace("%KEY%", key); - csharpcode.Replace("%IV%", iv); - csharpcode.Replace("%PROGRAM%", app); + csharpcode = csharpcode.Replace("%KEY%", key); + csharpcode = csharpcode.Replace("%IV%", iv); + csharpcode = csharpcode.Replace("%PROGRAM%", app); + + Assembly orig = Assembly.Load(assembly); + + + CSharpCodeProvider codeProvider = new CSharpCodeProvider(); - ICodeCompiler compiler = codeProvider.CreateCompiler(); + + CompilerParameters parameters = new CompilerParameters(); - parameters.GenerateInMemory = true; - parameters.GenerateExecutable = true; - parameters.OutputAssembly = "Packed.exe"; - CompilerResults results = compiler.CompileAssemblyFromSource(parameters, csharpcode); + parameters.CompilerOptions = "/target:winexe"; + + AssemblyName[] names = orig.GetReferencedAssemblies(); + + foreach (AssemblyName name in names) + { + if (name.Name.Contains("System.") || + name.Name.Contains("Microsoft.")) + parameters.ReferencedAssemblies.Add(name.Name + ".dll"); + } + + string tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".exe"; + + parameters.GenerateExecutable = true; + parameters.OutputAssembly = tempFile; + CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, csharpcode); + try { FileStream fs = results.CompiledAssembly.GetFiles()[0]; byte[] barr = new byte[fs.Length]; int r = fs.Read(barr, 0, barr.Length); + fs.Close(); + string fileName = fs.Name; + fs.Dispose(); + if (r == barr.Length) { return barr; @@ -66,6 +95,7 @@ public static byte[] Pack(byte[] assembly) return null; } } catch { + return null; } diff --git a/netcrypt/netcrypt/Properties/Resources.resx b/netcrypt/netcrypt/Properties/Resources.resx index c53b645..6683edb 100644 --- a/netcrypt/netcrypt/Properties/Resources.resx +++ b/netcrypt/netcrypt/Properties/Resources.resx @@ -143,7 +143,7 @@ namespace stub rijndael.KeySize = 256; rijndael.Key = Convert.FromBase64String(key); rijndael.IV = Convert.FromBase64String(IV); - + rijndael.Padding = PaddingMode.ISO10126; MemoryStream memoryStream = new MemoryStream(); CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndael.CreateDecryptor(), CryptoStreamMode.Write); byte[] app = Convert.FromBase64String(program); @@ -160,9 +160,9 @@ namespace stub newAssembly.EntryPoint.Invoke(null, null); } - catch + catch (Exception exz) { - MessageBox.Show(GENERIC_ERROR, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(GENERIC_ERROR + "\n\n" + exz.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/netcrypt/netcrypt/bin/Debug/netcrypt.dll b/netcrypt/netcrypt/bin/Debug/netcrypt.dll index 15f63ab..0e65581 100644 Binary files a/netcrypt/netcrypt/bin/Debug/netcrypt.dll and b/netcrypt/netcrypt/bin/Debug/netcrypt.dll differ diff --git a/netcrypt/netcrypt/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll b/netcrypt/netcrypt/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll index 1ce3fda..7286665 100644 Binary files a/netcrypt/netcrypt/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll and b/netcrypt/netcrypt/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll differ diff --git a/netcrypt/netcrypt/obj/Debug/netcrypt.Properties.Resources.resources b/netcrypt/netcrypt/obj/Debug/netcrypt.Properties.Resources.resources index 5dc2a03..f728092 100644 Binary files a/netcrypt/netcrypt/obj/Debug/netcrypt.Properties.Resources.resources and b/netcrypt/netcrypt/obj/Debug/netcrypt.Properties.Resources.resources differ diff --git a/netcrypt/netcrypt/obj/Debug/netcrypt.csproj.GenerateResource.Cache b/netcrypt/netcrypt/obj/Debug/netcrypt.csproj.GenerateResource.Cache index 9d67e09..2425a8f 100644 Binary files a/netcrypt/netcrypt/obj/Debug/netcrypt.csproj.GenerateResource.Cache and b/netcrypt/netcrypt/obj/Debug/netcrypt.csproj.GenerateResource.Cache differ diff --git a/netcrypt/netcrypt/obj/Debug/netcrypt.dll b/netcrypt/netcrypt/obj/Debug/netcrypt.dll index 15f63ab..0e65581 100644 Binary files a/netcrypt/netcrypt/obj/Debug/netcrypt.dll and b/netcrypt/netcrypt/obj/Debug/netcrypt.dll differ