NAME

Games::Hack::Patch::x86_64 - How to patch code sequences on x86_64

SYNOPSIS

$bytes=GetNOP( $adr_start, $adr_end, @disass );

DESCRIPTION

Not useful in itself; is used by Games::Hack::Live, and will possibly be used by Games::Hack::Offline.

Addresses given to this library are always in integer/decimal, so that the script can simply add and subtract. (gdb returns hex values.)

GetNOP

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.

Currently these are the only ones I've seen.

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.

BUGS/CAVEATS/TODO/IDEAS/WISHLIST

Some QA

A look from someone that knows all possible instructions, along with their side-effects, would be appreciated.

Patches are welcome.

AUTHOR

Ph. Marek <pmarek@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Ph. Marek; licensed under the GPLv3.