View previous topic :: View next topic |
Author |
Message |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sun Sep 16, 2007 11:06 am Post subject: [C/C++] Geting function size? (in bytes) |
|
|
Is it possible to get my function's size in byte?
Another question:
How can I convert an asm code to an array of bytes? I mean, something like CE's AA.. Is there any nice function that can do this?
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Sep 16, 2007 11:18 am Post subject: Re: [C/C++] Geting function size? (in bytes) |
|
|
assaf84 wrote: | Is it possible to get my function's size in byte?
Another question:
How can I convert an asm code to an array of bytes? I mean, something like CE's AA.. Is there any nice function that can do this? |
Can't say I know of a method of obtaining the function size, maybe some method using sizeof() or something, not sure.
As for converting to AoB, I usually use TSearch for that with its EasyWrite feature which is nice to have around. (I like EasyWrite more then CE's AA :/)
|
|
Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Sun Sep 16, 2007 11:37 am Post subject: |
|
|
I meant to this as a function inside my program..
And to get function size in "the hard way" I can put about 4 nops and then AOB search for them, get the address and then the size is this address minus the function address, but I'm pretty sure that there is an easier way..
|
|
Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Sun Sep 16, 2007 1:28 pm Post subject: |
|
|
You can always debug it to check.
_________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
Back to top |
|
 |
kittonkicker I post too much
Reputation: 1
Joined: 19 Apr 2006 Posts: 2171
|
Posted: Mon Sep 17, 2007 11:03 am Post subject: |
|
|
Last time I checked you can't use sizeof() on functions...
_________________
All gone  |
|
Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Sep 17, 2007 12:21 pm Post subject: |
|
|
A bit impractical way, but it works:
Code: | #include <iostream>
void functionStart();
void functionEnd();
int main(int argc, char* argv[])
{
std::cout << (int)::functionEnd-(int)::functionStart << std::endl;
return EXIT_SUCCESS;
}
__declspec(naked) void functionStart()
{
__asm
{
mov edi,edi // 2 bytes
nop // 1 byte
mov edi,edi // 2 bytes
ret // 1 byte
}
}
__declspec(naked) void functionEnd()
{
__asm
{
ret
}
} | Only works if you compile your file with /Od (in most cases!) :P When executing, it displays number 6 on the screen.
|
|
Back to top |
|
 |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
Posted: Mon Sep 17, 2007 12:33 pm Post subject: |
|
|
Ahhh beat me to the punch line, I was gunna say - if you know the order of your compiled functions - then they *should* be in order.
So the function is a point to it's actuall code - do the subtraction and you can figure out it's relative size.
_________________
0x7A 0x61 0x72 0x74
TEAM RESURRECTiON |
|
Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Mon Sep 17, 2007 12:57 pm Post subject: |
|
|
Nice...
By the way-
How do you compile C++ application with VC++ from command line?
|
|
Back to top |
|
 |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
Posted: Mon Sep 17, 2007 1:03 pm Post subject: |
|
|
_________________
0x7A 0x61 0x72 0x74
TEAM RESURRECTiON |
|
Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon Sep 17, 2007 1:05 pm Post subject: |
|
|
assaf84 wrote: | Nice...
By the way-
How do you compile C++ application with VC++ from command line? |
(for the purpose of illustration I will assume you are using visual studio 8 (2005))
1. open cmd
2. set appropriate path/library/include variables with
Code: |
call "%VS80COMNTOOLS%vsvars32.bat"
|
3. you can now call cl.exe to compile and link.exe to link. type <name> /? for options. cl will invoke the linker automatically if you do not tell it not to (you can tell it to compile only with /c)
|
|
Back to top |
|
 |
Uligor Grandmaster Cheater
Reputation: 0
Joined: 21 Jan 2006 Posts: 956
|
Posted: Mon Sep 17, 2007 3:23 pm Post subject: |
|
|
Make a dissasembler and analyzer.
_________________
|
|
Back to top |
|
 |
|