├── LICENSE ├── Patch ├── .classpath ├── .cproject ├── .project ├── AndroidManifest.xml ├── ic_launcher-web.png ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── Core.cpp │ ├── Patch.cpp │ ├── Patch.h │ ├── help │ │ ├── JNIHelp.cpp │ │ ├── JNIHelp.h │ │ ├── log.h │ │ ├── process_name.c │ │ └── process_name.h │ └── xdelta │ │ ├── COPYING │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── Makefile.mingw │ │ ├── Makefile.orig │ │ ├── README │ │ ├── aclocal.m4 │ │ ├── config.guess │ │ ├── config.h.in │ │ ├── config.sub │ │ ├── configure │ │ ├── configure.ac │ │ ├── depcomp │ │ ├── draft-korn-vcdiff.txt │ │ ├── examples │ │ ├── Makefile │ │ ├── README │ │ ├── checksum_test.cc │ │ ├── compare_test.c │ │ ├── encode_decode_test.c │ │ ├── iOS │ │ │ └── xdelta3-ios-test │ │ │ │ ├── xdelta3-ios-test.xcodeproj │ │ │ │ └── project.pbxproj │ │ │ │ └── xdelta3-ios-test │ │ │ │ ├── Xd3iOSAppDelegate.h │ │ │ │ ├── Xd3iOSAppDelegate.m │ │ │ │ ├── Xd3iOSViewController.h │ │ │ │ ├── Xd3iOSViewController.m │ │ │ │ ├── en.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ ├── MainStoryboard_iPad.storyboard │ │ │ │ └── MainStoryboard_iPhone.storyboard │ │ │ │ ├── file_v1.bin │ │ │ │ ├── file_v1_to_v2.bin │ │ │ │ ├── file_v2.bin │ │ │ │ ├── main.m │ │ │ │ ├── xdelta3-ios-test-Info.plist │ │ │ │ └── xdelta3-ios-test-Prefix.pch │ │ ├── small_page_test.c │ │ ├── speed_test.c │ │ └── test.h │ │ ├── install-sh │ │ ├── ltmain.sh │ │ ├── m4 │ │ └── ax_check_aligned_access_required.m4 │ │ ├── missing │ │ ├── testing │ │ ├── cmp.h │ │ ├── delta.h │ │ ├── file.h │ │ ├── modify.h │ │ ├── random.h │ │ ├── regtest.cc │ │ ├── regtest_c.c │ │ ├── segment.h │ │ ├── sizes.h │ │ ├── test.h │ │ ├── xdelta3-regtest.py │ │ └── xdelta3-test.py │ │ ├── xdelta3-blkcache.h │ │ ├── xdelta3-cfgs.h │ │ ├── xdelta3-decode.h │ │ ├── xdelta3-djw.h │ │ ├── xdelta3-fgk.h │ │ ├── xdelta3-hash.h │ │ ├── xdelta3-internal.h │ │ ├── xdelta3-list.h │ │ ├── xdelta3-lzma.h │ │ ├── xdelta3-main.h │ │ ├── xdelta3-merge.h │ │ ├── xdelta3-second.h │ │ ├── xdelta3-test.h │ │ ├── xdelta3.1 │ │ ├── xdelta3.c │ │ ├── xdelta3.h │ │ ├── xdelta3.i │ │ ├── xdelta3.vcxproj │ │ ├── xdelta3.wxi │ │ └── xdelta3.wxs ├── libs │ ├── android-support-v4.jar │ ├── armeabi-v7a │ │ └── libPatch.so │ ├── armeabi │ │ └── libPatch.so │ ├── mips │ │ └── libPatch.so │ └── x86 │ │ └── libPatch.so ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ └── activity_main.xml │ ├── menu │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── morgoo │ └── patch │ ├── MainActivity.java │ └── Patch.java └── README.md /Patch/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Patch/.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 | -------------------------------------------------------------------------------- /Patch/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Patch 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | com.android.ide.eclipse.adt.ResourceManagerBuilder 16 | 17 | 18 | 19 | 20 | com.android.ide.eclipse.adt.PreCompilerBuilder 21 | 22 | 23 | 24 | 25 | org.eclipse.jdt.core.javabuilder 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.ApkBuilder 31 | 32 | 33 | 34 | 35 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 36 | full,incremental, 37 | 38 | 39 | 40 | 41 | 42 | com.android.ide.eclipse.adt.AndroidNature 43 | org.eclipse.jdt.core.javanature 44 | org.eclipse.cdt.core.cnature 45 | org.eclipse.cdt.core.ccnature 46 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 47 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 48 | 49 | 50 | -------------------------------------------------------------------------------- /Patch/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Patch/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/ic_launcher-web.png -------------------------------------------------------------------------------- /Patch/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | cmd-strip = $(TOOLCHAIN_PREFIX)strip --strip-all -x $1 3 | include $(CLEAR_VARS) 4 | 5 | ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 6 | LOCAL_CFLAGS := -DHAVE_NEON=1 7 | endif 8 | 9 | # Define the default logging level based build type 10 | ifeq ($(APP_OPTIM),release) 11 | MY_LOG_LEVEL := LOG_SILENT 12 | else 13 | MY_LOG_LEVEL := LOG_VERBOSE 14 | endif 15 | MY_LOG_LEVEL := LOG_VERBOSE 16 | LOCAL_CFLAGS += -DMY_LOG_LEVEL=$(MY_LOG_LEVEL) 17 | LOCAL_CFLAGS += -fvisibility=hidden 18 | 19 | LOCAL_LDLIBS += -L$(LOCAL_PATH) -llog 20 | 21 | LOCAL_MODULE := Patch 22 | LOCAL_SRC_FILES := help/JNIHelp.h\ 23 | help/JNIHelp.cpp\ 24 | help/log.h\ 25 | Patch.h\ 26 | Patch.cpp\ 27 | Core.cpp 28 | 29 | include $(BUILD_SHARED_LIBRARY) 30 | -------------------------------------------------------------------------------- /Patch/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Build both ARMv5TE and ARMv7-A machine code. 2 | APP_STL := stlport_static 3 | APP_PLATFORM:=android-7 4 | #abis armeabi armeabi-v7a x86 mips 5 | APP_ABI := all -------------------------------------------------------------------------------- /Patch/jni/Core.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "help/log.h" 5 | #include "Patch.h" 6 | 7 | jint JNI_OnLoad(JavaVM* vm, void* p) { 8 | JNIEnv* env; 9 | if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { 10 | LOGE(TAG, "JavaVM::GetEnv() failed"); 11 | abort(); 12 | } 13 | registerNativeMethodsNativePatch(env, "com/morgoo/patch/Patch"); 14 | LOGE(TAG, "JNI_OnLoad OKAY"); 15 | return JNI_VERSION_1_6; 16 | } 17 | -------------------------------------------------------------------------------- /Patch/jni/Patch.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Permission to distribute this example by 3 | // Copyright (C) 2007 Ralf Junker 4 | // Ralf Junker 5 | // http://www.yunqa.de/delphi/ 6 | 7 | //--------------------------------------------------------------------------- 8 | 9 | #include 10 | #include 11 | #include "xdelta/xdelta3.h" 12 | #include "xdelta/xdelta3.c" 13 | 14 | #include "help/log.h" 15 | #include "help/JNIHelp.h" 16 | 17 | //--------------------------------------------------------------------------- 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | int code(int encode, FILE* InFile, FILE* SrcFile, FILE* OutFile, int BufSize) { 23 | int r, ret; 24 | struct stat statbuf; 25 | xd3_stream stream; 26 | xd3_config config; 27 | xd3_source source; 28 | uint8_t * Input_Buf; 29 | int Input_Buf_Read; 30 | 31 | if (BufSize < XD3_ALLOCSIZE) 32 | BufSize = XD3_ALLOCSIZE; 33 | 34 | memset(&stream, 0, sizeof(stream)); 35 | memset(&source, 0, sizeof(source)); 36 | 37 | xd3_init_config(&config, XD3_ADLER32); 38 | config.winsize = BufSize; 39 | xd3_config_stream(&stream, &config); 40 | 41 | if (SrcFile) { 42 | r = fstat(fileno(SrcFile), &statbuf); 43 | if (r) 44 | return r; 45 | 46 | source.blksize = BufSize; 47 | source.curblk = (uint8_t *) malloc(source.blksize); 48 | 49 | /* Load 1st block of stream. */ 50 | r = fseek(SrcFile, 0, SEEK_SET); 51 | if (r) 52 | return r; 53 | source.onblk = fread((void*) source.curblk, 1, source.blksize, SrcFile); 54 | source.curblkno = 0; 55 | /* Set the stream. */ 56 | xd3_set_source(&stream, &source); 57 | } 58 | 59 | Input_Buf = (uint8_t *) malloc(BufSize); 60 | 61 | fseek(InFile, 0, SEEK_SET); 62 | do { 63 | Input_Buf_Read = fread(Input_Buf, 1, BufSize, InFile); 64 | if (Input_Buf_Read < BufSize) { 65 | xd3_set_flags(&stream, XD3_FLUSH | stream.flags); 66 | } 67 | xd3_avail_input(&stream, Input_Buf, Input_Buf_Read); 68 | 69 | process: if (encode) { 70 | ret = xd3_encode_input(&stream); 71 | } else { 72 | ret = xd3_decode_input(&stream); 73 | } 74 | 75 | switch (ret) { 76 | case XD3_INPUT: { 77 | LOGD(TAG, "XD3_INPUT\n"); 78 | continue; 79 | } 80 | case XD3_OUTPUT: { 81 | LOGD(TAG, "XD3_OUTPUT\n"); 82 | r = fwrite(stream.next_out, 1, stream.avail_out, OutFile); 83 | if (r != (int) stream.avail_out) 84 | return r; 85 | xd3_consume_output(&stream); 86 | goto process; 87 | } 88 | case XD3_GETSRCBLK: { 89 | LOGD(TAG, "XD3_GETSRCBLK %qd\n", source.getblkno); 90 | if (SrcFile) { 91 | r = fseek(SrcFile, source.blksize * source.getblkno, SEEK_SET); 92 | if (r) 93 | return r; 94 | source.onblk = fread((void*) source.curblk, 1, source.blksize, 95 | SrcFile); 96 | source.curblkno = source.getblkno; 97 | } 98 | goto process; 99 | } 100 | case XD3_GOTHEADER: { 101 | LOGD(TAG, "XD3_GOTHEADER\n"); 102 | goto process; 103 | } 104 | case XD3_WINSTART: { 105 | LOGD(TAG, "XD3_WINSTART\n"); 106 | goto process; 107 | } 108 | case XD3_WINFINISH: { 109 | LOGD(TAG, "XD3_WINFINISH\n"); 110 | goto process; 111 | } 112 | default: { 113 | LOGD(TAG, "!!! INVALID %s %d !!!\n", stream.msg, ret); 114 | return ret; 115 | } 116 | 117 | } 118 | 119 | } while (Input_Buf_Read == BufSize); 120 | 121 | free(Input_Buf); 122 | 123 | free((void*) source.curblk); 124 | xd3_close_stream(&stream); 125 | xd3_free_stream(&stream); 126 | 127 | return 0; 128 | } 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | jint nativePatch(JNIEnv* env, jobject thiz, jint encode, jstring inPath, 134 | jstring srcPath, jstring outPath) { 135 | const char* inUTFPath; 136 | const char* srcUTFPath; 137 | const char* outUTFPath; 138 | FILE* InFile; 139 | FILE* SrcFile; 140 | FILE* OutFile; 141 | int res; 142 | 143 | //LOGI("=======-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-com_qihoo_appstore_utils_PatchUtil_patch called"); 144 | 145 | inUTFPath = env->GetStringUTFChars(inPath, NULL); 146 | InFile = fopen(inUTFPath, "rb"); 147 | if (InFile <= 0) { 148 | res = -1; 149 | goto out3; 150 | } 151 | 152 | env->ReleaseStringUTFChars(inPath, inUTFPath); 153 | srcUTFPath = env->GetStringUTFChars(srcPath, NULL); 154 | SrcFile = fopen(srcUTFPath, "rb"); 155 | if (SrcFile <= 0) { 156 | res = -1; 157 | goto out2; 158 | } 159 | 160 | env->ReleaseStringUTFChars(srcPath, srcUTFPath); 161 | outUTFPath = env->GetStringUTFChars(outPath, NULL); 162 | OutFile = fopen(outUTFPath, "wb"); 163 | if (OutFile <= 0) { 164 | res = -1; 165 | goto out1; 166 | } 167 | 168 | env->ReleaseStringUTFChars(outPath, outUTFPath); 169 | res = code(encode, InFile, SrcFile, OutFile, 0x1000); 170 | 171 | fclose(OutFile); 172 | out1: fclose(SrcFile); 173 | out2: fclose(InFile); 174 | out3: return res; 175 | } 176 | 177 | static JNINativeMethod gMethods[] = { 178 | /* name, signature, funcPtr */ 179 | { "nativePatch", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", 180 | (void*) nativePatch }, }; 181 | 182 | int registerNativeMethodsNativePatch(JNIEnv* env, const char* clazz) { 183 | jclass myclazz = env->FindClass(clazz); 184 | if (env->ExceptionCheck()) { 185 | env->ExceptionClear(); 186 | } 187 | if (!myclazz) { 188 | LOGE(TAG, "Can not found class(%s),skip RegisterNativeMethods", clazz); 189 | return -1; 190 | } 191 | JNINativeMethod method = gMethods[0]; 192 | jmethodID methodId = env->GetStaticMethodID(myclazz, method.name, 193 | method.signature); 194 | if (env->ExceptionCheck()) { 195 | env->ExceptionClear(); 196 | } 197 | if (!methodId) { 198 | LOGE(TAG, "Can not found %s in class(%s),skip RegisterNativeMethods", 199 | method.name, clazz); 200 | return -1; 201 | } 202 | LOGI(TAG, "jniRegisterNativeMethods for %s", clazz); 203 | return jniRegisterNativeMethods(env, clazz, gMethods, NELEM(gMethods)); 204 | 205 | } 206 | -------------------------------------------------------------------------------- /Patch/jni/Patch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * patch.h 3 | * 4 | * Created on: 2013年11月12日 5 | * Author: zhangyong6 6 | */ 7 | 8 | #ifndef PATCH_H_ 9 | #define PATCH_H_ 10 | 11 | #include 12 | 13 | int registerNativeMethodsNativePatch(JNIEnv* env, const char* clazz); 14 | 15 | #endif /* PATCH_H_ */ 16 | -------------------------------------------------------------------------------- /Patch/jni/help/JNIHelp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * JNI helper functions. 19 | * 20 | * This file may be included by C or C++ code, which is trouble because jni.h 21 | * uses different typedefs for JNIEnv in each language. 22 | */ 23 | #ifndef NATIVEHELPER_JNIHELP_H_ 24 | #define NATIVEHELPER_JNIHELP_H_ 25 | 26 | #include "jni.h" 27 | #include 28 | 29 | #ifndef NELEM 30 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* 38 | * Register one or more native methods with a particular class. 39 | * "className" looks like "java/lang/String". Aborts on failure. 40 | * TODO: fix all callers and change the return type to void. 41 | */ 42 | int jniRegisterNativeMethods(C_JNIEnv* env, const char* className, const JNINativeMethod* gMethods, int numMethods); 43 | 44 | /* 45 | * Throw an exception with the specified class and an optional message. 46 | * 47 | * The "className" argument will be passed directly to FindClass, which 48 | * takes strings with slashes (e.g. "java/lang/Object"). 49 | * 50 | * If an exception is currently pending, we log a warning message and 51 | * clear it. 52 | * 53 | * Returns 0 on success, nonzero if something failed (e.g. the exception 54 | * class couldn't be found, so *an* exception will still be pending). 55 | * 56 | * Currently aborts the VM if it can't throw the exception. 57 | */ 58 | int jniThrowException(C_JNIEnv* env, const char* className, const char* msg); 59 | 60 | /* 61 | * Throw a java.lang.NullPointerException, with an optional message. 62 | */ 63 | int jniThrowNullPointerException(C_JNIEnv* env, const char* msg); 64 | 65 | /* 66 | * Throw a java.lang.RuntimeException, with an optional message. 67 | */ 68 | int jniThrowRuntimeException(C_JNIEnv* env, const char* msg); 69 | 70 | /* 71 | * Throw a java.io.IOException, generating the message from errno. 72 | */ 73 | int jniThrowIOException(C_JNIEnv* env, int errnum); 74 | 75 | /* 76 | * Return a pointer to a locale-dependent error string explaining errno 77 | * value 'errnum'. The returned pointer may or may not be equal to 'buf'. 78 | * This function is thread-safe (unlike strerror) and portable (unlike 79 | * strerror_r). 80 | */ 81 | const char* jniStrError(int errnum, char* buf, size_t buflen); 82 | 83 | /* 84 | * Returns a new java.io.FileDescriptor for the given int fd. 85 | */ 86 | jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd); 87 | 88 | /* 89 | * Returns the int fd from a java.io.FileDescriptor. 90 | */ 91 | int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor); 92 | 93 | /* 94 | * Sets the int fd in a java.io.FileDescriptor. 95 | */ 96 | void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value); 97 | 98 | /* 99 | * Log a message and an exception. 100 | * If exception is NULL, logs the current exception in the JNI environment. 101 | */ 102 | void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | 109 | /* 110 | * For C++ code, we provide inlines that map to the C functions. g++ always 111 | * inlines these, even on non-optimized builds. 112 | */ 113 | #if defined(__cplusplus) 114 | inline int jniRegisterNativeMethods(JNIEnv* env, const char* className, const JNINativeMethod* gMethods, int numMethods) { 115 | return jniRegisterNativeMethods(&env->functions, className, gMethods, numMethods); 116 | } 117 | 118 | inline int jniThrowException(JNIEnv* env, const char* className, const char* msg) { 119 | return jniThrowException(&env->functions, className, msg); 120 | } 121 | 122 | extern "C" int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args); 123 | 124 | /* 125 | * Equivalent to jniThrowException but with a printf-like format string and 126 | * variable-length argument list. This is only available in C++. 127 | */ 128 | inline int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt, ...) { 129 | va_list args; 130 | va_start(args, fmt); 131 | return jniThrowExceptionFmt(&env->functions, className, fmt, args); 132 | va_end(args); 133 | } 134 | 135 | inline int jniThrowNullPointerException(JNIEnv* env, const char* msg) { 136 | return jniThrowNullPointerException(&env->functions, msg); 137 | } 138 | 139 | inline int jniThrowRuntimeException(JNIEnv* env, const char* msg) { 140 | return jniThrowRuntimeException(&env->functions, msg); 141 | } 142 | 143 | inline int jniThrowIOException(JNIEnv* env, int errnum) { 144 | return jniThrowIOException(&env->functions, errnum); 145 | } 146 | 147 | inline jobject jniCreateFileDescriptor(JNIEnv* env, int fd) { 148 | return jniCreateFileDescriptor(&env->functions, fd); 149 | } 150 | 151 | inline int jniGetFDFromFileDescriptor(JNIEnv* env, jobject fileDescriptor) { 152 | return jniGetFDFromFileDescriptor(&env->functions, fileDescriptor); 153 | } 154 | 155 | inline void jniSetFileDescriptorOfFD(JNIEnv* env, jobject fileDescriptor, int value) { 156 | jniSetFileDescriptorOfFD(&env->functions, fileDescriptor, value); 157 | } 158 | 159 | inline void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowable exception = NULL) { 160 | jniLogException(&env->functions, priority, tag, exception); 161 | } 162 | #endif 163 | 164 | /* Logging macros. 165 | * 166 | * Logs an exception. If the exception is omitted or NULL, logs the current exception 167 | * from the JNI environment, if any. 168 | */ 169 | #define LOG_EX(env, priority, tag, ...) \ 170 | IF_ALOG(priority, tag) jniLogException(env, ANDROID_##priority, tag, ##__VA_ARGS__) 171 | #define LOGV_EX(env, ...) LOG_EX(env, LOG_VERBOSE, LOG_TAG, ##__VA_ARGS__) 172 | #define LOGD_EX(env, ...) LOG_EX(env, LOG_DEBUG, LOG_TAG, ##__VA_ARGS__) 173 | #define LOGI_EX(env, ...) LOG_EX(env, LOG_INFO, LOG_TAG, ##__VA_ARGS__) 174 | #define LOGW_EX(env, ...) LOG_EX(env, LOG_WARN, LOG_TAG, ##__VA_ARGS__) 175 | #define LOGE_EX(env, ...) LOG_EX(env, LOG_ERROR, LOG_TAG, ##__VA_ARGS__) 176 | 177 | /* 178 | * TEMP_FAILURE_RETRY is defined by some, but not all, versions of 179 | * . (Alas, it is not as standard as we'd hoped!) So, if it's 180 | * not already defined, then define it here. 181 | */ 182 | #ifndef TEMP_FAILURE_RETRY 183 | /* Used to retry syscalls that can return EINTR. */ 184 | #define TEMP_FAILURE_RETRY(exp) ({ \ 185 | typeof (exp) _rc; \ 186 | do { \ 187 | _rc = (exp); \ 188 | } while (_rc == -1 && errno == EINTR); \ 189 | _rc; }) 190 | #endif 191 | 192 | #endif /* NATIVEHELPER_JNIHELP_H_ */ 193 | -------------------------------------------------------------------------------- /Patch/jni/help/log.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOG_H__ 2 | #define __LOG_H__ 3 | 4 | #include 5 | 6 | #define LOG_VERBOSE 1 7 | #define LOG_DEBUG 2 8 | #define LOG_INFO 3 9 | #define LOG_WARNING 4 10 | #define LOG_ERROR 5 11 | #define LOG_FATAL 6 12 | #define LOG_SILENT 7 13 | 14 | #ifndef MY_LOG_LEVEL 15 | #define MY_LOG_LEVEL LOG_SILENT 16 | #endif 17 | 18 | ///是否打开日志开关 19 | #ifndef DEBUG 20 | #define DEBUG MY_LOG_LEVEL 21 | #endif 22 | 23 | //默认的日志tag 24 | #ifndef TAG 25 | #define TAG (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 26 | #endif 27 | 28 | #if(DEBUG <= LOG_VERBOSE) 29 | #define LOGV(tag,...) __android_log_print(ANDROID_LOG_VERBOSE,tag,##__VA_ARGS__) 30 | #else 31 | #define LOGV(tag,...) 32 | #endif 33 | 34 | #if(DEBUG <= LOG_DEBUG) 35 | #define LOGD(tag,...) __android_log_print(ANDROID_LOG_DEBUG,tag,##__VA_ARGS__) 36 | #else 37 | #define LOGD(tag,...) 38 | #endif 39 | 40 | #if(DEBUG <= LOG_INFO) 41 | #define LOGI(tag,...) __android_log_print(ANDROID_LOG_INFO,tag,##__VA_ARGS__) 42 | #else 43 | #define LOGI(tag,...) 44 | #endif 45 | 46 | #if(DEBUG <= LOG_WARN) 47 | #define LOGW(tag,...) __android_log_print(ANDROID_LOG_WARN,tag,##__VA_ARGS__) 48 | #else 49 | #define LOGW(tag,...) 50 | #endif 51 | 52 | #if(DEBUG <= LOG_ERROR) 53 | #define LOGE(tag,...) __android_log_print(ANDROID_LOG_ERROR,tag,##__VA_ARGS__) 54 | #else 55 | #define LOGE(tag,...) 56 | #endif 57 | 58 | #if(DEBUG <= LOG_FATAL) 59 | #define LOGF(tag,...) __android_log_print(ANDROID_LOG_FATAL,tag,##__VA_ARGS__) 60 | #else 61 | #define LOGF(tag,...) 62 | #endif 63 | 64 | #endif /* LOG_H_ */ 65 | 66 | -------------------------------------------------------------------------------- /Patch/jni/help/process_name.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include "log.h" 13 | #include "process_name.h" 14 | 15 | #define PROCESS_NAME_DEVICE "/sys/qemu_trace/process_name" 16 | 17 | static const char* process_name = "unknown"; 18 | static int running_in_emulator = -1; 19 | 20 | void set_process_name(const char* new_name) { 21 | char propBuf[PROP_VALUE_MAX]; 22 | 23 | if (new_name == NULL) { 24 | return; 25 | } 26 | 27 | // We never free the old name. Someone else could be using it. 28 | int len = strlen(new_name); 29 | char* copy = (char*) malloc(len + 1); 30 | strcpy(copy, new_name); 31 | process_name = (const char*) copy; 32 | 33 | if (len < 16) { 34 | prctl(PR_SET_NAME, (unsigned long) new_name, 0, 0, 0); 35 | } else { 36 | prctl(PR_SET_NAME, (unsigned long) new_name + len - 15, 0, 0, 0); 37 | } 38 | 39 | // If we know we are not running in the emulator, then return. 40 | if (running_in_emulator == 0) { 41 | return; 42 | } 43 | 44 | // If the "running_in_emulator" variable has not been initialized, 45 | // then do it now. 46 | if (running_in_emulator == -1) { 47 | if (__system_property_get("ro.kernel.qemu", propBuf)) { 48 | if (propBuf[0] == '1') { 49 | running_in_emulator = 1; 50 | } else { 51 | running_in_emulator = 0; 52 | return; 53 | } 54 | } else { 55 | running_in_emulator = 0; 56 | return; 57 | } 58 | } 59 | 60 | // If the emulator was started with the "-trace file" command line option 61 | // then we want to record the process name in the trace even if we are 62 | // not currently tracing instructions (so that we will know the process 63 | // name when we do start tracing instructions). We do not need to execute 64 | // this code if we are just running in the emulator without the "-trace" 65 | // command line option, but we don't know that here and this function 66 | // isn't called frequently enough to bother optimizing that case. 67 | int fd = open(PROCESS_NAME_DEVICE, O_RDWR); 68 | if (fd < 0) 69 | return; 70 | write(fd, process_name, strlen(process_name) + 1); 71 | close(fd); 72 | } 73 | 74 | const char* get_process_name(void) { 75 | return process_name; 76 | } 77 | 78 | const char* get_process_name2() { 79 | char* name = (char*) malloc(PROP_VALUE_MAX); 80 | memset(name, 0, sizeof(name)); 81 | if (prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0) == 0) { 82 | return name; 83 | } else { 84 | free(name); 85 | return NULL; 86 | } 87 | } 88 | 89 | 90 | void set_process_name_from_main(const char* procname, int argc, char *argv[]) { 91 | size_t argv0_len = strlen(argv[0]); 92 | size_t procname_len = strlen(procname); 93 | size_t max_procname_len = 94 | (argv0_len > procname_len) ? procname_len : argv0_len; 95 | strncpy(argv[0], procname, max_procname_len); 96 | memset(&argv[0][max_procname_len], '\0', argv0_len - max_procname_len); 97 | set_process_name(procname); 98 | } 99 | -------------------------------------------------------------------------------- /Patch/jni/help/process_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Gives the current process a name. 19 | */ 20 | 21 | #ifndef __PROCESS_NAME_H 22 | #define __PROCESS_NAME_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * Sets the current process name. 30 | * 31 | * Warning: This leaks a string every time you call it. Use judiciously! 32 | */ 33 | void set_process_name(const char* process_name); 34 | 35 | /** Gets the current process name. */ 36 | const char* get_process_name(void); 37 | 38 | const char* get_process_name2(); 39 | 40 | void set_process_name_from_main(const char* procname, int argc, char *argv[]); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* __PROCESS_NAME_H */ 47 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | bin_PROGRAMS = xdelta3 4 | noinst_PROGRAMS = xdelta3regtest xdelta3decode 5 | 6 | common_SOURCES = \ 7 | xdelta3-blkcache.h \ 8 | xdelta3-decode.h \ 9 | xdelta3-djw.h \ 10 | xdelta3-fgk.h \ 11 | xdelta3-hash.h \ 12 | xdelta3-internal.h \ 13 | xdelta3-list.h \ 14 | xdelta3-lzma.h \ 15 | xdelta3-main.h \ 16 | xdelta3-merge.h \ 17 | xdelta3-second.h \ 18 | xdelta3-test.h \ 19 | xdelta3-cfgs.h \ 20 | xdelta3.h 21 | 22 | xdelta3_SOURCES = $(common_SOURCES) xdelta3.c 23 | 24 | xdelta3decode_SOURCES = $(common_SOURCES) xdelta3.c 25 | 26 | xdelta3regtest_SOURCES = $(common_SOURCES) \ 27 | testing/cmp.h \ 28 | testing/delta.h \ 29 | testing/file.h \ 30 | testing/modify.h \ 31 | testing/random.h \ 32 | testing/regtest.cc \ 33 | testing/regtest_c.c \ 34 | testing/segment.h \ 35 | testing/sizes.h \ 36 | testing/test.h 37 | 38 | # Note: for extra sanity checks, enable -Wconversion. Note there 39 | # are a lot of false positives. 40 | WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \ 41 | -Wextra -Wno-unused-parameter 42 | 43 | C_WFLAGS = $(WFLAGS) -pedantic -std=c99 44 | CXX_WFLAGS = $(WFLAGS) 45 | 46 | common_CFLAGS = \ 47 | -DGENERIC_ENCODE_TABLES=0 \ 48 | -DREGRESSION_TEST=1 \ 49 | -DSECONDARY_DJW=1 \ 50 | -DSECONDARY_FGK=1 \ 51 | -DXD3_POSIX=1 \ 52 | -DXD3_USE_LARGEFILE64=1 \ 53 | -DXD3_MAIN=1 54 | 55 | if DEBUG_SYMBOLS 56 | common_CFLAGS += -g 57 | endif 58 | 59 | # For additional debugging, add -DXD3_DEBUG=1, 2, 3, ... 60 | xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=0 61 | xdelta3_LDADD = -lm 62 | 63 | xdelta3decode_CFLAGS = \ 64 | $(C_WFLAGS) \ 65 | -DGENERIC_ENCODE_TABLES=0 \ 66 | -DREGRESSION_TEST=0 \ 67 | -DSECONDARY_DJW=0 \ 68 | -DSECONDARY_FGK=0 \ 69 | -DSECONDARY_LZMA=0 \ 70 | -DXD3_USE_LARGEFILE64=1 \ 71 | -DXD3_MAIN=1 \ 72 | -DXD3_ENCODER=0 \ 73 | -DXD3_STDIO=1 \ 74 | -DEXTERNAL_COMPRESSION=0 \ 75 | -DVCDIFF_TOOLS=0 76 | 77 | xdelta3regtest_CXXFLAGS = \ 78 | $(CXX_WFLAGS) $(common_CFLAGS) -DNOT_MAIN=1 -DXD3_DEBUG=1 79 | xdelta3regtest_CFLAGS = \ 80 | $(C_WFLAGS) $(common_CFLAGS) -DNOT_MAIN=1 -DXD3_DEBUG=1 81 | xdelta3regtest_LDADD = -lm 82 | 83 | man1_MANS = xdelta3.1 84 | 85 | EXTRA_DIST = \ 86 | draft-korn-vcdiff.txt \ 87 | README \ 88 | examples/Makefile \ 89 | examples/README \ 90 | examples/checksum_test.cc \ 91 | examples/compare_test.c \ 92 | examples/encode_decode_test.c \ 93 | examples/small_page_test.c \ 94 | examples/speed_test.c \ 95 | examples/test.h \ 96 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test.xcodeproj/project.pbxproj \ 97 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSAppDelegate.h \ 98 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSAppDelegate.m \ 99 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSViewController.h \ 100 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSViewController.m \ 101 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/en.lproj/InfoPlist.strings \ 102 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/en.lproj/MainStoryboard_iPad.storyboard \ 103 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/en.lproj/MainStoryboard_iPhone.storyboard \ 104 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/file_v1.bin \ 105 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/file_v1_to_v2.bin \ 106 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/file_v2.bin \ 107 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/main.m \ 108 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/xdelta3-ios-test-Info.plist \ 109 | examples/iOS/xdelta3-ios-test/xdelta3-ios-test/xdelta3-ios-test-Prefix.pch \ 110 | Makefile.mingw \ 111 | Makefile.orig \ 112 | testing/xdelta3-regtest.py \ 113 | testing/xdelta3-test.py \ 114 | xdelta3.1 \ 115 | xdelta3.i \ 116 | xdelta3.vcxproj \ 117 | xdelta3.wxi \ 118 | xdelta3.wxs 119 | 120 | # Broken, removed from distribution: 121 | # xdelta3_pywrap.c 122 | # xdelta3.py 123 | 124 | #PYFILES = xdelta3_pywrap.c xdelta3.py 125 | #XDELTA3PY = xdelta3.py 126 | #XDELTA3PYLIB = xdelta3.la 127 | 128 | #BUILT_SOURCES = $(PYFILES) 129 | 130 | #xdelta3_pywrap.c xdelta3.py : xdelta3.i 131 | # $(SWIG) -python -o xdelta3_pywrap.c xdelta3.i 132 | 133 | # OS X for some reason requires: 134 | # pythondir = $(PYTHON_SITE_PKG) 135 | # pyexecdir = $(PYTHON_SITE_PKG) 136 | 137 | #python_PYTHON = $(XDELTA3PY) 138 | #pyexec_LTLIBRARIES = $(XDELTA3PYLIB) 139 | #_xdelta3_la_SOURCES = $(srcdir)/xdelta3_pywrap.c $(xdelta3_SOURCES) 140 | #_xdelta3_la_CFLAGS = $(common_CFLAGS) -DNOT_MAIN=1 $(PYTHON_CPPFLAGS) 141 | #_xdelta3_la_LDFLAGS = -module 142 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/Makefile.mingw: -------------------------------------------------------------------------------- 1 | # xdelta 3 - delta compression tools and library 2 | # Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007. Joshua P. MacDonald 3 | 4 | UNAME = $(shell uname) 5 | CYGWIN = $(findstring CYGWIN, $(UNAME)) 6 | MINGW = $(findstring MINGW32, $(UNAME)) 7 | PYVER = 2.5 8 | 9 | ifneq ("$(CYGWIN)", "") 10 | SWIGTGT = xdelta3module.dll 11 | PYTGT = build/lib.cygwin-1.5.24-i686-$(PYVER)/xdelta3main.dll 12 | else 13 | ifneq ("$(MINGW)", "") 14 | # FIXME: WHAT TO DO HERE??? 15 | # FIXME: WHAT IF WE ARE CROSS-COMPILING??? 16 | endif 17 | endif 18 | 19 | SOURCES = xdelta3-cfgs.h \ 20 | xdelta3-decode.h \ 21 | xdelta3-djw.h \ 22 | xdelta3-fgk.h \ 23 | xdelta3-hash.h \ 24 | xdelta3-list.h \ 25 | xdelta3-main.h \ 26 | xdelta3-python.h \ 27 | xdelta3-second.h \ 28 | xdelta3-test.h \ 29 | xdelta3-test2.h \ 30 | xdelta3.c \ 31 | xdelta3.h 32 | 33 | TARGETS = xdelta3-debug.exe \ 34 | xdelta3.exe \ 35 | xdelta3-debug2.exe \ 36 | xdelta3-debug3.exe \ 37 | xdelta3.o \ 38 | xdelta3_wrap.o \ 39 | xdelta3-32.exe \ 40 | xdelta3-64.exe \ 41 | xdelta3-everything.exe \ 42 | xdelta3-decoder.exe xdelta3-decoder-nomain.o \ 43 | xdelta3-nosec.o xdelta3-all.o xdelta3-fgk.o \ 44 | xdelta3-noext.exe xdelta3-tools.exe \ 45 | xdelta3-notools.exe \ 46 | xdelta3_wrap.c xdelta3.py \ 47 | $(PYTGT) $(SWIGTGT) 48 | 49 | PYTHON = python 50 | 51 | WIXDIR = "/cygdrive/c/Program Files/wix2.0.4820" 52 | # FIXME: MinGW ???? 53 | 54 | CFLAGS= -Wall -Wshadow -fno-builtin 55 | XDWINFLAGS:=-DXD3_STDIO=0 -DXD3_POSIX=0 -DXD3_WIN32=1 -DEXTERNAL_COMPRESSION=0 56 | 57 | # $Format: "REL=$Xdelta3Version$" $ 58 | REL=3.0.1 59 | 60 | RELDIR = xdelta$(REL) 61 | 62 | EXTRA = Makefile COPYING linkxd3lib.c badcopy.c xdelta3.swig \ 63 | draft-korn-vcdiff.txt xdelta3.vcproj badcopy.vcproj \ 64 | xdelta3-regtest.py xdelta3-test.py setup.py \ 65 | examples/Makefile examples/small_page_test.c \ 66 | examples/README examples/encode_decode_test.c \ 67 | examples/compare_test.c examples/speed_test.c \ 68 | examples/test.h examples/checksum_test.cc \ 69 | xdelta3.py xdelta3_wrap.c xdelta3.wxs xdelta3.wxi \ 70 | README readme.txt 71 | 72 | SWIG_FLAGS = -DXD3_DEBUG=0 \ 73 | -DEXTERNAL_COMPRESSION=0 \ 74 | -DXD3_USE_LARGEFILE64=1 \ 75 | -DGENERIC_ENCODE_TABLES=1 \ 76 | -DSECONDARY_DJW=1 \ 77 | -DVCDIFF_TOOLS=1 \ 78 | -DSWIG_MODULE=1 79 | 80 | all: xdelta3-debug.exe xdelta3.exe 81 | 82 | all-py: all $(PYTGT) $(SWIGTGT) 83 | 84 | all-targets: $(TARGETS) 85 | 86 | all-targets-test: all-targets test 87 | 88 | pytgt: $(PYTGT) 89 | swigtgt: $(SWIGTGT) 90 | 91 | test: 92 | ./xdelta3-debug.exe test 93 | # FIXME: Not good when cross-compiling 94 | 95 | clean: 96 | rm -f $(TARGETS) 97 | rm -rf build Debug Release core cifs* *.stackdump *.exe \ 98 | xdelta3.ncb xdelta3.suo xdelta3.sln xdelta3.wixobj xdelta3.msi 99 | 100 | wix: xdelta3.wxs xdelta3.wxi readme.txt Release\xdelta3.exe 101 | $(WIXDIR)/candle.exe xdelta3.wxs -out xdelta3.wixobj 102 | $(WIXDIR)/light.exe xdelta3.wixobj -out xdelta3.msi 103 | # FIXME: MinGW ???? 104 | 105 | xdelta3.exe: $(SOURCES) 106 | $(CC) $(CFLAGS) -O3 xdelta3.c -lm -o xdelta3.exe \ 107 | $(XDWINFLAGS) \ 108 | -DGENERIC_ENCODE_TABLES=0 \ 109 | -DREGRESSION_TEST=1 \ 110 | -DSECONDARY_DJW=1 \ 111 | -DSECONDARY_FGK=1 \ 112 | -DXD3_DEBUG=0 \ 113 | -DXD3_MAIN=1 \ 114 | -DXD3_USE_LARGEFILE64=1 115 | 116 | xdelta3-debug.exe: $(SOURCES) 117 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug.exe \ 118 | $(XDWINFLAGS) \ 119 | -DGENERIC_ENCODE_TABLES=1 \ 120 | -DREGRESSION_TEST=1 \ 121 | -DSECONDARY_DJW=1 \ 122 | -DSECONDARY_FGK=1 \ 123 | -DXD3_DEBUG=1 \ 124 | -DXD3_MAIN=1 \ 125 | -DXD3_USE_LARGEFILE64=1 126 | 127 | xdelta3-32.exe: $(SOURCES) 128 | $(CC) -O3 $(CFLAGS) xdelta3.c -lm -o xdelta3-32.exe \ 129 | $(XDWINFLAGS) \ 130 | -DXD3_DEBUG=1 \ 131 | -DXD3_USE_LARGEFILE64=0 \ 132 | -DREGRESSION_TEST=1 \ 133 | -DSECONDARY_DJW=1 \ 134 | -DSECONDARY_FGK=1 \ 135 | -DXD3_MAIN=1 136 | 137 | xdelta3-debug2.exe: $(SOURCES) 138 | $(CC) -g $(CFLAGS) \ 139 | xdelta3.c -o xdelta3-debug2.exe \ 140 | $(XDWINFLAGS) \ 141 | -DXD3_DEBUG=2 \ 142 | -DXD3_MAIN=1 \ 143 | -DXD3_USE_LARGEFILE64=1 \ 144 | -DGENERIC_ENCODE_TABLES=1 \ 145 | -DREGRESSION_TEST=1 \ 146 | -DSECONDARY_DJW=1 \ 147 | -DSECONDARY_FGK=1 \ 148 | -lm 149 | 150 | xdelta3-debug3.exe: $(SOURCES) 151 | $(CC) -g $(CFLAGS) xdelta3.c -o xdelta3-debug3.exe \ 152 | $(XDWINFLAGS) \ 153 | -DXD3_MAIN=1 \ 154 | -DGENERIC_ENCODE_TABLES=1 \ 155 | -DXD3_USE_LARGEFILE64=1 \ 156 | -DREGRESSION_TEST=1 \ 157 | -DXD3_DEBUG=3 \ 158 | -DSECONDARY_DJW=1 \ 159 | -DSECONDARY_FGK=1 \ 160 | -lm 161 | 162 | $(PYTGT): $(SOURCES) setup.py 163 | $(PYTHON) setup.py install --verbose --compile --force 164 | 165 | xdelta3_wrap.c xdelta3.py: xdelta3.swig 166 | swig -python xdelta3.swig 167 | 168 | xdelta3.o: $(SOURCES) 169 | $(CC) -O3 $(CFLAGS) -c xdelta3.c $(SWIG_FLAGS) -o xdelta3.o 170 | 171 | xdelta3_wrap.o: xdelta3_wrap.c 172 | $(CC) -O3 $(CFLAGS) $(SWIG_FLAGS) \ 173 | -DHAVE_CONFIG_H \ 174 | -I/usr/include/python$(PYVER) \ 175 | -I/usr/lib/python$(PYVER)/config \ 176 | -fpic \ 177 | -c xdelta3_wrap.c 178 | # FIXME: MinGW ???? 179 | 180 | xdelta3module.dll: xdelta3_wrap.o xdelta3.o 181 | gcc -shared -Wl,--enable-auto-image-base \ 182 | xdelta3.o \ 183 | xdelta3_wrap.o \ 184 | -L/usr/lib/python$(PYVER)/config \ 185 | -lpython$(PYVER) \ 186 | -o xdelta3module.dll 187 | cp $(SWIGTGT) /usr/lib/python$(PYVER)/site-packages 188 | # FIXME: MinGW ???? 189 | 190 | xdelta3-decoder.exe: $(SOURCES) 191 | $(CC) -O3 -Wall -Wshadow xdelta3.c \ 192 | -DXD3_ENCODER=0 -DXD3_MAIN=1 -DSECONDARY_FGK=0 -DSECONDARY_DJW=0 \ 193 | $(XDWINFLAGS) -DVCDIFF_TOOLS=0 \ 194 | -o xdelta3-decoder.exe 195 | 196 | xdelta3-decoder-nomain.o: $(SOURCES) linkxd3lib.c 197 | $(CC) -O3 -Wall -Wshadow xdelta3.c linkxd3lib.c \ 198 | -DXD3_ENCODER=0 -DSECONDARY_FGK=0 -DSECONDARY_DJW=0 \ 199 | -o xdelta3-decoder-nomain.o 200 | strip xdelta3-decoder-nomain.o 201 | # FIXME: this OK with MinGW?? What's with strip?? 202 | 203 | xdelta3-64.exe: $(SOURCES) 204 | $(CC) -g $(CFLAGS) \ 205 | xdelta3.c \ 206 | -o xdelta3-64.exe \ 207 | $(XDWINFLAGS) \ 208 | -DXD3_MAIN=1 \ 209 | -DREGRESSION_TEST=1 \ 210 | -DXD3_DEBUG=0 \ 211 | -DXD3_USE_LARGEFILE64=1 \ 212 | -lm 213 | 214 | xdelta3-everything.exe: $(SOURCES) 215 | $(CC) -g $(CFLAGS) \ 216 | xdelta3.c \ 217 | -o xdelta3-everything.exe \ 218 | $(XDWINFLAGS) \ 219 | -DXD3_MAIN=1 \ 220 | -DVCDIFF_TOOLS=1 \ 221 | -DREGRESSION_TEST=1 \ 222 | -DSECONDARY_FGK=1 \ 223 | -DSECONDARY_DJW=1 \ 224 | -DGENERIC_ENCODE_TABLES=1 \ 225 | -DGENERIC_ENCODE_TABLES_COMPUTE=1 \ 226 | -DXD3_DEBUG=1 \ 227 | -lm 228 | 229 | xdelta3-nosec.o: $(SOURCES) 230 | $(CC) -O3 $(CFLAGS) -c xdelta3.c $(XDWINFLAGS) -DSECONDARY_FGK=0 -DSECONDARY_DJW=0 -o xdelta3-nosec.o 231 | 232 | xdelta3-all.o: $(SOURCES) 233 | $(CC) -O3 $(CFLAGS) -c xdelta3.c $(XDWINFLAGS) -DSECONDARY_FGK=1 -DSECONDARY_DJW=1 -o xdelta3-all.o 234 | 235 | xdelta3-fgk.o: $(SOURCES) 236 | $(CC) -O3 $(CFLAGS) -c xdelta3.c $(XDWINFLAGS) -DSECONDARY_FGK=1 -DSECONDARY_DJW=0 -o xdelta3-fgk.o 237 | 238 | xdelta3-noext.exe: $(SOURCES) 239 | $(CC) -O3 $(CFLAGS) xdelta3.c $(XDWINFLAGS) -DEXTERNAL_COMPRESSION=0 -DXD3_MAIN=1 -o xdelta3-noext.exe 240 | 241 | xdelta3-tools.exe: $(SOURCES) 242 | $(CC) -O3 $(CFLAGS) xdelta3.c $(XDWINFLAGS) -DXD3_MAIN=1 -o xdelta3-tools.exe 243 | 244 | xdelta3-notools.exe: $(SOURCES) 245 | $(CC) -O3 $(CFLAGS) xdelta3.c $(XDWINFLAGS) -DXD3_MAIN=1 -DVCDIFF_TOOLS=0 -o xdelta3-notools.exe 246 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/Makefile.orig: -------------------------------------------------------------------------------- 1 | # xdelta 3 - delta compression tools and library 2 | # Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007. Joshua P. MacDonald 3 | 4 | UNAME = $(shell uname) 5 | CYGWIN = $(findstring CYGWIN, $(UNAME)) 6 | DARWIN = $(findstring Darwin, $(UNAME)) 7 | PYVER = 2.6 8 | 9 | ifeq ("$(CYGWIN)", "") 10 | SWIGTGT = xdelta3module.so 11 | PYTGT = build/lib.macosx-10.6-universal-2.6/xdelta3main.so 12 | else 13 | SWIGTGT = xdelta3module.dll 14 | PYTGT = build/lib.cygwin-1.5.24-i686-$(PYVER)/xdelta3main.dll 15 | endif 16 | 17 | SOURCES = xdelta3-blkcache.h \ 18 | xdelta3-cfgs.h \ 19 | xdelta3-decode.h \ 20 | xdelta3-djw.h \ 21 | xdelta3-fgk.h \ 22 | xdelta3-hash.h \ 23 | xdelta3-list.h \ 24 | xdelta3-main.h \ 25 | xdelta3-merge.h \ 26 | xdelta3-python.h \ 27 | xdelta3-second.h \ 28 | xdelta3-test.h \ 29 | xdelta3.c \ 30 | xdelta3.h 31 | 32 | TARGETS = xdelta3-debug \ 33 | xdelta3-debug32 \ 34 | xdelta3-debug64 \ 35 | xdelta3 \ 36 | xdelta3-debug2 \ 37 | xdelta3-debugstdio \ 38 | xdelta3.o \ 39 | xdelta3_wrap.o \ 40 | xdelta3-32 \ 41 | xdelta3-64 \ 42 | xdelta3-everything \ 43 | xdelta3-Opg \ 44 | xdelta3-64-O \ 45 | xdelta3-Op \ 46 | xdelta3-decoder xdelta3-decoder-nomain.o \ 47 | xdelta3-nosec.o xdelta3-all.o xdelta3-fgk.o \ 48 | xdelta3-noext xdelta3-tools \ 49 | xdelta3-notools \ 50 | xdelta3_wrap.c xdelta3.py \ 51 | $(PYTGT) $(SWIGTGT) \ 52 | xdelta3-warnings 53 | 54 | PYTHON = python 55 | 56 | WIXDIR = "/cygdrive/c/Program Files/wix2.0.4820" 57 | 58 | CFLAGS= -Wall -Wshadow -fno-builtin 59 | WFLAGS= -Wextra -Wsign-compare -Wconversion -Wextra -Wno-unused-parameter 60 | 61 | # $Format: "REL=$Xdelta3Version$" $ 62 | REL=3.0.1 63 | 64 | RELDIR = xdelta$(REL) 65 | 66 | EXTRA = Makefile COPYING linkxd3lib.c badcopy.c xdelta3.swig \ 67 | draft-korn-vcdiff.txt xdelta3.vcproj badcopy.vcproj \ 68 | testing/xdelta3-regtest.py xdelta3-test.py setup.py \ 69 | examples/Makefile examples/small_page_test.c \ 70 | examples/README examples/encode_decode_test.c \ 71 | examples/compare_test.c examples/speed_test.c \ 72 | examples/test.h examples/checksum_test.cc \ 73 | xdelta3.py xdelta3_wrap.c xdelta3.wxs xdelta3.wxi \ 74 | testing/cmp.h testing/delta.h testing/file.h \ 75 | testing/modify.h testing/random.h testing/segment.h \ 76 | testing/sizes.h testing/test.h testing/Makefile \ 77 | testing/regtest.cc README readme.txt xdelta3.1 78 | 79 | SWIG_FLAGS = -DXD3_DEBUG=1 \ 80 | -DEXTERNAL_COMPRESSION=0 \ 81 | -DXD3_USE_LARGEFILE64=1 \ 82 | -DGENERIC_ENCODE_TABLES=1 \ 83 | -DSECONDARY_DJW=1 \ 84 | -DVCDIFF_TOOLS=1 \ 85 | -DSWIG_MODULE=1 86 | 87 | all: xdelta3-debug32 xdelta3-debug64 xdelta3-debug2 xdelta3 88 | (cd testing && make) 89 | 90 | all-py: all $(PYTGT) $(SWIGTGT) 91 | 92 | all-targets: $(TARGETS) 93 | 94 | all-targets-test: all-targets test 95 | 96 | pytgt: $(PYTGT) 97 | swigtgt: $(SWIGTGT) 98 | 99 | test: 100 | ./xdelta3-debug test 101 | 102 | tar: 103 | tar --exclude ".svn" -czf /tmp/$(RELDIR)-tmp.tar.gz $(SOURCES) $(EXTRA) 104 | rm -rf /tmp/$(RELDIR) 105 | mkdir /tmp/$(RELDIR) 106 | (cd /tmp/$(RELDIR) && tar -xzf ../$(RELDIR)-tmp.tar.gz) 107 | tar -czf ./$(RELDIR).tar.gz -C /tmp $(RELDIR) 108 | +tar -tzf ./$(RELDIR).tar.gz 109 | rm -rf /tmp/$(RELDIR) 110 | 111 | zip: 112 | tar --exclude ".svn" -czf /tmp/$(RELDIR)-tmp.tar.gz $(SOURCES) $(EXTRA) 113 | rm -rf /tmp/$(RELDIR) 114 | mkdir /tmp/$(RELDIR) 115 | (cd /tmp/$(RELDIR) && tar -xzf ../$(RELDIR)-tmp.tar.gz) 116 | tar -czf ./$(RELDIR).tar.gz -C /tmp $(RELDIR) 117 | +zip -r $(RELDIR).zip /tmp/$(RELDIR) 118 | rm -rf /tmp/$(RELDIR) 119 | 120 | clean: 121 | rm -f $(TARGETS) 122 | rm -rf build Debug Release core cifs* *.stackdump *.exe *~ *.dSYM \ 123 | xdelta3.ncb xdelta3.suo xdelta3.sln xdelta3.wixobj xdelta3.msi 124 | 125 | wix: xdelta3.wxs xdelta3.wxi readme.txt Release\xdelta3.exe 126 | $(WIXDIR)/candle.exe xdelta3.wxs -out xdelta3.wixobj 127 | $(WIXDIR)/light.exe xdelta3.wixobj -out xdelta3.msi 128 | 129 | xdelta3: $(SOURCES) 130 | $(CC) $(CFLAGS) -O3 xdelta3.c -lm -o xdelta3 \ 131 | -DGENERIC_ENCODE_TABLES=0 \ 132 | -DREGRESSION_TEST=1 \ 133 | -DSECONDARY_DJW=1 \ 134 | -DSECONDARY_FGK=1 \ 135 | -DXD3_DEBUG=0 \ 136 | -DXD3_MAIN=1 \ 137 | -DXD3_POSIX=1 \ 138 | -DXD3_USE_LARGEFILE64=1 139 | 140 | xdelta3-debug32: $(SOURCES) 141 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug32 \ 142 | -arch i386 \ 143 | -DGENERIC_ENCODE_TABLES=1 \ 144 | -DREGRESSION_TEST=1 \ 145 | -DSECONDARY_DJW=1 \ 146 | -DSECONDARY_FGK=1 \ 147 | -DXD3_DEBUG=1 \ 148 | -DXD3_MAIN=1 \ 149 | -DXD3_POSIX=1 \ 150 | -DXD3_USE_LARGEFILE64=1 151 | 152 | xdelta3-debug64: $(SOURCES) 153 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-debug64 \ 154 | -arch x86_64 \ 155 | -DGENERIC_ENCODE_TABLES=1 \ 156 | -DREGRESSION_TEST=1 \ 157 | -DSECONDARY_DJW=1 \ 158 | -DSECONDARY_FGK=1 \ 159 | -DXD3_DEBUG=1 \ 160 | -DXD3_MAIN=1 \ 161 | -DXD3_POSIX=1 \ 162 | -DXD3_USE_LARGEFILE64=1 163 | 164 | xdelta3-warnings: $(SOURCES) 165 | $(CC) -g $(CFLAGS) $(WFLAGS) xdelta3.c -lm -o xdelta3-warnings \ 166 | -DGENERIC_ENCODE_TABLES=1 \ 167 | -DREGRESSION_TEST=1 \ 168 | -DSECONDARY_DJW=1 \ 169 | -DSECONDARY_FGK=1 \ 170 | -DXD3_DEBUG=1 \ 171 | -DXD3_MAIN=1 \ 172 | -DXD3_STDIO=1 \ 173 | -DXD3_USE_LARGEFILE64=1 174 | 175 | xdelta3-32: $(SOURCES) 176 | $(CC) -g $(CFLAGS) xdelta3.c -lm -o xdelta3-32 \ 177 | -DXD3_DEBUG=1 \ 178 | -DXD3_USE_LARGEFILE64=0 \ 179 | -DREGRESSION_TEST=1 \ 180 | -DSECONDARY_DJW=1 \ 181 | -DSECONDARY_FGK=1 \ 182 | -DXD3_MAIN=1 \ 183 | -DXD3_POSIX=1 184 | 185 | xdelta3-debug2: $(SOURCES) 186 | $(CC) -g $(CFLAGS) \ 187 | xdelta3.c -o xdelta3-debug2 \ 188 | -DXD3_DEBUG=2 \ 189 | -DXD3_MAIN=1 \ 190 | -DXD3_POSIX=1 \ 191 | -DXD3_USE_LARGEFILE64=1 \ 192 | -DGENERIC_ENCODE_TABLES=1 \ 193 | -DREGRESSION_TEST=1 \ 194 | -DSECONDARY_DJW=1 \ 195 | -DSECONDARY_FGK=1 \ 196 | -lm 197 | 198 | xdelta3-debugstdio: $(SOURCES) 199 | $(CC) -g $(CFLAGS) xdelta3.c -o xdelta3-debugstdio \ 200 | -DXD3_MAIN=1 \ 201 | -DGENERIC_ENCODE_TABLES=1 \ 202 | -DXD3_USE_LARGEFILE64=1 \ 203 | -DXD3_STDIO=1 \ 204 | -DREGRESSION_TEST=1 \ 205 | -DXD3_DEBUG=1 \ 206 | -DSECONDARY_DJW=1 \ 207 | -DSECONDARY_FGK=1 \ 208 | -lm 209 | 210 | $(PYTGT): $(SOURCES) setup.py 211 | $(PYTHON) setup.py install --verbose --compile --force 212 | 213 | xdelta3_wrap.c xdelta3.py: xdelta3.swig 214 | swig -python xdelta3.swig 215 | 216 | xdelta3.o: $(SOURCES) 217 | $(CC) -O3 $(CFLAGS) -c xdelta3.c $(SWIG_FLAGS) -o xdelta3.o 218 | 219 | xdelta3_wrap.o: xdelta3_wrap.c 220 | $(CC) -O3 $(CFLAGS) $(SWIG_FLAGS) \ 221 | -DHAVE_CONFIG_H \ 222 | -I/usr/include/python$(PYVER) \ 223 | -I/usr/lib/python$(PYVER)/config \ 224 | -fpic \ 225 | -c xdelta3_wrap.c 226 | 227 | xdelta3module.dll: xdelta3_wrap.o xdelta3.o 228 | gcc -shared -Wl,--enable-auto-image-base \ 229 | xdelta3.o \ 230 | xdelta3_wrap.o \ 231 | -L/usr/lib/python$(PYVER)/config \ 232 | -lpython$(PYVER) \ 233 | -o xdelta3module.dll 234 | cp $(SWIGTGT) /usr/lib/python$(PYVER)/site-packages 235 | 236 | ifeq ("$(DARWIN)", "") 237 | xdelta3module.so: xdelta3_wrap.o xdelta3.o 238 | ld -shared xdelta3.o xdelta3_wrap.o \ 239 | -o xdelta3module.so \ 240 | /usr/lib/libpython$(PYVER).so \ 241 | -lc 242 | else 243 | xdelta3module.so: xdelta3_wrap.o xdelta3.o 244 | gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup \ 245 | -arch x86_64 $(CFLAGS) \ 246 | xdelta3.o xdelta3_wrap.o -o xdelta3module.so 247 | cp xdelta3module.so /Library/Python/2.6/site-packages 248 | endif 249 | 250 | xdelta3-decoder: $(SOURCES) 251 | $(CC) -O3 -Wall -Wshadow xdelta3.c \ 252 | -DXD3_ENCODER=0 -DXD3_MAIN=1 -DSECONDARY_FGK=0 -DSECONDARY_DJW=0 \ 253 | -DXD3_STDIO=1 -DEXTERNAL_COMPRESSION=0 -DVCDIFF_TOOLS=0 \ 254 | -o xdelta3-decoder 255 | 256 | xdelta3-decoder-nomain.o: $(SOURCES) linkxd3lib.c 257 | $(CC) -O3 -Wall -Wshadow xdelta3.c linkxd3lib.c \ 258 | -DXD3_ENCODER=0 -DSECONDARY_FGK=0 -DSECONDARY_DJW=0 \ 259 | -o xdelta3-decoder-nomain.o 260 | strip xdelta3-decoder-nomain.o 261 | 262 | xdelta3-O++: $(SOURCES) 263 | $(CXX) -g -O3 $(CFLAGS) xdelta3.c \ 264 | -o xdelta3-O++ \ 265 | -DXD3_MAIN=1 \ 266 | -DSECONDARY_DJW=1 \ 267 | -DREGRESSION_TEST=1 \ 268 | -lm 269 | 270 | xdelta3-Op: $(SOURCES) 271 | $(CC) -g -O3 $(CFLAGS) xdelta3.c \ 272 | -o xdelta3-Op \ 273 | -DXD3_POSIX=1 \ 274 | -DXD3_MAIN=1 \ 275 | -DREGRESSION_TEST=1 \ 276 | -lm 277 | 278 | xdelta3-64: $(SOURCES) 279 | $(CC) -g $(CFLAGS) \ 280 | xdelta3.c \ 281 | -o xdelta3-64 \ 282 | -DXD3_POSIX=1 \ 283 | -DXD3_MAIN=1 \ 284 | -DREGRESSION_TEST=1 \ 285 | -DXD3_DEBUG=0 \ 286 | -DXD3_USE_LARGEFILE64=1 \ 287 | -lm 288 | 289 | xdelta3-64-O: $(SOURCES) 290 | $(CC) -O3 $(CFLAGS) \ 291 | xdelta3.c \ 292 | -o xdelta3-64-O \ 293 | -DXD3_POSIX=1 \ 294 | -DXD3_MAIN=1 \ 295 | -DXD3_USE_LARGEFILE64=1 \ 296 | -lm 297 | 298 | xdelta3-everything: $(SOURCES) 299 | $(CC) -g $(CFLAGS) \ 300 | xdelta3.c \ 301 | -o xdelta3-everything \ 302 | -DXD3_MAIN=1 \ 303 | -DVCDIFF_TOOLS=1 \ 304 | -DREGRESSION_TEST=1 \ 305 | -DSECONDARY_FGK=1 \ 306 | -DSECONDARY_DJW=1 \ 307 | -DGENERIC_ENCODE_TABLES=1 \ 308 | -DGENERIC_ENCODE_TABLES_COMPUTE=1 \ 309 | -DXD3_POSIX=1 \ 310 | -DEXTERNAL_COMPRESSION=1 \ 311 | -DXD3_DEBUG=1 \ 312 | -lm 313 | 314 | xdelta3-Opg: $(SOURCES) 315 | $(CC) -pg -g -O3 $(CFLAGS) \ 316 | xdelta3.c \ 317 | -o xdelta3-Opg \ 318 | -DXD3_MAIN=1 \ 319 | -DSECONDARY_DJW=1 \ 320 | -DSECONDARY_FGK=1 \ 321 | -DXD3_POSIX=1 \ 322 | -DXD3_USE_LARGEFILE64=1 \ 323 | -DREGRESSION_TEST=1 324 | 325 | xdelta3-nosec.o: $(SOURCES) 326 | $(CC) -O3 $(CFLAGS) -c xdelta3.c -DSECONDARY_FGK=0 -DSECONDARY_DJW=0 -o xdelta3-nosec.o 327 | 328 | xdelta3-all.o: $(SOURCES) 329 | $(CC) -O3 $(CFLAGS) -c xdelta3.c -DSECONDARY_FGK=1 -DSECONDARY_DJW=1 -o xdelta3-all.o 330 | 331 | xdelta3-fgk.o: $(SOURCES) 332 | $(CC) -O3 $(CFLAGS) -c xdelta3.c -DSECONDARY_FGK=1 -DSECONDARY_DJW=0 -o xdelta3-fgk.o 333 | 334 | xdelta3-noext: $(SOURCES) 335 | $(CC) -O3 $(CFLAGS) xdelta3.c -DXD3_MAIN=1 -DEXTERNAL_COMPRESSION=0 -o xdelta3-noext 336 | 337 | xdelta3-tools: $(SOURCES) 338 | $(CC) -O3 $(CFLAGS) xdelta3.c -DXD3_MAIN=1 -o xdelta3-tools 339 | 340 | xdelta3-notools: $(SOURCES) 341 | $(CC) -O3 $(CFLAGS) xdelta3.c -DXD3_MAIN=1 -DVCDIFF_TOOLS=0 -o xdelta3-notools 342 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/README: -------------------------------------------------------------------------------- 1 | Xdelta 3.x readme.txt 2 | Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 3 | 4 | 5 | 6 | Thanks for downloading Xdelta! 7 | 8 | This directory contains the Xdelta3 command-line interface (CLI) and source 9 | distribution for VCDIFF differential compression, a.k.a. delta 10 | compression. The latest information and downloads are available here: 11 | 12 | http://xdelta.org/ 13 | http://code.google.com/p/xdelta/ 14 | 15 | The command-line syntax: 16 | 17 | http://code.google.com/p/xdelta/wiki/CommandLineSyntax 18 | 19 | Run 'xdelta3 -h' for brief help. Run 'xdelta3 test' for built-in tests. 20 | 21 | Sample commands (like gzip, -e means encode, -d means decode) 22 | 23 | xdelta3 -9 -S djw -e -vfs OLD_FILE NEW_FILE DELTA_FILE 24 | xdelta3 -d -vfs OLD_FILE DELTA_FILE DECODED_FILE 25 | 26 | File bug reports and browse open support issues here: 27 | 28 | http://code.google.com/p/xdelta/issues/list 29 | 30 | The source distribution contains the C/C++/Python APIs, Unix, Microsoft VC++ 31 | and Cygwin builds. Xdelta3 is covered under the terms of the GPL, see 32 | COPYING. 33 | 34 | Commercial inquiries welcome, please contact 35 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define if pointers to integers require aligned access */ 4 | #undef HAVE_ALIGNED_ACCESS_REQUIRED 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_INTTYPES_H 8 | 9 | /* Define to 1 if you have the `lzma' library (-llzma). */ 10 | #undef HAVE_LIBLZMA 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_LZMA_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_MEMORY_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STDINT_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STDLIB_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STRINGS_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_STRING_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_SYS_STAT_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_SYS_TYPES_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_UNISTD_H 38 | 39 | /* Define to the address where bug reports for this package should be sent. */ 40 | #undef PACKAGE_BUGREPORT 41 | 42 | /* Define to the full name of this package. */ 43 | #undef PACKAGE_NAME 44 | 45 | /* Define to the full name and version of this package. */ 46 | #undef PACKAGE_STRING 47 | 48 | /* Define to the one symbol short name of this package. */ 49 | #undef PACKAGE_TARNAME 50 | 51 | /* Define to the home page for this package. */ 52 | #undef PACKAGE_URL 53 | 54 | /* Define to the version of this package. */ 55 | #undef PACKAGE_VERSION 56 | 57 | /* Define to 1 if you have the ANSI C header files. */ 58 | #undef STDC_HEADERS 59 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([Xdelta3], [3.0.6], [josh.macdonald@gmail.com], 2 | [xdelta3], [http://xdelta.org/]) 3 | AC_PREREQ([2.68]) 4 | AC_CONFIG_MACRO_DIR([m4]) 5 | #LT_INIT 6 | AM_INIT_AUTOMAKE([1.9 no-define foreign tar-ustar]) 7 | #AC_DISABLE_STATIC 8 | AX_CHECK_ALIGNED_ACCESS_REQUIRED 9 | AC_PROG_CC 10 | AC_PROG_CXX 11 | AC_CHECK_HEADERS([lzma.h]) 12 | AC_CHECK_LIB(lzma, lzma_easy_buffer_encode) 13 | #AM_PATH_PYTHON(,, [:]) 14 | #AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :]) 15 | #AX_PYTHON_DEVEL() 16 | #AX_PKG_SWIG(2.0.0,,) 17 | #AX_SWIG_PYTHON 18 | 19 | dnl --enable-debug-symbols : build with debug symbols? 20 | AC_ARG_ENABLE(debug-symbols, 21 | AS_HELP_STRING(--enable-debug-symbols,[Build with debug symbols (default is NO)]),,enableval=no) 22 | AM_CONDITIONAL([DEBUG_SYMBOLS], [test ${enableval} = "yes"]) 23 | 24 | AC_CONFIG_HEADERS([config.h]) 25 | AC_CONFIG_FILES([Makefile]) 26 | AC_OUTPUT 27 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -g -Wall -I.. -DXD3_DEBUG=1 -DNDEBUG=0 2 | #CFLAGS = -O3 -Wall -I.. -DXD3_DEBUG=0 -fno-builtin -DNDEBUG=1 3 | # -pg 4 | 5 | SOURCES = small_page_test.c encode_decode_test.c speed_test.c 6 | 7 | DEPS = ../*.h ../*.c *.h 8 | 9 | TARGETS = small_page_test encode_decode_test speed_test32 speed_test64 compare_test checksum_test 10 | 11 | all: $(TARGETS) 12 | 13 | small_page_test: small_page_test.c $(DEPS) 14 | $(CC) $(CFLAGS) small_page_test.c -o small_page_test -DXD3_USE_LARGEFILE64=0 -DSECONDARY_DJW=1 15 | 16 | encode_decode_test: encode_decode_test.c $(DEPS) 17 | $(CC) $(CFLAGS) encode_decode_test.c -o encode_decode_test 18 | 19 | speed_test32: speed_test.c $(DEPS) 20 | $(CC) $(CFLAGS) -DXD3_USE_LARGEFILE64=0 speed_test.c -o speed_test32 21 | 22 | speed_test64: speed_test.c $(DEPS) 23 | $(CC) $(CFLAGS) -DXD3_USE_LARGEFILE64=1 speed_test.c -o speed_test64 24 | 25 | compare_test: compare_test.c 26 | $(CC) $(CFLAGS) compare_test.c -o compare_test 27 | 28 | checksum_test: checksum_test.cc 29 | $(CXX) $(CFLAGS) checksum_test.cc -o checksum_test 30 | 31 | clean: 32 | rm -r -f *.exe *.stackdump $(TARGETS) *.dSYM *~ 33 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/README: -------------------------------------------------------------------------------- 1 | Files in this directory demonstrate how to use the Xdelta3 API. Copyrights 2 | are held by the respective authors and these files are not covered by the GPL. 3 | 4 | small_page_test.c -- how to use xdelta3 in an environment such as the kernel 5 | for small pages with little memory 6 | 7 | encode_decode_test.c -- how to use xdelta3 to process (encode/decode) data in 8 | multiple windows with the non-blocking API 9 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/compare_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "xdelta3.h" 8 | 9 | #define NUM (1<<20) 10 | #define ITERS 100 11 | 12 | /* From wikipedia on RDTSC */ 13 | inline uint64_t rdtsc() { 14 | uint32_t lo, hi; 15 | asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); 16 | return (uint64_t)hi << 32 | lo; 17 | } 18 | 19 | typedef int (*test_func)(const char *s1, const char *s2, int n); 20 | 21 | void run_test(const char *buf1, const char *buf2, 22 | const char *name, test_func func) { 23 | uint64_t start, end; 24 | uint64_t accum = 0; 25 | int i, x; 26 | 27 | for (i = 0; i < ITERS; i++) { 28 | start = rdtsc(); 29 | x = func(buf1, buf2, NUM); 30 | end = rdtsc(); 31 | accum += end - start; 32 | assert(x == NUM - 1); 33 | } 34 | 35 | accum /= ITERS; 36 | 37 | printf("%s : %qu cycles\n", name, accum); 38 | } 39 | 40 | /* Build w/ -fno-builtin for this to be fast, this assumes that there 41 | * is a difference at s1[n-1] */ 42 | int memcmp_fake(const char *s1, const char *s2, int n) { 43 | int x = memcmp(s1, s2, n); 44 | return x < 0 ? n - 1 : n + 1; 45 | } 46 | 47 | #define UNALIGNED_OK 1 48 | static inline int 49 | test2(const char *s1c, const char *s2c, int n) 50 | { 51 | int i = 0; 52 | #if UNALIGNED_OK 53 | int nint = n / sizeof(int); 54 | 55 | if (nint >> 3) 56 | { 57 | int j = 0; 58 | const int *s1 = (const int*)s1c; 59 | const int *s2 = (const int*)s2c; 60 | int nint_8 = nint - 8; 61 | 62 | while (i <= nint_8 && 63 | s1[i++] == s2[j++] && 64 | s1[i++] == s2[j++] && 65 | s1[i++] == s2[j++] && 66 | s1[i++] == s2[j++] && 67 | s1[i++] == s2[j++] && 68 | s1[i++] == s2[j++] && 69 | s1[i++] == s2[j++] && 70 | s1[i++] == s2[j++]) { } 71 | 72 | i = (i - 1) * sizeof(int); 73 | } 74 | #endif 75 | 76 | while (i < n && s1c[i] == s2c[i]) 77 | { 78 | i++; 79 | } 80 | return i; 81 | } 82 | 83 | static inline int 84 | test1(const char *s1c, const char *s2c, int n) { 85 | int i = 0; 86 | while (i < n && s1c[i] == s2c[i]) 87 | { 88 | i++; 89 | } 90 | return i; 91 | } 92 | 93 | int main(/*int argc, char **argv*/) { 94 | char *buf1 = malloc(NUM+1); 95 | char *buf2 = malloc(NUM+1); 96 | int i; 97 | 98 | for (i = 0; i < NUM; i++) { 99 | buf1[i] = buf2[i] = rand(); 100 | } 101 | 102 | buf2[NUM-1]++; 103 | 104 | printf ("ALIGNED\n"); 105 | 106 | run_test(buf1, buf2, "memcmp", &memcmp_fake); 107 | run_test(buf1, buf2, "test1", &test1); 108 | run_test(buf1, buf2, "test2", &test2); 109 | 110 | for (i = 0; i < NUM; i++) { 111 | buf1[i] = buf2[i+1] = rand(); 112 | } 113 | 114 | buf2[NUM]++; 115 | 116 | printf ("UNALIGNED\n"); 117 | 118 | run_test(buf1, buf2+1, "memcmp", &memcmp_fake); 119 | run_test(buf1, buf2+1, "test1", &test1); 120 | run_test(buf1, buf2+1, "test2", &test2); 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/encode_decode_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // Permission to distribute this example by 3 | // Copyright (C) 2007 Ralf Junker 4 | // Ralf Junker 5 | // http://www.yunqa.de/delphi/ 6 | 7 | //--------------------------------------------------------------------------- 8 | 9 | #include 10 | #include 11 | #include "xdelta3.h" 12 | #include "xdelta3.c" 13 | 14 | //--------------------------------------------------------------------------- 15 | 16 | int code ( 17 | int encode, 18 | FILE* InFile, 19 | FILE* SrcFile , 20 | FILE* OutFile, 21 | int BufSize ) 22 | { 23 | int r, ret; 24 | struct stat statbuf; 25 | xd3_stream stream; 26 | xd3_config config; 27 | xd3_source source; 28 | void* Input_Buf; 29 | int Input_Buf_Read; 30 | 31 | if (BufSize < XD3_ALLOCSIZE) 32 | BufSize = XD3_ALLOCSIZE; 33 | 34 | memset (&stream, 0, sizeof (stream)); 35 | memset (&source, 0, sizeof (source)); 36 | 37 | xd3_init_config(&config, XD3_ADLER32); 38 | config.winsize = BufSize; 39 | xd3_config_stream(&stream, &config); 40 | 41 | if (SrcFile) 42 | { 43 | r = fstat(fileno(SrcFile), &statbuf); 44 | if (r) 45 | return r; 46 | 47 | source.blksize = BufSize; 48 | source.curblk = malloc(source.blksize); 49 | 50 | /* Load 1st block of stream. */ 51 | r = fseek(SrcFile, 0, SEEK_SET); 52 | if (r) 53 | return r; 54 | source.onblk = fread((void*)source.curblk, 1, source.blksize, SrcFile); 55 | source.curblkno = 0; 56 | /* Set the stream. */ 57 | xd3_set_source(&stream, &source); 58 | } 59 | 60 | Input_Buf = malloc(BufSize); 61 | 62 | fseek(InFile, 0, SEEK_SET); 63 | do 64 | { 65 | Input_Buf_Read = fread(Input_Buf, 1, BufSize, InFile); 66 | if (Input_Buf_Read < BufSize) 67 | { 68 | xd3_set_flags(&stream, XD3_FLUSH | stream.flags); 69 | } 70 | xd3_avail_input(&stream, Input_Buf, Input_Buf_Read); 71 | 72 | process: 73 | if (encode) 74 | ret = xd3_encode_input(&stream); 75 | else 76 | ret = xd3_decode_input(&stream); 77 | 78 | switch (ret) 79 | { 80 | case XD3_INPUT: 81 | { 82 | fprintf (stderr,"XD3_INPUT\n"); 83 | continue; 84 | } 85 | 86 | case XD3_OUTPUT: 87 | { 88 | fprintf (stderr,"XD3_OUTPUT\n"); 89 | r = fwrite(stream.next_out, 1, stream.avail_out, OutFile); 90 | if (r != (int)stream.avail_out) 91 | return r; 92 | xd3_consume_output(&stream); 93 | goto process; 94 | } 95 | 96 | case XD3_GETSRCBLK: 97 | { 98 | fprintf (stderr,"XD3_GETSRCBLK %qd\n", source.getblkno); 99 | if (SrcFile) 100 | { 101 | r = fseek(SrcFile, source.blksize * source.getblkno, SEEK_SET); 102 | if (r) 103 | return r; 104 | source.onblk = fread((void*)source.curblk, 1, 105 | source.blksize, SrcFile); 106 | source.curblkno = source.getblkno; 107 | } 108 | goto process; 109 | } 110 | 111 | case XD3_GOTHEADER: 112 | { 113 | fprintf (stderr,"XD3_GOTHEADER\n"); 114 | goto process; 115 | } 116 | 117 | case XD3_WINSTART: 118 | { 119 | fprintf (stderr,"XD3_WINSTART\n"); 120 | goto process; 121 | } 122 | 123 | case XD3_WINFINISH: 124 | { 125 | fprintf (stderr,"XD3_WINFINISH\n"); 126 | goto process; 127 | } 128 | 129 | default: 130 | { 131 | fprintf (stderr,"!!! INVALID %s %d !!!\n", 132 | stream.msg, ret); 133 | return ret; 134 | } 135 | 136 | } 137 | 138 | } 139 | while (Input_Buf_Read == BufSize); 140 | 141 | free(Input_Buf); 142 | 143 | free((void*)source.curblk); 144 | xd3_close_stream(&stream); 145 | xd3_free_stream(&stream); 146 | 147 | return 0; 148 | 149 | }; 150 | 151 | 152 | int main(int argc, char* argv[]) 153 | { 154 | FILE* InFile; 155 | FILE* SrcFile; 156 | FILE* OutFile; 157 | int r; 158 | 159 | if (argc != 3) { 160 | fprintf (stderr, "usage: %s source input\n", argv[0]); 161 | return 1; 162 | } 163 | 164 | char *input = argv[2]; 165 | char *source = argv[1]; 166 | const char *output = "encoded.testdata"; 167 | const char *decoded = "decoded.testdata"; 168 | 169 | /* Encode */ 170 | 171 | InFile = fopen(input, "rb"); 172 | SrcFile = fopen(source, "rb"); 173 | OutFile = fopen(output, "wb"); 174 | 175 | r = code (1, InFile, SrcFile, OutFile, 0x1000); 176 | 177 | fclose(OutFile); 178 | fclose(SrcFile); 179 | fclose(InFile); 180 | 181 | if (r) { 182 | fprintf (stderr, "Encode error: %d\n", r); 183 | return r; 184 | } 185 | 186 | /* Decode */ 187 | 188 | InFile = fopen(output, "rb"); 189 | SrcFile = fopen(source, "rb"); 190 | OutFile = fopen(decoded, "wb"); 191 | 192 | r = code (0, InFile, SrcFile, OutFile, 0x1000); 193 | 194 | fclose(OutFile); 195 | fclose(SrcFile); 196 | fclose(InFile); 197 | 198 | if (r) { 199 | fprintf (stderr, "Decode error: %d\n", r); 200 | return r; 201 | } 202 | 203 | return 0; 204 | } 205 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Xd3iOSAppDelegate.h 3 | // xdelta3-ios-test 4 | // 5 | // Created by Joshua MacDonald on 6/16/12. 6 | // Copyright (c) 2011, 2012 Joshua MacDonald. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Xd3iOSAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // Xd3iOSAppDelegate.m 3 | // xdelta3-ios-test 4 | // 5 | // Created by Joshua MacDonald on 6/16/12. 6 | // Copyright (c) 2011, 2012 Joshua MacDonald. All rights reserved. 7 | // 8 | 9 | #import "Xd3iOSAppDelegate.h" 10 | 11 | @implementation Xd3iOSAppDelegate 12 | 13 | @synthesize window = _window; 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 16 | { 17 | // Override point for customization after application launch. 18 | return YES; 19 | } 20 | 21 | - (void)applicationWillResignActive:(UIApplication *)application 22 | { 23 | /* 24 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | */ 27 | } 28 | 29 | - (void)applicationDidEnterBackground:(UIApplication *)application 30 | { 31 | /* 32 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 33 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | */ 35 | } 36 | 37 | - (void)applicationWillEnterForeground:(UIApplication *)application 38 | { 39 | /* 40 | Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 41 | */ 42 | } 43 | 44 | - (void)applicationDidBecomeActive:(UIApplication *)application 45 | { 46 | /* 47 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 | */ 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application 52 | { 53 | /* 54 | Called when the application is about to terminate. 55 | Save data if appropriate. 56 | See also applicationDidEnterBackground:. 57 | */ 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // Xd3iOSViewController.h 3 | // xdelta3-ios-test 4 | // 5 | // Created by Joshua MacDonald on 6/16/12. 6 | // Copyright (c) 2011, 2012 Joshua MacDonald. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Xd3iOSViewController : UIViewController { 12 | NSString *inputSeed; 13 | } 14 | - (IBAction)startTest:(id)sender; 15 | @property (weak, nonatomic) IBOutlet UITextField *theSeed; 16 | @property (weak, nonatomic) IBOutlet UITextView *theView; 17 | @property (atomic, retain) NSMutableString *theOutput; 18 | @property (nonatomic) BOOL inTest; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/Xd3iOSViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // Xd3iOSViewController.m 3 | // xdelta3-ios-test 4 | // 5 | // Created by Joshua MacDonald on 6/16/12. 6 | // Copyright (c) 2011, 2012 Joshua MacDonald. All rights reserved. 7 | // 8 | 9 | #import "Xd3iOSViewController.h" 10 | #include "xdelta3.h" 11 | #include "dispatch/queue.h" 12 | #include "Foundation/NSBundle.h" 13 | 14 | extern void (*xprintf_message_func)(const char* msg); 15 | void print_to_view(const char* buf); 16 | int xd3_main_cmdline(int argc, char **argv); 17 | void do_localfile_test(void); 18 | int compare_files(const char* file1, const char* file2); 19 | Xd3iOSViewController *static_ptr; 20 | 21 | @implementation Xd3iOSViewController 22 | @synthesize theSeed = _theSeed; 23 | @synthesize theView = _theView; 24 | @synthesize theOutput = _theOutput; 25 | @synthesize inTest = _inTest; 26 | 27 | - (void)didReceiveMemoryWarning 28 | { 29 | [super didReceiveMemoryWarning]; 30 | } 31 | 32 | #pragma mark - View lifecycle 33 | 34 | - (void)viewDidLoad 35 | { 36 | [super viewDidLoad]; 37 | } 38 | 39 | - (void)viewDidUnload 40 | { 41 | [self setTheSeed:nil]; 42 | [self setTheView:nil]; 43 | [self setTheView:nil]; 44 | [super viewDidUnload]; 45 | } 46 | 47 | - (void)viewWillAppear:(BOOL)animated 48 | { 49 | [super viewWillAppear:animated]; 50 | } 51 | 52 | - (void)viewDidAppear:(BOOL)animated 53 | { 54 | [super viewDidAppear:animated]; 55 | } 56 | 57 | - (void)viewWillDisappear:(BOOL)animated 58 | { 59 | [super viewWillDisappear:animated]; 60 | } 61 | 62 | - (void)viewDidDisappear:(BOOL)animated 63 | { 64 | [super viewDidDisappear:animated]; 65 | } 66 | 67 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 68 | { 69 | switch (interfaceOrientation) { 70 | case UIInterfaceOrientationPortrait: 71 | case UIInterfaceOrientationPortraitUpsideDown: 72 | return YES; 73 | default: 74 | break; 75 | } 76 | return NO; 77 | } 78 | - (BOOL)textFieldShouldReturn:(UITextField*)theTextField { 79 | if (theTextField == self.theSeed) { 80 | [theTextField resignFirstResponder]; 81 | } 82 | return YES; 83 | } 84 | - (IBAction)startTest:(id)sender { 85 | if (self.inTest) { 86 | return; 87 | } 88 | self.inTest = YES; 89 | NSString *seedString = self.theSeed.text; 90 | if ([seedString length] == 0) { 91 | seedString = @"RFC3284"; 92 | } 93 | static_ptr = self; 94 | xprintf_message_func = &print_to_view; 95 | self.theOutput = [[NSMutableString alloc] initWithFormat:@"Starting test (seed=%@)\n", seedString]; 96 | self.theView.text = self.theOutput; 97 | dispatch_queue_t mq = dispatch_get_main_queue(); 98 | dispatch_queue_t dq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 99 | dispatch_async(dq, ^{ 100 | do_localfile_test(); 101 | char *argv[] = { "xdelta3", "test", NULL }; 102 | xd3_main_cmdline(2, argv); 103 | print_to_view("Finished unittest: success"); 104 | dispatch_async(mq, ^{ 105 | self.inTest = NO; 106 | }); 107 | }); 108 | } 109 | 110 | void printns_to_view(NSString* ns); 111 | void printns_to_view(NSString* ns) { 112 | dispatch_queue_t mq = dispatch_get_main_queue(); 113 | dispatch_async(mq, ^{ 114 | if ([static_ptr.theOutput length] < 25000) { 115 | [static_ptr.theOutput appendString:ns]; 116 | } else { 117 | static_ptr.theOutput = [[NSMutableString alloc] initWithString:ns]; 118 | } 119 | static_ptr.theView.text = static_ptr.theOutput; 120 | CGSize size = static_ptr.theView.contentSize; 121 | [static_ptr.theView scrollRectToVisible:CGRectMake(0, size.height - 1, 1, 1) animated:NO]; 122 | }); 123 | } 124 | 125 | void print_to_view(const char* buf) { 126 | NSString *ns = [NSString stringWithCString:buf encoding:NSASCIIStringEncoding]; 127 | printns_to_view(ns); 128 | } 129 | 130 | void do_localfile_test(void) { 131 | NSBundle *bundle; 132 | bundle = [NSBundle mainBundle]; 133 | NSString *localfile1 = [bundle pathForResource:@"file_v1" ofType:@"bin"]; 134 | NSString *localfile2 = [bundle pathForResource:@"file_v2" ofType:@"bin"]; 135 | NSString *localfiled = [bundle pathForResource:@"file_v1_to_v2" ofType:@"bin"]; 136 | printns_to_view([localfile1 stringByAppendingString:@"\n"]); 137 | printns_to_view([localfile2 stringByAppendingString:@"\n"]); 138 | printns_to_view([localfiled stringByAppendingString:@"\n"]); 139 | NSString *tmpdir = NSTemporaryDirectory(); 140 | NSString *tmpfile = [tmpdir stringByAppendingPathComponent:@"delta.tmp"]; 141 | printns_to_view([tmpfile stringByAppendingString:@"\n"]); 142 | char *argv[] = { 143 | "xdelta3", "-dfvv", "-s", 144 | (char*)[localfile1 UTF8String], 145 | (char*)[localfiled UTF8String], 146 | (char*)[tmpfile UTF8String] }; 147 | xd3_main_cmdline(6, argv); 148 | 149 | NSFileManager *filemgr; 150 | 151 | filemgr = [NSFileManager defaultManager]; 152 | 153 | if ([filemgr contentsEqualAtPath: localfile2 andPath: tmpfile] == YES) { 154 | printns_to_view(@"File contents match\n"); 155 | } else { 156 | NSError *err1 = NULL; 157 | NSDictionary *d1 = [filemgr attributesOfItemAtPath: tmpfile error: &err1]; 158 | if (err1 != NULL) { 159 | printns_to_view([@"File localfile2 could not stat %s\n" stringByAppendingString: tmpfile]); 160 | } else { 161 | printns_to_view([@"File contents do not match!!!! tmpfile size=" stringByAppendingString: 162 | [[NSMutableString alloc] initWithFormat:@"%llu\n", [d1 fileSize]]]); 163 | } 164 | compare_files([localfile2 UTF8String], [tmpfile UTF8String]); 165 | } 166 | print_to_view("Finished localfile test.\n"); 167 | } 168 | 169 | @end 170 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/en.lproj/MainStoryboard_iPad.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 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 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/en.lproj/MainStoryboard_iPhone.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/file_v1_to_v2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/file_v1_to_v2.bin -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // xdelta3-ios-test 4 | // 5 | // Created by Joshua MacDonald on 6/16/12. 6 | // Copyright (c) 2011, 2012 Joshua MacDonald. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "Xd3iOSAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([Xd3iOSAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/xdelta3-ios-test-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFiles 12 | 13 | CFBundleIdentifier 14 | Joshua-MacDonald.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | UIMainStoryboardFile 30 | MainStoryboard_iPhone 31 | UIMainStoryboardFile~ipad 32 | MainStoryboard_iPad 33 | UIRequiredDeviceCapabilities 34 | 35 | armv7 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | UIInterfaceOrientationPortraitUpsideDown 43 | 44 | UISupportedInterfaceOrientations~ipad 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationPortraitUpsideDown 48 | UIInterfaceOrientationLandscapeLeft 49 | UIInterfaceOrientationLandscapeRight 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/iOS/xdelta3-ios-test/xdelta3-ios-test/xdelta3-ios-test-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'xdelta3-ios-test' target in the 'xdelta3-ios-test' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/small_page_test.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Josh MacDonald */ 2 | 3 | #include 4 | 5 | #define PAGE_SIZE 4096 6 | 7 | #define SPACE_MAX 131072 // how much memory per process 8 | #define OUTPUT_MAX 1024 // max size for output 9 | #define XD3_ALLOCSIZE 256 // internal size for various buffers 10 | #define IOPT_SIZE 128 // instruction buffer 11 | 12 | // SPACE_MAX of 32K is sufficient for most inputs with XD3_COMPLEVEL_1 13 | // XD3_COMPLEVEL_9 requires about 4x more space than XD3_COMPLEVEL_1 14 | 15 | #include "xdelta3.h" 16 | #include "xdelta3.c" 17 | 18 | typedef struct _context { 19 | uint8_t *buffer; 20 | int allocated; 21 | } context_t; 22 | 23 | static int max_allocated = 0; 24 | 25 | void* 26 | process_alloc (void* opaque, usize_t items, usize_t size) 27 | { 28 | context_t *ctx = (context_t*) opaque; 29 | usize_t t = items * size; 30 | void *ret; 31 | 32 | if (ctx->allocated + t > SPACE_MAX) 33 | { 34 | return NULL; 35 | } 36 | 37 | ret = ctx->buffer + ctx->allocated; 38 | ctx->allocated += t; 39 | return ret; 40 | } 41 | 42 | void 43 | process_free (void* opaque, void *ptr) 44 | { 45 | } 46 | 47 | int 48 | process_page (int is_encode, 49 | int (*func) (xd3_stream *), 50 | const uint8_t *input, 51 | usize_t input_size, 52 | const uint8_t *source, 53 | uint8_t *output, 54 | usize_t *output_size, 55 | usize_t output_size_max, 56 | int flags) { 57 | 58 | /* On my x86 this is 1072 of objects on the stack */ 59 | xd3_stream stream; 60 | xd3_config config; 61 | xd3_source src; 62 | context_t *ctx = calloc(SPACE_MAX, 1); 63 | int ret; 64 | 65 | memset (&config, 0, sizeof(config)); 66 | 67 | if (ctx == NULL) 68 | { 69 | printf("calloc failed\n"); 70 | return -1; 71 | } 72 | 73 | ctx->buffer = (uint8_t*)ctx; 74 | ctx->allocated = sizeof(*ctx); 75 | 76 | config.flags = flags; 77 | config.winsize = PAGE_SIZE; 78 | config.sprevsz = PAGE_SIZE; 79 | config.srcwin_maxsz = PAGE_SIZE; 80 | config.iopt_size = IOPT_SIZE; 81 | config.alloc = &process_alloc; 82 | config.freef = &process_free; 83 | config.opaque = (void*) ctx; 84 | 85 | src.blksize = PAGE_SIZE; 86 | src.onblk = PAGE_SIZE; 87 | src.curblk = source; 88 | src.curblkno = 0; 89 | 90 | if ((ret = xd3_config_stream (&stream, &config)) != 0 || 91 | (ret = xd3_set_source_and_size (&stream, &src, PAGE_SIZE)) != 0 || 92 | (ret = xd3_process_stream (is_encode, 93 | &stream, 94 | func, 1, 95 | input, input_size, 96 | output, output_size, 97 | output_size_max)) != 0) 98 | { 99 | if (stream.msg != NULL) 100 | { 101 | fprintf(stderr, "stream message: %s\n", stream.msg); 102 | } 103 | } 104 | 105 | xd3_free_stream (&stream); 106 | if (max_allocated < ctx->allocated) 107 | { 108 | max_allocated = ctx->allocated; 109 | fprintf(stderr, "max allocated %d\n", max_allocated); 110 | } 111 | 112 | free(ctx); 113 | return ret; 114 | } 115 | 116 | int test(int stride, int encode_flags) 117 | { 118 | uint8_t frompg[PAGE_SIZE]; 119 | uint8_t topg[PAGE_SIZE]; 120 | uint8_t output[OUTPUT_MAX]; 121 | uint8_t reout[PAGE_SIZE]; 122 | usize_t output_size; 123 | usize_t re_size; 124 | int i, j, ret; 125 | 126 | for (i = 0; i < PAGE_SIZE; i++) 127 | { 128 | topg[i] = frompg[i] = (rand() >> 3 ^ rand() >> 6 ^ rand() >> 9); 129 | } 130 | 131 | // change 1 byte every stride 132 | if (stride > 0) 133 | { 134 | for (j = stride; j <= PAGE_SIZE; j += stride) 135 | { 136 | topg[j - 1] ^= 0xff; 137 | } 138 | } 139 | 140 | if ((ret = process_page (1, xd3_encode_input, 141 | topg, PAGE_SIZE, 142 | frompg, output, 143 | &output_size, OUTPUT_MAX, 144 | encode_flags)) != 0) 145 | { 146 | fprintf (stderr, "encode failed: stride %u flags 0x%x\n", 147 | stride, encode_flags); 148 | return ret; 149 | } 150 | 151 | if ((ret = process_page (0, xd3_decode_input, 152 | output, output_size, 153 | frompg, reout, 154 | &re_size, PAGE_SIZE, 155 | 0)) != 0) 156 | { 157 | fprintf (stderr, "decode failed: stride %u output_size %u flags 0x%x\n", 158 | stride, output_size, encode_flags); 159 | return ret; 160 | } 161 | 162 | if (output_size > OUTPUT_MAX || re_size != PAGE_SIZE) 163 | { 164 | fprintf (stderr, "internal error: %u != %u\n", output_size, re_size); 165 | return -1; 166 | } 167 | 168 | for (i = 0; i < PAGE_SIZE; i++) 169 | { 170 | if (reout[i] != topg[i]) 171 | { 172 | fprintf (stderr, "encode-decode error: position %d\n", i); 173 | return -1; 174 | } 175 | } 176 | 177 | fprintf(stderr, "stride %d flags 0x%x size %u ", 178 | stride, encode_flags, output_size); 179 | fprintf(stderr, "%s\n", (ret == 0) ? "OK" : "FAIL"); 180 | 181 | return 0; 182 | } 183 | 184 | int main() 185 | { 186 | int stride; 187 | int level; 188 | 189 | for (level = 1; level < 10; level = (level == 1 ? 3 : level + 3)) 190 | { 191 | int lflag = level << XD3_COMPLEVEL_SHIFT; 192 | 193 | for (stride = 2; stride <= PAGE_SIZE; stride += 2) 194 | { 195 | test(stride, lflag); 196 | test(stride, lflag | XD3_SEC_DJW); 197 | } 198 | } 199 | 200 | return 0; 201 | } 202 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/speed_test.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Josh MacDonald */ 2 | 3 | #include "test.h" 4 | 5 | usize_t bench_speed(const uint8_t *from_buf, const size_t from_len, 6 | const uint8_t *to_buf, const size_t to_len, 7 | uint8_t *delta_buf, const size_t delta_alloc, 8 | int flags) { 9 | usize_t delta_size; 10 | int ret = xd3_encode_memory(to_buf, to_len, from_buf, from_len, 11 | delta_buf, &delta_size, delta_alloc, flags); 12 | if (ret != 0) { 13 | fprintf(stderr, "encode failure: %d: %s\n", ret, xd3_strerror(ret)); 14 | abort(); 15 | } 16 | return delta_size; 17 | } 18 | 19 | int main(int argc, char **argv) { 20 | int repeat, level; 21 | char *from, *to; 22 | uint8_t *from_buf = NULL, *to_buf = NULL, *delta_buf = NULL; 23 | size_t from_len = 0, to_len, delta_alloc, delta_size = 0; 24 | long start, finish; 25 | int i, ret; 26 | int flags; 27 | 28 | if (argc != 5) { 29 | fprintf(stderr, "usage: speed_test LEVEL COUNT FROM TO\n"); 30 | return 1; 31 | } 32 | 33 | level = atoi(argv[1]); 34 | repeat = atoi(argv[2]); 35 | from = argv[3]; 36 | to = argv[4]; 37 | flags = (level << XD3_COMPLEVEL_SHIFT) & XD3_COMPLEVEL_MASK; 38 | 39 | if ((strcmp(from, "null") != 0 && 40 | (ret = read_whole_file(from, &from_buf, &from_len))) || 41 | (ret = read_whole_file(to, &to_buf, &to_len))) { 42 | fprintf(stderr, "read_whole_file error\n"); 43 | goto exit; 44 | } 45 | 46 | delta_alloc = to_len * 11 / 10; 47 | delta_buf = main_malloc(delta_alloc); 48 | 49 | start = get_millisecs_now(); 50 | 51 | for (i = 0; i < repeat; ++i) { 52 | delta_size = bench_speed(from_buf, from_len, 53 | to_buf, to_len, delta_buf, delta_alloc, flags); 54 | } 55 | 56 | finish = get_millisecs_now(); 57 | 58 | fprintf(stderr, 59 | "STAT: encode %3.2f ms from %s to %s repeat %d %zdbit delta %zd\n", 60 | (double)(finish - start) / repeat, from, to, repeat, sizeof (xoff_t) * 8, delta_size); 61 | 62 | ret = 0; 63 | 64 | if (0) { 65 | exit: 66 | ret = 1; 67 | } 68 | 69 | main_free(to_buf); 70 | main_free(from_buf); 71 | main_free(delta_buf); 72 | return ret; 73 | } 74 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/examples/test.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Josh MacDonald */ 2 | 3 | #define NOT_MAIN 1 4 | 5 | #include "xdelta3.h" 6 | #include "xdelta3.c" 7 | 8 | static int read_whole_file(const char *name, 9 | uint8_t **buf_ptr, 10 | size_t *buf_len) { 11 | main_file file; 12 | int ret; 13 | xoff_t len; 14 | usize_t nread; 15 | main_file_init(&file); 16 | file.filename = name; 17 | ret = main_file_open(&file, name, XO_READ); 18 | if (ret != 0) { 19 | fprintf(stderr, "open failed\n"); 20 | goto exit; 21 | } 22 | ret = main_file_stat(&file, &len); 23 | if (ret != 0) { 24 | fprintf(stderr, "stat failed\n"); 25 | goto exit; 26 | } 27 | 28 | (*buf_len) = (size_t)len; 29 | (*buf_ptr) = (uint8_t*) main_malloc(*buf_len); 30 | ret = main_file_read(&file, *buf_ptr, *buf_len, &nread, 31 | "read failed"); 32 | if (ret == 0 && *buf_len == nread) { 33 | ret = 0; 34 | } else { 35 | fprintf(stderr, "invalid read\n"); 36 | ret = XD3_INTERNAL; 37 | } 38 | exit: 39 | main_file_cleanup(&file); 40 | return ret; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/m4/ax_check_aligned_access_required.m4: -------------------------------------------------------------------------------- 1 | # ==================================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_aligned_access_required.html 3 | # ==================================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AC_CHECK_ALIGNED_ACCESS_REQUIRED 8 | # 9 | # DESCRIPTION 10 | # 11 | # While the x86 CPUs allow access to memory objects to be unaligned it 12 | # happens that most of the modern designs require objects to be aligned - 13 | # or they will fail with a buserror. That mode is quite known by 14 | # big-endian machines (sparc, etc) however the alpha cpu is little- 15 | # endian. 16 | # 17 | # The following function will test for aligned access to be required and 18 | # set a config.h define HAVE_ALIGNED_ACCESS_REQUIRED (name derived by 19 | # standard usage). Structures loaded from a file (or mmapped to memory) 20 | # should be accessed per-byte in that case to avoid segfault type errors. 21 | # 22 | # LICENSE 23 | # 24 | # Copyright (c) 2008 Guido U. Draheim 25 | # 26 | # This program is free software; you can redistribute it and/or modify it 27 | # under the terms of the GNU General Public License as published by the 28 | # Free Software Foundation; either version 3 of the License, or (at your 29 | # option) any later version. 30 | # 31 | # This program is distributed in the hope that it will be useful, but 32 | # WITHOUT ANY WARRANTY; without even the implied warranty of 33 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 34 | # Public License for more details. 35 | # 36 | # You should have received a copy of the GNU General Public License along 37 | # with this program. If not, see . 38 | # 39 | # As a special exception, the respective Autoconf Macro's copyright owner 40 | # gives unlimited permission to copy, distribute and modify the configure 41 | # scripts that are the output of Autoconf when processing the Macro. You 42 | # need not follow the terms of the GNU General Public License when using 43 | # or distributing such scripts, even though portions of the text of the 44 | # Macro appear in them. The GNU General Public License (GPL) does govern 45 | # all other use of the material that constitutes the Autoconf Macro. 46 | # 47 | # This special exception to the GPL applies to versions of the Autoconf 48 | # Macro released by the Autoconf Archive. When you make and distribute a 49 | # modified version of the Autoconf Macro, you may extend this special 50 | # exception to the GPL to apply to your modified version as well. 51 | 52 | #serial 7 53 | 54 | AC_DEFUN([AX_CHECK_ALIGNED_ACCESS_REQUIRED], 55 | [AC_CACHE_CHECK([if pointers to integers require aligned access], 56 | [ax_cv_have_aligned_access_required], 57 | [AC_TRY_RUN([ 58 | #include 59 | #include 60 | 61 | int main() 62 | { 63 | char* string = malloc(40); 64 | int i; 65 | for (i=0; i < 40; i++) string[[i]] = i; 66 | { 67 | void* s = string; 68 | int* p = s+1; 69 | int* q = s+2; 70 | 71 | if (*p == *q) { return 1; } 72 | } 73 | return 0; 74 | } 75 | ], 76 | [ax_cv_have_aligned_access_required=yes], 77 | [ax_cv_have_aligned_access_required=no], 78 | [ax_cv_have_aligned_access_required=no]) 79 | ]) 80 | if test "$ax_cv_have_aligned_access_required" = yes ; then 81 | AC_DEFINE([HAVE_ALIGNED_ACCESS_REQUIRED], [1], 82 | [Define if pointers to integers require aligned access]) 83 | fi 84 | ]) 85 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common stub for a few missing GNU programs while installing. 3 | 4 | scriptversion=2012-01-06.13; # UTC 5 | 6 | # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 7 | # 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. 8 | # Originally by Fran,cois Pinard , 1996. 9 | 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | if test $# -eq 0; then 29 | echo 1>&2 "Try \`$0 --help' for more information" 30 | exit 1 31 | fi 32 | 33 | run=: 34 | sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' 35 | sed_minuso='s/.* -o \([^ ]*\).*/\1/p' 36 | 37 | # In the cases where this matters, `missing' is being run in the 38 | # srcdir already. 39 | if test -f configure.ac; then 40 | configure_ac=configure.ac 41 | else 42 | configure_ac=configure.in 43 | fi 44 | 45 | msg="missing on your system" 46 | 47 | case $1 in 48 | --run) 49 | # Try to run requested program, and just exit if it succeeds. 50 | run= 51 | shift 52 | "$@" && exit 0 53 | # Exit code 63 means version mismatch. This often happens 54 | # when the user try to use an ancient version of a tool on 55 | # a file that requires a minimum version. In this case we 56 | # we should proceed has if the program had been absent, or 57 | # if --run hadn't been passed. 58 | if test $? = 63; then 59 | run=: 60 | msg="probably too old" 61 | fi 62 | ;; 63 | 64 | -h|--h|--he|--hel|--help) 65 | echo "\ 66 | $0 [OPTION]... PROGRAM [ARGUMENT]... 67 | 68 | Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an 69 | error status if there is no known handling for PROGRAM. 70 | 71 | Options: 72 | -h, --help display this help and exit 73 | -v, --version output version information and exit 74 | --run try to run the given command, and emulate it if it fails 75 | 76 | Supported PROGRAM values: 77 | aclocal touch file \`aclocal.m4' 78 | autoconf touch file \`configure' 79 | autoheader touch file \`config.h.in' 80 | autom4te touch the output file, or create a stub one 81 | automake touch all \`Makefile.in' files 82 | bison create \`y.tab.[ch]', if possible, from existing .[ch] 83 | flex create \`lex.yy.c', if possible, from existing .c 84 | help2man touch the output file 85 | lex create \`lex.yy.c', if possible, from existing .c 86 | makeinfo touch the output file 87 | yacc create \`y.tab.[ch]', if possible, from existing .[ch] 88 | 89 | Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and 90 | \`g' are ignored when checking the name. 91 | 92 | Send bug reports to ." 93 | exit $? 94 | ;; 95 | 96 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 97 | echo "missing $scriptversion (GNU Automake)" 98 | exit $? 99 | ;; 100 | 101 | -*) 102 | echo 1>&2 "$0: Unknown \`$1' option" 103 | echo 1>&2 "Try \`$0 --help' for more information" 104 | exit 1 105 | ;; 106 | 107 | esac 108 | 109 | # normalize program name to check for. 110 | program=`echo "$1" | sed ' 111 | s/^gnu-//; t 112 | s/^gnu//; t 113 | s/^g//; t'` 114 | 115 | # Now exit if we have it, but it failed. Also exit now if we 116 | # don't have it and --version was passed (most likely to detect 117 | # the program). This is about non-GNU programs, so use $1 not 118 | # $program. 119 | case $1 in 120 | lex*|yacc*) 121 | # Not GNU programs, they don't have --version. 122 | ;; 123 | 124 | *) 125 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 126 | # We have it, but it failed. 127 | exit 1 128 | elif test "x$2" = "x--version" || test "x$2" = "x--help"; then 129 | # Could not run --version or --help. This is probably someone 130 | # running `$TOOL --version' or `$TOOL --help' to check whether 131 | # $TOOL exists and not knowing $TOOL uses missing. 132 | exit 1 133 | fi 134 | ;; 135 | esac 136 | 137 | # If it does not exist, or fails to run (possibly an outdated version), 138 | # try to emulate it. 139 | case $program in 140 | aclocal*) 141 | echo 1>&2 "\ 142 | WARNING: \`$1' is $msg. You should only need it if 143 | you modified \`acinclude.m4' or \`${configure_ac}'. You might want 144 | to install the \`Automake' and \`Perl' packages. Grab them from 145 | any GNU archive site." 146 | touch aclocal.m4 147 | ;; 148 | 149 | autoconf*) 150 | echo 1>&2 "\ 151 | WARNING: \`$1' is $msg. You should only need it if 152 | you modified \`${configure_ac}'. You might want to install the 153 | \`Autoconf' and \`GNU m4' packages. Grab them from any GNU 154 | archive site." 155 | touch configure 156 | ;; 157 | 158 | autoheader*) 159 | echo 1>&2 "\ 160 | WARNING: \`$1' is $msg. You should only need it if 161 | you modified \`acconfig.h' or \`${configure_ac}'. You might want 162 | to install the \`Autoconf' and \`GNU m4' packages. Grab them 163 | from any GNU archive site." 164 | files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` 165 | test -z "$files" && files="config.h" 166 | touch_files= 167 | for f in $files; do 168 | case $f in 169 | *:*) touch_files="$touch_files "`echo "$f" | 170 | sed -e 's/^[^:]*://' -e 's/:.*//'`;; 171 | *) touch_files="$touch_files $f.in";; 172 | esac 173 | done 174 | touch $touch_files 175 | ;; 176 | 177 | automake*) 178 | echo 1>&2 "\ 179 | WARNING: \`$1' is $msg. You should only need it if 180 | you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. 181 | You might want to install the \`Automake' and \`Perl' packages. 182 | Grab them from any GNU archive site." 183 | find . -type f -name Makefile.am -print | 184 | sed 's/\.am$/.in/' | 185 | while read f; do touch "$f"; done 186 | ;; 187 | 188 | autom4te*) 189 | echo 1>&2 "\ 190 | WARNING: \`$1' is needed, but is $msg. 191 | You might have modified some files without having the 192 | proper tools for further handling them. 193 | You can get \`$1' as part of \`Autoconf' from any GNU 194 | archive site." 195 | 196 | file=`echo "$*" | sed -n "$sed_output"` 197 | test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` 198 | if test -f "$file"; then 199 | touch $file 200 | else 201 | test -z "$file" || exec >$file 202 | echo "#! /bin/sh" 203 | echo "# Created by GNU Automake missing as a replacement of" 204 | echo "# $ $@" 205 | echo "exit 0" 206 | chmod +x $file 207 | exit 1 208 | fi 209 | ;; 210 | 211 | bison*|yacc*) 212 | echo 1>&2 "\ 213 | WARNING: \`$1' $msg. You should only need it if 214 | you modified a \`.y' file. You may need the \`Bison' package 215 | in order for those modifications to take effect. You can get 216 | \`Bison' from any GNU archive site." 217 | rm -f y.tab.c y.tab.h 218 | if test $# -ne 1; then 219 | eval LASTARG=\${$#} 220 | case $LASTARG in 221 | *.y) 222 | SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` 223 | if test -f "$SRCFILE"; then 224 | cp "$SRCFILE" y.tab.c 225 | fi 226 | SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` 227 | if test -f "$SRCFILE"; then 228 | cp "$SRCFILE" y.tab.h 229 | fi 230 | ;; 231 | esac 232 | fi 233 | if test ! -f y.tab.h; then 234 | echo >y.tab.h 235 | fi 236 | if test ! -f y.tab.c; then 237 | echo 'main() { return 0; }' >y.tab.c 238 | fi 239 | ;; 240 | 241 | lex*|flex*) 242 | echo 1>&2 "\ 243 | WARNING: \`$1' is $msg. You should only need it if 244 | you modified a \`.l' file. You may need the \`Flex' package 245 | in order for those modifications to take effect. You can get 246 | \`Flex' from any GNU archive site." 247 | rm -f lex.yy.c 248 | if test $# -ne 1; then 249 | eval LASTARG=\${$#} 250 | case $LASTARG in 251 | *.l) 252 | SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` 253 | if test -f "$SRCFILE"; then 254 | cp "$SRCFILE" lex.yy.c 255 | fi 256 | ;; 257 | esac 258 | fi 259 | if test ! -f lex.yy.c; then 260 | echo 'main() { return 0; }' >lex.yy.c 261 | fi 262 | ;; 263 | 264 | help2man*) 265 | echo 1>&2 "\ 266 | WARNING: \`$1' is $msg. You should only need it if 267 | you modified a dependency of a manual page. You may need the 268 | \`Help2man' package in order for those modifications to take 269 | effect. You can get \`Help2man' from any GNU archive site." 270 | 271 | file=`echo "$*" | sed -n "$sed_output"` 272 | test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` 273 | if test -f "$file"; then 274 | touch $file 275 | else 276 | test -z "$file" || exec >$file 277 | echo ".ab help2man is required to generate this page" 278 | exit $? 279 | fi 280 | ;; 281 | 282 | makeinfo*) 283 | echo 1>&2 "\ 284 | WARNING: \`$1' is $msg. You should only need it if 285 | you modified a \`.texi' or \`.texinfo' file, or any other file 286 | indirectly affecting the aspect of the manual. The spurious 287 | call might also be the consequence of using a buggy \`make' (AIX, 288 | DU, IRIX). You might want to install the \`Texinfo' package or 289 | the \`GNU make' package. Grab either from any GNU archive site." 290 | # The file to touch is that specified with -o ... 291 | file=`echo "$*" | sed -n "$sed_output"` 292 | test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` 293 | if test -z "$file"; then 294 | # ... or it is the one specified with @setfilename ... 295 | infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` 296 | file=`sed -n ' 297 | /^@setfilename/{ 298 | s/.* \([^ ]*\) *$/\1/ 299 | p 300 | q 301 | }' $infile` 302 | # ... or it is derived from the source name (dir/f.texi becomes f.info) 303 | test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info 304 | fi 305 | # If the file does not exist, the user really needs makeinfo; 306 | # let's fail without touching anything. 307 | test -f $file || exit 1 308 | touch $file 309 | ;; 310 | 311 | *) 312 | echo 1>&2 "\ 313 | WARNING: \`$1' is needed, and is $msg. 314 | You might have modified some files without having the 315 | proper tools for further handling them. Check the \`README' file, 316 | it often tells you about the needed prerequisites for installing 317 | this package. You may also peek at any GNU archive site, in case 318 | some other package would contain this missing \`$1' program." 319 | exit 1 320 | ;; 321 | esac 322 | 323 | exit 0 324 | 325 | # Local variables: 326 | # eval: (add-hook 'write-file-hooks 'time-stamp) 327 | # time-stamp-start: "scriptversion=" 328 | # time-stamp-format: "%:y-%02m-%02d.%02H" 329 | # time-stamp-time-zone: "UTC" 330 | # time-stamp-end: "; # UTC" 331 | # End: 332 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/cmp.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++ -*- */ 2 | static size_t CmpDifferentBlockBytes(const Block &a, const Block &b) { 3 | size_t total = 0; 4 | size_t i = 0; 5 | size_t m = min(a.Size(), b.Size()); 6 | 7 | for (; i < m; i++) { 8 | if (a[i] != b[i]) { 9 | total++; 10 | } 11 | } 12 | 13 | total += a.Size() - i; 14 | total += b.Size() - i; 15 | 16 | return total; 17 | } 18 | 19 | static xoff_t CmpDifferentBytes(const FileSpec &a, const FileSpec &b) { 20 | Block block_a, block_b; 21 | xoff_t total = 0; 22 | typename FileSpec::iterator a_i(a), b_i(b); 23 | 24 | for (; !a_i.Done() && !b_i.Done(); a_i.Next(), b_i.Next()) { 25 | 26 | a_i.Get(&block_a); 27 | b_i.Get(&block_b); 28 | 29 | total += CmpDifferentBlockBytes(block_a, block_b); 30 | } 31 | 32 | for (; !a_i.Done(); a_i.Next()) { 33 | total += a_i.BytesOnBlock(); 34 | } 35 | for (; !b_i.Done(); b_i.Next()) { 36 | total += b_i.BytesOnBlock(); 37 | } 38 | 39 | return total; 40 | } 41 | 42 | static size_t CmpDifferentBlockBytesAtOffset(const Block &a, 43 | const FileSpec &b_spec, 44 | xoff_t offset) { 45 | Block b; 46 | size_t size = a.Size(); 47 | CHECK_LE(offset, b_spec.Size()); 48 | if (b_spec.Size() < offset + size) { 49 | size = b_spec.Size() - offset; 50 | } 51 | b_spec.Get(&b, offset, size); 52 | return CmpDifferentBlockBytes(a, b); 53 | } 54 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/delta.h: -------------------------------------------------------------------------------- 1 | // Mode: -*- C++ -*- 2 | 3 | class Delta { 4 | public: 5 | Delta(const Block &block) { 6 | int ret; 7 | xd3_config config; 8 | memset(&stream_, 0, sizeof (stream_)); 9 | memset(&config, 0, sizeof (config)); 10 | 11 | xd3_init_config(&config, XD3_SKIP_EMIT | XD3_ADLER32_NOVER); 12 | 13 | CHECK_EQ(0, xd3_config_stream (&stream_, &config)); 14 | 15 | xd3_avail_input (&stream_, block.Data(), block.Size()); 16 | 17 | bool done = false; 18 | while (!done) { 19 | ret = xd3_decode_input(&stream_); 20 | 21 | switch (ret) { 22 | case XD3_INPUT: 23 | done = true; 24 | break; 25 | case XD3_OUTPUT: 26 | CHECK_EQ(0, xd3_whole_append_window (&stream_)); 27 | break; 28 | case XD3_GOTHEADER: 29 | case XD3_WINSTART: 30 | case XD3_WINFINISH: 31 | break; 32 | default: 33 | DP(RINT "error code %s\n", xd3_strerror (ret)); 34 | abort(); 35 | } 36 | } 37 | } 38 | 39 | ~Delta() { 40 | xd3_free_stream(&stream_); 41 | } 42 | 43 | xoff_t AddedBytes() const { 44 | return stream_.whole_target.addslen; 45 | } 46 | 47 | xoff_t Windows() const { 48 | return stream_.whole_target.wininfolen; 49 | } 50 | 51 | void Print() const { 52 | for (size_t i = 0; i < stream_.whole_target.instlen; i++) { 53 | xd3_winst &winst = stream_.whole_target.inst[i]; 54 | switch (winst.type) { 55 | case XD3_RUN: 56 | DP(RINT "%"Q"u run %u\n", winst.position, winst.size); 57 | break; 58 | case XD3_ADD: 59 | DP(RINT "%"Q"u add %u\n", winst.position, winst.size); 60 | break; 61 | default: 62 | DP(RINT "%"Q"u copy %u @ %"Q"u (mode %u)\n", 63 | winst.position, winst.size, winst.addr, winst.mode); 64 | break; 65 | } 66 | } 67 | } 68 | 69 | private: 70 | xd3_stream stream_; 71 | }; 72 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/file.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++ -*- */ 2 | class Block; 3 | class BlockIterator; 4 | class TmpFile; 5 | 6 | class Block { 7 | public: 8 | Block() 9 | : data_(NULL), 10 | data_size_(0), 11 | size_(0) { } 12 | 13 | ~Block() { 14 | if (data_) { 15 | delete [] data_; 16 | } 17 | } 18 | 19 | size_t Size() const { 20 | return size_; 21 | } 22 | 23 | uint8_t operator[](size_t i) const { 24 | CHECK_LT(i, size_); 25 | return data_[i]; 26 | } 27 | 28 | uint8_t* Data() const { 29 | if (data_ == NULL) { 30 | CHECK_EQ(0, size_); 31 | data_size_ = 1; 32 | data_ = new uint8_t[1]; 33 | } 34 | return data_; 35 | } 36 | 37 | // For writing to blocks 38 | void Append(const uint8_t *data, size_t size) { 39 | if (data_ == NULL) { 40 | CHECK_EQ(0, size_); 41 | CHECK_EQ(0, data_size_); 42 | data_ = new uint8_t[Constants::BLOCK_SIZE]; 43 | data_size_ = Constants::BLOCK_SIZE; 44 | } 45 | 46 | if (size_ + size > data_size_) { 47 | uint8_t *tmp = data_; 48 | while (size_ + size > data_size_) { 49 | data_size_ *= 2; 50 | } 51 | data_ = new uint8_t[data_size_]; 52 | memcpy(data_, tmp, size_); 53 | delete tmp; 54 | } 55 | 56 | memcpy(data_ + size_, data, size); 57 | size_ += size; 58 | } 59 | 60 | // For cleaing a block 61 | void Reset() { 62 | size_ = 0; 63 | } 64 | 65 | void Print() const { 66 | xoff_t pos = 0; 67 | for (size_t i = 0; i < Size(); i++) { 68 | if (pos % 16 == 0) { 69 | DP(RINT "%5"Q"x: ", pos); 70 | } 71 | DP(RINT "%02x ", (*this)[i]); 72 | if (pos % 16 == 15) { 73 | DP(RINT "\n"); 74 | } 75 | pos++; 76 | } 77 | DP(RINT "\n"); 78 | } 79 | 80 | void WriteTmpFile(TmpFile *f) const { 81 | f->Append(this); 82 | } 83 | 84 | void SetSize(size_t size) { 85 | size_ = size; 86 | 87 | if (data_size_ < size) { 88 | if (data_) { 89 | delete [] data_; 90 | } 91 | data_ = new uint8_t[size]; 92 | data_size_ = size; 93 | } 94 | } 95 | private: 96 | friend class BlockIterator; 97 | 98 | mutable uint8_t *data_; 99 | mutable size_t data_size_; 100 | size_t size_; 101 | }; 102 | 103 | class FileSpec { 104 | public: 105 | FileSpec(MTRandom *rand) 106 | : rand_(rand) { 107 | } 108 | 109 | // Generates a file with a known size 110 | void GenerateFixedSize(xoff_t size) { 111 | Reset(); 112 | 113 | for (xoff_t p = 0; p < size; ) { 114 | xoff_t t = min(Constants::BLOCK_SIZE, size - p); 115 | table_.insert(make_pair(p, Segment(t, rand_))); 116 | p += t; 117 | } 118 | } 119 | 120 | // Generates a file with exponential-random distributed size 121 | void GenerateRandomSize(xoff_t mean) { 122 | GenerateFixedSize(rand_->ExpRand(mean)); 123 | } 124 | 125 | // Returns the size of the file 126 | xoff_t Size() const { 127 | if (table_.empty()) { 128 | return 0; 129 | } 130 | ConstSegmentMapIterator i = --table_.end(); 131 | return i->first + i->second.Size(); 132 | } 133 | 134 | // Returns the number of blocks 135 | xoff_t Blocks(size_t blksize = Constants::BLOCK_SIZE) const { 136 | if (table_.empty()) { 137 | return 0; 138 | } 139 | return ((Size() - 1) / blksize) + 1; 140 | } 141 | 142 | // Returns the number of segments 143 | xoff_t Segments() const { 144 | return table_.size(); 145 | } 146 | 147 | // Create a mutation according to "what". 148 | void ModifyTo(const Mutator &mutator, 149 | FileSpec *modify) const { 150 | modify->Reset(); 151 | mutator.Mutate(&modify->table_, &table_, rand_); 152 | modify->CheckSegments(); 153 | } 154 | 155 | void CheckSegments() const { 156 | for (ConstSegmentMapIterator iter(table_.begin()); 157 | iter != table_.end(); ) { 158 | ConstSegmentMapIterator iter0(iter++); 159 | if (iter == table_.end()) { 160 | break; 161 | } 162 | CHECK_EQ(iter0->first + iter0->second.Size(), iter->first); 163 | } 164 | } 165 | 166 | void Reset() { 167 | table_.clear(); 168 | } 169 | 170 | void Print() const { 171 | for (ConstSegmentMapIterator iter(table_.begin()); 172 | iter != table_.end(); 173 | ++iter) { 174 | const Segment &seg = iter->second; 175 | cerr << "Segment at " << iter->first 176 | << " (" << seg.ToString() << ")" << endl; 177 | } 178 | } 179 | 180 | void PrintData() const { 181 | Block block; 182 | for (BlockIterator iter(*this); !iter.Done(); iter.Next()) { 183 | iter.Get(&block); 184 | block.Print(); 185 | } 186 | } 187 | 188 | void WriteTmpFile(TmpFile *f) const { 189 | Block block; 190 | for (BlockIterator iter(*this); !iter.Done(); iter.Next()) { 191 | iter.Get(&block); 192 | f->Append(&block); 193 | } 194 | } 195 | 196 | void Get(Block *block, xoff_t offset, size_t size) const { 197 | size_t got = 0; 198 | block->SetSize(size); 199 | 200 | ConstSegmentMapIterator pos = table_.upper_bound(offset); 201 | if (pos == table_.begin()) { 202 | CHECK_EQ(0, Size()); 203 | return; 204 | } 205 | --pos; 206 | 207 | while (got < size) { 208 | CHECK(pos != table_.end()); 209 | CHECK_GE(offset, pos->first); 210 | 211 | const Segment &seg = pos->second; 212 | 213 | // The position of this segment may start before this block starts, 214 | // and then the position of the data may be offset from the seeding 215 | // position. 216 | size_t seg_offset = offset - pos->first; 217 | size_t advance = min(seg.Size() - seg_offset, 218 | size - got); 219 | 220 | seg.Fill(seg_offset, advance, block->Data() + got); 221 | 222 | got += advance; 223 | offset += advance; 224 | ++pos; 225 | } 226 | } 227 | 228 | typedef BlockIterator iterator; 229 | 230 | private: 231 | friend class BlockIterator; 232 | 233 | MTRandom *rand_; 234 | SegmentMap table_; 235 | }; 236 | 237 | class BlockIterator { 238 | public: 239 | explicit BlockIterator(const FileSpec& spec) 240 | : spec_(spec), 241 | blkno_(0), 242 | blksize_(Constants::BLOCK_SIZE) { } 243 | 244 | BlockIterator(const FileSpec& spec, 245 | size_t blksize) 246 | : spec_(spec), 247 | blkno_(0), 248 | blksize_(blksize) { } 249 | 250 | bool Done() const { 251 | return blkno_ >= spec_.Blocks(blksize_); 252 | } 253 | 254 | void Next() { 255 | blkno_++; 256 | } 257 | 258 | xoff_t Blkno() const { 259 | return blkno_; 260 | } 261 | 262 | xoff_t Blocks() const { 263 | return spec_.Blocks(blksize_); 264 | } 265 | 266 | xoff_t Offset() const { 267 | return blkno_ * blksize_; 268 | } 269 | 270 | void SetBlock(xoff_t blkno) { 271 | blkno_ = blkno; 272 | } 273 | 274 | void Get(Block *block) const { 275 | spec_.Get(block, blkno_ * blksize_, BytesOnBlock()); 276 | } 277 | 278 | size_t BytesOnBlock() const { 279 | xoff_t blocks = spec_.Blocks(blksize_); 280 | xoff_t size = spec_.Size(); 281 | 282 | DCHECK((blkno_ < blocks) || 283 | (blkno_ == blocks && size % blksize_ == 0)); 284 | 285 | if (blkno_ == blocks) { 286 | return 0; 287 | } 288 | if (blkno_ + 1 == blocks) { 289 | return ((size - 1) % blksize_) + 1; 290 | } 291 | return blksize_; 292 | } 293 | 294 | size_t BlockSize() const { 295 | return blksize_; 296 | } 297 | 298 | private: 299 | const FileSpec& spec_; 300 | xoff_t blkno_; 301 | size_t blksize_; 302 | }; 303 | 304 | class ExtFile { 305 | public: 306 | ExtFile() { 307 | static int static_counter = 0; 308 | char buf[32]; 309 | snprintf(buf, 32, "/tmp/regtest.%d", static_counter++); 310 | filename_.append(buf); 311 | unlink(filename_.c_str()); 312 | } 313 | 314 | ~ExtFile() { 315 | unlink(filename_.c_str()); 316 | } 317 | 318 | const char* Name() const { 319 | return filename_.c_str(); 320 | } 321 | 322 | // Check whether a real file matches a file spec. 323 | bool EqualsSpec(const FileSpec &spec) const { 324 | main_file t; 325 | main_file_init(&t); 326 | CHECK_EQ(0, main_file_open(&t, Name(), XO_READ)); 327 | 328 | Block tblock; 329 | Block sblock; 330 | for (BlockIterator iter(spec); !iter.Done(); iter.Next()) { 331 | iter.Get(&sblock); 332 | tblock.SetSize(sblock.Size()); 333 | size_t tread; 334 | CHECK_EQ(0, main_file_read(&t, 335 | tblock.Data(), 336 | tblock.Size(), &tread, "read failed")); 337 | CHECK_EQ(0, CmpDifferentBlockBytes(tblock, sblock)); 338 | } 339 | 340 | CHECK_EQ(0, main_file_close(&t)); 341 | main_file_cleanup(&t); 342 | return true; 343 | } 344 | 345 | protected: 346 | string filename_; 347 | }; 348 | 349 | class TmpFile : public ExtFile { 350 | public: 351 | TmpFile() { 352 | main_file_init(&file_); 353 | CHECK_EQ(0, main_file_open(&file_, Name(), XO_WRITE)); 354 | } 355 | 356 | ~TmpFile() { 357 | main_file_cleanup(&file_); 358 | } 359 | 360 | void Append(const Block *block) { 361 | CHECK_EQ(0, main_file_write(&file_, 362 | block->Data(), block->Size(), 363 | "tmpfile write failed")); 364 | } 365 | 366 | const char* Name() const { 367 | if (main_file_isopen(&file_)) { 368 | CHECK_EQ(0, main_file_close(&file_)); 369 | } 370 | return ExtFile::Name(); 371 | } 372 | 373 | private: 374 | mutable main_file file_; 375 | }; 376 | 377 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/modify.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++ -*- 2 | class Mutator { 3 | public: 4 | virtual ~Mutator() { } 5 | virtual void Mutate(SegmentMap *table, 6 | const SegmentMap *source_table, 7 | MTRandom *rand) const = 0; 8 | }; 9 | 10 | class Change { 11 | public: 12 | enum Kind { 13 | MODIFY = 1, // Mutate a certain range w/ random or supplied data 14 | ADD = 2, // Insert random or supplied data 15 | DELETE = 3, // Delete a specified range of data 16 | COPY = 4, // Copy from one region, inserting elsewhere 17 | MOVE = 5, // Copy then delete copied-from range 18 | OVERWRITE = 6 // Copy then delete copied-to range 19 | 20 | // ADD, DELETE, and COPY change the file size 21 | // MODIFY, MOVE, OVERWRITE preserve the file size 22 | }; 23 | 24 | // Constructor for modify, add, delete. 25 | Change(Kind kind0, xoff_t size0, xoff_t addr1_0) 26 | : kind(kind0), 27 | size(size0), 28 | addr1(addr1_0), 29 | addr2(0), 30 | insert(NULL) { 31 | CHECK(kind != MOVE && kind != COPY && kind != OVERWRITE); 32 | } 33 | 34 | // Constructor for modify, add w/ provided data. 35 | Change(Kind kind0, xoff_t size0, xoff_t addr1_0, Segment *insert0) 36 | : kind(kind0), 37 | size(size0), 38 | addr1(addr1_0), 39 | addr2(0), 40 | insert(insert0) { 41 | CHECK(kind != MOVE && kind != COPY && kind != OVERWRITE); 42 | } 43 | 44 | // Constructor for move, copy, overwrite 45 | Change(Kind kind0, xoff_t size0, xoff_t addr1_0, xoff_t addr2_0) 46 | : kind(kind0), 47 | size(size0), 48 | addr1(addr1_0), 49 | addr2(addr2_0), 50 | insert(NULL) { 51 | CHECK(kind == MOVE || kind == COPY || kind == OVERWRITE); 52 | } 53 | 54 | Kind kind; 55 | xoff_t size; 56 | xoff_t addr1; 57 | xoff_t addr2; 58 | Segment *insert; // For modify and/or add 59 | }; 60 | 61 | typedef list ChangeList; 62 | typedef typename ChangeList::const_iterator ConstChangeListIterator; 63 | typedef typename ChangeList::iterator ChangeListIterator; 64 | 65 | class ChangeListMutator : public Mutator { 66 | public: 67 | ChangeListMutator(const ChangeList &cl) 68 | : cl_(cl) { } 69 | 70 | ChangeListMutator() { } 71 | 72 | void Mutate(SegmentMap *table, 73 | const SegmentMap *source_table, 74 | MTRandom *rand) const { 75 | // The speed of processing gigabytes of data is so slow compared with 76 | // these table-copy operations, no attempt to make this fast. 77 | SegmentMap tmp; 78 | 79 | for (ConstChangeListIterator iter(cl_.begin()); 80 | iter != cl_.end(); ++iter) { 81 | const Change &ch = *iter; 82 | tmp.clear(); 83 | Mutate(ch, &tmp, source_table, rand); 84 | tmp.swap(*table); 85 | source_table = table; 86 | } 87 | } 88 | 89 | static void Mutate(const Change &ch, 90 | SegmentMap *table, 91 | const SegmentMap *source_table, 92 | MTRandom *rand) { 93 | switch (ch.kind) { 94 | case Change::ADD: 95 | AddChange(ch, table, source_table, rand); 96 | break; 97 | case Change::MODIFY: 98 | ModifyChange(ch, table, source_table, rand); 99 | break; 100 | case Change::DELETE: 101 | DeleteChange(ch, table, source_table, rand); 102 | break; 103 | case Change::COPY: 104 | CopyChange(ch, table, source_table, rand); 105 | break; 106 | case Change::MOVE: 107 | MoveChange(ch, table, source_table, rand); 108 | break; 109 | case Change::OVERWRITE: 110 | OverwriteChange(ch, table, source_table, rand); 111 | break; 112 | } 113 | } 114 | 115 | static void ModifyChange(const Change &ch, 116 | SegmentMap *table, 117 | const SegmentMap *source_table, 118 | MTRandom *rand) { 119 | xoff_t m_start = ch.addr1; 120 | xoff_t m_end = m_start + ch.size; 121 | xoff_t i_start = 0; 122 | xoff_t i_end = 0; 123 | 124 | for (ConstSegmentMapIterator iter(source_table->begin()); 125 | iter != source_table->end(); 126 | ++iter) { 127 | const Segment &seg = iter->second; 128 | i_start = iter->first; 129 | i_end = i_start + seg.Size(); 130 | 131 | if (i_end <= m_start || i_start >= m_end) { 132 | table->insert(table->end(), make_pair(i_start, seg)); 133 | continue; 134 | } 135 | 136 | if (i_start < m_start) { 137 | table->insert(table->end(), 138 | make_pair(i_start, 139 | seg.Subseg(0, m_start - i_start))); 140 | } 141 | 142 | // Insert the entire segment, even though it may extend into later 143 | // segments. This condition avoids inserting it during later 144 | // segments. 145 | if (m_start >= i_start) { 146 | if (ch.insert != NULL) { 147 | table->insert(table->end(), make_pair(m_start, *ch.insert)); 148 | } else { 149 | Segment part(m_end - m_start, rand); 150 | table->insert(table->end(), make_pair(m_start, part)); 151 | } 152 | } 153 | 154 | if (i_end > m_end) { 155 | table->insert(table->end(), 156 | make_pair(m_end, 157 | seg.Subseg(m_end - i_start, i_end - m_end))); 158 | } 159 | } 160 | 161 | // This check verifies that the modify does not extend past the 162 | // source_table EOF. 163 | CHECK_LE(m_end, i_end); 164 | } 165 | 166 | static void AddChange(const Change &ch, 167 | SegmentMap *table, 168 | const SegmentMap *source_table, 169 | MTRandom *rand) { 170 | xoff_t m_start = ch.addr1; 171 | xoff_t i_start = 0; 172 | xoff_t i_end = 0; 173 | 174 | for (ConstSegmentMapIterator iter(source_table->begin()); 175 | iter != source_table->end(); 176 | ++iter) { 177 | const Segment &seg = iter->second; 178 | i_start = iter->first; 179 | i_end = i_start + seg.Size(); 180 | 181 | if (i_end <= m_start) { 182 | table->insert(table->end(), make_pair(i_start, seg)); 183 | continue; 184 | } 185 | 186 | if (i_start > m_start) { 187 | table->insert(table->end(), make_pair(i_start + ch.size, seg)); 188 | continue; 189 | } 190 | 191 | if (i_start < m_start) { 192 | table->insert(table->end(), 193 | make_pair(i_start, 194 | seg.Subseg(0, m_start - i_start))); 195 | } 196 | 197 | if (ch.insert != NULL) { 198 | table->insert(table->end(), make_pair(m_start, *ch.insert)); 199 | } else { 200 | Segment addseg(ch.size, rand); 201 | table->insert(table->end(), make_pair(m_start, addseg)); 202 | } 203 | 204 | if (m_start < i_end) { 205 | table->insert(table->end(), 206 | make_pair(m_start + ch.size, 207 | seg.Subseg(m_start - i_start, 208 | i_end - m_start))); 209 | } 210 | } 211 | 212 | CHECK_LE(m_start, i_end); 213 | 214 | // Special case for add at end-of-input. 215 | if (m_start == i_end) { 216 | Segment addseg(ch.size, rand); 217 | table->insert(table->end(), make_pair(m_start, addseg)); 218 | } 219 | } 220 | 221 | static void DeleteChange(const Change &ch, 222 | SegmentMap *table, 223 | const SegmentMap *source_table, 224 | MTRandom *rand) { 225 | xoff_t m_start = ch.addr1; 226 | xoff_t m_end = m_start + ch.size; 227 | xoff_t i_start = 0; 228 | xoff_t i_end = 0; 229 | 230 | for (ConstSegmentMapIterator iter(source_table->begin()); 231 | iter != source_table->end(); 232 | ++iter) { 233 | const Segment &seg = iter->second; 234 | i_start = iter->first; 235 | i_end = i_start + seg.Size(); 236 | 237 | if (i_end <= m_start) { 238 | table->insert(table->end(), make_pair(i_start, seg)); 239 | continue; 240 | } 241 | 242 | if (i_start >= m_end) { 243 | table->insert(table->end(), make_pair(i_start - ch.size, seg)); 244 | continue; 245 | } 246 | 247 | if (i_start < m_start) { 248 | table->insert(table->end(), 249 | make_pair(i_start, 250 | seg.Subseg(0, m_start - i_start))); 251 | } 252 | 253 | if (i_end > m_end) { 254 | table->insert(table->end(), 255 | make_pair(m_end - ch.size, 256 | seg.Subseg(m_end - i_start, i_end - m_end))); 257 | } 258 | } 259 | 260 | CHECK_LT(m_start, i_end); 261 | CHECK_LE(m_end, i_end); 262 | } 263 | 264 | // A move is a copy followed by delete of the copied-from range. 265 | static void MoveChange(const Change &ch, 266 | SegmentMap *table, 267 | const SegmentMap *source_table, 268 | MTRandom *rand) { 269 | SegmentMap tmp; 270 | CHECK_NE(ch.addr1, ch.addr2); 271 | CopyChange(ch, &tmp, source_table, rand); 272 | Change d(Change::DELETE, ch.size, 273 | ch.addr1 < ch.addr2 ? ch.addr1 : ch.addr1 + ch.size); 274 | DeleteChange(d, table, &tmp, rand); 275 | } 276 | 277 | // An overwrite is a copy followed by a delete of the copied-to range. 278 | static void OverwriteChange(const Change &ch, 279 | SegmentMap *table, 280 | const SegmentMap *source_table, 281 | MTRandom *rand) { 282 | SegmentMap tmp; 283 | CHECK_NE(ch.addr1, ch.addr2); 284 | CopyChange(ch, &tmp, source_table, rand); 285 | Change d(Change::DELETE, ch.size, ch.addr2 + ch.size); 286 | DeleteChange(d, table, &tmp, rand); 287 | } 288 | 289 | static void CopyChange(const Change &ch, 290 | SegmentMap *table, 291 | const SegmentMap *source_table, 292 | MTRandom *ignore) { 293 | xoff_t m_start = ch.addr2; 294 | xoff_t c_start = ch.addr1; 295 | xoff_t i_start = 0; 296 | xoff_t i_end = 0; 297 | 298 | // Like AddChange() with AppendCopy instead of a random segment. 299 | for (ConstSegmentMapIterator iter(source_table->begin()); 300 | iter != source_table->end(); 301 | ++iter) { 302 | const Segment &seg = iter->second; 303 | i_start = iter->first; 304 | i_end = i_start + seg.Size(); 305 | 306 | if (i_end <= m_start) { 307 | table->insert(table->end(), make_pair(i_start, seg)); 308 | continue; 309 | } 310 | 311 | if (i_start > m_start) { 312 | table->insert(table->end(), make_pair(i_start + ch.size, seg)); 313 | continue; 314 | } 315 | 316 | if (i_start < m_start) { 317 | table->insert(table->end(), 318 | make_pair(i_start, 319 | seg.Subseg(0, m_start - i_start))); 320 | } 321 | 322 | AppendCopy(table, source_table, c_start, m_start, ch.size); 323 | 324 | if (m_start < i_end) { 325 | table->insert(table->end(), 326 | make_pair(m_start + ch.size, 327 | seg.Subseg(m_start - i_start, i_end - m_start))); 328 | } 329 | } 330 | 331 | CHECK_LE(m_start, i_end); 332 | 333 | // Special case for copy to end-of-input. 334 | if (m_start == i_end) { 335 | AppendCopy(table, source_table, c_start, m_start, ch.size); 336 | } 337 | } 338 | 339 | static void AppendCopy(SegmentMap *table, 340 | const SegmentMap *source_table, 341 | xoff_t copy_offset, 342 | xoff_t append_offset, 343 | xoff_t length) { 344 | ConstSegmentMapIterator pos(source_table->upper_bound(copy_offset)); 345 | --pos; 346 | xoff_t got = 0; 347 | 348 | while (got < length) { 349 | size_t seg_offset = copy_offset - pos->first; 350 | size_t advance = min(pos->second.Size() - seg_offset, 351 | (size_t)(length - got)); 352 | 353 | table->insert(table->end(), 354 | make_pair(append_offset, 355 | pos->second.Subseg(seg_offset, 356 | advance))); 357 | 358 | got += advance; 359 | copy_offset += advance; 360 | append_offset += advance; 361 | ++pos; 362 | } 363 | } 364 | 365 | ChangeList* Changes() { 366 | return &cl_; 367 | } 368 | 369 | const ChangeList* Changes() const { 370 | return &cl_; 371 | } 372 | 373 | private: 374 | ChangeList cl_; 375 | }; 376 | 377 | class Modify1stByte : public Mutator { 378 | public: 379 | void Mutate(SegmentMap *table, 380 | const SegmentMap *source_table, 381 | MTRandom *rand) const { 382 | ChangeListMutator::Mutate(Change(Change::MODIFY, 1, 0), 383 | table, source_table, rand); 384 | } 385 | }; 386 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/random.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++ -*- */ 2 | /* This is public-domain Mersenne Twister code, 3 | * attributed to Michael Brundage. Thanks! 4 | * http://www.qbrundage.com/michaelb/pubs/essays/random_number_generation.html 5 | */ 6 | #undef MT_LEN 7 | #undef MT_IA 8 | class MTRandom { 9 | public: 10 | enum Constants { 11 | MT_LEN = 624, 12 | MT_IA = 397 13 | }; 14 | 15 | static const uint32_t TEST_SEED1; 16 | static const uint32_t UPPER_MASK; 17 | static const uint32_t LOWER_MASK; 18 | static const uint32_t MATRIX_A; 19 | 20 | MTRandom() { 21 | Init(TEST_SEED1); 22 | } 23 | 24 | MTRandom(uint32_t seed) { 25 | Init(seed); 26 | } 27 | 28 | uint32_t Rand32 () { 29 | uint32_t y; 30 | static unsigned long mag01[2] = { 31 | 0 , MATRIX_A 32 | }; 33 | 34 | if (mt_index_ >= MT_LEN) { 35 | int kk; 36 | 37 | for (kk = 0; kk < MT_LEN - MT_IA; kk++) { 38 | y = (mt_buffer_[kk] & UPPER_MASK) | (mt_buffer_[kk + 1] & LOWER_MASK); 39 | mt_buffer_[kk] = mt_buffer_[kk + MT_IA] ^ (y >> 1) ^ mag01[y & 0x1UL]; 40 | } 41 | for (;kk < MT_LEN - 1; kk++) { 42 | y = (mt_buffer_[kk] & UPPER_MASK) | (mt_buffer_[kk + 1] & LOWER_MASK); 43 | mt_buffer_[kk] = mt_buffer_[kk + (MT_IA - MT_LEN)] ^ (y >> 1) ^ mag01[y & 0x1UL]; 44 | } 45 | y = (mt_buffer_[MT_LEN - 1] & UPPER_MASK) | (mt_buffer_[0] & LOWER_MASK); 46 | mt_buffer_[MT_LEN - 1] = mt_buffer_[MT_IA - 1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 47 | 48 | mt_index_ = 0; 49 | } 50 | 51 | y = mt_buffer_[mt_index_++]; 52 | 53 | y ^= (y >> 11); 54 | y ^= (y << 7) & 0x9d2c5680UL; 55 | y ^= (y << 15) & 0xefc60000UL; 56 | y ^= (y >> 18); 57 | 58 | return y; 59 | } 60 | 61 | uint32_t ExpRand32(uint32_t mean) { 62 | double mean_d = mean; 63 | double erand = log (1.0 / (Rand32() / (double)UINT32_MAX)); 64 | uint32_t x = (uint32_t) (mean_d * erand + 0.5); 65 | return x; 66 | } 67 | 68 | uint64_t Rand64() { 69 | return ((uint64_t)Rand32() << 32) | Rand32(); 70 | } 71 | 72 | uint64_t ExpRand64(uint64_t mean) { 73 | double mean_d = mean; 74 | double erand = log (1.0 / (Rand64() / (double)UINT32_MAX)); 75 | uint64_t x = (uint64_t) (mean_d * erand + 0.5); 76 | return x; 77 | } 78 | 79 | template 80 | T Rand() { 81 | switch (sizeof(T)) { 82 | case sizeof(uint32_t): 83 | return Rand32(); 84 | case sizeof(uint64_t): 85 | return Rand64(); 86 | default: 87 | cerr << "Invalid sizeof T" << endl; 88 | abort(); 89 | } 90 | } 91 | 92 | template 93 | T ExpRand(T mean) { 94 | switch (sizeof(T)) { 95 | case sizeof(uint32_t): 96 | return ExpRand32(mean); 97 | case sizeof(uint64_t): 98 | return ExpRand64(mean); 99 | default: 100 | cerr << "Invalid sizeof T" << endl; 101 | abort(); 102 | } 103 | } 104 | 105 | private: 106 | void Init(uint32_t seed) { 107 | mt_buffer_[0] = seed; 108 | mt_index_ = MT_LEN; 109 | for (int i = 1; i < MT_LEN; i++) { 110 | /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 111 | /* In the previous versions, MSBs of the seed affect */ 112 | /* only MSBs of the array mt[]. */ 113 | /* 2002/01/09 modified by Makoto Matsumoto */ 114 | mt_buffer_[i] = 115 | (1812433253UL * (mt_buffer_[i-1] ^ (mt_buffer_[i-1] >> 30)) + i); 116 | } 117 | } 118 | 119 | int mt_index_; 120 | uint32_t mt_buffer_[MT_LEN]; 121 | }; 122 | 123 | const uint32_t MTRandom::TEST_SEED1 = 5489UL; 124 | const uint32_t MTRandom::UPPER_MASK = 0x80000000; 125 | const uint32_t MTRandom::LOWER_MASK = 0x7FFFFFFF; 126 | const uint32_t MTRandom::MATRIX_A = 0x9908B0DF; 127 | 128 | class MTRandom8 { 129 | public: 130 | MTRandom8(MTRandom *rand) 131 | : rand_(rand) { 132 | } 133 | 134 | uint8_t Rand8() { 135 | uint32_t r = rand_->Rand32(); 136 | 137 | // TODO: make this use a single byte at a time? 138 | return (r & 0xff) ^ (r >> 7) ^ (r >> 15) ^ (r >> 21); 139 | } 140 | 141 | private: 142 | MTRandom *rand_; 143 | }; 144 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/regtest_c.c: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++ -*- */ 2 | #include "../xdelta3.c" 3 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/segment.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++ -*- 2 | 3 | class Segment { 4 | public: 5 | Segment(size_t size, MTRandom *rand) 6 | : size_(size), 7 | seed_(rand->Rand32()), 8 | seed_offset_(0), 9 | data_(NULL) { 10 | CHECK_GT(size_, 0); 11 | } 12 | 13 | Segment(size_t size, uint32_t seed) 14 | : size_(size), 15 | seed_(seed), 16 | seed_offset_(0), 17 | data_(NULL) { 18 | CHECK_GT(size_, 0); 19 | } 20 | 21 | Segment(size_t size, uint8_t *data) 22 | : size_(size), 23 | seed_(0), 24 | seed_offset_(0), 25 | data_(data) { 26 | CHECK_GT(size_, 0); 27 | } 28 | 29 | size_t Size() const { 30 | return size_; 31 | } 32 | 33 | Segment Subseg(size_t start, size_t size) const { 34 | CHECK_LE(start + size, size_); 35 | if (data_) { 36 | return Segment(size, data_ + start); 37 | } else { 38 | return Segment(size, seed_, seed_offset_ + start); 39 | } 40 | } 41 | 42 | void Fill(size_t seg_offset, size_t size, uint8_t *data) const { 43 | CHECK_LE(seg_offset + size, size_); 44 | if (data_) { 45 | memcpy(data, data_ + seg_offset, size); 46 | } else { 47 | size_t skip = seg_offset + seed_offset_; 48 | MTRandom gen(seed_); 49 | MTRandom8 gen8(&gen); 50 | while (skip--) { 51 | gen8.Rand8(); 52 | } 53 | for (size_t i = 0; i < size; i++) { 54 | data[i] = gen8.Rand8(); 55 | } 56 | } 57 | } 58 | 59 | string ToString() const { 60 | string r; 61 | if (data_) { 62 | for (size_t i = 0; i < size_; i++) { 63 | char buf[10]; 64 | sprintf(buf, "%02x ", data_[i]); 65 | r.append(buf); 66 | } 67 | } else { 68 | char buf[256]; 69 | sprintf(buf, "size=%ld,seed=%ud,skip=%ld", size_, seed_, seed_offset_); 70 | r.append(buf); 71 | } 72 | return r; 73 | } 74 | 75 | private: 76 | // Used by Subseg() 77 | Segment(size_t size, uint32_t seed, size_t seed_offset) 78 | : size_(size), 79 | seed_(seed), 80 | seed_offset_(seed_offset), 81 | data_(NULL) { 82 | CHECK_GT(size_, 0); 83 | } 84 | 85 | size_t size_; // Size of this segment 86 | 87 | // For random segments 88 | uint32_t seed_; // Seed used for generating byte sequence 89 | size_t seed_offset_; // Seed positions the sequence this many bytes 90 | // before its beginning. 91 | 92 | // For literal segments (data is not owned) 93 | uint8_t *data_; 94 | }; 95 | 96 | typedef map SegmentMap; 97 | typedef typename SegmentMap::const_iterator ConstSegmentMapIterator; 98 | typedef typename SegmentMap::iterator SegmentMapIterator; 99 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/sizes.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++ -*- 2 | template 3 | class SizeIterator { 4 | public: 5 | SizeIterator(MTRandom *rand, size_t howmany) 6 | : rand_(rand), 7 | count_(0), 8 | fixed_(U::sizes), 9 | fixed_size_(SIZEOF_ARRAY(U::sizes)), 10 | howmany_(howmany) { } 11 | 12 | T Get() { 13 | if (count_ < fixed_size_) { 14 | return fixed_[count_]; 15 | } 16 | return rand_->Rand() % U::max_value; 17 | } 18 | 19 | bool Done() { 20 | return count_ >= fixed_size_ && count_ >= howmany_; 21 | } 22 | 23 | void Next() { 24 | count_++; 25 | } 26 | 27 | private: 28 | MTRandom *rand_; 29 | size_t count_; 30 | T* fixed_; 31 | size_t fixed_size_; 32 | size_t howmany_; 33 | }; 34 | 35 | // Small sizes 36 | class SmallSizes { 37 | public: 38 | static size_t sizes[]; 39 | static size_t max_value; 40 | }; 41 | 42 | size_t SmallSizes::sizes[] = { 43 | 0, 1, 128 / 4, 3333, 44 | 128 - (128 / 3), 45 | 128, 46 | 128 + (128 / 3), 47 | 2 * 128 - (128 / 3), 48 | 2 * 128, 49 | 2 * 128 + (128 / 3), 50 | }; 51 | 52 | size_t SmallSizes::max_value = 128 * 3; 53 | 54 | // Large sizes 55 | class LargeSizes { 56 | public: 57 | static size_t sizes[]; 58 | static size_t max_value; 59 | }; 60 | 61 | size_t LargeSizes::sizes[] = { 62 | 1 << 20, 63 | 1 << 18, 64 | 1 << 16, 65 | }; 66 | 67 | size_t LargeSizes::max_value = 1<<20; 68 | 69 | // Base constants 70 | struct BaseConstants { 71 | static const size_t TEST_ROUNDS; 72 | }; 73 | 74 | const size_t BaseConstants::TEST_ROUNDS = 10; 75 | 76 | // Regtest<> arguments 77 | struct SmallBlock : public BaseConstants { 78 | static const xoff_t BLOCK_SIZE; 79 | static const size_t WINDOW_SIZE; 80 | static const size_t READ_SIZE; 81 | typedef SmallSizes Sizes; 82 | }; 83 | 84 | const size_t SmallBlock::READ_SIZE = 1<<7; 85 | const xoff_t SmallBlock::BLOCK_SIZE = 1<<7; 86 | const size_t SmallBlock::WINDOW_SIZE = 1<<7; 87 | 88 | struct LargeBlock : public BaseConstants { 89 | static const xoff_t BLOCK_SIZE; 90 | static const size_t WINDOW_SIZE; 91 | static const size_t READ_SIZE; 92 | typedef LargeSizes Sizes; 93 | }; 94 | 95 | const size_t LargeBlock::READ_SIZE = (1 << 13); 96 | const xoff_t LargeBlock::BLOCK_SIZE = (1 << 13); 97 | const size_t LargeBlock::WINDOW_SIZE = (1 << 13); 98 | 99 | struct MixedBlock : public BaseConstants { 100 | static const xoff_t BLOCK_SIZE; 101 | static const size_t WINDOW_SIZE; 102 | static const size_t READ_SIZE; 103 | typedef SmallSizes Sizes; 104 | }; 105 | 106 | const size_t MixedBlock::READ_SIZE = 1<<6; 107 | const xoff_t MixedBlock::BLOCK_SIZE = 1<<7; 108 | const size_t MixedBlock::WINDOW_SIZE = 1<<8; 109 | 110 | struct OversizeBlock : public BaseConstants { 111 | static const xoff_t BLOCK_SIZE; 112 | static const size_t WINDOW_SIZE; 113 | static const size_t READ_SIZE; 114 | typedef SmallSizes Sizes; 115 | }; 116 | 117 | const size_t OversizeBlock::READ_SIZE = (1<<6) + (1<<7); 118 | const xoff_t OversizeBlock::BLOCK_SIZE = 1<<8; 119 | const size_t OversizeBlock::WINDOW_SIZE = 1<<7; 120 | 121 | struct PrimeBlock : public BaseConstants { 122 | static const xoff_t BLOCK_SIZE; 123 | static const size_t WINDOW_SIZE; 124 | static const size_t READ_SIZE; 125 | typedef SmallSizes Sizes; 126 | }; 127 | 128 | const size_t PrimeBlock::READ_SIZE = 71; 129 | const xoff_t PrimeBlock::BLOCK_SIZE = 512; // Must be a power-of-2 130 | const size_t PrimeBlock::WINDOW_SIZE = 73; 131 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/test.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++ -*- 2 | 3 | extern "C" { 4 | #include "../xdelta3.h" 5 | #include "../xdelta3-internal.h" 6 | } 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define CHECK_EQ(x,y) CHECK_OP(x,y,==) 13 | #define CHECK_NE(x,y) CHECK_OP(x,y,!=) 14 | #define CHECK_LT(x,y) CHECK_OP(x,y,<) 15 | #define CHECK_GT(x,y) CHECK_OP(x,y,>) 16 | #define CHECK_LE(x,y) CHECK_OP(x,y,<=) 17 | #define CHECK_GE(x,y) CHECK_OP(x,y,>=) 18 | 19 | #define CHECK_OP(x,y,OP) \ 20 | do { \ 21 | typeof(x) _x(x); \ 22 | typeof(x) _y(y); \ 23 | if (!(_x OP _y)) { \ 24 | cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x " " #OP " " #y << endl; \ 25 | cerr << __FILE__ << ":" << __LINE__ << " Expected: " << _x << endl; \ 26 | cerr << __FILE__ << ":" << __LINE__ << " Actual: " << _y << endl; \ 27 | abort(); \ 28 | } } while (false) 29 | #undef CHECK 30 | #define CHECK(x) \ 31 | do {if (!(x)) { \ 32 | cerr << __FILE__ << ":" << __LINE__ << " Check failed: " << #x << endl; \ 33 | abort(); \ 34 | } } while (false) 35 | 36 | #define DCHECK(x) 37 | 38 | using std::string; 39 | 40 | #include 41 | using std::vector; 42 | 43 | inline string CommandToString(const vector &v) { 44 | string s(v[0]); 45 | for (size_t i = 1; i < v.size() && v[i] != NULL; i++) { 46 | s.append(" "); 47 | s.append(v[i]); 48 | } 49 | return s; 50 | } 51 | 52 | #include 53 | using std::cerr; 54 | using std::endl; 55 | using std::ostream; 56 | 57 | #include 58 | using std::map; 59 | using std::pair; 60 | 61 | #include 62 | using std::list; 63 | 64 | template 65 | pair make_pair(const T& t, const U& u) { 66 | return pair(t, u); 67 | } 68 | 69 | using std::min; 70 | using std::max; 71 | 72 | 73 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/testing/xdelta3-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.7 2 | # xdelta 3 - delta compression tools and library 3 | # Copyright (C) 2003, 2006, 2007. Joshua P. MacDonald 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | 19 | import xdelta3 20 | 21 | # the test data section is expected to be len('target') 22 | source = 'source source input0 source source' 23 | target = 'source source target source source' 24 | 25 | # 26 | # 27 | 28 | print 'encode: basic ...' 29 | result, patch = xdelta3.xd3_encode_memory(target, source, 50) 30 | 31 | assert result == 0 32 | assert len(patch) < len(source) 33 | 34 | print 'encode: adler32 ...' 35 | result, patch_adler32 = xdelta3.xd3_encode_memory(target, source, 50, 36 | xdelta3.XD3_ADLER32) 37 | 38 | assert result == 0 39 | assert len(patch_adler32) < len(source) 40 | assert len(patch_adler32) > len(patch) 41 | 42 | print 'encode: secondary ...' 43 | result, patch_djw = xdelta3.xd3_encode_memory(target, source, 50, 44 | xdelta3.XD3_SEC_DJW) 45 | 46 | assert result == 0 47 | # secondary compression doesn't help 48 | assert len(patch_djw) > len(patch) 49 | 50 | print 'encode: exact ...' 51 | result, ignore = xdelta3.xd3_encode_memory(target, source, len(patch)) 52 | 53 | assert result == 0 54 | assert len(ignore) < len(source) 55 | 56 | print 'encode: out of space ...' 57 | result, ignore = xdelta3.xd3_encode_memory(target, source, len(patch) - 1) 58 | 59 | assert result == 28 60 | assert ignore == None 61 | 62 | print 'encode: zero space ...' 63 | result, ignore = xdelta3.xd3_encode_memory(target, source, 0) 64 | 65 | assert result == 28 66 | assert ignore == None 67 | 68 | print 'encode: no source ...' 69 | result, zdata = xdelta3.xd3_encode_memory(target, None, 50) 70 | 71 | assert result == 0 72 | assert len(zdata) > len(patch) 73 | 74 | print 'encode: no input ...' 75 | result, ignore = xdelta3.xd3_encode_memory(None, None, 50) 76 | 77 | assert result != 0 78 | 79 | print 'decode: basic ...' 80 | result, target1 = xdelta3.xd3_decode_memory(patch, source, len(target)) 81 | 82 | assert result == 0 83 | assert len(target1) == len(target) 84 | assert target1 == target 85 | 86 | print 'decode: out of space ...' 87 | result, ignore = xdelta3.xd3_decode_memory(patch, source, len(target) - 1) 88 | 89 | assert result == 28 90 | assert ignore == None 91 | 92 | print 'decode: zero space ...' 93 | result, ignore = xdelta3.xd3_decode_memory(patch, source, 0) 94 | 95 | assert result == 28 96 | assert ignore == None 97 | 98 | print 'decode: single byte error ...' 99 | # a few expected single-byte errors, e.g., unused address cache bits, see 100 | # xdelta3-test.h's single-bit error tests 101 | extra_count = 4 102 | noverify_count = 0 103 | for corrupt_pos in range(len(patch_adler32)): 104 | input = ''.join([j == corrupt_pos and '\xff' or patch_adler32[j] 105 | for j in range(len(patch_adler32))]) 106 | 107 | result, ignore = xdelta3.xd3_decode_memory(input, source, len(target), 0) 108 | assert result == -17712 109 | assert ignore == None 110 | 111 | # without adler32 verification, the error may be in the data section which 112 | # in this case is 6 bytes 'target' 113 | result, corrupt = xdelta3.xd3_decode_memory(input, source, len(target), 114 | xdelta3.XD3_ADLER32_NOVER) 115 | if result == 0: 116 | noverify_count = noverify_count + 1 117 | #print "got %s" % corrupt 118 | #end 119 | #end 120 | assert noverify_count == len('target') + extra_count 121 | 122 | print 'decode: no source ...' 123 | result, target2 = xdelta3.xd3_decode_memory(zdata, None, len(target)) 124 | 125 | assert result == 0 126 | assert target == target2 127 | 128 | # Test compression level setting via flags. assumes a 9 byte checksum 129 | # and that level 9 steps 2, level 1 steps 15: 130 | # 01234567890123456789012345678901 131 | # level 1 only indexes 2 checksums "abcdefghi" and "ABCDEFGHI" 132 | # outputs 43 vs. 23 bytes 133 | print 'encode: compression level ...' 134 | 135 | source = '_la_la_abcdefghi_la_la_ABCDEFGHI' 136 | target = 'la_la_ABCDEFGH__la_la_abcdefgh__' 137 | 138 | result1, level1 = xdelta3.xd3_encode_memory(target, source, 50, xdelta3.XD3_COMPLEVEL_1) 139 | result9, level9 = xdelta3.xd3_encode_memory(target, source, 50, xdelta3.XD3_COMPLEVEL_9) 140 | 141 | assert result1 == 0 and result9 == 0 142 | assert len(level1) > len(level9) 143 | 144 | # 145 | # Issue 65 146 | print 'encode: 65 ...' 147 | source = 'Hello World' 148 | target = 'Hello everyone' 149 | result, patch = xdelta3.xd3_encode_memory(target, source, len(target)) 150 | assert result != 0 151 | 152 | result, patch = xdelta3.xd3_encode_memory(target, source, 2 * len(target)) 153 | assert result == 0 154 | 155 | print 'PASS' 156 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3-cfgs.h: -------------------------------------------------------------------------------- 1 | /* xdelta 3 - delta compression tools and library 2 | * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007. Joshua P. MacDonald 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | /****************************************************************** 20 | SOFT string matcher 21 | ******************************************************************/ 22 | 23 | #if XD3_BUILD_SOFT 24 | 25 | #define TEMPLATE soft 26 | #define LLOOK stream->smatcher.large_look 27 | #define LSTEP stream->smatcher.large_step 28 | #define SLOOK stream->smatcher.small_look 29 | #define SCHAIN stream->smatcher.small_chain 30 | #define SLCHAIN stream->smatcher.small_lchain 31 | #define MAXLAZY stream->smatcher.max_lazy 32 | #define LONGENOUGH stream->smatcher.long_enough 33 | 34 | #define SOFTCFG 1 35 | #include "xdelta3.c" 36 | #undef SOFTCFG 37 | 38 | #undef TEMPLATE 39 | #undef LLOOK 40 | #undef SLOOK 41 | #undef LSTEP 42 | #undef SCHAIN 43 | #undef SLCHAIN 44 | #undef MAXLAZY 45 | #undef LONGENOUGH 46 | #endif 47 | 48 | #define SOFTCFG 0 49 | 50 | /************************************************************ 51 | FASTEST string matcher 52 | **********************************************************/ 53 | #if XD3_BUILD_FASTEST 54 | #define TEMPLATE fastest 55 | #define LLOOK 9 56 | #define LSTEP 26 57 | #define SLOOK 4U 58 | #define SCHAIN 1 59 | #define SLCHAIN 1 60 | #define MAXLAZY 6 61 | #define LONGENOUGH 6 62 | 63 | #include "xdelta3.c" 64 | 65 | #undef TEMPLATE 66 | #undef LLOOK 67 | #undef SLOOK 68 | #undef LSTEP 69 | #undef SCHAIN 70 | #undef SLCHAIN 71 | #undef MAXLAZY 72 | #undef LONGENOUGH 73 | #endif 74 | 75 | /************************************************************ 76 | FASTER string matcher 77 | **********************************************************/ 78 | #if XD3_BUILD_FASTER 79 | #define TEMPLATE faster 80 | #define LLOOK 9 81 | #define LSTEP 15 82 | #define SLOOK 4U 83 | #define SCHAIN 1 84 | #define SLCHAIN 1 85 | #define MAXLAZY 18 86 | #define LONGENOUGH 18 87 | 88 | #include "xdelta3.c" 89 | 90 | #undef TEMPLATE 91 | #undef LLOOK 92 | #undef SLOOK 93 | #undef LSTEP 94 | #undef SCHAIN 95 | #undef SLCHAIN 96 | #undef MAXLAZY 97 | #undef LONGENOUGH 98 | #endif 99 | 100 | /****************************************************** 101 | FAST string matcher 102 | ********************************************************/ 103 | #if XD3_BUILD_FAST 104 | #define TEMPLATE fast 105 | #define LLOOK 9 106 | #define LSTEP 8 107 | #define SLOOK 4U 108 | #define SCHAIN 4 109 | #define SLCHAIN 1 110 | #define MAXLAZY 18 111 | #define LONGENOUGH 35 112 | 113 | #include "xdelta3.c" 114 | 115 | #undef TEMPLATE 116 | #undef LLOOK 117 | #undef SLOOK 118 | #undef LSTEP 119 | #undef SCHAIN 120 | #undef SLCHAIN 121 | #undef MAXLAZY 122 | #undef LONGENOUGH 123 | #endif 124 | 125 | /************************************************** 126 | SLOW string matcher 127 | **************************************************************/ 128 | #if XD3_BUILD_SLOW 129 | #define TEMPLATE slow 130 | #define LLOOK 9 131 | #define LSTEP 2 132 | #define SLOOK 4U 133 | #define SCHAIN 44 134 | #define SLCHAIN 13 135 | #define MAXLAZY 90 136 | #define LONGENOUGH 70 137 | 138 | #include "xdelta3.c" 139 | 140 | #undef TEMPLATE 141 | #undef LLOOK 142 | #undef SLOOK 143 | #undef LSTEP 144 | #undef SCHAIN 145 | #undef SLCHAIN 146 | #undef MAXLAZY 147 | #undef LONGENOUGH 148 | #endif 149 | 150 | /******************************************************** 151 | DEFAULT string matcher 152 | ************************************************************/ 153 | #if XD3_BUILD_DEFAULT 154 | #define TEMPLATE default 155 | #define LLOOK 9 156 | #define LSTEP 3 157 | #define SLOOK 4U 158 | #define SCHAIN 8 159 | #define SLCHAIN 2 160 | #define MAXLAZY 36 161 | #define LONGENOUGH 70 162 | 163 | #include "xdelta3.c" 164 | 165 | #undef TEMPLATE 166 | #undef LLOOK 167 | #undef SLOOK 168 | #undef LSTEP 169 | #undef SCHAIN 170 | #undef SLCHAIN 171 | #undef MAXLAZY 172 | #undef LONGENOUGH 173 | #endif 174 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3-hash.h: -------------------------------------------------------------------------------- 1 | /* xdelta 3 - delta compression tools and library 2 | * Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007. Joshua P. MacDonald 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef _XDELTA3_HASH_H_ 20 | #define _XDELTA3_HASH_H_ 21 | 22 | #if XD3_DEBUG 23 | #define SMALL_HASH_DEBUG1(s,inp) \ 24 | uint32_t debug_state; \ 25 | uint32_t debug_hval = xd3_checksum_hash (& (s)->small_hash, \ 26 | xd3_scksum (&debug_state, (inp), (s)->smatcher.small_look)) 27 | #define SMALL_HASH_DEBUG2(s,inp) \ 28 | XD3_ASSERT (debug_hval == xd3_checksum_hash (& (s)->small_hash, \ 29 | xd3_scksum (&debug_state, (inp), (s)->smatcher.small_look))) 30 | #else 31 | #define SMALL_HASH_DEBUG1(s,inp) 32 | #define SMALL_HASH_DEBUG2(s,inp) 33 | #endif /* XD3_DEBUG */ 34 | 35 | /* This is a good hash multiplier for 32-bit LCGs: see "linear 36 | * congruential generators of different sizes and good lattice 37 | * structure" */ 38 | static const uint32_t hash_multiplier = 1597334677U; 39 | 40 | /*********************************************************************** 41 | Permute stuff 42 | ***********************************************************************/ 43 | 44 | #if HASH_PERMUTE == 0 45 | #define PERMUTE(x) (x) 46 | #else 47 | #define PERMUTE(x) (__single_hash[(uint32_t)x]) 48 | 49 | extern const uint16_t __single_hash[256]; 50 | #endif 51 | 52 | /* Update the checksum state. */ 53 | #if ADLER_LARGE_CKSUM 54 | inline uint32_t 55 | xd3_large_cksum_update (uint32_t cksum, 56 | const uint8_t *base, 57 | usize_t look) { 58 | uint32_t old_c = PERMUTE(base[0]); 59 | uint32_t new_c = PERMUTE(base[look]); 60 | uint32_t low = ((cksum & 0xffff) - old_c + new_c) & 0xffff; 61 | uint32_t high = ((cksum >> 16) - (old_c * look) + low) & 0xffff; 62 | return (high << 16) | low; 63 | } 64 | #else 65 | /* TODO: revisit this topic */ 66 | #endif 67 | 68 | #if UNALIGNED_OK 69 | #define UNALIGNED_READ32(dest,src) (*(dest)) = (*(uint32_t*)(src)) 70 | #else 71 | #define UNALIGNED_READ32(dest,src) memcpy((dest), (src), 4); 72 | #endif 73 | 74 | /* TODO: small cksum is hard-coded for 4 bytes (i.e., "look" is unused) */ 75 | static inline uint32_t 76 | xd3_scksum (uint32_t *state, 77 | const uint8_t *base, 78 | const usize_t look) 79 | { 80 | UNALIGNED_READ32(state, base); 81 | return (*state) * hash_multiplier; 82 | } 83 | static inline uint32_t 84 | xd3_small_cksum_update (uint32_t *state, 85 | const uint8_t *base, 86 | usize_t look) 87 | { 88 | UNALIGNED_READ32(state, base+1); 89 | return (*state) * hash_multiplier; 90 | } 91 | 92 | /*********************************************************************** 93 | Ctable stuff 94 | ***********************************************************************/ 95 | 96 | static inline usize_t 97 | xd3_checksum_hash (const xd3_hash_cfg *cfg, const usize_t cksum) 98 | { 99 | return (cksum >> cfg->shift) ^ (cksum & cfg->mask); 100 | } 101 | 102 | /*********************************************************************** 103 | Cksum function 104 | ***********************************************************************/ 105 | 106 | #if ADLER_LARGE_CKSUM 107 | static inline uint32_t 108 | xd3_lcksum (const uint8_t *seg, const usize_t ln) 109 | { 110 | usize_t i = 0; 111 | uint32_t low = 0; 112 | uint32_t high = 0; 113 | 114 | for (; i < ln; i += 1) 115 | { 116 | low += PERMUTE(*seg++); 117 | high += low; 118 | } 119 | 120 | return ((high & 0xffff) << 16) | (low & 0xffff); 121 | } 122 | #else 123 | static inline uint32_t 124 | xd3_lcksum (const uint8_t *seg, const usize_t ln) 125 | { 126 | usize_t i, j; 127 | uint32_t h = 0; 128 | for (i = 0, j = ln - 1; i < ln; ++i, --j) { 129 | h += PERMUTE(seg[i]) * hash_multiplier_powers[j]; 130 | } 131 | return h; 132 | } 133 | #endif 134 | 135 | #if XD3_ENCODER 136 | static usize_t 137 | xd3_size_log2 (usize_t slots) 138 | { 139 | int bits = 28; /* This should not be an unreasonable limit. */ 140 | int i; 141 | 142 | for (i = 3; i <= bits; i += 1) 143 | { 144 | if (slots < (1U << i)) 145 | { 146 | /* TODO: this is compaction=1 in checksum_test.cc and maybe should 147 | * not be fixed at -1. */ 148 | bits = i - 1; 149 | break; 150 | } 151 | } 152 | 153 | return bits; 154 | } 155 | 156 | static void 157 | xd3_size_hashtable (xd3_stream *stream, 158 | usize_t slots, 159 | xd3_hash_cfg *cfg) 160 | { 161 | int bits = xd3_size_log2 (slots); 162 | 163 | /* TODO: there's a 32-bit assumption here */ 164 | cfg->size = (1 << bits); 165 | cfg->mask = (cfg->size - 1); 166 | cfg->shift = 32 - bits; 167 | } 168 | #endif 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3-internal.h: -------------------------------------------------------------------------------- 1 | /* xdelta3 - delta compression tools and library 2 | * Copyright (C) 2011, 2012 Joshua P. MacDonald 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | #ifndef XDELTA3_INTERNAL_H__ 19 | #define XDELTA3_INTERNAL_H__ 20 | 21 | #include "xdelta3.h" 22 | 23 | typedef struct _main_file main_file; 24 | typedef struct _main_extcomp main_extcomp; 25 | 26 | void main_buffree (void *ptr); 27 | void* main_bufalloc (size_t size); 28 | void main_file_init (main_file *xfile); 29 | int main_file_close (main_file *xfile); 30 | void main_file_cleanup (main_file *xfile); 31 | int main_file_isopen (main_file *xfile); 32 | int main_file_open (main_file *xfile, const char* name, int mode); 33 | int main_file_exists (main_file *xfile); 34 | int xd3_whole_append_window (xd3_stream *stream); 35 | int xd3_main_cmdline (int argc, char **argv); 36 | int main_file_read (main_file *ifile, 37 | uint8_t *buf, 38 | size_t size, 39 | size_t *nread, 40 | const char *msg); 41 | int main_file_write (main_file *ofile, uint8_t *buf, 42 | usize_t size, const char *msg); 43 | usize_t xd3_bytes_on_srcblk (xd3_source *src, xoff_t blkno); 44 | xoff_t xd3_source_eof(const xd3_source *src); 45 | uint32_t xd3_large_cksum_update (uint32_t cksum, 46 | const uint8_t *base, 47 | usize_t look); 48 | int xd3_encode_init_full (xd3_stream *stream); 49 | #if PYTHON_MODULE || SWIG_MODULE || NOT_MAIN 50 | int xd3_main_cmdline (int argc, char **argv); 51 | #endif 52 | 53 | /* main_file->mode values */ 54 | typedef enum 55 | { 56 | XO_READ = 0, 57 | XO_WRITE = 1 58 | } main_file_modes; 59 | 60 | struct _main_file 61 | { 62 | #if XD3_STDIO 63 | FILE *file; 64 | #elif XD3_POSIX 65 | int file; 66 | #elif XD3_WIN32 67 | HANDLE file; 68 | #endif 69 | 70 | int mode; /* XO_READ and XO_WRITE */ 71 | const char *filename; /* File name or /dev/stdin, 72 | * /dev/stdout, /dev/stderr. */ 73 | char *filename_copy; /* File name or /dev/stdin, 74 | * /dev/stdout, /dev/stderr. */ 75 | const char *realname; /* File name or /dev/stdin, 76 | * /dev/stdout, /dev/stderr. */ 77 | const main_extcomp *compressor; /* External compression struct. */ 78 | int flags; /* RD_FIRST, RD_NONEXTERNAL, ... */ 79 | xoff_t nread; /* for input position */ 80 | xoff_t nwrite; /* for output position */ 81 | uint8_t *snprintf_buf; /* internal snprintf() use */ 82 | int size_known; /* Set by main_set_souze */ 83 | xoff_t source_position; /* for avoiding seek in getblk_func */ 84 | int seek_failed; /* after seek fails once, try FIFO */ 85 | }; 86 | 87 | /* According to the internet, Windows vsnprintf() differs from most 88 | * Unix implementations regarding the terminating 0 when the boundary 89 | * condition is met. It doesn't matter here, we don't rely on the 90 | * trailing 0. Besides, both Windows and DJGPP vsnprintf return -1 91 | * upon truncation, which isn't C99 compliant. To overcome this, 92 | * recent MinGW runtimes provided their own vsnprintf (notice the 93 | * absence of the '_' prefix) but they were initially buggy. So, 94 | * always use the native '_'-prefixed version with Win32. */ 95 | #ifdef _WIN32 96 | #define vsnprintf_func(str,size,fmt,args) \ 97 | _vsnprintf_s(str,size,size-1,fmt,args) 98 | #define snprintf_func(str,size,fmt,...) \ 99 | _snprintf_s(str,size,size-1,fmt,__VA_ARGS__) 100 | #else 101 | #define vsnprintf_func vsnprintf 102 | #define snprintf_func snprintf 103 | #endif 104 | #define short_sprintf(sb,fmt,...) \ 105 | snprintf_func((sb).buf,sizeof((sb).buf),fmt,__VA_ARGS__) 106 | 107 | /* Type used for short snprintf calls. */ 108 | typedef struct { 109 | char buf[48]; 110 | } shortbuf; 111 | 112 | /* Prior to SVN 303 this function was only defined in DJGPP and WIN32 113 | * environments and other platforms would use the builtin snprintf() 114 | * with an arrangement of macros below. In OS X 10.6, Apply made 115 | * snprintf() a macro, which defeated those macros (since snprintf 116 | * would be evaluated before its argument macros were expanded, 117 | * therefore always define xsnprintf_func. */ 118 | #undef PRINTF_ATTRIBUTE 119 | #ifdef __GNUC__ 120 | /* Let's just assume no one uses gcc 2.x! */ 121 | #define PRINTF_ATTRIBUTE(x,y) __attribute__ ((__format__ (__printf__, x, y))) 122 | #else 123 | #define PRINTF_ATTRIBUTE(x,y) 124 | #endif 125 | 126 | /* Underlying xprintf() */ 127 | int xsnprintf_func (char *str, int n, const char *fmt, ...) 128 | PRINTF_ATTRIBUTE(3,4); 129 | 130 | /* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */ 131 | void xprintf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2); 132 | #define XPR xprintf 133 | #define NT "xdelta3: " 134 | #define NTR "" 135 | 136 | #ifndef UINT32_MAX 137 | #define UINT32_MAX 4294967295U 138 | #endif 139 | 140 | #ifndef UINT64_MAX 141 | #define UINT64_MAX 18446744073709551615ULL 142 | #endif 143 | 144 | #endif // XDELTA3_INTERNAL_H__ 145 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3-list.h: -------------------------------------------------------------------------------- 1 | /* xdelta 3 - delta compression tools and library 2 | * Copyright (C) 2002, 2006, 2007. Joshua P. MacDonald 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef __XDELTA3_LIST__ 20 | #define __XDELTA3_LIST__ 21 | 22 | #define XD3_MAKELIST(LTYPE,ETYPE,LNAME) \ 23 | \ 24 | static inline ETYPE* \ 25 | LTYPE ## _entry (LTYPE* l) \ 26 | { \ 27 | return (ETYPE*) ((char*) l - (ptrdiff_t) &((ETYPE*) 0)->LNAME); \ 28 | } \ 29 | \ 30 | static inline void \ 31 | LTYPE ## _init (LTYPE *l) \ 32 | { \ 33 | l->next = l; \ 34 | l->prev = l; \ 35 | } \ 36 | \ 37 | static inline void \ 38 | LTYPE ## _add (LTYPE *prev, LTYPE *next, LTYPE *ins) \ 39 | { \ 40 | next->prev = ins; \ 41 | prev->next = ins; \ 42 | ins->next = next; \ 43 | ins->prev = prev; \ 44 | } \ 45 | \ 46 | static inline void \ 47 | LTYPE ## _push_back (LTYPE *l, ETYPE *i) \ 48 | { \ 49 | LTYPE ## _add (l->prev, l, & i->LNAME); \ 50 | } \ 51 | \ 52 | static inline void \ 53 | LTYPE ## _del (LTYPE *next, \ 54 | LTYPE *prev) \ 55 | { \ 56 | next->prev = prev; \ 57 | prev->next = next; \ 58 | } \ 59 | \ 60 | static inline ETYPE* \ 61 | LTYPE ## _remove (ETYPE *f) \ 62 | { \ 63 | LTYPE *i = f->LNAME.next; \ 64 | LTYPE ## _del (f->LNAME.next, f->LNAME.prev); \ 65 | return LTYPE ## _entry (i); \ 66 | } \ 67 | \ 68 | static inline ETYPE* \ 69 | LTYPE ## _pop_back (LTYPE *l) \ 70 | { \ 71 | LTYPE *i = l->prev; \ 72 | LTYPE ## _del (i->next, i->prev); \ 73 | return LTYPE ## _entry (i); \ 74 | } \ 75 | \ 76 | static inline ETYPE* \ 77 | LTYPE ## _pop_front (LTYPE *l) \ 78 | { \ 79 | LTYPE *i = l->next; \ 80 | LTYPE ## _del (i->next, i->prev); \ 81 | return LTYPE ## _entry (i); \ 82 | } \ 83 | \ 84 | static inline int \ 85 | LTYPE ## _empty (LTYPE *l) \ 86 | { \ 87 | return l == l->next; \ 88 | } \ 89 | \ 90 | static inline ETYPE* \ 91 | LTYPE ## _front (LTYPE *f) \ 92 | { \ 93 | return LTYPE ## _entry (f->next); \ 94 | } \ 95 | \ 96 | static inline ETYPE* \ 97 | LTYPE ## _back (LTYPE *f) \ 98 | { \ 99 | return LTYPE ## _entry (f->prev); \ 100 | } \ 101 | \ 102 | static inline int \ 103 | LTYPE ## _end (LTYPE *f, ETYPE *i) \ 104 | { \ 105 | return f == & i->LNAME; \ 106 | } \ 107 | \ 108 | static inline ETYPE* \ 109 | LTYPE ## _next (ETYPE *f) \ 110 | { \ 111 | return LTYPE ## _entry (f->LNAME.next); \ 112 | } \ 113 | \ 114 | static inline usize_t \ 115 | LTYPE ## _length (LTYPE *l) \ 116 | { \ 117 | LTYPE *p; \ 118 | int c = 0; \ 119 | \ 120 | for (p = l->next; p != l; p = p->next) \ 121 | { \ 122 | c += 1; \ 123 | } \ 124 | \ 125 | return c; \ 126 | } \ 127 | \ 128 | typedef int unused_ ## LTYPE 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3-lzma.h: -------------------------------------------------------------------------------- 1 | /* xdelta 3 - delta compression tools and library 2 | * Copyright (C) 2012. Joshua P. MacDonald 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | /* Note: The use of the _easy_ decoder means we're not calling the 20 | * xd3_stream malloc hooks. TODO(jmacd) Fix if anyone cares. */ 21 | 22 | #ifndef _XDELTA3_LZMA_H_ 23 | #define _XDELTA3_LZMA_H_ 24 | 25 | #include 26 | 27 | typedef struct _xd3_lzma_stream xd3_lzma_stream; 28 | 29 | struct _xd3_lzma_stream { 30 | lzma_stream lzma; 31 | }; 32 | 33 | xd3_sec_stream* 34 | xd3_lzma_alloc (xd3_stream *stream) 35 | { 36 | return (xd3_sec_stream*) xd3_alloc (stream, sizeof (xd3_lzma_stream), 1); 37 | } 38 | 39 | void 40 | xd3_lzma_destroy (xd3_stream *stream, xd3_sec_stream *sec_stream) 41 | { 42 | xd3_lzma_stream *ls = (xd3_lzma_stream*) sec_stream; 43 | lzma_end (&ls->lzma); 44 | xd3_free (stream, ls); 45 | } 46 | 47 | int 48 | xd3_lzma_init (xd3_stream *stream, xd3_lzma_stream *sec, int is_encode) 49 | { 50 | int ret; 51 | 52 | memset (&sec->lzma, 0, sizeof(sec->lzma)); 53 | 54 | if (is_encode) 55 | { 56 | int level = (stream->flags & XD3_COMPLEVEL_MASK) >> XD3_COMPLEVEL_SHIFT; 57 | 58 | ret = lzma_easy_encoder (&sec->lzma, level, LZMA_CHECK_CRC32); 59 | } 60 | else 61 | { 62 | ret = lzma_stream_decoder (&sec->lzma, UINT64_MAX, 0); 63 | } 64 | 65 | if (ret != LZMA_OK) 66 | { 67 | stream->msg = "lzma stream init failed"; 68 | return XD3_INTERNAL; 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | int xd3_decode_lzma (xd3_stream *stream, xd3_lzma_stream *sec, 75 | const uint8_t **input_pos, 76 | const uint8_t *const input_end, 77 | uint8_t **output_pos, 78 | const uint8_t *const output_end) 79 | { 80 | uint8_t *output = *output_pos; 81 | const uint8_t *input = *input_pos; 82 | size_t avail_in = input_end - input; 83 | size_t avail_out = output_end - output; 84 | 85 | sec->lzma.avail_in = avail_in; 86 | sec->lzma.next_in = input; 87 | sec->lzma.avail_out = avail_out; 88 | sec->lzma.next_out = output; 89 | 90 | while (sec->lzma.avail_in != 0 || sec->lzma.avail_out != 0) 91 | { 92 | int lret = lzma_code (&sec->lzma, LZMA_FINISH); 93 | 94 | if (sec->lzma.avail_out == 0 || lret == LZMA_STREAM_END) 95 | { 96 | (*output_pos) = sec->lzma.next_out; 97 | (*input_pos) = sec->lzma.next_in; 98 | } 99 | 100 | switch (lret) 101 | { 102 | case LZMA_STREAM_END: 103 | return 0; 104 | case LZMA_OK: 105 | break; 106 | 107 | default: 108 | stream->msg = "lzma decoding error"; 109 | return XD3_INTERNAL; 110 | } 111 | } 112 | 113 | return 0; 114 | } 115 | 116 | #if XD3_ENCODER 117 | 118 | int xd3_encode_lzma (xd3_stream *stream, 119 | xd3_lzma_stream *sec, 120 | xd3_output *input, 121 | xd3_output *output, 122 | xd3_sec_cfg *cfg) 123 | 124 | { 125 | lzma_action action = LZMA_RUN; 126 | 127 | sec->lzma.next_in = NULL; 128 | sec->lzma.avail_in = 0; 129 | sec->lzma.next_out = (output->base + output->next); 130 | sec->lzma.avail_out = (output->avail - output->next); 131 | 132 | while (1) 133 | { 134 | int lret; 135 | 136 | if (sec->lzma.avail_in == 0 && input != NULL) 137 | { 138 | sec->lzma.avail_in = input->next; 139 | sec->lzma.next_in = input->base; 140 | 141 | if ((input = input->next_page) == NULL) 142 | { 143 | action = LZMA_SYNC_FLUSH; 144 | } 145 | } 146 | 147 | lret = lzma_code (&sec->lzma, action); 148 | 149 | if (sec->lzma.avail_out == 0 || lret == LZMA_STREAM_END) 150 | { 151 | size_t nwrite = (output->avail - output->next) - sec->lzma.avail_out; 152 | output->next += nwrite; 153 | 154 | if (output->next == output->avail) 155 | { 156 | if ((output = xd3_alloc_output (stream, output)) == NULL) 157 | { 158 | return ENOMEM; 159 | } 160 | 161 | sec->lzma.next_out = output->base; 162 | sec->lzma.avail_out = output->avail; 163 | } 164 | } 165 | 166 | switch (lret) 167 | { 168 | case LZMA_OK: 169 | break; 170 | 171 | case LZMA_STREAM_END: 172 | return 0; 173 | 174 | default: 175 | stream->msg = "lzma encoding error"; 176 | return XD3_INTERNAL; 177 | } 178 | } 179 | 180 | return 0; 181 | } 182 | 183 | #endif /* XD3_ENCODER */ 184 | 185 | #endif /* _XDELTA3_LZMA_H_ */ 186 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3-second.h: -------------------------------------------------------------------------------- 1 | /* xdelta 3 - delta compression tools and library 2 | * Copyright (C) 2002, 2003, 2006, 2007. Joshua P. MacDonald 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef _XDELTA3_SECOND_H_ 20 | #define _XDELTA3_SECOND_H_ 21 | 22 | static inline void xd3_bit_state_encode_init (bit_state *bits) 23 | { 24 | bits->cur_byte = 0; 25 | bits->cur_mask = 1; 26 | } 27 | 28 | static inline int xd3_decode_bits (xd3_stream *stream, 29 | bit_state *bits, 30 | const uint8_t **input, 31 | const uint8_t *input_max, 32 | usize_t nbits, 33 | usize_t *valuep) 34 | { 35 | usize_t value = 0; 36 | usize_t vmask = 1 << nbits; 37 | 38 | if (bits->cur_mask == 0x100) { goto next_byte; } 39 | 40 | for (;;) 41 | { 42 | do 43 | { 44 | vmask >>= 1; 45 | 46 | if (bits->cur_byte & bits->cur_mask) 47 | { 48 | value |= vmask; 49 | } 50 | 51 | bits->cur_mask <<= 1; 52 | 53 | if (vmask == 1) { goto done; } 54 | } 55 | while (bits->cur_mask != 0x100); 56 | 57 | next_byte: 58 | 59 | if (*input == input_max) 60 | { 61 | stream->msg = "secondary decoder end of input"; 62 | return XD3_INTERNAL; 63 | } 64 | 65 | bits->cur_byte = *(*input)++; 66 | bits->cur_mask = 1; 67 | } 68 | 69 | done: 70 | 71 | IF_DEBUG2 (DP(RINT "(d) %u ", value)); 72 | 73 | (*valuep) = value; 74 | return 0; 75 | } 76 | 77 | #if REGRESSION_TEST 78 | /* There may be extra bits at the end of secondary decompression, this macro 79 | * checks for non-zero bits. This is overly strict, but helps pass the 80 | * single-bit-error regression test. */ 81 | static int 82 | xd3_test_clean_bits (xd3_stream *stream, bit_state *bits) 83 | { 84 | for (; bits->cur_mask != 0x100; bits->cur_mask <<= 1) 85 | { 86 | if (bits->cur_byte & bits->cur_mask) 87 | { 88 | stream->msg = "secondary decoder garbage"; 89 | return XD3_INTERNAL; 90 | } 91 | } 92 | 93 | return 0; 94 | } 95 | #endif 96 | 97 | static int 98 | xd3_get_secondary (xd3_stream *stream, xd3_sec_stream **sec_streamp, 99 | int is_encode) 100 | { 101 | if (*sec_streamp == NULL) 102 | { 103 | int ret; 104 | 105 | if ((*sec_streamp = stream->sec_type->alloc (stream)) == NULL) 106 | { 107 | stream->msg = "error initializing secondary stream"; 108 | return XD3_INVALID; 109 | } 110 | 111 | if ((ret = stream->sec_type->init (stream, *sec_streamp, is_encode)) != 0) 112 | { 113 | return ret; 114 | } 115 | } 116 | 117 | return 0; 118 | } 119 | 120 | static int 121 | xd3_decode_secondary (xd3_stream *stream, 122 | xd3_desect *sect, 123 | xd3_sec_stream **sec_streamp) 124 | { 125 | uint32_t dec_size; 126 | uint8_t *out_used; 127 | int ret; 128 | 129 | if ((ret = xd3_get_secondary (stream, sec_streamp, 0)) != 0) 130 | { 131 | return ret; 132 | } 133 | 134 | /* Decode the size, allocate the buffer. */ 135 | if ((ret = xd3_read_size (stream, & sect->buf, 136 | sect->buf_max, & dec_size)) || 137 | (ret = xd3_decode_allocate (stream, dec_size, 138 | & sect->copied2, & sect->alloc2))) 139 | { 140 | return ret; 141 | } 142 | 143 | out_used = sect->copied2; 144 | 145 | if ((ret = stream->sec_type->decode (stream, *sec_streamp, 146 | & sect->buf, sect->buf_max, 147 | & out_used, out_used + dec_size))) 148 | { 149 | return ret; 150 | } 151 | 152 | if (sect->buf != sect->buf_max) 153 | { 154 | stream->msg = "secondary decoder finished with unused input"; 155 | return XD3_INTERNAL; 156 | } 157 | 158 | if (out_used != sect->copied2 + dec_size) 159 | { 160 | stream->msg = "secondary decoder short output"; 161 | return XD3_INTERNAL; 162 | } 163 | 164 | sect->buf = sect->copied2; 165 | sect->buf_max = sect->copied2 + dec_size; 166 | sect->size = dec_size; 167 | 168 | return 0; 169 | } 170 | 171 | #if XD3_ENCODER 172 | static inline int xd3_encode_bit (xd3_stream *stream, 173 | xd3_output **output, 174 | bit_state *bits, 175 | usize_t bit) 176 | { 177 | int ret; 178 | 179 | if (bit) 180 | { 181 | bits->cur_byte |= bits->cur_mask; 182 | } 183 | 184 | /* OPT: Might help to buffer more than 8 bits at once. */ 185 | if (bits->cur_mask == 0x80) 186 | { 187 | if ((ret = xd3_emit_byte (stream, output, bits->cur_byte)) != 0) 188 | { 189 | return ret; 190 | } 191 | 192 | bits->cur_mask = 1; 193 | bits->cur_byte = 0; 194 | } 195 | else 196 | { 197 | bits->cur_mask <<= 1; 198 | } 199 | 200 | return 0; 201 | } 202 | 203 | static inline int xd3_flush_bits (xd3_stream *stream, 204 | xd3_output **output, 205 | bit_state *bits) 206 | { 207 | return (bits->cur_mask == 1) ? 0 : 208 | xd3_emit_byte (stream, output, bits->cur_byte); 209 | } 210 | 211 | static inline int xd3_encode_bits (xd3_stream *stream, 212 | xd3_output **output, 213 | bit_state *bits, 214 | usize_t nbits, 215 | usize_t value) 216 | { 217 | int ret; 218 | usize_t mask = 1 << nbits; 219 | 220 | XD3_ASSERT (nbits > 0); 221 | XD3_ASSERT (nbits < sizeof (usize_t) * 8); 222 | XD3_ASSERT (value < mask); 223 | 224 | do 225 | { 226 | mask >>= 1; 227 | 228 | if ((ret = xd3_encode_bit (stream, output, bits, value & mask))) 229 | { 230 | return ret; 231 | } 232 | } 233 | while (mask != 1); 234 | 235 | IF_DEBUG2 (DP(RINT "(e) %u ", value)); 236 | 237 | return 0; 238 | } 239 | 240 | static int 241 | xd3_encode_secondary (xd3_stream *stream, 242 | xd3_output **head, 243 | xd3_output **tail, 244 | xd3_sec_stream **sec_streamp, 245 | xd3_sec_cfg *cfg, 246 | int *did_it) 247 | { 248 | xd3_output *tmp_head; 249 | xd3_output *tmp_tail; 250 | 251 | usize_t comp_size; 252 | usize_t orig_size; 253 | 254 | int ret; 255 | 256 | orig_size = xd3_sizeof_output (*head); 257 | 258 | if (orig_size < SECONDARY_MIN_INPUT) { return 0; } 259 | 260 | if ((ret = xd3_get_secondary (stream, sec_streamp, 1)) != 0) 261 | { 262 | return ret; 263 | } 264 | 265 | tmp_head = xd3_alloc_output (stream, NULL); 266 | 267 | /* Encode the size, encode the data. Encoding the size makes it 268 | * simpler, but is a little gross. Should not need the entire 269 | * section in contiguous memory, but it is much easier this way. */ 270 | if ((ret = xd3_emit_size (stream, & tmp_head, orig_size)) || 271 | (ret = stream->sec_type->encode (stream, *sec_streamp, *head, 272 | tmp_head, cfg))) 273 | { 274 | goto getout; 275 | } 276 | 277 | /* If the secondary compressor determines it's no good, it returns 278 | * XD3_NOSECOND. */ 279 | 280 | /* Setup tmp_tail, comp_size */ 281 | tmp_tail = tmp_head; 282 | comp_size = tmp_head->next; 283 | 284 | while (tmp_tail->next_page != NULL) 285 | { 286 | tmp_tail = tmp_tail->next_page; 287 | comp_size += tmp_tail->next; 288 | } 289 | 290 | XD3_ASSERT (comp_size == xd3_sizeof_output (tmp_head)); 291 | XD3_ASSERT (tmp_tail != NULL); 292 | 293 | if (comp_size < (orig_size - SECONDARY_MIN_SAVINGS)) 294 | { 295 | IF_DEBUG1(DP(RINT "secondary saved %u bytes: %u -> %u (%0.2f%%)\n", 296 | orig_size - comp_size, orig_size, comp_size, 297 | 100.0 * (double) comp_size / (double) orig_size)); 298 | 299 | xd3_free_output (stream, *head); 300 | 301 | *head = tmp_head; 302 | *tail = tmp_tail; 303 | *did_it = 1; 304 | } 305 | else 306 | { 307 | getout: 308 | if (ret == XD3_NOSECOND) { ret = 0; } 309 | xd3_free_output (stream, tmp_head); 310 | } 311 | 312 | return ret; 313 | } 314 | #endif /* XD3_ENCODER */ 315 | #endif /* _XDELTA3_SECOND_H_ */ 316 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3.1: -------------------------------------------------------------------------------- 1 | .TH XDELTA3 "1" "August 2009" "Xdelta3" 2 | .SH NAME 3 | xdelta3 \- VCDIFF (RFC 3284) binary diff tool 4 | .SH SYNOPSIS 5 | .B xdelta3 6 | .RI [ command ] 7 | .RI [ options ] 8 | .RI [ input 9 | .RI [ output ]] 10 | .SH DESCRIPTION 11 | .B xdelta3 12 | is a binary diff tool that uses the VCDIFF (RFC 3284) format and compression. 13 | .SH COMMANDS 14 | .TP 15 | .BI config 16 | prints xdelta3 configuration 17 | .TP 18 | .BI decode 19 | decompress the input, also set by -d 20 | .TP 21 | .BI encode 22 | compress the input, also set by -e (default) 23 | .TP 24 | .BI test 25 | run the builtin tests 26 | .TP 27 | .BI printdelta 28 | print information about the entire delta 29 | .TP 30 | .BI printhdr 31 | print information about the first window 32 | .TP 33 | .BI printhdrs 34 | print information about all windows 35 | .TP 36 | .BI recode 37 | encode with new application/secondary settings 38 | 39 | .SH OPTIONS 40 | standard options: 41 | .TP 42 | .BI "\-0 .. \-9" 43 | compression level 44 | .TP 45 | .BI "\-c" 46 | use stdout 47 | .TP 48 | .BI "\-d" 49 | decompress 50 | .TP 51 | .BI \-e 52 | compress 53 | .TP 54 | .BI \-f 55 | force overwrite 56 | .TP 57 | .BI \-h 58 | show help 59 | .TP 60 | .BI \-q 61 | be quiet 62 | .TP 63 | .BI \-v 64 | be verbose (max 2) 65 | .TP 66 | .BI \-V 67 | show version 68 | 69 | .TP 70 | memory options: 71 | .TP 72 | .BI \-B 73 | .RI bytes 74 | source window size 75 | .TP 76 | .BI \-W 77 | .RI bytes 78 | input window size 79 | .TP 80 | .BI \-P 81 | .RI size 82 | compression duplicates window 83 | .TP 84 | .BI \-I 85 | .RI size 86 | instruction buffer size (0 = unlimited) 87 | 88 | .TP 89 | compression options: 90 | .TP 91 | .BI \-s 92 | .RI source 93 | source file to copy from (if any) 94 | .TP 95 | .BI "\-S " [djw|fgk] 96 | enable/disable secondary compression 97 | .TP 98 | .BI \-N 99 | disable small string-matching compression 100 | .TP 101 | .BI \-D 102 | disable external decompression (encode/decode) 103 | .TP 104 | .BI \-R 105 | disable external recompression (decode) 106 | .TP 107 | .BI \-n 108 | disable checksum (encode/decode) 109 | .TP 110 | .BI \-C 111 | soft config (encode, undocumented) 112 | .TP 113 | .BI "\-A " [apphead] 114 | disable/provide application header (encode) 115 | .TP 116 | .BI \-J 117 | disable output (check/compute only) 118 | .TP 119 | .BI \-T 120 | use alternate code table (test) 121 | 122 | .SH NOTES 123 | The 124 | .B XDELTA 125 | environment variable may contain extra args: 126 | 127 | .RS 128 | XDELTA="-s source-x.y.tar.gz" \\ 129 | .br 130 | tar --use-compress-program=xdelta3 -cf \\ 131 | .br 132 | target-x.z.tar.gz.vcdiff target-x.y/ 133 | 134 | .SH EXAMPLES 135 | 136 | Compress the differences between SOURCE and TARGET, yielding OUT, 137 | using "djw" secondary compression: 138 | 139 | xdelta3 -S djw -s SOURCE TARGET OUT 140 | 141 | Do the same, using standard input and output: 142 | 143 | xdelta3 -S djw -s SOURCE < TARGET > OUT 144 | 145 | To decompress OUT, using SOURCE, yielding TARGET: 146 | 147 | xdelta3 -d -s SOURCE OUT TARGET 148 | 149 | .SH AUTHOR 150 | xdelta3 was written by Josh MacDonald . 151 | .PP 152 | This manual page was written by Leo 'costela' Antunes 153 | for the Debian project (but may be used by others). 154 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3.i: -------------------------------------------------------------------------------- 1 | %module xdelta3 2 | %import cstring.i 3 | %import argcargv.i 4 | %{ 5 | #include "xdelta3.h" 6 | 7 | int xd3_main_cmdline (int ARGC, char **ARGV); 8 | %} 9 | 10 | %cstring_input_binary(const char *input, unsigned int input_size); 11 | %cstring_input_binary(const char *source, unsigned int source_size); 12 | 13 | %define %max_output_withsize(TYPEMAP, SIZE, MAXSIZE) 14 | %typemap(in) MAXSIZE (unsigned int alloc_size) { 15 | $1 = alloc_size = PyInt_AsLong(obj2); 16 | } 17 | %typemap(in,numinputs=0) (TYPEMAP, SIZE) { 18 | } 19 | %typemap(check) (TYPEMAP, SIZE) { 20 | // alloc_size input is #7th position in xd3_xxcode_memory() 21 | $1 = malloc(alloc_size7); 22 | $2 = &alloc_size7; 23 | } 24 | %typemap(argout,fragment="t_output_helper") (TYPEMAP, SIZE) { 25 | if (result == 0) { 26 | PyObject *o; 27 | // alloc_size7 now carries actual size 28 | o = PyString_FromStringAndSize($1,alloc_size7); 29 | $result = t_output_helper($result,o); 30 | } else { 31 | $result = t_output_helper($result,Py_None); 32 | } 33 | free($1); 34 | } 35 | %typemap(default) int flags { 36 | $1 = 0; 37 | } 38 | %enddef 39 | 40 | %max_output_withsize(char *output_buf, unsigned int *output_size, unsigned int max_output); 41 | 42 | int xd3_encode_memory (const uint8_t *input, 43 | usize_t input_size, 44 | const uint8_t *source, 45 | usize_t source_size, 46 | uint8_t *output_buffer, 47 | usize_t *output_size, 48 | usize_t avail_output, 49 | int flags); 50 | 51 | int xd3_decode_memory (const uint8_t *input, 52 | usize_t input_size, 53 | const uint8_t *source, 54 | usize_t source_size, 55 | uint8_t *output_buf, 56 | usize_t *output_size, 57 | usize_t avail_output, 58 | int flags); 59 | 60 | int xd3_main_cmdline (int ARGC, char **ARGV); 61 | 62 | /* Is this the right way? */ 63 | enum { 64 | /*XD3_JUST_HDR,*/ 65 | /*XD3_SKIP_WINDOW,*/ 66 | /*XD3_SKIP_EMIT,*/ 67 | /*XD3_FLUSH,*/ 68 | XD3_SEC_DJW, 69 | XD3_SEC_FGK, 70 | /*XD3_SEC_TYPE,*/ 71 | XD3_SEC_NODATA, 72 | XD3_SEC_NOINST, 73 | XD3_SEC_NOADDR, 74 | /*XD3_SEC_OTHER,*/ 75 | XD3_ADLER32, 76 | XD3_ADLER32_NOVER, 77 | XD3_ALT_CODE_TABLE, 78 | XD3_NOCOMPRESS, 79 | XD3_BEGREEDY, 80 | XD3_COMPLEVEL_SHIFT, 81 | XD3_COMPLEVEL_MASK, 82 | XD3_COMPLEVEL_1, 83 | XD3_COMPLEVEL_3, 84 | XD3_COMPLEVEL_6, 85 | XD3_COMPLEVEL_9, 86 | }; 87 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3.wxi: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Patch/jni/xdelta/xdelta3.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 20 | 21 | 24 | 25 | 26 | 27 | 29 | 30 | 32 | 38 | 39 | 40 | 41 | 43 | 49 | 54 | 55 | 56 | 57 | 59 | 65 | 70 | 71 | 72 | 73 | 75 | 81 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /Patch/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/libs/android-support-v4.jar -------------------------------------------------------------------------------- /Patch/libs/armeabi-v7a/libPatch.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/libs/armeabi-v7a/libPatch.so -------------------------------------------------------------------------------- /Patch/libs/armeabi/libPatch.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/libs/armeabi/libPatch.so -------------------------------------------------------------------------------- /Patch/libs/mips/libPatch.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/libs/mips/libPatch.so -------------------------------------------------------------------------------- /Patch/libs/x86/libPatch.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/libs/x86/libPatch.so -------------------------------------------------------------------------------- /Patch/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 | -------------------------------------------------------------------------------- /Patch/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-19 15 | -------------------------------------------------------------------------------- /Patch/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Patch/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Patch/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Patch/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmzy/androidXdelta/353b942b075b8d3d25aaedab50480518589609cd/Patch/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Patch/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Patch/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Patch/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Patch/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /Patch/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Patch/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Patch/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /Patch/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Patch 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /Patch/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Patch/src/com/morgoo/patch/MainActivity.java: -------------------------------------------------------------------------------- 1 | 2 | package com.morgoo.patch; 3 | 4 | import android.app.Activity; 5 | import android.os.Bundle; 6 | import android.view.Menu; 7 | 8 | public class MainActivity extends Activity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | Patch.test(); 15 | } 16 | 17 | @Override 18 | public boolean onCreateOptionsMenu(Menu menu) { 19 | // Inflate the menu; this adds items to the action bar if it is present. 20 | getMenuInflater().inflate(R.menu.main, menu); 21 | return true; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Patch/src/com/morgoo/patch/Patch.java: -------------------------------------------------------------------------------- 1 | 2 | package com.morgoo.patch; 3 | 4 | import android.accounts.AccountsException; 5 | import android.util.AndroidRuntimeException; 6 | 7 | public class Patch { 8 | 9 | private static boolean sIsPatchLoaded = false; 10 | 11 | static { 12 | System.loadLibrary("Patch"); 13 | sIsPatchLoaded = true; 14 | } 15 | 16 | public static boolean isSoLoaded() { 17 | return sIsPatchLoaded; 18 | } 19 | 20 | public static void test() { 21 | 22 | } 23 | 24 | private final static native int nativePatch(int encode, String inPath, 25 | String srcPath, String outPath); 26 | 27 | public final static int patch(int encode, String inPath, 28 | String srcPath, String outPath) { 29 | if (sIsPatchLoaded) { 30 | return nativePatch(encode, inPath, srcPath, outPath); 31 | } else { 32 | throw new AndroidRuntimeException("Patch.so has not loaded"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | androidXdelta 2 | ============= 3 | 4 | xdelta3 so lib for android 5 | --------------------------------------------------------------------------------