react-native-stallion 2.4.0-alpha.3 → 2.4.0-alpha.5
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/android/src/main/cpp/CMakeLists.txt +41 -0
- package/android/src/main/cpp/bspatch_bridge.c +268 -0
- package/android/src/main/cpp/bspatch_bridge.h +26 -0
- package/android/src/main/cpp/bzip2/blocksort.c +1094 -0
- package/android/src/main/cpp/bzip2/bzlib.c +1572 -0
- package/android/src/main/cpp/bzip2/bzlib.h +282 -0
- package/android/src/main/cpp/bzip2/bzlib_private.h +509 -0
- package/android/src/main/cpp/bzip2/compress.c +672 -0
- package/android/src/main/cpp/bzip2/crctable.c +104 -0
- package/android/src/main/cpp/bzip2/decompress.c +652 -0
- package/android/src/main/cpp/bzip2/huffman.c +205 -0
- package/android/src/main/cpp/bzip2/randtable.c +84 -0
- package/android/src/main/cpp/stallion_bspatch_jni.cpp +39 -0
- package/android/src/main/java/com/stallion/StallionModule.java +13 -1
- package/android/src/main/java/com/stallion/networkmanager/StallionPatchHandler.java +222 -0
- package/android/src/main/java/com/stallion/networkmanager/StallionSyncHandler.java +88 -16
- package/android/src/main/java/com/stallion/storage/StallionMeta.java +12 -0
- package/android/src/main/java/com/stallion/storage/StallionStateManager.java +25 -0
- package/android/src/main/java/com/stallion/utils/StallionBSPatch.java +30 -0
- package/ios/Stallion.xcodeproj/project.pbxproj +6 -0
- package/ios/main/Stallion-Bridging-Header.h +1 -0
- package/ios/main/Stallion.m +22 -0
- package/ios/main/Stallion.swift +8 -1
- package/ios/main/StallionBSPatch.swift +35 -0
- package/ios/main/StallionMeta.h +1 -0
- package/ios/main/StallionMeta.m +12 -0
- package/ios/main/StallionModule.m +3 -3
- package/ios/main/StallionPatchHandler.swift +206 -0
- package/ios/main/StallionSignatureVerification.swift +1 -1
- package/ios/main/StallionStateManager.h +3 -0
- package/ios/main/StallionStateManager.m +3 -0
- package/ios/main/StallionSyncHandler.swift +86 -10
- package/ios/main/bspatch.c +270 -0
- package/ios/main/bspatch_bridge.h +25 -0
- package/package.json +1 -1
- package/react-native-stallion.podspec +3 -1
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/main/utils/StallionNativeUtils.js +3 -0
- package/src/main/utils/StallionNativeUtils.js.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/main/utils/StallionNativeUtils.d.ts +2 -1
- package/types/main/utils/StallionNativeUtils.d.ts.map +1 -1
- package/types/types/utils.types.d.ts +1 -0
- package/types/types/utils.types.d.ts.map +1 -1
|
@@ -8,6 +8,34 @@ add_library(
|
|
|
8
8
|
stallion_signal_handler.cpp
|
|
9
9
|
)
|
|
10
10
|
|
|
11
|
+
# Build bzip2 as a static library
|
|
12
|
+
# Using the same bzip2 that works in iOS and CLI
|
|
13
|
+
add_library(
|
|
14
|
+
bzip2_static
|
|
15
|
+
STATIC
|
|
16
|
+
bzip2/blocksort.c
|
|
17
|
+
bzip2/huffman.c
|
|
18
|
+
bzip2/crctable.c
|
|
19
|
+
bzip2/randtable.c
|
|
20
|
+
bzip2/compress.c
|
|
21
|
+
bzip2/decompress.c
|
|
22
|
+
bzip2/bzlib.c
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Include bzip2 headers
|
|
26
|
+
target_include_directories(
|
|
27
|
+
bzip2_static
|
|
28
|
+
PUBLIC
|
|
29
|
+
${CMAKE_CURRENT_SOURCE_DIR}/bzip2
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
add_library(
|
|
33
|
+
stallion-bspatch
|
|
34
|
+
SHARED
|
|
35
|
+
bspatch_bridge.c
|
|
36
|
+
stallion_bspatch_jni.cpp
|
|
37
|
+
)
|
|
38
|
+
|
|
11
39
|
find_library(
|
|
12
40
|
log-lib
|
|
13
41
|
log
|
|
@@ -18,6 +46,19 @@ target_link_libraries(
|
|
|
18
46
|
${log-lib}
|
|
19
47
|
)
|
|
20
48
|
|
|
49
|
+
target_link_libraries(
|
|
50
|
+
stallion-bspatch
|
|
51
|
+
${log-lib}
|
|
52
|
+
bzip2_static
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Include bzip2 headers for bspatch
|
|
56
|
+
target_include_directories(
|
|
57
|
+
stallion-bspatch
|
|
58
|
+
PRIVATE
|
|
59
|
+
${CMAKE_CURRENT_SOURCE_DIR}/bzip2
|
|
60
|
+
)
|
|
61
|
+
|
|
21
62
|
# Fix for 16KB page size compatibility (required for Android 15+)
|
|
22
63
|
# This ensures LOAD segments are aligned at 16KB boundaries
|
|
23
64
|
set_target_properties(stallion-crash PROPERTIES
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
//
|
|
2
|
+
// bspatch_bridge.c
|
|
3
|
+
// react-native-stallion
|
|
4
|
+
//
|
|
5
|
+
// Bridge implementation for Android - adapts shared bspatch.c to function interface
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#include "bspatch_bridge.h"
|
|
9
|
+
#include <bzlib.h>
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
#include <stdio.h>
|
|
12
|
+
#include <string.h>
|
|
13
|
+
#include <errno.h>
|
|
14
|
+
#include <sys/types.h>
|
|
15
|
+
#include <unistd.h>
|
|
16
|
+
#include <fcntl.h>
|
|
17
|
+
|
|
18
|
+
// Error codes (negative)
|
|
19
|
+
#define BSPATCH_ERR_OPEN_OLD -1
|
|
20
|
+
#define BSPATCH_ERR_OPEN_NEW -2
|
|
21
|
+
#define BSPATCH_ERR_OPEN_PATCH -3
|
|
22
|
+
#define BSPATCH_ERR_READ_HDR -4
|
|
23
|
+
#define BSPATCH_ERR_BAD_MAGIC -5
|
|
24
|
+
#define BSPATCH_ERR_READ_CTRL -6
|
|
25
|
+
#define BSPATCH_ERR_READ_DIFF -7
|
|
26
|
+
#define BSPATCH_ERR_READ_EXTRA -8
|
|
27
|
+
#define BSPATCH_ERR_SEEK_OLD -9
|
|
28
|
+
#define BSPATCH_ERR_WRITE_NEW -10
|
|
29
|
+
#define BSPATCH_ERR_BZ2_ERROR -11
|
|
30
|
+
#define BSPATCH_ERR_OVERFLOW -12
|
|
31
|
+
|
|
32
|
+
/* Type compatibility */
|
|
33
|
+
#ifndef u_char
|
|
34
|
+
#define u_char unsigned char
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
static off_t offtin(u_char *buf)
|
|
38
|
+
{
|
|
39
|
+
off_t y;
|
|
40
|
+
|
|
41
|
+
y=buf[7]&0x7F;
|
|
42
|
+
y=y*256;y+=buf[6];
|
|
43
|
+
y=y*256;y+=buf[5];
|
|
44
|
+
y=y*256;y+=buf[4];
|
|
45
|
+
y=y*256;y+=buf[3];
|
|
46
|
+
y=y*256;y+=buf[2];
|
|
47
|
+
y=y*256;y+=buf[1];
|
|
48
|
+
y=y*256;y+=buf[0];
|
|
49
|
+
|
|
50
|
+
if(buf[7]&0x80) y=-y;
|
|
51
|
+
|
|
52
|
+
return y;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
int bspatch_apply(const char *oldPath, const char *newPath, const char *patchPath) {
|
|
56
|
+
FILE * f = NULL, * cpf = NULL, * dpf = NULL, * epf = NULL;
|
|
57
|
+
BZFILE * cpfbz2 = NULL, * dpfbz2 = NULL, * epfbz2 = NULL;
|
|
58
|
+
int cbz2err, dbz2err, ebz2err;
|
|
59
|
+
int fd = -1;
|
|
60
|
+
ssize_t oldsize,newsize;
|
|
61
|
+
ssize_t bzctrllen,bzdatalen;
|
|
62
|
+
u_char header[32],buf[8];
|
|
63
|
+
u_char *old = NULL, *new = NULL;
|
|
64
|
+
off_t oldpos,newpos;
|
|
65
|
+
off_t ctrl[3];
|
|
66
|
+
off_t lenread;
|
|
67
|
+
off_t i;
|
|
68
|
+
int ret = 0;
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
File format:
|
|
72
|
+
0 8 "BSDIFF40"
|
|
73
|
+
8 8 X
|
|
74
|
+
16 8 Y
|
|
75
|
+
24 8 sizeof(newfile)
|
|
76
|
+
32 X bzip2(control block)
|
|
77
|
+
32+X Y bzip2(diff block)
|
|
78
|
+
32+X+Y ??? bzip2(extra block)
|
|
79
|
+
with control block a set of triples (x,y,z) meaning "add x bytes
|
|
80
|
+
from oldfile to x bytes from the diff block; copy y bytes from the
|
|
81
|
+
extra block; seek forwards in oldfile by z bytes".
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/* Open patch file */
|
|
85
|
+
if ((f = fopen(patchPath, "rb")) == NULL) {
|
|
86
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
87
|
+
goto cleanup;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Read header */
|
|
91
|
+
if (fread(header, 1, 32, f) < 32) {
|
|
92
|
+
ret = BSPATCH_ERR_READ_HDR;
|
|
93
|
+
goto cleanup;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* Check for appropriate magic */
|
|
97
|
+
if (memcmp(header, "BSDIFF40", 8) != 0) {
|
|
98
|
+
ret = BSPATCH_ERR_BAD_MAGIC;
|
|
99
|
+
goto cleanup;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Read lengths from header */
|
|
103
|
+
bzctrllen=offtin(header+8);
|
|
104
|
+
bzdatalen=offtin(header+16);
|
|
105
|
+
newsize=offtin(header+24);
|
|
106
|
+
if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) {
|
|
107
|
+
ret = BSPATCH_ERR_OVERFLOW;
|
|
108
|
+
goto cleanup;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Close patch file and re-open it via libbzip2 at the right places */
|
|
112
|
+
if (fclose(f)) {
|
|
113
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
114
|
+
goto cleanup;
|
|
115
|
+
}
|
|
116
|
+
f = NULL;
|
|
117
|
+
|
|
118
|
+
/* Open control stream */
|
|
119
|
+
if ((cpf = fopen(patchPath, "rb")) == NULL) {
|
|
120
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
121
|
+
goto cleanup;
|
|
122
|
+
}
|
|
123
|
+
if (fseeko(cpf, 32, SEEK_SET)) {
|
|
124
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
125
|
+
goto cleanup;
|
|
126
|
+
}
|
|
127
|
+
if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) {
|
|
128
|
+
ret = BSPATCH_ERR_BZ2_ERROR;
|
|
129
|
+
goto cleanup;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* Open diff stream */
|
|
133
|
+
if ((dpf = fopen(patchPath, "rb")) == NULL) {
|
|
134
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
135
|
+
goto cleanup;
|
|
136
|
+
}
|
|
137
|
+
if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) {
|
|
138
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
139
|
+
goto cleanup;
|
|
140
|
+
}
|
|
141
|
+
if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) {
|
|
142
|
+
ret = BSPATCH_ERR_BZ2_ERROR;
|
|
143
|
+
goto cleanup;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Open extra stream */
|
|
147
|
+
if ((epf = fopen(patchPath, "rb")) == NULL) {
|
|
148
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
149
|
+
goto cleanup;
|
|
150
|
+
}
|
|
151
|
+
if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) {
|
|
152
|
+
ret = BSPATCH_ERR_OPEN_PATCH;
|
|
153
|
+
goto cleanup;
|
|
154
|
+
}
|
|
155
|
+
if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) {
|
|
156
|
+
ret = BSPATCH_ERR_BZ2_ERROR;
|
|
157
|
+
goto cleanup;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Load old file into memory */
|
|
161
|
+
if(((fd=open(oldPath,O_RDONLY,0))<0) ||
|
|
162
|
+
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
|
|
163
|
+
((old=malloc(oldsize+1))==NULL) ||
|
|
164
|
+
(lseek(fd,0,SEEK_SET)!=0) ||
|
|
165
|
+
(read(fd,old,oldsize)!=oldsize) ||
|
|
166
|
+
(close(fd)==-1)) {
|
|
167
|
+
if (fd >= 0) close(fd);
|
|
168
|
+
fd = -1;
|
|
169
|
+
ret = BSPATCH_ERR_OPEN_OLD;
|
|
170
|
+
goto cleanup;
|
|
171
|
+
}
|
|
172
|
+
fd = -1;
|
|
173
|
+
|
|
174
|
+
/* Allocate memory for new file */
|
|
175
|
+
if((new=malloc(newsize+1))==NULL) {
|
|
176
|
+
ret = BSPATCH_ERR_OVERFLOW;
|
|
177
|
+
goto cleanup;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
oldpos=0;newpos=0;
|
|
181
|
+
while(newpos<newsize) {
|
|
182
|
+
/* Read control data */
|
|
183
|
+
for(i=0;i<=2;i++) {
|
|
184
|
+
lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8);
|
|
185
|
+
if ((lenread < 8) || ((cbz2err != BZ_OK) &&
|
|
186
|
+
(cbz2err != BZ_STREAM_END))) {
|
|
187
|
+
ret = BSPATCH_ERR_READ_CTRL;
|
|
188
|
+
goto cleanup;
|
|
189
|
+
}
|
|
190
|
+
ctrl[i]=offtin(buf);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/* Sanity-check */
|
|
194
|
+
if(newpos+ctrl[0]>newsize) {
|
|
195
|
+
ret = BSPATCH_ERR_OVERFLOW;
|
|
196
|
+
goto cleanup;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* Read diff string */
|
|
200
|
+
lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]);
|
|
201
|
+
if ((lenread < ctrl[0]) ||
|
|
202
|
+
((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) {
|
|
203
|
+
ret = BSPATCH_ERR_READ_DIFF;
|
|
204
|
+
goto cleanup;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* Add old data to diff string */
|
|
208
|
+
for(i=0;i<ctrl[0];i++)
|
|
209
|
+
if((oldpos+i>=0) && (oldpos+i<oldsize))
|
|
210
|
+
new[newpos+i]+=old[oldpos+i];
|
|
211
|
+
|
|
212
|
+
/* Adjust pointers */
|
|
213
|
+
newpos+=ctrl[0];
|
|
214
|
+
oldpos+=ctrl[0];
|
|
215
|
+
|
|
216
|
+
/* Sanity-check */
|
|
217
|
+
if(newpos+ctrl[1]>newsize) {
|
|
218
|
+
ret = BSPATCH_ERR_OVERFLOW;
|
|
219
|
+
goto cleanup;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* Read extra string */
|
|
223
|
+
lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]);
|
|
224
|
+
if ((lenread < ctrl[1]) ||
|
|
225
|
+
((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) {
|
|
226
|
+
ret = BSPATCH_ERR_READ_EXTRA;
|
|
227
|
+
goto cleanup;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* Adjust pointers */
|
|
231
|
+
newpos+=ctrl[1];
|
|
232
|
+
oldpos+=ctrl[2];
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/* Clean up the bzip2 reads */
|
|
236
|
+
BZ2_bzReadClose(&cbz2err, cpfbz2);
|
|
237
|
+
cpfbz2 = NULL;
|
|
238
|
+
BZ2_bzReadClose(&dbz2err, dpfbz2);
|
|
239
|
+
dpfbz2 = NULL;
|
|
240
|
+
BZ2_bzReadClose(&ebz2err, epfbz2);
|
|
241
|
+
epfbz2 = NULL;
|
|
242
|
+
|
|
243
|
+
/* Write the new file */
|
|
244
|
+
if(((fd=open(newPath,O_CREAT|O_TRUNC|O_WRONLY,0666))<0) ||
|
|
245
|
+
(write(fd,new,newsize)!=newsize) || (close(fd)==-1)) {
|
|
246
|
+
if (fd >= 0) close(fd);
|
|
247
|
+
fd = -1;
|
|
248
|
+
ret = BSPATCH_ERR_WRITE_NEW;
|
|
249
|
+
goto cleanup;
|
|
250
|
+
}
|
|
251
|
+
fd = -1;
|
|
252
|
+
|
|
253
|
+
ret = 0;
|
|
254
|
+
|
|
255
|
+
cleanup:
|
|
256
|
+
if (cpfbz2) BZ2_bzReadClose(&cbz2err, cpfbz2);
|
|
257
|
+
if (dpfbz2) BZ2_bzReadClose(&dbz2err, dpfbz2);
|
|
258
|
+
if (epfbz2) BZ2_bzReadClose(&ebz2err, epfbz2);
|
|
259
|
+
if (f) fclose(f);
|
|
260
|
+
if (cpf) fclose(cpf);
|
|
261
|
+
if (dpf) fclose(dpf);
|
|
262
|
+
if (epf) fclose(epf);
|
|
263
|
+
if (fd >= 0) close(fd);
|
|
264
|
+
if (new) free(new);
|
|
265
|
+
if (old) free(old);
|
|
266
|
+
|
|
267
|
+
return ret;
|
|
268
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// bspatch_bridge.h
|
|
3
|
+
// react-native-stallion
|
|
4
|
+
//
|
|
5
|
+
// Bridge header for Android JNI
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef BSPATCH_BRIDGE_H
|
|
9
|
+
#define BSPATCH_BRIDGE_H
|
|
10
|
+
|
|
11
|
+
#include <stddef.h>
|
|
12
|
+
|
|
13
|
+
#ifdef __cplusplus
|
|
14
|
+
extern "C" {
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
// Apply a bsdiff patch file to oldPath, writing the result to newPath.
|
|
18
|
+
// Returns 0 on success, negative values on error.
|
|
19
|
+
int bspatch_apply(const char *oldPath, const char *newPath, const char *patchPath);
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
}
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#endif /* BSPATCH_BRIDGE_H */
|
|
26
|
+
|