core/x86/instr.c
/* Checks whether instr is a jecxz/loop* that was originally an app instruction.
 * All such app instructions are mangled into a jecxz/loop*,jmp_short,jmp sequence.
 * If pc != NULL, pc is expected to point the the beginning of the encoding of
 * instr, and the following instructions are assumed to be encoded in sequence
 * after instr.
 * Otherwise, the encoding is expected to be found in instr's allocated bits.
 * This routine does NOT decode instr to the opcode level.
 */
Checks whether instr is a jecxz/loop* that was originally an app instruction.
All such app instructions are mangled into a jecxz/loop*,jmp_short,jmp sequence.
If pc != NULL, pc is expected to point the the beginning of the encoding of
instr, and the following instructions are assumed to be encoded in sequence
after instr.
Otherwise, the encoding is expected to be found in instr's allocated bits.
This routine does NOT decode instr to the opcode level.
Checks whether instr is a jecxz / loop * that was originally an app instruction . All such app instructions are mangled into a jecxz / loop * jmp_short jmp sequence . If pc ! = NULL pc is expected to point the the beginning of the encoding of instr and the following instructions are assumed to be encoded in sequence after instr . Otherwise the encoding is expected to be found in instr ' s allocated bits . This routine does NOT decode instr to the opcode level .
bool
instr_is_cti_short_rewrite(instr_t *instr, byte *pc)
{
    if (pc == NULL) {
        if (!instr_has_allocated_bits(instr))
            return false;
        pc = instr_get_raw_bits(instr);
        if (*pc == ADDR_PREFIX_OPCODE) {
            pc++;
            if (instr->length != CTI_SHORT_REWRITE_LENGTH + 1)
                return false;
        } else if (instr->length != CTI_SHORT_REWRITE_LENGTH)
            return false;
    }
    if (instr_opcode_valid(instr)) {
        int opc = instr_get_opcode(instr);
        if (opc < OP_loopne || opc > OP_jecxz)
            return false;
    }
    else {
        int raw_opc = (int) *(pc);
        if (raw_opc < RAW_OPCODE_loop_start || raw_opc > RAW_OPCODE_loop_end)
            return false;
    }
    if (*(pc+2) != decode_first_opcode_byte(OP_jmp_short))
        return false;
    if (*(pc+4) != decode_first_opcode_byte(OP_jmp))
        return false;
    return true;
}
bool instr_is_cti_short_rewrite ( instr_t * instr , byte * pc ) { if ( pc == NULL ) { if ( ! instr_has_allocated_bits ( instr ) ) return false ; pc = instr_get_raw_bits ( instr ) ; if ( * pc == ADDR_PREFIX_OPCODE ) { pc ++ ; if ( instr -> length != CTI_SHORT_REWRITE_LENGTH + 1 ) return false ; } else if ( instr -> length != CTI_SHORT_REWRITE_LENGTH ) return false ; } if ( instr_opcode_valid ( instr ) ) { int opc = instr_get_opcode ( instr ) ; if ( opc < OP_loopne || opc > OP_jecxz ) return false ; } else { int raw_opc = ( int ) * ( pc ) ; if ( raw_opc < RAW_OPCODE_loop_start || raw_opc > RAW_OPCODE_loop_end ) return false ; } if ( * ( pc + 2 ) != decode_first_opcode_byte ( OP_jmp_short ) ) return false ; if ( * ( pc + 4 ) != decode_first_opcode_byte ( OP_jmp ) ) return false ; return true ; }
Checks whether instr is a jecxz/loop* that was originally an app instruction.
Checks whether instr is a jecxz / loop * that was originally an app instruction .
/* ASSUMPTION: all app jecxz/loop* are converted to the pattern
     * (jecxz/loop*,jmp_short,jmp), and all jecxz/loop* generated by DynamoRIO
     * DO NOT MATCH THAT PATTERN.
     *
     * For clients, I belive we're robust in the presence of a client adding a
     * pattern that matches ours exactly: decode_fragment() won't think it's an
     * exit cti if it's in a fine-grained fragment where we have Linkstubs.  Since
     * bb building marks as non-coarse if a client adds any cti at all (meta or
     * not), we're protected there.  The other uses of remangle are in perscache,
     * which is only for coarse once again (coarse in general has a hard time
     * finding exit ctis: case 8711/PR 213146), and instr_expand(), which shouldn't
     * be used in the presence of clients w/ bb hooks.
     * Note that we now help clients make jecxz/loop transformations that look
     * just like ours: instr_convert_short_meta_jmp_to_long() (PR 266292).
     */ /* don't require decoding to opcode level */ /* now check remaining undecoded bytes */