* Find the instruction at the given address. */
| 192 | * Find the instruction at the given address. |
| 193 | */ |
| 194 | Instr *findInstr(const Binary *B, intptr_t addr) |
| 195 | { |
| 196 | Instr *lb = B->Is.front(), *ub = B->Is.end(); |
| 197 | if (lb == nullptr || ub == nullptr) |
| 198 | return nullptr; |
| 199 | Instr *Is = lb; |
| 200 | ssize_t lo = 0, hi = (ub - lb) - 1; |
| 201 | while (lo <= hi) |
| 202 | { |
| 203 | ssize_t mid = (lo + hi) / 2; |
| 204 | if (addr > Is[mid].addr) |
| 205 | lo = mid+1; |
| 206 | else if (addr < Is[mid].addr) |
| 207 | hi = mid-1; |
| 208 | else |
| 209 | return &Is[mid]; |
| 210 | } |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Optimize a jump (or call) instruction. |
no test coverage detected