首页  编辑  

直接调用机器代码

Tags: /C#/其他技巧/   Date Created:

internal delegate int MyFunction (int A, int B);

private void button1_Click( object sender , EventArgs ce)

{

    byte [] vBuffer = { 85 , 139 , 236 , 139 , 85 , 12 , 139 , 69 , 8 , 139 , 200 , 15 ,

        175 , 202 , 113 , 5 , 232 , 19 , 53 , 251 , 255 , 3 , 193 , 113 , 5 , 232 , 10 ,

        53 , 251 , 255 , 3 , 208 , 113 , 5 , 232 , 1 , 53 , 251 , 255 , 139 , 194 , 93 ,

        194 , 8 , 0 , 141 , 64 , 0 };

    IntPtr vProcAddress = Marshal . UnsafeAddrOfPinnedArrayElement(vBuffer, 0 );

    MyFunction vMyFunction = Marshal . GetDelegateForFunctionPointer(

       vProcAddress, typeof ( MyFunction )) as MyFunction ;

   Text = vMyFunction( 12 , 13 ) . ToString();

}