How to map machine instctions in memory and execute them? (Aka, how to create a loader)
rempas
rempas at tutanota.com
Mon Jun 6 18:14:42 UTC 2022
On Monday, 6 June 2022 at 18:05:23 UTC, Johan wrote:
> This instruction is wrong. Note that you are writing twice to
> RDX, but also that you are using `mov sign_extend imm32, reg64`
> instead of `mov imm64, reg64` (`0x48 0xBA`?). Third, why append
> an extra zero (`*cast(char*)(code + 32) = 0x00;`)? That must be
> a bug too.
>
> cheers,
> Johan
Thanks! It seems that there is probably a "typo" from the
original [source](https://github.com/vishen/go-x64-executable)
that I got the code. The hex values are different however so
there is only a mistake in the comment, the code normally works
in the example repository (and I made a D version that works
too). The padding in the end seems to be necessary else the
example doesn't compile (I don't know why, I'm SUPER n00b when it
comes to machine language, I don't know almost anything!). I'm
also not sure how the "encode" will be for `mov imm64, reg64` as
I tried to type what you typed in the parenthesis and it doesn't
seem to work.
More information about the Digitalmars-d-learn
mailing list