core/x86/instr.c
/* Given a machine state, returns whether or not the cbr instr would be taken
 * if the state is before execution (pre == true) or after (pre == false).
 */
Given a machine state, returns whether or not the cbr instr would be taken
if the state is before execution (pre == true) or after (pre == false).
Given a machine state returns whether or not the cbr instr would be taken if the state is before execution ( pre == true ) or after ( pre == false ) .
bool
instr_cbr_taken(instr_t *instr, dr_mcontext_t *mcontext, bool pre)
{
    CLIENT_ASSERT(instr_is_cbr(instr), "instr_cbr_taken: instr not a cbr");
    if (instr_is_cti_loop(instr)) {
        uint opc = instr_get_opcode(instr);
        switch (opc) {
        case OP_loop:
            return (mcontext->xcx != (pre ? 1U : 0U));
        case OP_loope:
            return (TEST(EFLAGS_ZF, mcontext->xflags) &&
                    mcontext->xcx != (pre ? 1U : 0U));
        case OP_loopne:
            return (!TEST(EFLAGS_ZF, mcontext->xflags) &&
                    mcontext->xcx != (pre ? 1U : 0U));
        case OP_jecxz:
            return (mcontext->xcx == 0U);
        default:
            CLIENT_ASSERT(false, "instr_cbr_taken: unknown opcode");
            return false;
        }
    }
    return instr_jcc_taken(instr, mcontext->xflags);
}
bool instr_cbr_taken ( instr_t * instr , dr_mcontext_t * mcontext , bool pre ) { CLIENT_ASSERT ( instr_is_cbr ( instr ) , " " ) ; if ( instr_is_cti_loop ( instr ) ) { uint opc = instr_get_opcode ( instr ) ; switch ( opc ) { case OP_loop : return ( mcontext -> xcx != ( pre ? 1U : 0U ) ) ; case OP_loope : return ( TEST ( EFLAGS_ZF , mcontext -> xflags ) && mcontext -> xcx != ( pre ? 1U : 0U ) ) ; case OP_loopne : return ( ! TEST ( EFLAGS_ZF , mcontext -> xflags ) && mcontext -> xcx != ( pre ? 1U : 0U ) ) ; case OP_jecxz : return ( mcontext -> xcx == 0U ) ; default : CLIENT_ASSERT ( false , " " ) ; return false ; } } return instr_jcc_taken ( instr , mcontext -> xflags ) ; }
Given a machine state, returns whether or not the cbr instr would be taken
 if the state is before execution (pre == true) or after (pre == false).
Given a machine state returns whether or not the cbr instr would be taken if the state is before execution ( pre == true ) or after ( pre == false ) .