How to get the body of a function/asm statement in hexadecimal

max haughton maxhaton at gmail.com
Sun Jan 29 22:19:46 UTC 2023


On Sunday, 29 January 2023 at 21:45:11 UTC, Ruby the Roobster 
wrote:
> I'm trying to do something like
>
> ```d
> void main()
> {
>     auto d = &c;
>     *d.writeln;
> }
>
> void c()
> {
> }
> ```
>
> In an attempt to get the hexadecimal representation of the 
> machine code of a function.  Of course, function pointers 
> cannot be dereferenced.  What do?
>
> Furthermore, I would like to be able to do the same for an 
> `asm` statement.

The function pointer can be casted to a pointer type. It is worth 
saying, however, that it is not trivial to find where the *end* 
of a function is. In X86 it's not even trivial to find the end of 
an instruction!

If you'd just like the bytes for inspection, you could use a tool 
like objdump. For more complicated situations you will need to 
use a hack to tell you where the end of a function is.


More information about the Digitalmars-d-learn mailing list