Exemplo n.º 1
0
        private void ButtonWriteData_Click(object sender, RoutedEventArgs e)
        {
            if (TrashMem != null && listboxAllocations.SelectedItem != null)
            {
                uint address = ((MemoryAllocation)listboxAllocations.SelectedItem).Address;
                int  size    = ((MemoryAllocation)listboxAllocations.SelectedItem).Size;

                switch ((string)comboboxDataType.SelectedItem)
                {
                case "Bytes":
                    byte[] bytes = Encoding.ASCII.GetBytes(textboxData.Text);
                    if (bytes.Length <= size)
                    {
                        TrashMem.WriteBytes(address, bytes);
                    }
                    break;

                case "Char":
                    if (char.TryParse(textboxData.Text, out char charValue))
                    {
                        TrashMem.Write(address, charValue);
                    }
                    break;

                case "Int16":
                    if (short.TryParse(textboxData.Text, out short shortValue))
                    {
                        TrashMem.Write(address, shortValue);
                    }
                    break;

                case "Int32":
                    if (int.TryParse(textboxData.Text, out int intValue))
                    {
                        TrashMem.Write(address, intValue);
                    }
                    break;

                case "Int64":
                    if (long.TryParse(textboxData.Text, out long longValue))
                    {
                        TrashMem.Write(address, longValue);
                    }
                    break;

                case "Float":
                    if (float.TryParse(textboxData.Text, out float floatValue))
                    {
                        TrashMem.Write(address, floatValue);
                    }
                    break;

                case "Double":
                    if (double.TryParse(textboxData.Text, out double doubleValue))
                    {
                        TrashMem.Write(address, doubleValue);
                    }
                    break;

                case "ASCII String":
                    TrashMem.WriteString(address, textboxData.Text, Encoding.ASCII);
                    break;
                }

                UpdateByteViews(address, size);
            }
        }
Exemplo n.º 2
0
        private void SetupEndsceneHook()
        {
            // first thing thats 5 bytes big is here
            // we are going to replace this 5 bytes with
            // our JMP instruction (JMP (1 byte) + Address (4 byte))
            EndsceneAddress += ENDSCENE_HOOK_OFFSET;

            // if WoW is already hooked, unhook it
            if (IsWoWHooked)
            {
                DisposeHook();
            }
            else
            {
                originalEndsceneBytes = TrashMem.ReadChars(EndsceneAddress, 5);
            }

            // if WoW is now/was unhooked, hook it
            if (!IsWoWHooked)
            {
                AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tHooking EndScene at \"0x{EndsceneAddress.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}\"", LogLevel.Verbose);

                // the address that we will return to after
                // the jump wer'e going to inject
                EndsceneReturnAddress = EndsceneAddress + 0x5;

                // integer to check if there is code waiting to be executed
                CodeToExecuteAddress = TrashMem.AllocateMemory(4);
                TrashMem.Write(CodeToExecuteAddress.Address, 0);

                // integer to save the address of the return value
                ReturnValueAddress = TrashMem.AllocateMemory(4);
                TrashMem.Write(ReturnValueAddress.Address, 0);

                // codecave to check if we need to execute something
                CodecaveForCheck = TrashMem.AllocateMemory(128);
                AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tCCCheck is at \"0x{CodecaveForCheck.Address.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}\"", LogLevel.Verbose);
                // codecave for the code we wa't to execute
                CodecaveForExecution = TrashMem.AllocateMemory(2048);
                AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tCCExecution is at \"0x{CodecaveForExecution.Address.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}\"", LogLevel.Verbose);

                TrashMem.Asm.Clear();
                // save registers
                TrashMem.Asm.AddLine("PUSHFD");
                TrashMem.Asm.AddLine("PUSHAD");

                // check for code to be executed
                TrashMem.Asm.AddLine($"MOV EBX, [0x{CodeToExecuteAddress.Address.ToString("X")}]");
                TrashMem.Asm.AddLine("TEST EBX, 1");
                TrashMem.Asm.AddLine("JE @out");

                // execute our stuff and get return address
                TrashMem.Asm.AddLine($"MOV EDX, 0x{CodecaveForExecution.Address.ToString("X")}");
                TrashMem.Asm.AddLine("CALL EDX");
                TrashMem.Asm.AddLine($"MOV [0x{ReturnValueAddress.Address.ToString("X")}], EAX");

                // finish up our execution
                TrashMem.Asm.AddLine("@out:");
                TrashMem.Asm.AddLine("MOV EDX, 0");
                TrashMem.Asm.AddLine($"MOV [0x{CodeToExecuteAddress.Address.ToString("X")}], EDX");

                // restore registers
                TrashMem.Asm.AddLine("POPAD");
                TrashMem.Asm.AddLine("POPFD");

                byte[] asmBytes = TrashMem.Asm.Assemble();

                // needed to determine the position where the original
                // asm is going to be placed
                int asmLenght = asmBytes.Length;

                // inject the instructions into our codecave
                TrashMem.Asm.Inject(CodecaveForCheck.Address);
                // ---------------------------------------------------
                // End of the code that checks if there is asm to be
                // executed on our hook
                // ---------------------------------------------------

                // Prepare to replace the instructions inside WoW
                TrashMem.Asm.Clear();

                // do the original EndScene stuff after we restored the registers
                // and insert it after our code
                TrashMem.WriteBytes(CodecaveForCheck.Address + (uint)asmLenght, originalEndsceneBytes);

                // return to original function after we're done with our stuff
                TrashMem.Asm.AddLine($"JMP 0x{EndsceneReturnAddress.ToString("X")}");
                TrashMem.Asm.Inject(CodecaveForCheck.Address + (uint)asmLenght + 5);
                TrashMem.Asm.Clear();
                // ---------------------------------------------------
                // End of doing the original stuff and returning to
                // the original instruction
                // ---------------------------------------------------

                // modify original EndScene instructions to start the hook
                TrashMem.Asm.AddLine($"JMP 0x{CodecaveForCheck.Address.ToString("X")}");
                TrashMem.Asm.Inject(EndsceneAddress);
                AmeisenBotLogger.Instance.Log($"[{ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tInjected Hook [IsWoWHooked = {IsWoWHooked}]", LogLevel.Verbose);
                // we should've hooked WoW now
            }
        }