小さな復号化および実行アプリケーションを開発しましたが、実行部分で立ち往生しています。以下の方法を使用して、.NET アセンブリを正常に実行します。
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);
しかし、この投稿を使用して実行可能領域を割り当てようとすると、アプリケーションがクラッシュします
私が得る唯一の有用な情報はこれです:
Fault Module Name: StackHash_0a9e
これが私のコードです:
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());