Hi% username%! So, let's continue writing our bot. Today we will inject our code into the gameplay (not without the help of assembler), and later we will take care that it would not be so easy to find it, because it’s punished not for cheating, but for getting caught. And to be honest to the end, even if we don’t completely embrace the process of the game, we will implement it, and only once during the entire life cycle.
var ProcessHandle = OpenProcess(processId); Process.EnterDebugMode(); var dwThreadId = Process.GetProcessById(dwProcessId).Threads[0].Id; var ThreadHandle = OpenThread(0x1F03FF, false, (uint)dwThreadId); var HookAddress = Memory.AllocateMemory(6000); var argumentAddress1 = Memory.AllocateMemory(80); Memory.WriteBytes(argumentAddress1, new byte[80]); var argumentAddress2 = Memory.AllocateMemory(BufferSize); Memory.WriteBytes(argumentAddress2, new byte[80]); var resultAddress = Memory.AllocateMemory(4); Memory.Write<int>(_resultAddress, 0); var asmLine = new List<string> { "pushfd", "pushad", "mov edx, 0", "mov ecx, " + resultAddress, "mov [ecx], edx", "@loop:", "mov eax, [ecx]", "cmp eax, " + 80, "jae @end", "mov eax, " + argumentAddress1, "add eax, [ecx]", "mov eax, [eax]", "test eax, eax", "je @out", "call eax", "mov ecx, " + resultAddress, "mov edx, " + argumentAddress2, "add edx, [ecx]", "mov [edx], eax", "mov edx, " + argumentAddress1, "add edx, [ecx]", "mov eax, 0", "mov [edx], eax", "@out:", "mov eax, [ecx]", "add eax, 4", "mov [ecx], eax", "jmp @loop", "@end:", "popad", "popfd" }; Memory.Asm = new ManagedFasm(ProcessHandle); Memory.Asm.Clear(); foreach (var str in asmLine) { Memory.Asm.AddLine(str); } Memory.Asm.Inject(HookAddress); var length = (uint) Memory.Asm.Assemble().Length; Memory.WriteBytes(HookAddress + length, OpCodes); Memory.Asm.Clear(); Memory.Asm.AddLine("jmp " + (Address + OpCodes.Length)); Memory.Asm.Inject((uint)((HookAddress + length) + OpCodes.Length)); Memory.Asm.Clear(); Memory.Asm.AddLine("jmp " + HookAddress); for (var k = 0; k <= ((OpCodes.Length - 5) - 1); k++) { Memory.Asm.AddLine("nop"); } Memory.Asm.Inject(Address); public byte[] InjectAndExecute(IEnumerable<string> asm, bool returnValue = false, int returnLength = 0) { Memory.Asm.Clear(); foreach (var str in asm) { Memory.Asm.AddLine(str); } dwAddress = Memory.AllocateMemory(Memory.Asm.Assemble().Length + 60); Memory.Asm.Inject(dwAddress); Memory.Write<uint>(argumentAddress1, dwAddress); while (Memory.Read<int>(argumentAddress1) > 0) { Thread.Sleep(1); } byte[] result = new byte[0]; if (returnValue) { result = Memory.ReadBytes(Memory.Read<uint>(argumentAddress2), returnLength); } Memory.Write<int>(argumentAddress2, 0); Memory.FreeMemory(dwAddress); return result; } Source: https://habr.com/ru/post/251149/
All Articles