Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 15, 2012 How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
How do get the address of a function in naked assembly code? void foo() { asm { naked; mov EAX, &foo; } } This doesn't work... |
May 15, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad Attachments:
| I think I had that one before. Try this one: void foo() { void* foopt = cast(void*)&foo; asm { naked; mov EAX fooptr; } } On Tue, May 15, 2012 at 11:33 PM, Mehrdad <wfunction@hotmail.com> wrote: > How do get the address of a function in naked assembly code? > > void foo() > { > asm > { > naked; > mov EAX, &foo; > } > } > > This doesn't work... > -- Bye, Gor Gyolchanyan. |
May 15, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gor Gyolchanyan | On 15-05-2012 22:51, Gor Gyolchanyan wrote: > I think I had that one before. Try this one: > void foo() > { > void* foopt = cast(void*)&foo; > asm > { > naked; > mov EAX fooptr; > } > } > > On Tue, May 15, 2012 at 11:33 PM, Mehrdad <wfunction@hotmail.com > <mailto:wfunction@hotmail.com>> wrote: > > How do get the address of a function in naked assembly code? > > void foo() > { > asm > { > naked; > mov EAX, &foo; > } > } > > This doesn't work... > > > > > -- > Bye, > Gor Gyolchanyan. That's not naked inline asm, though. Something like this might work: void foo() { asm { naked; mox EAX, dword ptr foo; /* whatever... */ } } -- Alex Rønne Petersen alex@lycus.org http://lycus.org |
May 15, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | Le 15/05/2012 21:33, Mehrdad a écrit :
> How do get the address of a function in naked assembly code?
>
> void foo()
> {
> asm
> {
> naked;
> mov EAX, &foo;
> }
> }
>
> This doesn't work...
As it is naked,
mov EAX, EIP;
is enough.
|
May 15, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | Le 15/05/2012 23:27, deadalnix a écrit :
>
> mov EAX, EIP;
>
> is enough.
I think this is illegal in assembly, try to call a label in your function then pop.
void* selfAddress() // actually tested
{
asm
{
naked;
call my_label;
my_label:
pop EAX;
sub EAX, 5;
ret;
}
}
|
May 15, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 15-05-2012 23:27, deadalnix wrote: > Le 15/05/2012 21:33, Mehrdad a écrit : >> How do get the address of a function in naked assembly code? >> >> void foo() >> { >> asm >> { >> naked; >> mov EAX, &foo; >> } >> } >> >> This doesn't work... > > As it is naked, > > mov EAX, EIP; > > is enough. I suspect he wanted a solution where he could load an arbitrary function's address. -- Alex Rønne Petersen alex@lycus.org http://lycus.org |
May 15, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | Le 15/05/2012 23:58, Alex Rønne Petersen a écrit :
>
> I suspect he wanted a solution where he could load an arbitrary
> function's address.
>
I'm also searching for a way to get a label address from inline assembly.
This would be useful for hard-coded jumptables.
|
May 16, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | On Tuesday, 15 May 2012 at 21:58:56 UTC, Alex Rønne Petersen wrote:
> On 15-05-2012 23:27, deadalnix wrote:
>> Le 15/05/2012 21:33, Mehrdad a écrit :
>>> How do get the address of a function in naked assembly code?
>>>
>>> void foo()
>>> {
>>> asm
>>> {
>>> naked;
>>> mov EAX, &foo;
>>> }
>>> }
>>>
>>> This doesn't work...
>>
>> As it is naked,
>>
>> mov EAX, EIP;
>>
>> is enough.
>
> I suspect he wanted a solution where he could load an arbitrary function's address.
indeed
|
May 16, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | On 5/15/2012 12:33 PM, Mehrdad wrote:
> How do get the address of a function in naked assembly code?
>
> void foo()
> {
> asm
> {
> naked;
> mov EAX, &foo;
> }
> }
>
> This doesn't work...
I know, but also be aware that even if it did work, it would not work in the presence of PIC code and shared libraries. It's best if you stick to using D code to get the address of a function, which accounts for all these variations and wierdness.
|
May 16, 2012 Re: How to mov EAX, &func? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Wednesday, 16 May 2012 at 07:05:10 UTC, Walter Bright wrote:
> On 5/15/2012 12:33 PM, Mehrdad wrote:
>> How do get the address of a function in naked assembly code?
>>
>> void foo()
>> {
>> asm
>> {
>> naked;
>> mov EAX, &foo;
>> }
>> }
>>
>> This doesn't work...
>
> I know, but also be aware that even if it did work, it would not work in the presence of PIC code and shared libraries. It's best if you stick to using D code to get the address of a function, which accounts for all these variations and wierdness.
Yeah I know, but currently shared libraries are the least of my worries.
The trouble with 'sticking to D code' is that, well, I can't... it's naked...
|
Copyright © 1999-2021 by the D Language Foundation