react-native-bspatch 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +471 -0
- package/android/build.gradle +100 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/vn/reactnativebspatch/BsPatchModule.kt +139 -0
- package/android/src/main/java/vn/reactnativebspatch/BsPatchPackage.kt +16 -0
- package/android/src/main/java/vn/reactnativebspatch/OtaBundleResolver.kt +227 -0
- package/cpp/CMakeLists.txt +43 -0
- package/cpp/bsdiff/bspatch.c +194 -0
- package/cpp/bsdiff/bspatch.h +41 -0
- package/cpp/bsdiff/bspatch_wrapper.c +150 -0
- package/cpp/bsdiff/bspatch_wrapper.h +6 -0
- package/cpp/bspatch_jni.cpp +41 -0
- package/cpp/bzip2/LICENSE +42 -0
- package/cpp/bzip2/blocksort.c +1094 -0
- package/cpp/bzip2/bzlib.c +1572 -0
- package/cpp/bzip2/bzlib.h +282 -0
- package/cpp/bzip2/bzlib_private.h +509 -0
- package/cpp/bzip2/compress.c +672 -0
- package/cpp/bzip2/crctable.c +104 -0
- package/cpp/bzip2/decompress.c +652 -0
- package/cpp/bzip2/huffman.c +205 -0
- package/cpp/bzip2/randtable.c +84 -0
- package/ios/OtaBundleResolver.swift +241 -0
- package/ios/RNBsPatch.h +8 -0
- package/ios/RNBsPatch.mm +198 -0
- package/lib/commonjs/NativeBsPatch.js +9 -0
- package/lib/commonjs/NativeBsPatch.js.map +1 -0
- package/lib/commonjs/crypto-js.d.js +2 -0
- package/lib/commonjs/crypto-js.d.js.map +1 -0
- package/lib/commonjs/index.js +90 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/ota/OtaProvider.js +306 -0
- package/lib/commonjs/ota/OtaProvider.js.map +1 -0
- package/lib/commonjs/ota/otaAssetResolver.js +145 -0
- package/lib/commonjs/ota/otaAssetResolver.js.map +1 -0
- package/lib/commonjs/ota/otaCore.js +736 -0
- package/lib/commonjs/ota/otaCore.js.map +1 -0
- package/lib/commonjs/ota/otaLogger.js +64 -0
- package/lib/commonjs/ota/otaLogger.js.map +1 -0
- package/lib/commonjs/ota/otaMetadata.js +138 -0
- package/lib/commonjs/ota/otaMetadata.js.map +1 -0
- package/lib/commonjs/ota/storage/CustomStorage.js +140 -0
- package/lib/commonjs/ota/storage/CustomStorage.js.map +1 -0
- package/lib/commonjs/ota/storage/GitHubReleaseStorage.js +96 -0
- package/lib/commonjs/ota/storage/GitHubReleaseStorage.js.map +1 -0
- package/lib/commonjs/ota/types.js +39 -0
- package/lib/commonjs/ota/types.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/NativeBsPatch.js +5 -0
- package/lib/module/NativeBsPatch.js.map +1 -0
- package/lib/module/crypto-js.d.js +2 -0
- package/lib/module/crypto-js.d.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/ota/OtaProvider.js +299 -0
- package/lib/module/ota/OtaProvider.js.map +1 -0
- package/lib/module/ota/otaAssetResolver.js +138 -0
- package/lib/module/ota/otaAssetResolver.js.map +1 -0
- package/lib/module/ota/otaCore.js +725 -0
- package/lib/module/ota/otaCore.js.map +1 -0
- package/lib/module/ota/otaLogger.js +59 -0
- package/lib/module/ota/otaLogger.js.map +1 -0
- package/lib/module/ota/otaMetadata.js +127 -0
- package/lib/module/ota/otaMetadata.js.map +1 -0
- package/lib/module/ota/storage/CustomStorage.js +134 -0
- package/lib/module/ota/storage/CustomStorage.js.map +1 -0
- package/lib/module/ota/storage/GitHubReleaseStorage.js +90 -0
- package/lib/module/ota/storage/GitHubReleaseStorage.js.map +1 -0
- package/lib/module/ota/types.js +38 -0
- package/lib/module/ota/types.js.map +1 -0
- package/lib/typescript/NativeBsPatch.d.ts +39 -0
- package/lib/typescript/NativeBsPatch.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +15 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/ota/OtaProvider.d.ts +10 -0
- package/lib/typescript/ota/OtaProvider.d.ts.map +1 -0
- package/lib/typescript/ota/otaAssetResolver.d.ts +15 -0
- package/lib/typescript/ota/otaAssetResolver.d.ts.map +1 -0
- package/lib/typescript/ota/otaCore.d.ts +109 -0
- package/lib/typescript/ota/otaCore.d.ts.map +1 -0
- package/lib/typescript/ota/otaLogger.d.ts +44 -0
- package/lib/typescript/ota/otaLogger.d.ts.map +1 -0
- package/lib/typescript/ota/otaMetadata.d.ts +46 -0
- package/lib/typescript/ota/otaMetadata.d.ts.map +1 -0
- package/lib/typescript/ota/storage/CustomStorage.d.ts +12 -0
- package/lib/typescript/ota/storage/CustomStorage.d.ts.map +1 -0
- package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts +20 -0
- package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts.map +1 -0
- package/lib/typescript/ota/types.d.ts +191 -0
- package/lib/typescript/ota/types.d.ts.map +1 -0
- package/package.json +89 -0
- package/react-native-bspatch.podspec +46 -0
- package/src/NativeBsPatch.ts +52 -0
- package/src/crypto-js.d.ts +1 -0
- package/src/index.ts +29 -0
- package/src/ota/OtaProvider.tsx +399 -0
- package/src/ota/otaAssetResolver.ts +182 -0
- package/src/ota/otaCore.ts +963 -0
- package/src/ota/otaLogger.ts +72 -0
- package/src/ota/otaMetadata.ts +149 -0
- package/src/ota/storage/CustomStorage.ts +143 -0
- package/src/ota/storage/GitHubReleaseStorage.ts +98 -0
- package/src/ota/types.ts +211 -0
- package/tools/bsdiff +0 -0
- package/tools/bsdiff.c +445 -0
- package/tools/bsdiff.h +45 -0
- package/tools/build_ota.sh +457 -0
- package/tools/setup_project.js +273 -0
- package/tools/update_registry.js +145 -0
- package/tools/upload_ota_custom.sh +138 -0
package/tools/bsdiff.c
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright 2003-2005 Colin Percival
|
|
3
|
+
* Copyright 2012 Matthew Endsley
|
|
4
|
+
* All rights reserved
|
|
5
|
+
*
|
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
|
7
|
+
* modification, are permitted providing that the following conditions
|
|
8
|
+
* are met:
|
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
|
14
|
+
*
|
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
16
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
18
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
19
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
21
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
22
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
23
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
24
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
25
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#include "bsdiff.h"
|
|
29
|
+
|
|
30
|
+
#include <limits.h>
|
|
31
|
+
#include <string.h>
|
|
32
|
+
|
|
33
|
+
#define MIN(x,y) (((x)<(y)) ? (x) : (y))
|
|
34
|
+
|
|
35
|
+
static void split(int64_t *I,int64_t *V,int64_t start,int64_t len,int64_t h)
|
|
36
|
+
{
|
|
37
|
+
int64_t i,j,k,x,tmp,jj,kk;
|
|
38
|
+
|
|
39
|
+
if(len<16) {
|
|
40
|
+
for(k=start;k<start+len;k+=j) {
|
|
41
|
+
j=1;x=V[I[k]+h];
|
|
42
|
+
for(i=1;k+i<start+len;i++) {
|
|
43
|
+
if(V[I[k+i]+h]<x) {
|
|
44
|
+
x=V[I[k+i]+h];
|
|
45
|
+
j=0;
|
|
46
|
+
};
|
|
47
|
+
if(V[I[k+i]+h]==x) {
|
|
48
|
+
tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
|
|
49
|
+
j++;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
|
|
53
|
+
if(j==1) I[k]=-1;
|
|
54
|
+
};
|
|
55
|
+
return;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
x=V[I[start+len/2]+h];
|
|
59
|
+
jj=0;kk=0;
|
|
60
|
+
for(i=start;i<start+len;i++) {
|
|
61
|
+
if(V[I[i]+h]<x) jj++;
|
|
62
|
+
if(V[I[i]+h]==x) kk++;
|
|
63
|
+
};
|
|
64
|
+
jj+=start;kk+=jj;
|
|
65
|
+
|
|
66
|
+
i=start;j=0;k=0;
|
|
67
|
+
while(i<jj) {
|
|
68
|
+
if(V[I[i]+h]<x) {
|
|
69
|
+
i++;
|
|
70
|
+
} else if(V[I[i]+h]==x) {
|
|
71
|
+
tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
|
|
72
|
+
j++;
|
|
73
|
+
} else {
|
|
74
|
+
tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
|
|
75
|
+
k++;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
while(jj+j<kk) {
|
|
80
|
+
if(V[I[jj+j]+h]==x) {
|
|
81
|
+
j++;
|
|
82
|
+
} else {
|
|
83
|
+
tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
|
|
84
|
+
k++;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if(jj>start) split(I,V,start,jj-start,h);
|
|
89
|
+
|
|
90
|
+
for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
|
|
91
|
+
if(jj==kk-1) I[jj]=-1;
|
|
92
|
+
|
|
93
|
+
if(start+len>kk) split(I,V,kk,start+len-kk,h);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static void qsufsort(int64_t *I,int64_t *V,const uint8_t *old,int64_t oldsize)
|
|
97
|
+
{
|
|
98
|
+
int64_t buckets[256];
|
|
99
|
+
int64_t i,h,len;
|
|
100
|
+
|
|
101
|
+
for(i=0;i<256;i++) buckets[i]=0;
|
|
102
|
+
for(i=0;i<oldsize;i++) buckets[old[i]]++;
|
|
103
|
+
for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
|
|
104
|
+
for(i=255;i>0;i--) buckets[i]=buckets[i-1];
|
|
105
|
+
buckets[0]=0;
|
|
106
|
+
|
|
107
|
+
for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
|
|
108
|
+
I[0]=oldsize;
|
|
109
|
+
for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
|
|
110
|
+
V[oldsize]=0;
|
|
111
|
+
for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
|
|
112
|
+
I[0]=-1;
|
|
113
|
+
|
|
114
|
+
for(h=1;I[0]!=-(oldsize+1);h+=h) {
|
|
115
|
+
len=0;
|
|
116
|
+
for(i=0;i<oldsize+1;) {
|
|
117
|
+
if(I[i]<0) {
|
|
118
|
+
len-=I[i];
|
|
119
|
+
i-=I[i];
|
|
120
|
+
} else {
|
|
121
|
+
if(len) I[i-len]=-len;
|
|
122
|
+
len=V[I[i]]+1-i;
|
|
123
|
+
split(I,V,i,len,h);
|
|
124
|
+
i+=len;
|
|
125
|
+
len=0;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
if(len) I[i-len]=-len;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
for(i=0;i<oldsize+1;i++) I[V[i]]=i;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static int64_t matchlen(const uint8_t *old,int64_t oldsize,const uint8_t *new,int64_t newsize)
|
|
135
|
+
{
|
|
136
|
+
int64_t i;
|
|
137
|
+
|
|
138
|
+
for(i=0;(i<oldsize)&&(i<newsize);i++)
|
|
139
|
+
if(old[i]!=new[i]) break;
|
|
140
|
+
|
|
141
|
+
return i;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static int64_t search(const int64_t *I,const uint8_t *old,int64_t oldsize,
|
|
145
|
+
const uint8_t *new,int64_t newsize,int64_t st,int64_t en,int64_t *pos)
|
|
146
|
+
{
|
|
147
|
+
int64_t x,y;
|
|
148
|
+
|
|
149
|
+
if(en-st<2) {
|
|
150
|
+
x=matchlen(old+I[st],oldsize-I[st],new,newsize);
|
|
151
|
+
y=matchlen(old+I[en],oldsize-I[en],new,newsize);
|
|
152
|
+
|
|
153
|
+
if(x>y) {
|
|
154
|
+
*pos=I[st];
|
|
155
|
+
return x;
|
|
156
|
+
} else {
|
|
157
|
+
*pos=I[en];
|
|
158
|
+
return y;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
x=st+(en-st)/2;
|
|
163
|
+
if(memcmp(old+I[x],new,MIN(oldsize-I[x],newsize))<0) {
|
|
164
|
+
return search(I,old,oldsize,new,newsize,x,en,pos);
|
|
165
|
+
} else {
|
|
166
|
+
return search(I,old,oldsize,new,newsize,st,x,pos);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static void offtout(int64_t x,uint8_t *buf)
|
|
171
|
+
{
|
|
172
|
+
int64_t y;
|
|
173
|
+
|
|
174
|
+
if(x<0) y=-x; else y=x;
|
|
175
|
+
|
|
176
|
+
buf[0]=y%256;y-=buf[0];
|
|
177
|
+
y=y/256;buf[1]=y%256;y-=buf[1];
|
|
178
|
+
y=y/256;buf[2]=y%256;y-=buf[2];
|
|
179
|
+
y=y/256;buf[3]=y%256;y-=buf[3];
|
|
180
|
+
y=y/256;buf[4]=y%256;y-=buf[4];
|
|
181
|
+
y=y/256;buf[5]=y%256;y-=buf[5];
|
|
182
|
+
y=y/256;buf[6]=y%256;y-=buf[6];
|
|
183
|
+
y=y/256;buf[7]=y%256;
|
|
184
|
+
|
|
185
|
+
if(x<0) buf[7]|=0x80;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static int64_t writedata(struct bsdiff_stream* stream, const void* buffer, int64_t length)
|
|
189
|
+
{
|
|
190
|
+
int64_t result = 0;
|
|
191
|
+
|
|
192
|
+
while (length > 0)
|
|
193
|
+
{
|
|
194
|
+
const int smallsize = (int)MIN(length, INT_MAX);
|
|
195
|
+
const int writeresult = stream->write(stream, buffer, smallsize);
|
|
196
|
+
if (writeresult == -1)
|
|
197
|
+
{
|
|
198
|
+
return -1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
result += writeresult;
|
|
202
|
+
length -= smallsize;
|
|
203
|
+
buffer = (uint8_t*)buffer + smallsize;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
struct bsdiff_request
|
|
210
|
+
{
|
|
211
|
+
const uint8_t* old;
|
|
212
|
+
int64_t oldsize;
|
|
213
|
+
const uint8_t* new;
|
|
214
|
+
int64_t newsize;
|
|
215
|
+
struct bsdiff_stream* stream;
|
|
216
|
+
int64_t *I;
|
|
217
|
+
uint8_t *buffer;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
static int bsdiff_internal(const struct bsdiff_request req)
|
|
221
|
+
{
|
|
222
|
+
int64_t *I,*V;
|
|
223
|
+
int64_t scan,pos,len;
|
|
224
|
+
int64_t lastscan,lastpos,lastoffset;
|
|
225
|
+
int64_t oldscore,scsc;
|
|
226
|
+
int64_t s,Sf,lenf,Sb,lenb;
|
|
227
|
+
int64_t overlap,Ss,lens;
|
|
228
|
+
int64_t i;
|
|
229
|
+
uint8_t *buffer;
|
|
230
|
+
uint8_t buf[8 * 3];
|
|
231
|
+
|
|
232
|
+
if((V=req.stream->malloc((req.oldsize+1)*sizeof(int64_t)))==NULL) return -1;
|
|
233
|
+
I = req.I;
|
|
234
|
+
|
|
235
|
+
qsufsort(I,V,req.old,req.oldsize);
|
|
236
|
+
req.stream->free(V);
|
|
237
|
+
|
|
238
|
+
buffer = req.buffer;
|
|
239
|
+
|
|
240
|
+
/* Compute the differences, writing ctrl as we go */
|
|
241
|
+
scan=0;len=0;pos=0;
|
|
242
|
+
lastscan=0;lastpos=0;lastoffset=0;
|
|
243
|
+
while(scan<req.newsize) {
|
|
244
|
+
oldscore=0;
|
|
245
|
+
|
|
246
|
+
for(scsc=scan+=len;scan<req.newsize;scan++) {
|
|
247
|
+
len=search(I,req.old,req.oldsize,req.new+scan,req.newsize-scan,
|
|
248
|
+
0,req.oldsize,&pos);
|
|
249
|
+
|
|
250
|
+
for(;scsc<scan+len;scsc++)
|
|
251
|
+
if((scsc+lastoffset<req.oldsize) &&
|
|
252
|
+
(req.old[scsc+lastoffset] == req.new[scsc]))
|
|
253
|
+
oldscore++;
|
|
254
|
+
|
|
255
|
+
if(((len==oldscore) && (len!=0)) ||
|
|
256
|
+
(len>oldscore+8)) break;
|
|
257
|
+
|
|
258
|
+
if((scan+lastoffset<req.oldsize) &&
|
|
259
|
+
(req.old[scan+lastoffset] == req.new[scan]))
|
|
260
|
+
oldscore--;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
if((len!=oldscore) || (scan==req.newsize)) {
|
|
264
|
+
s=0;Sf=0;lenf=0;
|
|
265
|
+
for(i=0;(lastscan+i<scan)&&(lastpos+i<req.oldsize);) {
|
|
266
|
+
if(req.old[lastpos+i]==req.new[lastscan+i]) s++;
|
|
267
|
+
i++;
|
|
268
|
+
if(s*2-i>Sf*2-lenf) { Sf=s; lenf=i; };
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
lenb=0;
|
|
272
|
+
if(scan<req.newsize) {
|
|
273
|
+
s=0;Sb=0;
|
|
274
|
+
for(i=1;(scan>=lastscan+i)&&(pos>=i);i++) {
|
|
275
|
+
if(req.old[pos-i]==req.new[scan-i]) s++;
|
|
276
|
+
if(s*2-i>Sb*2-lenb) { Sb=s; lenb=i; };
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
if(lastscan+lenf>scan-lenb) {
|
|
281
|
+
overlap=(lastscan+lenf)-(scan-lenb);
|
|
282
|
+
s=0;Ss=0;lens=0;
|
|
283
|
+
for(i=0;i<overlap;i++) {
|
|
284
|
+
if(req.new[lastscan+lenf-overlap+i]==
|
|
285
|
+
req.old[lastpos+lenf-overlap+i]) s++;
|
|
286
|
+
if(req.new[scan-lenb+i]==
|
|
287
|
+
req.old[pos-lenb+i]) s--;
|
|
288
|
+
if(s>Ss) { Ss=s; lens=i+1; };
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
lenf+=lens-overlap;
|
|
292
|
+
lenb-=lens;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
offtout(lenf,buf);
|
|
296
|
+
offtout((scan-lenb)-(lastscan+lenf),buf+8);
|
|
297
|
+
offtout((pos-lenb)-(lastpos+lenf),buf+16);
|
|
298
|
+
|
|
299
|
+
/* Write control data */
|
|
300
|
+
if (writedata(req.stream, buf, sizeof(buf)))
|
|
301
|
+
return -1;
|
|
302
|
+
|
|
303
|
+
/* Write diff data */
|
|
304
|
+
for(i=0;i<lenf;i++)
|
|
305
|
+
buffer[i]=req.new[lastscan+i]-req.old[lastpos+i];
|
|
306
|
+
if (writedata(req.stream, buffer, lenf))
|
|
307
|
+
return -1;
|
|
308
|
+
|
|
309
|
+
/* Write extra data */
|
|
310
|
+
for(i=0;i<(scan-lenb)-(lastscan+lenf);i++)
|
|
311
|
+
buffer[i]=req.new[lastscan+lenf+i];
|
|
312
|
+
if (writedata(req.stream, buffer, (scan-lenb)-(lastscan+lenf)))
|
|
313
|
+
return -1;
|
|
314
|
+
|
|
315
|
+
lastscan=scan-lenb;
|
|
316
|
+
lastpos=pos-lenb;
|
|
317
|
+
lastoffset=pos-scan;
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream)
|
|
325
|
+
{
|
|
326
|
+
int result;
|
|
327
|
+
struct bsdiff_request req;
|
|
328
|
+
|
|
329
|
+
if((req.I=stream->malloc((oldsize+1)*sizeof(int64_t)))==NULL)
|
|
330
|
+
return -1;
|
|
331
|
+
|
|
332
|
+
if((req.buffer=stream->malloc(newsize+1))==NULL)
|
|
333
|
+
{
|
|
334
|
+
stream->free(req.I);
|
|
335
|
+
return -1;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
req.old = old;
|
|
339
|
+
req.oldsize = oldsize;
|
|
340
|
+
req.new = new;
|
|
341
|
+
req.newsize = newsize;
|
|
342
|
+
req.stream = stream;
|
|
343
|
+
|
|
344
|
+
result = bsdiff_internal(req);
|
|
345
|
+
|
|
346
|
+
stream->free(req.buffer);
|
|
347
|
+
stream->free(req.I);
|
|
348
|
+
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
#if defined(BSDIFF_EXECUTABLE)
|
|
353
|
+
|
|
354
|
+
#include <sys/types.h>
|
|
355
|
+
|
|
356
|
+
#include <bzlib.h>
|
|
357
|
+
#include <err.h>
|
|
358
|
+
#include <fcntl.h>
|
|
359
|
+
#include <stdio.h>
|
|
360
|
+
#include <stdlib.h>
|
|
361
|
+
#include <unistd.h>
|
|
362
|
+
|
|
363
|
+
static int bz2_write(struct bsdiff_stream* stream, const void* buffer, int size)
|
|
364
|
+
{
|
|
365
|
+
int bz2err;
|
|
366
|
+
BZFILE* bz2;
|
|
367
|
+
|
|
368
|
+
bz2 = (BZFILE*)stream->opaque;
|
|
369
|
+
BZ2_bzWrite(&bz2err, bz2, (void*)buffer, size);
|
|
370
|
+
if (bz2err != BZ_STREAM_END && bz2err != BZ_OK)
|
|
371
|
+
return -1;
|
|
372
|
+
|
|
373
|
+
return 0;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
int main(int argc,char *argv[])
|
|
377
|
+
{
|
|
378
|
+
int fd;
|
|
379
|
+
int bz2err;
|
|
380
|
+
uint8_t *old,*new;
|
|
381
|
+
off_t oldsize,newsize;
|
|
382
|
+
uint8_t buf[8];
|
|
383
|
+
FILE * pf;
|
|
384
|
+
struct bsdiff_stream stream;
|
|
385
|
+
BZFILE* bz2;
|
|
386
|
+
|
|
387
|
+
memset(&bz2, 0, sizeof(bz2));
|
|
388
|
+
stream.malloc = malloc;
|
|
389
|
+
stream.free = free;
|
|
390
|
+
stream.write = bz2_write;
|
|
391
|
+
|
|
392
|
+
if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
|
|
393
|
+
|
|
394
|
+
/* Allocate oldsize+1 bytes instead of oldsize bytes to ensure
|
|
395
|
+
that we never try to malloc(0) and get a NULL pointer */
|
|
396
|
+
if(((fd=open(argv[1],O_RDONLY,0))<0) ||
|
|
397
|
+
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
|
|
398
|
+
((old=malloc(oldsize+1))==NULL) ||
|
|
399
|
+
(lseek(fd,0,SEEK_SET)!=0) ||
|
|
400
|
+
(read(fd,old,oldsize)!=oldsize) ||
|
|
401
|
+
(close(fd)==-1)) err(1,"%s",argv[1]);
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
/* Allocate newsize+1 bytes instead of newsize bytes to ensure
|
|
405
|
+
that we never try to malloc(0) and get a NULL pointer */
|
|
406
|
+
if(((fd=open(argv[2],O_RDONLY,0))<0) ||
|
|
407
|
+
((newsize=lseek(fd,0,SEEK_END))==-1) ||
|
|
408
|
+
((new=malloc(newsize+1))==NULL) ||
|
|
409
|
+
(lseek(fd,0,SEEK_SET)!=0) ||
|
|
410
|
+
(read(fd,new,newsize)!=newsize) ||
|
|
411
|
+
(close(fd)==-1)) err(1,"%s",argv[2]);
|
|
412
|
+
|
|
413
|
+
/* Create the patch file */
|
|
414
|
+
if ((pf = fopen(argv[3], "w")) == NULL)
|
|
415
|
+
err(1, "%s", argv[3]);
|
|
416
|
+
|
|
417
|
+
/* Write header (signature+newsize)*/
|
|
418
|
+
offtout(newsize, buf);
|
|
419
|
+
if (fwrite("ENDSLEY/BSDIFF43", 16, 1, pf) != 1 ||
|
|
420
|
+
fwrite(buf, sizeof(buf), 1, pf) != 1)
|
|
421
|
+
err(1, "Failed to write header");
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
if (NULL == (bz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)))
|
|
425
|
+
errx(1, "BZ2_bzWriteOpen, bz2err=%d", bz2err);
|
|
426
|
+
|
|
427
|
+
stream.opaque = bz2;
|
|
428
|
+
if (bsdiff(old, oldsize, new, newsize, &stream))
|
|
429
|
+
err(1, "bsdiff");
|
|
430
|
+
|
|
431
|
+
BZ2_bzWriteClose(&bz2err, bz2, 0, NULL, NULL);
|
|
432
|
+
if (bz2err != BZ_OK)
|
|
433
|
+
err(1, "BZ2_bzWriteClose, bz2err=%d", bz2err);
|
|
434
|
+
|
|
435
|
+
if (fclose(pf))
|
|
436
|
+
err(1, "fclose");
|
|
437
|
+
|
|
438
|
+
/* Free the memory we used */
|
|
439
|
+
free(old);
|
|
440
|
+
free(new);
|
|
441
|
+
|
|
442
|
+
return 0;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
#endif
|
package/tools/bsdiff.h
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright 2003-2005 Colin Percival
|
|
3
|
+
* Copyright 2012 Matthew Endsley
|
|
4
|
+
* All rights reserved
|
|
5
|
+
*
|
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
|
7
|
+
* modification, are permitted providing that the following conditions
|
|
8
|
+
* are met:
|
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
|
14
|
+
*
|
|
15
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
16
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
17
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
18
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
19
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
21
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
22
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
23
|
+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
24
|
+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
25
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifndef BSDIFF_H
|
|
29
|
+
# define BSDIFF_H
|
|
30
|
+
|
|
31
|
+
# include <stddef.h>
|
|
32
|
+
# include <stdint.h>
|
|
33
|
+
|
|
34
|
+
struct bsdiff_stream
|
|
35
|
+
{
|
|
36
|
+
void* opaque;
|
|
37
|
+
|
|
38
|
+
void* (*malloc)(size_t size);
|
|
39
|
+
void (*free)(void* ptr);
|
|
40
|
+
int (*write)(struct bsdiff_stream* stream, const void* buffer, int size);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
int bsdiff(const uint8_t* old, int64_t oldsize, const uint8_t* new, int64_t newsize, struct bsdiff_stream* stream);
|
|
44
|
+
|
|
45
|
+
#endif
|