GithubHelp home page GithubHelp logo

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/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

go-bsdiff's People

Contributors

gabstv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-bsdiff's Issues

Difference between examples and reverse patching

Hello!
I have been looking to see if anyone has implemented bsdiff directly into Go. Lovely work!

  1. I was wondering what the difference between the two examples is in your README.md, in terms of you have Bsdiff Bytes and Bsdiff Reader - is it just a way to literally view the diff?

  2. I am interested in reversing patches, rather than applying patches to old files, to get new ones.

So for instance if I have files

v0.1
v0.2
v0.3

and I want to get from v0.3 to v0.1 I want to reverse the patch from v0.3 -> v0.2 and then reverse the patch from 0.2 to v0.1
Is this possible do you know, or do you know what it would involve?

Thanks
Alex!

bspatch: corrupt patch or bzstream ended (3)

Hi. I tried generating patch for some .dll file (47.2 MB -> 57.8 MB).
Patch is generated successfully, but bspatch is giving error:
bspatch: corrupt patch or bzstream ended (3):.
I also tried applying this patch (generated with go-bsdiff) with original bspatch. File was patched successfully and target and patched files are identical.
So, I think, there is an error in bspatch?
I can provide files, if you need it.

Passing a channel so a diff can be cancelled

Hi (again...)
If I wanted to cancel a diff, for instance if it was diffing a large file and I wanted to stop it, could a helper function that takes a channel be used?
Im prodding around in your code, but it's pretty full on code and In worried im poking around in areas I am not familiar with and could cause problems.
Any suggestion would be very helpful as to where to check for a message on a channel to cancel whatever is going on.

Thanks
A

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.