Skip to content

Commit

Permalink
ReplaceBLX instruction (closes #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Dec 15, 2018
1 parent ee926b4 commit a1dc20d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
13 changes: 13 additions & 0 deletions patchfile/kobopatch/kobopatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions patchlib/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a1dc20d

Please # to comment.