├── .DS_Store ├── AndroidReactNativeBsidffBundle ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── LibBSdiff │ ├── .gitignore │ ├── build.gradle │ ├── jni │ │ ├── Android.mk │ │ ├── Application.mk │ │ ├── bzip2 │ │ │ ├── blocksort.c │ │ │ ├── bzip2.c │ │ │ ├── bzip2recover.c │ │ │ ├── bzlib.c │ │ │ ├── bzlib.h │ │ │ ├── bzlib_private.h │ │ │ ├── compress.c │ │ │ ├── crctable.c │ │ │ ├── decompress.c │ │ │ ├── huffman.c │ │ │ ├── randtable.c │ │ │ └── readMe.txt │ │ ├── com_pk_bsdiff_utils_PatchUtils.c │ │ └── com_pk_bsdiff_utils_PatchUtils.h │ ├── libs │ │ ├── armeabi-v7a │ │ │ └── libApkPatchLibrary.so │ │ ├── armeabi │ │ │ └── libApkPatchLibrary.so │ │ └── x86 │ │ │ └── libApkPatchLibrary.so │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── pk │ │ │ └── bsdiff │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── pk │ │ │ │ └── bsdiff │ │ │ │ └── utils │ │ │ │ └── PatchUtils.java │ │ ├── jniLibs │ │ │ ├── armeabi-v7a │ │ │ │ └── libApkPatchLibrary.so │ │ │ ├── armeabi │ │ │ │ └── libApkPatchLibrary.so │ │ │ └── x86 │ │ │ │ └── libApkPatchLibrary.so │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── pk │ │ └── bsdiff │ │ └── ExampleUnitTest.java ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── pk │ │ │ └── com │ │ │ └── reactnativebsidffbundle │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ │ ├── module.json │ │ │ └── rn │ │ │ │ ├── common.js │ │ │ │ └── patchs │ │ │ │ ├── 10001.patch │ │ │ │ └── 10002.patch │ │ ├── java │ │ │ └── pk │ │ │ │ └── com │ │ │ │ └── reactnativebsidffbundle │ │ │ │ ├── BaseReactActivity.java │ │ │ │ ├── BsdiffPatchUtil.java │ │ │ │ ├── HomeAddress.java │ │ │ │ ├── HomeAddressReactModle.java │ │ │ │ ├── HomeAddressReactPackage.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── RNBsdiffApplication.java │ │ │ │ ├── RNModule.java │ │ │ │ └── SignUtils.java │ │ ├── jniLibs │ │ │ ├── armeabi-v7a │ │ │ │ └── libApkPatchLibrary.so │ │ │ ├── armeabi │ │ │ │ └── libApkPatchLibrary.so │ │ │ └── x86 │ │ │ │ └── libApkPatchLibrary.so │ │ └── res │ │ │ ├── layout │ │ │ ├── activity_base_react.xml │ │ │ └── activity_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── pk │ │ └── com │ │ └── reactnativebsidffbundle │ │ └── ExampleUnitTest.java ├── build.gradle ├── familyAddress.android.bundle ├── familyAddress.js ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── index.android.js ├── package.json └── settings.gradle ├── PatchLibraryServer ├── .DS_Store ├── .classpath ├── .cproject ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── 10001.patch ├── 10002.patch ├── bin │ └── com │ │ └── cundong │ │ ├── apkdiff │ │ └── ApkDiffDemo.class │ │ ├── apkpatch │ │ └── ApkPatchDemo.class │ │ ├── common │ │ └── Constants.class │ │ └── utils │ │ ├── DiffUtils.class │ │ └── PatchUtils.class ├── common.js ├── familyAddress.android.bundle ├── index.android.bundle ├── jni │ ├── bzip2 │ │ ├── blocksort.c │ │ ├── bzip2.c │ │ ├── bzlib.c │ │ ├── bzlib.h │ │ ├── bzlib_private.h │ │ ├── compress.c │ │ ├── crctable.c │ │ ├── decompress.c │ │ ├── dlltest.c │ │ ├── huffman.c │ │ ├── randtable.c │ │ └── readMe.txt │ ├── com_cundong_utils_DiffUtils.c │ ├── com_cundong_utils_DiffUtils.h │ ├── com_cundong_utils_PatchUtils.c │ └── com_cundong_utils_PatchUtils.h ├── libApkPatchLibraryServer.dylib ├── src │ └── com │ │ └── cundong │ │ ├── apkdiff │ │ └── ApkDiffDemo.java │ │ ├── apkpatch │ │ └── ApkPatchDemo.java │ │ ├── common │ │ └── Constants.java │ │ └── utils │ │ ├── DiffUtils.java │ │ └── PatchUtils.java └── update.patch └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/.DS_Store -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/.name: -------------------------------------------------------------------------------- 1 | ReactNativeBsidffBundle -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion '23.0.3' 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | testCompile 'junit:junit:4.12' 24 | compile 'com.android.support:appcompat-v7:23.3.0' 25 | } 26 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := ApkPatchLibrary 6 | LOCAL_SRC_FILES := com_pk_bsdiff_utils_PatchUtils.c 7 | 8 | LOCAL_LDLIBS := -lz -llog 9 | 10 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := armeabi armeabi-v7a x86 2 | APP_PLATFORM := android-15 -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/bzip2recover.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------*/ 2 | /*--- Block recoverer program for bzip2 ---*/ 3 | /*--- bzip2recover.c ---*/ 4 | /*-----------------------------------------------------------*/ 5 | 6 | /* ------------------------------------------------------------------ 7 | This file is part of bzip2/libbzip2, a program and library for 8 | lossless, block-sorting data compression. 9 | 10 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 11 | Copyright (C) 1996-2010 Julian Seward 12 | 13 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 14 | README file. 15 | 16 | This program is released under the terms of the license contained 17 | in the file LICENSE. 18 | ------------------------------------------------------------------ */ 19 | 20 | /* This program is a complete hack and should be rewritten properly. 21 | It isn't very complicated. */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | /* This program records bit locations in the file to be recovered. 30 | That means that if 64-bit ints are not supported, we will not 31 | be able to recover .bz2 files over 512MB (2^32 bits) long. 32 | On GNU supported platforms, we take advantage of the 64-bit 33 | int support to circumvent this problem. Ditto MSVC. 34 | 35 | This change occurred in version 1.0.2; all prior versions have 36 | the 512MB limitation. 37 | */ 38 | #ifdef __GNUC__ 39 | typedef unsigned long long int MaybeUInt64; 40 | # define MaybeUInt64_FMT "%Lu" 41 | #else 42 | #ifdef _MSC_VER 43 | typedef unsigned __int64 MaybeUInt64; 44 | # define MaybeUInt64_FMT "%I64u" 45 | #else 46 | typedef unsigned int MaybeUInt64; 47 | # define MaybeUInt64_FMT "%u" 48 | #endif 49 | #endif 50 | 51 | typedef unsigned int UInt32; 52 | typedef int Int32; 53 | typedef unsigned char UChar; 54 | typedef char Char; 55 | typedef unsigned char Bool; 56 | #define True ((Bool)1) 57 | #define False ((Bool)0) 58 | 59 | 60 | #define BZ_MAX_FILENAME 2000 61 | 62 | Char inFileName[BZ_MAX_FILENAME]; 63 | Char outFileName[BZ_MAX_FILENAME]; 64 | Char progName[BZ_MAX_FILENAME]; 65 | 66 | MaybeUInt64 bytesOut = 0; 67 | MaybeUInt64 bytesIn = 0; 68 | 69 | 70 | /*---------------------------------------------------*/ 71 | /*--- Header bytes ---*/ 72 | /*---------------------------------------------------*/ 73 | 74 | #define BZ_HDR_B 0x42 /* 'B' */ 75 | #define BZ_HDR_Z 0x5a /* 'Z' */ 76 | #define BZ_HDR_h 0x68 /* 'h' */ 77 | #define BZ_HDR_0 0x30 /* '0' */ 78 | 79 | 80 | /*---------------------------------------------------*/ 81 | /*--- I/O errors ---*/ 82 | /*---------------------------------------------------*/ 83 | 84 | /*---------------------------------------------*/ 85 | static void readError ( void ) 86 | { 87 | fprintf ( stderr, 88 | "%s: I/O error reading `%s', possible reason follows.\n", 89 | progName, inFileName ); 90 | perror ( progName ); 91 | fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n", 92 | progName ); 93 | exit ( 1 ); 94 | } 95 | 96 | 97 | /*---------------------------------------------*/ 98 | static void writeError ( void ) 99 | { 100 | fprintf ( stderr, 101 | "%s: I/O error reading `%s', possible reason follows.\n", 102 | progName, inFileName ); 103 | perror ( progName ); 104 | fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n", 105 | progName ); 106 | exit ( 1 ); 107 | } 108 | 109 | 110 | /*---------------------------------------------*/ 111 | static void mallocFail ( Int32 n ) 112 | { 113 | fprintf ( stderr, 114 | "%s: malloc failed on request for %d bytes.\n", 115 | progName, n ); 116 | fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n", 117 | progName ); 118 | exit ( 1 ); 119 | } 120 | 121 | 122 | /*---------------------------------------------*/ 123 | static void tooManyBlocks ( Int32 max_handled_blocks ) 124 | { 125 | fprintf ( stderr, 126 | "%s: `%s' appears to contain more than %d blocks\n", 127 | progName, inFileName, max_handled_blocks ); 128 | fprintf ( stderr, 129 | "%s: and cannot be handled. To fix, increase\n", 130 | progName ); 131 | fprintf ( stderr, 132 | "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n", 133 | progName ); 134 | exit ( 1 ); 135 | } 136 | 137 | 138 | 139 | /*---------------------------------------------------*/ 140 | /*--- Bit stream I/O ---*/ 141 | /*---------------------------------------------------*/ 142 | 143 | typedef 144 | struct { 145 | FILE* handle; 146 | Int32 buffer; 147 | Int32 buffLive; 148 | Char mode; 149 | } 150 | BitStream; 151 | 152 | 153 | /*---------------------------------------------*/ 154 | static BitStream* bsOpenReadStream ( FILE* stream ) 155 | { 156 | BitStream *bs = malloc ( sizeof(BitStream) ); 157 | if (bs == NULL) mallocFail ( sizeof(BitStream) ); 158 | bs->handle = stream; 159 | bs->buffer = 0; 160 | bs->buffLive = 0; 161 | bs->mode = 'r'; 162 | return bs; 163 | } 164 | 165 | 166 | /*---------------------------------------------*/ 167 | static BitStream* bsOpenWriteStream ( FILE* stream ) 168 | { 169 | BitStream *bs = malloc ( sizeof(BitStream) ); 170 | if (bs == NULL) mallocFail ( sizeof(BitStream) ); 171 | bs->handle = stream; 172 | bs->buffer = 0; 173 | bs->buffLive = 0; 174 | bs->mode = 'w'; 175 | return bs; 176 | } 177 | 178 | 179 | /*---------------------------------------------*/ 180 | static void bsPutBit ( BitStream* bs, Int32 bit ) 181 | { 182 | if (bs->buffLive == 8) { 183 | Int32 retVal = putc ( (UChar) bs->buffer, bs->handle ); 184 | if (retVal == EOF) writeError(); 185 | bytesOut++; 186 | bs->buffLive = 1; 187 | bs->buffer = bit & 0x1; 188 | } else { 189 | bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) ); 190 | bs->buffLive++; 191 | }; 192 | } 193 | 194 | 195 | /*---------------------------------------------*/ 196 | /*-- 197 | Returns 0 or 1, or 2 to indicate EOF. 198 | --*/ 199 | static Int32 bsGetBit ( BitStream* bs ) 200 | { 201 | if (bs->buffLive > 0) { 202 | bs->buffLive --; 203 | return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 ); 204 | } else { 205 | Int32 retVal = getc ( bs->handle ); 206 | if ( retVal == EOF ) { 207 | if (errno != 0) readError(); 208 | return 2; 209 | } 210 | bs->buffLive = 7; 211 | bs->buffer = retVal; 212 | return ( ((bs->buffer) >> 7) & 0x1 ); 213 | } 214 | } 215 | 216 | 217 | /*---------------------------------------------*/ 218 | static void bsClose ( BitStream* bs ) 219 | { 220 | Int32 retVal; 221 | 222 | if ( bs->mode == 'w' ) { 223 | while ( bs->buffLive < 8 ) { 224 | bs->buffLive++; 225 | bs->buffer <<= 1; 226 | }; 227 | retVal = putc ( (UChar) (bs->buffer), bs->handle ); 228 | if (retVal == EOF) writeError(); 229 | bytesOut++; 230 | retVal = fflush ( bs->handle ); 231 | if (retVal == EOF) writeError(); 232 | } 233 | retVal = fclose ( bs->handle ); 234 | if (retVal == EOF) { 235 | if (bs->mode == 'w') writeError(); else readError(); 236 | } 237 | free ( bs ); 238 | } 239 | 240 | 241 | /*---------------------------------------------*/ 242 | static void bsPutUChar ( BitStream* bs, UChar c ) 243 | { 244 | Int32 i; 245 | for (i = 7; i >= 0; i--) 246 | bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 ); 247 | } 248 | 249 | 250 | /*---------------------------------------------*/ 251 | static void bsPutUInt32 ( BitStream* bs, UInt32 c ) 252 | { 253 | Int32 i; 254 | 255 | for (i = 31; i >= 0; i--) 256 | bsPutBit ( bs, (c >> i) & 0x1 ); 257 | } 258 | 259 | 260 | /*---------------------------------------------*/ 261 | static Bool endsInBz2 ( Char* name ) 262 | { 263 | Int32 n = strlen ( name ); 264 | if (n <= 4) return False; 265 | return 266 | (name[n-4] == '.' && 267 | name[n-3] == 'b' && 268 | name[n-2] == 'z' && 269 | name[n-1] == '2'); 270 | } 271 | 272 | 273 | /*---------------------------------------------------*/ 274 | /*--- ---*/ 275 | /*---------------------------------------------------*/ 276 | 277 | /* This logic isn't really right when it comes to Cygwin. */ 278 | #ifdef _WIN32 279 | # define BZ_SPLIT_SYM '\\' /* path splitter on Windows platform */ 280 | #else 281 | # define BZ_SPLIT_SYM '/' /* path splitter on Unix platform */ 282 | #endif 283 | 284 | #define BLOCK_HEADER_HI 0x00003141UL 285 | #define BLOCK_HEADER_LO 0x59265359UL 286 | 287 | #define BLOCK_ENDMARK_HI 0x00001772UL 288 | #define BLOCK_ENDMARK_LO 0x45385090UL 289 | 290 | /* Increase if necessary. However, a .bz2 file with > 50000 blocks 291 | would have an uncompressed size of at least 40GB, so the chances 292 | are low you'll need to up this. 293 | */ 294 | #define BZ_MAX_HANDLED_BLOCKS 50000 295 | 296 | MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS]; 297 | MaybeUInt64 bEnd [BZ_MAX_HANDLED_BLOCKS]; 298 | MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS]; 299 | MaybeUInt64 rbEnd [BZ_MAX_HANDLED_BLOCKS]; 300 | 301 | 302 | /*-----------------------------------------------------------*/ 303 | /*--- end bzip2recover.c ---*/ 304 | /*-----------------------------------------------------------*/ 305 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/bzlib.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Public header file for the library. ---*/ 4 | /*--- bzlib.h ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #ifndef _BZLIB_H 23 | #define _BZLIB_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define BZ_RUN 0 30 | #define BZ_FLUSH 1 31 | #define BZ_FINISH 2 32 | 33 | #define BZ_OK 0 34 | #define BZ_RUN_OK 1 35 | #define BZ_FLUSH_OK 2 36 | #define BZ_FINISH_OK 3 37 | #define BZ_STREAM_END 4 38 | #define BZ_SEQUENCE_ERROR (-1) 39 | #define BZ_PARAM_ERROR (-2) 40 | #define BZ_MEM_ERROR (-3) 41 | #define BZ_DATA_ERROR (-4) 42 | #define BZ_DATA_ERROR_MAGIC (-5) 43 | #define BZ_IO_ERROR (-6) 44 | #define BZ_UNEXPECTED_EOF (-7) 45 | #define BZ_OUTBUFF_FULL (-8) 46 | #define BZ_CONFIG_ERROR (-9) 47 | 48 | typedef 49 | struct { 50 | char *next_in; 51 | unsigned int avail_in; 52 | unsigned int total_in_lo32; 53 | unsigned int total_in_hi32; 54 | 55 | char *next_out; 56 | unsigned int avail_out; 57 | unsigned int total_out_lo32; 58 | unsigned int total_out_hi32; 59 | 60 | void *state; 61 | 62 | void *(*bzalloc)(void *,int,int); 63 | void (*bzfree)(void *,void *); 64 | void *opaque; 65 | } 66 | bz_stream; 67 | 68 | 69 | #ifndef BZ_IMPORT 70 | #define BZ_EXPORT 71 | #endif 72 | 73 | #ifndef BZ_NO_STDIO 74 | /* Need a definitition for FILE */ 75 | #include 76 | #endif 77 | 78 | #ifdef _WIN32 79 | # include 80 | # ifdef small 81 | /* windows.h define small to char */ 82 | # undef small 83 | # endif 84 | # ifdef BZ_EXPORT 85 | # define BZ_API(func) WINAPI func 86 | # define BZ_EXTERN extern 87 | # else 88 | /* import windows dll dynamically */ 89 | # define BZ_API(func) (WINAPI * func) 90 | # define BZ_EXTERN 91 | # endif 92 | #else 93 | # define BZ_API(func) func 94 | # define BZ_EXTERN extern 95 | #endif 96 | 97 | 98 | /*-- Core (low-level) library functions --*/ 99 | 100 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 101 | bz_stream* strm, 102 | int blockSize100k, 103 | int verbosity, 104 | int workFactor 105 | ); 106 | 107 | BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 108 | bz_stream* strm, 109 | int action 110 | ); 111 | 112 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 113 | bz_stream* strm 114 | ); 115 | 116 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 117 | bz_stream *strm, 118 | int verbosity, 119 | int small 120 | ); 121 | 122 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 123 | bz_stream* strm 124 | ); 125 | 126 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 127 | bz_stream *strm 128 | ); 129 | 130 | 131 | 132 | /*-- High(er) level library functions --*/ 133 | 134 | #ifndef BZ_NO_STDIO 135 | #define BZ_MAX_UNUSED 5000 136 | 137 | typedef void BZFILE; 138 | 139 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 140 | int* bzerror, 141 | FILE* f, 142 | int verbosity, 143 | int small, 144 | void* unused, 145 | int nUnused 146 | ); 147 | 148 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 149 | int* bzerror, 150 | BZFILE* b 151 | ); 152 | 153 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 154 | int* bzerror, 155 | BZFILE* b, 156 | void** unused, 157 | int* nUnused 158 | ); 159 | 160 | BZ_EXTERN int BZ_API(BZ2_bzRead) ( 161 | int* bzerror, 162 | BZFILE* b, 163 | void* buf, 164 | int len 165 | ); 166 | 167 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 168 | int* bzerror, 169 | FILE* f, 170 | int blockSize100k, 171 | int verbosity, 172 | int workFactor 173 | ); 174 | 175 | BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 176 | int* bzerror, 177 | BZFILE* b, 178 | void* buf, 179 | int len 180 | ); 181 | 182 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 183 | int* bzerror, 184 | BZFILE* b, 185 | int abandon, 186 | unsigned int* nbytes_in, 187 | unsigned int* nbytes_out 188 | ); 189 | 190 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 191 | int* bzerror, 192 | BZFILE* b, 193 | int abandon, 194 | unsigned int* nbytes_in_lo32, 195 | unsigned int* nbytes_in_hi32, 196 | unsigned int* nbytes_out_lo32, 197 | unsigned int* nbytes_out_hi32 198 | ); 199 | #endif 200 | 201 | 202 | /*-- Utility functions --*/ 203 | 204 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 205 | char* dest, 206 | unsigned int* destLen, 207 | char* source, 208 | unsigned int sourceLen, 209 | int blockSize100k, 210 | int verbosity, 211 | int workFactor 212 | ); 213 | 214 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 215 | char* dest, 216 | unsigned int* destLen, 217 | char* source, 218 | unsigned int sourceLen, 219 | int small, 220 | int verbosity 221 | ); 222 | 223 | 224 | /*-- 225 | Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) 226 | to support better zlib compatibility. 227 | This code is not _officially_ part of libbzip2 (yet); 228 | I haven't tested it, documented it, or considered the 229 | threading-safeness of it. 230 | If this code breaks, please contact both Yoshioka and me. 231 | --*/ 232 | 233 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( 234 | void 235 | ); 236 | 237 | #ifndef BZ_NO_STDIO 238 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( 239 | const char *path, 240 | const char *mode 241 | ); 242 | 243 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( 244 | int fd, 245 | const char *mode 246 | ); 247 | 248 | BZ_EXTERN int BZ_API(BZ2_bzread) ( 249 | BZFILE* b, 250 | void* buf, 251 | int len 252 | ); 253 | 254 | BZ_EXTERN int BZ_API(BZ2_bzwrite) ( 255 | BZFILE* b, 256 | void* buf, 257 | int len 258 | ); 259 | 260 | BZ_EXTERN int BZ_API(BZ2_bzflush) ( 261 | BZFILE* b 262 | ); 263 | 264 | BZ_EXTERN void BZ_API(BZ2_bzclose) ( 265 | BZFILE* b 266 | ); 267 | 268 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( 269 | BZFILE *b, 270 | int *errnum 271 | ); 272 | #endif 273 | 274 | #ifdef __cplusplus 275 | } 276 | #endif 277 | 278 | #endif 279 | 280 | /*-------------------------------------------------------------*/ 281 | /*--- end bzlib.h ---*/ 282 | /*-------------------------------------------------------------*/ 283 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/bzlib_private.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Private header file for the library. ---*/ 4 | /*--- bzlib_private.h ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #ifndef _BZLIB_PRIVATE_H 23 | #define _BZLIB_PRIVATE_H 24 | 25 | #include 26 | 27 | #ifndef BZ_NO_STDIO 28 | #include 29 | #include 30 | #include 31 | #endif 32 | 33 | #include "bzlib.h" 34 | 35 | 36 | 37 | /*-- General stuff. --*/ 38 | 39 | #define BZ_VERSION "1.0.6, 6-Sept-2010" 40 | 41 | typedef char Char; 42 | typedef unsigned char Bool; 43 | typedef unsigned char UChar; 44 | typedef int Int32; 45 | typedef unsigned int UInt32; 46 | typedef short Int16; 47 | typedef unsigned short UInt16; 48 | 49 | #define True ((Bool)1) 50 | #define False ((Bool)0) 51 | 52 | #ifndef __GNUC__ 53 | #define __inline__ /* */ 54 | #endif 55 | 56 | #ifndef BZ_NO_STDIO 57 | 58 | extern void BZ2_bz__AssertH__fail ( int errcode ); 59 | #define AssertH(cond,errcode) \ 60 | { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); } 61 | 62 | #if BZ_DEBUG 63 | #define AssertD(cond,msg) \ 64 | { if (!(cond)) { \ 65 | fprintf ( stderr, \ 66 | "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\ 67 | exit(1); \ 68 | }} 69 | #else 70 | #define AssertD(cond,msg) /* */ 71 | #endif 72 | 73 | #define VPrintf0(zf) \ 74 | fprintf(stderr,zf) 75 | #define VPrintf1(zf,za1) \ 76 | fprintf(stderr,zf,za1) 77 | #define VPrintf2(zf,za1,za2) \ 78 | fprintf(stderr,zf,za1,za2) 79 | #define VPrintf3(zf,za1,za2,za3) \ 80 | fprintf(stderr,zf,za1,za2,za3) 81 | #define VPrintf4(zf,za1,za2,za3,za4) \ 82 | fprintf(stderr,zf,za1,za2,za3,za4) 83 | #define VPrintf5(zf,za1,za2,za3,za4,za5) \ 84 | fprintf(stderr,zf,za1,za2,za3,za4,za5) 85 | 86 | #else 87 | 88 | extern void bz_internal_error ( int errcode ); 89 | #define AssertH(cond,errcode) \ 90 | { if (!(cond)) bz_internal_error ( errcode ); } 91 | #define AssertD(cond,msg) do { } while (0) 92 | #define VPrintf0(zf) do { } while (0) 93 | #define VPrintf1(zf,za1) do { } while (0) 94 | #define VPrintf2(zf,za1,za2) do { } while (0) 95 | #define VPrintf3(zf,za1,za2,za3) do { } while (0) 96 | #define VPrintf4(zf,za1,za2,za3,za4) do { } while (0) 97 | #define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0) 98 | 99 | #endif 100 | 101 | 102 | #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1) 103 | #define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp)) 104 | 105 | 106 | /*-- Header bytes. --*/ 107 | 108 | #define BZ_HDR_B 0x42 /* 'B' */ 109 | #define BZ_HDR_Z 0x5a /* 'Z' */ 110 | #define BZ_HDR_h 0x68 /* 'h' */ 111 | #define BZ_HDR_0 0x30 /* '0' */ 112 | 113 | /*-- Constants for the back end. --*/ 114 | 115 | #define BZ_MAX_ALPHA_SIZE 258 116 | #define BZ_MAX_CODE_LEN 23 117 | 118 | #define BZ_RUNA 0 119 | #define BZ_RUNB 1 120 | 121 | #define BZ_N_GROUPS 6 122 | #define BZ_G_SIZE 50 123 | #define BZ_N_ITERS 4 124 | 125 | #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) 126 | 127 | 128 | 129 | /*-- Stuff for randomising repetitive blocks. --*/ 130 | 131 | extern Int32 BZ2_rNums[512]; 132 | 133 | #define BZ_RAND_DECLS \ 134 | Int32 rNToGo; \ 135 | Int32 rTPos \ 136 | 137 | #define BZ_RAND_INIT_MASK \ 138 | s->rNToGo = 0; \ 139 | s->rTPos = 0 \ 140 | 141 | #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0) 142 | 143 | #define BZ_RAND_UPD_MASK \ 144 | if (s->rNToGo == 0) { \ 145 | s->rNToGo = BZ2_rNums[s->rTPos]; \ 146 | s->rTPos++; \ 147 | if (s->rTPos == 512) s->rTPos = 0; \ 148 | } \ 149 | s->rNToGo--; 150 | 151 | 152 | 153 | /*-- Stuff for doing CRCs. --*/ 154 | 155 | extern UInt32 BZ2_crc32Table[256]; 156 | 157 | #define BZ_INITIALISE_CRC(crcVar) \ 158 | { \ 159 | crcVar = 0xffffffffL; \ 160 | } 161 | 162 | #define BZ_FINALISE_CRC(crcVar) \ 163 | { \ 164 | crcVar = ~(crcVar); \ 165 | } 166 | 167 | #define BZ_UPDATE_CRC(crcVar,cha) \ 168 | { \ 169 | crcVar = (crcVar << 8) ^ \ 170 | BZ2_crc32Table[(crcVar >> 24) ^ \ 171 | ((UChar)cha)]; \ 172 | } 173 | 174 | 175 | 176 | /*-- States and modes for compression. --*/ 177 | 178 | #define BZ_M_IDLE 1 179 | #define BZ_M_RUNNING 2 180 | #define BZ_M_FLUSHING 3 181 | #define BZ_M_FINISHING 4 182 | 183 | #define BZ_S_OUTPUT 1 184 | #define BZ_S_INPUT 2 185 | 186 | #define BZ_N_RADIX 2 187 | #define BZ_N_QSORT 12 188 | #define BZ_N_SHELL 18 189 | #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2) 190 | 191 | 192 | 193 | 194 | /*-- Structure holding all the compression-side stuff. --*/ 195 | 196 | typedef 197 | struct { 198 | /* pointer back to the struct bz_stream */ 199 | bz_stream* strm; 200 | 201 | /* mode this stream is in, and whether inputting */ 202 | /* or outputting data */ 203 | Int32 mode; 204 | Int32 state; 205 | 206 | /* remembers avail_in when flush/finish requested */ 207 | UInt32 avail_in_expect; 208 | 209 | /* for doing the block sorting */ 210 | UInt32* arr1; 211 | UInt32* arr2; 212 | UInt32* ftab; 213 | Int32 origPtr; 214 | 215 | /* aliases for arr1 and arr2 */ 216 | UInt32* ptr; 217 | UChar* block; 218 | UInt16* mtfv; 219 | UChar* zbits; 220 | 221 | /* for deciding when to use the fallback sorting algorithm */ 222 | Int32 workFactor; 223 | 224 | /* run-length-encoding of the input */ 225 | UInt32 state_in_ch; 226 | Int32 state_in_len; 227 | BZ_RAND_DECLS; 228 | 229 | /* input and output limits and current posns */ 230 | Int32 nblock; 231 | Int32 nblockMAX; 232 | Int32 numZ; 233 | Int32 state_out_pos; 234 | 235 | /* map of bytes used in block */ 236 | Int32 nInUse; 237 | Bool inUse[256]; 238 | UChar unseqToSeq[256]; 239 | 240 | /* the buffer for bit stream creation */ 241 | UInt32 bsBuff; 242 | Int32 bsLive; 243 | 244 | /* block and combined CRCs */ 245 | UInt32 blockCRC; 246 | UInt32 combinedCRC; 247 | 248 | /* misc administratium */ 249 | Int32 verbosity; 250 | Int32 blockNo; 251 | Int32 blockSize100k; 252 | 253 | /* stuff for coding the MTF values */ 254 | Int32 nMTF; 255 | Int32 mtfFreq [BZ_MAX_ALPHA_SIZE]; 256 | UChar selector [BZ_MAX_SELECTORS]; 257 | UChar selectorMtf[BZ_MAX_SELECTORS]; 258 | 259 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 260 | Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 261 | Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 262 | /* second dimension: only 3 needed; 4 makes index calculations faster */ 263 | UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]; 264 | 265 | } 266 | EState; 267 | 268 | 269 | 270 | /*-- externs for compression. --*/ 271 | 272 | extern void 273 | BZ2_blockSort ( EState* ); 274 | 275 | extern void 276 | BZ2_compressBlock ( EState*, Bool ); 277 | 278 | extern void 279 | BZ2_bsInitWrite ( EState* ); 280 | 281 | extern void 282 | BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 ); 283 | 284 | extern void 285 | BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 ); 286 | 287 | 288 | 289 | /*-- states for decompression. --*/ 290 | 291 | #define BZ_X_IDLE 1 292 | #define BZ_X_OUTPUT 2 293 | 294 | #define BZ_X_MAGIC_1 10 295 | #define BZ_X_MAGIC_2 11 296 | #define BZ_X_MAGIC_3 12 297 | #define BZ_X_MAGIC_4 13 298 | #define BZ_X_BLKHDR_1 14 299 | #define BZ_X_BLKHDR_2 15 300 | #define BZ_X_BLKHDR_3 16 301 | #define BZ_X_BLKHDR_4 17 302 | #define BZ_X_BLKHDR_5 18 303 | #define BZ_X_BLKHDR_6 19 304 | #define BZ_X_BCRC_1 20 305 | #define BZ_X_BCRC_2 21 306 | #define BZ_X_BCRC_3 22 307 | #define BZ_X_BCRC_4 23 308 | #define BZ_X_RANDBIT 24 309 | #define BZ_X_ORIGPTR_1 25 310 | #define BZ_X_ORIGPTR_2 26 311 | #define BZ_X_ORIGPTR_3 27 312 | #define BZ_X_MAPPING_1 28 313 | #define BZ_X_MAPPING_2 29 314 | #define BZ_X_SELECTOR_1 30 315 | #define BZ_X_SELECTOR_2 31 316 | #define BZ_X_SELECTOR_3 32 317 | #define BZ_X_CODING_1 33 318 | #define BZ_X_CODING_2 34 319 | #define BZ_X_CODING_3 35 320 | #define BZ_X_MTF_1 36 321 | #define BZ_X_MTF_2 37 322 | #define BZ_X_MTF_3 38 323 | #define BZ_X_MTF_4 39 324 | #define BZ_X_MTF_5 40 325 | #define BZ_X_MTF_6 41 326 | #define BZ_X_ENDHDR_2 42 327 | #define BZ_X_ENDHDR_3 43 328 | #define BZ_X_ENDHDR_4 44 329 | #define BZ_X_ENDHDR_5 45 330 | #define BZ_X_ENDHDR_6 46 331 | #define BZ_X_CCRC_1 47 332 | #define BZ_X_CCRC_2 48 333 | #define BZ_X_CCRC_3 49 334 | #define BZ_X_CCRC_4 50 335 | 336 | 337 | 338 | /*-- Constants for the fast MTF decoder. --*/ 339 | 340 | #define MTFA_SIZE 4096 341 | #define MTFL_SIZE 16 342 | 343 | 344 | 345 | /*-- Structure holding all the decompression-side stuff. --*/ 346 | 347 | typedef 348 | struct { 349 | /* pointer back to the struct bz_stream */ 350 | bz_stream* strm; 351 | 352 | /* state indicator for this stream */ 353 | Int32 state; 354 | 355 | /* for doing the final run-length decoding */ 356 | UChar state_out_ch; 357 | Int32 state_out_len; 358 | Bool blockRandomised; 359 | BZ_RAND_DECLS; 360 | 361 | /* the buffer for bit stream reading */ 362 | UInt32 bsBuff; 363 | Int32 bsLive; 364 | 365 | /* misc administratium */ 366 | Int32 blockSize100k; 367 | Bool smallDecompress; 368 | Int32 currBlockNo; 369 | Int32 verbosity; 370 | 371 | /* for undoing the Burrows-Wheeler transform */ 372 | Int32 origPtr; 373 | UInt32 tPos; 374 | Int32 k0; 375 | Int32 unzftab[256]; 376 | Int32 nblock_used; 377 | Int32 cftab[257]; 378 | Int32 cftabCopy[257]; 379 | 380 | /* for undoing the Burrows-Wheeler transform (FAST) */ 381 | UInt32 *tt; 382 | 383 | /* for undoing the Burrows-Wheeler transform (SMALL) */ 384 | UInt16 *ll16; 385 | UChar *ll4; 386 | 387 | /* stored and calculated CRCs */ 388 | UInt32 storedBlockCRC; 389 | UInt32 storedCombinedCRC; 390 | UInt32 calculatedBlockCRC; 391 | UInt32 calculatedCombinedCRC; 392 | 393 | /* map of bytes used in block */ 394 | Int32 nInUse; 395 | Bool inUse[256]; 396 | Bool inUse16[16]; 397 | UChar seqToUnseq[256]; 398 | 399 | /* for decoding the MTF values */ 400 | UChar mtfa [MTFA_SIZE]; 401 | Int32 mtfbase[256 / MTFL_SIZE]; 402 | UChar selector [BZ_MAX_SELECTORS]; 403 | UChar selectorMtf[BZ_MAX_SELECTORS]; 404 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 405 | 406 | Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 407 | Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 408 | Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 409 | Int32 minLens[BZ_N_GROUPS]; 410 | 411 | /* save area for scalars in the main decompress code */ 412 | Int32 save_i; 413 | Int32 save_j; 414 | Int32 save_t; 415 | Int32 save_alphaSize; 416 | Int32 save_nGroups; 417 | Int32 save_nSelectors; 418 | Int32 save_EOB; 419 | Int32 save_groupNo; 420 | Int32 save_groupPos; 421 | Int32 save_nextSym; 422 | Int32 save_nblockMAX; 423 | Int32 save_nblock; 424 | Int32 save_es; 425 | Int32 save_N; 426 | Int32 save_curr; 427 | Int32 save_zt; 428 | Int32 save_zn; 429 | Int32 save_zvec; 430 | Int32 save_zj; 431 | Int32 save_gSel; 432 | Int32 save_gMinlen; 433 | Int32* save_gLimit; 434 | Int32* save_gBase; 435 | Int32* save_gPerm; 436 | 437 | } 438 | DState; 439 | 440 | 441 | 442 | /*-- Macros for decompression. --*/ 443 | 444 | #define BZ_GET_FAST(cccc) \ 445 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 446 | if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 447 | s->tPos = s->tt[s->tPos]; \ 448 | cccc = (UChar)(s->tPos & 0xff); \ 449 | s->tPos >>= 8; 450 | 451 | #define BZ_GET_FAST_C(cccc) \ 452 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 453 | if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \ 454 | c_tPos = c_tt[c_tPos]; \ 455 | cccc = (UChar)(c_tPos & 0xff); \ 456 | c_tPos >>= 8; 457 | 458 | #define SET_LL4(i,n) \ 459 | { if (((i) & 0x1) == 0) \ 460 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \ 461 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \ 462 | } 463 | 464 | #define GET_LL4(i) \ 465 | ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF) 466 | 467 | #define SET_LL(i,n) \ 468 | { s->ll16[i] = (UInt16)(n & 0x0000ffff); \ 469 | SET_LL4(i, n >> 16); \ 470 | } 471 | 472 | #define GET_LL(i) \ 473 | (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16)) 474 | 475 | #define BZ_GET_SMALL(cccc) \ 476 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 477 | if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 478 | cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \ 479 | s->tPos = GET_LL(s->tPos); 480 | 481 | 482 | /*-- externs for decompression. --*/ 483 | 484 | extern Int32 485 | BZ2_indexIntoF ( Int32, Int32* ); 486 | 487 | extern Int32 488 | BZ2_decompress ( DState* ); 489 | 490 | extern void 491 | BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, 492 | Int32, Int32, Int32 ); 493 | 494 | 495 | #endif 496 | 497 | 498 | /*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/ 499 | 500 | #ifdef BZ_NO_STDIO 501 | #ifndef NULL 502 | #define NULL 0 503 | #endif 504 | #endif 505 | 506 | 507 | /*-------------------------------------------------------------*/ 508 | /*--- end bzlib_private.h ---*/ 509 | /*-------------------------------------------------------------*/ 510 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/crctable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for doing CRCs ---*/ 4 | /*--- crctable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | /*-- 25 | I think this is an implementation of the AUTODIN-II, 26 | Ethernet & FDDI 32-bit CRC standard. Vaguely derived 27 | from code by Rob Warnock, in Section 51 of the 28 | comp.compression FAQ. 29 | --*/ 30 | 31 | UInt32 BZ2_crc32Table[256] = { 32 | 33 | /*-- Ugly, innit? --*/ 34 | 35 | 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L, 36 | 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L, 37 | 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L, 38 | 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL, 39 | 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L, 40 | 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L, 41 | 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L, 42 | 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL, 43 | 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L, 44 | 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L, 45 | 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L, 46 | 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL, 47 | 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L, 48 | 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L, 49 | 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L, 50 | 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL, 51 | 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL, 52 | 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L, 53 | 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L, 54 | 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL, 55 | 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL, 56 | 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L, 57 | 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L, 58 | 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL, 59 | 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL, 60 | 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L, 61 | 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L, 62 | 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL, 63 | 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL, 64 | 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L, 65 | 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L, 66 | 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL, 67 | 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L, 68 | 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL, 69 | 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL, 70 | 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L, 71 | 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L, 72 | 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL, 73 | 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL, 74 | 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L, 75 | 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L, 76 | 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL, 77 | 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL, 78 | 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L, 79 | 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L, 80 | 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL, 81 | 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL, 82 | 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L, 83 | 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L, 84 | 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL, 85 | 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L, 86 | 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L, 87 | 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L, 88 | 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL, 89 | 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L, 90 | 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L, 91 | 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L, 92 | 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL, 93 | 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L, 94 | 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L, 95 | 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L, 96 | 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL, 97 | 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L, 98 | 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L 99 | }; 100 | 101 | 102 | /*-------------------------------------------------------------*/ 103 | /*--- end crctable.c ---*/ 104 | /*-------------------------------------------------------------*/ 105 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/huffman.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Huffman coding low-level stuff ---*/ 4 | /*--- huffman.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | /*---------------------------------------------------*/ 25 | #define WEIGHTOF(zz0) ((zz0) & 0xffffff00) 26 | #define DEPTHOF(zz1) ((zz1) & 0x000000ff) 27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3)) 28 | 29 | #define ADDWEIGHTS(zw1,zw2) \ 30 | (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \ 31 | (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2))) 32 | 33 | #define UPHEAP(z) \ 34 | { \ 35 | Int32 zz, tmp; \ 36 | zz = z; tmp = heap[zz]; \ 37 | while (weight[tmp] < weight[heap[zz >> 1]]) { \ 38 | heap[zz] = heap[zz >> 1]; \ 39 | zz >>= 1; \ 40 | } \ 41 | heap[zz] = tmp; \ 42 | } 43 | 44 | #define DOWNHEAP(z) \ 45 | { \ 46 | Int32 zz, yy, tmp; \ 47 | zz = z; tmp = heap[zz]; \ 48 | while (True) { \ 49 | yy = zz << 1; \ 50 | if (yy > nHeap) break; \ 51 | if (yy < nHeap && \ 52 | weight[heap[yy+1]] < weight[heap[yy]]) \ 53 | yy++; \ 54 | if (weight[tmp] < weight[heap[yy]]) break; \ 55 | heap[zz] = heap[yy]; \ 56 | zz = yy; \ 57 | } \ 58 | heap[zz] = tmp; \ 59 | } 60 | 61 | 62 | /*---------------------------------------------------*/ 63 | void BZ2_hbMakeCodeLengths ( UChar *len, 64 | Int32 *freq, 65 | Int32 alphaSize, 66 | Int32 maxLen ) 67 | { 68 | /*-- 69 | Nodes and heap entries run from 1. Entry 0 70 | for both the heap and nodes is a sentinel. 71 | --*/ 72 | Int32 nNodes, nHeap, n1, n2, i, j, k; 73 | Bool tooLong; 74 | 75 | Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ]; 76 | Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ]; 77 | Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 78 | 79 | for (i = 0; i < alphaSize; i++) 80 | weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8; 81 | 82 | while (True) { 83 | 84 | nNodes = alphaSize; 85 | nHeap = 0; 86 | 87 | heap[0] = 0; 88 | weight[0] = 0; 89 | parent[0] = -2; 90 | 91 | for (i = 1; i <= alphaSize; i++) { 92 | parent[i] = -1; 93 | nHeap++; 94 | heap[nHeap] = i; 95 | UPHEAP(nHeap); 96 | } 97 | 98 | AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 ); 99 | 100 | while (nHeap > 1) { 101 | n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 102 | n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 103 | nNodes++; 104 | parent[n1] = parent[n2] = nNodes; 105 | weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]); 106 | parent[nNodes] = -1; 107 | nHeap++; 108 | heap[nHeap] = nNodes; 109 | UPHEAP(nHeap); 110 | } 111 | 112 | AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 ); 113 | 114 | tooLong = False; 115 | for (i = 1; i <= alphaSize; i++) { 116 | j = 0; 117 | k = i; 118 | while (parent[k] >= 0) { k = parent[k]; j++; } 119 | len[i-1] = j; 120 | if (j > maxLen) tooLong = True; 121 | } 122 | 123 | if (! tooLong) break; 124 | 125 | /* 17 Oct 04: keep-going condition for the following loop used 126 | to be 'i < alphaSize', which missed the last element, 127 | theoretically leading to the possibility of the compressor 128 | looping. However, this count-scaling step is only needed if 129 | one of the generated Huffman code words is longer than 130 | maxLen, which up to and including version 1.0.2 was 20 bits, 131 | which is extremely unlikely. In version 1.0.3 maxLen was 132 | changed to 17 bits, which has minimal effect on compression 133 | ratio, but does mean this scaling step is used from time to 134 | time, enough to verify that it works. 135 | 136 | This means that bzip2-1.0.3 and later will only produce 137 | Huffman codes with a maximum length of 17 bits. However, in 138 | order to preserve backwards compatibility with bitstreams 139 | produced by versions pre-1.0.3, the decompressor must still 140 | handle lengths of up to 20. */ 141 | 142 | for (i = 1; i <= alphaSize; i++) { 143 | j = weight[i] >> 8; 144 | j = 1 + (j / 2); 145 | weight[i] = j << 8; 146 | } 147 | } 148 | } 149 | 150 | 151 | /*---------------------------------------------------*/ 152 | void BZ2_hbAssignCodes ( Int32 *code, 153 | UChar *length, 154 | Int32 minLen, 155 | Int32 maxLen, 156 | Int32 alphaSize ) 157 | { 158 | Int32 n, vec, i; 159 | 160 | vec = 0; 161 | for (n = minLen; n <= maxLen; n++) { 162 | for (i = 0; i < alphaSize; i++) 163 | if (length[i] == n) { code[i] = vec; vec++; }; 164 | vec <<= 1; 165 | } 166 | } 167 | 168 | 169 | /*---------------------------------------------------*/ 170 | void BZ2_hbCreateDecodeTables ( Int32 *limit, 171 | Int32 *base, 172 | Int32 *perm, 173 | UChar *length, 174 | Int32 minLen, 175 | Int32 maxLen, 176 | Int32 alphaSize ) 177 | { 178 | Int32 pp, i, j, vec; 179 | 180 | pp = 0; 181 | for (i = minLen; i <= maxLen; i++) 182 | for (j = 0; j < alphaSize; j++) 183 | if (length[j] == i) { perm[pp] = j; pp++; }; 184 | 185 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0; 186 | for (i = 0; i < alphaSize; i++) base[length[i]+1]++; 187 | 188 | for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1]; 189 | 190 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0; 191 | vec = 0; 192 | 193 | for (i = minLen; i <= maxLen; i++) { 194 | vec += (base[i+1] - base[i]); 195 | limit[i] = vec-1; 196 | vec <<= 1; 197 | } 198 | for (i = minLen + 1; i <= maxLen; i++) 199 | base[i] = ((limit[i-1] + 1) << 1) - base[i]; 200 | } 201 | 202 | 203 | /*-------------------------------------------------------------*/ 204 | /*--- end huffman.c ---*/ 205 | /*-------------------------------------------------------------*/ 206 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/randtable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for randomising repetitive blocks ---*/ 4 | /*--- randtable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | 25 | /*---------------------------------------------*/ 26 | Int32 BZ2_rNums[512] = { 27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 78 | 936, 638 79 | }; 80 | 81 | 82 | /*-------------------------------------------------------------*/ 83 | /*--- end randtable.c ---*/ 84 | /*-------------------------------------------------------------*/ 85 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/bzip2/readMe.txt: -------------------------------------------------------------------------------- 1 | bzip2包中文件来来自: 2 | http://www.bzip.org/downloads.html -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/com_pk_bsdiff_utils_PatchUtils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "bzip2/bzlib.c" 11 | #include "bzip2/crctable.c" 12 | #include "bzip2/compress.c" 13 | #include "bzip2/decompress.c" 14 | #include "bzip2/randtable.c" 15 | #include "bzip2/blocksort.c" 16 | #include "bzip2/huffman.c" 17 | 18 | #include "com_pk_bsdiff_utils_PatchUtils.h" 19 | 20 | static off_t offtin(u_char *buf) { 21 | off_t y; 22 | 23 | y = buf[7] & 0x7F; 24 | y = y * 256; 25 | y += buf[6]; 26 | y = y * 256; 27 | y += buf[5]; 28 | y = y * 256; 29 | y += buf[4]; 30 | y = y * 256; 31 | y += buf[3]; 32 | y = y * 256; 33 | y += buf[2]; 34 | y = y * 256; 35 | y += buf[1]; 36 | y = y * 256; 37 | y += buf[0]; 38 | 39 | if (buf[7] & 0x80) 40 | y = -y; 41 | 42 | return y; 43 | } 44 | 45 | int applypatch(int argc, char * argv[]) { 46 | FILE * f, *cpf, *dpf, *epf; 47 | BZFILE * cpfbz2, *dpfbz2, *epfbz2; 48 | int cbz2err, dbz2err, ebz2err; 49 | int fd; 50 | ssize_t oldsize, newsize; 51 | ssize_t bzctrllen, bzdatalen; 52 | u_char header[32], buf[8]; 53 | u_char *old, *new; 54 | off_t oldpos, newpos; 55 | off_t ctrl[3]; 56 | off_t lenread; 57 | off_t i; 58 | 59 | if (argc != 4) 60 | errx(1, "usage: %s oldfile newfile patchfile\n", argv[0]); 61 | 62 | /* Open patch file */ 63 | if ((f = fopen(argv[3], "r")) == NULL) 64 | err(1, "fopen(%s)", argv[3]); 65 | 66 | /* 67 | File format: 68 | 0 8 "BSDIFF40" 69 | 8 8 X 70 | 16 8 Y 71 | 24 8 sizeof(newfile) 72 | 32 X bzip2(control block) 73 | 32+X Y bzip2(diff block) 74 | 32+X+Y ??? bzip2(extra block) 75 | with control block a set of triples (x,y,z) meaning "add x bytes 76 | from oldfile to x bytes from the diff block; copy y bytes from the 77 | extra block; seek forwards in oldfile by z bytes". 78 | */ 79 | 80 | /* Read header */ 81 | if (fread(header, 1, 32, f) < 32) { 82 | if (feof(f)) 83 | errx(1, "Corrupt patch\n"); 84 | err(1, "fread(%s)", argv[3]); 85 | } 86 | 87 | /* Check for appropriate magic */ 88 | if (memcmp(header, "BSDIFF40", 8) != 0) 89 | errx(1, "Corrupt patch\n"); 90 | 91 | /* Read lengths from header */ 92 | bzctrllen = offtin(header + 8); 93 | bzdatalen = offtin(header + 16); 94 | newsize = offtin(header + 24); 95 | if ((bzctrllen < 0) || (bzdatalen < 0) || (newsize < 0)) 96 | errx(1, "Corrupt patch\n"); 97 | 98 | /* Close patch file and re-open it via libbzip2 at the right places */ 99 | if (fclose(f)) 100 | err(1, "fclose(%s)", argv[3]); 101 | if ((cpf = fopen(argv[3], "r")) == NULL) 102 | err(1, "fopen(%s)", argv[3]); 103 | if (fseeko(cpf, 32, SEEK_SET)) 104 | err(1, "fseeko(%s, %lld)", argv[3], (long long) 32); 105 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) 106 | errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); 107 | if ((dpf = fopen(argv[3], "r")) == NULL) 108 | err(1, "fopen(%s)", argv[3]); 109 | if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) 110 | err(1, "fseeko(%s, %lld)", argv[3], (long long) (32 + bzctrllen)); 111 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) 112 | errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); 113 | if ((epf = fopen(argv[3], "r")) == NULL) 114 | err(1, "fopen(%s)", argv[3]); 115 | if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) 116 | err(1, "fseeko(%s, %lld)", argv[3], 117 | (long long) (32 + bzctrllen + bzdatalen)); 118 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) 119 | errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); 120 | 121 | if (((fd = open(argv[1], O_RDONLY, 0)) < 0) 122 | || ((oldsize = lseek(fd, 0, SEEK_END)) == -1) 123 | || ((old = malloc(oldsize + 1)) == NULL) 124 | || (lseek(fd, 0, SEEK_SET) != 0) 125 | || (read(fd, old, oldsize) != oldsize) || (close(fd) == -1)) 126 | err(1, "%s", argv[1]); 127 | if ((new = malloc(newsize + 1)) == NULL) 128 | err(1, NULL); 129 | 130 | oldpos = 0; 131 | newpos = 0; 132 | while (newpos < newsize) { 133 | /* Read control data */ 134 | for (i = 0; i <= 2; i++) { 135 | lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8); 136 | if ((lenread < 8) 137 | || ((cbz2err != BZ_OK) && (cbz2err != BZ_STREAM_END))) 138 | errx(1, "Corrupt patch\n"); 139 | ctrl[i] = offtin(buf); 140 | }; 141 | 142 | /* Sanity-check */ 143 | if (newpos + ctrl[0] > newsize) 144 | errx(1, "Corrupt patch\n"); 145 | 146 | /* Read diff string */ 147 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); 148 | if ((lenread < ctrl[0]) 149 | || ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) 150 | errx(1, "Corrupt patch\n"); 151 | 152 | /* Add old data to diff string */ 153 | for (i = 0; i < ctrl[0]; i++) 154 | if ((oldpos + i >= 0) && (oldpos + i < oldsize)) 155 | new[newpos + i] += old[oldpos + i]; 156 | 157 | /* Adjust pointers */ 158 | newpos += ctrl[0]; 159 | oldpos += ctrl[0]; 160 | 161 | /* Sanity-check */ 162 | if (newpos + ctrl[1] > newsize) 163 | errx(1, "Corrupt patch\n"); 164 | 165 | /* Read extra string */ 166 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); 167 | if ((lenread < ctrl[1]) 168 | || ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) 169 | errx(1, "Corrupt patch\n"); 170 | 171 | /* Adjust pointers */ 172 | newpos += ctrl[1]; 173 | oldpos += ctrl[2]; 174 | }; 175 | 176 | /* Clean up the bzip2 reads */ 177 | BZ2_bzReadClose(&cbz2err, cpfbz2); 178 | BZ2_bzReadClose(&dbz2err, dpfbz2); 179 | BZ2_bzReadClose(&ebz2err, epfbz2); 180 | if (fclose(cpf) || fclose(dpf) || fclose(epf)) 181 | err(1, "fclose(%s)", argv[3]); 182 | 183 | /* Write the new file */ 184 | if (((fd = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0) 185 | || (write(fd, new, newsize) != newsize) || (close(fd) == -1)) 186 | err(1, "%s", argv[2]); 187 | 188 | free(new); 189 | free(old); 190 | 191 | return 0; 192 | } 193 | 194 | /* 195 | * Class: com_pk_bsdiff_utils_PatchUtils 196 | * Method: patch 197 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 198 | */ 199 | JNIEXPORT jint JNICALL Java_com_pk_bsdiff_utils_PatchUtils_patch(JNIEnv *env, 200 | jobject obj, jstring old, jstring new, jstring patch) { 201 | 202 | char * ch[4]; 203 | ch[0] = "bspatch"; 204 | ch[1] = (char*) ((*env)->GetStringUTFChars(env, old, 0)); 205 | ch[2] = (char*) ((*env)->GetStringUTFChars(env, new, 0)); 206 | ch[3] = (char*) ((*env)->GetStringUTFChars(env, patch, 0)); 207 | 208 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "old = %s ", ch[1]); 209 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "new = %s ", ch[2]); 210 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "patch = %s ", ch[3]); 211 | 212 | int ret = applypatch(4, ch); 213 | 214 | __android_log_print(ANDROID_LOG_INFO, "ApkPatchLibrary", "applypatch result = %d ", ret); 215 | 216 | (*env)->ReleaseStringUTFChars(env, old, ch[1]); 217 | (*env)->ReleaseStringUTFChars(env, new, ch[2]); 218 | (*env)->ReleaseStringUTFChars(env, patch, ch[3]); 219 | 220 | return ret; 221 | } 222 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/jni/com_pk_bsdiff_utils_PatchUtils.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_pk_bsdiff_utils_PatchUtils */ 4 | 5 | #ifndef _Included_com_pk_bsdiff_utils_PatchUtils 6 | #define _Included_com_pk_bsdiff_utils_PatchUtils 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_pk_bsdiff_utils_PatchUtils 12 | * Method: patch 13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_pk_bsdiff_utils_PatchUtils_patch 16 | (JNIEnv *, jclass, jstring, jstring, jstring); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/libs/armeabi-v7a/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/LibBSdiff/libs/armeabi-v7a/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/libs/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/LibBSdiff/libs/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/libs/x86/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/LibBSdiff/libs/x86/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/pukai/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/androidTest/java/com/pk/bsdiff/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.pk.bsdiff; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/main/java/com/pk/bsdiff/utils/PatchUtils.java: -------------------------------------------------------------------------------- 1 | package com.pk.bsdiff.utils; 2 | 3 | /** 4 | * 类说明: APK Patch工具类 5 | *

6 | * Created by pukai on 16/12/6. 7 | */ 8 | public class PatchUtils { 9 | 10 | /** 11 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath 12 | *

13 | * 返回:0,说明操作成功 14 | * 15 | * @param oldPath 示例:/sdcard/old.apk 16 | * @param newPath 示例:/sdcard/new.apk 17 | * @param patchPath 示例:/sdcard/xx.patch 18 | * @return 19 | */ 20 | public static native int patch(String oldPath, String newPath, 21 | String patchPath); 22 | 23 | static { 24 | System.loadLibrary("ApkPatchLibrary"); 25 | } 26 | } -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/main/jniLibs/armeabi-v7a/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/LibBSdiff/src/main/jniLibs/armeabi-v7a/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/main/jniLibs/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/LibBSdiff/src/main/jniLibs/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/main/jniLibs/x86/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/LibBSdiff/src/main/jniLibs/x86/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Bsdiff 3 | 4 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/LibBSdiff/src/test/java/com/pk/bsdiff/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.pk.bsdiff; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "24.0.3" 6 | 7 | defaultConfig { 8 | applicationId "pk.com.reactnativebsidffbundle" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | ndk { 14 | abiFilters "armeabi-v7a", "x86" 15 | } 16 | packagingOptions { 17 | exclude "lib/arm64-v8a/librealm-jni.so" 18 | } 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | compile project(path: ':LibBSdiff') 30 | compile fileTree(dir: 'libs', include: ['*.jar']) 31 | testCompile 'junit:junit:4.12' 32 | compile 'com.android.support:appcompat-v7:23+' 33 | compile("com.facebook.react:react-native:+") 34 | // Gson 35 | compile 'com.google.code.gson:gson:2.7' 36 | } 37 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/pukai/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/androidTest/java/pk/com/reactnativebsidffbundle/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/assets/module.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "moduleName":"familyAddress", 4 | "moduleId":"10001", 5 | "md5":"1b0e4cf79c1500fed1e10c1cc849d2d7" 6 | }, 7 | { 8 | "moduleName":"login", 9 | "moduleId":"10002", 10 | "md5":"5a4215643e2a35662642d36e215cef9c" 11 | } 12 | ] -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/assets/rn/patchs/10001.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/assets/rn/patchs/10001.patch -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/assets/rn/patchs/10002.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/assets/rn/patchs/10002.patch -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/BaseReactActivity.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Intent; 5 | import android.os.Build; 6 | import android.os.Bundle; 7 | import android.provider.Settings; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.text.TextUtils; 10 | import android.view.KeyEvent; 11 | import android.widget.Toast; 12 | 13 | import com.facebook.react.ReactInstanceManager; 14 | import com.facebook.react.ReactPackage; 15 | import com.facebook.react.ReactRootView; 16 | import com.facebook.react.bridge.NativeModuleCallExceptionHandler; 17 | import com.facebook.react.common.LifecycleState; 18 | import com.facebook.react.devsupport.DoubleTapReloadRecognizer; 19 | import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; 20 | import com.facebook.react.modules.core.PermissionAwareActivity; 21 | import com.facebook.react.modules.core.PermissionListener; 22 | import com.facebook.react.shell.MainReactPackage; 23 | 24 | import java.io.File; 25 | 26 | import javax.annotation.Nullable; 27 | 28 | public abstract class BaseReactActivity 29 | extends AppCompatActivity 30 | implements DefaultHardwareBackBtnHandler, PermissionAwareActivity { 31 | 32 | private static final String TAG = "BaseReactActivity"; 33 | private static final String REDBOX_PERMISSION_MESSAGE = 34 | "Overlay permissions needs to be granted in order for react native apps to run in dev mode"; 35 | public static final String JS_MAIN_BUNDLE_NAME = "index.android"; 36 | public static final String JS_BUNDLE_LOCAL_FILE = "index.android.bundle"; 37 | 38 | private boolean isFirstResume = true; 39 | 40 | private ReactInstanceManager mReactInstanceManager; 41 | private 42 | @Nullable 43 | PermissionListener mPermissionListener; 44 | private DoubleTapReloadRecognizer mDoubleTapReloadRecognizer; 45 | private ReactRootView mReactRootView; 46 | 47 | private NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler = new NativeModuleCallExceptionHandler() { 48 | @Override 49 | public void handleException(Exception e) { 50 | finish(); 51 | } 52 | }; 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23) { 58 | // Get permission to show redbox in dev builds. 59 | if (!Settings.canDrawOverlays(this)) { 60 | Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); 61 | startActivity(serviceIntent); 62 | Toast.makeText(this, REDBOX_PERMISSION_MESSAGE, Toast.LENGTH_LONG).show(); 63 | } 64 | } 65 | setContentView(R.layout.activity_base_react); 66 | mReactRootView = (ReactRootView) findViewById(R.id.baseReactView); 67 | iniReactRootView(); 68 | } 69 | 70 | protected void iniReactRootView() { 71 | ReactInstanceManager.Builder builder = ReactInstanceManager.builder() 72 | .setApplication(getApplication()) 73 | .setJSMainModuleName(TextUtils.isEmpty(getMainBundleName()) ? JS_MAIN_BUNDLE_NAME : getMainBundleName()) 74 | .setUseDeveloperSupport(BuildConfig.DEBUG) 75 | .addPackage(new MainReactPackage()) 76 | .setInitialLifecycleState(LifecycleState.BEFORE_CREATE) 77 | .setCurrentActivity(this) 78 | .setNativeModuleCallExceptionHandler(nativeModuleCallExceptionHandler); 79 | String jsBundleFile = getJSBundleFile(); 80 | File file = null; 81 | if (!TextUtils.isEmpty(jsBundleFile)) { 82 | file = new File(jsBundleFile); 83 | } 84 | if (file != null && file.exists()) { 85 | builder.setJSBundleFile(getJSBundleFile()); 86 | } else { 87 | String bundleAssetName = getBundleAssetName(); 88 | builder.setBundleAssetName(TextUtils.isEmpty(bundleAssetName) ? JS_BUNDLE_LOCAL_FILE : bundleAssetName); 89 | } 90 | if (getPackages() != null) { 91 | builder.addPackage(getPackages()); 92 | } 93 | mReactInstanceManager = builder.build(); 94 | mReactRootView.startReactApplication(mReactInstanceManager, getJsModuleName(), null); 95 | mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer(); 96 | } 97 | 98 | protected abstract String getJsModuleName(); 99 | 100 | abstract protected ReactPackage getPackages(); 101 | 102 | /** 103 | * 与modlue对应的js文件的名称 104 | * 105 | * @return 106 | */ 107 | abstract protected String getMainBundleName(); 108 | 109 | /** 110 | * 从本地sd卡读取bundle文件 111 | * 112 | * @return 113 | */ 114 | abstract protected String getJSBundleFile(); 115 | 116 | /** 117 | * assets 中自带的 bundle名称 118 | * 119 | * @return 120 | */ 121 | abstract protected String getBundleAssetName(); 122 | 123 | @Override 124 | protected void onDestroy() { 125 | super.onDestroy(); 126 | } 127 | 128 | @Override 129 | protected void onPause() { 130 | super.onPause(); 131 | if (mReactInstanceManager != null) { 132 | mReactInstanceManager.onHostPause(); 133 | } 134 | } 135 | 136 | @Override 137 | protected void onResume() { 138 | super.onResume(); 139 | if (mReactInstanceManager != null) { 140 | mReactInstanceManager.onHostResume(this, new DefaultHardwareBackBtnHandler() { 141 | @Override 142 | public void invokeDefaultOnBackPressed() { 143 | finish(); 144 | } 145 | }); 146 | } 147 | if (isFirstResume) { 148 | isFirstResume = false; 149 | } 150 | } 151 | 152 | @Override 153 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 154 | if (mReactInstanceManager != null) { 155 | mReactInstanceManager.onActivityResult(BaseReactActivity.this, requestCode, resultCode, data); 156 | } 157 | } 158 | 159 | @Override 160 | public boolean onKeyUp(int keyCode, KeyEvent event) { 161 | if (mReactInstanceManager != null && BuildConfig.DEBUG) { 162 | if (keyCode == KeyEvent.KEYCODE_MENU) { 163 | mReactInstanceManager.showDevOptionsDialog(); 164 | return true; 165 | } 166 | if (mDoubleTapReloadRecognizer.didDoubleTapR(keyCode, getCurrentFocus())) { 167 | mReactInstanceManager.getDevSupportManager().handleReloadJS(); 168 | } 169 | } 170 | return super.onKeyUp(keyCode, event); 171 | } 172 | 173 | @Override 174 | public void onBackPressed() { 175 | if (mReactInstanceManager != null) { 176 | mReactInstanceManager.onBackPressed(); 177 | } else { 178 | super.onBackPressed(); 179 | } 180 | } 181 | 182 | @Override 183 | public void invokeDefaultOnBackPressed() { 184 | super.onBackPressed(); 185 | } 186 | 187 | @Override 188 | public void onNewIntent(Intent intent) { 189 | if (mReactInstanceManager != null) { 190 | mReactInstanceManager.onNewIntent(intent); 191 | } else { 192 | super.onNewIntent(intent); 193 | } 194 | } 195 | 196 | @TargetApi(23) 197 | @Override 198 | public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) { 199 | mPermissionListener = listener; 200 | this.requestPermissions(permissions, requestCode); 201 | } 202 | 203 | @Override 204 | public void onRequestPermissionsResult( 205 | int requestCode, 206 | String[] permissions, 207 | int[] grantResults) { 208 | if (mPermissionListener != null && 209 | mPermissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) { 210 | mPermissionListener = null; 211 | } 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/BsdiffPatchUtil.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.res.AssetManager; 6 | import android.os.Environment; 7 | import android.util.Log; 8 | 9 | 10 | import com.google.gson.Gson; 11 | import com.google.gson.reflect.TypeToken; 12 | import com.pk.bsdiff.utils.PatchUtils; 13 | 14 | import java.io.BufferedReader; 15 | import java.io.File; 16 | import java.io.FileOutputStream; 17 | import java.io.InputStream; 18 | import java.io.InputStreamReader; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | *

使用common.js与对应的业务包 合成 业务bundle

24 | * Created by pukai on 16/12/6. 25 | */ 26 | public class BsdiffPatchUtil { 27 | public final static String COMMONJS = "common.js"; 28 | public final static String PACTH_PATH = "patchs"; 29 | public final static String BUSSINESS_PATH = "bussness"; 30 | public final static String patchExtensions = ".patch"; 31 | public final static String bundleExtensions = ".bundle"; 32 | public final static String BASE_SD_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + RNBsdiffApplication.sContext.getPackageName() + "/rn"; 33 | private String TAG = "BsdiffPatchUtil"; 34 | 35 | /** 36 | * 通过传递的moduleName 从 module.json 文件中找到对应的js文件名称,与common.js合成新的业务bundle; 37 | * example familyAddree:10001 -> patch/10001.patch+common.js -> 10001.bundle(RN setJSBundleFile 的文件) 38 | * 39 | * @param module 40 | * @return 成功 返回Bundle文件所在的文件路径 41 | * 失败 返回"" 42 | */ 43 | private String patch(RNModule module) { 44 | String modlueName = module.getModuleName(); 45 | String md5 = module.getMd5(); 46 | if (null == containsModule(modlueName)) { 47 | Log.e(TAG, modlueName + " not exists!"); 48 | } 49 | if (!isFileExists(BASE_SD_PATH + File.separator + COMMONJS)) { 50 | Log.e(TAG, "com" + " not exists!"); 51 | return ""; 52 | } 53 | if (!isFileExists(getSDCardPatchFilePath(modlueName))) { 54 | Log.e(TAG, modlueName + " not exists!"); 55 | return ""; 56 | } 57 | File file = new File(BASE_SD_PATH + File.separator + BUSSINESS_PATH); 58 | if (!file.exists()) { 59 | file.mkdirs(); 60 | } 61 | /** 62 | * 判断sd卡上是否存在业务的bundle 如果不存在或者 md5 与最新的md5不同则合成新的业务bundle 63 | * 64 | */ 65 | if (!isFileExists(getOutputFilePath(modlueName)) || !SignUtils.checkMd5(new File(getOutputFilePath(modlueName)), md5)) { 66 | if (PatchUtils.patch(BASE_SD_PATH + File.separator + COMMONJS, getOutputFilePath(modlueName), getSDCardPatchFilePath(modlueName)) == 0) { 67 | /** 68 | * 验证合成后的md5 是否与 最新的md5相同 检验合成是否成功 69 | */ 70 | if (SignUtils.checkMd5(getOutputFilePath(modlueName), md5)) { 71 | return getOutputFilePath(modlueName); 72 | } else { 73 | return ""; 74 | } 75 | } else { 76 | return ""; 77 | } 78 | } else { 79 | return ""; 80 | } 81 | } 82 | 83 | private boolean patchAll() { 84 | for (RNModule module : listModules) { 85 | if (null == patch(module)) { 86 | return false; 87 | } 88 | } 89 | return true; 90 | } 91 | 92 | private Runnable copyFileAndPatchAllRunnable = new Runnable() { 93 | @Override 94 | public void run() { 95 | init(); 96 | patchAll(); 97 | } 98 | }; 99 | private Runnable patchAllRunnable = new Runnable() { 100 | @Override 101 | public void run() { 102 | patchAll(); 103 | } 104 | }; 105 | 106 | private class PatchRunnable implements Runnable { 107 | private String moduleName; 108 | 109 | public PatchRunnable(String newModuleName) { 110 | moduleName = newModuleName; 111 | } 112 | 113 | @Override 114 | public void run() { 115 | if (listModules == null) { 116 | return; 117 | } 118 | for (RNModule module : listModules) { 119 | if (moduleName.equals(module.getModuleName())) { 120 | patch(module); 121 | } 122 | } 123 | } 124 | } 125 | 126 | /** 127 | * 复制asset下的全部文件并且合成所有的业务bundle 128 | */ 129 | public void copyFileAndPatchAllBundle() { 130 | new Thread(copyFileAndPatchAllRunnable).start(); 131 | } 132 | 133 | /** 134 | * 合成所有的bundle 135 | */ 136 | public void patchAllBundle() { 137 | new Thread(patchAllRunnable).start(); 138 | } 139 | 140 | /** 141 | * 合成指定moduleName的业务bundle 142 | * 143 | * @param moduleName 144 | */ 145 | public void patchBundle(String moduleName) { 146 | new Thread(new PatchRunnable(moduleName)).start(); 147 | } 148 | 149 | private String getSDCardPatchFilePath(String moduleName) { 150 | RNModule module = containsModule(moduleName); 151 | if (null != module) { 152 | return BASE_SD_PATH + File.separator + PACTH_PATH + File.separator + module.getModuleId() + patchExtensions; 153 | } else { 154 | return ""; 155 | } 156 | } 157 | 158 | 159 | public String getOutputFilePath(String moduleName) { 160 | RNModule module = containsModule(moduleName); 161 | if (null != module) { 162 | return BASE_SD_PATH + File.separator + BUSSINESS_PATH + File.separator + module.getModuleId() + bundleExtensions; 163 | } else { 164 | return ""; 165 | } 166 | } 167 | 168 | private RNModule containsModule(String str) { 169 | for (RNModule modlue : listModules) { 170 | if (str.equals(modlue.getModuleName()) || str.equals(modlue.getModuleId())) { 171 | return modlue; 172 | } 173 | } 174 | return null; 175 | } 176 | 177 | private boolean isFileExists(String path) { 178 | File file = new File(path); 179 | return file.exists(); 180 | } 181 | 182 | private static BsdiffPatchUtil bsdiffPatchUtil; 183 | 184 | public static BsdiffPatchUtil getInstance() { 185 | if (bsdiffPatchUtil == null) { 186 | bsdiffPatchUtil = new BsdiffPatchUtil(); 187 | } 188 | return bsdiffPatchUtil; 189 | } 190 | 191 | private List listModules = new ArrayList<>(); 192 | 193 | private BsdiffPatchUtil() { 194 | } 195 | 196 | private void init() { 197 | File file = new File(BASE_SD_PATH); 198 | if (!file.exists()) { 199 | file.mkdirs(); 200 | } 201 | /** 202 | * 将assets/rn 文件复制到sd卡 并且读取其中module.text的内容存放到moduleap里 203 | */ 204 | if (copyFilesFassets(RNBsdiffApplication.sContext, "rn", BASE_SD_PATH)) { 205 | try { 206 | AssetManager assetManager = RNBsdiffApplication.sContext.getAssets(); 207 | //File moduleFile = new File(BASE_SD_PATH + File.separator + "module.json"); 208 | //FileInputStream inputStream = new FileInputStream(moduleFile); 209 | InputStream inputStream = assetManager.open("module.json"); 210 | String content = readTextFromSDcard(inputStream); 211 | listModules = initModules(content); 212 | } catch (Exception e) { 213 | e.printStackTrace(); 214 | } 215 | } 216 | } 217 | 218 | /** 219 | * 存文件流中读取内容 220 | * 221 | * @param is 222 | * @return 223 | * @throws Exception 224 | */ 225 | private String readTextFromSDcard(InputStream is) throws Exception { 226 | InputStreamReader reader = new InputStreamReader(is, "UTF-8"); 227 | BufferedReader bufferedReader = new BufferedReader(reader); 228 | StringBuffer buffer = new StringBuffer(""); 229 | String str; 230 | while ((str = bufferedReader.readLine()) != null) { 231 | buffer.append(str); 232 | } 233 | return buffer.toString(); 234 | } 235 | 236 | /** 237 | *

将json字符串转换成 list

238 | * 239 | * @param str 240 | * @return 241 | */ 242 | private List initModules(String str) { 243 | List list = new ArrayList<>(); 244 | if (str != null && !str.isEmpty()) { 245 | try { 246 | Gson gson = new Gson(); 247 | list = gson.fromJson(str, new TypeToken>() { 248 | }.getType()); 249 | } catch (Exception e) { 250 | e.printStackTrace(); 251 | } 252 | } 253 | return list; 254 | } 255 | 256 | /** 257 | *

从assets目录中复制整个文件夹内容

258 | * 259 | * @param context Context 使用CopyFiles类的Context 260 | * @param oldPath String 原文件路径 如:rn 261 | * @param newPath String 复制后路径 如:xx:/bb/cc 262 | */ 263 | public boolean copyFilesFassets(Context context, String oldPath, String newPath) { 264 | try { 265 | String fileNames[] = context.getAssets().list(oldPath); 266 | if (fileNames.length > 0) { 267 | File file = new File(newPath); 268 | file.mkdirs(); 269 | for (String fileName : fileNames) { 270 | copyFilesFassets(context, oldPath + "/" + fileName, newPath + "/" + fileName); 271 | } 272 | } else { 273 | /** 274 | * 如果文件已经存在 且MD5 相同 跳过复制 275 | */ 276 | if (isFileExists(newPath) && SignUtils.getMd5ByFile(context.getAssets().open(oldPath)).equals(SignUtils.getMd5ByFile(new File(newPath)))) { 277 | Log.e("file", "exist " + newPath); 278 | } else { 279 | InputStream is = context.getAssets().open(oldPath); 280 | FileOutputStream fos = new FileOutputStream(new File(newPath)); 281 | byte[] buffer = new byte[1024]; 282 | int byteCount = 0; 283 | while ((byteCount = is.read(buffer)) != -1) { 284 | fos.write(buffer, 0, byteCount); 285 | } 286 | fos.flush(); 287 | is.close(); 288 | fos.close(); 289 | } 290 | } 291 | return true; 292 | } catch (Exception e) { 293 | e.printStackTrace(); 294 | return false; 295 | } 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/HomeAddress.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.facebook.react.bridge.WritableMap; 7 | import com.facebook.react.bridge.WritableNativeMap; 8 | 9 | /** 10 | * @author pukai 11 | * @date 2016-11-23 12 | */ 13 | public class HomeAddress implements Parcelable { 14 | 15 | // {"addrId":43,"uid":6195148937236480,"cityId":348,"detailAddr":"贡古鲁克山口","lat":41.48715,"lng":78.6585,"selected":true,"createTime":1479722555000,"updateTime":1479722555000}, 16 | public String addrId; 17 | public String uid; 18 | public String cityId; 19 | 20 | public HomeAddress(String addrId, String detailAddr, boolean selected) { 21 | this.addrId = addrId; 22 | this.detailAddr = detailAddr; 23 | this.selected = selected; 24 | } 25 | 26 | public String detailAddr; 27 | public double lat; 28 | public double lng; 29 | public boolean selected; 30 | public String createTime; 31 | public String updateTime; 32 | 33 | public WritableMap getWritableMap(){ 34 | WritableMap writableMap = new WritableNativeMap(); 35 | writableMap.putString("addrId",addrId); 36 | writableMap.putString("uid",uid); 37 | writableMap.putString("cityId",cityId); 38 | writableMap.putString("detailAddr",detailAddr); 39 | writableMap.putDouble("lat",lat); 40 | writableMap.putDouble("lng",lng); 41 | writableMap.putBoolean("selected",selected); 42 | writableMap.putString("createTime",createTime); 43 | writableMap.putString("updateTime",updateTime); 44 | return writableMap; 45 | } 46 | @Override 47 | public int describeContents() { return 0; } 48 | 49 | 50 | @Override 51 | public void writeToParcel(Parcel dest, int flags) { 52 | dest.writeString(addrId); 53 | dest.writeString(uid); 54 | dest.writeString(cityId); 55 | dest.writeString(detailAddr); 56 | dest.writeDouble(lat); 57 | dest.writeDouble(lng); 58 | dest.writeByte((byte) (selected ? 1 : 0)); 59 | dest.writeString(createTime); 60 | dest.writeString(updateTime); 61 | } 62 | 63 | 64 | protected HomeAddress(Parcel in) { 65 | addrId = in.readString(); 66 | uid = in.readString(); 67 | cityId = in.readString(); 68 | detailAddr = in.readString(); 69 | lat = in.readDouble(); 70 | lng = in.readDouble(); 71 | selected = in.readByte() == 1; 72 | 73 | } 74 | 75 | 76 | 77 | public static final Creator CREATOR = new Creator() { 78 | @Override 79 | public HomeAddress createFromParcel(Parcel source) {return new HomeAddress(source);} 80 | 81 | @Override 82 | public HomeAddress[] newArray(int size) {return new HomeAddress[size];} 83 | }; 84 | 85 | 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/HomeAddressReactModle.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.app.Activity; 4 | import android.widget.Toast; 5 | 6 | import com.facebook.react.bridge.Callback; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | import com.facebook.react.bridge.WritableArray; 11 | import com.facebook.react.bridge.WritableNativeArray; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by pukai on 2016-10-27. 18 | */ 19 | public class HomeAddressReactModle extends ReactContextBaseJavaModule { 20 | private Activity context; 21 | private ReactApplicationContext reactApplicationContext; 22 | 23 | public HomeAddressReactModle(final ReactApplicationContext reactContext, Activity context) { 24 | super(reactContext); 25 | this.context = context; 26 | reactApplicationContext = reactContext; 27 | } 28 | 29 | @Override 30 | public String getName() { 31 | return "NativeMethod"; 32 | } 33 | 34 | 35 | /** 36 | * 在js文件调用该方法的方式 NativeModules.NativeMethod.js2Native 37 | * 38 | * @param content 普通类型的参数 39 | */ 40 | @ReactMethod 41 | public void showWarnToast(String content) { 42 | Toast.makeText(context, content, Toast.LENGTH_SHORT).show(); 43 | } 44 | 45 | @ReactMethod 46 | public void showSuccessToast(String content) { 47 | Toast.makeText(context, content, Toast.LENGTH_SHORT).show(); 48 | } 49 | 50 | @ReactMethod 51 | public void showLoading() { 52 | } 53 | 54 | @ReactMethod 55 | public void hideLoading() { 56 | } 57 | 58 | /** 59 | * 可以添加多个方法 60 | */ 61 | @ReactMethod 62 | public void getAddressList(final Callback successCallback, final Callback failedCallback) { 63 | List list = new ArrayList<>(); 64 | list.add(new HomeAddress("0", "测试地址0", true)); 65 | list.add(new HomeAddress("1", "测试地址1", false)); 66 | list.add(new HomeAddress("2", "测试地址2", false)); 67 | WritableArray writableArray = new WritableNativeArray(); 68 | for (HomeAddress address : list) { 69 | if (address != null) { 70 | writableArray.pushMap(address.getWritableMap()); 71 | } 72 | } 73 | successCallback.invoke(writableArray); 74 | //failedCallback.invoke(); 75 | 76 | } 77 | 78 | 79 | @ReactMethod 80 | public void setDefaultAddress(final String addrId, final Callback successCallback, final Callback failedCallback) { 81 | successCallback.invoke(addrId); 82 | // failedCallback.invoke(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/HomeAddressReactPackage.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.app.Activity; 4 | 5 | import com.facebook.react.LazyReactPackage; 6 | import com.facebook.react.bridge.JavaScriptModule; 7 | import com.facebook.react.bridge.ModuleSpec; 8 | import com.facebook.react.bridge.NativeModule; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.uimanager.ViewManager; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | import java.util.Collections; 15 | import java.util.List; 16 | 17 | import javax.inject.Provider; 18 | 19 | /** 20 | * Created by pukai on 2016-10-27. 21 | */ 22 | public class HomeAddressReactPackage extends LazyReactPackage { 23 | private Activity context; 24 | 25 | public HomeAddressReactPackage(Activity homeAddressRNActivity) { 26 | this.context = homeAddressRNActivity; 27 | } 28 | 29 | @Override 30 | public List getNativeModules(final ReactApplicationContext reactContext) { 31 | return Arrays.asList(new ModuleSpec(HomeAddressReactModle.class, new Provider() { 32 | @Override 33 | public NativeModule get() { 34 | return new HomeAddressReactModle(reactContext, context); 35 | } 36 | })); 37 | } 38 | 39 | @Override 40 | public List> createJSModules() { 41 | return Collections.emptyList(); 42 | } 43 | 44 | @Override 45 | public List createViewManagers(ReactApplicationContext reactContext) { 46 | return new ArrayList<>(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/MainActivity.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import com.facebook.react.ReactPackage; 4 | 5 | import javax.annotation.Nullable; 6 | 7 | public class MainActivity extends BaseReactActivity { 8 | 9 | 10 | public static final String JS_MAIN_MODULE_NAME = "FamilyAddressModule"; 11 | public static final String JS_MAIN_BUNDLE_NAME = "familyAddress.android"; 12 | public static final String JS_BUNDLE_LOCAL_FILE = "familyAddress.android.bundle"; 13 | 14 | 15 | @Override 16 | protected String getJsModuleName() { 17 | return JS_MAIN_MODULE_NAME; 18 | } 19 | 20 | @Override 21 | protected ReactPackage getPackages() { 22 | return new HomeAddressReactPackage(this); 23 | } 24 | 25 | @Override 26 | protected String getMainBundleName() { 27 | return JS_MAIN_BUNDLE_NAME; 28 | } 29 | 30 | @Nullable 31 | @Override 32 | protected String getJSBundleFile() { 33 | return BsdiffPatchUtil.getInstance().getOutputFilePath("familyAddress"); 34 | } 35 | 36 | @Nullable 37 | @Override 38 | protected String getBundleAssetName() { 39 | return JS_BUNDLE_LOCAL_FILE; 40 | } 41 | 42 | @Override 43 | public void onBackPressed() { 44 | super.onBackPressed(); 45 | finish(); 46 | } 47 | 48 | @Override 49 | protected void onDestroy() { 50 | super.onDestroy(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/RNBsdiffApplication.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | /** 7 | * Created by pukai on 17/3/9. 8 | */ 9 | public class RNBsdiffApplication extends Application { 10 | public static Context sContext; 11 | 12 | @Override 13 | public void onCreate() { 14 | super.onCreate(); 15 | sContext = getApplicationContext(); 16 | BsdiffPatchUtil.getInstance().copyFileAndPatchAllBundle(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/RNModule.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | /** 4 | * Created by pukai on 16/12/7. 5 | */ 6 | public class RNModule { 7 | private String moduleName; 8 | private String moduleId; 9 | private String md5; 10 | 11 | public String getMd5() { 12 | return md5; 13 | } 14 | 15 | public void setMd5(String md5) { 16 | this.md5 = md5; 17 | } 18 | 19 | public String getModuleName() { 20 | return moduleName; 21 | } 22 | 23 | public void setModuleName(String moduleName) { 24 | this.moduleName = moduleName; 25 | } 26 | 27 | public String getModuleId() { 28 | return moduleId; 29 | } 30 | 31 | public void setModuleId(String moduleId) { 32 | this.moduleId = moduleId; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/java/pk/com/reactnativebsidffbundle/SignUtils.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import android.text.TextUtils; 4 | import android.util.Log; 5 | 6 | import java.io.File; 7 | import java.io.FileInputStream; 8 | import java.io.FileNotFoundException; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.security.MessageDigest; 12 | 13 | /** 14 | * 类说明: apk 签名信息获取工具类 15 | * 16 | * @author pukai 17 | * @version 1.0 18 | * @date 2016-10-26 19 | */ 20 | public class SignUtils { 21 | 22 | private static final boolean DEBUG = BuildConfig.DEBUG; 23 | 24 | private static final String TAG = DEBUG ? "SignUtils" : SignUtils.class.getSimpleName(); 25 | 26 | private static String bytes2Hex(byte[] src) { 27 | char[] res = new char[src.length * 2]; 28 | final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 29 | for (int i = 0, j = 0; i < src.length; i++) { 30 | res[j++] = hexDigits[src[i] >>> 4 & 0x0f]; 31 | res[j++] = hexDigits[src[i] & 0x0f]; 32 | } 33 | 34 | return new String(res); 35 | } 36 | 37 | public static String getMd5ByFile(File file) { 38 | FileInputStream in; 39 | try { 40 | in = new FileInputStream(file); 41 | return getMd5ByFile(in); 42 | } catch (FileNotFoundException e) { 43 | e.printStackTrace(); 44 | } 45 | return ""; 46 | } 47 | 48 | public static String getMd5ByFile(InputStream in) { 49 | String value = ""; 50 | try { 51 | MessageDigest digester = MessageDigest.getInstance("MD5"); 52 | byte[] bytes = new byte[8192]; 53 | int byteCount; 54 | while ((byteCount = in.read(bytes)) > 0) { 55 | digester.update(bytes, 0, byteCount); 56 | } 57 | value = bytes2Hex(digester.digest()); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | } finally { 61 | if (null != in) { 62 | try { 63 | in.close(); 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | } 69 | return value; 70 | } 71 | 72 | /** 73 | * 判断文件的MD5是否为指定值 74 | * 75 | * @param file 76 | * @param md5 77 | * @return 78 | */ 79 | public static boolean checkMd5(File file, String md5) { 80 | if (TextUtils.isEmpty(md5)) { 81 | throw new RuntimeException("md5 cannot be empty"); 82 | } 83 | 84 | String fileMd5 = getMd5ByFile(file); 85 | 86 | if (DEBUG) { 87 | Log.d(TAG, String.format(file.getPath()+" file's md5=%s, real md5=%s", fileMd5, md5)); 88 | } 89 | 90 | if (md5.equals(fileMd5)) { 91 | return true; 92 | } else { 93 | return false; 94 | } 95 | } 96 | 97 | /** 98 | * 判断文件的MD5是否为指定值 99 | * 100 | * @param filePath 101 | * @param md5 102 | * @return 103 | */ 104 | public static boolean checkMd5(String filePath, String md5) { 105 | return checkMd5(new File(filePath), md5); 106 | } 107 | } -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/jniLibs/armeabi-v7a/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/jniLibs/armeabi-v7a/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/jniLibs/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/jniLibs/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/jniLibs/x86/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/jniLibs/x86/libApkPatchLibrary.so -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/layout/activity_base_react.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ReactNativeBsidffBundle 3 | 4 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/app/src/test/java/pk/com/reactnativebsidffbundle/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package pk.com.reactnativebsidffbundle; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | maven { url "$rootDir/node_modules/react-native/android" } 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } 25 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/familyAddress.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import{ 3 | AppRegistry, 4 | StyleSheet, 5 | Text, 6 | Image, 7 | ListView, 8 | View, 9 | TouchableWithoutFeedback, 10 | NativeModules 11 | } from 'react-native'; 12 | 13 | const ds = new ListView.DataSource({rowHasChanged:(r1,r2) =>r1 !== r2}); 14 | 15 | class FamilyAddressComponent extends Component{ 16 | constructor(props){ 17 | super(props); 18 | let arrayData = []; 19 | this.state={ 20 | showNull:2, 21 | selectedID:0, 22 | list:arrayData, 23 | rowData:ds.cloneWithRows(arrayData) 24 | }; 25 | this.getFamilyAddressList(); 26 | } 27 | componentWillMount(){ 28 | } 29 | componentDidMount(){ 30 | } 31 | render(){ 32 | let showWhat = this.state.showNull; 33 | if(showWhat===0){ 34 | return ; 35 | }else if(showWhat===1){ 36 | return ( 37 | 38 | 每日首单以您的家庭住址为基准就近派单。 39 | 44 | 45 | ) 46 | }else{ 47 | return 48 | } 49 | } 50 | _renderRow(rowData,sectionID,rowID,highlightRow){ 51 | return ( 52 | 53 | { 57 | NativeModules.NativeMethod.hideLoading(); 58 | if(this.state.selectedID!==rowID){ 59 | let arrayData = this.state.list.concat(); 60 | arrayData[rowID].selected=true; 61 | arrayData[this.state.selectedID].selected=false; 62 | this.setState({ 63 | selectedID:rowID, 64 | list:arrayData, 65 | rowData:ds.cloneWithRows(arrayData) 66 | }); 67 | } 68 | NativeModules.NativeMethod.showSuccessToast("默认地址已更新\n新地址即刻生效"); 69 | },()=>{ 70 | NativeModules.NativeMethod.hideLoading(); 71 | NativeModules.NativeMethod.showWarnToast("修改失败,请稍后再试"); 72 | }); 73 | 74 | }.bind(this) 75 | 76 | }> 77 | 78 | 79 | 80 | 81 | 82 | ); 83 | } 84 | getFamilyAddressList(){ 85 | NativeModules.NativeMethod.showLoading(); 86 | NativeModules.NativeMethod.getAddressList((arrayData)=>{ 87 | NativeModules.NativeMethod.hideLoading(); 88 | if(arrayData.length===0){ 89 | this.setState({ 90 | showNull:0, 91 | selectedID:0, 92 | list:[], 93 | rowData:ds.cloneWithRows([]) 94 | }); 95 | }else{ 96 | let id =0; 97 | for(var i=0;i{ 112 | NativeModules.NativeMethod.hideLoading(); 113 | this.setState({ 114 | showNull:0, 115 | selectedID:0, 116 | list:[], 117 | rowData:ds.cloneWithRows([]) 118 | }); 119 | }); 120 | } 121 | } 122 | class ViewItem extends Component{ 123 | render(){ 124 | let viewStyleCenter=styles.ViewItemCenter; 125 | let textStyle10=styles.TextStyle10; 126 | let textStyle14=styles.TextStyle14; 127 | if(this.props.data.selected){ 128 | viewStyleCenter=styles.ViewItemCenterSelect; 129 | textStyle10=styles.TextStyle10Select; 130 | textStyle14=styles.TextStyle14Select; 131 | } 132 | return( 133 | 134 | 135 | {this.props.data.detailAddr} 136 | 137 | 138 | 设置为默认 139 | 140 | 141 | 142 | ) 143 | } 144 | } 145 | class NoDataView extends Component{ 146 | render(){ 147 | return( 148 | 149 | 150 | 151 | 152 | 您还未添加家庭住址,请尽快联系运控进行添加 153 | 添加后每日首单将以您的家庭住址为基准就近派单 154 | 155 | 156 | ) 157 | } 158 | } 159 | const styles = StyleSheet.create({ 160 | ListViewStyle:{ 161 | marginLeft:10, 162 | marginRight:10, 163 | flex:1, 164 | }, 165 | ViewItemStyle:{ 166 | marginTop:10, 167 | paddingTop:15, 168 | paddingBottom:15, 169 | paddingLeft:16, 170 | paddingRight:16, 171 | borderRadius:2, 172 | backgroundColor:'white', 173 | borderWidth:0.5, 174 | borderColor:'#e5e5e5', 175 | }, 176 | ViewItemCenter:{ 177 | alignItems:'center', 178 | flexDirection:'row' 179 | }, 180 | ViewItemCenterSelect:{ 181 | alignItems:'center', 182 | flexDirection:'row', 183 | }, 184 | ViewImageAndTextStyle:{ 185 | width:80, 186 | flexDirection:'column', 187 | alignItems:'flex-end', 188 | justifyContent:'center', 189 | }, 190 | ImageStyle:{ 191 | width:15, 192 | height:15 193 | }, 194 | TextStyle10:{ 195 | marginTop:5, 196 | fontSize:12, 197 | color:"#999" 198 | }, 199 | TextStyle10Select:{ 200 | marginTop:5, 201 | fontSize:12, 202 | color:"#fc9153" 203 | }, 204 | TextStyle12:{ 205 | fontSize:14, 206 | color:"#6e7080" 207 | }, 208 | TextStyle14:{ 209 | flex:1, 210 | fontSize:16, 211 | color:"#6e7080" 212 | }, 213 | TextStyle12Select:{ 214 | fontSize:14, 215 | color:"#fc9153" 216 | }, 217 | TextStyle14Select:{ 218 | flex:1, 219 | fontSize:16, 220 | color:"#fc9153" 221 | } 222 | }); 223 | AppRegistry.registerComponent('FamilyAddressModule',()=>FamilyAddressComponent); 224 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Thu Mar 09 14:27:34 CST 2017 16 | android.useDeprecatedNdk=true 17 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/AndroidReactNativeBsidffBundle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/index.android.js: -------------------------------------------------------------------------------- 1 | require('./app/rn/login'); -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "c", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "bundle-android": "react-native bundle --platform android --dev false --entry-file familyAddress.js --bundle-output app/src/main/assets/familyAddress.android.bundle" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "eslint": "^3.7.1", 13 | "eslint-plugin-react": "^6.4.0", 14 | "react": "15.3.2", 15 | "react-native": "^0.35.0" 16 | }, 17 | "devDependencies": { 18 | "babel-jest": "16.0.0", 19 | "babel-preset-react-native": "1.9.0", 20 | "jest": "16.0.2", 21 | "jest-react-native": "16.0.0", 22 | "react-test-renderer": "15.3.2" 23 | }, 24 | "description": "" 25 | } 26 | -------------------------------------------------------------------------------- /AndroidReactNativeBsidffBundle/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':LibBSdiff' 2 | -------------------------------------------------------------------------------- /PatchLibraryServer/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/.DS_Store -------------------------------------------------------------------------------- /PatchLibraryServer/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /PatchLibraryServer/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ApkPatchLibraryServer 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javabuilder 16 | 17 | 18 | 19 | 20 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 21 | full,incremental, 22 | 23 | 24 | 25 | 26 | 27 | org.eclipse.jdt.core.javanature 28 | org.eclipse.cdt.core.cnature 29 | org.eclipse.cdt.core.ccnature 30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 32 | 33 | 34 | -------------------------------------------------------------------------------- /PatchLibraryServer/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /PatchLibraryServer/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /PatchLibraryServer/10001.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/10001.patch -------------------------------------------------------------------------------- /PatchLibraryServer/10002.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/10002.patch -------------------------------------------------------------------------------- /PatchLibraryServer/bin/com/cundong/apkdiff/ApkDiffDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/bin/com/cundong/apkdiff/ApkDiffDemo.class -------------------------------------------------------------------------------- /PatchLibraryServer/bin/com/cundong/apkpatch/ApkPatchDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/bin/com/cundong/apkpatch/ApkPatchDemo.class -------------------------------------------------------------------------------- /PatchLibraryServer/bin/com/cundong/common/Constants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/bin/com/cundong/common/Constants.class -------------------------------------------------------------------------------- /PatchLibraryServer/bin/com/cundong/utils/DiffUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/bin/com/cundong/utils/DiffUtils.class -------------------------------------------------------------------------------- /PatchLibraryServer/bin/com/cundong/utils/PatchUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/bin/com/cundong/utils/PatchUtils.class -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/bzlib.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Public header file for the library. ---*/ 4 | /*--- bzlib.h ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #ifndef _BZLIB_H 23 | #define _BZLIB_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define BZ_RUN 0 30 | #define BZ_FLUSH 1 31 | #define BZ_FINISH 2 32 | 33 | #define BZ_OK 0 34 | #define BZ_RUN_OK 1 35 | #define BZ_FLUSH_OK 2 36 | #define BZ_FINISH_OK 3 37 | #define BZ_STREAM_END 4 38 | #define BZ_SEQUENCE_ERROR (-1) 39 | #define BZ_PARAM_ERROR (-2) 40 | #define BZ_MEM_ERROR (-3) 41 | #define BZ_DATA_ERROR (-4) 42 | #define BZ_DATA_ERROR_MAGIC (-5) 43 | #define BZ_IO_ERROR (-6) 44 | #define BZ_UNEXPECTED_EOF (-7) 45 | #define BZ_OUTBUFF_FULL (-8) 46 | #define BZ_CONFIG_ERROR (-9) 47 | 48 | typedef 49 | struct { 50 | char *next_in; 51 | unsigned int avail_in; 52 | unsigned int total_in_lo32; 53 | unsigned int total_in_hi32; 54 | 55 | char *next_out; 56 | unsigned int avail_out; 57 | unsigned int total_out_lo32; 58 | unsigned int total_out_hi32; 59 | 60 | void *state; 61 | 62 | void *(*bzalloc)(void *,int,int); 63 | void (*bzfree)(void *,void *); 64 | void *opaque; 65 | } 66 | bz_stream; 67 | 68 | 69 | #ifndef BZ_IMPORT 70 | #define BZ_EXPORT 71 | #endif 72 | 73 | #ifndef BZ_NO_STDIO 74 | /* Need a definitition for FILE */ 75 | #include 76 | #endif 77 | 78 | #ifdef _WIN32 79 | # include 80 | # ifdef small 81 | /* windows.h define small to char */ 82 | # undef small 83 | # endif 84 | # ifdef BZ_EXPORT 85 | # define BZ_API(func) WINAPI func 86 | # define BZ_EXTERN extern 87 | # else 88 | /* import windows dll dynamically */ 89 | # define BZ_API(func) (WINAPI * func) 90 | # define BZ_EXTERN 91 | # endif 92 | #else 93 | # define BZ_API(func) func 94 | # define BZ_EXTERN extern 95 | #endif 96 | 97 | 98 | /*-- Core (low-level) library functions --*/ 99 | 100 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( 101 | bz_stream* strm, 102 | int blockSize100k, 103 | int verbosity, 104 | int workFactor 105 | ); 106 | 107 | BZ_EXTERN int BZ_API(BZ2_bzCompress) ( 108 | bz_stream* strm, 109 | int action 110 | ); 111 | 112 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( 113 | bz_stream* strm 114 | ); 115 | 116 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( 117 | bz_stream *strm, 118 | int verbosity, 119 | int small 120 | ); 121 | 122 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( 123 | bz_stream* strm 124 | ); 125 | 126 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( 127 | bz_stream *strm 128 | ); 129 | 130 | 131 | 132 | /*-- High(er) level library functions --*/ 133 | 134 | #ifndef BZ_NO_STDIO 135 | #define BZ_MAX_UNUSED 5000 136 | 137 | typedef void BZFILE; 138 | 139 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( 140 | int* bzerror, 141 | FILE* f, 142 | int verbosity, 143 | int small, 144 | void* unused, 145 | int nUnused 146 | ); 147 | 148 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( 149 | int* bzerror, 150 | BZFILE* b 151 | ); 152 | 153 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( 154 | int* bzerror, 155 | BZFILE* b, 156 | void** unused, 157 | int* nUnused 158 | ); 159 | 160 | BZ_EXTERN int BZ_API(BZ2_bzRead) ( 161 | int* bzerror, 162 | BZFILE* b, 163 | void* buf, 164 | int len 165 | ); 166 | 167 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( 168 | int* bzerror, 169 | FILE* f, 170 | int blockSize100k, 171 | int verbosity, 172 | int workFactor 173 | ); 174 | 175 | BZ_EXTERN void BZ_API(BZ2_bzWrite) ( 176 | int* bzerror, 177 | BZFILE* b, 178 | void* buf, 179 | int len 180 | ); 181 | 182 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( 183 | int* bzerror, 184 | BZFILE* b, 185 | int abandon, 186 | unsigned int* nbytes_in, 187 | unsigned int* nbytes_out 188 | ); 189 | 190 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( 191 | int* bzerror, 192 | BZFILE* b, 193 | int abandon, 194 | unsigned int* nbytes_in_lo32, 195 | unsigned int* nbytes_in_hi32, 196 | unsigned int* nbytes_out_lo32, 197 | unsigned int* nbytes_out_hi32 198 | ); 199 | #endif 200 | 201 | 202 | /*-- Utility functions --*/ 203 | 204 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( 205 | char* dest, 206 | unsigned int* destLen, 207 | char* source, 208 | unsigned int sourceLen, 209 | int blockSize100k, 210 | int verbosity, 211 | int workFactor 212 | ); 213 | 214 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( 215 | char* dest, 216 | unsigned int* destLen, 217 | char* source, 218 | unsigned int sourceLen, 219 | int small, 220 | int verbosity 221 | ); 222 | 223 | 224 | /*-- 225 | Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) 226 | to support better zlib compatibility. 227 | This code is not _officially_ part of libbzip2 (yet); 228 | I haven't tested it, documented it, or considered the 229 | threading-safeness of it. 230 | If this code breaks, please contact both Yoshioka and me. 231 | --*/ 232 | 233 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( 234 | void 235 | ); 236 | 237 | #ifndef BZ_NO_STDIO 238 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( 239 | const char *path, 240 | const char *mode 241 | ); 242 | 243 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( 244 | int fd, 245 | const char *mode 246 | ); 247 | 248 | BZ_EXTERN int BZ_API(BZ2_bzread) ( 249 | BZFILE* b, 250 | void* buf, 251 | int len 252 | ); 253 | 254 | BZ_EXTERN int BZ_API(BZ2_bzwrite) ( 255 | BZFILE* b, 256 | void* buf, 257 | int len 258 | ); 259 | 260 | BZ_EXTERN int BZ_API(BZ2_bzflush) ( 261 | BZFILE* b 262 | ); 263 | 264 | BZ_EXTERN void BZ_API(BZ2_bzclose) ( 265 | BZFILE* b 266 | ); 267 | 268 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( 269 | BZFILE *b, 270 | int *errnum 271 | ); 272 | #endif 273 | 274 | #ifdef __cplusplus 275 | } 276 | #endif 277 | 278 | #endif 279 | 280 | /*-------------------------------------------------------------*/ 281 | /*--- end bzlib.h ---*/ 282 | /*-------------------------------------------------------------*/ 283 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/bzlib_private.h: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Private header file for the library. ---*/ 4 | /*--- bzlib_private.h ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #ifndef _BZLIB_PRIVATE_H 23 | #define _BZLIB_PRIVATE_H 24 | 25 | #include 26 | 27 | #ifndef BZ_NO_STDIO 28 | #include 29 | #include 30 | #include 31 | #endif 32 | 33 | #include "bzlib.h" 34 | 35 | 36 | 37 | /*-- General stuff. --*/ 38 | 39 | #define BZ_VERSION "1.0.6, 6-Sept-2010" 40 | 41 | typedef char Char; 42 | typedef unsigned char Bool; 43 | typedef unsigned char UChar; 44 | typedef int Int32; 45 | typedef unsigned int UInt32; 46 | typedef short Int16; 47 | typedef unsigned short UInt16; 48 | 49 | #define True ((Bool)1) 50 | #define False ((Bool)0) 51 | 52 | #ifndef __GNUC__ 53 | #define __inline__ /* */ 54 | #endif 55 | 56 | #ifndef BZ_NO_STDIO 57 | 58 | extern void BZ2_bz__AssertH__fail ( int errcode ); 59 | #define AssertH(cond,errcode) \ 60 | { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); } 61 | 62 | #if BZ_DEBUG 63 | #define AssertD(cond,msg) \ 64 | { if (!(cond)) { \ 65 | fprintf ( stderr, \ 66 | "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\ 67 | exit(1); \ 68 | }} 69 | #else 70 | #define AssertD(cond,msg) /* */ 71 | #endif 72 | 73 | #define VPrintf0(zf) \ 74 | fprintf(stderr,zf) 75 | #define VPrintf1(zf,za1) \ 76 | fprintf(stderr,zf,za1) 77 | #define VPrintf2(zf,za1,za2) \ 78 | fprintf(stderr,zf,za1,za2) 79 | #define VPrintf3(zf,za1,za2,za3) \ 80 | fprintf(stderr,zf,za1,za2,za3) 81 | #define VPrintf4(zf,za1,za2,za3,za4) \ 82 | fprintf(stderr,zf,za1,za2,za3,za4) 83 | #define VPrintf5(zf,za1,za2,za3,za4,za5) \ 84 | fprintf(stderr,zf,za1,za2,za3,za4,za5) 85 | 86 | #else 87 | 88 | extern void bz_internal_error ( int errcode ); 89 | #define AssertH(cond,errcode) \ 90 | { if (!(cond)) bz_internal_error ( errcode ); } 91 | #define AssertD(cond,msg) do { } while (0) 92 | #define VPrintf0(zf) do { } while (0) 93 | #define VPrintf1(zf,za1) do { } while (0) 94 | #define VPrintf2(zf,za1,za2) do { } while (0) 95 | #define VPrintf3(zf,za1,za2,za3) do { } while (0) 96 | #define VPrintf4(zf,za1,za2,za3,za4) do { } while (0) 97 | #define VPrintf5(zf,za1,za2,za3,za4,za5) do { } while (0) 98 | 99 | #endif 100 | 101 | 102 | #define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1) 103 | #define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp)) 104 | 105 | 106 | /*-- Header bytes. --*/ 107 | 108 | #define BZ_HDR_B 0x42 /* 'B' */ 109 | #define BZ_HDR_Z 0x5a /* 'Z' */ 110 | #define BZ_HDR_h 0x68 /* 'h' */ 111 | #define BZ_HDR_0 0x30 /* '0' */ 112 | 113 | /*-- Constants for the back end. --*/ 114 | 115 | #define BZ_MAX_ALPHA_SIZE 258 116 | #define BZ_MAX_CODE_LEN 23 117 | 118 | #define BZ_RUNA 0 119 | #define BZ_RUNB 1 120 | 121 | #define BZ_N_GROUPS 6 122 | #define BZ_G_SIZE 50 123 | #define BZ_N_ITERS 4 124 | 125 | #define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) 126 | 127 | 128 | 129 | /*-- Stuff for randomising repetitive blocks. --*/ 130 | 131 | extern Int32 BZ2_rNums[512]; 132 | 133 | #define BZ_RAND_DECLS \ 134 | Int32 rNToGo; \ 135 | Int32 rTPos \ 136 | 137 | #define BZ_RAND_INIT_MASK \ 138 | s->rNToGo = 0; \ 139 | s->rTPos = 0 \ 140 | 141 | #define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0) 142 | 143 | #define BZ_RAND_UPD_MASK \ 144 | if (s->rNToGo == 0) { \ 145 | s->rNToGo = BZ2_rNums[s->rTPos]; \ 146 | s->rTPos++; \ 147 | if (s->rTPos == 512) s->rTPos = 0; \ 148 | } \ 149 | s->rNToGo--; 150 | 151 | 152 | 153 | /*-- Stuff for doing CRCs. --*/ 154 | 155 | extern UInt32 BZ2_crc32Table[256]; 156 | 157 | #define BZ_INITIALISE_CRC(crcVar) \ 158 | { \ 159 | crcVar = 0xffffffffL; \ 160 | } 161 | 162 | #define BZ_FINALISE_CRC(crcVar) \ 163 | { \ 164 | crcVar = ~(crcVar); \ 165 | } 166 | 167 | #define BZ_UPDATE_CRC(crcVar,cha) \ 168 | { \ 169 | crcVar = (crcVar << 8) ^ \ 170 | BZ2_crc32Table[(crcVar >> 24) ^ \ 171 | ((UChar)cha)]; \ 172 | } 173 | 174 | 175 | 176 | /*-- States and modes for compression. --*/ 177 | 178 | #define BZ_M_IDLE 1 179 | #define BZ_M_RUNNING 2 180 | #define BZ_M_FLUSHING 3 181 | #define BZ_M_FINISHING 4 182 | 183 | #define BZ_S_OUTPUT 1 184 | #define BZ_S_INPUT 2 185 | 186 | #define BZ_N_RADIX 2 187 | #define BZ_N_QSORT 12 188 | #define BZ_N_SHELL 18 189 | #define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2) 190 | 191 | 192 | 193 | 194 | /*-- Structure holding all the compression-side stuff. --*/ 195 | 196 | typedef 197 | struct { 198 | /* pointer back to the struct bz_stream */ 199 | bz_stream* strm; 200 | 201 | /* mode this stream is in, and whether inputting */ 202 | /* or outputting data */ 203 | Int32 mode; 204 | Int32 state; 205 | 206 | /* remembers avail_in when flush/finish requested */ 207 | UInt32 avail_in_expect; 208 | 209 | /* for doing the block sorting */ 210 | UInt32* arr1; 211 | UInt32* arr2; 212 | UInt32* ftab; 213 | Int32 origPtr; 214 | 215 | /* aliases for arr1 and arr2 */ 216 | UInt32* ptr; 217 | UChar* block; 218 | UInt16* mtfv; 219 | UChar* zbits; 220 | 221 | /* for deciding when to use the fallback sorting algorithm */ 222 | Int32 workFactor; 223 | 224 | /* run-length-encoding of the input */ 225 | UInt32 state_in_ch; 226 | Int32 state_in_len; 227 | BZ_RAND_DECLS; 228 | 229 | /* input and output limits and current posns */ 230 | Int32 nblock; 231 | Int32 nblockMAX; 232 | Int32 numZ; 233 | Int32 state_out_pos; 234 | 235 | /* map of bytes used in block */ 236 | Int32 nInUse; 237 | Bool inUse[256]; 238 | UChar unseqToSeq[256]; 239 | 240 | /* the buffer for bit stream creation */ 241 | UInt32 bsBuff; 242 | Int32 bsLive; 243 | 244 | /* block and combined CRCs */ 245 | UInt32 blockCRC; 246 | UInt32 combinedCRC; 247 | 248 | /* misc administratium */ 249 | Int32 verbosity; 250 | Int32 blockNo; 251 | Int32 blockSize100k; 252 | 253 | /* stuff for coding the MTF values */ 254 | Int32 nMTF; 255 | Int32 mtfFreq [BZ_MAX_ALPHA_SIZE]; 256 | UChar selector [BZ_MAX_SELECTORS]; 257 | UChar selectorMtf[BZ_MAX_SELECTORS]; 258 | 259 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 260 | Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 261 | Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 262 | /* second dimension: only 3 needed; 4 makes index calculations faster */ 263 | UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]; 264 | 265 | } 266 | EState; 267 | 268 | 269 | 270 | /*-- externs for compression. --*/ 271 | 272 | extern void 273 | BZ2_blockSort ( EState* ); 274 | 275 | extern void 276 | BZ2_compressBlock ( EState*, Bool ); 277 | 278 | extern void 279 | BZ2_bsInitWrite ( EState* ); 280 | 281 | extern void 282 | BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 ); 283 | 284 | extern void 285 | BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 ); 286 | 287 | 288 | 289 | /*-- states for decompression. --*/ 290 | 291 | #define BZ_X_IDLE 1 292 | #define BZ_X_OUTPUT 2 293 | 294 | #define BZ_X_MAGIC_1 10 295 | #define BZ_X_MAGIC_2 11 296 | #define BZ_X_MAGIC_3 12 297 | #define BZ_X_MAGIC_4 13 298 | #define BZ_X_BLKHDR_1 14 299 | #define BZ_X_BLKHDR_2 15 300 | #define BZ_X_BLKHDR_3 16 301 | #define BZ_X_BLKHDR_4 17 302 | #define BZ_X_BLKHDR_5 18 303 | #define BZ_X_BLKHDR_6 19 304 | #define BZ_X_BCRC_1 20 305 | #define BZ_X_BCRC_2 21 306 | #define BZ_X_BCRC_3 22 307 | #define BZ_X_BCRC_4 23 308 | #define BZ_X_RANDBIT 24 309 | #define BZ_X_ORIGPTR_1 25 310 | #define BZ_X_ORIGPTR_2 26 311 | #define BZ_X_ORIGPTR_3 27 312 | #define BZ_X_MAPPING_1 28 313 | #define BZ_X_MAPPING_2 29 314 | #define BZ_X_SELECTOR_1 30 315 | #define BZ_X_SELECTOR_2 31 316 | #define BZ_X_SELECTOR_3 32 317 | #define BZ_X_CODING_1 33 318 | #define BZ_X_CODING_2 34 319 | #define BZ_X_CODING_3 35 320 | #define BZ_X_MTF_1 36 321 | #define BZ_X_MTF_2 37 322 | #define BZ_X_MTF_3 38 323 | #define BZ_X_MTF_4 39 324 | #define BZ_X_MTF_5 40 325 | #define BZ_X_MTF_6 41 326 | #define BZ_X_ENDHDR_2 42 327 | #define BZ_X_ENDHDR_3 43 328 | #define BZ_X_ENDHDR_4 44 329 | #define BZ_X_ENDHDR_5 45 330 | #define BZ_X_ENDHDR_6 46 331 | #define BZ_X_CCRC_1 47 332 | #define BZ_X_CCRC_2 48 333 | #define BZ_X_CCRC_3 49 334 | #define BZ_X_CCRC_4 50 335 | 336 | 337 | 338 | /*-- Constants for the fast MTF decoder. --*/ 339 | 340 | #define MTFA_SIZE 4096 341 | #define MTFL_SIZE 16 342 | 343 | 344 | 345 | /*-- Structure holding all the decompression-side stuff. --*/ 346 | 347 | typedef 348 | struct { 349 | /* pointer back to the struct bz_stream */ 350 | bz_stream* strm; 351 | 352 | /* state indicator for this stream */ 353 | Int32 state; 354 | 355 | /* for doing the final run-length decoding */ 356 | UChar state_out_ch; 357 | Int32 state_out_len; 358 | Bool blockRandomised; 359 | BZ_RAND_DECLS; 360 | 361 | /* the buffer for bit stream reading */ 362 | UInt32 bsBuff; 363 | Int32 bsLive; 364 | 365 | /* misc administratium */ 366 | Int32 blockSize100k; 367 | Bool smallDecompress; 368 | Int32 currBlockNo; 369 | Int32 verbosity; 370 | 371 | /* for undoing the Burrows-Wheeler transform */ 372 | Int32 origPtr; 373 | UInt32 tPos; 374 | Int32 k0; 375 | Int32 unzftab[256]; 376 | Int32 nblock_used; 377 | Int32 cftab[257]; 378 | Int32 cftabCopy[257]; 379 | 380 | /* for undoing the Burrows-Wheeler transform (FAST) */ 381 | UInt32 *tt; 382 | 383 | /* for undoing the Burrows-Wheeler transform (SMALL) */ 384 | UInt16 *ll16; 385 | UChar *ll4; 386 | 387 | /* stored and calculated CRCs */ 388 | UInt32 storedBlockCRC; 389 | UInt32 storedCombinedCRC; 390 | UInt32 calculatedBlockCRC; 391 | UInt32 calculatedCombinedCRC; 392 | 393 | /* map of bytes used in block */ 394 | Int32 nInUse; 395 | Bool inUse[256]; 396 | Bool inUse16[16]; 397 | UChar seqToUnseq[256]; 398 | 399 | /* for decoding the MTF values */ 400 | UChar mtfa [MTFA_SIZE]; 401 | Int32 mtfbase[256 / MTFL_SIZE]; 402 | UChar selector [BZ_MAX_SELECTORS]; 403 | UChar selectorMtf[BZ_MAX_SELECTORS]; 404 | UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 405 | 406 | Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 407 | Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 408 | Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 409 | Int32 minLens[BZ_N_GROUPS]; 410 | 411 | /* save area for scalars in the main decompress code */ 412 | Int32 save_i; 413 | Int32 save_j; 414 | Int32 save_t; 415 | Int32 save_alphaSize; 416 | Int32 save_nGroups; 417 | Int32 save_nSelectors; 418 | Int32 save_EOB; 419 | Int32 save_groupNo; 420 | Int32 save_groupPos; 421 | Int32 save_nextSym; 422 | Int32 save_nblockMAX; 423 | Int32 save_nblock; 424 | Int32 save_es; 425 | Int32 save_N; 426 | Int32 save_curr; 427 | Int32 save_zt; 428 | Int32 save_zn; 429 | Int32 save_zvec; 430 | Int32 save_zj; 431 | Int32 save_gSel; 432 | Int32 save_gMinlen; 433 | Int32* save_gLimit; 434 | Int32* save_gBase; 435 | Int32* save_gPerm; 436 | 437 | } 438 | DState; 439 | 440 | 441 | 442 | /*-- Macros for decompression. --*/ 443 | 444 | #define BZ_GET_FAST(cccc) \ 445 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 446 | if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 447 | s->tPos = s->tt[s->tPos]; \ 448 | cccc = (UChar)(s->tPos & 0xff); \ 449 | s->tPos >>= 8; 450 | 451 | #define BZ_GET_FAST_C(cccc) \ 452 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 453 | if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \ 454 | c_tPos = c_tt[c_tPos]; \ 455 | cccc = (UChar)(c_tPos & 0xff); \ 456 | c_tPos >>= 8; 457 | 458 | #define SET_LL4(i,n) \ 459 | { if (((i) & 0x1) == 0) \ 460 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \ 461 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \ 462 | } 463 | 464 | #define GET_LL4(i) \ 465 | ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF) 466 | 467 | #define SET_LL(i,n) \ 468 | { s->ll16[i] = (UInt16)(n & 0x0000ffff); \ 469 | SET_LL4(i, n >> 16); \ 470 | } 471 | 472 | #define GET_LL(i) \ 473 | (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16)) 474 | 475 | #define BZ_GET_SMALL(cccc) \ 476 | /* c_tPos is unsigned, hence test < 0 is pointless. */ \ 477 | if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \ 478 | cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \ 479 | s->tPos = GET_LL(s->tPos); 480 | 481 | 482 | /*-- externs for decompression. --*/ 483 | 484 | extern Int32 485 | BZ2_indexIntoF ( Int32, Int32* ); 486 | 487 | extern Int32 488 | BZ2_decompress ( DState* ); 489 | 490 | extern void 491 | BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, 492 | Int32, Int32, Int32 ); 493 | 494 | 495 | #endif 496 | 497 | 498 | /*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/ 499 | 500 | #ifdef BZ_NO_STDIO 501 | #ifndef NULL 502 | #define NULL 0 503 | #endif 504 | #endif 505 | 506 | 507 | /*-------------------------------------------------------------*/ 508 | /*--- end bzlib_private.h ---*/ 509 | /*-------------------------------------------------------------*/ 510 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/crctable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for doing CRCs ---*/ 4 | /*--- crctable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | /*-- 25 | I think this is an implementation of the AUTODIN-II, 26 | Ethernet & FDDI 32-bit CRC standard. Vaguely derived 27 | from code by Rob Warnock, in Section 51 of the 28 | comp.compression FAQ. 29 | --*/ 30 | 31 | UInt32 BZ2_crc32Table[256] = { 32 | 33 | /*-- Ugly, innit? --*/ 34 | 35 | 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L, 36 | 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L, 37 | 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L, 38 | 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL, 39 | 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L, 40 | 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L, 41 | 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L, 42 | 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL, 43 | 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L, 44 | 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L, 45 | 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L, 46 | 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL, 47 | 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L, 48 | 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L, 49 | 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L, 50 | 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL, 51 | 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL, 52 | 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L, 53 | 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L, 54 | 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL, 55 | 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL, 56 | 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L, 57 | 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L, 58 | 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL, 59 | 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL, 60 | 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L, 61 | 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L, 62 | 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL, 63 | 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL, 64 | 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L, 65 | 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L, 66 | 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL, 67 | 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L, 68 | 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL, 69 | 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL, 70 | 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L, 71 | 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L, 72 | 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL, 73 | 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL, 74 | 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L, 75 | 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L, 76 | 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL, 77 | 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL, 78 | 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L, 79 | 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L, 80 | 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL, 81 | 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL, 82 | 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L, 83 | 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L, 84 | 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL, 85 | 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L, 86 | 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L, 87 | 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L, 88 | 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL, 89 | 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L, 90 | 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L, 91 | 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L, 92 | 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL, 93 | 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L, 94 | 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L, 95 | 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L, 96 | 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL, 97 | 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L, 98 | 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L 99 | }; 100 | 101 | 102 | /*-------------------------------------------------------------*/ 103 | /*--- end crctable.c ---*/ 104 | /*-------------------------------------------------------------*/ 105 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/dlltest.c: -------------------------------------------------------------------------------- 1 | /* 2 | minibz2 3 | libbz2.dll test program. 4 | by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) 5 | This file is Public Domain. Welcome any email to me. 6 | 7 | usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename] 8 | */ 9 | 10 | #define BZ_IMPORT 11 | #include 12 | #include 13 | #include "bzlib.h" 14 | #ifdef _WIN32 15 | #include 16 | #endif 17 | 18 | 19 | #ifdef _WIN32 20 | 21 | #define BZ2_LIBNAME "libbz2-1.0.2.DLL" 22 | 23 | #include 24 | static int BZ2DLLLoaded = 0; 25 | static HINSTANCE BZ2DLLhLib; 26 | int BZ2DLLLoadLibrary(void) 27 | { 28 | HINSTANCE hLib; 29 | 30 | if(BZ2DLLLoaded==1){return 0;} 31 | hLib=LoadLibrary(BZ2_LIBNAME); 32 | if(hLib == NULL){ 33 | fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME); 34 | return -1; 35 | } 36 | BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion"); 37 | BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen"); 38 | BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen"); 39 | BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread"); 40 | BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite"); 41 | BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush"); 42 | BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose"); 43 | BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror"); 44 | 45 | if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen 46 | || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush 47 | || !BZ2_bzclose || !BZ2_bzerror) { 48 | fprintf(stderr,"GetProcAddress failed.\n"); 49 | return -1; 50 | } 51 | BZ2DLLLoaded=1; 52 | BZ2DLLhLib=hLib; 53 | return 0; 54 | 55 | } 56 | int BZ2DLLFreeLibrary(void) 57 | { 58 | if(BZ2DLLLoaded==0){return 0;} 59 | FreeLibrary(BZ2DLLhLib); 60 | BZ2DLLLoaded=0; 61 | } 62 | #endif /* WIN32 */ 63 | 64 | void usage(void) 65 | { 66 | puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]"); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/huffman.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Huffman coding low-level stuff ---*/ 4 | /*--- huffman.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | /*---------------------------------------------------*/ 25 | #define WEIGHTOF(zz0) ((zz0) & 0xffffff00) 26 | #define DEPTHOF(zz1) ((zz1) & 0x000000ff) 27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3)) 28 | 29 | #define ADDWEIGHTS(zw1,zw2) \ 30 | (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \ 31 | (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2))) 32 | 33 | #define UPHEAP(z) \ 34 | { \ 35 | Int32 zz, tmp; \ 36 | zz = z; tmp = heap[zz]; \ 37 | while (weight[tmp] < weight[heap[zz >> 1]]) { \ 38 | heap[zz] = heap[zz >> 1]; \ 39 | zz >>= 1; \ 40 | } \ 41 | heap[zz] = tmp; \ 42 | } 43 | 44 | #define DOWNHEAP(z) \ 45 | { \ 46 | Int32 zz, yy, tmp; \ 47 | zz = z; tmp = heap[zz]; \ 48 | while (True) { \ 49 | yy = zz << 1; \ 50 | if (yy > nHeap) break; \ 51 | if (yy < nHeap && \ 52 | weight[heap[yy+1]] < weight[heap[yy]]) \ 53 | yy++; \ 54 | if (weight[tmp] < weight[heap[yy]]) break; \ 55 | heap[zz] = heap[yy]; \ 56 | zz = yy; \ 57 | } \ 58 | heap[zz] = tmp; \ 59 | } 60 | 61 | 62 | /*---------------------------------------------------*/ 63 | void BZ2_hbMakeCodeLengths ( UChar *len, 64 | Int32 *freq, 65 | Int32 alphaSize, 66 | Int32 maxLen ) 67 | { 68 | /*-- 69 | Nodes and heap entries run from 1. Entry 0 70 | for both the heap and nodes is a sentinel. 71 | --*/ 72 | Int32 nNodes, nHeap, n1, n2, i, j, k; 73 | Bool tooLong; 74 | 75 | Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ]; 76 | Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ]; 77 | Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; 78 | 79 | for (i = 0; i < alphaSize; i++) 80 | weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8; 81 | 82 | while (True) { 83 | 84 | nNodes = alphaSize; 85 | nHeap = 0; 86 | 87 | heap[0] = 0; 88 | weight[0] = 0; 89 | parent[0] = -2; 90 | 91 | for (i = 1; i <= alphaSize; i++) { 92 | parent[i] = -1; 93 | nHeap++; 94 | heap[nHeap] = i; 95 | UPHEAP(nHeap); 96 | } 97 | 98 | AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 ); 99 | 100 | while (nHeap > 1) { 101 | n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 102 | n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); 103 | nNodes++; 104 | parent[n1] = parent[n2] = nNodes; 105 | weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]); 106 | parent[nNodes] = -1; 107 | nHeap++; 108 | heap[nHeap] = nNodes; 109 | UPHEAP(nHeap); 110 | } 111 | 112 | AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 ); 113 | 114 | tooLong = False; 115 | for (i = 1; i <= alphaSize; i++) { 116 | j = 0; 117 | k = i; 118 | while (parent[k] >= 0) { k = parent[k]; j++; } 119 | len[i-1] = j; 120 | if (j > maxLen) tooLong = True; 121 | } 122 | 123 | if (! tooLong) break; 124 | 125 | /* 17 Oct 04: keep-going condition for the following loop used 126 | to be 'i < alphaSize', which missed the last element, 127 | theoretically leading to the possibility of the compressor 128 | looping. However, this count-scaling step is only needed if 129 | one of the generated Huffman code words is longer than 130 | maxLen, which up to and including version 1.0.2 was 20 bits, 131 | which is extremely unlikely. In version 1.0.3 maxLen was 132 | changed to 17 bits, which has minimal effect on compression 133 | ratio, but does mean this scaling step is used from time to 134 | time, enough to verify that it works. 135 | 136 | This means that bzip2-1.0.3 and later will only produce 137 | Huffman codes with a maximum length of 17 bits. However, in 138 | order to preserve backwards compatibility with bitstreams 139 | produced by versions pre-1.0.3, the decompressor must still 140 | handle lengths of up to 20. */ 141 | 142 | for (i = 1; i <= alphaSize; i++) { 143 | j = weight[i] >> 8; 144 | j = 1 + (j / 2); 145 | weight[i] = j << 8; 146 | } 147 | } 148 | } 149 | 150 | 151 | /*---------------------------------------------------*/ 152 | void BZ2_hbAssignCodes ( Int32 *code, 153 | UChar *length, 154 | Int32 minLen, 155 | Int32 maxLen, 156 | Int32 alphaSize ) 157 | { 158 | Int32 n, vec, i; 159 | 160 | vec = 0; 161 | for (n = minLen; n <= maxLen; n++) { 162 | for (i = 0; i < alphaSize; i++) 163 | if (length[i] == n) { code[i] = vec; vec++; }; 164 | vec <<= 1; 165 | } 166 | } 167 | 168 | 169 | /*---------------------------------------------------*/ 170 | void BZ2_hbCreateDecodeTables ( Int32 *limit, 171 | Int32 *base, 172 | Int32 *perm, 173 | UChar *length, 174 | Int32 minLen, 175 | Int32 maxLen, 176 | Int32 alphaSize ) 177 | { 178 | Int32 pp, i, j, vec; 179 | 180 | pp = 0; 181 | for (i = minLen; i <= maxLen; i++) 182 | for (j = 0; j < alphaSize; j++) 183 | if (length[j] == i) { perm[pp] = j; pp++; }; 184 | 185 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0; 186 | for (i = 0; i < alphaSize; i++) base[length[i]+1]++; 187 | 188 | for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1]; 189 | 190 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0; 191 | vec = 0; 192 | 193 | for (i = minLen; i <= maxLen; i++) { 194 | vec += (base[i+1] - base[i]); 195 | limit[i] = vec-1; 196 | vec <<= 1; 197 | } 198 | for (i = minLen + 1; i <= maxLen; i++) 199 | base[i] = ((limit[i-1] + 1) << 1) - base[i]; 200 | } 201 | 202 | 203 | /*-------------------------------------------------------------*/ 204 | /*--- end huffman.c ---*/ 205 | /*-------------------------------------------------------------*/ 206 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/randtable.c: -------------------------------------------------------------------------------- 1 | 2 | /*-------------------------------------------------------------*/ 3 | /*--- Table for randomising repetitive blocks ---*/ 4 | /*--- randtable.c ---*/ 5 | /*-------------------------------------------------------------*/ 6 | 7 | /* ------------------------------------------------------------------ 8 | This file is part of bzip2/libbzip2, a program and library for 9 | lossless, block-sorting data compression. 10 | 11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010 12 | Copyright (C) 1996-2010 Julian Seward 13 | 14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the 15 | README file. 16 | 17 | This program is released under the terms of the license contained 18 | in the file LICENSE. 19 | ------------------------------------------------------------------ */ 20 | 21 | 22 | #include "bzlib_private.h" 23 | 24 | 25 | /*---------------------------------------------*/ 26 | Int32 BZ2_rNums[512] = { 27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, 28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, 29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, 30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, 31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, 32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, 33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, 34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, 35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, 36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, 37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, 38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, 39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, 40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, 41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, 42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, 43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, 44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, 45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, 46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, 47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, 48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, 49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, 50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, 51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, 52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, 53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, 54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, 55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, 56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, 57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, 58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, 59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, 60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, 61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, 62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, 63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, 64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, 65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, 66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, 67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, 68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, 69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, 70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, 71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, 72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, 73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, 74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, 75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, 76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, 77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, 78 | 936, 638 79 | }; 80 | 81 | 82 | /*-------------------------------------------------------------*/ 83 | /*--- end randtable.c ---*/ 84 | /*-------------------------------------------------------------*/ 85 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/bzip2/readMe.txt: -------------------------------------------------------------------------------- 1 | bzip2包中文件来来自: 2 | http://www.bzip.org/downloads.html -------------------------------------------------------------------------------- /PatchLibraryServer/jni/com_cundong_utils_DiffUtils.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2003-2005 Colin Percival 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. 25 | */ 26 | 27 | #if 0 28 | __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05 cperciva Exp $"); 29 | #endif 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "com_cundong_utils_DiffUtils.h" 42 | 43 | #define MIN(x,y) (((x)<(y)) ? (x) : (y)) 44 | 45 | static void split(off_t *I, off_t *V, off_t start, off_t len, off_t h) { 46 | off_t i, j, k, x, tmp, jj, kk; 47 | 48 | if (len < 16) { 49 | for (k = start; k < start + len; k += j) { 50 | j = 1; 51 | x = V[I[k] + h]; 52 | for (i = 1; k + i < start + len; i++) { 53 | if (V[I[k + i] + h] < x) { 54 | x = V[I[k + i] + h]; 55 | j = 0; 56 | }; 57 | if (V[I[k + i] + h] == x) { 58 | tmp = I[k + j]; 59 | I[k + j] = I[k + i]; 60 | I[k + i] = tmp; 61 | j++; 62 | }; 63 | }; 64 | for (i = 0; i < j; i++) 65 | V[I[k + i]] = k + j - 1; 66 | if (j == 1) 67 | I[k] = -1; 68 | }; 69 | return; 70 | }; 71 | 72 | x = V[I[start + len / 2] + h]; 73 | jj = 0; 74 | kk = 0; 75 | for (i = start; i < start + len; i++) { 76 | if (V[I[i] + h] < x) 77 | jj++; 78 | if (V[I[i] + h] == x) 79 | kk++; 80 | }; 81 | jj += start; 82 | kk += jj; 83 | 84 | i = start; 85 | j = 0; 86 | k = 0; 87 | while (i < jj) { 88 | if (V[I[i] + h] < x) { 89 | i++; 90 | } else if (V[I[i] + h] == x) { 91 | tmp = I[i]; 92 | I[i] = I[jj + j]; 93 | I[jj + j] = tmp; 94 | j++; 95 | } else { 96 | tmp = I[i]; 97 | I[i] = I[kk + k]; 98 | I[kk + k] = tmp; 99 | k++; 100 | }; 101 | }; 102 | 103 | while (jj + j < kk) { 104 | if (V[I[jj + j] + h] == x) { 105 | j++; 106 | } else { 107 | tmp = I[jj + j]; 108 | I[jj + j] = I[kk + k]; 109 | I[kk + k] = tmp; 110 | k++; 111 | }; 112 | }; 113 | 114 | if (jj > start) 115 | split(I, V, start, jj - start, h); 116 | 117 | for (i = 0; i < kk - jj; i++) 118 | V[I[jj + i]] = kk - 1; 119 | if (jj == kk - 1) 120 | I[jj] = -1; 121 | 122 | if (start + len > kk) 123 | split(I, V, kk, start + len - kk, h); 124 | } 125 | 126 | static void qsufsort(off_t *I, off_t *V, u_char *old, off_t oldsize) { 127 | off_t buckets[256]; 128 | off_t i, h, len; 129 | 130 | for (i = 0; i < 256; i++) 131 | buckets[i] = 0; 132 | for (i = 0; i < oldsize; i++) 133 | buckets[old[i]]++; 134 | for (i = 1; i < 256; i++) 135 | buckets[i] += buckets[i - 1]; 136 | for (i = 255; i > 0; i--) 137 | buckets[i] = buckets[i - 1]; 138 | buckets[0] = 0; 139 | 140 | for (i = 0; i < oldsize; i++) 141 | I[++buckets[old[i]]] = i; 142 | I[0] = oldsize; 143 | for (i = 0; i < oldsize; i++) 144 | V[i] = buckets[old[i]]; 145 | V[oldsize] = 0; 146 | for (i = 1; i < 256; i++) 147 | if (buckets[i] == buckets[i - 1] + 1) 148 | I[buckets[i]] = -1; 149 | I[0] = -1; 150 | 151 | for (h = 1; I[0] != -(oldsize + 1); h += h) { 152 | len = 0; 153 | for (i = 0; i < oldsize + 1;) { 154 | if (I[i] < 0) { 155 | len -= I[i]; 156 | i -= I[i]; 157 | } else { 158 | if (len) 159 | I[i - len] = -len; 160 | len = V[I[i]] + 1 - i; 161 | split(I, V, i, len, h); 162 | i += len; 163 | len = 0; 164 | }; 165 | }; 166 | if (len) 167 | I[i - len] = -len; 168 | }; 169 | 170 | for (i = 0; i < oldsize + 1; i++) 171 | I[V[i]] = i; 172 | } 173 | 174 | static off_t matchlen(u_char *old, off_t oldsize, u_char *new, off_t newsize) { 175 | off_t i; 176 | 177 | for (i = 0; (i < oldsize) && (i < newsize); i++) 178 | if (old[i] != new[i]) 179 | break; 180 | 181 | return i; 182 | } 183 | 184 | static off_t search(off_t *I, u_char *old, off_t oldsize, u_char *new, 185 | off_t newsize, off_t st, off_t en, off_t *pos) { 186 | off_t x, y; 187 | 188 | if (en - st < 2) { 189 | x = matchlen(old + I[st], oldsize - I[st], new, newsize); 190 | y = matchlen(old + I[en], oldsize - I[en], new, newsize); 191 | 192 | if (x > y) { 193 | *pos = I[st]; 194 | return x; 195 | } else { 196 | *pos = I[en]; 197 | return y; 198 | } 199 | }; 200 | 201 | x = st + (en - st) / 2; 202 | if (memcmp(old + I[x], new, MIN(oldsize-I[x],newsize)) < 0) { 203 | return search(I, old, oldsize, new, newsize, x, en, pos); 204 | } else { 205 | return search(I, old, oldsize, new, newsize, st, x, pos); 206 | }; 207 | } 208 | 209 | static void offtout(off_t x, u_char *buf) { 210 | off_t y; 211 | 212 | if (x < 0) 213 | y = -x; 214 | else 215 | y = x; 216 | 217 | buf[0] = y % 256; 218 | y -= buf[0]; 219 | y = y / 256; 220 | buf[1] = y % 256; 221 | y -= buf[1]; 222 | y = y / 256; 223 | buf[2] = y % 256; 224 | y -= buf[2]; 225 | y = y / 256; 226 | buf[3] = y % 256; 227 | y -= buf[3]; 228 | y = y / 256; 229 | buf[4] = y % 256; 230 | y -= buf[4]; 231 | y = y / 256; 232 | buf[5] = y % 256; 233 | y -= buf[5]; 234 | y = y / 256; 235 | buf[6] = y % 256; 236 | y -= buf[6]; 237 | y = y / 256; 238 | buf[7] = y % 256; 239 | 240 | if (x < 0) 241 | buf[7] |= 0x80; 242 | } 243 | 244 | int genpatch(int argc, char *argv[]) { 245 | int fd; 246 | u_char *old, *new; 247 | off_t oldsize, newsize; 248 | off_t *I, *V; 249 | off_t scan, pos, len; 250 | off_t lastscan, lastpos, lastoffset; 251 | off_t oldscore, scsc; 252 | off_t s, Sf, lenf, Sb, lenb; 253 | off_t overlap, Ss, lens; 254 | off_t i; 255 | off_t dblen, eblen; 256 | u_char *db, *eb; 257 | u_char buf[8]; 258 | u_char header[32]; 259 | FILE * pf; 260 | BZFILE * pfbz2; 261 | int bz2err; 262 | 263 | if (argc != 4) 264 | errx(1, "usage: %s oldfile newfile patchfile\n", argv[0]); 265 | 266 | /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure 267 | that we never try to malloc(0) and get a NULL pointer */ 268 | if (((fd = open(argv[1], O_RDONLY, 0)) < 0) 269 | || ((oldsize = lseek(fd, 0, SEEK_END)) == -1) 270 | || ((old = malloc(oldsize + 1)) == NULL ) 271 | || (lseek(fd, 0, SEEK_SET) != 0) 272 | || (read(fd, old, oldsize) != oldsize) || (close(fd) == -1))err(1, "%s", argv[1]); 273 | 274 | if (((I = malloc((oldsize + 1) * sizeof(off_t))) == NULL ) 275 | || ((V = malloc((oldsize + 1) * sizeof(off_t))) == NULL))err(1, NULL); 276 | 277 | qsufsort(I, V, old, oldsize); 278 | 279 | free(V); 280 | 281 | /* Allocate newsize+1 bytes instead of newsize bytes to ensure 282 | that we never try to malloc(0) and get a NULL pointer */ 283 | if (((fd = open(argv[2], O_RDONLY, 0)) < 0) 284 | || ((newsize = lseek(fd, 0, SEEK_END)) == -1) 285 | || ((new = malloc(newsize + 1)) == NULL ) 286 | || (lseek(fd, 0, SEEK_SET) != 0) 287 | || (read(fd, new, newsize) != newsize) || (close(fd) == -1))err(1, "%s", argv[2]); 288 | 289 | if (((db = malloc(newsize + 1)) == NULL ) 290 | || ((eb = malloc(newsize + 1)) == NULL))err(1, NULL); 291 | dblen = 0; 292 | eblen = 0; 293 | 294 | /* Create the patch file */ 295 | if ((pf = fopen(argv[3], "w")) == NULL ) 296 | err(1, "%s", argv[3]); 297 | 298 | /* Header is 299 | 0 8 "BSDIFF40" 300 | 8 8 length of bzip2ed ctrl block 301 | 16 8 length of bzip2ed diff block 302 | 24 8 length of new file */ 303 | /* File is 304 | 0 32 Header 305 | 32 ?? Bzip2ed ctrl block 306 | ?? ?? Bzip2ed diff block 307 | ?? ?? Bzip2ed extra block */ 308 | memcpy(header, "BSDIFF40", 8); 309 | offtout(0, header + 8); 310 | offtout(0, header + 16); 311 | offtout(newsize, header + 24); 312 | if (fwrite(header, 32, 1, pf) != 1) 313 | err(1, "fwrite(%s)", argv[3]); 314 | 315 | /* Compute the differences, writing ctrl as we go */ 316 | if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL ) 317 | errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); 318 | scan = 0; 319 | len = 0; 320 | lastscan = 0; 321 | lastpos = 0; 322 | lastoffset = 0; 323 | while (scan < newsize) { 324 | oldscore = 0; 325 | 326 | for (scsc = scan += len; scan < newsize; scan++) { 327 | len = search(I, old, oldsize, new + scan, newsize - scan, 0, 328 | oldsize, &pos); 329 | 330 | for (; scsc < scan + len; scsc++) 331 | if ((scsc + lastoffset < oldsize) 332 | && (old[scsc + lastoffset] == new[scsc])) 333 | oldscore++; 334 | 335 | if (((len == oldscore) && (len != 0)) || (len > oldscore + 8)) 336 | break; 337 | 338 | if ((scan + lastoffset < oldsize) 339 | && (old[scan + lastoffset] == new[scan])) 340 | oldscore--; 341 | }; 342 | 343 | if ((len != oldscore) || (scan == newsize)) { 344 | s = 0; 345 | Sf = 0; 346 | lenf = 0; 347 | for (i = 0; (lastscan + i < scan) && (lastpos + i < oldsize);) { 348 | if (old[lastpos + i] == new[lastscan + i]) 349 | s++; 350 | i++; 351 | if (s * 2 - i > Sf * 2 - lenf) { 352 | Sf = s; 353 | lenf = i; 354 | }; 355 | }; 356 | 357 | lenb = 0; 358 | if (scan < newsize) { 359 | s = 0; 360 | Sb = 0; 361 | for (i = 1; (scan >= lastscan + i) && (pos >= i); i++) { 362 | if (old[pos - i] == new[scan - i]) 363 | s++; 364 | if (s * 2 - i > Sb * 2 - lenb) { 365 | Sb = s; 366 | lenb = i; 367 | }; 368 | }; 369 | }; 370 | 371 | if (lastscan + lenf > scan - lenb) { 372 | overlap = (lastscan + lenf) - (scan - lenb); 373 | s = 0; 374 | Ss = 0; 375 | lens = 0; 376 | for (i = 0; i < overlap; i++) { 377 | if (new[lastscan + lenf - overlap + i] 378 | == old[lastpos + lenf - overlap + i]) 379 | s++; 380 | if (new[scan - lenb + i] == old[pos - lenb + i]) 381 | s--; 382 | if (s > Ss) { 383 | Ss = s; 384 | lens = i + 1; 385 | }; 386 | }; 387 | 388 | lenf += lens - overlap; 389 | lenb -= lens; 390 | }; 391 | 392 | for (i = 0; i < lenf; i++) 393 | db[dblen + i] = new[lastscan + i] - old[lastpos + i]; 394 | for (i = 0; i < (scan - lenb) - (lastscan + lenf); i++) 395 | eb[eblen + i] = new[lastscan + lenf + i]; 396 | 397 | dblen += lenf; 398 | eblen += (scan - lenb) - (lastscan + lenf); 399 | 400 | offtout(lenf, buf); 401 | BZ2_bzWrite(&bz2err, pfbz2, buf, 8); 402 | if (bz2err != BZ_OK) 403 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); 404 | 405 | offtout((scan - lenb) - (lastscan + lenf), buf); 406 | BZ2_bzWrite(&bz2err, pfbz2, buf, 8); 407 | if (bz2err != BZ_OK) 408 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); 409 | 410 | offtout((pos - lenb) - (lastpos + lenf), buf); 411 | BZ2_bzWrite(&bz2err, pfbz2, buf, 8); 412 | if (bz2err != BZ_OK) 413 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); 414 | 415 | lastscan = scan - lenb; 416 | lastpos = pos - lenb; 417 | lastoffset = pos - scan; 418 | }; 419 | }; 420 | BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL ); 421 | if (bz2err != BZ_OK) 422 | errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err); 423 | 424 | /* Compute size of compressed ctrl data */ 425 | if ((len = ftello(pf)) == -1) 426 | err(1, "ftello"); 427 | offtout(len - 32, header + 8); 428 | 429 | /* Write compressed diff data */ 430 | if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL ) 431 | errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); 432 | BZ2_bzWrite(&bz2err, pfbz2, db, dblen); 433 | if (bz2err != BZ_OK) 434 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); 435 | BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL ); 436 | if (bz2err != BZ_OK) 437 | errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err); 438 | 439 | /* Compute size of compressed diff data */ 440 | if ((newsize = ftello(pf)) == -1) 441 | err(1, "ftello"); 442 | offtout(newsize - len, header + 16); 443 | 444 | /* Write compressed extra data */ 445 | if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL ) 446 | errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); 447 | BZ2_bzWrite(&bz2err, pfbz2, eb, eblen); 448 | if (bz2err != BZ_OK) 449 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); 450 | BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL ); 451 | if (bz2err != BZ_OK) 452 | errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err); 453 | 454 | /* Seek to the beginning, write the header, and close the file */ 455 | if (fseeko(pf, 0, SEEK_SET)) 456 | err(1, "fseeko"); 457 | if (fwrite(header, 32, 1, pf) != 1) 458 | err(1, "fwrite(%s)", argv[3]); 459 | if (fclose(pf)) 460 | err(1, "fclose"); 461 | 462 | /* Free the memory we used */ 463 | free(db); 464 | free(eb); 465 | free(I); 466 | free(old); 467 | free(new); 468 | 469 | return 0; 470 | } 471 | 472 | JNIEXPORT jint JNICALL Java_com_cundong_utils_DiffUtils_genDiff(JNIEnv *env, 473 | jclass cls, jstring old, jstring new, jstring patch) { 474 | int argc = 4; 475 | char * argv[argc]; 476 | argv[0] = "bsdiff"; 477 | argv[1] = (char*) ((*env)->GetStringUTFChars(env, old, 0)); 478 | argv[2] = (char*) ((*env)->GetStringUTFChars(env, new, 0)); 479 | argv[3] = (char*) ((*env)->GetStringUTFChars(env, patch, 0)); 480 | 481 | printf("old apk = %s \n", argv[1]); 482 | printf("new apk = %s \n", argv[2]); 483 | printf("patch = %s \n", argv[3]); 484 | 485 | int ret = genpatch(argc, argv); 486 | 487 | printf("genDiff result = %d ", ret); 488 | 489 | (*env)->ReleaseStringUTFChars(env, old, argv[1]); 490 | (*env)->ReleaseStringUTFChars(env, new, argv[2]); 491 | (*env)->ReleaseStringUTFChars(env, patch, argv[3]); 492 | 493 | return ret; 494 | } 495 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/com_cundong_utils_DiffUtils.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_cundong_utils_JDiff */ 4 | 5 | #ifndef _Included_com_cundong_utils_JDiff 6 | #define _Included_com_cundong_utils_JDiff 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_cundong_utils_DiffUtils 12 | * Method: genDiff 13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_cundong_utils_DiffUtils_genDiff 16 | (JNIEnv *, jclass, jstring, jstring, jstring); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/com_cundong_utils_PatchUtils.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2003-2005 Colin Percival 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. 25 | */ 26 | 27 | #if 0 28 | __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $"); 29 | #endif 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "com_cundong_utils_PatchUtils.h" 43 | 44 | static off_t offtin(u_char *buf) 45 | { 46 | off_t y; 47 | 48 | y=buf[7]&0x7F; 49 | y=y*256;y+=buf[6]; 50 | y=y*256;y+=buf[5]; 51 | y=y*256;y+=buf[4]; 52 | y=y*256;y+=buf[3]; 53 | y=y*256;y+=buf[2]; 54 | y=y*256;y+=buf[1]; 55 | y=y*256;y+=buf[0]; 56 | 57 | if(buf[7]&0x80) y=-y; 58 | 59 | return y; 60 | } 61 | 62 | int applypatch(int argc,char * argv[]) 63 | { 64 | FILE * f, * cpf, * dpf, * epf; 65 | BZFILE * cpfbz2, * dpfbz2, * epfbz2; 66 | int cbz2err, dbz2err, ebz2err; 67 | int fd; 68 | ssize_t oldsize,newsize; 69 | ssize_t bzctrllen,bzdatalen; 70 | u_char header[32],buf[8]; 71 | u_char *old, *new; 72 | off_t oldpos,newpos; 73 | off_t ctrl[3]; 74 | off_t lenread; 75 | off_t i; 76 | 77 | if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); 78 | 79 | /* Open patch file */ 80 | if ((f = fopen(argv[3], "r")) == NULL) 81 | err(1, "fopen(%s)", argv[3]); 82 | 83 | /* 84 | File format: 85 | 0 8 "BSDIFF40" 86 | 8 8 X 87 | 16 8 Y 88 | 24 8 sizeof(newfile) 89 | 32 X bzip2(control block) 90 | 32+X Y bzip2(diff block) 91 | 32+X+Y ??? bzip2(extra block) 92 | with control block a set of triples (x,y,z) meaning "add x bytes 93 | from oldfile to x bytes from the diff block; copy y bytes from the 94 | extra block; seek forwards in oldfile by z bytes". 95 | */ 96 | 97 | /* Read header */ 98 | if (fread(header, 1, 32, f) < 32) { 99 | if (feof(f)) 100 | errx(1, "Corrupt patch\n"); 101 | err(1, "fread(%s)", argv[3]); 102 | } 103 | 104 | /* Check for appropriate magic */ 105 | if (memcmp(header, "BSDIFF40", 8) != 0) 106 | errx(1, "Corrupt patch\n"); 107 | 108 | /* Read lengths from header */ 109 | bzctrllen=offtin(header+8); 110 | bzdatalen=offtin(header+16); 111 | newsize=offtin(header+24); 112 | if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) 113 | errx(1,"Corrupt patch\n"); 114 | 115 | /* Close patch file and re-open it via libbzip2 at the right places */ 116 | if (fclose(f)) 117 | err(1, "fclose(%s)", argv[3]); 118 | if ((cpf = fopen(argv[3], "r")) == NULL) 119 | err(1, "fopen(%s)", argv[3]); 120 | if (fseeko(cpf, 32, SEEK_SET)) 121 | err(1, "fseeko(%s, %lld)", argv[3], 122 | (long long)32); 123 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) 124 | errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); 125 | if ((dpf = fopen(argv[3], "r")) == NULL) 126 | err(1, "fopen(%s)", argv[3]); 127 | if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) 128 | err(1, "fseeko(%s, %lld)", argv[3], 129 | (long long)(32 + bzctrllen)); 130 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) 131 | errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); 132 | if ((epf = fopen(argv[3], "r")) == NULL) 133 | err(1, "fopen(%s)", argv[3]); 134 | if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) 135 | err(1, "fseeko(%s, %lld)", argv[3], 136 | (long long)(32 + bzctrllen + bzdatalen)); 137 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) 138 | errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); 139 | 140 | if(((fd=open(argv[1],O_RDONLY,0))<0) || 141 | ((oldsize=lseek(fd,0,SEEK_END))==-1) || 142 | ((old=malloc(oldsize+1))==NULL) || 143 | (lseek(fd,0,SEEK_SET)!=0) || 144 | (read(fd,old,oldsize)!=oldsize) || 145 | (close(fd)==-1)) err(1,"%s",argv[1]); 146 | if((new=malloc(newsize+1))==NULL) err(1,NULL); 147 | 148 | oldpos=0;newpos=0; 149 | while(newposnewsize) 161 | errx(1,"Corrupt patch\n"); 162 | 163 | /* Read diff string */ 164 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); 165 | if ((lenread < ctrl[0]) || 166 | ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) 167 | errx(1, "Corrupt patch\n"); 168 | 169 | /* Add old data to diff string */ 170 | for(i=0;i=0) && (oldpos+inewsize) 180 | errx(1,"Corrupt patch\n"); 181 | 182 | /* Read extra string */ 183 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); 184 | if ((lenread < ctrl[1]) || 185 | ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) 186 | errx(1, "Corrupt patch\n"); 187 | 188 | /* Adjust pointers */ 189 | newpos+=ctrl[1]; 190 | oldpos+=ctrl[2]; 191 | }; 192 | 193 | /* Clean up the bzip2 reads */ 194 | BZ2_bzReadClose(&cbz2err, cpfbz2); 195 | BZ2_bzReadClose(&dbz2err, dpfbz2); 196 | BZ2_bzReadClose(&ebz2err, epfbz2); 197 | if (fclose(cpf) || fclose(dpf) || fclose(epf)) 198 | err(1, "fclose(%s)", argv[3]); 199 | 200 | /* Write the new file */ 201 | if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || 202 | (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) 203 | err(1,"%s",argv[2]); 204 | 205 | free(new); 206 | free(old); 207 | 208 | return 0; 209 | } 210 | 211 | JNIEXPORT jint JNICALL Java_com_cundong_utils_PatchUtils_patch 212 | (JNIEnv *env, jclass cls, 213 | jstring old, jstring new, jstring patch){ 214 | int argc = 4; 215 | char * argv[argc]; 216 | argv[0] = "bspatch"; 217 | argv[1] = (char*) ((*env)->GetStringUTFChars(env, old, 0)); 218 | argv[2] = (char*) ((*env)->GetStringUTFChars(env, new, 0)); 219 | argv[3] = (char*) ((*env)->GetStringUTFChars(env, patch, 0)); 220 | 221 | printf("old apk = %s \n", argv[1]); 222 | printf("patch = %s \n", argv[3]); 223 | printf("new apk = %s \n", argv[2]); 224 | 225 | int ret = applypatch(argc, argv); 226 | 227 | printf("patch result = %d ", ret); 228 | 229 | (*env)->ReleaseStringUTFChars(env, old, argv[1]); 230 | (*env)->ReleaseStringUTFChars(env, new, argv[2]); 231 | (*env)->ReleaseStringUTFChars(env, patch, argv[3]); 232 | return ret; 233 | } 234 | -------------------------------------------------------------------------------- /PatchLibraryServer/jni/com_cundong_utils_PatchUtils.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_cundong_utils_JPatch */ 4 | 5 | #ifndef _Included_com_cundong_utils_JPatch 6 | #define _Included_com_cundong_utils_JPatch 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_cundong_utils_PatchUtils 12 | * Method: genNewApk 13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_cundong_utils_PatchUtils_patch 16 | (JNIEnv *, jclass, jstring, jstring, jstring); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /PatchLibraryServer/libApkPatchLibraryServer.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/libApkPatchLibraryServer.dylib -------------------------------------------------------------------------------- /PatchLibraryServer/src/com/cundong/apkdiff/ApkDiffDemo.java: -------------------------------------------------------------------------------- 1 | package com.cundong.apkdiff; 2 | 3 | import com.cundong.common.Constants; 4 | import com.cundong.utils.DiffUtils; 5 | 6 | /** 7 | * 类说明: 新旧apk包,生成差分包实例 8 | * 9 | * @author Cundong 10 | * @date 2014-9-6 11 | * @version 1.2 12 | */ 13 | public class ApkDiffDemo { 14 | 15 | public static void main(String[] args) { 16 | 17 | long start = System.currentTimeMillis(); 18 | 19 | System.out.println("开始生成差分包,请等待..."); 20 | 21 | int genDiff = DiffUtils.genDiff(Constants.OLD_APK, Constants.NEW_APK, 22 | Constants.PATCH_FILE); 23 | 24 | long end = System.currentTimeMillis(); 25 | 26 | System.out.println("生成差分包成功:" + Constants.PATCH_FILE + ",耗时:" 27 | + (end - start) / 1000 + "秒, result=" + genDiff); 28 | } 29 | 30 | static { 31 | System.loadLibrary("ApkPatchLibraryServer"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /PatchLibraryServer/src/com/cundong/apkpatch/ApkPatchDemo.java: -------------------------------------------------------------------------------- 1 | package com.cundong.apkpatch; 2 | 3 | import com.cundong.common.Constants; 4 | import com.cundong.utils.PatchUtils; 5 | 6 | /** 7 | * 类说明: 使用旧版apk包+差分包,合并新包实例 8 | * 9 | * @author Cundong 10 | * @date 2014-9-6 11 | * @version 1.2 12 | */ 13 | public class ApkPatchDemo { 14 | 15 | public static void main(String[] args) { 16 | 17 | long start = System.currentTimeMillis(); 18 | 19 | System.out.println("开始合成新包,请等待..."); 20 | 21 | start = System.currentTimeMillis(); 22 | 23 | int patchResult = PatchUtils.patch(Constants.OLD_APK, Constants.OLD_2_NEW_APK, Constants.PATCH_FILE); 24 | 25 | long end = System.currentTimeMillis(); 26 | 27 | System.out.println("合成新包成功:" + Constants.NEW_APK + ",耗时:" + (end - start) 28 | / 1000 + "秒,patchResult=" + patchResult); 29 | } 30 | 31 | static { 32 | System.loadLibrary("ApkPatchLibraryServer"); 33 | } 34 | } -------------------------------------------------------------------------------- /PatchLibraryServer/src/com/cundong/common/Constants.java: -------------------------------------------------------------------------------- 1 | package com.cundong.common; 2 | 3 | public class Constants { 4 | 5 | // 旧版本微博 6 | public static final String OLD_APK = "common.js"; 7 | 8 | // 新版本微博 9 | public static final String NEW_APK = "familyAddress.android.bundle"; 10 | 11 | // patch包存储路径 12 | public static final String PATCH_FILE = "10001.patch"; 13 | 14 | // 使用旧版本微博+patch包,合成的新包 15 | public static final String OLD_2_NEW_APK = "/Users/cundong/Documents/SmartAppUpdates/weiboOld2New.apk"; 16 | } -------------------------------------------------------------------------------- /PatchLibraryServer/src/com/cundong/utils/DiffUtils.java: -------------------------------------------------------------------------------- 1 | package com.cundong.utils; 2 | 3 | /** 4 | * 类说明: APK Diff工具类 5 | * 6 | * @author Cundong 7 | * @date 2013-9-6 8 | * @version 1.0 9 | */ 10 | public class DiffUtils { 11 | 12 | /** 13 | * native方法 比较路径为oldPath的apk与newPath的apk之间差异,并生成patch包,存储于patchPath 14 | * 15 | * 返回:0,说明操作成功 16 | * 17 | * @param oldApkPath 示例:/sdcard/old.apk 18 | * @param newApkPath 示例:/sdcard/new.apk 19 | * @param patchPath 示例:/sdcard/xx.patch 20 | * @return 21 | */ 22 | public static native int genDiff(String oldApkPath, String newApkPath, String patchPath); 23 | } -------------------------------------------------------------------------------- /PatchLibraryServer/src/com/cundong/utils/PatchUtils.java: -------------------------------------------------------------------------------- 1 | package com.cundong.utils; 2 | 3 | /** 4 | * 类说明: APK Patch工具类 5 | * 6 | * @author Cundong 7 | * @date 2013-9-6 8 | * @version 1.0 9 | */ 10 | public class PatchUtils { 11 | 12 | /** 13 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath 14 | * 15 | * 返回:0,说明操作成功 16 | * 17 | * @param oldApkPath 示例:/sdcard/old.apk 18 | * @param newApkPath 示例:/sdcard/new.apk 19 | * @param patchPath 示例:/sdcard/xx.patch 20 | * @return 21 | */ 22 | public static native int patch(String oldApkPath, String newApkPath, 23 | String patchPath); 24 | } -------------------------------------------------------------------------------- /PatchLibraryServer/update.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pukaicom/ReactNativeBsdiff/d18e25f2b261cc1cc095e30f8f50c6d9bfa22881/PatchLibraryServer/update.patch -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReactNativeBsdiff 2 | da 结合ReactNative bundle的基本特点 使用bsdiff 合成实现 reactNative bundle的 拆分和合成 3 | da 可以使用 bsdiff的源代码(C语言)使用ndk 自己编译so 4 | da demo里面有server的源代码可在mac os eclipse下直接运行 将需要做查分的文件 放进去即可生成差分包 5 | da module.json 是对每个业务bundle的 定义 程序运行时会预先去解析bundle的内容然后在本地合成相应的业务bundle 6 | da DDDD 7 | --------------------------------------------------------------------------------