.net assembly - C# load raw bytes -


i've developped small decrypt , execute application , i'm stuck @ execution part. succesfully execute .net assemblies using method below:

 assembly asm = assembly.load(decryptedbytes);     if (asm.entrypoint == null)      throw new applicationexception("no entry point found!");   methodinfo epoint = asm.entrypoint;  object ins = asm.createinstance(epoint.name);  epoint.invoke(ins, null); 

but when try allocating executable region using post application crashes

the useful information this:

fault module name:  stackhash_0a9e 

here code:

  const uint page_execute_readwrite = 0x40;   const uint mem_commit = 0x1000;    [dllimport("kernel32.dll", setlasterror = true)]   static extern intptr virtualalloc(intptr lpaddress, uint dwsize, uint flallocationtype, uint flprotect);    private delegate int intreturner();  intptr buf = virtualalloc(intptr.zero, (uint)decryptedbytes.length, mem_commit, page_execute_readwrite); marshal.copy(decryptedbytes, 0, buf, decryptedbytes.length);  intreturner ptr = (intreturner)marshal.getdelegateforfunctionpointer(buf, typeof(intreturner)); console.writeline(ptr()); 


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -