Games::Hack::Patch::x86_64 - How to patch code sequences on x86_64
$bytes=GetNOP( $adr_start, $adr_end, @disass );
Not useful in itself; is used by
Games::Hack::Live, and will possibly be used by
Addresses given to this library are always in integer/decimal, so that the script can simply add and subtract. (
gdb returns hex values.)
Given a start and an end address, and the disassembled instructions (although normally only one) in the given range (via
gdb), return a binary string that, when written at the start address, causes this part of the program to be ignored.
The easiest way is simply returning the NOP opcode (0x90 on x86), as many times as needed.
A bit better, because it's shorter, is to return a
short jump, with the correct offset.
Currently these are the only ones I've seen.
Unfortunately there are some instructions with side effects; eg. the coprocessor instructions are typically issued with the suffix pop stack, which causes this instruction to change the internal state.
Simply jumping over such sequences leaves the old values on the coprocessor stack and can cause irregular behaviour, aborts, core dumps, and other crashes.
So some care must be taken for them.
A look from someone that knows all possible instructions, along with their side-effects, would be appreciated.
Patches are welcome.
Ph. Marek <email@example.com>
Copyright (C) 2007 by Ph. Marek; licensed under the GPLv3.