MCPcopy Create free account
hub / github.com/GJDuck/e9patch / patchShortJump

Function patchShortJump

src/e9patch/e9tactics.cpp:369–385  ·  view source on GitHub ↗

* Patch in a short jmp instruction. */

Source from the content-addressed store, hash-verified

367 * Patch in a short jmp instruction.
368 */
369static void patchShortJump(Patch *P, intptr_t addr)
370{
371 intptr_t diff = addr - (P->I->addr + /*sizeof(short jmp)=*/2);
372 assert(diff >= INT8_MIN && diff <= INT8_MAX);
373 int8_t rel8 = (int8_t)diff;
374
375 uint8_t *bytes = P->I->PATCH,
376 *state = P->I->STATE;
377
378 assert(*state == STATE_INSTRUCTION || *state == STATE_FREE);
379 *bytes++ = /*short jmp opcode=*/0xEB;
380 *state++ = STATE_PATCHED;
381
382 assert(*state == STATE_INSTRUCTION || *state == STATE_FREE);
383 *bytes++ = (uint8_t)rel8;
384 *state++ = STATE_PATCHED;
385}
386
387/*
388 * Patch in a trap (illegal) instruction.

Callers 1

tactic_T3Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected