-
December 4th, 2012, 09:29 AM
#1
issue with asm intel syntax
Hi;
My code below give me two warnings when compile with gcc, also it has no effect during execution. Warnings are :
- warning: 'naked' attribute directive ignored [-Wattributes]
- warning: no return statement in function returning non-void [-Wreturn-type]
Code:
void __declspec(naked) *ker_adr()
{
asm("mov eax, fs:[0x30]\n");
asm("mov eax, [eax+0x0c]\n");
asm("mov eax, [eax+0x1c]\n");
asm("mov eax, [eax]\n");
asm("mov eax, [eax+0x08]\n");
asm("ret\n");
}
Regards
-
December 4th, 2012, 10:30 AM
#2
Re: issue with asm intel syntax
1) __declspec(naked) is a directiv for the VS compiler. it tells the compiler to generate a function entrypoint but NOT provide it with the normal entry/exit code (setting up a stack frame, saving registers, cleaning up the stack frame and doign a return.
if your target compiler doesn't understand this, then it is very much possible that things will not quite work right. And it might not be immediately obvious from running the code that it doesn't work right.
gcc seems to not know the directive. assuming... this code wasn't designed for Gcc (inline assembly tends to not mix well on compilers other than what it was designed for).
2) gcc seems to expect an explicit C/C++ "return" clause. the asm code doesn't make a need (or non-need) for this obvious to the compiler hence the warning.
It looks alright, return is in eax, and eax is set to "something" whether it's correct is another matter
This may or may not work when compiling on another compiler than VS. The fact you're accessing explicit addresses relative to FS mean all bets are off.
-
December 4th, 2012, 02:44 PM
#3
Re: issue with asm intel syntax
I changed my code a little bite. I want to capture the value into res and return this value using return.
Code:
void *kernel_addr()
{
HMODULE res=0;
asm(".intel_syntax noprefix\n");
asm("mov eax, fs:[0x30]\n");
asm("mov eax, [eax+0x0c]\n");
asm("mov eax, [eax+0x1c]\n");
asm("mov eax, [eax]\n");
asm("mov eax, [eax+0x08]\n");
asm("mov %0, eax\n");
asm(".att_syntax noprefix\n"
: "=r"(res)
);
return res;
}
But this time i get two errors :
- Error: bad expression
- Error: junk `0' after expression
Any help is appreciated.
-
December 10th, 2012, 11:22 AM
#4
Re: issue with asm intel syntax
well, for one, your method declaration expects a void * to be returned and you are returning and HMODULE.
-
December 12th, 2012, 08:30 AM
#5
Re: issue with asm intel syntax
in vs this would work:
void *kernel_addr()
{
void* res=0;
__asm{
mov eax, fs:[0x30];
mov eax, [eax+0x0c];
mov eax, [eax+0x1c];
mov eax, [eax];
mov eax, [eax+0x08];
mov res,eax;
}
return res;
}
only on x86 system, ofcourse.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|