core/x86/mangle.c
/* For jecxz and loop*, we create 3 instructions in a single
 * instr that we treat like a single conditional branch.
 * On re-decoding our own output we need to recreate that instr.
 * This routine assumes that the instructions encoded at pc
 * are indeed a mangled cti short.
 * Assumes that the first instr has already been decoded into instr,
 * that pc points to the start of that instr.
 * Converts instr into a new 3-raw-byte-instr with a private copy of the
 * original raw bits.
 * Optionally modifies the target to "target" if "target" is non-null.
 * Returns the pc of the instruction after the remangled sequence.
 */
For jecxz and loop*, we create 3 instructions in a single
instr that we treat like a single conditional branch.
On re-decoding our own output we need to recreate that instr.
This routine assumes that the instructions encoded at pc
are indeed a mangled cti short.
Assumes that the first instr has already been decoded into instr,
that pc points to the start of that instr.
Converts instr into a new 3-raw-byte-instr with a private copy of the
original raw bits.
Optionally modifies the target to "target" if "target" is non-null.
Returns the pc of the instruction after the remangled sequence.
For jecxz and loop * we create 3 instructions in a single instr that we treat like a single conditional branch . On re - decoding our own output we need to recreate that instr . This routine assumes that the instructions encoded at pc are indeed a mangled cti short . Assumes that the first instr has already been decoded into instr that pc points to the start of that instr . Converts instr into a new 3 - raw - byte - instr with a private copy of the original raw bits . Optionally modifies the target to " target " if " target " is non - null . Returns the pc of the instruction after the remangled sequence .
byte *
remangle_short_rewrite(dcontext_t *dcontext,
                       instr_t *instr, byte *pc, app_pc target)
{
    ASSERT(instr_is_cti_short_rewrite(instr, pc));
    if (target == NULL) {
        int rel_target = *((int *)(pc+5));
        target = pc + CTI_SHORT_REWRITE_LENGTH + rel_target;
    }
    instr_set_target(instr, opnd_create_pc(target));
    instr_allocate_raw_bits(dcontext, instr, CTI_SHORT_REWRITE_LENGTH);
    instr_set_raw_bytes(instr, pc, CTI_SHORT_REWRITE_LENGTH);
    instr_set_raw_word(instr, 5, (int)(target - (pc + CTI_SHORT_REWRITE_LENGTH)));
    instr_set_operands_valid(instr, true);
    return (pc+CTI_SHORT_REWRITE_LENGTH);
}
byte * remangle_short_rewrite ( dcontext_t * dcontext , instr_t * instr , byte * pc , app_pc target ) { ASSERT ( instr_is_cti_short_rewrite ( instr , pc ) ) ; if ( target == NULL ) { int rel_target = * ( ( int * ) ( pc + 5 ) ) ; target = pc + CTI_SHORT_REWRITE_LENGTH + rel_target ; } instr_set_target ( instr , opnd_create_pc ( target ) ) ; instr_allocate_raw_bits ( dcontext , instr , CTI_SHORT_REWRITE_LENGTH ) ; instr_set_raw_bytes ( instr , pc , CTI_SHORT_REWRITE_LENGTH ) ; instr_set_raw_word ( instr , 5 , ( int ) ( target - ( pc + CTI_SHORT_REWRITE_LENGTH ) ) ) ; instr_set_operands_valid ( instr , true ) ; return ( pc + CTI_SHORT_REWRITE_LENGTH ) ; }
For jecxz and loop*, we create 3 instructions in a single
 instr that we treat like a single conditional branch.
For jecxz and loop * we create 3 instructions in a single instr that we treat like a single conditional branch .
/* first set the target in the actual operand src0 */ /* acquire existing absolute target */ /* now set up the bundle of raw instructions
     * we've already read the first 2-byte instruction, jecxz/loop*
     * they all take up CTI_SHORT_REWRITE_LENGTH bytes
     */ /* for x64 we may not reach, but we go ahead and try */ /* now make operands valid */