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 


How to make Naked Functions in GCC (explained)

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

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Aug 25, 2008 12:52 pm    Post subject: How to make Naked Functions in GCC (explained) Reply with quote

GCC has a somewhat arbitrary restriction of not allowing declspec(naked) (or rather, __attribute__((naked)) ) on any processors except ARM, AVR, C4x and IP2K. This is a pain in the ass. However, it is possible to circumvent.

Demo:
Code:
#include <stdlib.h>
#include <stdio.h>

int foobar(void);

int main()
{
   printf("%i",foobar());
   return 0;
}

__asm(
   ".intel_syntax\r\n"
   "_foobar:\r\n"
   "mov eax,5\r\n"
   "ret\r\n"
   ".att_syntax\r\n"
   );


The way this works: int foobar declares the function prototype, without defining the function. Since the function is never defined in C, the buck gets passed to the linker to find foobar (mingw appends an underscore to the symbol name). The asm block gets passed, along with the asm generated by gcc, to the assembler, which makes _foobar into a symbol which the linker then finds.

Another note: .intel_syntax allows you to use intel asm syntax with GCC. At the end of your block you must use .att_syntax again or the assembler will try to interpret GCC's att asm as intel asm.

~nog_lorp
Credits to GynvaelColdwind of OpenRCE for his advice.

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming 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