Skip to content

Commit

Permalink
patchfile/kobopatch: Implemented new symbol instructions (fixes #31) (c…
Browse files Browse the repository at this point in the history
…loses #32)

New instructions/fields:
* FlexAbsOffset can be used in place of wherever an absolute offset is taken
  (ReplaceBytes.Base, ReplaceBytes.FindInstBLX, ReplaceBytes.ReplaceInstBLX,
  ReplaceBytes.FindInstBW, ReplaceBytes.ReplaceInstBW,
  ReplaceBytes.ReplaceInstNOP, BaseAddress), with the exception of deprecated
  instructions/fields which need to retain compatibility regarding symbol
  offsets (see #31).
  * It can be used shorthand with an integer (for the Offset field) or a
    string (for the Sym field).
  * It has an Offset field for absolute offsets.
  * It has a Sym field for dynamic symbols.
  * It has a SymPLT field for their PLT entries.
  * It has a SymPLTTail field for matching the corresponding tail call stub.
  * It has a Rel field for adding/subtracting from the resulting absolute
    offset. Note that in general, it is preferred to use the Offset field
    of a more specific instruction, unless using the Rel field greatly
    simplifies the readability or maintainability of a patch.
  * All symbols can be matched using mangled or demangled names.
* ReplaceBytes now has new generators:
  * InstBLX can find/replace BLX instructions and takes a FlexAbsOffset.
  * InstBW can find/replace B.W instructions and takes a FlexAbsOffset.
  * The branch generators above have simple sanity checks built-in.
  * InstNOP replaces with NOPs.
  * CheckOnly skips replacements and instead just ensures the Find is
    present. This is mainly useful for multi-version patches made using
    the new symbol stuff which also needs to do things like ensure an
    argument is as expected.

Deprecations (these will still remain indefinitely for compatibility with
the old patches):
* ReplaceBytesAtSymbol is now deprecated in favour of ReplaceBytes.Base.Sym.
* FindBaseAddressSymbol is now deprecated in favour of BaseAddress.Sym.
* ReplaceBytesNOP is now deprecated in favour of ReplaceBytes.ReplaceNOP.
* ReplaceBLX is now deprecated in favour of ReplaceBytes.FindInstBLX
  and ReplaceBytes.ReplaceInstBLX.

Bugfixes/improvements:
* The log for ReplaceBytes is now a lot more useful and easier to
  understand, especially when using generators.
* Instruction names in certain error messages have been corrected.
* The bug where all symbol offsets were off by one has been fixed
  in the *new* instructions (the old ones are being left as-is to
  maintain backwards-compatibility (see #31).

I've tested the results of an updated version of the patches against the
original ones, and everything is perfectly identical.
  • Loading branch information
pgaskin committed Mar 17, 2020
1 parent 599ac1c commit f1494c5
Show file tree
Hide file tree
Showing 2 changed files with 419 additions and 92 deletions.
Loading

0 comments on commit f1494c5

Please sign in to comment.