Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Nov 27, 2018
1 parent 48cef25 commit d78af15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions patchfile/kobopatch/kobopatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ func (ps *PatchSet) ApplyTo(pt *patchlib.Patcher) error {
r := *i.ReplaceZlib
patchfile.Log(" ReplaceZlib(%#v, %#v, %#v)\n", r.Offset, r.Find, r.Replace)
err = pt.ReplaceZlib(r.Offset, r.Find, r.Replace)
case i.ReplaceZlibGroup != nil:
r := *i.ReplaceZlibGroup
patchfile.Log(" ReplaceZlibGroup(%#v, %#v)\n", r.Offset, r.Replacements)
rs := []patchlib.Replacement{}
for _, rr := range r.Replacements {
rs = append(rs, patchlib.Replacement{Find: rr.Find, Replace: rr.Replace})
}
err = pt.ReplaceZlibGroup(r.Offset, rs)
default:
patchfile.Log(" invalid instruction: %#v\n", i)
err = errors.Errorf("invalid instruction: %#v", i)
Expand Down
13 changes: 8 additions & 5 deletions patchlib/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,16 @@ func (p *Patcher) FindZlibHash(hash string) error {

// ReplaceZlib replaces a part of a zlib css stream at the current offset.
func (p *Patcher) ReplaceZlib(offset int32, find, replace string) error {
return p.ReplaceZlibGroup(offset, []struct{ find, replace string }{{find, replace}})
return p.ReplaceZlibGroup(offset, []Replacement{{find, replace}})
}

// Replacement is a replacement for ReplaceZlibGroup.
type Replacement struct {
Find, Replace string
}

// ReplaceZlibGroup is the same as ReplaceZlib, but it replaces all at once.
func (p *Patcher) ReplaceZlibGroup(offset int32, repl []struct {
find, replace string
}) error {
func (p *Patcher) ReplaceZlibGroup(offset int32, repl []Replacement) error {
if !bytes.HasPrefix(p.buf[p.cur+offset:p.cur+offset+2], []byte{0x78, 0x9c}) {
return errors.New("ReplaceZlib: not a zlib stream")
}
Expand All @@ -206,7 +209,7 @@ func (p *Patcher) ReplaceZlibGroup(offset int32, repl []struct {
return errors.New("ReplaceZlib: sanity check failed: recompressed original data does not match original (this is a bug, so please report it)")
}
for _, r := range repl {
find, replace := r.find, r.replace
find, replace := r.Find, r.Replace
if !bytes.Contains(dbuf, []byte(find)) {
find = strings.Replace(find, "\n ", "\n", -1)
find = strings.Replace(find, "\n ", "\n", -1)
Expand Down

0 comments on commit d78af15

Please # to comment.