Games::Hack::Patch::i686 - How to patch code sequences on i686
$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.
- Memory moves from register
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.
- Floating point operations
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.
- Some QA
A look from someone that knows all possible instructions, along with their side-effects, would be appreciated.
- Hardware support
Modules for other CPUs would be nice.
Patches are welcome.
Ph. Marek <firstname.lastname@example.org>
Copyright (C) 2007 by Ph. Marek; licensed under the GPLv3.