go-bsdiff

Pure Go bsdiff and bspatch libraries and CLI tools.

  • Owner: gabstv/go-bsdiff
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

go-bsdiff

Pure Go implementation of bsdiff 4.

GoDoc
Go Report Card
Build Status
Coverage Status

bsdiff and bspatch are tools for building and applying patches to binary files. By using suffix sorting (specifically, Larsson and Sadakane's qsufsort) 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

package main

import (
  "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

package main

import (
  "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)

go get -u -v github.com/gabstv/go-bsdiff/cmd/...

bsdiff oldfile newfile patch
bspatch oldfile newfile2 patch

Main metrics

Overview
Name With Ownergabstv/go-bsdiff
Primary LanguageGo
Program languageGo (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2019-02-23 23:33:50
Pushed At2019-03-21 12:35:11
Last Commit At2019-03-21 09:34:08
Release Count4
Last Release Namev1.0.5 (Posted on 2019-03-21 09:34:11)
First Release Namev1.0.2 (Posted on 2019-02-27 12:57:09)
用户参与
Stargazers Count165
Watchers Count3
Fork Count28
Commits Count54
Has Issues Enabled
Issues Count3
Issue Open Count0
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private