Ejemplo n.º 1
0
        public static uint InjectCode(AppProcess process, uint address, int replacedInstructionSize, byte[] newCode)
        {
            if (replacedInstructionSize < 5)
            {
                throw new Exception("Replaced instruction size much be greater than 5.");
            }

            //Allocate the memory required
            uint allocatedMem = process.AllocateMemory((uint)(newCode.Length + replacedInstructionSize + JMPSize));

            //Write the new code in the allocated memory
            process.WriteBytes((int)allocatedMem, newCode);

            //Copy the old code
            CopyInstructions(process, address, allocatedMem + (uint)newCode.Length, replacedInstructionSize);

            //Write jump at the end of the allocated memory
            WriteJump(process, allocatedMem + (uint)newCode.Length + (uint)replacedInstructionSize, address + (uint)replacedInstructionSize);

            //Write jump address
            WriteJump(process, address, allocatedMem);

            //Write nops to be clean
            WriteNOPs(process, address + JMPSize, replacedInstructionSize - JMPSize);

            return(allocatedMem);
        }
Ejemplo n.º 2
0
        public static void WriteNOPs(AppProcess process, uint address, int count)
        {
            if (count <= 0)
            {
                return;
            }

            byte[] nops = new byte[count];
            for (int i = 0; i < count; i++)
            {
                nops[i] = NOP;
            }

            process.WriteBytes((int)address, nops);
        }
Ejemplo n.º 3
0
        public static uint DeinjectCode(AppProcess process, uint allocatedMem, uint address, int replacedInstructionSize, int newCodeLength)
        {
            if (replacedInstructionSize < 5)
            {
                throw new Exception("Replaced instruction size much be greater than 5.");
            }

            //Write original instructions
            CopyInstructions(process, allocatedMem + (uint)newCodeLength, address, replacedInstructionSize);

            //Free the allocated memory
            process.FreeMemory(allocatedMem);

            return(allocatedMem);
        }
Ejemplo n.º 4
0
 public MemoryEditManager(AppProcess process)
 {
     mProcess = process;
 }
Ejemplo n.º 5
0
 public static void CopyInstructions(AppProcess process, uint srcAddress, uint destAddress, int size)
 {
     byte[] instructions = process.GetBytes((int)srcAddress, size);
     process.WriteBytes((int)destAddress, instructions);
 }
Ejemplo n.º 6
0
 public static void WriteJump(AppProcess process, uint srcAddress, uint destAddress)
 {
     process.WriteInt8((int)srcAddress, 0xE9);
     process.WriteInt32((int)srcAddress + 1, destAddress - srcAddress - JMPSize);
 }