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 


Auto Assembly Template for Calling Functions?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Thu Feb 03, 2022 12:50 am    Post subject: Auto Assembly Template for Calling Functions? Reply with quote

Maybe this is a stupid question.

How difficult would it be to create an auto assembly template that uses the current breakpoint data that would allow the user to automatically create a script that calls that particular function, with the correct calling convention requirements and all of the necessary parameters, that will continue to work with future sessions?

Would this be possible, or is this something that has to be manually done?

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

Joined: 06 Jul 2014
Posts: 4652

PostPosted: Thu Feb 03, 2022 3:07 am    Post subject: This post has 1 review(s) Reply with quote

Practically impossible.

The biggest problem is automatically detecting the calling convention. Even detecting common conventions would be mildly difficult, esoteric conventions next to impossible (e.g. no general way to give any order to parameters).

You can make templates for common conventions, but that would assume the user knows what they're doing. This would make the template pretty much useless since someone who could identify a calling convention themselves should surely be able to write the few lines of assembly faster and more accurately than using a template.

And even if you did get something working, there's no way to give meaningful semantics to the parameters. You might be able to tell if a parameter is an integer, a pointer, etc., but what does it do? Only the user of the template could figure that out.
Also, impure functions (something that accesses mutable global state) might not work regardless of how well you make the template.

_________________
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
predprey
Master Cheater
Reputation: 24

Joined: 08 Oct 2015
Posts: 486

PostPosted: Thu Feb 03, 2022 4:10 am    Post subject: This post has 1 review(s) Reply with quote

Maybe you could elaborate more on the use case? I would think it would depend on where your breakpoint is. If the breakpoint is on a call to the function that you want to call with your script, you could probably parse the few instructions before the call to detect the common conventions and have the template extract out the lines involved with parameter passing.

But if what you want is to generate the template from anywhere within the function code itself and detect which registers it uses and which of these had their values passed in, that would probably be harder.

Then as ParkourPenguin said, there is still the semantics, so the template would only detect which registers are used for passing values and where these values are to be taken from, but you have to rename or comment on what these values are, similar to decompilation.
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 03, 2022 5:42 am    Post subject: Reply with quote

Thank you, everyone, for responding. I really appreciate it.

I suppose that it may not be overly practical, now thinking about it. Maybe something basic might be worth considering, just to save time.

predprey wrote:
Maybe you could elaborate more on the use case? I would think it would depend on where your breakpoint is. If the breakpoint is on a call to the function that you want to call with your script, you could probably parse the few instructions before the call to detect the common conventions and have the template extract out the lines involved with parameter passing.
-Yes, something like that, with the breakpoint on the call, where CE could analyze the code before the call and make a best-guess attempt. Maybe CE could also auto-step into the call and analyze some of the code there. For that matter, the entire subroutine could run until return.

It's mostly over my head, anyway. I have no programming background, so I was curious about possibilities.

I see that IDA can make a best-guess attempt at identifying calling convention and arguments, so I was curious.

Thanks, everyone.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 204

Joined: 25 Jan 2006
Posts: 8579
Location: 127.0.0.1

PostPosted: Fri Feb 04, 2022 4:02 am    Post subject: This post has 1 review(s) Reply with quote

Along with what ParkourPenguin mentioned, each compiler has varying levels of optimizing that can be performed which will alter how the assembly is generated for everything. There are a lot of edge cases where those optimizations can lead to handling params 'automatically' in an invalid manner.

For example, some compilers may push things onto the stack between the actual call they are for, and for minor-sub calls. So unless you design something to analyze all paths in the flow of what is being checked, there isn't really a clean way to pull the actual argument list.

Another issue-case would be functions that take VARARGS. It'd be basically impossible to tell what is/isn't a parameter automatically.

++METHOS wrote:

I see that IDA can make a best-guess attempt at identifying calling convention and arguments, so I was curious.


Keep in mind that it is just a best-guess. IDA gets things wrong a lot. Especially calling conventions which in turn breaks guessed arguments and stack sizes.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Fri Feb 04, 2022 4:42 am    Post subject: Reply with quote

Thanks, atom0s.

Getting back into things, and it is frustrating not knowing more about some things, so I think I will start expanding on what I know. Probably going to start with C++.

Thanks, everyone.
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