From a1dc20dd774901dda89779a45fc74bcad032d682 Mon Sep 17 00:00:00 2001 From: Patrick G Date: Fri, 14 Dec 2018 22:47:18 -0500 Subject: [PATCH] ReplaceBLX instruction (closes #19) --- README.md | 2 ++ patchfile/kobopatch/kobopatch.go | 13 +++++++++++++ patchlib/patcher.go | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index ddc8848..f6faa1a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ An improved patching system for Kobo eReaders. See https://www.mobileread.com/fo - [X] Zlib support - [X] CSS extraction tool (./cssextract) - [X] Support for adding additional files +- [X] ReplaceBLX support **Improvements/Goals:** - More readable code @@ -34,5 +35,6 @@ An improved patching system for Kobo eReaders. See https://www.mobileread.com/fo - No need for temp files - Save and restore lists of enabled patches - Translation file support +- Replacement of assembly instructions - more - Zlib support \ No newline at end of file diff --git a/patchfile/kobopatch/kobopatch.go b/patchfile/kobopatch/kobopatch.go index 9c3dfd4..d87ea01 100644 --- a/patchfile/kobopatch/kobopatch.go +++ b/patchfile/kobopatch/kobopatch.go @@ -64,6 +64,11 @@ type instruction struct { Replace string `yaml:"Replace,omitempty"` } `yaml:"Replacements,omitempty"` } `yaml:"ReplaceZlibGroup,omitempty"` + ReplaceBLX *struct { + Offset int32 `yaml:"Offset,omitempty"` + Find uint32 `yaml:"Find,omitempty"` + Replace uint32 `yaml:"Replace,omitempty"` + } `yaml:"ReplaceBLX,omitempty"` } // Parse parses a PatchSet from a buf. @@ -212,6 +217,10 @@ func (ps *PatchSet) Validate() error { } } } + if i.ReplaceBLX != nil { + ic++ + roc++ + } if ic < 1 { return errors.Errorf("i%d: internal error while validating `%s` (you should report this as a bug)", instn+1, n) } @@ -351,6 +360,10 @@ func (ps *PatchSet) ApplyTo(pt *patchlib.Patcher) error { rs = append(rs, patchlib.Replacement{Find: rr.Find, Replace: rr.Replace}) } err = pt.ReplaceZlibGroup(r.Offset, rs) + case i.ReplaceBLX != nil: + r := *i.ReplaceBLX + patchfile.Log(" ReplaceBLX(%#v, %#v, %#v)\n", r.Offset, r.Find, r.Replace) + err = pt.ReplaceBLX(r.Offset, r.Find, r.Replace) default: patchfile.Log(" invalid instruction: %#v\n", i) err = errors.Errorf("invalid instruction: %#v", i) diff --git a/patchlib/patcher.go b/patchlib/patcher.go index 7a94e22..d0fe793 100644 --- a/patchlib/patcher.go +++ b/patchlib/patcher.go @@ -304,6 +304,11 @@ func (p *Patcher) ExtractZlib() ([]ZlibItem, error) { return zlibs, nil } +// ReplaceBLX replaces a BLX instruction at PC (offset). Find and Replace are the target offsets. +func (p *Patcher) ReplaceBLX(offset int32, find, replace uint32) error { + return p.replaceValue(offset, blx(uint32(offset), find), blx(uint32(offset), replace), true) +} + // replaceValue encodes find and replace as little-endian binary and replaces the first // occurrence starting at cur. The lengths of the encoded find and replace must be the // same, or an error will be returned.