GithubHelp home page GithubHelp logo

classicvalues / go-bsdiff Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kiteco/go-bsdiff

2.0 1.0 0.0 65 KB

Pure Go bsdiff and bspatch libraries and CLI tools.

License: MIT License

Go 99.28% Shell 0.72%

go-bsdiff's Introduction

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/kiteco/go-bsdiff/v2/pkg/bsdiff"
  "github.com/kiteco/go-bsdiff/v2/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/kiteco/go-bsdiff/v2/pkg/bsdiff"
  "github.com/kiteco/go-bsdiff/v2/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/kiteco/go-bsdiff/v2/cmd/...

bsdiff oldfile newfile patch
bspatch oldfile newfile2 patch

go-bsdiff's People

Contributors

gabstv avatar tonycheang avatar metalogical avatar

Stargazers

Classic Values avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.