arm/shared/KernelExploit/Sources/CFastFind/CFastFind.c
/**
 * Find an xref to an address
 *
 * \param start Start address
 * \param end End address
 * \param xrefTo The address for which a xref should be found
 */
Find an xref to an address
\param start Start address
\param end End address
\param xrefTo The address for which a xref should be found
Find an xref to an address \ param start Start address \ param end End address \ param xrefTo The address for which a xref should be found
uint64_t find_xref_to(const void *start, const void *end, uint64_t xrefTo, uint64_t pc) {
    uint32_t *cur = (uint32_t*) start;
    while (cur < (uint32_t*) end) {
        uint32_t inst = *cur;
        uint64_t xref = aarch64_emulate_adr(inst, pc);
        if (!xref) {
            xref = aarch64_emulate_adrp_add(inst, *(cur+1), pc);
            if (!xref) {
                xref = aarch64_emulate_branch(inst, pc);
                if (!xref) {
                    xref = aarch64_emulate_compare_branch(inst, pc);
                    if (!xref) {
                        xref = aarch64_emulate_conditional_branch(inst, pc);
                    }
                }
            }
        }
        if (xref == xrefTo) {
            return pc;
        }
        cur++;
        pc += 4;
    }
    return 0;
}
uint64_t find_xref_to ( const void * start , const void * end , uint64_t xrefTo , uint64_t pc ) { uint32_t * cur = ( uint32_t * ) start ; while ( cur < ( uint32_t * ) end ) { uint32_t inst = * cur ; uint64_t xref = aarch64_emulate_adr ( inst , pc ) ; if ( ! xref ) { xref = aarch64_emulate_adrp_add ( inst , * ( cur + 1 ) , pc ) ; if ( ! xref ) { xref = aarch64_emulate_branch ( inst , pc ) ; if ( ! xref ) { xref = aarch64_emulate_compare_branch ( inst , pc ) ; if ( ! xref ) { xref = aarch64_emulate_conditional_branch ( inst , pc ) ; } } } } if ( xref == xrefTo ) { return pc ; } cur ++ ; pc += 4 ; } return 0 ; }
Find an xref to an address
 \param start Start address
 \param end End address
 \param xrefTo The address for which a xref should be found
Find an xref to an address \ param start Start address \ param end End address \ param xrefTo The address for which a xref should be found