Raised This Month: $51 Target: $400
 12% 

Questions about signature scanning


Post New Thread Reply   
 
Thread Tools Display Modes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-14-2009 , 18:06   Re: Questions about signature scanning
Reply With Quote #11

jim, I learnt inline assembly but I haven't solved yet completly my problem. I think now its more of a plain assembly problem.

Luckily, I reached this code to work:
PHP Code:
static cell AMX_NATIVE_CALL respawn(AMX *amxcell *params)
{
    
typedef void (*RoundRespawn)();
    
RoundRespawn roundRespawn = (RoundRespawnResolveSig((void *)MDLL_Spawn,"RoundRespawn__11CBasePlayer");

    
void *pPlayer = (void *) INDEXENT(params[1])->pvPrivateData;
    
void **pPlayerPointer = &pPlayer;    

    
printf(" ");

    
asm ("pop %%eax":::"%eax");
    
asm ("pushl %0"::"m"(pPlayerPointer));
    
asm ("call %0"::"m"(roundRespawn));

    return 
0;

But, not only it is stupid as also if I remove the printf or the pop it crashes the server instantly. I believe that the problem is with the stack (or the lack of handling it). If you can help me out fixing the code I'll be appreciated once again.
__________________

Last edited by joaquimandrade; 09-14-2009 at 18:40.
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-14-2009 , 20:46   Re: Questions about signature scanning
Reply With Quote #12

Code:
static cell AMX_NATIVE_CALL respawn(AMX *amx, cell *params)
{
    edict_t *pEdict = MF_GetPlayerEdict(params[1]);
    void *pthis = pEdict->pvPrivateData;
    void **vtbl = *(void ***)pthis;
    void *CBasePlayer_RoundRespawn = vtbl[86];
    pEdict->v.deadflag = DEAD_RESPAWNABLE;
    pEdict->v.flags |= FL_FROZEN;
    CBasePlayer *pPlayer = (CBasePlayer *)pEdict->pvPrivateData;
    typedef void (*RoundRespawn)(CBasePlayer *);
    RoundRespawn func = (RoundRespawn)CBasePlayer_RoundRespawn;
    func(pPlayer);
    return 0;
}
static cell AMX_NATIVE_CALL respawn(AMX *amx, cell *params)
{
    edict_t *pEdict = MF_GetPlayerEdict(params[1]);
    void *pthis = pEdict->pvPrivateData;
    void **vtbl = *(void ***)pthis;
    void *CBasePlayer_RoundRespawn = vtbl[86];
    pEdict->v.deadflag = DEAD_RESPAWNABLE;
    pEdict->v.flags |= FL_FROZEN;
    reinterpret_cast<void (*)(void*)>(CBasePlayer_RoundRespawn)(pthis);
    return 0;
}
first is csdm but use vfunc not signature way
second is ham
untested
vtbl index is linux 86 for roundrespawn
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-14-2009 , 22:46   Re: Questions about signature scanning
Reply With Quote #13

Quote:
Originally Posted by jim_yang View Post
Code:
static cell AMX_NATIVE_CALL respawn(AMX *amx, cell *params)
{
    edict_t *pEdict = MF_GetPlayerEdict(params[1]);
    void *pthis = pEdict->pvPrivateData;
    void **vtbl = *(void ***)pthis;
    void *CBasePlayer_RoundRespawn = vtbl[86];
    pEdict->v.deadflag = DEAD_RESPAWNABLE;
    pEdict->v.flags |= FL_FROZEN;
    CBasePlayer *pPlayer = (CBasePlayer *)pEdict->pvPrivateData;
    typedef void (*RoundRespawn)(CBasePlayer *);
    RoundRespawn func = (RoundRespawn)CBasePlayer_RoundRespawn;
    func(pPlayer);
    return 0;
}
static cell AMX_NATIVE_CALL respawn(AMX *amx, cell *params)
{
    edict_t *pEdict = MF_GetPlayerEdict(params[1]);
    void *pthis = pEdict->pvPrivateData;
    void **vtbl = *(void ***)pthis;
    void *CBasePlayer_RoundRespawn = vtbl[86];
    pEdict->v.deadflag = DEAD_RESPAWNABLE;
    pEdict->v.flags |= FL_FROZEN;
    reinterpret_cast<void (*)(void*)>(CBasePlayer_RoundRespawn)(pthis);
    return 0;
}
first is csdm but use vfunc not signature way
second is ham
untested
vtbl index is linux 86 for roundrespawn
No jim you didn't understand me. I can call it normally. I want to call it with inline assembly so I can pass it arguments via a for loop to make it dynamic.
__________________
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-14-2009 , 22:52   Re: Questions about signature scanning
Reply With Quote #14

oh, I see.
for member function call,
push "this" to ecx,
push param_n
push param_n-1
....
push param_1
call func

for __cdecl function call
push param_n
...
push param_1
call func
add esp, 4*params

__fastcall
mov edx, param_2
mov ecx, param_1
push param_n
...
push param_n-2
call

__stdcall
push n
...
push 1
call func

only __cdecl call you should cleanup the stack yourself
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-14-2009 , 23:03   Re: Questions about signature scanning
Reply With Quote #15

Quote:
Originally Posted by jim_yang View Post
oh, I see.
for member function call,
push "this" to ecx,
push param_n
push param_n-1
....
push param_1
call func

for __cdecl function call
push param_n
...
push param_1
call func
add esp, 4*params

__fastcall
mov edx, param_2
mov ecx, param_1
push param_n
...
push param_n-2
call

__stdcall
push n
...
push 1
call func

only __cdecl call you should cleanup the stack yourself
This part
Quote:
push "this" to ecx
i think it's only for MSVC and not for GCC. It says that in here (http://www.sourcemod.net/devlog/?p=57).

What I'm puzzled about is why in that code above with inline assembly i've posted I can't remove the printf and the pop from there.
__________________
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-14-2009 , 23:04   Re: Questions about signature scanning
Reply With Quote #16

I've read an article about linux member function call, but I've forgot if it pass the "this" pointer through ecx, seems only vc use that
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-14-2009 , 23:08   Re: Questions about signature scanning
Reply With Quote #17

Ok thanks
__________________
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-14-2009 , 23:24   Re: Questions about signature scanning
Reply With Quote #18

you can try this
void *pthis = ENTINDEX(params[1])->pvPrivateData;
push pthis;
call func;
add esp, 4;
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-14-2009 , 23:34   Re: Questions about signature scanning
Reply With Quote #19

Quote:
Originally Posted by jim_yang View Post
you can try this
void *pthis = ENTINDEX(params[1])->pvPrivateData;
push pthis;
call func;
add esp, 4;
I've tried

PHP Code:
asm ("pushl %0"::"m"(pPlayerPointer));
asm ("call %0"::"m"(roundRespawn));
asm ("addw 4, %esp"); 
and

PHP Code:
asm ("pushl %0"::"m"(pPlayerPointer));
asm ("call %0"::"m"(roundRespawn));
asm ("addl 4, %esp"); 
and both crash. Btw, addw stands for "add word" and addl stands for "add long". But if i'm correct registers are words so it should be addw. I'm gonna keep trying if you remember more things to try please let me know.

One question: do I have to clean the stack before executing this assembly code? Or just after?
__________________

Last edited by joaquimandrade; 09-14-2009 at 23:37.
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-14-2009 , 23:47   Re: Questions about signature scanning
Reply With Quote #20

after, you push a param stack -= 4, so you should add esp, 4 after call it

by the way
do you use void **pPlayerPointer, it should be void *pPlayerPointer = ent->pvPrivateDate;
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode