示例#1
0
 private IntPtr CreateMethod(IntPtr stub)
 {
     Compiler compiler = new Compiler();
     compiler.NewFunction(CallingConvention.Default, typeof(Func<int>));
     GPVar x = compiler.NewGP(VariableType.INT32);
     compiler.Mov(x, 2);
     compiler.Ret(x);
     compiler.EndFunction();
     return compiler.Make();
 }
示例#2
0
        private static void Main(string[] args)
        {
            TestExceptionHandling test = new TestExceptionHandling();
            test.RunTest();

            Compiler compiler = new Compiler();
            CallingConvention callingConvention = CallingConvention.Default;
            compiler.NewFunction(callingConvention, typeof(Func<int>));
            GPVar var = compiler.NewGP();
            compiler.Mov(var, 3);
            compiler.Ret(var);
            compiler.EndFunction();
            IntPtr ptr = compiler.Make();
            Method1 method = (Method1)Marshal.GetDelegateForFunctionPointer(ptr, typeof(Method1));
            int result = method();
            Console.WriteLine(result);

            IntPtr method2Ptr = CreateMethodStub();
            TestMethod method2 = (TestMethod)Marshal.GetDelegateForFunctionPointer(method2Ptr, typeof(TestMethod));
            Console.WriteLine(method2());
        }
示例#3
0
        private static CpuIdMethod BuildCpuIdFunction()
        {
            Compiler compiler = new Compiler();

            compiler.NewFunction(CallingConvention.Default, typeof(Action<IntPtr, IntPtr, IntPtr, IntPtr>));
            compiler.Function.SetHint(FunctionHints.Naked, true);

            GPVar eaxPtr = compiler.ArgGP(0);
            GPVar ebxPtr = compiler.ArgGP(1);
            GPVar ecxPtr = compiler.ArgGP(2);
            GPVar edxPtr = compiler.ArgGP(3);

            GPVar eax = compiler.NewGP();
            GPVar ebx = compiler.NewGP();
            GPVar ecx = compiler.NewGP();
            GPVar edx = compiler.NewGP();

            compiler.Mov(eax, Mem.dword_ptr(eaxPtr));
            compiler.Cpuid(eax, ebx, ecx, edx);
            compiler.Mov(Mem.dword_ptr(eaxPtr), eax);
            compiler.Mov(Mem.dword_ptr(ebxPtr), ebx);
            compiler.Mov(Mem.dword_ptr(ecxPtr), ecx);
            compiler.Mov(Mem.dword_ptr(edxPtr), edx);

            compiler.Ret();
            compiler.EndFunction();
            CpuIdMethod cpuId = (CpuIdMethod)Marshal.GetDelegateForFunctionPointer(compiler.Make(), typeof(CpuIdMethod));

            return cpuId;
        }