Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C/C++] Geting function size? (in bytes)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
assaf84
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 238

PostPosted: Sun Sep 16, 2007 11:06 am    Post subject: [C/C++] Geting function size? (in bytes) Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Sep 16, 2007 11:18 am    Post subject: Re: [C/C++] Geting function size? (in bytes) Reply with quote

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
View user's profile Send private message Visit poster's website
assaf84
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 238

PostPosted: Sun Sep 16, 2007 11:37 am    Post subject: Reply with quote

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
View user's profile Send private message
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Sun Sep 16, 2007 1:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Mon Sep 17, 2007 11:03 am    Post subject: Reply with quote

Last time I checked you can't use sizeof() on functions...
_________________
All gone Sad
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Sep 17, 2007 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Mon Sep 17, 2007 12:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
assaf84
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 238

PostPosted: Mon Sep 17, 2007 12:57 pm    Post subject: Reply with quote

Nice...

By the way-
How do you compile C++ application with VC++ from command line?
Back to top
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Mon Sep 17, 2007 1:03 pm    Post subject: Reply with quote


_________________
0x7A 0x61 0x72 0x74

TEAM RESURRECTiON
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Mon Sep 17, 2007 1:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
Uligor
Grandmaster Cheater
Reputation: 0

Joined: 21 Jan 2006
Posts: 956

PostPosted: Mon Sep 17, 2007 3:23 pm    Post subject: Reply with quote

Make a dissasembler and analyzer.
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites