Getting The Size of a C++ Function

后端 未结 16 2138
醉酒成梦
醉酒成梦 2020-12-06 09:37

I was reading this question because I\'m trying to find the size of a function in a C++ program, It is hinted at that there may be a way that is platform specific. My target

16条回答
  •  春和景丽
    2020-12-06 10:02

    No, this will not work:

    1. There is no guarantee that your function only contains a single ret instruction.
    2. Even if it only does contain a single ret, you can't just look at the individual bytes - because the corresponding value could appear as simply a value, rather than an instruction.

    The first problem can possibly be worked around if you restrict your coding style to, say, only have a single point of return in your function, but the other basically requires a disassembler so you can tell the individual instructions apart.

提交回复
热议问题