├── AssemblyLoad
├── AssemblyLoad.csproj
├── MainForm.Designer.cs
├── MainForm.cs
├── MainForm.resx
├── Modules.Designer.cs
├── Modules.cs
├── Modules.resx
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── SendToJit.cs
└── AssemblyLoadTest.sln
/AssemblyLoad/AssemblyLoad.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {67C4527C-A791-40E2-BE4B-F7A3B7A21635}
4 | Debug
5 | x86
6 | WinExe
7 | AssemblyLoad
8 | AssemblyLoad
9 | v2.0
10 | Properties
11 | C:\Documents and Settings\Mihai\Application Data\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis
12 | True
13 | False
14 | 4
15 | false
16 |
17 |
18 | x86
19 | False
20 | Auto
21 | 4194304
22 | 4096
23 |
24 |
25 | bin\Debug\
26 | true
27 | Full
28 | False
29 | True
30 | DEBUG;TRACE
31 |
32 |
33 | bin\Release\
34 | False
35 | None
36 | True
37 | False
38 | TRACE
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | MainForm.cs
52 |
53 |
54 |
55 | Modules.cs
56 |
57 |
58 |
59 |
60 |
61 | MainForm.cs
62 |
63 |
64 | Modules.cs
65 |
66 |
67 |
--------------------------------------------------------------------------------
/AssemblyLoad/MainForm.Designer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: Bogdan
4 | * Date: 01.01.2013
5 | * Time: 19:59
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | namespace AssemblyLoad
10 | {
11 | partial class MainForm
12 | {
13 | ///
14 | /// Designer variable used to keep track of non-visual components.
15 | ///
16 | private System.ComponentModel.IContainer components = null;
17 |
18 | ///
19 | /// Disposes resources used by the form.
20 | ///
21 | /// true if managed resources should be disposed; otherwise, false.
22 | protected override void Dispose(bool disposing)
23 | {
24 | if (disposing) {
25 | if (components != null) {
26 | components.Dispose();
27 | }
28 | }
29 | base.Dispose(disposing);
30 | }
31 |
32 | ///
33 | /// This method is required for Windows Forms designer support.
34 | /// Do not change the method contents inside the source code editor. The Forms designer might
35 | /// not be able to load this method if it was changed manually.
36 | ///
37 | private void InitializeComponent()
38 | {
39 | this.components = new System.ComponentModel.Container();
40 | this.assemblieslist = new System.Windows.Forms.ListView();
41 | this.handle = new System.Windows.Forms.ColumnHeader();
42 | this.assemblies = new System.Windows.Forms.ColumnHeader();
43 | this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
44 | this.copyHandleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
45 | this.sendMainModuleToJitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
46 | this.enumModulesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
47 | this.contextMenuStrip1.SuspendLayout();
48 | this.SuspendLayout();
49 | //
50 | // assemblieslist
51 | //
52 | this.assemblieslist.Alignment = System.Windows.Forms.ListViewAlignment.Default;
53 | this.assemblieslist.AllowDrop = true;
54 | this.assemblieslist.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
55 | | System.Windows.Forms.AnchorStyles.Left)
56 | | System.Windows.Forms.AnchorStyles.Right)));
57 | this.assemblieslist.AutoArrange = false;
58 | this.assemblieslist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
59 | this.handle,
60 | this.assemblies});
61 | this.assemblieslist.ContextMenuStrip = this.contextMenuStrip1;
62 | this.assemblieslist.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
63 | this.assemblieslist.FullRowSelect = true;
64 | this.assemblieslist.GridLines = true;
65 | this.assemblieslist.Location = new System.Drawing.Point(22, 12);
66 | this.assemblieslist.Name = "assemblieslist";
67 | this.assemblieslist.Size = new System.Drawing.Size(555, 307);
68 | this.assemblieslist.TabIndex = 68;
69 | this.assemblieslist.UseCompatibleStateImageBehavior = false;
70 | this.assemblieslist.View = System.Windows.Forms.View.Details;
71 | //
72 | // handle
73 | //
74 | this.handle.Text = "Handle:";
75 | this.handle.Width = 91;
76 | //
77 | // assemblies
78 | //
79 | this.assemblies.Text = "Assemblies";
80 | this.assemblies.Width = 168;
81 | //
82 | // contextMenuStrip1
83 | //
84 | this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
85 | this.copyHandleToolStripMenuItem,
86 | this.sendMainModuleToJitToolStripMenuItem,
87 | this.enumModulesToolStripMenuItem});
88 | this.contextMenuStrip1.Name = "contextMenuStrip1";
89 | this.contextMenuStrip1.Size = new System.Drawing.Size(197, 92);
90 | //
91 | // copyHandleToolStripMenuItem
92 | //
93 | this.copyHandleToolStripMenuItem.Name = "copyHandleToolStripMenuItem";
94 | this.copyHandleToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
95 | this.copyHandleToolStripMenuItem.Text = "Copy Handle";
96 | this.copyHandleToolStripMenuItem.Click += new System.EventHandler(this.CopyHandleToolStripMenuItemClick);
97 | //
98 | // sendMainModuleToJitToolStripMenuItem
99 | //
100 | this.sendMainModuleToJitToolStripMenuItem.Name = "sendMainModuleToJitToolStripMenuItem";
101 | this.sendMainModuleToJitToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
102 | this.sendMainModuleToJitToolStripMenuItem.Text = "Send main module to jit";
103 | this.sendMainModuleToJitToolStripMenuItem.Click += new System.EventHandler(this.SendMainModuleToJitToolStripMenuItemClick);
104 | //
105 | // enumModulesToolStripMenuItem
106 | //
107 | this.enumModulesToolStripMenuItem.Name = "enumModulesToolStripMenuItem";
108 | this.enumModulesToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
109 | this.enumModulesToolStripMenuItem.Text = "Enumerate modules";
110 | this.enumModulesToolStripMenuItem.Click += new System.EventHandler(this.EnumModulesToolStripMenuItemClick);
111 | //
112 | // MainForm
113 | //
114 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
115 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
116 | this.ClientSize = new System.Drawing.Size(589, 344);
117 | this.Controls.Add(this.assemblieslist);
118 | this.Name = "MainForm";
119 | this.Text = "Assemblies list:";
120 | this.Shown += new System.EventHandler(this.MainFormShown);
121 | this.contextMenuStrip1.ResumeLayout(false);
122 | this.ResumeLayout(false);
123 | }
124 | private System.Windows.Forms.ToolStripMenuItem enumModulesToolStripMenuItem;
125 | private System.Windows.Forms.ToolStripMenuItem sendMainModuleToJitToolStripMenuItem;
126 | private System.Windows.Forms.ToolStripMenuItem copyHandleToolStripMenuItem;
127 | private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
128 | private System.Windows.Forms.ColumnHeader handle;
129 | private System.Windows.Forms.ColumnHeader assemblies;
130 | private System.Windows.Forms.ListView assemblieslist;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/AssemblyLoad/MainForm.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: Bogdan
4 | * Date: 01.01.2013
5 | * Time: 19:59
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Drawing;
12 | using System.Windows.Forms;
13 | using System.Reflection;
14 | using System.Runtime.InteropServices;
15 |
16 | namespace AssemblyLoad
17 | {
18 | ///
19 | /// Description of MainForm.
20 | ///
21 | public partial class MainForm : Form
22 | {
23 | public MainForm()
24 | {
25 | //
26 | // The InitializeComponent() call is required for Windows Forms designer support.
27 | //
28 | InitializeComponent();
29 |
30 | //
31 | // TODO: Add constructor code after the InitializeComponent() call.
32 | //
33 | }
34 |
35 | void MainFormShown(object sender, EventArgs e)
36 | {
37 | Assembly[] asemblies = AppDomain.CurrentDomain.GetAssemblies();
38 | for (int i=0;iassemblies.Width)
47 | {
48 | assemblies.Width=assemblieslenght;
49 | }
50 | IntPtr address = Marshal.GetHINSTANCE(asemblies[i].ManifestModule);
51 | string modaddress = ((uint)(address)).ToString("X8");
52 | string[] prcdetails = new string[]{modaddress,asemblies[i].FullName};
53 | ListViewItem proc = new ListViewItem(prcdetails);
54 | assemblieslist.Items.Add(proc);
55 | }
56 | }
57 |
58 | void CopyHandleToolStripMenuItemClick(object sender, EventArgs e)
59 | {
60 | if (assemblieslist.SelectedIndices.Count>0)
61 | {
62 | string strtoset = assemblieslist.Items[assemblieslist.SelectedIndices[0]].SubItems[0].Text;
63 | if (strtoset!="") Clipboard.SetText(strtoset);
64 | }
65 | }
66 |
67 | void SendMainModuleToJitToolStripMenuItemClick(object sender, EventArgs e)
68 | {
69 | if (assemblieslist.SelectedIndices.Count>0)
70 | {
71 | string fullname = assemblieslist.Items[assemblieslist.SelectedIndices[0]].SubItems[1].Text;
72 | Assembly[] asemblies = AppDomain.CurrentDomain.GetAssemblies();
73 | for (int i=0;i0)
86 | {
87 | string fullname = assemblieslist.Items[assemblieslist.SelectedIndices[0]].SubItems[1].Text;
88 | Assembly[] asemblies = AppDomain.CurrentDomain.GetAssemblies();
89 | for (int i=0;i
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
--------------------------------------------------------------------------------
/AssemblyLoad/Modules.Designer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: Bogdan
4 | * Date: 03.01.2013
5 | * Time: 20:15
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | namespace AssemblyLoad
10 | {
11 | partial class Modules
12 | {
13 | ///
14 | /// Designer variable used to keep track of non-visual components.
15 | ///
16 | private System.ComponentModel.IContainer components = null;
17 |
18 | ///
19 | /// Disposes resources used by the form.
20 | ///
21 | /// true if managed resources should be disposed; otherwise, false.
22 | protected override void Dispose(bool disposing)
23 | {
24 | if (disposing) {
25 | if (components != null) {
26 | components.Dispose();
27 | }
28 | }
29 | base.Dispose(disposing);
30 | }
31 |
32 | ///
33 | /// This method is required for Windows Forms designer support.
34 | /// Do not change the method contents inside the source code editor. The Forms designer might
35 | /// not be able to load this method if it was changed manually.
36 | ///
37 | private void InitializeComponent()
38 | {
39 | this.components = new System.ComponentModel.Container();
40 | this.moduleslist = new System.Windows.Forms.ListView();
41 | this.handle = new System.Windows.Forms.ColumnHeader();
42 | this.moduless = new System.Windows.Forms.ColumnHeader();
43 | this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
44 | this.sendModuleToJitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
45 | this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
46 | this.contextMenuStrip1.SuspendLayout();
47 | this.SuspendLayout();
48 | //
49 | // moduleslist
50 | //
51 | this.moduleslist.Alignment = System.Windows.Forms.ListViewAlignment.Default;
52 | this.moduleslist.AllowDrop = true;
53 | this.moduleslist.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
54 | | System.Windows.Forms.AnchorStyles.Left)
55 | | System.Windows.Forms.AnchorStyles.Right)));
56 | this.moduleslist.AutoArrange = false;
57 | this.moduleslist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
58 | this.handle,
59 | this.moduless});
60 | this.moduleslist.ContextMenuStrip = this.contextMenuStrip1;
61 | this.moduleslist.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
62 | this.moduleslist.FullRowSelect = true;
63 | this.moduleslist.GridLines = true;
64 | this.moduleslist.Location = new System.Drawing.Point(12, 12);
65 | this.moduleslist.Name = "moduleslist";
66 | this.moduleslist.Size = new System.Drawing.Size(586, 231);
67 | this.moduleslist.TabIndex = 69;
68 | this.moduleslist.UseCompatibleStateImageBehavior = false;
69 | this.moduleslist.View = System.Windows.Forms.View.Details;
70 | //
71 | // handle
72 | //
73 | this.handle.Text = "Handle:";
74 | this.handle.Width = 91;
75 | //
76 | // moduless
77 | //
78 | this.moduless.Text = "Modules";
79 | this.moduless.Width = 168;
80 | //
81 | // contextMenuStrip1
82 | //
83 | this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
84 | this.sendModuleToJitToolStripMenuItem,
85 | this.copyToolStripMenuItem});
86 | this.contextMenuStrip1.Name = "contextMenuStrip1";
87 | this.contextMenuStrip1.Size = new System.Drawing.Size(172, 70);
88 | //
89 | // sendModuleToJitToolStripMenuItem
90 | //
91 | this.sendModuleToJitToolStripMenuItem.Name = "sendModuleToJitToolStripMenuItem";
92 | this.sendModuleToJitToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
93 | this.sendModuleToJitToolStripMenuItem.Text = "Send module to jit";
94 | this.sendModuleToJitToolStripMenuItem.Click += new System.EventHandler(this.SendModuleToJitToolStripMenuItemClick);
95 | //
96 | // copyToolStripMenuItem
97 | //
98 | this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
99 | this.copyToolStripMenuItem.Size = new System.Drawing.Size(171, 22);
100 | this.copyToolStripMenuItem.Text = "Copy handle";
101 | this.copyToolStripMenuItem.Click += new System.EventHandler(this.CopyToolStripMenuItemClick);
102 | //
103 | // Modules
104 | //
105 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
106 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
107 | this.ClientSize = new System.Drawing.Size(619, 266);
108 | this.Controls.Add(this.moduleslist);
109 | this.Name = "Modules";
110 | this.Text = "Modules";
111 | this.Shown += new System.EventHandler(this.ModulesShown);
112 | this.contextMenuStrip1.ResumeLayout(false);
113 | this.ResumeLayout(false);
114 | }
115 | private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem;
116 | private System.Windows.Forms.ToolStripMenuItem sendModuleToJitToolStripMenuItem;
117 | private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
118 | private System.Windows.Forms.ColumnHeader moduless;
119 | private System.Windows.Forms.ColumnHeader handle;
120 | private System.Windows.Forms.ListView moduleslist;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/AssemblyLoad/Modules.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: Bogdan
4 | * Date: 03.01.2013
5 | * Time: 20:15
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | using System;
10 | using System.Drawing;
11 | using System.Windows.Forms;
12 | using System.Reflection;
13 | using System.Runtime.InteropServices;
14 |
15 | namespace AssemblyLoad
16 | {
17 | ///
18 | /// Description of Modules.
19 | ///
20 | public partial class Modules : Form
21 | {
22 | Assembly asm;
23 | public Modules(Assembly inputasm)
24 | {
25 | asm = inputasm;
26 |
27 | //
28 | // The InitializeComponent() call is required for Windows Forms designer support.
29 | //
30 | InitializeComponent();
31 |
32 | //
33 | // TODO: Add constructor code after the InitializeComponent() call.
34 | //
35 | }
36 |
37 | void ModulesShown(object sender, EventArgs e)
38 | {
39 | this.Text = "Modules from "+asm.FullName;
40 |
41 | Module[] modules = asm.GetModules();
42 | for (int i=0;i0)
55 | {
56 | string moduleaddress = moduleslist.Items[moduleslist.SelectedIndices[0]].SubItems[0].Text;
57 | int modulevalue = Convert.ToInt32(moduleaddress, 16);
58 |
59 | Module[] mod = asm.GetModules();
60 | for (int i=0;i0)
74 | {
75 | string strtoset = moduleslist.Items[moduleslist.SelectedIndices[0]].SubItems[0].Text;
76 | if (strtoset!="") Clipboard.SetText(strtoset);
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/AssemblyLoad/Modules.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
--------------------------------------------------------------------------------
/AssemblyLoad/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: Bogdan
4 | * Date: 01.01.2013
5 | * Time: 19:59
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | using System;
10 | using System.Windows.Forms;
11 | using System.Reflection;
12 | using System.Runtime.InteropServices;
13 |
14 | namespace AssemblyLoad
15 | {
16 | public class MyClass
17 | {
18 | // This method will be called by native code inside the target process...
19 | public static int MyMethod(String pwzArgument)
20 | {
21 | try
22 | {
23 | Application.EnableVisualStyles();
24 | Application.SetCompatibleTextRenderingDefault(false);
25 | }
26 | catch
27 | {
28 | }
29 | MainForm mf = new MainForm();
30 | mf.Show();
31 | Application.Run();
32 |
33 |
34 | return 0;
35 | }
36 |
37 | }
38 |
39 | ///
40 | /// Class with program entry point.
41 | ///
42 | internal sealed class Program
43 | {
44 |
45 | ///
46 | /// Program entry point.
47 | ///
48 | [STAThread]
49 | public static void Main(string[] args)
50 | {
51 | string target = @"C:\\Deobfuscator.exe";
52 | Assembly asm = Assembly.LoadFile(target);
53 | SendToJit.SendModuleToJit(asm.ManifestModule);
54 |
55 | Application.EnableVisualStyles();
56 | Application.SetCompatibleTextRenderingDefault(false);
57 | Application.Run(new MainForm());
58 | }
59 |
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/AssemblyLoad/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region Using directives
2 |
3 | using System;
4 | using System.Reflection;
5 | using System.Runtime.InteropServices;
6 |
7 | #endregion
8 |
9 | // General Information about an assembly is controlled through the following
10 | // set of attributes. Change these attribute values to modify the information
11 | // associated with an assembly.
12 | [assembly: AssemblyTitle("AssemblyLoad")]
13 | [assembly: AssemblyDescription("")]
14 | [assembly: AssemblyConfiguration("")]
15 | [assembly: AssemblyCompany("")]
16 | [assembly: AssemblyProduct("AssemblyLoad")]
17 | [assembly: AssemblyCopyright("Copyright 2013")]
18 | [assembly: AssemblyTrademark("")]
19 | [assembly: AssemblyCulture("")]
20 |
21 | // This sets the default COM visibility of types in the assembly to invisible.
22 | // If you need to expose a type to COM, use [ComVisible(true)] on that type.
23 | [assembly: ComVisible(false)]
24 |
25 | // The assembly version has following format :
26 | //
27 | // Major.Minor.Build.Revision
28 | //
29 | // You can specify all the values or you can use the default the Revision and
30 | // Build Numbers by using the '*' as shown below:
31 | [assembly: AssemblyVersion("1.0.*")]
32 |
--------------------------------------------------------------------------------
/AssemblyLoad/SendToJit.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Created by SharpDevelop.
3 | * User: Bogdan
4 | * Date: 03.01.2013
5 | * Time: 17:31
6 | *
7 | * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 | */
9 | using System;
10 | using System.Reflection;
11 | using System.Runtime.CompilerServices;
12 | using System.Windows.Forms;
13 | using System.Runtime.InteropServices;
14 | using System.IO;
15 |
16 | namespace AssemblyLoad
17 | {
18 | ///
19 | /// Description of SendToJit.
20 | ///
21 | public class SendToJit
22 | {
23 | public SendToJit()
24 | {
25 | }
26 | static int methodcount=0;
27 | static int failed=0;
28 | static Module imodule;
29 | static int methodtoken;
30 | private static void SendMethodToJit(MethodBase mbase)
31 | {
32 | methodcount++;
33 | if (mbase.MetadataToken>methodtoken)
34 | methodtoken=mbase.MetadataToken;
35 |
36 |
37 | }
38 |
39 | [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
40 | private delegate IntPtr DoPrestub(RuntimeMethodHandle method);
41 |
42 | private static DoPrestub doPrestub;
43 | private unsafe static void InitPrestub()
44 | {
45 | // 0x79e80f8d
46 | // 7A0C743F mscorwks!MethodDesc::CompileMethod = "_CompileMethod" from RuntimeHelpers:
47 | // 7a0c74e5 call mscorwks!MethodDesc::DoPrestub (79e80f8d) - "clr/src/vm/prestub.cpp"
48 | IntPtr compileaddress = (IntPtr)typeof(RuntimeHelpers).GetMethod("_CompileMethod", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance).MethodHandle.GetFunctionPointer().ToPointer();
49 |
50 | int N=0;
51 | do
52 | {
53 | N++;
54 | }
55 | while (Marshal.ReadInt32(compileaddress, N)!=0x01FC45C6);
56 | N = N+8;
57 |
58 | IntPtr IntPtrdoprestub = (IntPtr)(Marshal.ReadInt32(compileaddress,N+1)+(int)compileaddress+N+5);
59 |
60 | doPrestub = (DoPrestub)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtrdoprestub,typeof(DoPrestub));
61 | }
62 |
63 |
64 | private static void SendMethodsToJit()
65 | {
66 | MethodBase mbase =null;
67 |
68 | for (int j = 0x06000001; j <= methodtoken; j++)
69 | {
70 | try
71 | {
72 | mbase = imodule.ResolveMethod(j);
73 | RuntimeTypeHandle handle = new RuntimeTypeHandle();
74 | doPrestub(mbase.MethodHandle);
75 |
76 | }
77 | catch
78 | {
79 |
80 | }
81 |
82 |
83 | }
84 | }
85 | private static void SendTypeToJit(Type tdef)
86 | {
87 | MethodBase[] mbases = tdef.GetMethods(BindingFlags.NonPublic | BindingFlags.Public
88 | | BindingFlags.Instance | BindingFlags.Static);
89 | for (int i = 0; i < mbases.Length; i++)
90 | {
91 | if (mbases[i].Module==imodule)
92 | SendMethodToJit(mbases[i]);
93 | }
94 |
95 | MethodBase[] cbases = tdef.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public
96 | | BindingFlags.Instance | BindingFlags.Static);
97 | for (int i = 0; i < cbases.Length; i++)
98 | {
99 | if (cbases[i].Module==imodule)
100 | SendMethodToJit(cbases[i]);
101 | }
102 |
103 | Type[] nestedtypes = tdef.GetNestedTypes();
104 | for (int i = 0; i < nestedtypes.Length; i++)
105 | SendTypeToJit(nestedtypes[i]);
106 |
107 | }
108 | public static void SendModuleToJit(Module mod)
109 | {
110 | InitPrestub();
111 | imodule = mod;
112 |
113 | MethodBase[] mbases = mod.GetMethods(BindingFlags.NonPublic | BindingFlags.Public
114 | | BindingFlags.Instance | BindingFlags.Static);
115 | for (int i = 0; i < mbases.Length; i++)
116 | {
117 | if ( mbases[i].Module==imodule)
118 | SendMethodToJit(mbases[i]);
119 | }
120 | Type[] types = mod.GetTypes();
121 | for (int i = 0; i < types.Length; i++)
122 | SendTypeToJit(types[i]);
123 |
124 | SendMethodsToJit();
125 |
126 |
127 | MessageBox.Show("Last method token: "+methodtoken.ToString("X8")+"; failed: "+failed.ToString());
128 | }
129 |
130 |
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/AssemblyLoadTest.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual Studio 2008
4 | # SharpDevelop 3.2.1.6466
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssemblyLoad", "AssemblyLoad\AssemblyLoad.csproj", "{67C4527C-A791-40E2-BE4B-F7A3B7A21635}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|x86 = Debug|x86
10 | Release|x86 = Release|x86
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {67C4527C-A791-40E2-BE4B-F7A3B7A21635}.Debug|x86.Build.0 = Debug|x86
14 | {67C4527C-A791-40E2-BE4B-F7A3B7A21635}.Debug|x86.ActiveCfg = Debug|x86
15 | {67C4527C-A791-40E2-BE4B-F7A3B7A21635}.Release|x86.Build.0 = Release|x86
16 | {67C4527C-A791-40E2-BE4B-F7A3B7A21635}.Release|x86.ActiveCfg = Release|x86
17 | EndGlobalSection
18 | EndGlobal
19 |
--------------------------------------------------------------------------------