Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Value at address keeps getting rewritten

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Wed Feb 01, 2017 7:32 pm    Post subject: Value at address keeps getting rewritten Reply with quote

Firstly, this is related to mapped memory used by an emulator, specifically nullDC. The problem is that I'm trying to set a static value on a specific address but that value gets rewritten almost immediately. I tried observing what writes to the address and by replacing that code it did the trick. The issue is that the source of the change is constantly jumping around and changing adresses and the replacement in the codelist is no longer valid: The memory content isn't what it should be. Also, the instruction doesn't seem specific enough:
Code:
mov [ecx+10020000],edx


How would you advise to proceed in this case?
I know that the question is basic but I would appreciate if you could point me out in the right direction.

Thanks!

Image below to illustrate.



ndc_tmp.png
 Description:
 Filesize:  115.39 KB
 Viewed:  6302 Time(s)

ndc_tmp.png


Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4703

PostPosted: Wed Feb 01, 2017 9:00 pm    Post subject: Reply with quote

It's an emulator: it's probably not going to be as basic as you would hope it to be. If you want to know why, look up what an emulator is and how they work.

I'd recommend using whatever tools the emulator provides for you. Modifying whatever machine code the game uses is probably going to be easier than trying to modify the implementation of the emulator's interpreter. It might be easier if the emulator uses JIT compilation, but it's still better to not use CE if you don't have to IMO.

If you need to use CE, do some research first. Learn how emulators generally work, figure out the design and relevant implementation of nullDC, and your life will be easier in the end. nullDC seems to be open source, so that shouldn't be too hard.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
SunBeam
I post too much
Reputation: 65

Joined: 25 Feb 2005
Posts: 4023
Location: Romania

PostPosted: Thu Feb 02, 2017 3:49 am    Post subject: Reply with quote

Was going to say something similar: emulator code that "accesses" your game's value isn't accessing only that. It's probably a handler of some sorts and you'll need to do some research first.

Something similar: LUA (see Driver game; this post). There's a major handler there that can be hooked and based on certain differentiation, you can filter out only what you need Smile
Back to top
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Thu Feb 02, 2017 4:00 pm    Post subject: Reply with quote

I understand what you mean.
And although you are probably right, and as dirty as it seems, I still want to do it just to see what happens.

If I do it manually it doesn't seem to produce side effects (to be continued...) and the code that I change always stays the "same" it just migrates around regions in memory. Anyway, I lack crucial understanding, but anyway... here is my actual question:

Given a static address, can a LUA function check what writes to that very address and patch the asm function responsible for the "writing"?
This is basically a request to automate the "Find what writes to this address & Replace"

An example would be nice.

Thank you for the help.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Thu Feb 02, 2017 5:07 pm    Post subject: Reply with quote

You need to look at incorporating AOBscan. CE can build a script for you, but since it's an emulator, you may have to build out the AOB signature manually. That said, since it's being emulated, it may or may not work indefinitely.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4703

PostPosted: Thu Feb 02, 2017 5:32 pm    Post subject: Reply with quote

Yes, Lua can be used to set breakpoints on an address. Yes, Lua can be used to modify assembly. No, I do not believe this is a good solution to your problem.

Regardless, there is documentation in main.lua that will be helpful (i.e. debug_setBreakpoint, writeBytes, autoAssemble), and most Lua features have examples somewhere in CEF that can be found by using Google.

This is one way to do this:
Code:
local test = {0x89, 0x83, 0x80, 4, 0, 0}

debug_setBreakpoint(address, valueSize, bptWrite, function()
  -- EIP is after the instruction has executed
  -- if necessary, check to make sure this is the correct instruction
  for k,v in ipairs(readBytes(EIP-6, 6, true)) do
    if test[k] ~= v then return end
  end

  -- this replaces the 6-byte writing instruction w/ NOPs
  writeBytes(EIP-6, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90)

  debug_continueFromBreakpoint(co_run)
  return 0
end)

Another way would be to use autoAssemble to avoid having to write the bytes directly, but that shouldn't be too hard to figure out.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
ner0
Cheater
Reputation: 0

Joined: 10 Dec 2011
Posts: 32

PostPosted: Thu Feb 02, 2017 5:38 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Yes, Lua can be used to set breakpoints on an address. Yes, Lua can be used to modify assembly. No, I do not believe this is a good solution to your problem.

Regardless, there is documentation in main.lua that will be helpful (i.e. debug_setBreakpoint, writeBytes, autoAssemble), and most Lua features have examples somewhere in CEF that can be found by using Google.

This is one way to do this:
Code:
local test = {0x89, 0x83, 0x80, 4, 0, 0}

debug_setBreakpoint(address, valueSize, bptWrite, function()
  -- EIP is after the instruction has executed
  -- if necessary, check to make sure this is the correct instruction
  for k,v in ipairs(readBytes(EIP-6, 6, true)) do
    if test[k] ~= v then return end
  end

  -- this replaces the 6-byte writing instruction w/ NOPs
  writeBytes(EIP-6, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90)

  debug_continueFromBreakpoint(co_run)
  return 0
end)

Another way would be to use autoAssemble to avoid having to write the bytes directly, but that shouldn't be too hard to figure out.


I was literally about to post my "solution", which is roughly similar to what you posted there with breakpoints. But I'll look at your code closely later because I might be missing on some useful bits.

Anyway, what I did that worked (so far), was this:
Code:
breakOnAddress = 0x2C2F17CA

function debugger_onBreakpoint()
  patchThat = EIP-16
  patchThatHEX = string.format("%x", patchThat)
  print(patchThatHEX )
  debug_removeBreakpoint(breakOnAddress)
  writeBytes(patchThat, 0xE9, 0x40, 0x01, 0x00, 0x00, 0x90)
  writeFloat(breakOnAddress, 45.2)
  debug_continueFromBreakpoint(co_run)
  return 1
end

debug_setBreakpoint(breakOnAddress, 4, bptWrite)


Thanks again for the help.
I'll go with this approach for now, which I know is not nearly ideal... later I will try and learn a proper one. Smile
Back to top
View user's profile Send private message
SunBeam
I post too much
Reputation: 65

Joined: 25 Feb 2005
Posts: 4023
Location: Romania

PostPosted: Thu Feb 02, 2017 9:49 pm    Post subject: Reply with quote

Just to be clear on this: I was not suggesting to use LUA, was just giving an example of game engine where everything is intertwined and a huge-ass handler manages everything.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites