Jump to content
Tuts 4 You

Save Assembly to File


Dumpper

Recommended Posts

Posted

Hi,

 

At this time i have success load byte array contain assembly to application, Below sample script:

 

//1. Load raw assembly from byte array

  Assembly SampleAssembly = Assembly.Load(byte_arr_assembly);

 

//2. Launch Form Inside Assembley, Success

 

if (SampleAssembly != null)
            {
                
                Type[] types = SampleAssembly.GetTypes();                foreach (Type type in types)
                {
                    MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.Static);                    foreach (MethodInfo mf in methodInfos)
                    {
                        if (mf.Name == "Invoke")
                        {
                            type.InvokeMember("Invoke", BindingFlags.InvokeMethod, null, null, new object[0]);
                            break;
                        }
                    }
               
                }
            }

 

My Question: How i can save those assembly to file, so i can run it,

 

Regards,

B.C

 

Posted (edited)

I didn't exactly understand the question.


If uou want to dump an assembly from your program, then just insert File.WriteAllBytes(@"C:\myfile.exe", byte_arr_assembly).


If you want to make the assembly to load, then just create a DLL then copy its bytes.


If it's not your program and you want to dump, you can insert File.WriteAllBytes(@"C:\myfile.exe", byte_arr_assembly), use WinDBG with SOS or use Reflector VSPro in VS. There's nothing easier ;)


 


EDIT: btw, why every types/methods are checked ? you should better use GetType("MyType") and GetMethod("MyMethod") ?


Edited by mArTi
Posted (edited)

Hello mArTi,


 


Tq for attention, finally success directly write byte array to file as your advice,


 


"btw, why every types/methods are checked ? you should better use GetType("MyType") and GetMethod("MyMethod") ?"


 


Actually i don't know assembly inside byte array coz obfuscated, so i use those methode, 


Edited by Dumpper

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...