P
Paul
Is there any way to find function size in C ?
Regards,
Galoma B
Regards,
Galoma B
Is there any way to find function size in C ?
Regards,
Galoma B
Is there any way to find function size in C ?
Keith Thompson said:Not portably.
Paul said:Thanks for your reply. But I see some one doing that, check out
http://help.madshi.net/CopyFunction.htm. I was wondering how he must
have done that and can we do the same in C. May be its less to do with
language and more to do with OS.
Tricks like this won't help.
void foo()
{
//do something
}
void dummy()
{
//do nothing
}
main()
{
int sizeoffoo = (int)((long)dummy - (long)foo);
}
any rescue???
Regards,
Galoma B.
Thanks for your reply. But I see some one doing that, check out
http://help.madshi.net/CopyFunction.htm. I was wondering how he must
have done that and can we do the same in C.
May be its less to do with
language and more to do with OS.
Tricks like this won't help.
void foo()
{
//do something
}
void dummy()
{
//do nothing
}
main()
{
int sizeoffoo = (int)((long)dummy - (long)foo);
}
any rescue???
Paul said:Keith Thompson <[email protected]> wrote in message
Thanks for your reply. But I see some one doing that, check out
http://help.madshi.net/CopyFunction.htm. I was wondering how he must
have done that and can we do the same in C. May be its less to do with
language and more to do with OS.
Tricks like this won't help.
void foo()
{
//do something
}
void dummy()
{
//do nothing
}
main()
{
int sizeoffoo = (int)((long)dummy - (long)foo);
}
any rescue???
Regards,
Galoma B.
Dag Viken said:While it is not portable, I got the above code to work with VC7 as long as
incremental linking was disabled. I suspect function level linking must also
be disabled (not tested). Further, in release mode, if foo() and dummy() are
both empty they will be optimized to a single RET instruction at the same
address - so the size of foo will come out as zero.
The web page you refer to is obviously for Win32 platforms. However, if you
want to copy a function and execute it you need more information than just
the function address and size. Function calls and references to global
variables must be relocated since relative addressing is used almost
exclusively. When a program or DLL is loaded into memory, the OS relocates
addresses based on the relocation tables inside the Portable Executable
(PE). When copying a function you will need to do the same thing, i.e. read
the relocation info and update the relative addresses. It is not too
difficult but you will need to study the PE format and understand how it
works.
Dag
Jack said:In C types and objects, and only types and objects, have size. A
function is neither of these.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.