Example #1
0
        protected override void BuildCustomRemoteCode(X86Writer w, MemoryStream ms)
        {
            RecordedValueHandle?.Dispose();
            RecordedValueHandle = new SafeRemoteHandle(sizeof(int));

            //Move address in Register into the value of RecordedValueHandle
            //
            //  e.g. with RecordedValueHandle = 7777 and Register = X86Register32.EAX:
            //      mov [7777],eax
            w.Mov32(new X86Address(X86Register32.None, RecordedValueHandle.GetHandle().ToInt32()), Register);
        }
Example #2
0
        private void InitAsmBuffer(int funcAddr, IEnumerable <dynamic> parameters, List <SafeRemoteHandle> allocPtrList,
                                   dynamic eax = null,
                                   dynamic ecx = null,
                                   dynamic edx = null,
                                   dynamic ebx = null,
                                   dynamic esp = null,
                                   dynamic esi = null,
                                   dynamic edi = null)
        {
            var args = parameters.ToArray();

            AsmBuffer.Position = 0;
            X86Writer asm = new X86Writer(AsmBuffer, CodeHandle.GetHandle());

            //ASM START:
            asm.Push32(Reg32.EBP);
            asm.Mov32(Reg32.EBP, Reg32.ESP);
            asm.Push32(Reg32.EAX);

            for (int i = args.Length - 1; i >= 0; i += -1)
            {
                asm.Mov32(Reg32.EAX, SquashIntoDword(ref allocPtrList, args[i]));
                asm.Push32(Reg32.EAX);
            }

            if (eax != null)
            {
                asm.Mov32(Reg32.EAX, SquashIntoDword(ref allocPtrList, eax));
            }

            if (ecx != null)
            {
                asm.Mov32(Reg32.ECX, SquashIntoDword(ref allocPtrList, ecx));
            }

            if (edx != null)
            {
                asm.Mov32(Reg32.EDX, SquashIntoDword(ref allocPtrList, edx));
            }

            if (ebx != null)
            {
                asm.Mov32(Reg32.EBX, SquashIntoDword(ref allocPtrList, ebx));
            }

            if (esp != null)
            {
                asm.Mov32(Reg32.ESP, SquashIntoDword(ref allocPtrList, esp));
            }

            if (esi != null)
            {
                asm.Mov32(Reg32.ESI, SquashIntoDword(ref allocPtrList, esi));
            }

            if (edi != null)
            {
                asm.Mov32(Reg32.EDI, SquashIntoDword(ref allocPtrList, edi));
            }

            //CALL LUA FUNCTION:
            asm.Call(new IntPtr(funcAddr));
            AsmLocAfterLuaFunctionCall = new MoveableAddressOffset(this, asm.Position);
            //SET RETURN POS:
            asm.Mov32(Reg32.EBX, CodeHandle.GetHandle().ToInt32() + FUNC_RETURN_ADDR_OFFSET);
            asm.Mov32(new Addr(Reg32.EBX, 0), Reg32.EAX);
            //mov [ebx], eax
            asm.Pop32(Reg32.EAX);

            for (int i = args.Length - 1; i >= 0; i += -1)
            {
                asm.Pop32(Reg32.EAX);
            }

            asm.Mov32(Reg32.ESP, Reg32.EBP);
            asm.Pop32(Reg32.EBP);
            asm.Retn();
        }