Dont really know if this should be posted here but i didnt really see a section for Masm32.

I got the following question, is it possible to get the size of a function (a PROC)
so u could do, for instance:
dd offset Func1                        ; now this DD points to Func1
dd size Func1                          ; this has to do, size of the Code inside Func1,

but the "size Func1" doesnt work, is there a simple way to do that?

Posted on 2006-05-12 02:54:56 by pyr0_mathic
it is not posible directly. function is not a data type. you may place 2 labels (at the begin and at the end) and get size subtracting them. there could be errors because of adding prolog and epylog to functions, defined with "proc/endp"
Posted on 2006-05-12 03:09:01 by Shoo
thx for the quick reply..

but adding a start and end label aint really an option.... its way to much work and to "dirty"

Posted on 2006-05-12 03:55:53 by pyr0_mathic
PyroMathic, Shoo is right, that's the only way how to get the size.

And there is no problem with prologue and epilogue - the subtraction would be always correct.
Posted on 2006-05-12 04:55:47 by MazeGen

And there is no problem with prologue and epilogue - the subtraction would be always correct.

So long as the end label is after the ENDP directive (assuming that you use the function name as the start pointer).

Posted on 2006-05-12 05:00:06 by Ossa
That's true i can put the label after endp and before proc, but then i need to put a lot of extra work into it, i need to do it to about 200 functions or so.....

but i think ill simply make an array of all the offset's of the Functions, and then take the 1 member out of that array and look which other member is the nearesed to that member. so then i also have the size...

like this:

pfunc1 dd offset func1
pfunc2 dd offset func2
pfunc3 dd offset func3

size of func1 == pfunc2 - pfunc1

something like that.

are there ways to enumerate all proc's in my program? (whitout building a program for it)
for example as external includes, or anything else like that..


Posted on 2006-05-12 07:09:57 by pyr0_mathic
I think if I were you I'd consider just using some word-processing macro, to get the job done. The other way round you'll probably spend more energy trying to think up a way to save energy :)

Something like

Search for "proc"
Insert label
Find the first following "endp"
Insert label

With a variable inserted, you could have it do it automatically for all procs.
Then do another variable, set up a script that makes the variables in the source.

Posted on 2006-05-12 08:11:28 by Fake51
pyr0, 'main' is just fine.

As for how to accomplish your task, there's more than a couple of ways to do it, and choosing the best one will depend on your needs. I guess we can all agree that manual labour is NOT fun.

Now, do you need the proc sizes at build-time or run-time?

If at run-time, it should be possible to very quickly hack together something that parses LINK's map output and generates a list of functions...
Posted on 2006-05-12 09:54:17 by f0dder
Maybe a custom prologue and epilogue ?
Posted on 2006-05-12 12:10:00 by Dr. Manhattan

Maybe a custom prologue and epilogue ?

hmm, interesting idea - if prologue/epilogue are full-blown macros in MASM, perhaps they could be (ab)used to generate the symbols he need.
Posted on 2006-05-12 12:10:54 by f0dder