zyantific / zydis

Fast and lightweight x86/x86-64 disassembler and code generation library
https://zydis.re
MIT License
3.4k stars 434 forks source link

ZydisEncoderRequest and ZydisOperandEncoding #509

Closed odzhan closed 3 months ago

odzhan commented 3 months ago

This is just one example because it can happen with other instructions.

The decoder will work fine with the following MOV r32, r/m32 mnemonic. 8BC3 mov eax,ebx

But using an encoding request will generate the following MOV r/m32, r32 instead. 89D8 mov eax,ebx

The encoded instructions continue to work fine but I'd rather keep the original operand encoding if possible. Is there a way to keep the original with existing code base or is an update needed?

thank you

mappzor commented 3 months ago

The encoded instructions continue to work fine but I'd rather keep the original operand encoding if possible.

Not possible. Encoder's API is semantic-driven, so encoder request describes semantics of an instruction and encoder will fulfil that request if possible. That's the contract. By design there's no control over details of physical encoding, so if there are multiple encodings that result in instruction of the same size encoder is free to choose which one to use.

odzhan commented 3 months ago

Okay. That's too bad. Would be nice to have support for controlling the operand encoding. Thanks for response.

flobernd commented 3 months ago

@odzhan Out of interest: What would be the use-case that requires a specific encoding to be emitted?