netmaestro wrote:
Correct the typo and it's still 0.
Unusual way to generate the code but true, but now it's at least the right 0
Maybe it's possible to get the address of the desired procedure and then move upwards along the code until you reach one of the possible opcodes for the RET instruction (and consider its optional parameter).
Then subtract the two addresses.
But since the same number can be found in other instructions or operands along the way, you may have to use a runtime disassembler, like the one coming with pb, or Bea Engine. Then you can get the "real" RET instruction.
The returned size would change between debug and release builds I imagine.
Just a quick try to show the idea, I've not verified if the results are right.
Code:
DisableDebugger
Procedure fun1()
a = a + 1
EndProcedure
Procedure.s fun2(a, b, c)
a$ = "hello"
For k = 1 To 10
a$ + Str(k)
Next
ProcedureReturn a$
EndProcedure
Procedure.i GetFunSize(*entry)
If ExamineAssembly(*entry)
While NextInstruction()
i$ = Trim(InstructionString())
*addr = InstructionAddress()
If Left(i$,3) = "ret"
NextInstruction()
*addr = InstructionAddress()
Break
EndIf
Wend
ProcedureReturn *addr - *entry
EndIf
ProcedureReturn 0
EndProcedure
MessageRequester("fun1()", Str(GetFunSize(@fun1())))
MessageRequester("fun2()", Str(GetFunSize(@fun2())))
This supposing the bundled disassembler works (I don't think it does it reliably enough and I would use another one).