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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +471 -0
  3. package/android/build.gradle +100 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/vn/reactnativebspatch/BsPatchModule.kt +139 -0
  6. package/android/src/main/java/vn/reactnativebspatch/BsPatchPackage.kt +16 -0
  7. package/android/src/main/java/vn/reactnativebspatch/OtaBundleResolver.kt +227 -0
  8. package/cpp/CMakeLists.txt +43 -0
  9. package/cpp/bsdiff/bspatch.c +194 -0
  10. package/cpp/bsdiff/bspatch.h +41 -0
  11. package/cpp/bsdiff/bspatch_wrapper.c +150 -0
  12. package/cpp/bsdiff/bspatch_wrapper.h +6 -0
  13. package/cpp/bspatch_jni.cpp +41 -0
  14. package/cpp/bzip2/LICENSE +42 -0
  15. package/cpp/bzip2/blocksort.c +1094 -0
  16. package/cpp/bzip2/bzlib.c +1572 -0
  17. package/cpp/bzip2/bzlib.h +282 -0
  18. package/cpp/bzip2/bzlib_private.h +509 -0
  19. package/cpp/bzip2/compress.c +672 -0
  20. package/cpp/bzip2/crctable.c +104 -0
  21. package/cpp/bzip2/decompress.c +652 -0
  22. package/cpp/bzip2/huffman.c +205 -0
  23. package/cpp/bzip2/randtable.c +84 -0
  24. package/ios/OtaBundleResolver.swift +241 -0
  25. package/ios/RNBsPatch.h +8 -0
  26. package/ios/RNBsPatch.mm +198 -0
  27. package/lib/commonjs/NativeBsPatch.js +9 -0
  28. package/lib/commonjs/NativeBsPatch.js.map +1 -0
  29. package/lib/commonjs/crypto-js.d.js +2 -0
  30. package/lib/commonjs/crypto-js.d.js.map +1 -0
  31. package/lib/commonjs/index.js +90 -0
  32. package/lib/commonjs/index.js.map +1 -0
  33. package/lib/commonjs/ota/OtaProvider.js +306 -0
  34. package/lib/commonjs/ota/OtaProvider.js.map +1 -0
  35. package/lib/commonjs/ota/otaAssetResolver.js +145 -0
  36. package/lib/commonjs/ota/otaAssetResolver.js.map +1 -0
  37. package/lib/commonjs/ota/otaCore.js +736 -0
  38. package/lib/commonjs/ota/otaCore.js.map +1 -0
  39. package/lib/commonjs/ota/otaLogger.js +64 -0
  40. package/lib/commonjs/ota/otaLogger.js.map +1 -0
  41. package/lib/commonjs/ota/otaMetadata.js +138 -0
  42. package/lib/commonjs/ota/otaMetadata.js.map +1 -0
  43. package/lib/commonjs/ota/storage/CustomStorage.js +140 -0
  44. package/lib/commonjs/ota/storage/CustomStorage.js.map +1 -0
  45. package/lib/commonjs/ota/storage/GitHubReleaseStorage.js +96 -0
  46. package/lib/commonjs/ota/storage/GitHubReleaseStorage.js.map +1 -0
  47. package/lib/commonjs/ota/types.js +39 -0
  48. package/lib/commonjs/ota/types.js.map +1 -0
  49. package/lib/commonjs/package.json +1 -0
  50. package/lib/module/NativeBsPatch.js +5 -0
  51. package/lib/module/NativeBsPatch.js.map +1 -0
  52. package/lib/module/crypto-js.d.js +2 -0
  53. package/lib/module/crypto-js.d.js.map +1 -0
  54. package/lib/module/index.js +23 -0
  55. package/lib/module/index.js.map +1 -0
  56. package/lib/module/ota/OtaProvider.js +299 -0
  57. package/lib/module/ota/OtaProvider.js.map +1 -0
  58. package/lib/module/ota/otaAssetResolver.js +138 -0
  59. package/lib/module/ota/otaAssetResolver.js.map +1 -0
  60. package/lib/module/ota/otaCore.js +725 -0
  61. package/lib/module/ota/otaCore.js.map +1 -0
  62. package/lib/module/ota/otaLogger.js +59 -0
  63. package/lib/module/ota/otaLogger.js.map +1 -0
  64. package/lib/module/ota/otaMetadata.js +127 -0
  65. package/lib/module/ota/otaMetadata.js.map +1 -0
  66. package/lib/module/ota/storage/CustomStorage.js +134 -0
  67. package/lib/module/ota/storage/CustomStorage.js.map +1 -0
  68. package/lib/module/ota/storage/GitHubReleaseStorage.js +90 -0
  69. package/lib/module/ota/storage/GitHubReleaseStorage.js.map +1 -0
  70. package/lib/module/ota/types.js +38 -0
  71. package/lib/module/ota/types.js.map +1 -0
  72. package/lib/typescript/NativeBsPatch.d.ts +39 -0
  73. package/lib/typescript/NativeBsPatch.d.ts.map +1 -0
  74. package/lib/typescript/index.d.ts +15 -0
  75. package/lib/typescript/index.d.ts.map +1 -0
  76. package/lib/typescript/ota/OtaProvider.d.ts +10 -0
  77. package/lib/typescript/ota/OtaProvider.d.ts.map +1 -0
  78. package/lib/typescript/ota/otaAssetResolver.d.ts +15 -0
  79. package/lib/typescript/ota/otaAssetResolver.d.ts.map +1 -0
  80. package/lib/typescript/ota/otaCore.d.ts +109 -0
  81. package/lib/typescript/ota/otaCore.d.ts.map +1 -0
  82. package/lib/typescript/ota/otaLogger.d.ts +44 -0
  83. package/lib/typescript/ota/otaLogger.d.ts.map +1 -0
  84. package/lib/typescript/ota/otaMetadata.d.ts +46 -0
  85. package/lib/typescript/ota/otaMetadata.d.ts.map +1 -0
  86. package/lib/typescript/ota/storage/CustomStorage.d.ts +12 -0
  87. package/lib/typescript/ota/storage/CustomStorage.d.ts.map +1 -0
  88. package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts +20 -0
  89. package/lib/typescript/ota/storage/GitHubReleaseStorage.d.ts.map +1 -0
  90. package/lib/typescript/ota/types.d.ts +191 -0
  91. package/lib/typescript/ota/types.d.ts.map +1 -0
  92. package/package.json +89 -0
  93. package/react-native-bspatch.podspec +46 -0
  94. package/src/NativeBsPatch.ts +52 -0
  95. package/src/crypto-js.d.ts +1 -0
  96. package/src/index.ts +29 -0
  97. package/src/ota/OtaProvider.tsx +399 -0
  98. package/src/ota/otaAssetResolver.ts +182 -0
  99. package/src/ota/otaCore.ts +963 -0
  100. package/src/ota/otaLogger.ts +72 -0
  101. package/src/ota/otaMetadata.ts +149 -0
  102. package/src/ota/storage/CustomStorage.ts +143 -0
  103. package/src/ota/storage/GitHubReleaseStorage.ts +98 -0
  104. package/src/ota/types.ts +211 -0
  105. package/tools/bsdiff +0 -0
  106. package/tools/bsdiff.c +445 -0
  107. package/tools/bsdiff.h +45 -0
  108. package/tools/build_ota.sh +457 -0
  109. package/tools/setup_project.js +273 -0
  110. package/tools/update_registry.js +145 -0
  111. package/tools/upload_ota_custom.sh +138 -0
@@ -0,0 +1,150 @@
1
+ #include <bzlib.h>
2
+ #include <stdlib.h>
3
+ #include <stdint.h>
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+ #include <sys/types.h>
7
+ #include <sys/stat.h>
8
+ #include <unistd.h>
9
+ #include <fcntl.h>
10
+ #include "bspatch.h"
11
+ #include "bspatch_wrapper.h"
12
+
13
+ #ifdef __ANDROID__
14
+ #include <android/log.h>
15
+ #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "bspatch", __VA_ARGS__)
16
+ #else
17
+ #define LOGE(...)
18
+ #endif
19
+
20
+ static int64_t wrapper_offtin(uint8_t *buf)
21
+ {
22
+ int64_t y;
23
+
24
+ y=buf[7]&0x7F;
25
+ y=y*256;y+=buf[6];
26
+ y=y*256;y+=buf[5];
27
+ y=y*256;y+=buf[4];
28
+ y=y*256;y+=buf[3];
29
+ y=y*256;y+=buf[2];
30
+ y=y*256;y+=buf[1];
31
+ y=y*256;y+=buf[0];
32
+
33
+ if(buf[7]&0x80) y=-y;
34
+
35
+ return y;
36
+ }
37
+
38
+ static int bz2_read(const struct bspatch_stream* stream, void* buffer, int length)
39
+ {
40
+ int n;
41
+ int bz2err;
42
+ BZFILE* bz2;
43
+
44
+ bz2 = (BZFILE*)stream->opaque;
45
+ n = BZ2_bzRead(&bz2err, bz2, buffer, length);
46
+ if (n != length)
47
+ return -1;
48
+
49
+ return 0;
50
+ }
51
+
52
+ int apply_bspatch(const char *oldfile, const char *newfile, const char *patchfile)
53
+ {
54
+ FILE * f;
55
+ int fd = -1;
56
+ int bz2err;
57
+ uint8_t header[24];
58
+ uint8_t *old = NULL, *new_buf = NULL;
59
+ int64_t oldsize, newsize;
60
+ BZFILE* bz2 = NULL;
61
+ struct bspatch_stream stream;
62
+ struct stat sb;
63
+
64
+ /* Open patch file */
65
+ if ((f = fopen(patchfile, "r")) == NULL) {
66
+ LOGE("Failed to open patch file: %s", patchfile);
67
+ return -1;
68
+ }
69
+
70
+ /* Read header */
71
+ if (fread(header, 1, 24, f) != 24) {
72
+ LOGE("Failed to read header from patch file");
73
+ fclose(f);
74
+ return -1;
75
+ }
76
+
77
+ /* Check for appropriate magic */
78
+ if (memcmp(header, "ENDSLEY/BSDIFF43", 16) != 0) {
79
+ LOGE("Invalid magic in patch header");
80
+ fclose(f);
81
+ return -1;
82
+ }
83
+
84
+ /* Read lengths from header */
85
+ newsize = wrapper_offtin(header + 16);
86
+ if(newsize < 0) {
87
+ LOGE("Invalid newsize in patch header");
88
+ fclose(f);
89
+ return -1;
90
+ }
91
+
92
+ /* Close patch file and re-open it via libbzip2 at the right places */
93
+ if(((fd=open(oldfile,O_RDONLY,0))<0) ||
94
+ ((oldsize=lseek(fd,0,SEEK_END))==-1) ||
95
+ ((old=malloc(oldsize+1))==NULL) ||
96
+ (lseek(fd,0,SEEK_SET)!=0) ||
97
+ (read(fd,old,oldsize)!=oldsize) ||
98
+ (fstat(fd, &sb)) ||
99
+ (close(fd)==-1)) {
100
+ LOGE("Failed reading oldfile (fd=%d, oldsize=%lld)", fd, (long long)oldsize);
101
+ if (fd >= 0) close(fd);
102
+ if (old) free(old);
103
+ fclose(f);
104
+ return -1;
105
+ }
106
+
107
+ if((new_buf=malloc(newsize+1))==NULL) {
108
+ LOGE("Failed to allocate memory for new_buf (%lld)", (long long)newsize);
109
+ free(old);
110
+ fclose(f);
111
+ return -1;
112
+ }
113
+
114
+ if (NULL == (bz2 = BZ2_bzReadOpen(&bz2err, f, 0, 0, NULL, 0))) {
115
+ LOGE("BZ2_bzReadOpen failed: err=%d", bz2err);
116
+ free(new_buf);
117
+ free(old);
118
+ fclose(f);
119
+ return -1;
120
+ }
121
+
122
+ stream.read = bz2_read;
123
+ stream.opaque = bz2;
124
+ if (bspatch(old, oldsize, new_buf, newsize, &stream)) {
125
+ LOGE("bspatch core logic failed");
126
+ BZ2_bzReadClose(&bz2err, bz2);
127
+ free(new_buf);
128
+ free(old);
129
+ fclose(f);
130
+ return -1;
131
+ }
132
+
133
+ /* Clean up the bzip2 reads */
134
+ BZ2_bzReadClose(&bz2err, bz2);
135
+ fclose(f);
136
+
137
+ /* Write the new file */
138
+ if(((fd=open(newfile,O_CREAT|O_TRUNC|O_WRONLY,sb.st_mode))<0) ||
139
+ (write(fd,new_buf,newsize)!=newsize) || (close(fd)==-1)) {
140
+ if (fd >= 0) close(fd);
141
+ free(new_buf);
142
+ free(old);
143
+ return -1;
144
+ }
145
+
146
+ free(new_buf);
147
+ free(old);
148
+
149
+ return 0; // Success
150
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef BSPATCH_WRAPPER_H
2
+ #define BSPATCH_WRAPPER_H
3
+
4
+ int apply_bspatch(const char *oldfile, const char *newfile, const char *patchfile);
5
+
6
+ #endif // BSPATCH_WRAPPER_H
@@ -0,0 +1,41 @@
1
+ #ifdef __ANDROID__
2
+ #include <jni.h>
3
+ #include <string>
4
+ extern "C" {
5
+ #include "bsdiff/bspatch_wrapper.h"
6
+ }
7
+ #include <android/log.h>
8
+
9
+ #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "bspatch", __VA_ARGS__)
10
+ #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "bspatch", __VA_ARGS__)
11
+
12
+ extern "C" JNIEXPORT jboolean JNICALL
13
+ Java_vn_reactnativebspatch_BsPatchModule_nativeApplyPatch(
14
+ JNIEnv* env,
15
+ jobject /* this */,
16
+ jstring oldPath,
17
+ jstring newPath,
18
+ jstring patchPath) {
19
+
20
+ const char *old_file = env->GetStringUTFChars(oldPath, 0);
21
+ const char *new_file = env->GetStringUTFChars(newPath, 0);
22
+ const char *patch_file = env->GetStringUTFChars(patchPath, 0);
23
+
24
+ LOGI("Applying patch: old=%s, new=%s, patch=%s", old_file, new_file, patch_file);
25
+
26
+ // Call the C wrapper
27
+ int result = apply_bspatch(old_file, new_file, patch_file);
28
+
29
+ LOGI("apply_bspatch result = %d", result);
30
+
31
+ env->ReleaseStringUTFChars(oldPath, old_file);
32
+ env->ReleaseStringUTFChars(newPath, new_file);
33
+ env->ReleaseStringUTFChars(patchPath, patch_file);
34
+
35
+ if (result != 0) {
36
+ LOGE("apply_bspatch failed with code %d", result);
37
+ }
38
+
39
+ return (result == 0) ? JNI_TRUE : JNI_FALSE;
40
+ }
41
+ #endif
@@ -0,0 +1,42 @@
1
+
2
+ --------------------------------------------------------------------------
3
+
4
+ This program, "bzip2", the associated library "libbzip2", and all
5
+ documentation, are copyright (C) 1996-2019 Julian R Seward. All
6
+ rights reserved.
7
+
8
+ Redistribution and use in source and binary forms, with or without
9
+ modification, are permitted provided that the following conditions
10
+ are met:
11
+
12
+ 1. Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+
15
+ 2. The origin of this software must not be misrepresented; you must
16
+ not claim that you wrote the original software. If you use this
17
+ software in a product, an acknowledgment in the product
18
+ documentation would be appreciated but is not required.
19
+
20
+ 3. Altered source versions must be plainly marked as such, and must
21
+ not be misrepresented as being the original software.
22
+
23
+ 4. The name of the author may not be used to endorse or promote
24
+ products derived from this software without specific prior written
25
+ permission.
26
+
27
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
28
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
31
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+
39
+ Julian Seward, jseward@acm.org
40
+ bzip2/libbzip2 version 1.0.8 of 13 July 2019
41
+
42
+ --------------------------------------------------------------------------