Пример #1
0
        public void CallCustomX86(Action <X86Writer> writeX86)
        {
            if (CodeHandle.IsClosed || CodeHandle.IsInvalid)
            {
                CompletelyReInitializeAndInjectCodeInNewLocation();
            }

            Kernel.CheckAddress(CodeHandle.GetHandle().ToInt64(), FUNCTION_CALL_ASM_BUFFER_SIZE, "execute function");

            Buffer_ParamPointerList.Clear();

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

            writeX86.Invoke(asm);

            if (WriteAsm((uint)CodeHandle.GetHandle(), AsmBuffer.ToArray(), (int)AsmBuffer.Position))
            {
                var threadHandle = new SafeRemoteThreadHandle(CodeHandle);
                if (!threadHandle.IsClosed & !threadHandle.IsInvalid)
                {
                    Kernel.WaitForSingleObject(threadHandle.GetHandle(), MAX_WAIT);
                }
                threadHandle.Close();
                threadHandle.Dispose();
                threadHandle = null;
            }
        }
Пример #2
0
        private byte[] ExecuteAsm()
        {
            var threadHandle = new SafeRemoteThreadHandle(CodeHandle);

            if (!threadHandle.IsClosed & !threadHandle.IsInvalid)
            {
                Kernel.WaitForSingleObject(threadHandle.GetHandle(), MAX_WAIT);
            }
            threadHandle.Close();
            threadHandle.Dispose();
            threadHandle = null;

            return(CodeHandle.GetFuncReturnValue());
        }
Пример #3
0
        public void CallArrayOfBytes(byte[] asmBytes)
        {
            if (CodeHandle.IsClosed || CodeHandle.IsInvalid)
            {
                CompletelyReInitializeAndInjectCodeInNewLocation();
            }

            if (WriteAsm((uint)CodeHandle.GetHandle().ToInt64(), asmBytes, asmBytes.Length))
            {
                var threadHandle = new SafeRemoteThreadHandle(CodeHandle);
                if (!threadHandle.IsClosed & !threadHandle.IsInvalid)
                {
                    Kernel.WaitForSingleObject(threadHandle.GetHandle(), MAX_WAIT);
                }
                threadHandle.Close();
                threadHandle.Dispose();
                threadHandle = null;
            }
        }