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

Questions about signature scanning


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-10-2009 , 10:22   Questions about signature scanning
Reply With Quote #1

I'm trying to learn assembly, c++ and signature scanning.

On cs_i386.so.objdump there is:

Code:
000e049c <StartDeathCam__11CBasePlayer>:
   e049c:    55                       push   %ebp
   e049d:    89 e5                    mov    %esp,%ebp
   e049f:    83 ec 2c                 sub    $0x2c,%esp
   e04a2:    57                       push   %edi
   e04a3:    56                       push   %esi
   e04a4:    53                       push   %ebx
By mixing code from http://www.sourcemod.net/devlog/?p=55 and jim yang's modules I have this code:

PHP Code:
void *FindSignature(unsigned char *pBaseAddresssize_t baseLengthunsigned char *pSignaturesize_t sigLength)
{
   
unsigned char *pBasePtr pBaseAddress;
   
unsigned char *pEndPtr pBaseAddress baseLength;

   
size_t i;

   while (
pBasePtr pEndPtr)
   {
      for (
i=0i<sigLengthi++)
      {
         if (
pSignature[i] != 0x2A && pSignature[i] != pBasePtr[i])
            break;
      }

      
//iff i reached the end, we know we have a match!
      
if (== sigLength+1)
      {
         return (
void *)pBasePtr;
      }

      
pBasePtr += sizeof (unsigned char *);  //search memory in an aligned manner
   
}
    
   return (
void *) NULL;
}

typedef void (*StartDeathCam)(CBasePlayer *);

static 
cell AMX_NATIVE_CALL startDeathCam(AMX *amxcell *params)
{
    
unsigned char signature[] = {0x55,0x89,0xE5,0x83,0xEC,0x2A,0x57,0x56,0x53};

    
MEMORY_BASIC_INFORMATION mem;
    
    if (!
VirtualQuery(MDLL_AddToFullPack, &memsizeof(mem)))
        return 
false;

    
unsigned char *pBaseAddr = (unsigned char *) mem.AllocationBase;

    
size_t memLength 0x100000;

    
StartDeathCam startDeathCam = (StartDeathCamFindSignature(pBaseAddr,memLength,signature,sizeof signature);

    
SERVER_PRINT("\n");

    if(
startDeathCam)
    {
        
SERVER_PRINT("Function deathcam found");

        
edict_t *pPlayer MF_GetPlayerEdict(1);

        
__asm
        
{
          
mov ecxpPlayer;
          
call startDeathCam;
          
ret;
        };
    }
    else
    {
        
SERVER_PRINT("Function deathcam not found");
    }

    
SERVER_PRINT("\n");

    return !!
startDeathCam;

I'm testing it in windows and the problem is that the function is not found.

I know and confirmed that in the address pointed to by pBaseAddr there is the content of mp.dll.

I'm assuming that mp.dll is the equivalent of cs_i386.so but since the function can't be found in memory I've tried using a hex editor to find a portion of the function above (55 89 e5 83) in mp.dll and it doesn't exist so, it is normal that the signature is not being found.

What am I doing wrong?

(I have memLength with a static value because I think it is enough and to make the code more simple)

Edit:

There was a little error on the code here http://www.sourcemod.net/devlog/?p=57

PHP Code:
(== sigLength+1
should be

PHP Code:
(== sigLength
Still, I haven't make it to work.
__________________

Last edited by joaquimandrade; 09-10-2009 at 18:57.
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-10-2009 , 19:43   Re: Questions about signature scanning
Reply With Quote #2

windows binary maybe different from linux, so you should find the sig in windows dll then sigscan it
__________________
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-10-2009 , 19:52   Re: Questions about signature scanning
Reply With Quote #3

Quote:
Originally Posted by jim_yang View Post
windows binary maybe different from linux, so you should find the sig in windows dll then sigscan it
Ok thanks I will try.

One question:

Why does, by opening mp.dll in IDA, it show only the name of a small amount of functions and when opening cs_i386.so it shows them all (I believe)?
__________________

Last edited by joaquimandrade; 09-10-2009 at 19:57.
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-10-2009 , 20:25   Re: Questions about signature scanning
Reply With Quote #4

that's the compiler trick, not all function names will keep in the executable files, such as inline function, or some functions will be optimized by compile. some situations will lead function name disappear in binary file. in windows, only rare export function names will keep. damn my poor english
__________________
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-10-2009 , 20:28   Re: Questions about signature scanning
Reply With Quote #5

Quote:
Originally Posted by jim_yang View Post
that's the compiler trick, not all function names will keep in the executable files, such as inline function, or some functions will be optimized by compile. some situations will lead function name disappear in binary file. in windows, only rare export function names will keep. damn my poor english
Ok. Thanks. It will be harder by looking at windows binary but I will try. And your text is clearly understandable.

Edit:

Sorry, one more question. If I want to execute a function like

PHP Code:
typedef void (*x)(CGrenade *); 
it will be possible? I'm asking because CGrenade is not present to the compiler when I tried to use it.
__________________

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

I don't think it will compile succeed since CGrenade is not declare. Just use inline asm
push parameter
call func
also care about the calling conventions
or just use void *
__________________
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-10-2009 , 20:45   Re: Questions about signature scanning
Reply With Quote #7

Quote:
Originally Posted by jim_yang View Post
I don't think it will compile succeed since CGrenade is not declare. Just use inline asm
push parameter
call func
also care about the calling conventions
or just use void *
Yes it won't compile. Ok I will leave that for the future. I will be happy for now to execute functions from CBasePlayer and CBasePlayerItem. Thanks for everything.
__________________
joaquimandrade is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-12-2009 , 21:34   Re: Questions about signature scanning
Reply With Quote #8

Jim, yes the problem was that you have to extract the signature from the own binary (the compiled code is totally different). I moved to linux and called successfully functions. Now I have a new help request. If you can tell me before I figure out I'll be appreciated.

What is the ported code to linux (gcc) of:

PHP Code:
__asm
   
{
      
mov ecxpPlayer;
      
push name;
      
push iSubType;
      
call g_GiveItemFunc;
      
mov pReturnEnteax;
   }; 
I mean, in assembly. I need it that way. I read some articles that show "inline assembly in gcc" and tried to do it and it did compile but the module then doesn't even load.

Edit:

And about that CGrenade* question, it worked with void*.
CGrenade:: Detonate3 against some default grenades:

http://www.youtube.com/watch?v=3adt2qmZ4uc
__________________

Last edited by joaquimandrade; 09-13-2009 at 01:15.
joaquimandrade is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 09-13-2009 , 02:33   Re: Questions about signature scanning
Reply With Quote #9

I'm not good at gcc inline asm too, it use AT&T asm format and some input output format which I think is trouble although it's useful and powerful
here are two articles, good luck
http://www.ibiblio.org/gferg/ldp/GCC...bly-HOWTO.html
http://groups.google.com/group/muc.l...8860dd41ddd42b

Edit:
or you can look at the source code of ham, use reinterpret_cast to cast the function pointer to your expected format
__________________
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>

Last edited by jim_yang; 09-13-2009 at 02:42.
jim_yang is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 09-13-2009 , 08:50   Re: Questions about signature scanning
Reply With Quote #10

What I want to do is:

instead of calling something like void (*func)(CBasePlayer *,CBasePlayerWeapon *),

having void(*func)() and having an array of void* pointers, iterate over it and push each one of them via

PHP Code:
__asm
{
    
push x



and then do

PHP Code:
__asm
{
    
call func




__________________
joaquimandrade 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 03:14.


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