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 


Overwriting a function?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
mitch92
How do I cheat?
Reputation: 0

Joined: 07 Dec 2016
Posts: 2

PostPosted: Sat Dec 10, 2016 11:48 pm    Post subject: Overwriting a function? Reply with quote

Hi! I am really noob about all these hacking stuffs. There is a program I wanna try to hack. The program uses a dll library to execute one of the function and I am hoping to "overwrite" the function with my own. I cannot just create another dummy dll with my own function to overwrite his because the program detects if the dll file is modified in any way before loading it.

The function I want to replace takes in a string parameter and then outputs a string as the result. I want to modify the string output with mine.


I tried creating my own function in a dll, inject the dll, overwrite the first line of the subroutine of the original function with a call to the "fake function". And second line of the original subroutine to the a ret to prevent loading the original function at all. However, it does not work.
Back to top
View user's profile Send private message
ulysse31
Master Cheater
Reputation: 2

Joined: 19 Mar 2015
Posts: 324
Location: Paris

PostPosted: Sun Dec 11, 2016 4:22 am    Post subject: Reply with quote

The string is an HWID ?
Have you tried loading the dll in ollydbg, hooking the function which your program calls and hook it to a memory page with space already present in your dll, write your stuff here, then return the code to the usual execution flow, save modified DLL.
That's how i proceded, i'd be very surprised if that didn't work.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Dec 11, 2016 8:25 pm    Post subject: Reply with quote

There are a few methods you could use to get around this.

1. Determine how the parent application detects changes to the DLL and bypass that. Would be the easier method if the detection is weak and easily bypassed.

2. Inject a new DLL and hook the original DLLs functions. You can do this a number of ways to ensure that your hook is working and being handled properly.

If you have issues hooking at the right time, simply hook the parent application instead. Either find and hook where the DLLs function is called, or hook LoadLibrary and monitor for when the DLL is loaded. When it is being loaded, allow it to load normally, then load and run your own code as needed after it loads the original DLL.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
mitch92
How do I cheat?
Reputation: 0

Joined: 07 Dec 2016
Posts: 2

PostPosted: Wed Dec 14, 2016 6:12 am    Post subject: Reply with quote

Hi! Thanks for the reply! Sorry I am still not getting it, currently what I did is

I coded my own dll with a function that passes in a String and returns another String that I wanted.

I then inject the dll to the process and intercept the calls to the original function like this in auto assemble.

Code:

OrginalDll.OrginalFunc:
call MyOwnDll.MyOwnFunc
ret


Is this hooking already? And nope it is not HWID string.

I tried doing this but I THINK(not for sure), I cannot seem to get it to pass in the string parameter into my function.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 960

PostPosted: Wed Dec 14, 2016 7:38 am    Post subject: Reply with quote

"The function I want to replace takes in a string parameter and then outputs a string as the result. I want to modify the string output with mine. "

"replace" or hijack(?) the output?

In hijack case
Code:

(input parameters)=> original function => eax/rax of out string
your function: modify the content of eax/rax point to


May be this in CE AA if not misunderstood:
(64bit case will be more complex, this is 32bit)
Code:

OrginalDll.OrginalFunc:
jmp  YourCave             // this will be 5+some or zero bytes
nop....                      // to be copy by readmem
returnHere:
...

YourCave:
xchg  ebp,[esp]
xchg  ebp,[esp+0c]
xchg  ebp,[esp+08]   // this depend on how many parameters in stack.
xchg  ebp,[esp+04]   // this is in case of 3 input parameter on stack
xchg  ebp,[esp]
push  @f
  readmem(OrginalDll.OrginalFunc,5+??)
  jmp  returnHere
@@:
xchg  ebp,[esp]         // not need in callee clean up
xchg  ebp,[esp+04]
xchg  ebp,[esp+08]
xchg  ebp,[esp+0c]   // restore stack in caller clean up
xchg  ebp,[esp]

push  eax // input parameter is output of original function???
call MyOwnDll.MyOwnFunc

ret


basically manipulate the stack before enter the original function so that it will jump to your function after original function return.
Should not work for recursive function. (or that has closure capture?)

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 14, 2016 6:08 pm    Post subject: Reply with quote

mitch92 wrote:
Hi! Thanks for the reply! Sorry I am still not getting it, currently what I did is

I coded my own dll with a function that passes in a String and returns another String that I wanted.

I then inject the dll to the process and intercept the calls to the original function like this in auto assemble.

Code:

OrginalDll.OrginalFunc:
call MyOwnDll.MyOwnFunc
ret


Is this hooking already? And nope it is not HWID string.

I tried doing this but I THINK(not for sure), I cannot seem to get it to pass in the string parameter into my function.


In a way yes but it's not the best way to go about things. Something you need to keep in mind is when you force another function to call soemthing else, you are accountable for ensuring the stack is properly aligned and things are being returned properly to prevent over/underflows or misalignments.

Rather than use Cheat Engine to place a call/jump, just do it all in your personal DLL. There are many freely available hooking libraries out there to help with this exact purpose. You can use something well known such as Detours from Microsoft or an open source library called minhook, or use any of the hundreds of other iterations of basically the same code.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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