Skip to content

How to encode branches while letting the encoder choose the branch type and width? #345

Answered by jonomango
jonomango asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone else in a similar situation, this is how I ended up resolving the issue:

// Try to re-encode a relative branch instruction with a new delta value.
// This new value is relative to the start of the instruction, rather
// than the end. The function returns false if it is unable to fit the
// new delta value in a relative instruction.
static bool reencode_relative_branch(
    ZydisDecodedInstruction const&   decoded_instruction,
    ZydisDecodedOperand const* const decoded_operands,
    std::int64_t               const delta,
    std::uint8_t*              const buffer,
    std::size_t&                     length) {
  // make sure we're dealing with a relative branch...
  assert(d…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@jonomango
Comment options

@ZehMatt
Comment options

Comment options

You must be logged in to vote
3 replies
@athre0z
Comment options

@flobernd
Comment options

@jonomango
Comment options

Answer selected by jonomango
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants