├── .gitignore ├── ApkPatchLibrary ├── .cproject ├── .externalToolBuilders │ └── NDK_Builder__.launch ├── .gitignore ├── AndroidManifest.xml ├── jni │ ├── Android.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_jph_utils_PatchUtils.c │ └── com_jph_utils_PatchUtils.h ├── libs │ └── armeabi │ │ └── libApkPatchLibrary.so ├── lint.xml ├── obj │ └── local │ │ └── armeabi │ │ ├── libApkPatchLibrary.so │ │ └── objs │ │ └── ApkPatchLibrary │ │ ├── com_cundong_utils_PatchUtils.o │ │ ├── com_cundong_utils_PatchUtils.o.d │ │ ├── com_jph_utils_PatchUtils.o │ │ └── com_jph_utils_PatchUtils.o.d ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── jph │ └── utils │ └── PatchUtils.java ├── IncrementalUpdate-Android ├── .gitignore ├── .idea │ └── vcs.xml ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── jph │ │ │ ├── iu │ │ │ └── activity │ │ │ │ ├── ApkUtils.java │ │ │ │ ├── Constants.java │ │ │ │ ├── MainActivity.java │ │ │ │ └── SignUtils.java │ │ │ └── utils │ │ │ └── PatchUtils.java │ │ ├── jniLibs │ │ └── armeabi │ │ │ └── libApkPatchLibrary.so │ │ └── res │ │ ├── layout │ │ └── 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 ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── IncrementalUpdate-web ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent │ ├── ApplyPatch.jsp │ ├── GenPatch.jsp │ ├── META-INF │ │ └── MANIFEST.MF │ └── WEB-INF │ │ ├── lib │ │ ├── bsdiff.exe │ │ └── bspatch.exe │ │ └── web.xml └── src │ └── com │ └── jph │ └── iu │ └── server │ ├── servlet │ ├── ApplyPatch.java │ └── GenPatch.java │ └── util │ └── PatchFile.java ├── LICENSE ├── PatchUtil-cs ├── .vs │ └── PatchUtil │ │ └── v14 │ │ └── .suo ├── PatchUtil.sln └── PatchUtil │ ├── App.config │ ├── Main.Designer.cs │ ├── Main.cs │ ├── Main.resx │ ├── PatchUtil.csproj │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ ├── lib │ ├── bsdiff.exe │ └── bspatch.exe │ └── obj │ └── Debug │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── PatchUtil.csproj.FileListAbsolute.txt │ ├── PatchUtil.csproj.GenerateResource.Cache │ ├── PatchUtil.csprojResolveAssemblyReference.cache │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ ├── WindowsFormsApplication2.Main.resources │ ├── WindowsFormsApplication2.Properties.Resources.resources │ ├── WindowsFormsApplication2.csproj.FileListAbsolute.txt │ ├── WindowsFormsApplication2.csproj.GenerateResource.Cache │ ├── WindowsFormsApplication2.csprojResolveAssemblyReference.cache │ ├── WindowsFormsApplication2.exe │ └── WindowsFormsApplication2.pdb └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | -------------------------------------------------------------------------------- /ApkPatchLibrary/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /ApkPatchLibrary/.externalToolBuilders/NDK_Builder__.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ApkPatchLibrary/.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.ap_ 3 | 4 | # files for the dex VM 5 | *.dex 6 | 7 | # Java class files 8 | *.class 9 | 10 | # generated files 11 | bin/ 12 | gen/ 13 | 14 | # Local configuration file (sdk path, etc) 15 | local.properties 16 | 17 | # Proguard folder generated by Eclipse 18 | proguard/ 19 | 20 | # Ignore gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | .settings/ 28 | 29 | # Intellij project files 30 | *.iml 31 | *.ipr 32 | *.iws 33 | .idea/ 34 | 35 | # Mac system files 36 | .DS_Store 37 | -------------------------------------------------------------------------------- /ApkPatchLibrary/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ApkPatchLibrary/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := ApkPatchLibrary 6 | LOCAL_SRC_FILES := com_jph_utils_PatchUtils.c 7 | 8 | LOCAL_LDLIBS := -lz -llog 9 | 10 | include $(BUILD_SHARED_LIBRARY) -------------------------------------------------------------------------------- /ApkPatchLibrary/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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/jni/bzip2/readMe.txt: -------------------------------------------------------------------------------- 1 | bzip2包中文件来来自: 2 | http://www.bzip.org/downloads.html -------------------------------------------------------------------------------- /ApkPatchLibrary/jni/com_jph_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_jph_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_jph_utils_PatchUtils 196 | * Method: patch 197 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 198 | */ 199 | JNIEXPORT jint JNICALL Java_com_jph_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 | -------------------------------------------------------------------------------- /ApkPatchLibrary/jni/com_jph_utils_PatchUtils.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_jph_utils_PatchUtils */ 4 | 5 | #ifndef _Included_com_jph_utils_PatchUtils 6 | #define _Included_com_jph_utils_PatchUtils 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_jph_utils_PatchUtils 12 | * Method: patch 13 | * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_jph_utils_PatchUtils_patch 16 | (JNIEnv *, jclass, jstring, jstring, jstring); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /ApkPatchLibrary/libs/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/libs/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /ApkPatchLibrary/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /ApkPatchLibrary/obj/local/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/obj/local/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o -------------------------------------------------------------------------------- /ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o.d: -------------------------------------------------------------------------------- 1 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_cundong_utils_PatchUtils.o: \ 2 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/com_cundong_utils_PatchUtils.c \ 3 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.c \ 4 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib_private.h \ 5 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.h \ 6 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/crctable.c \ 7 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/compress.c \ 8 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/decompress.c \ 9 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/randtable.c \ 10 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/blocksort.c \ 11 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/huffman.c \ 12 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/com_cundong_utils_PatchUtils.h 13 | 14 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.c: 15 | 16 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib_private.h: 17 | 18 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/bzlib.h: 19 | 20 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/crctable.c: 21 | 22 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/compress.c: 23 | 24 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/decompress.c: 25 | 26 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/randtable.c: 27 | 28 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/blocksort.c: 29 | 30 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/bzip2/huffman.c: 31 | 32 | C:/Users/Penn/Desktop/lib/ApkPatchLibrary/jni/com_cundong_utils_PatchUtils.h: 33 | -------------------------------------------------------------------------------- /ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o -------------------------------------------------------------------------------- /ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o.d: -------------------------------------------------------------------------------- 1 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/obj/local/armeabi/objs/ApkPatchLibrary/com_jph_utils_PatchUtils.o: \ 2 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.c \ 3 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.c \ 4 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib_private.h \ 5 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.h \ 6 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/crctable.c \ 7 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/compress.c \ 8 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/decompress.c \ 9 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/randtable.c \ 10 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/blocksort.c \ 11 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/huffman.c \ 12 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.h 13 | 14 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.c: 15 | 16 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib_private.h: 17 | 18 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/bzlib.h: 19 | 20 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/crctable.c: 21 | 22 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/compress.c: 23 | 24 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/decompress.c: 25 | 26 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/randtable.c: 27 | 28 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/blocksort.c: 29 | 30 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/bzip2/huffman.c: 31 | 32 | E:/JiaPengHui/workplace/GitRepository/IncrementalUpdate/ApkPatchLibrary/jni/com_jph_utils_PatchUtils.h: 33 | -------------------------------------------------------------------------------- /ApkPatchLibrary/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /ApkPatchLibrary/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-23 15 | android.library=true -------------------------------------------------------------------------------- /ApkPatchLibrary/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ApkPatchLibrary/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ApkPatchLibrary/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/ApkPatchLibrary/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ApkPatchLibrary/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ApkPatchLibrary/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ApkPatchLibrary/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | ApkPatchLibrary 4 | 5 | 6 | -------------------------------------------------------------------------------- /ApkPatchLibrary/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ApkPatchLibrary/src/com/jph/utils/PatchUtils.java: -------------------------------------------------------------------------------- 1 | package com.jph.utils; 2 | 3 | 4 | /** 5 | * APK Patch工具类 6 | * @author Penn 7 | * 8 | */ 9 | public class PatchUtils { 10 | 11 | /** 12 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath 13 | * 14 | * 返回:0,说明操作成功 15 | * 16 | * @param oldApkPath 示例:/sdcard/old.apk 17 | * @param newApkPath 示例:/sdcard/new.apk 18 | * @param patchPath 示例:/sdcard/xx.patch 19 | * @return 20 | */ 21 | public static native int patch(String oldApkPath, String newApkPath, 22 | String patchPath); 23 | } -------------------------------------------------------------------------------- /IncrementalUpdate-Android/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | /*/build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | 32 | ### JetBrains template 33 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion 34 | 35 | *.iml 36 | 37 | ## Directory-based project format: 38 | .idea/ 39 | # if you remove the above rule, at least ignore the following: 40 | 41 | # User-specific stuff: 42 | # .idea/workspace.xml 43 | # .idea/tasks.xml 44 | # .idea/dictionaries 45 | 46 | # Sensitive or high-churn files: 47 | # .idea/dataSources.ids 48 | # .idea/dataSources.xml 49 | # .idea/sqlDataSources.xml 50 | # .idea/dynamic.xml 51 | # .idea/uiDesigner.xml 52 | 53 | # Gradle: 54 | # .idea/gradle.xml 55 | # .idea/libraries 56 | 57 | # Mongo Explorer plugin: 58 | # .idea/mongoSettings.xml 59 | 60 | ## File-based project format: 61 | *.ipr 62 | *.iws 63 | 64 | ## Plugin-specific files: 65 | 66 | # IntelliJ 67 | /out/ 68 | 69 | # mpeltonen/sbt-idea plugin 70 | .idea_modules/ 71 | 72 | # JIRA plugin 73 | atlassian-ide-plugin.xml 74 | 75 | # Crashlytics plugin (for Android Studio and IntelliJ) 76 | com_crashlytics_export_strings.xml 77 | crashlytics.properties 78 | crashlytics-build.properties 79 | 80 | 81 | ### Gradle template 82 | .gradle 83 | 84 | # Ignore Gradle GUI config 85 | gradle-app.setting 86 | 87 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 88 | !gradle-wrapper.jar 89 | 90 | 91 | -------------------------------------------------------------------------------- /IncrementalUpdate-Android/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.jph.iu.incrementalupdate_android" 9 | minSdkVersion 9 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.3.0' 26 | } 27 | -------------------------------------------------------------------------------- /IncrementalUpdate-Android/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 D:\android-sdk\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 | -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/ApkUtils.java: -------------------------------------------------------------------------------- 1 | package com.jph.iu.activity; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.ApplicationInfo; 6 | import android.content.pm.PackageInfo; 7 | import android.content.pm.PackageManager; 8 | import android.content.pm.PackageManager.NameNotFoundException; 9 | import android.net.Uri; 10 | import android.text.TextUtils; 11 | 12 | import java.util.Iterator; 13 | import java.util.List; 14 | 15 | /** 16 | * Apk工具类 * 17 | * @author jph 18 | */ 19 | public class ApkUtils { 20 | 21 | /** 22 | * 获取已安装apk的PackageInfo 23 | * 24 | * @param context 25 | * @param packageName 26 | * @return 27 | */ 28 | public static PackageInfo getInstalledApkPackageInfo(Context context, String packageName) { 29 | PackageManager pm = context.getPackageManager(); 30 | List apps = pm.getInstalledPackages(PackageManager.GET_SIGNATURES); 31 | 32 | Iterator it = apps.iterator(); 33 | while (it.hasNext()) { 34 | PackageInfo packageinfo = it.next(); 35 | String thisName = packageinfo.packageName; 36 | if (thisName.equals(packageName)) { 37 | return packageinfo; 38 | } 39 | } 40 | 41 | return null; 42 | } 43 | 44 | /** 45 | * 判断apk是否已安装 46 | * 47 | * @param context 48 | * @param packageName 49 | * @return 50 | */ 51 | public static boolean isInstalled(Context context, String packageName) { 52 | PackageManager pm = context.getPackageManager(); 53 | boolean installed = false; 54 | try { 55 | pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); 56 | installed = true; 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | 61 | return installed; 62 | } 63 | 64 | /** 65 | * 获取已安装Apk文件的源Apk文件 66 | * 如:/data/app/com.sina.weibo-1.apk 67 | * 68 | * @param context 69 | * @param packageName 70 | * @return 71 | */ 72 | public static String getSourceApkPath(Context context, String packageName) { 73 | if (TextUtils.isEmpty(packageName)) 74 | return null; 75 | 76 | try { 77 | ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0); 78 | return appInfo.sourceDir; 79 | } catch (NameNotFoundException e) { 80 | e.printStackTrace(); 81 | } 82 | 83 | return null; 84 | } 85 | 86 | /** 87 | * 安装Apk 88 | * 89 | * @param context 90 | * @param apkPath 91 | */ 92 | public static void installApk(Context context, String apkPath) { 93 | 94 | Intent intent = new Intent(Intent.ACTION_VIEW); 95 | intent.setDataAndType(Uri.parse("file://" + apkPath), 96 | "application/vnd.android.package-archive"); 97 | 98 | context.startActivity(intent); 99 | } 100 | } -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/Constants.java: -------------------------------------------------------------------------------- 1 | package com.jph.iu.activity; 2 | 3 | import java.io.File; 4 | 5 | import android.os.Environment; 6 | 7 | /** 8 | * 常量类 9 | * @author JPH 10 | */ 11 | public class Constants { 12 | 13 | public static final boolean DEBUG = true; 14 | 15 | //KSD接单(V1.0.7).apk 正确的MD5值,如果本地安装的apk MD5值不是TA,说明本地安装的是被二次打包的apk 16 | public static final String KSD_OLD_MD5 = "6da2aaa9a5acfbbff2a8f6466e81ba6c"; 17 | 18 | //KSD接单(V1.0.8).apk正确的MD5值 19 | public static final String KSD_NEW_MD5 = "7a333adaadfa08bd707e9b0b86a973e7"; 20 | 21 | //用于测试的packageName 22 | public static final String TEST_PACKAGENAME = "com.ksudi.shuttle"; 23 | 24 | public static final String PATH = Environment.getExternalStorageDirectory() + File.separator; 25 | 26 | //合成得到的新版apk 27 | public static final String NEW_APK_PATH = PATH + "KSD接单_new.apk"; 28 | 29 | //从服务器下载来的差分包 30 | public static final String PATCH_PATH = PATH + "KSD接单.patch"; 31 | // public static final String PATCH_PATH = PATH + "weibo.patch"; 32 | } -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jph.iu.activity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.pm.PackageInfo; 7 | import android.net.Uri; 8 | import android.os.AsyncTask; 9 | import android.os.Bundle; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.text.TextUtils; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.jph.iu.simple.R; 18 | import com.jph.utils.PatchUtils; 19 | 20 | import java.io.File; 21 | 22 | /** 23 | * ApkPatchLibrary 使用Sample 24 | */ 25 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 26 | 27 | private static final String TAG = Constants.DEBUG ? "MainActivity" : MainActivity.class.getSimpleName(); 28 | 29 | // 成功 30 | private static final int WHAT_SUCCESS = 1; 31 | 32 | // 本地安装的APP MD5不正确 33 | private static final int WHAT_FAIL_OLD_MD5 = -1; 34 | 35 | // 新生成的APP MD5不正确 36 | private static final int WHAT_FAIL_GEN_MD5 = -2; 37 | 38 | // 合成失败 39 | private static final int WHAT_FAIL_PATCH = -3; 40 | 41 | // 获取源文件失败 42 | private static final int WHAT_FAIL_GET_SOURCE = -4; 43 | 44 | // 未知错误 45 | private static final int WHAT_FAIL_UNKNOWN = -5; 46 | 47 | private Context mContext = null; 48 | 49 | private ProgressDialog mProgressDialog; 50 | private TextView mResultView; 51 | private Button mStartButton, mGithubButton; 52 | 53 | private long mBeginTime, mEndTime; 54 | 55 | @Override 56 | protected void onCreate(Bundle savedInstanceState) { 57 | super.onCreate(savedInstanceState); 58 | setContentView(R.layout.activity_main); 59 | 60 | mContext = getApplicationContext(); 61 | 62 | mProgressDialog = new ProgressDialog(this); 63 | mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 64 | mProgressDialog.setMessage("正在合成..."); 65 | mProgressDialog.setCancelable(false); 66 | 67 | mResultView = (TextView) findViewById(R.id.textview4); 68 | 69 | mStartButton = (Button) findViewById(R.id.start_btn); 70 | mGithubButton = (Button) findViewById(R.id.github_btn); 71 | mStartButton.setOnClickListener(this); 72 | mGithubButton.setOnClickListener(this); 73 | } 74 | 75 | @Override 76 | public void onClick(View v) { 77 | if (v == mStartButton) { 78 | File patchFile = new File(Constants.PATCH_PATH); 79 | 80 | if (!ApkUtils.isInstalled(mContext, Constants.TEST_PACKAGENAME)) { 81 | Toast.makeText(mContext, getString(R.string.demo_info1), Toast.LENGTH_LONG).show(); 82 | } else if (!patchFile.exists()) { 83 | Toast.makeText(mContext, getString(R.string.demo_info2), Toast.LENGTH_LONG).show(); 84 | } else { 85 | new PatchApkTask().execute(); 86 | } 87 | } else if (v == mGithubButton) { 88 | Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("https://github.com/crazycodeboy/IncrementalUpdate")); 89 | startActivity(intent); 90 | } 91 | } 92 | 93 | private String mCurentRealMD5, mNewRealMD5; 94 | 95 | /** 96 | * 模拟请求服务器,根据当前安装微博客户端的versionCode、versionName,来获取其文件的正确MD5,防止本地安装的是被篡改的版本 97 | */ 98 | private void requestOldMD5(int versionCode, String versionName) { 99 | mCurentRealMD5 = Constants.KSD_OLD_MD5; 100 | mNewRealMD5 = Constants.KSD_NEW_MD5; 101 | } 102 | 103 | private class PatchApkTask extends AsyncTask { 104 | 105 | @Override 106 | protected void onPreExecute() { 107 | super.onPreExecute(); 108 | 109 | mProgressDialog.show(); 110 | 111 | mResultView.setText(""); 112 | mBeginTime = System.currentTimeMillis(); 113 | } 114 | 115 | @Override 116 | protected Integer doInBackground(String... params) { 117 | 118 | PackageInfo packageInfo = ApkUtils.getInstalledApkPackageInfo(mContext, Constants.TEST_PACKAGENAME); 119 | 120 | if (packageInfo != null) { 121 | 122 | requestOldMD5(packageInfo.versionCode, packageInfo.versionName); 123 | 124 | String oldApkSource = ApkUtils.getSourceApkPath(mContext, Constants.TEST_PACKAGENAME); 125 | 126 | if (!TextUtils.isEmpty(oldApkSource)) { 127 | 128 | // 校验一下本地安装APK的MD5是不是和真实的MD5一致 129 | if (SignUtils.checkMd5(oldApkSource, mCurentRealMD5)) { 130 | int patchResult = PatchUtils.patch(oldApkSource, Constants.NEW_APK_PATH, Constants.PATCH_PATH); 131 | 132 | if (patchResult == 0) { 133 | 134 | if (SignUtils.checkMd5(Constants.NEW_APK_PATH, mNewRealMD5)) { 135 | return WHAT_SUCCESS; 136 | } else { 137 | return WHAT_FAIL_GEN_MD5; 138 | } 139 | } else { 140 | return WHAT_FAIL_PATCH; 141 | } 142 | } else { 143 | return WHAT_FAIL_OLD_MD5; 144 | } 145 | } else { 146 | return WHAT_FAIL_GET_SOURCE; 147 | } 148 | } else { 149 | return WHAT_FAIL_UNKNOWN; 150 | } 151 | } 152 | 153 | @Override 154 | protected void onPostExecute(Integer result) { 155 | super.onPostExecute(result); 156 | 157 | if (mProgressDialog.isShowing()) { 158 | mProgressDialog.dismiss(); 159 | } 160 | 161 | mEndTime = System.currentTimeMillis(); 162 | mResultView.setText("耗时: " + (mEndTime - mBeginTime) + "ms"); 163 | 164 | switch (result) { 165 | case WHAT_SUCCESS: { 166 | 167 | String text = "新apk已合成成功:" + Constants.NEW_APK_PATH; 168 | showToast(text); 169 | 170 | ApkUtils.installApk(MainActivity.this, Constants.NEW_APK_PATH); 171 | break; 172 | } 173 | case WHAT_FAIL_OLD_MD5: { 174 | String text = "现在安装的KSD接单(V1.0.7)的MD5不对!"; 175 | showToast(text); 176 | break; 177 | } 178 | case WHAT_FAIL_GEN_MD5: { 179 | String text = "合成完毕,但是合成得到的apk MD5不对!"; 180 | showToast(text); 181 | break; 182 | } 183 | case WHAT_FAIL_PATCH: { 184 | String text = "新apk已合成失败!"; 185 | showToast(text); 186 | break; 187 | } 188 | case WHAT_FAIL_GET_SOURCE: { 189 | String text = "无法获取KSD接单的源apk文件,只能整包更新了!"; 190 | showToast(text); 191 | break; 192 | } 193 | } 194 | } 195 | } 196 | 197 | private void showToast(final String text) { 198 | Toast.makeText(mContext, text, Toast.LENGTH_LONG).show(); 199 | } 200 | 201 | 202 | static { 203 | System.loadLibrary("ApkPatchLibrary"); 204 | } 205 | } -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/java/com/jph/iu/activity/SignUtils.java: -------------------------------------------------------------------------------- 1 | package com.jph.iu.activity; 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.IOException; 9 | import java.security.MessageDigest; 10 | 11 | /** 12 | * apk 签名信息获取工具类 13 | */ 14 | public class SignUtils { 15 | 16 | private static final boolean DEBUG = Constants.DEBUG; 17 | 18 | private static final String TAG = DEBUG ? "SignUtils" : SignUtils.class.getSimpleName(); 19 | 20 | private static String bytes2Hex(byte[] src) { 21 | char[] res = new char[src.length * 2]; 22 | final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 23 | for (int i = 0, j = 0; i < src.length; i++) { 24 | res[j++] = hexDigits[src[i] >>> 4 & 0x0f]; 25 | res[j++] = hexDigits[src[i] & 0x0f]; 26 | } 27 | 28 | return new String(res); 29 | } 30 | 31 | private static String getMd5ByFile(File file) { 32 | String value = null; 33 | FileInputStream in = null; 34 | try { 35 | in = new FileInputStream(file); 36 | 37 | MessageDigest digester = MessageDigest.getInstance("MD5"); 38 | byte[] bytes = new byte[8192]; 39 | int byteCount; 40 | while ((byteCount = in.read(bytes)) > 0) { 41 | digester.update(bytes, 0, byteCount); 42 | } 43 | value = bytes2Hex(digester.digest()); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } finally { 47 | if (null != in) { 48 | try { 49 | in.close(); 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | } 55 | return value; 56 | } 57 | 58 | /** 59 | * 判断文件的MD5是否为指定值 60 | * 61 | * @param file 62 | * @param md5 63 | * @return 64 | */ 65 | public static boolean checkMd5(File file, String md5) { 66 | if (TextUtils.isEmpty(md5)) { 67 | throw new RuntimeException("md5 cannot be empty"); 68 | } 69 | 70 | String fileMd5 = getMd5ByFile(file); 71 | 72 | if (DEBUG) { 73 | Log.d(TAG, String.format("file's md5=%s, real md5=%s", fileMd5, md5)); 74 | } 75 | 76 | if (md5.equals(fileMd5)) { 77 | return true; 78 | } else { 79 | return false; 80 | } 81 | } 82 | 83 | /** 84 | * 判断文件的MD5是否为指定值 85 | * 86 | * @param filePath 87 | * @param md5 88 | * @return 89 | */ 90 | public static boolean checkMd5(String filePath, String md5) { 91 | return checkMd5(new File(filePath), md5); 92 | } 93 | } -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/java/com/jph/utils/PatchUtils.java: -------------------------------------------------------------------------------- 1 | package com.jph.utils; 2 | 3 | /** 4 | * APK Patch工具类 5 | */ 6 | public class PatchUtils { 7 | 8 | /** 9 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath 10 | * 11 | * 返回:0,说明操作成功 12 | * 13 | * @param oldApkPath 示例:/sdcard/old.apk 14 | * @param newApkPath 示例:/sdcard/new.apk 15 | * @param patchPath 示例:/sdcard/xx.patch 16 | * @return 17 | */ 18 | public static native int patch(String oldApkPath, String newApkPath, String patchPath); 19 | } -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/jniLibs/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazycodeboy/IncrementalUpdate/ad8d310c71ba319a0d1e14968865142978830816/IncrementalUpdate-Android/app/src/main/jniLibs/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /IncrementalUpdate-Android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 22 | 23 | 31 | 32 | 40 | 41 |