Example #1
0
        public unsafe bool Inject(IntPtr hProcess, uint dwAddress)
        {
            if (hProcess == IntPtr.Zero)
            {
                return(false);
            }
            if (this.m_AssemblyString.ToString().Contains("use64") || this.m_AssemblyString.ToString().Contains("use16"))
            {
                this.m_AssemblyString.Replace("use32\n", "");
            }
            if (!this.m_AssemblyString.ToString().Contains("org "))
            {
                this.m_AssemblyString.Insert(0, string.Format("org 0x{0:X08}\n", (object)dwAddress));
            }
            IntPtr hglobal = IntPtr.Zero;

            try
            {
                bool flag;
                try
                {
                    hglobal = Marshal.StringToHGlobalAnsi(this.m_AssemblyString.ToString());
                    int num = (int)\u003CModule\u003E._c_FasmAssemble((sbyte *)hglobal.ToPointer(), (uint)this.m_MemorySize, (uint)this.m_PassLimit);
                    goto label_13;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    flag = false;
                }
                return(flag);
            }
            finally
            {
                if (hglobal != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(hglobal);
                }
            }
label_13:
            _c_FasmState * cFasmStatePtr = (_c_FasmState *)\u003CModule\u003E._c_fasm_memorybuf;
            if (*(int *)cFasmStatePtr != 0)
            {
                throw new Exception(string.Format("Assembly failed!  Error code: {0};  Error Line: {1}; ASM: {2}", (object)*(int *)((IntPtr)cFasmStatePtr + 4), (object)(uint)*(int *)(*(int *)((IntPtr)cFasmStatePtr + 8) + 4), (object)this.m_AssemblyString.ToString()));
            }
            else
            {
                return(\u003CModule\u003E.WriteProcessMemory((void *)hProcess, (void *)dwAddress, (void *)*(int *)((IntPtr)cFasmStatePtr + 8), (uint)*(int *)((IntPtr)cFasmStatePtr + 4), (uint *)0) != 0);
            }
        }
Example #2
0
        public static unsafe byte[] Assemble(string szSource, int nMemorySize, int nPassLimit)
        {
            IntPtr        num1          = new IntPtr();
            IntPtr        hglobal       = Marshal.StringToHGlobalAnsi(szSource);
            int           num2          = (int)\u003CModule\u003E._c_FasmAssemble((sbyte *)hglobal.ToPointer(), (uint)nMemorySize, (uint)nPassLimit);
            _c_FasmState *cFasmStatePtr = (_c_FasmState *)\u003CModule\u003E._c_fasm_memorybuf;

            Marshal.FreeHGlobal(hglobal);
            if (*(int *)cFasmStatePtr != 0)
            {
                throw new Exception(string.Format("Assembly failed!  Error code: {0};  Error Line: {1}", (object)*(int *)((IntPtr)cFasmStatePtr + 4), (object)(uint)*(int *)(*(int *)((IntPtr)cFasmStatePtr + 8) + 4)));
            }
            byte[] destination = new byte[*(int *)((IntPtr)cFasmStatePtr + 4)];
            Marshal.Copy((IntPtr)((void *)*(int *)((IntPtr)cFasmStatePtr + 8)), destination, 0, *(int *)((IntPtr)cFasmStatePtr + 4));
            return(destination);
        }