[Mono-bugs] [Bug 419966] Cannot copy instructions from one assembly to another
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Aug 25 10:11:20 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=419966
User high6 at live.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=419966#c2
--- Comment #2 from high six <high6 at live.com> 2008-08-25 08:11:19 MDT ---
I rather keep my source closed so here is the dump of the method's body.
ldarg.0
ldstr System.Security.Cryptography.MD5
ldc.i4 1
newarr System.Object
stloc.s V_4
stloc.s V_5
ldloc.s V_4
ldc.i4 0
ldloc.s V_5
stelem.ref
ldloc.s V_4
ldc.i4 0
ldelem.ref
castclass System.String
ldc.i4 1
newarr System.Object
stloc.s V_2
stloc.s V_3
ldloc.s V_2
ldc.i4 0
ldloc.s V_3
stelem.ref
ldloc.s V_2
ldc.i4 0
ldelem.ref
castclass System.String
ldnull
call System.Object
System.Security.Cryptography.CryptoConfig::CreateFromName(System.String,System.Object[])
castclass System.Security.Cryptography.MD5
stfld System.Security.Cryptography.MD5 ConsoleApplication1.Program::md5
ldarg.0
ldfld System.Security.Cryptography.MD5 ConsoleApplication1.Program::md5
ldsfld System.Text.Encoding System.Text.Encoding::asciiEncoding
brtrue Mono.Cecil.Cil.Instruction
newobj System.Void System.Text.ASCIIEncoding::.ctor()
stsfld System.Text.Encoding System.Text.Encoding::asciiEncoding
ldsfld System.Text.Encoding System.Text.Encoding::asciiEncoding
ldstr HI!
callvirt System.Byte[] System.Text.Encoding::GetBytes(System.String)
callvirt System.Byte[]
System.Security.Cryptography.HashAlgorithm::ComputeHash(System.Byte[])
stloc.0
ldloc.0
call System.String System.Convert::ToBase64String(System.Byte[])
stloc.1
ldloc.1
ret
and here is the exe after that is saved.
http://rapidshare.com/files/139997368/ConsoleApplication2.exe.exe.html
All I am doing is loading the crypto dll and inlining the static methods.
(Inline works fine on local static classes)
The code I am using to get the md5 method. (This code I am fine with sharing)
List<AssemblyDefinition> Loaded = new List<AssemblyDefinition>();
AssemblyDefinition LoadAssembly(string name, string ver)
{
for (int a = 0; a < Loaded.Count; a++)
{
if (name == Loaded[a].Name.Name)
{
return Loaded[a];
}
}
string file = Environment.GetEnvironmentVariable("SystemRoot") +
"/Microsoft.NET/Framework/" + ver + "/" + name + ".dll";
if (System.IO.File.Exists(file) == false)
return null;
AssemblyDefinition asm = AssemblyFactory.GetAssembly(file);
Loaded.Add(asm);
return asm;
}
MethodDefinition GetDefinition(MethodReference mr, string ver)
{
TypeReference t = mr.DeclaringType;
string file = "ERROR!";
if (t.Scope is AssemblyNameReference)
{
file = ((AssemblyNameReference)t.Scope).Name;
}
else if (t.Scope is ModuleDefinition)
{
file = ((ModuleDefinition)t.Scope).Assembly.Name.Name;
}
else
{
}
if (file.EndsWith(".dll"))
file = file.Substring(0, file.Length - 4);
AssemblyDefinition asm = LoadAssembly(file, ver);
if (asm == null)
return null;
for (int a = 0; a < asm.MainModule.Types.Count; a++)
{
if (t.Namespace == asm.MainModule.Types[a].Namespace && t.Name ==
asm.MainModule.Types[a].Name)
{
for (int b = 0; b < asm.MainModule.Types[a].Methods.Count; b++)
{
if (mr.Name == asm.MainModule.Types[a].Methods[b].Name &&
ParamCmp(mr.Parameters, asm.MainModule.Types[a].Methods[b].Parameters))
{
return asm.MainModule.Types[a].Methods[b];
}
}
}
}
return null;
}
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list