ZydisEncoderEncodeInstructionAbsolute correctly predicts instruction sizes but if no relevant hint is provided it does nothing to enforce predicted instruction size. Usually this isn't an issue as size of immediate is enough to enforce correct variant. This however isn't sufficient for some edge cases where change of instruction size causes relative operand to fit into a smaller variant.
Example:jz instruction is meant to be placed at 0x4000 and is supposed to jump to 0x4082. 2-byte instruction (opcode + 8 bits of relative operand) can reach up to 0x4000+2+0x7F=0x4081, so encoder predicts 6 bytes for jump instruction. Relative operand gets adjusted to 0x4082-(0x4000+6)=0x7C but 0x7C <= 0x7F, so encoder will encode 2-byte instruction without a proper hint, therefore resulting instruction doesn't jump where it should.
ZydisEncoderEncodeInstructionAbsolute
correctly predicts instruction sizes but if no relevant hint is provided it does nothing to enforce predicted instruction size. Usually this isn't an issue as size of immediate is enough to enforce correct variant. This however isn't sufficient for some edge cases where change of instruction size causes relative operand to fit into a smaller variant.Example:
jz
instruction is meant to be placed at0x4000
and is supposed to jump to0x4082
. 2-byte instruction (opcode + 8 bits of relative operand) can reach up to0x4000+2+0x7F=0x4081
, so encoder predicts 6 bytes for jump instruction. Relative operand gets adjusted to0x4082-(0x4000+6)=0x7C
but0x7C <= 0x7F
, so encoder will encode 2-byte instruction without a proper hint, therefore resulting instruction doesn't jump where it should.