Skip to content

Commit a703ebb

Browse files
committed
Replace bsdiff submodule reference with actual copy.
Source: https://github.com/mendsley/bsdiff/tree/64ad986cb7bfa8b9145a2d48cd95986660b35d53 Fixes #2.
1 parent 1518b3f commit a703ebb

File tree

13 files changed

+966
-4
lines changed

13 files changed

+966
-4
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

bsdiff

Lines changed: 0 additions & 1 deletion
This file was deleted.

bsdiff/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.deps/*
2+
.libs/*
3+
*.lo
4+
*.o
5+
.dirstamp
6+
Makefile-bsdiff.am.inc
7+
AUTHORS
8+
NEWS
9+
README
10+
ChangeLog
11+
COPYING

bsdiff/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright 2003-2005 Colin Percival
2+
Copyright 2012 Matthew Endsley
3+
All rights reserved
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted providing that the following conditions
7+
are met:
8+
1. Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
POSSIBILITY OF SUCH DAMAGE.

bsdiff/Makefile-bsdiff.am

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (C) 2015 Giuseppe Scrivano <[email protected]>
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted providing that the following conditions
5+
# are met:
6+
# 1. Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
# 2. Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
#
12+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
13+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
16+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
20+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
21+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
# POSSIBILITY OF SUCH DAMAGE.
23+
#
24+
25+
EXTRA_DIST += $(libbsdiff_srcpath)/bsdiff.h $(libbsdiff_srcpath)/bspatch.h $(libbsdiff_srcpath)/LICENSE $(libbsdiff_srcpath)/README.md
26+
27+
libbsdiff_la_SOURCES = \
28+
$(libbsdiff_srcpath)/bsdiff.c \
29+
$(libbsdiff_srcpath)/bspatch.c \
30+
$(NULL)
31+
32+
libbsdiff_la_CFLAGS = $(AM_CFLAGS)

bsdiff/Makefile.am

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bin_PROGRAMS = bsdiff bspatch
2+
3+
bsdiff_SOURCES = bsdiff.c
4+
5+
bspatch_SOURCES = bspatch.c
6+
7+
bsdiff_CFLAGS = -DBSDIFF_EXECUTABLE
8+
bspatch_CFLAGS = -DBSPATCH_EXECUTABLE
9+
10+
EXTRA_DIST = bsdiff.h bspatch.h
11+

bsdiff/README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
bsdiff/bspatch
2+
==============
3+
bsdiff and bspatch are libraries for building and applying patches to binary
4+
files.
5+
6+
The original algorithm and implementation was developed by Colin Percival. The
7+
algorithm is detailed in his paper, [Naïve Differences of Executable Code](http://www.daemonology.net/papers/bsdiff.pdf). For more information, visit his
8+
website at <http://www.daemonology.net/bsdiff/>.
9+
10+
I maintain this project separately from Colin's work, with the goal of making
11+
the core functionality easily embeddable in existing projects.
12+
13+
Contact
14+
-------
15+
[@MatthewEndsley](https://twitter.com/#!/MatthewEndsley)
16+
<https://github.com/mendsley/bsdiff>
17+
18+
License
19+
-------
20+
Copyright 2003-2005 Colin Percival
21+
Copyright 2012 Matthew Endsley
22+
23+
This project is governed by the BSD 2-clause license. For details see the file
24+
titled LICENSE in the project root folder.
25+
26+
Overview
27+
--------
28+
There are two separate libraries in the project, bsdiff and bspatch. Each are
29+
self contained in bsdiff.c and bspatch.c The easiest way to integrate is to
30+
simply copy the c file to your source folder and build it.
31+
32+
The overarching goal was to modify the original bsdiff/bspatch code from Colin
33+
and eliminate external dependencies and provide a simple interface to the core
34+
functionality.
35+
36+
I've exposed relevant functions via the `_stream` classes. The only external
37+
dependency not exposed is `memcmp` in `bsdiff`.
38+
39+
This library generates patches that are not compatible with the original bsdiff
40+
tool. The incompatibilities were motivated by the patching needs for the game
41+
AirMech <https://www.carbongames.com> and the following requirements:
42+
43+
* Eliminate/minimize any seek operations when applying patches
44+
* Eliminate any required disk I/O and support embedded streams
45+
* Ability to easily embed the routines as a library instead of an external binary
46+
* Compile+run on all platforms we use to build the game (Windows, Linux, NaCl, OSX)
47+
48+
Compiling
49+
---------
50+
The libraries should compile warning free in any moderately recent version of
51+
gcc. The project uses `<stdint.h>` which is technically a C99 file and not
52+
available in Microsoft Visual Studio. The easiest solution here is to use the
53+
msinttypes version of stdint.h from <https://code.google.com/p/msinttypes/>.
54+
The direct link for the lazy people is:
55+
<https://msinttypes.googlecode.com/svn/trunk/stdint.h>.
56+
57+
If your compiler does not provide an implementation of `<stdint.h>` you can
58+
remove the header from the bsdiff/bspatch files and provide your own typedefs
59+
for the following symbols: `uint8_t`, `uint64_t` and `int64_t`.
60+
61+
Examples
62+
--------
63+
Each project has an optional main function that serves as an example for using
64+
the library. Simply defined `BSDIFF_EXECUTABLE` or `BSPATCH_EXECUTABLE` to
65+
enable building the standalone tools.
66+
67+
Reference
68+
---------
69+
### bsdiff
70+
71+
struct bsdiff_stream
72+
{
73+
void* opaque;
74+
void* (*malloc)(size_t size);
75+
void (*free)(void* ptr);
76+
int (*write)(struct bsdiff_stream* stream,
77+
const void* buffer, int size);
78+
};
79+
80+
int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new,
81+
int64_t newsize, struct bsdiff_stream* stream);
82+
83+
84+
In order to use `bsdiff`, you need to define functions for allocating memory and
85+
writing binary data. This behavior is controlled by the `stream` parameter
86+
passed to to `bsdiff(...)`.
87+
88+
The `opaque` field is never read or modified from within the `bsdiff` function.
89+
The caller can use this field to store custom state data needed for the callback
90+
functions.
91+
92+
The `malloc` and `free` members should point to functions that behave like the
93+
standard `malloc` and `free` C functions.
94+
95+
The `write` function is called by bsdiff to write a block of binary data to the
96+
stream. The return value for `write` should be `0` on success and non-zero if
97+
the callback failed to write all data. In the default example, bzip2 is used to
98+
compress output data.
99+
100+
`bsdiff` returns `0` on success and `-1` on failure.
101+
102+
### bspatch
103+
104+
struct bspatch_stream
105+
{
106+
void* opaque;
107+
int (*read)(const struct bspatch_stream* stream,
108+
void* buffer, int length);
109+
};
110+
111+
int bspatch(const uint8_t* old, int64_t oldsize, uint8_t* new,
112+
int64_t newsize, struct bspatch_stream* stream);
113+
114+
The `bspatch` function transforms the data for a file using data generated from
115+
`bsdiff`. The caller takes care of loading the old file and allocating space for
116+
new file data. The `stream` parameter controls the process for reading binary
117+
patch data.
118+
119+
The `opaque` field is never read or modified from within the bspatch function.
120+
The caller can use this field to store custom state data needed for the read
121+
function.
122+
123+
The `read` function is called by `bspatch` to read a block of binary data from
124+
the stream. The return value for `read` should be `0` on success and non-zero
125+
if the callback failed to read the requested amount of data. In the default
126+
example, bzip2 is used to decompress input data.
127+
128+
`bspatch` returns `0` on success and `-1` on failure. On success, `new` contains
129+
the data for the patched file.

bsdiff/autogen.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
touch AUTHORS NEWS README ChangeLog
4+
cp LICENSE COPYING
5+
6+
autoreconf -fis

0 commit comments

Comments
 (0)