Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gabstv/go-bsdiff
Pure Go bsdiff and bspatch libraries and CLI tools.
https://github.com/gabstv/go-bsdiff
Last synced: about 2 months ago
JSON representation
Pure Go bsdiff and bspatch libraries and CLI tools.
- Host: GitHub
- URL: https://github.com/gabstv/go-bsdiff
- Owner: gabstv
- License: mit
- Created: 2019-02-23T23:33:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-21T12:35:11.000Z (almost 6 years ago)
- Last Synced: 2024-07-31T20:53:33.500Z (5 months ago)
- Language: Go
- Homepage:
- Size: 66.4 KB
- Stars: 162
- Watchers: 4
- Forks: 27
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-bsdiff - Pure Go bsdiff and bspatch libraries and CLI tools. (Utilities / Utility/Miscellaneous)
- awesome-go-extra - go-bsdiff - 02-23T23:33:50Z|2019-03-21T12:35:11Z| (Utilities / Fail injection)
README
# go-bsdiff
Pure Go implementation of [bsdiff](http://www.daemonology.net/bsdiff/) 4.[![GoDoc](https://godoc.org/github.com/gabstv/go-bsdiff?status.svg)](https://godoc.org/github.com/gabstv/go-bsdiff)
[![Go Report Card](https://goreportcard.com/badge/github.com/gabstv/go-bsdiff)](https://goreportcard.com/report/github.com/gabstv/go-bsdiff)
[![Build Status](https://travis-ci.org/gabstv/go-bsdiff.svg?branch=master)](https://travis-ci.org/gabstv/go-bsdiff)
[![Coverage Status](https://coveralls.io/repos/github/gabstv/go-bsdiff/badge.svg?branch=master)](https://coveralls.io/github/gabstv/go-bsdiff?branch=master)bsdiff and bspatch are tools for building and applying patches to binary files. By using suffix sorting (specifically, Larsson and Sadakane's [qsufsort](http://www.larsson.dogma.net/ssrev-tr.pdf)) and taking advantage of how executable files change.
The package can be used as a library (pkg/bsdiff pkg/bspatch) or as a cli program (cmd/bsdiff cmd/bspatch).
## As a library
### Bsdiff Bytes
```Go
package mainimport (
"fmt"
"bytes""github.com/gabstv/go-bsdiff/pkg/bsdiff"
"github.com/gabstv/go-bsdiff/pkg/bspatch"
)func main(){
// example files
oldfile := []byte{0xfa, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}
newfile := []byte{0xfa, 0xdd, 0x00, 0x00, 0x00, 0xee, 0xee, 0x00, 0x00, 0xff, 0xfe, 0xfe}// generate a BSDIFF4 patch
patch, err := bsdiff.Bytes(oldfile, newfile)
if err != nil {
panic(err)
}
fmt.Println(patch)// Apply a BSDIFF4 patch
newfile2, err := bspatch.Bytes(oldfile, patch)
if err != nil {
panic(err)
}
if !bytes.Equal(newfile, newfile2) {
panic()
}
}
```
### Bsdiff Reader
```Go
package mainimport (
"fmt"
"bytes""github.com/gabstv/go-bsdiff/pkg/bsdiff"
"github.com/gabstv/go-bsdiff/pkg/bspatch"
)func main(){
oldrdr := bytes.NewReader([]byte{0xfa, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff})
newrdr := bytes.NewReader([]byte{0xfa, 0xdd, 0x00, 0x00, 0x00, 0xee, 0xee, 0x00, 0x00, 0xff, 0xfe, 0xfe})
patch := new(bytes.Buffer)// generate a BSDIFF4 patch
if err := bsdiff.Reader(oldrdr, newrdr, patch); err != nil {
panic(err)
}newpatchedf := new(bytes.Buffer)
oldrdr.Seek(0, 0)// Apply a BSDIFF4 patch
if err := bspatch.Reader(oldrdr, newpatchedf, patch); err != nil {
panic(err)
}
fmt.Println(newpatchedf.Bytes())
}
```## As a program (CLI)
```sh
go get -u -v github.com/gabstv/go-bsdiff/cmd/...bsdiff oldfile newfile patch
bspatch oldfile newfile2 patch
```