-2

I have found the address of a value in MyGame using Cheat Engine and created a Cheat Table (mygame.ct)

Here is some Lua code I found to change values:

function AOBRep(search, change)
    local aob = AOBScan(search)
    if aob then
        for i=0,aob.Count-1 do
            autoAssemble(aob[i]..':\ndb '..change)
        end
        aob.Destroy()
    end
end

function option2()
    searchV = 'B8 41 00 00 C8 41 00 00 F4 41' --off
    searchV2 = 'B8 41 00 00 AF 43 00 00 AF 43' --on1
    replaceV = 'B8 41 00 00 2F 44 00 00 2F 44' --on2
    AOBRep(searchV,replaceV)
    AOBRep(searchV2,replaceV)
end

function option1()
    searchV = 'B8 41 00 00 C8 41 00 00 F4 41' --off
    replaceV = 'B8 41 00 00 AF 43 00 00 AF 43' --on
    AOBRep(searchV,replaceV)
end

MyForm = createForm(true)
MyForm.Caption = 'My Game'
MyForm.Width = 300
MyForm.Height = 200

mbbo = createButton(MyForm)
mbbo.Left = 20
mbbo.Top = 100
mbbo.Width = 80
mbbo.Height = 40
mbbo.onClick = option2
mbbo.Caption = 'Option2'

ahbf = createButton(MyForm)
ahbf.Left = 6
ahbf.Top = 4
ahbf.Width = 90
ahbf.Height = 50
ahbf.onClick = option1
ahbf.Caption = 'Option1'

I want to convert this Lua code to change Values in C++,

For example convert this the Lua code to change AOB Value B8 41 00 00 C8 41 00 00 F4 41 to B8 41 00 00 AF 43 00 00 AF 43

function option2()
    searchV = 'B8 41 00 00 C8 41 00 00 F4 41' --off
    searchV2 = 'B8 41 00 00 AF 43 00 00 AF 43' --hs
    replaceV = 'B8 41 00 00 2F 44 00 00 2F 44' --mb
    AOBRep(searchV,replaceV)
    AOBRep(searchV2,replaceV)
end
Taazar
  • 1,545
  • 18
  • 27
Abdul
  • 1
  • 3
  • Hello and welcome to stackoverflow. I think you need to clarify your question a bit. You can read a bit more about it here: stackoverflow.com/help/how-to-ask – asm0dey Jan 19 '20 at 20:04
  • 1. I can't find question here 2. It's unclear what you've tried to do 3. It's unclear how c++ is related to question 4. it's unclear what cheat engine you're talking about – asm0dey Jan 20 '20 at 07:59
  • @asm0dey (1) He wants to change the first code to change the values he picked at the bottom. (2) He has found the AOB Values and put them into the very bottom Lua code. (3) I think he wants to convert the code to C++. (4) The program he is using is just called Cheat Engine: https://www.cheatengine.org/ – Taazar Jan 20 '20 at 11:29
  • Please consider to edit your question – Munkhdelger Tumenbayar Jan 24 '20 at 03:55

1 Answers1

0

Seeing how Cheatengine runs on Windows, and you want to replace data within another process' address space, it all boils down to using three functions:

  1. CreateProcess in order to create a process and get a handle with the necessary access rights to it (this is by far the easiest way of getting a handle that will work).
  2. ReadProcessMemory to copy memory to your own process where you can then memcmp to find a match
  3. WriteProcessMemory to copy the data that you want to the location where you found the pattern

While it's pretty trivial in theory, the devil is in the details. Good luck.

You may consider using VirtualQuery to find out which memory regions are actually existent, and QueryVirtualMemoryInformation which may tell you whether a page is private (private pages likely being the only ones you are interested in for cheats). Otherwise you can of course just call ReadProcessMemory all over the place, which will "work", but will be wasteful (especially under 64 bits where there's quite a bit of address space to walk through, when doing so totally uninformed).

Damon
  • 67,688
  • 20
  • 135
  • 185
  • Thank you for comment.. i want change AOB ( Array of Byte) Value.. i can change AOB Value easily in cheat Engine, but i want to do in c++, – Abdul Jan 21 '20 at 09:04
  • In order to do the same thing in C++, you will need to use `WriteProcessMemory`. And you'll need a handle first, and since you do not seem to know the address (only a search/replace pattern from your example), you will also need to `ReadProcessMemory` so you can find the match. Short of other tricks that are arguably more complicated (code injection, creating a remote thread) that's the straightforward way of getting into another process' address space under Windows. – Damon Jan 22 '20 at 17:14
  • i have already creates WriteProcessMemory and ReadProcessMemory in my program and i'm fine change ( double and float and dword etc) values – Abdul Jan 23 '20 at 08:39
  • but i don't know how to change AOB.. How write code for AOB? – Abdul Jan 23 '20 at 08:40
  • AOB = array of bytes. For user convenience, they're hexadecimal when displayed because `ø¦¿3#¶` isn't very easy to decipher, but they're still only just _some bytes_. Bytes are sequential "raw data", so I fail to see the difficulty? In fact, they ought to be easier to get right than `float`. – Damon Jan 25 '20 at 10:47