├── .gitignore ├── LDRNDiffUpdate.podspec ├── LICENSE ├── README.md ├── android ├── .gitignore ├── build.gradle ├── libs │ ├── armeabi-v7a │ │ └── libApkPatchLibrary.so │ ├── armeabi │ │ └── libApkPatchLibrary.so │ └── x86 │ │ └── libApkPatchLibrary.so ├── proguard-rules.pro ├── react-native-diff-update.iml └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ ├── leadeon │ └── diffupdate │ │ ├── LeadeonDiff.java │ │ ├── bean │ │ └── checkversion │ │ │ ├── RnCheck.java │ │ │ ├── RnCheckRes.java │ │ │ ├── VersionReq.java │ │ │ └── VersionRes.java │ │ ├── downloader │ │ ├── CopyAndUnzipRes.java │ │ ├── CopyModule.java │ │ ├── RnModuleDiffUpdateManager.java │ │ ├── RnModuleDownloader.java │ │ └── RnVersionManager.java │ │ └── utils │ │ ├── AppUtils.java │ │ ├── FileMd5Utils.java │ │ ├── FileUtil.java │ │ ├── LogUtils.java │ │ ├── RNFilePathUtils.java │ │ └── okutil │ │ └── OkHttpManager.java │ └── yyh │ └── lib │ └── bsdiff │ └── PatchUtils.java ├── doc └── image │ └── ReactNativeDiffUpdate.png ├── ios ├── LDRNDiffUpdate.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── LDRNDiffUpdate │ ├── LDPatchFileManager.h │ ├── LDPatchFileManager.m │ ├── LDRNBundleList.h │ ├── LDRNBundleList.m │ ├── LDRNDiffUpdate.h │ ├── LDRNDiffUpdate.m │ ├── LDRNVersionManager.h │ ├── LDRNVersionManager.m │ ├── SSZipArchive │ ├── Common.h │ ├── README.md │ ├── SSZipArchive.h │ ├── SSZipArchive.m │ ├── aes │ │ ├── aes.h │ │ ├── aes_via_ace.h │ │ ├── aescrypt.c │ │ ├── aeskey.c │ │ ├── aesopt.h │ │ ├── aestab.c │ │ ├── aestab.h │ │ ├── brg_endian.h │ │ ├── brg_types.h │ │ ├── entropy.c │ │ ├── entropy.h │ │ ├── fileenc.c │ │ ├── fileenc.h │ │ ├── hmac.c │ │ ├── hmac.h │ │ ├── prng.c │ │ ├── prng.h │ │ ├── pwd2key.c │ │ ├── pwd2key.h │ │ ├── sha1.c │ │ └── sha1.h │ └── minizip │ │ ├── crypt.h │ │ ├── ioapi.c │ │ ├── ioapi.h │ │ ├── mztools.c │ │ ├── mztools.h │ │ ├── unzip.c │ │ ├── unzip.h │ │ ├── zip.c │ │ └── zip.h │ ├── bsdiff │ ├── bspatch.c │ └── bspatch.h │ └── md5 │ ├── FileHash.h │ └── FileHash.m ├── js └── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /LDRNDiffUpdate.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint react-native-diff-update.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | 11 | s.name = "LDRNDiffUpdate" 12 | s.version = "1.0.8" 13 | s.summary = "react native hot update." 14 | 15 | s.description = <<-DESC 16 | react native component for diff update. 17 | DESC 18 | 19 | s.homepage = "https://github.com/xuwening/LDReactNativeDiffUpdate.git" 20 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 21 | 22 | s.license = { :type => 'MIT', :file => 'LICENSE' } 23 | s.author = { "hongjingjun" => "hongjingjun@leadeon.cn" } 24 | 25 | # s.platform = :ios 26 | # s.platform = :ios, "5.0" 27 | s.ios.deployment_target = '8.0' 28 | 29 | s.library = 'z', 'bz2' 30 | s.dependency 'React' 31 | s.dependency 'SSZipArchive' 32 | 33 | 34 | s.source_files = 'ios/LDRNDiffUpdate/*.{h,m}', 'ios/LDRNDiffUpdate/bsdiff/*.{h,c}', 'ios/LDRNDiffUpdate/md5/*.{h,m}' 35 | s.public_header_files = ['ios/LDRNDiffUpdate/LDRNDiffUpdate.h', 'ios/LDRNDiffUpdate/LDRNBundleList.h'] 36 | 37 | # s.subspec 'Core' do |core| 38 | # core.source_files = 'ios/LDRNDiffUpdate/*.{h,m}' 39 | # core.public_header_files = ['ios/LDRNDiffUpdate/LDRNDiffUpdate.h'] 40 | # end 41 | 42 | # s.subspec 'SSZipArchive' do |ss| 43 | # ss.source_files = 'ios/LDRNDiffUpdate/SSZipArchive/*.{h,m}', 'ios/LDRNDiffUpdate/SSZipArchive/aes/*.{h,c}', 'ios/LDRNDiffUpdate/SSZipArchive/minizip/*.{h,c}' 44 | # ss.private_header_files = 'ios/LDRNDiffUpdate/SSZipArchive/*.h', 'ios/LDRNDiffUpdate/SSZipArchive/aes/*.h', 'ios/LDRNDiffUpdate/SSZipArchive/minizip/*.h' 45 | # end 46 | 47 | # s.subspec 'bspatch' do |bs| 48 | # bs.source_files = 'ios/LDRNDiffUpdate/bzip/*.{h,c}' 49 | # bs.private_header_files = 'ios/LDRNDiffUpdate/bzip/*.h' 50 | # end 51 | 52 | # s.subspec 'md5' do |md| 53 | # md.source_files = 'ios/LDRNDiffUpdate/md5/*.{h,m}' 54 | # md.private_header_files = 'ios/LDRNDiffUpdate/md5/*.h' 55 | # end 56 | 57 | s.source = { :git => "https://github.com/xuwening/LDReactNativeDiffUpdate.git", :tag => "#{s.version}" } 58 | 59 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave" 60 | 61 | # s.framework = "SomeFramework" 62 | # s.frameworks = "SomeFramework", "AnotherFramework" 63 | 64 | # s.library = "iconv" 65 | # s.libraries = "iconv", "xml2" 66 | 67 | 68 | end 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LDReactNativeDiffUpdate 2 | React native增量更新,支持多入口多业务。 3 | 4 | ## 更新(20171031) 5 | 6 | 后台雏形代码已经上传github: 7 | 8 | #### 开源的目的 9 | 10 | 目前业界还没有一款足够适应大部分增量更新场景的方案,要么不支持多业务入口,要么没有开源,要么没有开放后台源码。基于这些需求,我们想通过开源社区的力量,大家一起打造出比较完善易用的增量更新框架,因此,需要大家的参与及支持,为RN的生态系统做点儿小贡献(为了项目的灵活自由发展,我们采用了MIT许可)。 11 | 12 | * QQ交流群:**539533937** ReactNative热更新 13 | 14 | 15 | ![](./doc/image/ReactNativeDiffUpdate.png) 16 | 17 | 18 | 19 | ## 增量更新实现机制 20 | 21 | 目前增量更新采用native实现,后续会暴露功能接口,供js控制更新流程。 22 | 23 | 为了更好的用户体验,所有业务包进行工程内置,增量包后台下载合并操作,App下次启动更新生效(后续增加立即生效功能)。 24 | 25 | 增量算法采用bsdiff差异算法。 26 | 27 | ## 安装和使用 28 | 29 | 客户端与后台相对独立,可集成客户端增量更新模块,自己构建后台版本接口,也可采用我们后台框架搭建(暂时还未开源)。 30 | 31 | #### 安装增量更新 32 | 33 | 工程根目录执行: 34 | 35 | `npm install --save react-native-diff-update` 36 | 37 | `react-native link react-native-diff-update` 38 | 39 | 打开工程可以看到`Libraries`下`LDRNDiffUpdate`就是增量更新模块。 40 | 41 | ##### iOS Pod集成方式: 42 | 43 | `npm install --save react-native-diff-update` 44 | 45 | 在工程`Podfile`文件中加入: 46 | 47 | `pod 'LDRNDiffUpdate', :path => '../node_modules/react-native-diff-update'` 48 | 49 | 然后执行:`pod install` 50 | 51 | ##### SSZipArchive库冲突问题 52 | 53 | 假如原有工程已经存在SSZipArchive库,与本pod spec冲突,建议采用`v1.0.5`版本,此版本没有将SSZipArchive进行分离,因此更容易处理冲突问题,install时增加版本号: 54 | 55 | `npm install --save react-native-diff-update@v1.0.5` 56 | 57 | 这样集成到工程中时,只需要把原有工程SSZipArchive删除即可。至于SSZipArchive工程分离方式,目前没有找到比较好的方法,可以参见`code push`的处理方式也是这样。 58 | 59 | 60 | 61 | #### iOS使用方式 62 | 63 | 首先进行相关配置,配置信息在`LDRNBundleList.m`文件中,核心设置有: 64 | 65 | ```json 66 | appKey //应用唯一标识 67 | rnVersion //当前工程使用的React Native版本 68 | originBundles //工程内置的业务bundle 69 | originBundlesHash //业务bundle的md5 (可选) 70 | entryJSName //bundle入口文件名称 71 | patchFileName //补丁bundle入口文件名称 72 | versionUrl //版本请求接口地址 73 | ``` 74 | 75 | 配置信息不应该直接修改`LDRNBundleList.m`源文件,更合理的方式是创建`LDRNBundleList的分类`,当然只需设置需要项: 76 | 77 | ```objective-c 78 | @implementation LDRNBundleList (setting) 79 | 80 | +(NSString *) appKey { 81 | return @"11111111"; 82 | } 83 | 84 | +(NSString *) rnVersion { 85 | return @"0.48.3"; 86 | } 87 | 88 | +(NSDictionary *) originBundles { 89 | return @{ 90 | //首次集成置空 91 | }; 92 | } 93 | 94 | @end 95 | ``` 96 | 97 | > 注意首次集成时originBundles设置为空字典,否则在工程中找不到zip文件,会引起程序崩溃。等增加zip文件后再进行配置。 98 | 99 | 配置好信息后,在自己的需要加载bundle的`viewController`中引入头文件`#import "LDRNDiffUpdate.h"`,然后指定jsBundle文件名即可(每个jsBundle代表一个独立的业务): 100 | 101 | ```OC 102 | NSURL *jsCodeLocation = [LDRNDiffUpdate jsBundleUrl:@"LDBusinessEntry"]; 103 | ``` 104 | 105 | #### android使用方式 106 | 107 | 在Android中有时候npm 的link会不成功,这时可通过如下步骤进行配置: 108 | 109 | 找到 android/settings.gradle文件并添加: 110 | 111 | ```java 112 | include ':react-native-diff-update' 113 | project(':react-native-diff-update').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-diff-update/android') 114 | ``` 115 | 116 | 找到 android/app/build.gradle 文件并添加: 117 | 118 | ```java 119 | dependencies { 120 | compile project(':react-native-diff-update') 121 | } 122 | ``` 123 | 124 | 配置完后需要在应用启动的第一个Activity的onCreate方法中调用 125 | 126 | ```java 127 | LeadeonDiff.init(this, this); 128 | ``` 129 | 130 | > 第一个参数是应用程序的上下文,不能为null,第二个参数是CopyCompletedCallback接口的实现,当首次复制完assets目录下的rn模块后会回调此接口。 131 | 132 | 133 | 134 | ## 版本请求接口说明 135 | 136 | 每次启动app时,检测本地所有jsBundle是否有更新,如果有更新则根据下载条件浸没下载,再根据加载策略进行实时更新还是下次启动更新RN业务。也可以对有问题的jsBundle业务进行回滚操作。 137 | 138 | ```js 139 | 接口名称[POST]:/RN/patchVersion 140 | 141 | 请求body: 142 | { 143 | appKey: "", //app唯一标识 144 | appVersion: "", //app当前版本 145 | rnVersion: "", //react native集成版本 146 | platform: "", //平台ios android 147 | resBody: { 148 | "LDBizName1": "1.2.0", //业务名称: 版本号 149 | "LDBizName2": "1.1.0", 150 | ... 151 | } 152 | } 153 | 154 | 响应body: 155 | 156 | ```json 157 | { 158 | retCode: '000000', //响应码:000000代表成功,其他代表失败 159 | retDesc: 'xxx', //失败原因描述 160 | rspBody: [ 161 | { 162 | "loadType": "ReactNative", //业务类型:ReactNative、HybridApp 163 | "zipPath": "https://xx.xx.com/patchzip/LDBizModuleName1.zip", //下载路径 164 | "version": "1.3.0", //业务版本号 165 | "moduleName": "LDBizName1", //jsBundle名称 166 | "zipHash": "xxxxxx", //zip文件md5值 167 | "jsbundleHash": "xxxxxx", //差异合并后js文件md5值 168 | "downloadNow": "3", //0:总是下载, 1:wifi下载,2: 4g和wifi下载 169 | "loadNow": "true", //true:即刻更新,false:下次启动更新 170 | "needGoBack": "false", //是否需要回退版本 171 | }, 172 | 173 | ... 174 | ] 175 | } 176 | 177 | ``` 178 | 179 | ## 安全策略 180 | 181 | 增量更新安全主要涉及到jsBundle,jsBundle只是js代码,虽然经过混淆处理,但依然是纯明文,虽然可以对js做加密处理,但这种行为不太明智。 182 | 183 | 主要考虑以下安全因素: 184 | 185 | 1. 网络接口安全。这点其实和增量更新关系不大,版本接口复用原有后台安全策略即可。 186 | 187 | 2. jsBundle篡改安全。为防止篡改js入侵app业务,需对jsBundle做签名校验,一是下载文件后校验其完整性,二是每次加载jsBundle时校验,这样就防止了整条链路篡改风险。 188 | 189 | 3. jsBundle业务安全。因为jsBundle是明文,所以业务中需要进行加解密等敏感措施就不能在js侧实现,解决的办法是native实现加解密暴露给js接口调用。加解密可作为RN独立module实现,不在增量更新体现。 190 | 191 | 192 | ## Licence 193 | 194 | (MIT) 195 | 196 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.2' 9 | } 10 | } 11 | 12 | apply plugin: 'com.android.library' 13 | 14 | android { 15 | compileSdkVersion 25 16 | buildToolsVersion "25.0.3" 17 | 18 | defaultConfig { 19 | minSdkVersion 14 20 | targetSdkVersion 25 21 | versionCode 1 22 | versionName "1.0" 23 | 24 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 25 | 26 | } 27 | buildTypes { 28 | release { 29 | minifyEnabled false 30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 31 | } 32 | } 33 | 34 | sourceSets { 35 | main { 36 | jniLibs.srcDirs = ['libs'] 37 | } 38 | } 39 | android { 40 | lintOptions { 41 | abortOnError false 42 | warning 'InvalidPackage' 43 | } 44 | } 45 | 46 | } 47 | 48 | dependencies { 49 | compile fileTree(dir: 'libs', include: ['*.jar']) 50 | 51 | // From node_modules 52 | compile 'com.liulishuo.filedownloader:library:1.6.3' 53 | compile 'com.alibaba:fastjson:1.2.37' 54 | } 55 | -------------------------------------------------------------------------------- /android/libs/armeabi-v7a/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xagreenpoint/LDReactNativeDiffUpdate/e9a99e87ede1086652abec9c20092e4c88c1cd40/android/libs/armeabi-v7a/libApkPatchLibrary.so -------------------------------------------------------------------------------- /android/libs/armeabi/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xagreenpoint/LDReactNativeDiffUpdate/e9a99e87ede1086652abec9c20092e4c88c1cd40/android/libs/armeabi/libApkPatchLibrary.so -------------------------------------------------------------------------------- /android/libs/x86/libApkPatchLibrary.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xagreenpoint/LDReactNativeDiffUpdate/e9a99e87ede1086652abec9c20092e4c88c1cd40/android/libs/x86/libApkPatchLibrary.so -------------------------------------------------------------------------------- /android/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\androidSDK\adt-bundle-windows-x86_64-20140702\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /android/react-native-diff-update.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/LeadeonDiff.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate; 2 | 3 | import android.content.Context; 4 | 5 | import com.leadeon.diffupdate.downloader.RnModuleDiffUpdateManager; 6 | import com.leadeon.diffupdate.utils.RNFilePathUtils; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Lynn on 2017/9/1. 12 | */ 13 | 14 | public class LeadeonDiff { 15 | 16 | 17 | /** 18 | * 当首次复制assets中的模块完成时会 回调 19 | * CopyCompletedCallback 接口, 20 | * @param context 21 | * @param copyCompletedCallback 22 | */ 23 | public static void init(Context context,String appkey,String rnversion,String url,CopyCompletedCallback copyCompletedCallback) { 24 | if(context!=null){ 25 | new RnModuleDiffUpdateManager(context,appkey,rnversion,url,copyCompletedCallback).start(); 26 | }else { 27 | throw new NullPointerException("context is null ,please check your agent"); 28 | } 29 | } 30 | 31 | 32 | 33 | public static String getMoudleJsBundleFile( Context mcontext,String moudleName){ 34 | File indexFile=new File(RNFilePathUtils.getBundleFile(mcontext,moudleName)); 35 | if(indexFile.exists()){ 36 | return RNFilePathUtils.getBundleFile(mcontext,moudleName); 37 | }else { 38 | return RNFilePathUtils.getBaseBundleFile(mcontext,moudleName); 39 | } 40 | } 41 | 42 | 43 | public interface CopyCompletedCallback{ 44 | void onCompleted(); 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/bean/checkversion/RnCheck.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.bean.checkversion; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Lynn on 2017/12/5. 7 | */ 8 | 9 | public class RnCheck implements Serializable { 10 | 11 | private VersionReq reqBody=null; 12 | 13 | public VersionReq getReqBody() { 14 | return reqBody; 15 | } 16 | 17 | public void setReqBody(VersionReq reqBody) { 18 | this.reqBody = reqBody; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/bean/checkversion/RnCheckRes.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.bean.checkversion; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Lynn on 2017/8/17. 7 | */ 8 | 9 | public class RnCheckRes implements Serializable { 10 | private String loadType=null; //业务类型:ReactNative、HybridApp 11 | private String zipPath = null; //下载路径 12 | private String version = null; //业务版本号 13 | private String moduleName = null; //jsBundle名称 14 | private String zipHash = null; //zip文件md5值 15 | private String jsbundleHash = null; //差异合并后js文件md5值 16 | private String downloadNow=null; //0:总是下载, 1:wifi下载,2: 4g和wifi下载 17 | private String loadNow=null; //true:即刻更新,false:下次启动更新 18 | private String needGoBack=null; //是否需要回退版本 19 | 20 | 21 | public String getLoadType() { 22 | return loadType; 23 | } 24 | 25 | public void setLoadType(String loadType) { 26 | this.loadType = loadType; 27 | } 28 | 29 | public String getZipPath() { 30 | return zipPath; 31 | } 32 | 33 | public void setZipPath(String zipPath) { 34 | this.zipPath = zipPath; 35 | } 36 | 37 | public String getVersion() { 38 | return version; 39 | } 40 | 41 | public void setVersion(String version) { 42 | this.version = version; 43 | } 44 | 45 | public String getModuleName() { 46 | return moduleName; 47 | } 48 | 49 | public void setModuleName(String moduleName) { 50 | this.moduleName = moduleName; 51 | } 52 | 53 | public String getZipHash() { 54 | return zipHash; 55 | } 56 | 57 | public void setZipHash(String zipHash) { 58 | this.zipHash = zipHash; 59 | } 60 | 61 | public String getJsbundleHash() { 62 | return jsbundleHash; 63 | } 64 | 65 | public void setJsbundleHash(String jsbundleHash) { 66 | this.jsbundleHash = jsbundleHash; 67 | } 68 | 69 | public String getDownloadNow() { 70 | return downloadNow; 71 | } 72 | 73 | public void setDownloadNow(String downloadNow) { 74 | this.downloadNow = downloadNow; 75 | } 76 | 77 | public String getLoadNow() { 78 | return loadNow; 79 | } 80 | 81 | public void setLoadNow(String loadNow) { 82 | this.loadNow = loadNow; 83 | } 84 | 85 | public String getNeedGoBack() { 86 | return needGoBack; 87 | } 88 | 89 | public void setNeedGoBack(String needGoBack) { 90 | this.needGoBack = needGoBack; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/bean/checkversion/VersionReq.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.bean.checkversion; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashMap; 5 | 6 | /** 7 | * Created by Lynn on 2017/10/24. 8 | */ 9 | 10 | public class VersionReq implements Serializable { 11 | 12 | 13 | private String appKey=null; 14 | private String appVersion=null; 15 | private String platForm=null; 16 | private String rnVersion=null; 17 | private HashMap reqParam=null; 18 | 19 | 20 | public String getAppKey() { 21 | return appKey; 22 | } 23 | 24 | public void setAppKey(String appKey) { 25 | this.appKey = appKey; 26 | } 27 | 28 | public String getAppVersion() { 29 | return appVersion; 30 | } 31 | 32 | 33 | public String getPlatForm() { 34 | return platForm; 35 | } 36 | 37 | public void setPlatForm(String platForm) { 38 | this.platForm = platForm; 39 | } 40 | 41 | public void setAppVersion(String appVersion) { 42 | this.appVersion = appVersion; 43 | } 44 | 45 | 46 | public String getRnVersion() { 47 | return rnVersion; 48 | } 49 | 50 | public void setRnVersion(String rnVersion) { 51 | this.rnVersion = rnVersion; 52 | } 53 | 54 | public HashMap getReqParam() { 55 | return reqParam; 56 | } 57 | 58 | public void setReqParam(HashMap reqParam) { 59 | this.reqParam = reqParam; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/bean/checkversion/VersionRes.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.bean.checkversion; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by Lynn on 2017/10/24. 8 | */ 9 | 10 | public class VersionRes implements Serializable { 11 | 12 | private String retCode = null; 13 | private String retDesc = null; 14 | private List rspBody = null; 15 | 16 | public String getRetCode() { 17 | return retCode; 18 | } 19 | 20 | public void setRetCode(String retCode) { 21 | this.retCode = retCode; 22 | } 23 | 24 | public String getRetDesc() { 25 | return retDesc; 26 | } 27 | 28 | public void setRetDesc(String retDesc) { 29 | this.retDesc = retDesc; 30 | } 31 | 32 | public List getRspBody() { 33 | return rspBody; 34 | } 35 | 36 | public void setRspBody(List rspBody) { 37 | this.rspBody = rspBody; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/downloader/CopyAndUnzipRes.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.downloader; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | 6 | import com.leadeon.diffupdate.utils.FileUtil; 7 | import com.leadeon.diffupdate.utils.LogUtils; 8 | import com.leadeon.diffupdate.utils.RNFilePathUtils; 9 | 10 | import java.io.File; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * 此类主要用于 16 | * 复制上次合并的jsbundle文件 17 | * 解压上次下载的 18 | * zip文件 19 | * Created by Lynn on 2017/8/17. 20 | */ 21 | 22 | public class CopyAndUnzipRes { 23 | 24 | private Context context = null; 25 | 26 | 27 | public CopyAndUnzipRes(Context context){ 28 | if (this.context == null) { 29 | this.context = context.getApplicationContext(); 30 | } 31 | } 32 | 33 | 34 | 35 | public void start(Handler handler) { 36 | File file = new File(RNFilePathUtils.getBundleRootPath(this.context)); 37 | if (file.exists()) { 38 | if (file.isDirectory()) { 39 | List listMoudleName = new ArrayList<>(); 40 | File[] childFiles = file.listFiles(); 41 | for (int i = 0; i < childFiles.length; i++) { 42 | listMoudleName.add(childFiles[i].getName()); 43 | } 44 | if (listMoudleName.size() == 0) { 45 | handler.sendEmptyMessage(2); //表示完成了解压和复制 46 | LogUtils.writeLog("解压和复制bundle总耗时为: 没有可解压和复制的文件"); 47 | } else { 48 | //开启一个线程来进行文件操作 49 | startnewThread(listMoudleName,handler); 50 | } 51 | } 52 | }else { 53 | handler.sendEmptyMessage(2); //表示完成了解压和复制 54 | } 55 | } 56 | 57 | 58 | /** 59 | * 开启一个线程来 60 | * @param listMoudleName 61 | * @param handler 62 | */ 63 | private void startnewThread(final List listMoudleName, final Handler handler) { 64 | new Thread(new Runnable() { 65 | @Override 66 | public void run() { 67 | long time1=System.currentTimeMillis(); 68 | for (String moduleName : listMoudleName) { 69 | copyAndUnzip(moduleName); 70 | } 71 | long time2=System.currentTimeMillis(); 72 | LogUtils.writeLog("解压和复制bundle总耗时为:"+(time2-time1)); 73 | handler.sendEmptyMessage(2); //表示完成了解压和复制 74 | } 75 | }).start(); 76 | } 77 | 78 | 79 | /** 80 | * 将patch文件夹下的资源文件解压到index文件夹下 81 | * 将merge文件夹下的jsbundle复制到index文件夹下 82 | * @param moduleName 83 | */ 84 | private void copyAndUnzip(String moduleName) { 85 | File file = new File(RNFilePathUtils.getBundleMergeFile(this.context, moduleName)); 86 | if (file.exists()) { 87 | LogUtils.writeLog("存在可解压的文件以及需要复制的jsbundle"); 88 | FileUtil.unZipRes( 89 | RNFilePathUtils.getBundleZipFile(this.context, moduleName), 90 | RNFilePathUtils.getBundlePath(this.context, moduleName) 91 | ); //资源覆盖解压 92 | 93 | FileUtil.copyFile( 94 | RNFilePathUtils.getBundleMergeFile(this.context, moduleName), 95 | RNFilePathUtils.getBundleFile(this.context, moduleName) 96 | ); //复制合并后的jsbundle 97 | //此处应该读取版本信息存储在share文件中 98 | 99 | FileUtil.deleteAll(RNFilePathUtils.getBundleMergePath(this.context, moduleName)); //删除merge文件夹下的东西 100 | FileUtil.deleteAll(RNFilePathUtils.getBundlePatchPath(this.context, moduleName)); //删除patch文件夹下的东西 101 | 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/downloader/CopyModule.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.downloader; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | import android.os.Handler; 7 | 8 | import com.alibaba.fastjson.JSON; 9 | import com.leadeon.diffupdate.bean.checkversion.RnCheckRes; 10 | import com.leadeon.diffupdate.utils.FileUtil; 11 | import com.leadeon.diffupdate.utils.LogUtils; 12 | import com.leadeon.diffupdate.utils.RNFilePathUtils; 13 | 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.util.List; 17 | 18 | /** 19 | * 此模块主要用于从 assets目录下复制 20 | * 文件 21 | * Created by Lynn on 2017/8/20. 22 | */ 23 | 24 | public class CopyModule { 25 | 26 | 27 | private Context mContext=null; 28 | private RnVersionManager rnVersionManager=null; 29 | 30 | public CopyModule(Context context){ 31 | this.mContext=context; 32 | this.rnVersionManager=new RnVersionManager(context); 33 | } 34 | 35 | 36 | /** 37 | * 用于从assets文件夹下复制 rn的zip包 38 | * @param handler 39 | */ 40 | public void start(final Handler handler){ 41 | /** 42 | * 判断客户端是否进行了覆盖安装 43 | */ 44 | boolean mergedAssets =this.rnVersionManager.getSharedPreference().getString("lastVersion","").equals(getVersion(mContext)); 45 | if (!mergedAssets) { 46 | new Thread(new Runnable() { 47 | @Override 48 | public void run() { 49 | rnVersionManager.deleteRnDescription(); //清空在磁盘中保存的rn模块的版本信息 50 | merge(handler); 51 | } 52 | }).start(); 53 | }else { 54 | handler.sendEmptyMessage(1); //通知主线程不需要进行复制 55 | } 56 | } 57 | 58 | /** 59 | * 从assets目录下复制基础包 60 | * 基础包的个数和业务的个数一样 61 | * 有多少种业务包就有多少个基础包 62 | * @param handler 63 | */ 64 | private void merge(Handler handler){ 65 | long time1=System.currentTimeMillis(); 66 | 67 | try { //从配置文件中读取数据 68 | String rnConfig= FileUtil.readFile(this.mContext.getAssets().open("rn_base_model.json")); 69 | List rnCheckResList= JSON.parseArray(rnConfig,RnCheckRes.class); 70 | for (RnCheckRes rnCheckRes:rnCheckResList){ 71 | firstMergeAssets(rnCheckRes); 72 | } 73 | this.rnVersionManager.getSharedPreference().edit().putString("lastVersion",getVersion(mContext)).commit(); //保存客户端版本号 74 | } catch (IOException e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | handler.sendEmptyMessage(1); //通知主线程首次复制已完成 79 | long time2=System.currentTimeMillis(); 80 | LogUtils.writeLog("首次的复制总耗时为 "+(time2-time1)); 81 | } 82 | 83 | 84 | /** 85 | * 用于从assets文件夹下复制预埋的rn代码和资源的zip包 86 | * 87 | * @param rnCheckRes 88 | */ 89 | private void firstMergeAssets(RnCheckRes rnCheckRes) { 90 | String moduleName=rnCheckRes.getModuleName(); 91 | try { 92 | LogUtils.writeLog("开始复制 "); 93 | FileUtil.deleteAll(RNFilePathUtils.getBundleRootPath(this.mContext)); //删除rn_bundle目录下所有文件 94 | InputStream assestInput = this.mContext.getAssets().open(moduleName+".zip"); 95 | String dest = RNFilePathUtils.getBaseZipFile(this.mContext, moduleName); 96 | if (FileUtil.copyFile(assestInput, dest)) { //copy插件包到宿主的安装目录下 97 | FileUtil.unZipAll( //将对应的module的基础包解压到对应的module文件夹下的base文件夹下 98 | dest, 99 | RNFilePathUtils.getBaseBundlePath(this.mContext, moduleName) 100 | ); //资源解压到base文件夹下 101 | //将bundle的描述信息以及版本信息写入sharedpreference 102 | this.rnVersionManager.saveRnDescription(rnCheckRes); 103 | } 104 | } catch (IOException e) { 105 | e.printStackTrace(); 106 | } 107 | } 108 | 109 | 110 | /** 111 | * 获取客户端的版本号 112 | * @param context 113 | * @return 114 | */ 115 | public static String getVersion(Context context) { 116 | try { 117 | PackageManager manager = context.getPackageManager(); 118 | PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); 119 | return info.versionName; 120 | } catch (Exception e) { 121 | return ""; 122 | } 123 | } 124 | 125 | 126 | 127 | 128 | 129 | 130 | } 131 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/downloader/RnModuleDiffUpdateManager.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.downloader; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.text.TextUtils; 7 | 8 | import com.alibaba.fastjson.JSON; 9 | import com.leadeon.diffupdate.LeadeonDiff; 10 | import com.leadeon.diffupdate.bean.checkversion.RnCheck; 11 | import com.leadeon.diffupdate.bean.checkversion.VersionRes; 12 | import com.leadeon.diffupdate.bean.checkversion.RnCheckRes; 13 | import com.leadeon.diffupdate.bean.checkversion.VersionReq; 14 | import com.leadeon.diffupdate.utils.AppUtils; 15 | import com.leadeon.diffupdate.utils.LogUtils; 16 | import com.leadeon.diffupdate.utils.okutil.OkHttpManager; 17 | import com.liulishuo.filedownloader.FileDownloader; 18 | 19 | import java.util.HashMap; 20 | import java.util.List; 21 | 22 | /** 23 | * Created by Lynn on 2017/8/17. 24 | */ 25 | 26 | public class RnModuleDiffUpdateManager { 27 | 28 | private LeadeonDiff.CopyCompletedCallback copyCompletedCallback = null; 29 | 30 | private Handler handler = new Handler() { 31 | @Override 32 | public void handleMessage(Message msg) { 33 | super.handleMessage(msg); 34 | switch (msg.what) { 35 | case 1: //表示首次的资源复制已经完成 36 | LogUtils.writeLog("首次的资源复制已经完成"); 37 | copyBundleUnzipRes(); 38 | break; 39 | case 2: //表示下载后的资源已经解压和复制 完成 40 | setComplete(); 41 | LogUtils.writeLog("表示下载后的资源已经解压和复制 完成"); 42 | checkVersion(); 43 | break; 44 | case 3: //此处表示zip已下载,jsbundle也已经合并 45 | System.out.println("停止service"); 46 | break; 47 | } 48 | } 49 | }; 50 | 51 | private Context mContext = null; 52 | private String AppKey=null; 53 | private String RnVersion=null; 54 | private String url=null; 55 | 56 | 57 | public RnModuleDiffUpdateManager(Context context,String appKey,String rnVersion,String url, LeadeonDiff.CopyCompletedCallback copyCompletedCallback) { 58 | if (context == null) { 59 | throw new NullPointerException("context is null ,please check your agent"); 60 | } 61 | this.copyCompletedCallback = copyCompletedCallback; 62 | this.mContext = context.getApplicationContext(); 63 | this.AppKey=appKey; 64 | this.RnVersion=rnVersion; 65 | this.url=url; 66 | FileDownloader.setup(this.mContext); 67 | } 68 | 69 | public void start() { 70 | new CopyModule(this.mContext).start(this.handler); 71 | } 72 | 73 | 74 | private void setComplete() { 75 | if (this.copyCompletedCallback != null) { 76 | this.copyCompletedCallback.onCompleted(); 77 | } 78 | } 79 | 80 | 81 | /** 82 | * 复制上次合并后的jsbundle文件 83 | * 开始解压上次下载的zip中的资源 84 | */ 85 | private void copyBundleUnzipRes() { 86 | new CopyAndUnzipRes(this.mContext).start(this.handler); 87 | } 88 | 89 | /** 90 | * 开始版本检测 91 | */ 92 | private void checkVersion() { 93 | RnVersionManager rnVersionManager = new RnVersionManager(this.mContext); 94 | HashMap versions = rnVersionManager.getRnVersion(); 95 | 96 | RnCheck rnCheck = new RnCheck(); 97 | VersionReq versionReq = new VersionReq(); 98 | versionReq.setAppKey(AppKey); 99 | versionReq.setRnVersion(RnVersion); 100 | versionReq.setAppVersion(AppUtils.getAppVersionName(mContext)); 101 | versionReq.setPlatForm("android"); 102 | versionReq.setReqParam(versions); 103 | rnCheck.setReqBody(versionReq); 104 | 105 | OkHttpManager.getInstance().post(this.url, rnCheck, new OkHttpManager.DataCallBack() { 106 | @Override 107 | public void requestSuccess(String result) { 108 | VersionRes versionRes = JSON.parseObject(result, VersionRes.class); 109 | if (versionRes != null && versionRes.getRetCode().equals("000000")) { 110 | //表示业务成功 111 | List list = versionRes.getRspBody(); 112 | if (list != null && list.size() > 0) { 113 | next(list); 114 | } 115 | } 116 | } 117 | 118 | @Override 119 | public void requestError(String retCode) { 120 | LogUtils.writeLog("版本检测接口失败 可能是网络问题 http错误码为" + retCode); 121 | } 122 | 123 | }); 124 | } 125 | 126 | 127 | /** 128 | * 当有新版本时执行下边代码进行 129 | * 增量更新包的下载,以及合并工作 130 | * 负责 则不用执行此方法 131 | * 132 | * @param ls 133 | */ 134 | private void next(List ls) { 135 | for (RnCheckRes checkRes:ls){ 136 | if(!TextUtils.isEmpty(checkRes.getNeedGoBack())&&checkRes.getNeedGoBack().equalsIgnoreCase("true")){ 137 | new RnVersionManager(this.mContext).getSharedPreference().edit().putString("lastVersion","").commit(); 138 | break; 139 | } 140 | } 141 | new RnModuleDownloader(this.mContext).startDown(ls, this.handler); 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/downloader/RnModuleDownloader.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.downloader; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.text.TextUtils; 6 | 7 | import com.alibaba.fastjson.JSON; 8 | import com.leadeon.diffupdate.bean.checkversion.RnCheckRes; 9 | import com.leadeon.diffupdate.utils.FileMd5Utils; 10 | import com.leadeon.diffupdate.utils.FileUtil; 11 | import com.leadeon.diffupdate.utils.LogUtils; 12 | import com.leadeon.diffupdate.utils.RNFilePathUtils; 13 | import com.liulishuo.filedownloader.BaseDownloadTask; 14 | import com.liulishuo.filedownloader.FileDownloadQueueSet; 15 | import com.liulishuo.filedownloader.FileDownloadSampleListener; 16 | import com.liulishuo.filedownloader.FileDownloader; 17 | import com.yyh.lib.bsdiff.PatchUtils; 18 | 19 | import java.io.File; 20 | import java.util.ArrayList; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by Lynn on 2017/8/17. 26 | */ 27 | 28 | public class RnModuleDownloader { 29 | 30 | 31 | private Context context = null; 32 | private HashMap rnModules = null; 33 | 34 | public RnModuleDownloader(Context context) { 35 | this.context = context.getApplicationContext(); 36 | } 37 | 38 | 39 | /** 40 | * 开始下载rn模块代码 41 | * 此方法应该在rn的版本检测成功后调用 42 | * 43 | * @param resList 44 | */ 45 | public void startDown(List resList, final Handler handler) { 46 | if (resList == null || resList.size() == 0) { 47 | LogUtils.writeLog("没有可下载的文件 "); 48 | handler.sendEmptyMessage(3); 49 | return; 50 | } 51 | this.rnModules = new HashMap<>(); 52 | for (RnCheckRes rnCheckRes : resList) { 53 | this.rnModules.put(rnCheckRes.getModuleName(), false); 54 | } 55 | 56 | 57 | LogUtils.writeLog("开始执行下载模块的代码"); 58 | FileDownloadQueueSet queueSet = new FileDownloadQueueSet(new FileDownloadSampleListener() { 59 | @Override 60 | protected void completed(BaseDownloadTask task) { 61 | super.completed(task); 62 | 63 | String path = task.getPath(); 64 | LogUtils.writeLog("blockComplete 下载完成 本地存储路径为" + path + " thread: " + Thread.currentThread().getName()); 65 | RnCheckRes rnCheckRes = ((RnCheckRes) task.getTag()); 66 | if (FileMd5Utils.MD5File(path).equals(rnCheckRes.getZipHash())) { //比对zipmd5 67 | unZipPatchAndMerge(rnCheckRes); 68 | } else { //删除patch文件夹下所有文件 69 | LogUtils.writeLog("下载完文件后 进行MD5校验未通过 执行删除操作"); 70 | FileUtil.deleteAll(RNFilePathUtils.getBundlePatchPath(context, rnCheckRes.getModuleName())); 71 | } 72 | sendComplete(rnCheckRes); 73 | } 74 | 75 | @Override 76 | protected void blockComplete(BaseDownloadTask task) { 77 | super.blockComplete(task); 78 | } 79 | 80 | private void sendComplete(RnCheckRes rnCheckRes) { 81 | if (rnModules != null) { 82 | rnModules.remove(rnCheckRes.getModuleName()); 83 | if (rnModules.size() == 0) { 84 | handler.sendEmptyMessage(3); 85 | } 86 | } 87 | } 88 | 89 | @Override 90 | protected void error(BaseDownloadTask task, Throwable e) { 91 | super.error(task, e); 92 | if (rnModules != null) { 93 | RnCheckRes rnCheckRes = ((RnCheckRes) task.getTag()); 94 | sendComplete(rnCheckRes); 95 | } 96 | } 97 | }); 98 | 99 | List tasks = new ArrayList<>(); 100 | for (RnCheckRes rnCheckRes : resList) { 101 | if (!TextUtils.isEmpty(rnCheckRes.getZipPath())) { 102 | String zipFilePath = RNFilePathUtils.getBundleZipFile(this.context, rnCheckRes.getModuleName()); 103 | tasks.add(FileDownloader.getImpl().create(rnCheckRes.getZipPath()).setPath(zipFilePath).setTag(rnCheckRes)); 104 | } 105 | } 106 | queueSet.disableCallbackProgressTimes(); // 由于是队列任务, 这里是我们假设了现在不需要每个任务都回调`FileDownloadListener#progress`, 我们只关系每个任务是否完成, 所以这里这样设置可以很有效的减少ipc. 107 | queueSet.setAutoRetryTimes(1); // 所有任务在下载失败的时候都不进行重试 108 | queueSet.downloadTogether(tasks); // 并行执行该任务队列 109 | queueSet.start(); 110 | } 111 | 112 | 113 | /** 114 | * 开始解压patch,并且合并patch文件 115 | * 116 | * @param rnCheckRes 117 | */ 118 | private void unZipPatchAndMerge(RnCheckRes rnCheckRes) { 119 | String moduleName = rnCheckRes.getModuleName(); 120 | String jsbundleMd5 = rnCheckRes.getJsbundleHash(); 121 | FileUtil.unZipPatch( 122 | RNFilePathUtils.getBundleZipFile(this.context, moduleName), 123 | RNFilePathUtils.getBundlePatchPath(this.context, moduleName)); //解压到patch文件夹下 124 | LogUtils.writeLog("解压完成 开始合并"); 125 | 126 | 127 | LogUtils.writeLog("old path " + RNFilePathUtils.getBaseBundleFile(this.context, moduleName)); 128 | LogUtils.writeLog("new path " + RNFilePathUtils.getBundleMergeFile(this.context, moduleName)); 129 | LogUtils.writeLog("patch path " + RNFilePathUtils.getBundlePatchFile(this.context, moduleName)); 130 | 131 | LogUtils.writeLog("patch path 开始创建文件"); 132 | File oldFile = new File(RNFilePathUtils.getBaseBundleFile(this.context, moduleName)); 133 | File patchFile=new File(RNFilePathUtils.getBundlePatchFile(this.context, moduleName)); 134 | if (!oldFile.exists()||!patchFile.exists()) { 135 | FileUtil.deleteAll(patchFile.getPath()); 136 | return; 137 | } 138 | int res = PatchUtils.getInstance().mergePatch( //合并jsbundle 139 | RNFilePathUtils.getBaseBundleFile(this.context, moduleName), 140 | RNFilePathUtils.getBundleMergeFile(this.context, moduleName), 141 | RNFilePathUtils.getBundlePatchFile(this.context, moduleName) 142 | ); 143 | LogUtils.writeLog("合并结果为 " + res); 144 | LogUtils.writeLog("服务器端的MD5 " + jsbundleMd5); 145 | String md5 = FileMd5Utils.MD5File(RNFilePathUtils.getBundleMergeFile(this.context, moduleName)); 146 | LogUtils.writeLog("客户端MD5 " + md5); 147 | 148 | if (!md5.equals(jsbundleMd5)) { 149 | FileUtil.deleteAll(RNFilePathUtils.getBundleMergeFile(this.context, moduleName)); //删除下载的文件 150 | LogUtils.writeLog("合并完文件后 进行MD5校验未通过 执行删除操作"); 151 | } else { 152 | LogUtils.writeLog("合并完文件 并保存版本信息" + JSON.toJSONString(rnCheckRes)); 153 | // 保存版本号 154 | new RnVersionManager(this.context).saveRnDescription(rnCheckRes); //保存版本信息 155 | } 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/downloader/RnVersionManager.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.downloader; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.text.TextUtils; 6 | import android.util.Base64; 7 | 8 | import com.leadeon.diffupdate.bean.checkversion.RnCheckRes; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.ByteArrayOutputStream; 12 | import java.io.IOException; 13 | import java.io.ObjectInputStream; 14 | import java.io.ObjectOutputStream; 15 | import java.io.Serializable; 16 | import java.util.HashMap; 17 | import java.util.Hashtable; 18 | import java.util.Map; 19 | 20 | /** 21 | * Created by Lynn on 2017/8/20. 22 | */ 23 | 24 | public class RnVersionManager { 25 | 26 | private String RN_VERSION_KEY = "rn_version_key"; 27 | private String RN_VERSION_SP = "rn_version_sp"; 28 | private Context context = null; 29 | 30 | public RnVersionManager(Context context) { 31 | this.context = context; 32 | } 33 | 34 | public synchronized void saveRnDescription(RnCheckRes rnCheckRes) { 35 | if (rnCheckRes == null) { 36 | return; 37 | } 38 | Hashtable oldHashTable = readRn(RN_VERSION_KEY); 39 | if (oldHashTable == null) { 40 | oldHashTable = new Hashtable<>(); 41 | } 42 | oldHashTable.put(rnCheckRes.getModuleName(), rnCheckRes); 43 | saveRn(RN_VERSION_KEY, oldHashTable); 44 | } 45 | 46 | /** 47 | * 用于清空rn模块的版本信息 48 | */ 49 | public void deleteRnDescription(){ 50 | saveRn(RN_VERSION_KEY, new Hashtable()); 51 | } 52 | 53 | public synchronized Hashtable getRnDescription() { 54 | return readRn(RN_VERSION_KEY); 55 | } 56 | 57 | /** 58 | * 获取所有的Rn模块的版本信息 59 | * 返回一个hashmap,map的key是模块的名字 60 | * map的value是rn的版本号 61 | * @return 62 | */ 63 | public synchronized HashMap getRnVersion() { 64 | HashMap hashMap = new HashMap<>(); 65 | Hashtable hashtable = readRn(RN_VERSION_KEY); 66 | if (hashtable != null) { 67 | for (Map.Entry entry : hashtable.entrySet()) { 68 | hashMap.put(entry.getKey(), entry.getValue().getVersion()); 69 | } 70 | } 71 | return hashMap; 72 | } 73 | 74 | 75 | public SharedPreferences getSharedPreference() { 76 | return this.context.getApplicationContext().getSharedPreferences(RN_VERSION_SP, Context.MODE_PRIVATE); 77 | } 78 | 79 | 80 | private synchronized boolean saveRn(String key, Hashtable rns) { 81 | 82 | ObjectOutputStream objectOutputStream = null; 83 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 84 | try { 85 | objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); 86 | objectOutputStream.writeObject(rns); 87 | objectOutputStream.flush(); 88 | 89 | byte[] data = byteArrayOutputStream.toByteArray(); 90 | String list = Base64.encodeToString(data, Base64.DEFAULT); 91 | 92 | getSharedPreference().edit().putString(key, list).commit(); 93 | return true; 94 | } catch (Exception e) { 95 | e.printStackTrace(); 96 | } finally { 97 | if (objectOutputStream != null) { 98 | try { 99 | objectOutputStream.close(); 100 | } catch (IOException e) { 101 | e.printStackTrace(); 102 | } 103 | } 104 | if (byteArrayOutputStream != null) { 105 | try { 106 | byteArrayOutputStream.close(); 107 | } catch (IOException e) { 108 | e.printStackTrace(); 109 | } 110 | } 111 | } 112 | return false; 113 | } 114 | 115 | private synchronized Hashtable readRn(String key) { 116 | String list = getSharedPreference().getString(key, ""); 117 | Serializable object = null; 118 | if (!TextUtils.isEmpty(list)) { 119 | ByteArrayInputStream byteArrayInputStream = null; 120 | ObjectInputStream objectInputStream = null; 121 | try { 122 | byteArrayInputStream = new ByteArrayInputStream(Base64.decode(list, Base64.DEFAULT)); 123 | objectInputStream = new ObjectInputStream(byteArrayInputStream); 124 | object = (Serializable) objectInputStream.readObject(); 125 | } catch (Exception e) { 126 | e.printStackTrace(); 127 | } finally { 128 | if (objectInputStream != null) { 129 | try { 130 | objectInputStream.close(); 131 | } catch (IOException e) { 132 | e.printStackTrace(); 133 | } 134 | } 135 | if (byteArrayInputStream != null) { 136 | try { 137 | byteArrayInputStream.close(); 138 | } catch (IOException e) { 139 | e.printStackTrace(); 140 | } 141 | } 142 | } 143 | } 144 | 145 | return (Hashtable) object; 146 | } 147 | 148 | 149 | } 150 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/utils/AppUtils.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.utils; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | 7 | /** 8 | * Created by Lynn on 2017/12/5. 9 | */ 10 | 11 | public class AppUtils { 12 | public static String getAppVersionName(Context context) { 13 | String versionName = ""; 14 | try { 15 | // ---get the package info--- 16 | PackageManager pm = context.getPackageManager(); 17 | PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); 18 | versionName = pi.versionName; 19 | if (versionName == null || versionName.length() <= 0) { 20 | return ""; 21 | } 22 | } catch (Exception e) { 23 | } 24 | return versionName; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/utils/FileMd5Utils.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.security.MessageDigest; 7 | 8 | /** 9 | * Created by Lynn on 2017/8/17. 10 | */ 11 | 12 | public class FileMd5Utils { 13 | 14 | static char hexdigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', 15 | '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 16 | /** 17 | * md5文件生成摘要 18 | * 19 | * @param filePath 20 | * @return 21 | * @see [类、类#方法、类#成员] 22 | */ 23 | public static String MD5File(String filePath) { 24 | File file=new File(filePath); 25 | FileInputStream fis = null; 26 | try { 27 | MessageDigest md = MessageDigest.getInstance("MD5"); 28 | fis = new FileInputStream(file); 29 | byte[] buffer = new byte[2048]; 30 | int length = -1; 31 | while ((length = fis.read(buffer)) != -1) { 32 | md.update(buffer, 0, length); 33 | } 34 | // 32位加密 35 | byte[] b = md.digest(); 36 | return byteToHexString(b); 37 | } catch (Exception ex) { 38 | ex.printStackTrace(); 39 | return null; 40 | } finally { 41 | try { 42 | fis.close(); 43 | } catch (IOException ex) { 44 | ex.printStackTrace(); 45 | } 46 | } 47 | } 48 | 49 | 50 | /** 51 | * @param tmp 52 | * @return 53 | * @see [类、类#方法、类#成员] 54 | */ 55 | private static String byteToHexString(byte[] tmp) { 56 | String s; 57 | // 用字节表示就是 16 个字节 58 | char str[] = new char[16 * 2]; // 每个字节用 16 进制表示的话,使用两个字符, 59 | // 所以表示成 16 进制需要 32 个字符 60 | // 表示转换结果中对应的字符位置 61 | int k = 0; 62 | for (int i = 0; i < 16; i++) { 63 | // 从第一个字节开始,对 MD5 的每一个字节 64 | // 转换成 16 进制字符的转换 65 | // 取第 i 个字节 66 | byte byte0 = tmp[i]; 67 | // 取字节中高 4 位的数字转换, 68 | str[k++] = hexdigits[byte0 >>> 4 & 0xf]; 69 | // >>> 为逻辑右移,将符号位一起右移 70 | // 取字节中低 4 位的数字转换 71 | str[k++] = hexdigits[byte0 & 0xf]; 72 | } 73 | // 换后的结果转换为字符串 74 | s = new String(str); 75 | return s; 76 | } 77 | 78 | 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/utils/LogUtils.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.utils; 2 | 3 | /** 4 | * Created by Lynn on 2017/8/21. 5 | */ 6 | 7 | public class LogUtils { 8 | 9 | public static boolean isDebug=true; 10 | public static String TAG="com.leadeon.diffipdate 日志 "; 11 | 12 | public static void writeLog(String msg){ 13 | 14 | if(isDebug){ 15 | System.out.println(TAG+msg); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/utils/RNFilePathUtils.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.io.File; 6 | 7 | /** 8 | * Created by Lynn on 2017/8/8. 9 | */ 10 | 11 | public class RNFilePathUtils { 12 | 13 | public static String INDEX_BUNDLE_NAME="main.jsbundle"; 14 | public static String BASE_BUNDLE_NAME="main.jsbundle"; 15 | public static String BASE_BUNDLE_ZIP="base.zip"; 16 | 17 | 18 | public static String MERGE_BUNDLE_NAME="merge.jsbundle"; 19 | public static String BUNDLE_PATCH_NAME="patch.jsbundle"; 20 | public static String PATCH_ZIP_NAME="patch.zip"; 21 | 22 | 23 | 24 | public static String getBundleRootPath(Context context){ 25 | return context.getApplicationContext().getCacheDir().getParent()+File.separator+"rn_bundle"; 26 | } 27 | 28 | 29 | public static String getBundlePath(Context context,String moduleName){ 30 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"index"; 31 | } 32 | public static String getBundleFile(Context context,String moduleName){ 33 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"index"+File.separator+INDEX_BUNDLE_NAME; 34 | } 35 | 36 | /** 37 | * 获取patch的路径 38 | * @param context 39 | * @return 40 | */ 41 | public static String getBundlePatchPath(Context context,String moduleName){ 42 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"patch"; 43 | } 44 | 45 | public static String getBundlePatchFile(Context context,String moduleName){ 46 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"patch"+File.separator+BUNDLE_PATCH_NAME; 47 | } 48 | public static String getBundleZipFile(Context context,String moduleName){ 49 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"patch"+File.separator+PATCH_ZIP_NAME; 50 | } 51 | 52 | /** 53 | * 获取用于存放合并文件的路径 54 | * @param context 55 | * @return 56 | */ 57 | public static String getBundleMergePath(Context context,String moduleName){ 58 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"merge"; 59 | } 60 | public static String getBundleMergeFile(Context context,String moduleName){ 61 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"merge"+File.separator+MERGE_BUNDLE_NAME; 62 | } 63 | /** 64 | * 获取存储基线包的路径 65 | * @param context 66 | * @return 67 | */ 68 | public static String getBaseBundlePath(Context context,String moduleName){ 69 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"base"; 70 | } 71 | 72 | public static String getBaseBundleFile(Context context,String moduleName){ 73 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"base"+File.separator+BASE_BUNDLE_NAME; 74 | } 75 | 76 | public static String getBaseZipFile(Context context,String moduleName){ 77 | return getBundleRootPath(context)+File.separator+moduleName+File.separator+"base"+File.separator+BASE_BUNDLE_ZIP; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /android/src/main/java/com/leadeon/diffupdate/utils/okutil/OkHttpManager.java: -------------------------------------------------------------------------------- 1 | package com.leadeon.diffupdate.utils.okutil; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | 6 | import com.alibaba.fastjson.JSON; 7 | import com.leadeon.diffupdate.utils.LogUtils; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.DataOutputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.InputStreamReader; 14 | import java.net.HttpURLConnection; 15 | import java.net.URL; 16 | 17 | /** 18 | * Created by Lynn on 2017/9/28. 19 | */ 20 | 21 | public class OkHttpManager { 22 | 23 | /** 24 | * 静态实例 25 | */ 26 | private static OkHttpManager sOkHttpManager; 27 | 28 | 29 | 30 | /** 31 | * 因为我们请求数据一般都是子线程中请求,在这里我们使用了handler 32 | */ 33 | private Handler mHandler; 34 | 35 | /** 36 | * 单例模式 获取OkHttpManager实例 37 | * 38 | * @return 39 | */ 40 | public static OkHttpManager getInstance() { 41 | if (sOkHttpManager == null) { 42 | sOkHttpManager = new OkHttpManager(); 43 | } 44 | return sOkHttpManager; 45 | } 46 | 47 | 48 | /** 49 | * 构造方法 50 | */ 51 | private OkHttpManager() { 52 | /** 53 | * 初始化handler 54 | */ 55 | mHandler = new Handler(Looper.getMainLooper()); 56 | } 57 | 58 | /** 59 | * 数据回调接口 60 | */ 61 | public interface DataCallBack { 62 | void requestSuccess(String result); 63 | void requestError(String retCode); 64 | } 65 | 66 | 67 | public void post(final String urls, final Object object, final DataCallBack dataCallBack){ 68 | new Thread(new Runnable() { 69 | @Override 70 | public void run() { 71 | try { 72 | postJson(urls,object,dataCallBack); 73 | } catch (IOException e) { 74 | e.printStackTrace(); 75 | } 76 | } 77 | }).start(); 78 | } 79 | 80 | private void postJson(String urls, Object object, final DataCallBack dataCallBack) throws IOException { 81 | HttpURLConnection urlConnection = null; 82 | URL url = new URL(urls); 83 | urlConnection = (HttpURLConnection) url.openConnection(); 84 | urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); 85 | urlConnection.setRequestProperty("Accept", "application/json"); 86 | urlConnection.setRequestMethod("POST"); 87 | urlConnection.setDoOutput(true); 88 | DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); 89 | String jsonString = JSON.toJSONString(object); 90 | 91 | LogUtils.writeLog("请求 为 "+jsonString); 92 | 93 | wr.writeBytes(jsonString); 94 | wr.flush(); 95 | wr.close(); 96 | // try to get response 97 | final int statusCode = urlConnection.getResponseCode(); 98 | if (statusCode == 200) { 99 | final StringBuffer sb = new StringBuffer(); 100 | String str = null; 101 | InputStream inputStream1=urlConnection.getInputStream(); 102 | BufferedReader br = new BufferedReader(new InputStreamReader(inputStream1)); 103 | try { 104 | while ((str = br.readLine()) != null) { 105 | sb.append(str); 106 | } 107 | } catch (IOException e) { 108 | e.printStackTrace(); 109 | }finally { 110 | inputStream1.close(); 111 | } 112 | final String resout=sb.toString(); 113 | mHandler.post(new Runnable() { 114 | @Override 115 | public void run() { 116 | dataCallBack.requestSuccess(resout); 117 | } 118 | }); 119 | LogUtils.writeLog("相应结果为:"+resout); 120 | }else { 121 | mHandler.post(new Runnable() { 122 | @Override 123 | public void run() { 124 | dataCallBack.requestError(""+statusCode); 125 | } 126 | }); 127 | } 128 | 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /android/src/main/java/com/yyh/lib/bsdiff/PatchUtils.java: -------------------------------------------------------------------------------- 1 | package com.yyh.lib.bsdiff; 2 | 3 | import com.leadeon.diffupdate.utils.LogUtils; 4 | import com.leadeon.diffupdate.utils.RNFilePathUtils; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * APK Patch工具类 11 | * 12 | * @author yuyuhang 13 | * @date 2016-1-26 下午1:10:40 14 | */ 15 | public class PatchUtils { 16 | 17 | private static PatchUtils instance; 18 | 19 | public static PatchUtils getInstance() { 20 | if (instance == null) 21 | instance = new PatchUtils(); 22 | return instance; 23 | } 24 | 25 | static { 26 | System.loadLibrary("ApkPatchLibrary"); 27 | } 28 | 29 | public synchronized int mergePatch(String oldbundlePath, String newbundlePath, String patchPath){ 30 | 31 | File destFile = new File(newbundlePath); 32 | 33 | destFile.getParentFile().mkdirs(); 34 | try { 35 | LogUtils.writeLog("创建merage文件"); 36 | if(destFile.exists()){ 37 | destFile.delete(); 38 | } 39 | destFile.createNewFile(); 40 | LogUtils.writeLog("创建merage文件夹成功"); 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | LogUtils.writeLog("创建merage文件夹失败"+e.getMessage()); 44 | } 45 | return patch(oldbundlePath,newbundlePath,patchPath); 46 | } 47 | 48 | 49 | 50 | /** 51 | * native方法 使用路径为oldApkPath的apk与路径为patchPath的补丁包,合成新的apk,并存储于newApkPath 52 | * 返回:0,说明操作成功 53 | * @param oldbundlePath 54 | * 示例:/sdcard/old.apk 55 | * @param newbundlePath 56 | * 示例:/sdcard/new.apk 57 | * @param patchPath 58 | * 示例:/sdcard/xx.patch 59 | * @return 60 | */ 61 | public native int patch(String oldbundlePath, String newbundlePath, String patchPath); 62 | } -------------------------------------------------------------------------------- /doc/image/ReactNativeDiffUpdate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xagreenpoint/LDReactNativeDiffUpdate/e9a99e87ede1086652abec9c20092e4c88c1cd40/doc/image/ReactNativeDiffUpdate.png -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDPatchFileManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // PatchFileManager.h 3 | // demo 4 | // 5 | // Created by hong on 2017/8/20. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LDPatchFileManager : NSObject 12 | 13 | + (void) clearLDReactNativeCache; 14 | + (void) goBackOriginal: (NSString *) bundleName; 15 | 16 | + (void) updateReactNativeLocalPath; 17 | + (void) copyLDBundleToReactNativePath; 18 | + (void) downloadPatchFile: (NSString *) url withBundle: (NSString *) bundleName; 19 | + (void) reloadAllJSPatch; 20 | 21 | + (NSString *) jsbundleLocation: (NSString *) bundleName; 22 | 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDRNBundleList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LDRNBundleList.h 3 | // demo 4 | // 5 | // Created by hong on 2017/8/20. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LDRNBundleList : NSObject 12 | 13 | +(NSString *) appKey; 14 | +(NSString *) versionUrl; 15 | +(NSString *) rnVersion; 16 | 17 | +(NSString *) LDRNRootpath; 18 | +(NSDictionary *) originBundles; 19 | +(NSDictionary *) originBundlesHash; 20 | 21 | +(NSString *) entryJSName; 22 | +(NSString *) patchFileName; 23 | 24 | +(NSString *) resFolder; 25 | 26 | +(NSArray *) folders; 27 | 28 | +(NSString *) indexFolder; 29 | +(NSString *) mergeFolder; 30 | +(NSString *) patchFolder; 31 | +(NSString *) originFolder; 32 | 33 | +(NSString *) rnSaveKey; 34 | +(NSString *) rnDownloadKey; 35 | +(NSString *) appInfoKey; 36 | 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDRNBundleList.m: -------------------------------------------------------------------------------- 1 | // 2 | // LDRNBundleList.m 3 | // demo 4 | // 5 | // Created by hong on 2017/8/20. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import "LDRNBundleList.h" 10 | 11 | @implementation LDRNBundleList 12 | 13 | +(NSString *) appKey { 14 | return @"xxxxxxxxxxxx"; 15 | } 16 | 17 | +(NSString *) LDRNRootpath { 18 | return @"rn_res"; 19 | } 20 | 21 | +(NSString *) rnVersion { 22 | return @"0.46.4"; 23 | } 24 | 25 | +(NSDictionary *) originBundles { 26 | return @{ 27 | @"LDBusinessEntry": @"1.0.1", 28 | @"LDCommon": @"1.0.0", 29 | }; 30 | } 31 | 32 | +(NSDictionary *) originBundlesHash { 33 | return @{ 34 | @"LDBusinessEntry": @"6c36ebdd7fbde18b26be726d2d3a7254", 35 | @"LDCommon": @"4f2601d5e4dbd4a8eea9d4110561dca4", 36 | }; 37 | } 38 | 39 | 40 | +(NSString *) entryJSName { 41 | return @"main.jsbundle"; 42 | } 43 | 44 | +(NSString *) patchFileName { 45 | return @"patch.jsbundle"; 46 | } 47 | 48 | +(NSString *) resFolder { 49 | return @"assets"; 50 | } 51 | 52 | +(NSArray *) folders { 53 | return @[ 54 | @"index", 55 | @"merge", 56 | @"patch", 57 | @"origin", 58 | ]; 59 | } 60 | 61 | +(NSString *) indexFolder { 62 | return [[LDRNBundleList folders] objectAtIndex: 0]; 63 | } 64 | 65 | +(NSString *) mergeFolder { 66 | return [[LDRNBundleList folders] objectAtIndex: 1]; 67 | } 68 | 69 | +(NSString *) patchFolder { 70 | return [[LDRNBundleList folders] objectAtIndex: 2]; 71 | } 72 | 73 | +(NSString *) originFolder { 74 | 75 | return [[LDRNBundleList folders] lastObject]; 76 | } 77 | 78 | +(NSString *) versionUrl { 79 | return @"http://192.168.6.30:3000/biz-orange/RN/patchVersion"; 80 | } 81 | 82 | +(NSString *) rnSaveKey { 83 | return @"_reactNativeBundlesVersion"; 84 | } 85 | 86 | +(NSString *) rnDownloadKey { 87 | return @"_reactNativeDownloadFlag"; 88 | } 89 | 90 | +(NSString *) appInfoKey { 91 | return @"_reactNativeAppInfo"; 92 | } 93 | 94 | 95 | 96 | @end 97 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDRNDiffUpdate.h: -------------------------------------------------------------------------------- 1 | // 2 | // LDRNDiffUpdate.h 3 | // demo 4 | // 5 | // Created by hong on 2017/8/22. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LDRNDiffUpdate : NSObject 12 | 13 | +(NSURL *) jsBundleUrl: (NSString *) bundleName; 14 | 15 | +(NSURL *) jsBundleUrlDefault; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDRNDiffUpdate.m: -------------------------------------------------------------------------------- 1 | // 2 | // LDRNDiffUpdate.m 3 | // demo 4 | // 5 | // Created by hong on 2017/8/22. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import "LDRNDiffUpdate.h" 10 | 11 | #import "LDPatchFileManager.h" 12 | #import "LDRNVersionManager.h" 13 | #import "LDRNBundleList.h" 14 | 15 | @implementation LDRNDiffUpdate 16 | 17 | +(NSURL *) jsBundleUrl: (NSString *) bundleName { 18 | 19 | NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 20 | NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 21 | 22 | NSDictionary *appInfo = [[NSUserDefaults standardUserDefaults] objectForKey: [LDRNBundleList appInfoKey]]; 23 | if (appInfo == nil || appInfo[@"appVersion"] == nil || ![appInfo[@"appVersion"] isEqualToString: appCurVersion]) { 24 | 25 | //first 26 | appInfo = @{ 27 | @"appVersion": appCurVersion 28 | }; 29 | [[NSUserDefaults standardUserDefaults] setObject:appInfo forKey: [LDRNBundleList appInfoKey]]; 30 | [[NSUserDefaults standardUserDefaults] synchronize]; 31 | 32 | [LDPatchFileManager clearLDReactNativeCache]; 33 | [LDPatchFileManager updateReactNativeLocalPath]; 34 | [LDPatchFileManager copyLDBundleToReactNativePath]; 35 | } else { 36 | 37 | //not first 38 | [LDRNVersionManager gobackOriginalIfNeed]; 39 | [LDPatchFileManager updateReactNativeLocalPath]; 40 | [LDPatchFileManager reloadAllJSPatch]; 41 | } 42 | 43 | NSURL *jslocation = [NSURL fileURLWithPath: [LDPatchFileManager jsbundleLocation: bundleName]]; 44 | [LDRNVersionManager updateReactNativeBundles]; 45 | return jslocation; 46 | } 47 | 48 | 49 | +(NSURL *) jsBundleUrlDefault { 50 | NSString *commonBundle = @"LDCommon"; 51 | return [LDRNDiffUpdate jsBundleUrl: commonBundle]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDRNVersionManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // LDRNVersionManager.h 3 | // demo 4 | // 5 | // Created by hong on 2017/8/21. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | typedef void (^SUCCESS_CALLBACK)(NSArray *data, NSURLResponse *response); 13 | typedef void (^FAILED_CALLBACK)(NSError *error, NSURLResponse *response); 14 | 15 | 16 | 17 | @interface LDRNVersionManager : NSObject 18 | 19 | +(void) checkRNBundlesVersion: (SUCCESS_CALLBACK) success withFailure: (FAILED_CALLBACK) failure; 20 | +(void) updateReactNativeBundles; 21 | +(void) gobackOriginalIfNeed; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/LDRNVersionManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // LDRNVersionManager.m 3 | // demo 4 | // 5 | // Created by hong on 2017/8/21. 6 | // Copyright © 2017年 leadeon. All rights reserved. 7 | // 8 | 9 | #import "LDRNVersionManager.h" 10 | #import "LDRNBundleList.h" 11 | #import "LDPatchFileManager.h" 12 | 13 | 14 | @implementation LDRNVersionManager 15 | 16 | 17 | +(BOOL) validResBody: (NSDictionary *) res { 18 | 19 | if (res == nil 20 | || res[@"retCode"] == nil 21 | || ![res[@"retCode"] isEqualToString:@"000000"] 22 | || res[@"resBody"] == nil) { 23 | 24 | return NO; 25 | } 26 | 27 | return YES; 28 | } 29 | 30 | +(void) checkRNBundlesVersion: (SUCCESS_CALLBACK) success withFailure: (FAILED_CALLBACK) failure { 31 | 32 | NSURL *url = [NSURL URLWithString: [LDRNBundleList versionUrl]]; 33 | 34 | NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; 35 | NSURLSession *session = [NSURLSession sessionWithConfiguration: config]; 36 | 37 | NSArray *patchs = [[NSUserDefaults standardUserDefaults] objectForKey:[LDRNBundleList rnSaveKey]]; 38 | 39 | __block NSDictionary *body = [LDRNBundleList originBundles]; 40 | if (patchs && patchs.count > 0) { 41 | 42 | NSMutableDictionary *bundles = [NSMutableDictionary dictionary]; 43 | [patchs enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 44 | 45 | [bundles setValue:obj[@"version"] forKey:obj[@"moduleName"]]; 46 | }]; 47 | 48 | body = bundles; 49 | } 50 | 51 | NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 52 | NSString *appVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; 53 | NSDictionary *reqObj = @{ 54 | @"reqBody": @{ 55 | @"appKey": [LDRNBundleList appKey], 56 | @"appVersion": appVersion, 57 | @"rnVersion": [LDRNBundleList rnVersion], 58 | @"platForm": @"ios", 59 | @"reqParam": body, 60 | } 61 | }; 62 | 63 | NSData *reqData = [NSJSONSerialization dataWithJSONObject:reqObj options:kNilOptions error:nil]; 64 | 65 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url]; 66 | request.HTTPMethod = @"POST"; 67 | [request setValue:@"application/Json" forHTTPHeaderField:@"Content-Type"]; 68 | request.HTTPBody = reqData; 69 | NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 70 | 71 | if (error) { 72 | failure(error, response); 73 | return ; 74 | } 75 | 76 | NSError *err = nil; 77 | NSDictionary *res = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error: &err]; 78 | 79 | if (err) { 80 | failure(err, response); 81 | return ; 82 | } 83 | 84 | NSError *customError = [NSError errorWithDomain:@"custom.rn.errdomain" code: -3 userInfo:@{NSLocalizedDescriptionKey: @"response data format not well"}]; 85 | if ([LDRNVersionManager validResBody: res]) { 86 | 87 | failure(customError, response); 88 | return ; 89 | } 90 | 91 | NSArray *patchs = res[@"rspBody"]; 92 | if (patchs == nil || ![patchs isKindOfClass:[NSArray class]]) { 93 | 94 | failure(customError, response); 95 | return ; 96 | } 97 | 98 | if (patchs.count > 0) { 99 | 100 | [[NSUserDefaults standardUserDefaults] setObject:patchs forKey: [LDRNBundleList rnSaveKey]]; 101 | [[NSUserDefaults standardUserDefaults] setObject:@[] forKey: [LDRNBundleList rnDownloadKey]]; 102 | [[NSUserDefaults standardUserDefaults] synchronize]; 103 | } 104 | 105 | success(patchs, response); 106 | }]; 107 | 108 | [task resume]; 109 | } 110 | 111 | +(NSArray *) unDownloadBundles { 112 | 113 | 114 | NSArray *flags = [[NSUserDefaults standardUserDefaults] objectForKey:[LDRNBundleList rnDownloadKey]]; 115 | NSArray *patchs = [[NSUserDefaults standardUserDefaults] objectForKey:[LDRNBundleList rnSaveKey]]; 116 | 117 | __block NSMutableArray *arrs = [NSMutableArray array]; 118 | [patchs enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 119 | 120 | NSString *bundleName = obj[@"moduleName"]; 121 | if (flags != nil && ![flags containsObject: bundleName]) { 122 | [arrs addObject: obj]; 123 | } 124 | }]; 125 | 126 | return arrs; 127 | } 128 | 129 | +(void) updateReactNativeBundles { 130 | 131 | NSArray *bundles = [LDRNVersionManager unDownloadBundles]; 132 | if ([bundles count] > 0) { 133 | 134 | //continue download 135 | [bundles enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 136 | 137 | NSString *downloadUrl = obj[@"zipPath"]; 138 | NSString *bundleName = obj[@"moduleName"]; 139 | NSString *needGoback = obj[@"needGoBack"]; 140 | 141 | if ([needGoback isEqualToString:@"true"]) { 142 | return ; 143 | } 144 | 145 | [LDPatchFileManager downloadPatchFile:downloadUrl withBundle:bundleName]; 146 | }]; 147 | 148 | return; 149 | } 150 | 151 | [LDRNVersionManager checkRNBundlesVersion:^(NSArray *bundlesInfo, NSURLResponse *response) { 152 | 153 | [bundlesInfo enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull info, NSUInteger idx, BOOL * _Nonnull stop) { 154 | 155 | NSString *zipUrl = info[@"zipPath"]; 156 | NSString *bundleName = info[@"moduleName"]; 157 | NSString *needGoback = info[@"needGoBack"]; 158 | 159 | if ([needGoback isEqualToString:@"true"]) { 160 | return ; 161 | } 162 | 163 | if (zipUrl != nil && bundleName != nil) { 164 | [LDPatchFileManager downloadPatchFile: zipUrl withBundle: bundleName]; 165 | } 166 | 167 | }]; 168 | 169 | } withFailure:^(NSError *error, NSURLResponse *response) { 170 | 171 | }]; 172 | } 173 | 174 | + (void) gobackOriginalIfNeed { 175 | 176 | NSArray *patchs = [[NSUserDefaults standardUserDefaults] objectForKey:[LDRNBundleList rnSaveKey]]; 177 | 178 | [patchs enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull info, NSUInteger idx, BOOL * _Nonnull stop) { 179 | 180 | NSString *bundleName = info[@"moduleName"]; 181 | NSString *needGoback = info[@"needGoBack"]; 182 | 183 | if ([needGoback isEqualToString:@"true"]) { 184 | 185 | [LDPatchFileManager goBackOriginal: bundleName]; 186 | 187 | //先进行整体回滚 188 | [[NSUserDefaults standardUserDefaults] setObject:@[] forKey: [LDRNBundleList rnSaveKey]]; 189 | [[NSUserDefaults standardUserDefaults] synchronize]; 190 | return ; 191 | } 192 | }]; 193 | } 194 | 195 | @end 196 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/Common.h: -------------------------------------------------------------------------------- 1 | #ifndef SSZipCommon 2 | #define SSZipCommon 3 | 4 | /* tm_unz contain date/time info */ 5 | typedef struct tm_unz_s 6 | { 7 | unsigned int tm_sec; /* seconds after the minute - [0,59] */ 8 | unsigned int tm_min; /* minutes after the hour - [0,59] */ 9 | unsigned int tm_hour; /* hours since midnight - [0,23] */ 10 | unsigned int tm_mday; /* day of the month - [1,31] */ 11 | unsigned int tm_mon; /* months since January - [0,11] */ 12 | unsigned int tm_year; /* years - [1980..2044] */ 13 | } tm_unz; 14 | 15 | typedef struct unz_file_info_s 16 | { 17 | unsigned long version; /* version made by 2 bytes */ 18 | unsigned long version_needed; /* version needed to extract 2 bytes */ 19 | unsigned long flag; /* general purpose bit flag 2 bytes */ 20 | unsigned long compression_method; /* compression method 2 bytes */ 21 | unsigned long dosDate; /* last mod file date in Dos fmt 4 bytes */ 22 | unsigned long crc; /* crc-32 4 bytes */ 23 | unsigned long compressed_size; /* compressed size 4 bytes */ 24 | unsigned long uncompressed_size; /* uncompressed size 4 bytes */ 25 | unsigned long size_filename; /* filename length 2 bytes */ 26 | unsigned long size_file_extra; /* extra field length 2 bytes */ 27 | unsigned long size_file_comment; /* file comment length 2 bytes */ 28 | 29 | unsigned long disk_num_start; /* disk number start 2 bytes */ 30 | unsigned long internal_fa; /* internal file attributes 2 bytes */ 31 | unsigned long external_fa; /* external file attributes 4 bytes */ 32 | 33 | tm_unz tmu_date; 34 | } unz_file_info; 35 | 36 | /* unz_file_info contain information about a file in the zipfile */ 37 | typedef struct unz_file_info64_s 38 | { 39 | unsigned long version; /* version made by 2 bytes */ 40 | unsigned long version_needed; /* version needed to extract 2 bytes */ 41 | unsigned long flag; /* general purpose bit flag 2 bytes */ 42 | unsigned long compression_method; /* compression method 2 bytes */ 43 | unsigned long dosDate; /* last mod file date in Dos fmt 4 bytes */ 44 | unsigned long crc; /* crc-32 4 bytes */ 45 | unsigned long long compressed_size; /* compressed size 8 bytes */ 46 | unsigned long long uncompressed_size; /* uncompressed size 8 bytes */ 47 | unsigned long size_filename; /* filename length 2 bytes */ 48 | unsigned long size_file_extra; /* extra field length 2 bytes */ 49 | unsigned long size_file_comment; /* file comment length 2 bytes */ 50 | 51 | unsigned long disk_num_start; /* disk number start 2 bytes */ 52 | unsigned long internal_fa; /* internal file attributes 2 bytes */ 53 | unsigned long external_fa; /* external file attributes 4 bytes */ 54 | 55 | tm_unz tmu_date; 56 | unsigned long long disk_offset; 57 | unsigned long size_file_extra_internal; 58 | } unz_file_info64; 59 | 60 | typedef struct unz_global_info_s 61 | { 62 | unsigned long number_entry; /* total number of entries in 63 | the central dir on this disk */ 64 | 65 | unsigned long number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 66 | 67 | 68 | unsigned long size_comment; /* size of the global comment of the zipfile */ 69 | } unz_global_info; 70 | 71 | typedef struct unz_global_info64 72 | { 73 | unsigned long long number_entry; /* total number of entries in 74 | the central dir on this disk */ 75 | 76 | unsigned long number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/ 77 | 78 | unsigned long size_comment; /* size of the global comment of the zipfile */ 79 | } unz_global_info64; 80 | 81 | #endif -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/README.md: -------------------------------------------------------------------------------- 1 | The source code in this folder is taken from [https://github.com/ZipArchive/ZipArchive/tree/35fe9b6af48527cde0b5db52287474ed3a32d75f/SSZipArchive](https://github.com/ZipArchive/ZipArchive/tree/35fe9b6af48527cde0b5db52287474ed3a32d75f/SSZipArchive) which is [MIT licensed](https://github.com/ZipArchive/ZipArchive/blob/35fe9b6af48527cde0b5db52287474ed3a32d75f/LICENSE.txt). -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/SSZipArchive.h: -------------------------------------------------------------------------------- 1 | // 2 | // SSZipArchive.h 3 | // SSZipArchive 4 | // 5 | // Created by Sam Soffes on 7/21/10. 6 | // Copyright (c) Sam Soffes 2010-2015. All rights reserved. 7 | // 8 | 9 | #ifndef _SSZIPARCHIVE_H 10 | #define _SSZIPARCHIVE_H 11 | 12 | #import 13 | #include "Common.h" 14 | 15 | @protocol SSZipArchiveDelegate; 16 | 17 | @interface SSZipArchive : NSObject 18 | 19 | // Unzip 20 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination; 21 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination delegate:(id)delegate; 22 | 23 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError * *)error; 24 | + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination overwrite:(BOOL)overwrite password:(NSString *)password error:(NSError * *)error delegate:(id)delegate; 25 | 26 | + (BOOL)unzipFileAtPath:(NSString *)path 27 | toDestination:(NSString *)destination 28 | progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 29 | completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler; 30 | 31 | + (BOOL)unzipFileAtPath:(NSString *)path 32 | toDestination:(NSString *)destination 33 | overwrite:(BOOL)overwrite 34 | password:(NSString *)password 35 | progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler 36 | completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler; 37 | 38 | // Zip 39 | 40 | // without password 41 | + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths; 42 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath; 43 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirector; 44 | 45 | // with password, password could be nil 46 | + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray *)paths withPassword:(NSString *)password; 47 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(NSString *)password; 48 | + (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(NSString *)password; 49 | 50 | - (instancetype)initWithPath:(NSString *)path; 51 | @property (NS_NONATOMIC_IOSONLY, readonly, getter = isOpen) BOOL open; 52 | - (BOOL)writeFile:(NSString *)path withPassword:(NSString *)password; 53 | - (BOOL)writeFileAtPath:(NSString *)path withFileName:(NSString *)fileName withPassword:(NSString *)password; 54 | - (BOOL)writeData:(NSData *)data filename:(NSString *)filename withPassword:(NSString *)password; 55 | @property (NS_NONATOMIC_IOSONLY, readonly, getter = isClosed) BOOL close; 56 | 57 | @end 58 | 59 | @protocol SSZipArchiveDelegate 60 | 61 | @optional 62 | 63 | - (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo; 64 | - (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath; 65 | 66 | - (BOOL)zipArchiveShouldUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 67 | - (void)zipArchiveWillUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 68 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath fileInfo:(unz_file_info)fileInfo; 69 | - (void)zipArchiveDidUnzipFileAtIndex:(NSInteger)fileIndex totalFiles:(NSInteger)totalFiles archivePath:(NSString *)archivePath unzippedFilePath:(NSString *)unzippedFilePath; 70 | 71 | - (void)zipArchiveProgressEvent:(unsigned long long)loaded total:(unsigned long long)total; 72 | - (void)zipArchiveDidUnzipArchiveFile:(NSString *)zipFile entryPath:(NSString *)entryPath destPath:(NSString *)destPath; 73 | 74 | @end 75 | 76 | #endif /* _SSZIPARCHIVE_H */ 77 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the definitions required to use AES in C. See aesopt.h 21 | for optimisation details. 22 | */ 23 | 24 | #ifndef _AES_H 25 | #define _AES_H 26 | 27 | #include 28 | 29 | /* This include is used to find 8 & 32 bit unsigned integer types */ 30 | #include "brg_types.h" 31 | 32 | #if defined(__cplusplus) 33 | extern "C" 34 | { 35 | #endif 36 | 37 | #define AES_128 /* if a fast 128 bit key scheduler is needed */ 38 | #define AES_192 /* if a fast 192 bit key scheduler is needed */ 39 | #define AES_256 /* if a fast 256 bit key scheduler is needed */ 40 | #define AES_VAR /* if variable key size scheduler is needed */ 41 | #define AES_MODES /* if support is needed for modes */ 42 | 43 | /* The following must also be set in assembler files if being used */ 44 | 45 | #define AES_ENCRYPT /* if support for encryption is needed */ 46 | #define AES_DECRYPT /* if support for decryption is needed */ 47 | #define AES_REV_DKS /* define to reverse decryption key schedule */ 48 | 49 | #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ 50 | #define N_COLS 4 /* the number of columns in the state */ 51 | 52 | /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ 53 | /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ 54 | /* or 44, 52 or 60 32-bit words. */ 55 | 56 | #if defined( AES_VAR ) || defined( AES_256 ) 57 | #define KS_LENGTH 60 58 | #elif defined( AES_192 ) 59 | #define KS_LENGTH 52 60 | #else 61 | #define KS_LENGTH 44 62 | #endif 63 | 64 | #define AES_RETURN INT_RETURN 65 | 66 | /* the character array 'inf' in the following structures is used */ 67 | /* to hold AES context information. This AES code uses cx->inf.b[0] */ 68 | /* to hold the number of rounds multiplied by 16. The other three */ 69 | /* elements can be used by code that implements additional modes */ 70 | 71 | typedef union 72 | { uint_32t l; 73 | uint_8t b[4]; 74 | } aes_inf; 75 | 76 | typedef struct 77 | { uint_32t ks[KS_LENGTH]; 78 | aes_inf inf; 79 | } aes_encrypt_ctx; 80 | 81 | typedef struct 82 | { uint_32t ks[KS_LENGTH]; 83 | aes_inf inf; 84 | } aes_decrypt_ctx; 85 | 86 | /* This routine must be called before first use if non-static */ 87 | /* tables are being used */ 88 | 89 | AES_RETURN aes_init(void); 90 | 91 | /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */ 92 | /* those in the range 128 <= key_len <= 256 are given in bits */ 93 | 94 | #if defined( AES_ENCRYPT ) 95 | 96 | #if defined( AES_128 ) || defined( AES_VAR) 97 | AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]); 98 | #endif 99 | 100 | #if defined( AES_192 ) || defined( AES_VAR) 101 | AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]); 102 | #endif 103 | 104 | #if defined( AES_256 ) || defined( AES_VAR) 105 | AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]); 106 | #endif 107 | 108 | #if defined( AES_VAR ) 109 | AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]); 110 | #endif 111 | 112 | AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); 113 | 114 | #endif 115 | 116 | #if defined( AES_DECRYPT ) 117 | 118 | #if defined( AES_128 ) || defined( AES_VAR) 119 | AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]); 120 | #endif 121 | 122 | #if defined( AES_192 ) || defined( AES_VAR) 123 | AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]); 124 | #endif 125 | 126 | #if defined( AES_256 ) || defined( AES_VAR) 127 | AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]); 128 | #endif 129 | 130 | #if defined( AES_VAR ) 131 | AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]); 132 | #endif 133 | 134 | AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); 135 | 136 | #endif 137 | 138 | #if defined( AES_MODES ) 139 | 140 | /* Multiple calls to the following subroutines for multiple block */ 141 | /* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */ 142 | /* long messages incremantally provided that the context AND the iv */ 143 | /* are preserved between all such calls. For the ECB and CBC modes */ 144 | /* each individual call within a series of incremental calls must */ 145 | /* process only full blocks (i.e. len must be a multiple of 16) but */ 146 | /* the CFB, OFB and CTR mode calls can handle multiple incremental */ 147 | /* calls of any length. Each mode is reset when a new AES key is */ 148 | /* set but ECB and CBC operations can be reset without setting a */ 149 | /* new key by setting a new IV value. To reset CFB, OFB and CTR */ 150 | /* without setting the key, aes_mode_reset() must be called and the */ 151 | /* IV must be set. NOTE: All these calls update the IV on exit so */ 152 | /* this has to be reset if a new operation with the same IV as the */ 153 | /* previous one is required (or decryption follows encryption with */ 154 | /* the same IV array). */ 155 | 156 | AES_RETURN aes_test_alignment_detection(unsigned int n); 157 | 158 | AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 159 | int len, const aes_encrypt_ctx cx[1]); 160 | 161 | AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 162 | int len, const aes_decrypt_ctx cx[1]); 163 | 164 | AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf, 165 | int len, unsigned char *iv, const aes_encrypt_ctx cx[1]); 166 | 167 | AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf, 168 | int len, unsigned char *iv, const aes_decrypt_ctx cx[1]); 169 | 170 | AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]); 171 | 172 | AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 173 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 174 | 175 | AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 176 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 177 | 178 | #define aes_ofb_encrypt aes_ofb_crypt 179 | #define aes_ofb_decrypt aes_ofb_crypt 180 | 181 | AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf, 182 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 183 | 184 | typedef void cbuf_inc(unsigned char *cbuf); 185 | 186 | #define aes_ctr_encrypt aes_ctr_crypt 187 | #define aes_ctr_decrypt aes_ctr_crypt 188 | 189 | AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf, 190 | int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]); 191 | 192 | #endif 193 | 194 | #if defined(__cplusplus) 195 | } 196 | #endif 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/aestab.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the code for declaring the tables needed to implement 21 | AES. The file aesopt.h is assumed to be included before this header file. 22 | If there are no global variables, the definitions here can be used to put 23 | the AES tables in a structure so that a pointer can then be added to the 24 | AES context to pass them to the AES routines that need them. If this 25 | facility is used, the calling program has to ensure that this pointer is 26 | managed appropriately. In particular, the value of the t_dec(in,it) item 27 | in the table structure must be set to zero in order to ensure that the 28 | tables are initialised. In practice the three code sequences in aeskey.c 29 | that control the calls to aes_init() and the aes_init() routine itself will 30 | have to be changed for a specific implementation. If global variables are 31 | available it will generally be preferable to use them with the precomputed 32 | FIXED_TABLES option that uses static global tables. 33 | 34 | The following defines can be used to control the way the tables 35 | are defined, initialised and used in embedded environments that 36 | require special features for these purposes 37 | 38 | the 't_dec' construction is used to declare fixed table arrays 39 | the 't_set' construction is used to set fixed table values 40 | the 't_use' construction is used to access fixed table values 41 | 42 | 256 byte tables: 43 | 44 | t_xxx(s,box) => forward S box 45 | t_xxx(i,box) => inverse S box 46 | 47 | 256 32-bit word OR 4 x 256 32-bit word tables: 48 | 49 | t_xxx(f,n) => forward normal round 50 | t_xxx(f,l) => forward last round 51 | t_xxx(i,n) => inverse normal round 52 | t_xxx(i,l) => inverse last round 53 | t_xxx(l,s) => key schedule table 54 | t_xxx(i,m) => key schedule table 55 | 56 | Other variables and tables: 57 | 58 | t_xxx(r,c) => the rcon table 59 | */ 60 | 61 | #if !defined( _AESTAB_H ) 62 | #define _AESTAB_H 63 | 64 | #if defined(__cplusplus) 65 | extern "C" { 66 | #endif 67 | 68 | #define t_dec(m,n) t_##m##n 69 | #define t_set(m,n) t_##m##n 70 | #define t_use(m,n) t_##m##n 71 | 72 | #if defined(FIXED_TABLES) 73 | # if !defined( __GNUC__ ) && (defined( __MSDOS__ ) || defined( __WIN16__ )) 74 | /* make tables far data to avoid using too much DGROUP space (PG) */ 75 | # define CONST const far 76 | # else 77 | # define CONST const 78 | # endif 79 | #else 80 | # define CONST 81 | #endif 82 | 83 | #if defined(DO_TABLES) 84 | # define EXTERN 85 | #else 86 | # define EXTERN extern 87 | #endif 88 | 89 | #if defined(_MSC_VER) && defined(TABLE_ALIGN) 90 | #define ALIGN __declspec(align(TABLE_ALIGN)) 91 | #else 92 | #define ALIGN 93 | #endif 94 | 95 | #if defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1100 ) 96 | # define XP_DIR __cdecl 97 | #else 98 | # define XP_DIR 99 | #endif 100 | 101 | #if defined(DO_TABLES) && defined(FIXED_TABLES) 102 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] = b(e) 103 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] = { b(e), b(f), b(g), b(h) } 104 | EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0); 105 | #else 106 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] 107 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] 108 | EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH]; 109 | #endif 110 | 111 | #if defined( SBX_SET ) 112 | d_1(uint_8t, t_dec(s,box), sb_data, h0); 113 | #endif 114 | #if defined( ISB_SET ) 115 | d_1(uint_8t, t_dec(i,box), isb_data, h0); 116 | #endif 117 | 118 | #if defined( FT1_SET ) 119 | d_1(uint_32t, t_dec(f,n), sb_data, u0); 120 | #endif 121 | #if defined( FT4_SET ) 122 | d_4(uint_32t, t_dec(f,n), sb_data, u0, u1, u2, u3); 123 | #endif 124 | 125 | #if defined( FL1_SET ) 126 | d_1(uint_32t, t_dec(f,l), sb_data, w0); 127 | #endif 128 | #if defined( FL4_SET ) 129 | d_4(uint_32t, t_dec(f,l), sb_data, w0, w1, w2, w3); 130 | #endif 131 | 132 | #if defined( IT1_SET ) 133 | d_1(uint_32t, t_dec(i,n), isb_data, v0); 134 | #endif 135 | #if defined( IT4_SET ) 136 | d_4(uint_32t, t_dec(i,n), isb_data, v0, v1, v2, v3); 137 | #endif 138 | 139 | #if defined( IL1_SET ) 140 | d_1(uint_32t, t_dec(i,l), isb_data, w0); 141 | #endif 142 | #if defined( IL4_SET ) 143 | d_4(uint_32t, t_dec(i,l), isb_data, w0, w1, w2, w3); 144 | #endif 145 | 146 | #if defined( LS1_SET ) 147 | #if defined( FL1_SET ) 148 | #undef LS1_SET 149 | #else 150 | d_1(uint_32t, t_dec(l,s), sb_data, w0); 151 | #endif 152 | #endif 153 | 154 | #if defined( LS4_SET ) 155 | #if defined( FL4_SET ) 156 | #undef LS4_SET 157 | #else 158 | d_4(uint_32t, t_dec(l,s), sb_data, w0, w1, w2, w3); 159 | #endif 160 | #endif 161 | 162 | #if defined( IM1_SET ) 163 | d_1(uint_32t, t_dec(i,m), mm_data, v0); 164 | #endif 165 | #if defined( IM4_SET ) 166 | d_4(uint_32t, t_dec(i,m), mm_data, v0, v1, v2, v3); 167 | #endif 168 | 169 | #if defined(__cplusplus) 170 | } 171 | #endif 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/brg_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #ifndef _BRG_ENDIAN_H 22 | #define _BRG_ENDIAN_H 23 | 24 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 25 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 26 | 27 | /* Include files where endian defines and byteswap functions may reside */ 28 | #if defined( __sun ) 29 | # include 30 | #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) 31 | # include 32 | #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ 33 | defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) 34 | # include 35 | #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) 36 | # if !defined( __MINGW32__ ) && !defined( _AIX ) 37 | # include 38 | # if !defined( __BEOS__ ) 39 | # include 40 | # endif 41 | # endif 42 | #endif 43 | 44 | /* Now attempt to set the define for platform byte order using any */ 45 | /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ 46 | /* seem to encompass most endian symbol definitions */ 47 | 48 | #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) 49 | # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN 50 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 51 | # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN 52 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 53 | # endif 54 | #elif defined( BIG_ENDIAN ) 55 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 56 | #elif defined( LITTLE_ENDIAN ) 57 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 58 | #endif 59 | 60 | #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) 61 | # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN 62 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 63 | # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN 64 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 65 | # endif 66 | #elif defined( _BIG_ENDIAN ) 67 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 68 | #elif defined( _LITTLE_ENDIAN ) 69 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 70 | #endif 71 | 72 | #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) 73 | # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN 74 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 75 | # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN 76 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 77 | # endif 78 | #elif defined( __BIG_ENDIAN ) 79 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 80 | #elif defined( __LITTLE_ENDIAN ) 81 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 82 | #endif 83 | 84 | #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) 85 | # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ 86 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 87 | # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ 88 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 89 | # endif 90 | #elif defined( __BIG_ENDIAN__ ) 91 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 92 | #elif defined( __LITTLE_ENDIAN__ ) 93 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 94 | #endif 95 | 96 | /* if the platform byte order could not be determined, then try to */ 97 | /* set this define using common machine defines */ 98 | #if !defined(PLATFORM_BYTE_ORDER) 99 | 100 | #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ 101 | defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ 102 | defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ 103 | defined( vax ) || defined( vms ) || defined( VMS ) || \ 104 | defined( __VMS ) || defined( _M_X64 ) 105 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 106 | 107 | #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ 108 | defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ 109 | defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ 110 | defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ 111 | defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ 112 | defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ 113 | defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) 114 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 115 | 116 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 117 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 118 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 119 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 120 | #else 121 | # error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order 122 | #endif 123 | 124 | #endif 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/brg_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | The unsigned integer types defined here are of the form uint_t where 21 | is the length of the type; for example, the unsigned 32-bit type is 22 | 'uint_32t'. These are NOT the same as the 'C99 integer types' that are 23 | defined in the inttypes.h and stdint.h headers since attempts to use these 24 | types have shown that support for them is still highly variable. However, 25 | since the latter are of the form uint_t, a regular expression search 26 | and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t') 27 | can be used to convert the types used here to the C99 standard types. 28 | */ 29 | 30 | #ifndef _BRG_TYPES_H 31 | #define _BRG_TYPES_H 32 | 33 | #if defined(__cplusplus) 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | 39 | #if defined( _MSC_VER ) && ( _MSC_VER >= 1300 ) 40 | # include 41 | # define ptrint_t intptr_t 42 | #elif defined( __ECOS__ ) 43 | # define intptr_t unsigned int 44 | # define ptrint_t intptr_t 45 | #elif defined( __GNUC__ ) && ( __GNUC__ >= 3 ) 46 | # include 47 | # define ptrint_t intptr_t 48 | #else 49 | # define ptrint_t int 50 | #endif 51 | 52 | #ifndef BRG_UI8 53 | # define BRG_UI8 54 | # if UCHAR_MAX == 255u 55 | typedef unsigned char uint_8t; 56 | # else 57 | # error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h 58 | # endif 59 | #endif 60 | 61 | #ifndef BRG_UI16 62 | # define BRG_UI16 63 | # if USHRT_MAX == 65535u 64 | typedef unsigned short uint_16t; 65 | # else 66 | # error Please define uint_16t as a 16-bit unsigned short type in brg_types.h 67 | # endif 68 | #endif 69 | 70 | #ifndef BRG_UI32 71 | # define BRG_UI32 72 | # if UINT_MAX == 4294967295u 73 | # define li_32(h) 0x##h##u 74 | typedef unsigned int uint_32t; 75 | # elif ULONG_MAX == 4294967295u 76 | # define li_32(h) 0x##h##ul 77 | typedef unsigned long uint_32t; 78 | # elif defined( _CRAY ) 79 | # error This code needs 32-bit data types, which Cray machines do not provide 80 | # else 81 | # error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h 82 | # endif 83 | #endif 84 | 85 | #ifndef BRG_UI64 86 | # if defined( __BORLANDC__ ) && !defined( __MSDOS__ ) 87 | # define BRG_UI64 88 | # define li_64(h) 0x##h##ui64 89 | typedef unsigned __int64 uint_64t; 90 | # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */ 91 | # define BRG_UI64 92 | # define li_64(h) 0x##h##ui64 93 | typedef unsigned __int64 uint_64t; 94 | # elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful 95 | # define BRG_UI64 96 | # define li_64(h) 0x##h##ull 97 | typedef unsigned long long uint_64t; 98 | # elif defined( __MVS__ ) 99 | # define BRG_UI64 100 | # define li_64(h) 0x##h##ull 101 | typedef unsigned int long long uint_64t; 102 | # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u 103 | # if UINT_MAX == 18446744073709551615u 104 | # define BRG_UI64 105 | # define li_64(h) 0x##h##u 106 | typedef unsigned int uint_64t; 107 | # endif 108 | # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u 109 | # if ULONG_MAX == 18446744073709551615ul 110 | # define BRG_UI64 111 | # define li_64(h) 0x##h##ul 112 | typedef unsigned long uint_64t; 113 | # endif 114 | # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u 115 | # if ULLONG_MAX == 18446744073709551615ull 116 | # define BRG_UI64 117 | # define li_64(h) 0x##h##ull 118 | typedef unsigned long long uint_64t; 119 | # endif 120 | # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u 121 | # if ULONG_LONG_MAX == 18446744073709551615ull 122 | # define BRG_UI64 123 | # define li_64(h) 0x##h##ull 124 | typedef unsigned long long uint_64t; 125 | # endif 126 | # endif 127 | #endif 128 | 129 | #if !defined( BRG_UI64 ) 130 | # if defined( NEED_UINT_64T ) 131 | # error Please define uint_64t as an unsigned 64 bit type in brg_types.h 132 | # endif 133 | #endif 134 | 135 | #ifndef RETURN_VALUES 136 | # define RETURN_VALUES 137 | # if defined( DLL_EXPORT ) 138 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 139 | # define VOID_RETURN __declspec( dllexport ) void __stdcall 140 | # define INT_RETURN __declspec( dllexport ) int __stdcall 141 | # elif defined( __GNUC__ ) 142 | # define VOID_RETURN __declspec( __dllexport__ ) void 143 | # define INT_RETURN __declspec( __dllexport__ ) int 144 | # else 145 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 146 | # endif 147 | # elif defined( DLL_IMPORT ) 148 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 149 | # define VOID_RETURN __declspec( dllimport ) void __stdcall 150 | # define INT_RETURN __declspec( dllimport ) int __stdcall 151 | # elif defined( __GNUC__ ) 152 | # define VOID_RETURN __declspec( __dllimport__ ) void 153 | # define INT_RETURN __declspec( __dllimport__ ) int 154 | # else 155 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 156 | # endif 157 | # elif defined( __WATCOMC__ ) 158 | # define VOID_RETURN void __cdecl 159 | # define INT_RETURN int __cdecl 160 | # else 161 | # define VOID_RETURN void 162 | # define INT_RETURN int 163 | # endif 164 | #endif 165 | 166 | /* These defines are used to detect and set the memory alignment of pointers. 167 | Note that offsets are in bytes. 168 | 169 | ALIGN_OFFSET(x,n) return the positive or zero offset of 170 | the memory addressed by the pointer 'x' 171 | from an address that is aligned on an 172 | 'n' byte boundary ('n' is a power of 2) 173 | 174 | ALIGN_FLOOR(x,n) return a pointer that points to memory 175 | that is aligned on an 'n' byte boundary 176 | and is not higher than the memory address 177 | pointed to by 'x' ('n' is a power of 2) 178 | 179 | ALIGN_CEIL(x,n) return a pointer that points to memory 180 | that is aligned on an 'n' byte boundary 181 | and is not lower than the memory address 182 | pointed to by 'x' ('n' is a power of 2) 183 | */ 184 | 185 | #define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1)) 186 | #define ALIGN_FLOOR(x,n) ((uint_8t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1))) 187 | #define ALIGN_CEIL(x,n) ((uint_8t*)(x) + (-((ptrint_t)(x)) & ((n) - 1))) 188 | 189 | /* These defines are used to declare buffers in a way that allows 190 | faster operations on longer variables to be used. In all these 191 | defines 'size' must be a power of 2 and >= 8. NOTE that the 192 | buffer size is in bytes but the type length is in bits 193 | 194 | UNIT_TYPEDEF(x,size) declares a variable 'x' of length 195 | 'size' bits 196 | 197 | BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize' 198 | bytes defined as an array of variables 199 | each of 'size' bits (bsize must be a 200 | multiple of size / 8) 201 | 202 | UNIT_CAST(x,size) casts a variable to a type of 203 | length 'size' bits 204 | 205 | UPTR_CAST(x,size) casts a pointer to a pointer to a 206 | varaiable of length 'size' bits 207 | */ 208 | 209 | #define UI_TYPE(size) uint_##size##t 210 | #define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x 211 | #define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)] 212 | #define UNIT_CAST(x,size) ((UI_TYPE(size) )(x)) 213 | #define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x)) 214 | 215 | #if defined(__cplusplus) 216 | } 217 | #endif 218 | 219 | #endif 220 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/entropy.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #include 3 | #else 4 | #include 5 | #include 6 | #include 7 | #endif 8 | 9 | #if defined(__cplusplus) 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #ifdef _WIN32 15 | int entropy_fun(unsigned char buf[], unsigned int len) 16 | { 17 | HCRYPTPROV provider; 18 | unsigned __int64 pentium_tsc[1]; 19 | unsigned int i; 20 | int result = 0; 21 | 22 | 23 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) 24 | { 25 | result = CryptGenRandom(provider, len, buf); 26 | CryptReleaseContext(provider, 0); 27 | if (result) 28 | return len; 29 | } 30 | 31 | QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc); 32 | 33 | for(i = 0; i < 8 && i < len; ++i) 34 | buf[i] = ((unsigned char*)pentium_tsc)[i]; 35 | 36 | return i; 37 | } 38 | #else 39 | int entropy_fun(unsigned char buf[], unsigned int len) 40 | { 41 | int frand = open("/dev/random", O_RDONLY); 42 | int rlen = 0; 43 | if (frand != -1) 44 | { 45 | rlen = (int)read(frand, buf, len); 46 | close(frand); 47 | } 48 | return rlen; 49 | } 50 | #endif 51 | 52 | #if defined(__cplusplus) 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/entropy.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENTROPY_FUN_H 3 | #define _ENTROPY_FUN_H 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | int entropy_fun(unsigned char buf[], unsigned int len); 11 | 12 | #if defined(__cplusplus) 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/fileenc.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | ------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements password based file encryption and authentication 34 | using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password 35 | based key derivation. 36 | 37 | */ 38 | 39 | #include 40 | 41 | #include "fileenc.h" 42 | 43 | #if defined(__cplusplus) 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /* subroutine for data encryption/decryption */ 49 | /* this could be speeded up a lot by aligning */ 50 | /* buffers and using 32 bit operations */ 51 | 52 | static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1]) 53 | { 54 | unsigned long i = 0, pos = cx->encr_pos; 55 | 56 | while (i < d_len) { 57 | if (pos == AES_BLOCK_SIZE) { 58 | unsigned int j = 0; 59 | /* increment encryption nonce */ 60 | while (j < 8 && !++cx->nonce[j]) 61 | ++j; 62 | /* encrypt the nonce to form next xor buffer */ 63 | aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx); 64 | pos = 0; 65 | } 66 | 67 | data[i++] ^= cx->encr_bfr[pos++]; 68 | } 69 | 70 | cx->encr_pos = (unsigned int)pos; 71 | } 72 | 73 | int fcrypt_init( 74 | int mode, /* the mode to be used (input) */ 75 | const unsigned char pwd[], /* the user specified password (input) */ 76 | unsigned int pwd_len, /* the length of the password (input) */ 77 | const unsigned char salt[], /* the salt (input) */ 78 | #ifdef PASSWORD_VERIFIER 79 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 80 | #endif 81 | fcrypt_ctx cx[1]) /* the file encryption context (output) */ 82 | { 83 | unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; 84 | 85 | if (pwd_len > MAX_PWD_LENGTH) 86 | return PASSWORD_TOO_LONG; 87 | 88 | if (mode < 1 || mode > 3) 89 | return BAD_MODE; 90 | 91 | cx->mode = mode; 92 | cx->pwd_len = pwd_len; 93 | 94 | /* derive the encryption and authentication keys and the password verifier */ 95 | derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS, 96 | kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); 97 | 98 | /* initialise the encryption nonce and buffer pos */ 99 | cx->encr_pos = AES_BLOCK_SIZE; 100 | /* if we need a random component in the encryption */ 101 | /* nonce, this is where it would have to be set */ 102 | memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char)); 103 | 104 | /* initialise for encryption using key 1 */ 105 | aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx); 106 | 107 | /* initialise for authentication using key 2 */ 108 | hmac_sha_begin(cx->auth_ctx); 109 | hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx); 110 | 111 | #ifdef PASSWORD_VERIFIER 112 | memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); 113 | #endif 114 | 115 | return GOOD_RETURN; 116 | } 117 | 118 | /* perform 'in place' encryption and authentication */ 119 | 120 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 121 | { 122 | encr_data(data, data_len, cx); 123 | hmac_sha_data(data, data_len, cx->auth_ctx); 124 | } 125 | 126 | /* perform 'in place' authentication and decryption */ 127 | 128 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 129 | { 130 | hmac_sha_data(data, data_len, cx->auth_ctx); 131 | encr_data(data, data_len, cx); 132 | } 133 | 134 | /* close encryption/decryption and return the MAC value */ 135 | 136 | int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1]) 137 | { 138 | hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx); 139 | return MAC_LENGTH(cx->mode); /* return MAC length in bytes */ 140 | } 141 | 142 | #if defined(__cplusplus) 143 | } 144 | #endif 145 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/fileenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file contains the header file for fileenc.c, which implements password 34 | based file encryption and authentication using AES in CTR mode, HMAC-SHA1 35 | authentication and RFC2898 password based key derivation. 36 | */ 37 | 38 | #ifndef _FENC_H 39 | #define _FENC_H 40 | 41 | #include "aes.h" 42 | #include "hmac.h" 43 | #include "pwd2key.h" 44 | 45 | #define PASSWORD_VERIFIER 46 | 47 | #define MAX_KEY_LENGTH 32 48 | #define MAX_PWD_LENGTH 128 49 | #define MAX_SALT_LENGTH 16 50 | #define KEYING_ITERATIONS 1000 51 | 52 | #ifdef PASSWORD_VERIFIER 53 | #define PWD_VER_LENGTH 2 54 | #else 55 | #define PWD_VER_LENGTH 0 56 | #endif 57 | 58 | #define GOOD_RETURN 0 59 | #define PASSWORD_TOO_LONG -100 60 | #define BAD_MODE -101 61 | 62 | /* 63 | Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4) 64 | 65 | Mode Key Salt MAC Overhead 66 | 1 16 8 10 18 67 | 2 24 12 10 22 68 | 3 32 16 10 26 69 | 70 | The following macros assume that the mode value is correct. 71 | */ 72 | 73 | #define KEY_LENGTH(mode) (8 * (mode & 3) + 8) 74 | #define SALT_LENGTH(mode) (4 * (mode & 3) + 4) 75 | #define MAC_LENGTH(mode) (10) 76 | 77 | /* the context for file encryption */ 78 | 79 | #if defined(__cplusplus) 80 | extern "C" 81 | { 82 | #endif 83 | 84 | typedef struct 85 | { unsigned char nonce[AES_BLOCK_SIZE]; /* the CTR nonce */ 86 | unsigned char encr_bfr[AES_BLOCK_SIZE]; /* encrypt buffer */ 87 | aes_encrypt_ctx encr_ctx[1]; /* encryption context */ 88 | hmac_ctx auth_ctx[1]; /* authentication context */ 89 | unsigned int encr_pos; /* block position (enc) */ 90 | unsigned int pwd_len; /* password length */ 91 | unsigned int mode; /* File encryption mode */ 92 | } fcrypt_ctx; 93 | 94 | /* initialise file encryption or decryption */ 95 | 96 | int fcrypt_init( 97 | int mode, /* the mode to be used (input) */ 98 | const unsigned char pwd[], /* the user specified password (input) */ 99 | unsigned int pwd_len, /* the length of the password (input) */ 100 | const unsigned char salt[], /* the salt (input) */ 101 | #ifdef PASSWORD_VERIFIER 102 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 103 | #endif 104 | fcrypt_ctx cx[1]); /* the file encryption context (output) */ 105 | 106 | /* perform 'in place' encryption or decryption and authentication */ 107 | 108 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 109 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 110 | 111 | /* close encryption/decryption and return the MAC value */ 112 | /* the return value is the length of the MAC */ 113 | 114 | int fcrypt_end(unsigned char mac[], /* the MAC value (output) */ 115 | fcrypt_ctx cx[1]); /* the context (input) */ 116 | 117 | #if defined(__cplusplus) 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of HMAC, the FIPS standard keyed hash function 33 | */ 34 | 35 | #include "hmac.h" 36 | #include "brg_types.h" 37 | 38 | #if defined(__cplusplus) 39 | extern "C" 40 | { 41 | #endif 42 | 43 | /* initialise the HMAC context to zero */ 44 | void hmac_sha_begin(hmac_ctx cx[1]) 45 | { 46 | memset(cx, 0, sizeof(hmac_ctx)); 47 | } 48 | 49 | /* input the HMAC key (can be called multiple times) */ 50 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]) 51 | { 52 | if(cx->klen == HMAC_IN_DATA) /* error if further key input */ 53 | return HMAC_BAD_MODE; /* is attempted in data mode */ 54 | 55 | if(cx->klen + key_len > HASH_INPUT_SIZE) /* if the key has to be hashed */ 56 | { 57 | if(cx->klen <= HASH_INPUT_SIZE) /* if the hash has not yet been */ 58 | { /* started, initialise it and */ 59 | sha_begin(cx->ctx); /* hash stored key characters */ 60 | sha_hash(cx->key, cx->klen, cx->ctx); 61 | } 62 | 63 | sha_hash(key, key_len, cx->ctx); /* hash long key data into hash */ 64 | } 65 | else /* otherwise store key data */ 66 | memcpy(cx->key + cx->klen, key, key_len); 67 | 68 | cx->klen += key_len; /* update the key length count */ 69 | return HMAC_OK; 70 | } 71 | 72 | /* input the HMAC data (can be called multiple times) - */ 73 | /* note that this call terminates the key input phase */ 74 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]) 75 | { unsigned int i; 76 | 77 | if(cx->klen != HMAC_IN_DATA) /* if not yet in data phase */ 78 | { 79 | if(cx->klen > HASH_INPUT_SIZE) /* if key is being hashed */ 80 | { /* complete the hash and */ 81 | sha_end(cx->key, cx->ctx); /* store the result as the */ 82 | cx->klen = HASH_OUTPUT_SIZE; /* key and set new length */ 83 | } 84 | 85 | /* pad the key if necessary */ 86 | memset(cx->key + cx->klen, 0, HASH_INPUT_SIZE - cx->klen); 87 | 88 | /* xor ipad into key value */ 89 | for(i = 0; i < (HASH_INPUT_SIZE >> 2); ++i) 90 | ((uint_32t*)cx->key)[i] ^= 0x36363636; 91 | 92 | /* and start hash operation */ 93 | sha_begin(cx->ctx); 94 | sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx); 95 | 96 | /* mark as now in data mode */ 97 | cx->klen = HMAC_IN_DATA; 98 | } 99 | 100 | /* hash the data (if any) */ 101 | if(data_len) 102 | sha_hash(data, data_len, cx->ctx); 103 | } 104 | 105 | /* compute and output the MAC value */ 106 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]) 107 | { unsigned char dig[HASH_OUTPUT_SIZE]; 108 | unsigned int i; 109 | 110 | /* if no data has been entered perform a null data phase */ 111 | if(cx->klen != HMAC_IN_DATA) 112 | hmac_sha_data((const unsigned char*)0, 0, cx); 113 | 114 | sha_end(dig, cx->ctx); /* complete the inner hash */ 115 | 116 | /* set outer key value using opad and removing ipad */ 117 | for(i = 0; i < (HASH_INPUT_SIZE >> 2); ++i) 118 | ((uint_32t*)cx->key)[i] ^= 0x36363636 ^ 0x5c5c5c5c; 119 | 120 | /* perform the outer hash operation */ 121 | sha_begin(cx->ctx); 122 | sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx); 123 | sha_hash(dig, HASH_OUTPUT_SIZE, cx->ctx); 124 | sha_end(dig, cx->ctx); 125 | 126 | /* output the hash value */ 127 | for(i = 0; i < mac_len; ++i) 128 | mac[i] = dig[i]; 129 | } 130 | 131 | /* 'do it all in one go' subroutine */ 132 | void hmac_sha(const unsigned char key[], unsigned long key_len, 133 | const unsigned char data[], unsigned long data_len, 134 | unsigned char mac[], unsigned long mac_len) 135 | { hmac_ctx cx[1]; 136 | 137 | hmac_sha_begin(cx); 138 | hmac_sha_key(key, key_len, cx); 139 | hmac_sha_data(data, data_len, cx); 140 | hmac_sha_end(mac, mac_len, cx); 141 | } 142 | 143 | #if defined(__cplusplus) 144 | } 145 | #endif 146 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/hmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of HMAC, the FIPS standard keyed hash function 33 | */ 34 | 35 | #ifndef _HMAC_H 36 | #define _HMAC_H 37 | 38 | #include 39 | 40 | #if defined(__cplusplus) 41 | extern "C" 42 | { 43 | #endif 44 | 45 | #define USE_SHA1 46 | 47 | #if !defined(USE_SHA1) && !defined(USE_SHA256) 48 | #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm 49 | #endif 50 | 51 | #ifdef USE_SHA1 52 | 53 | #include "sha1.h" 54 | 55 | #define HASH_INPUT_SIZE SHA1_BLOCK_SIZE 56 | #define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE 57 | #define sha_ctx sha1_ctx 58 | #define sha_begin sha1_begin 59 | #define sha_hash sha1_hash 60 | #define sha_end sha1_end 61 | 62 | #endif 63 | 64 | #ifdef USE_SHA256 65 | 66 | #include "sha2.h" 67 | 68 | #define HASH_INPUT_SIZE SHA256_BLOCK_SIZE 69 | #define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE 70 | #define sha_ctx sha256_ctx 71 | #define sha_begin sha256_begin 72 | #define sha_hash sha256_hash 73 | #define sha_end sha256_end 74 | 75 | #endif 76 | 77 | #define HMAC_OK 0 78 | #define HMAC_BAD_MODE -1 79 | #define HMAC_IN_DATA 0xffffffff 80 | 81 | typedef struct 82 | { unsigned char key[HASH_INPUT_SIZE]; 83 | sha_ctx ctx[1]; 84 | unsigned long klen; 85 | } hmac_ctx; 86 | 87 | void hmac_sha_begin(hmac_ctx cx[1]); 88 | 89 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]); 90 | 91 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]); 92 | 93 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]); 94 | 95 | void hmac_sha(const unsigned char key[], unsigned long key_len, 96 | const unsigned char data[], unsigned long data_len, 97 | unsigned char mac[], unsigned long mac_len); 98 | 99 | #if defined(__cplusplus) 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/prng.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements a random data pool based on the use of an external 34 | entropy function. It is based on the ideas advocated by Peter Gutmann in 35 | his work on pseudo random sequence generators. It is not a 'paranoid' 36 | random sequence generator and no attempt is made to protect the pool 37 | from prying eyes either by memory locking or by techniques to obscure 38 | its location in memory. 39 | */ 40 | 41 | #include 42 | #include "prng.h" 43 | 44 | #if defined(__cplusplus) 45 | extern "C" 46 | { 47 | #endif 48 | 49 | /* mix a random data pool using the SHA1 compression function (as */ 50 | /* suggested by Peter Gutmann in his paper on random pools) */ 51 | 52 | static void prng_mix(unsigned char buf[]) 53 | { unsigned int i, len; 54 | sha1_ctx ctx[1]; 55 | 56 | /*lint -e{663} unusual array to pointer conversion */ 57 | for(i = 0; i < PRNG_POOL_SIZE; i += SHA1_DIGEST_SIZE) 58 | { 59 | /* copy digest size pool block into SHA1 hash block */ 60 | memcpy(ctx->hash, buf + (i ? i : PRNG_POOL_SIZE) 61 | - SHA1_DIGEST_SIZE, SHA1_DIGEST_SIZE); 62 | 63 | /* copy data from pool into the SHA1 data buffer */ 64 | len = PRNG_POOL_SIZE - i; 65 | memcpy(ctx->wbuf, buf + i, (len > SHA1_BLOCK_SIZE ? SHA1_BLOCK_SIZE : len)); 66 | 67 | if(len < SHA1_BLOCK_SIZE) 68 | memcpy(((char*)ctx->wbuf) + len, buf, SHA1_BLOCK_SIZE - len); 69 | 70 | /* compress using the SHA1 compression function */ 71 | sha1_compile(ctx); 72 | 73 | /* put digest size block back into the random pool */ 74 | memcpy(buf + i, ctx->hash, SHA1_DIGEST_SIZE); 75 | } 76 | } 77 | 78 | /* refresh the output buffer and update the random pool by adding */ 79 | /* entropy and remixing */ 80 | 81 | static void update_pool(prng_ctx ctx[1]) 82 | { unsigned int i = 0; 83 | 84 | /* transfer random pool data to the output buffer */ 85 | memcpy(ctx->obuf, ctx->rbuf, PRNG_POOL_SIZE); 86 | 87 | /* enter entropy data into the pool */ 88 | while(i < PRNG_POOL_SIZE) 89 | i += ctx->entropy(ctx->rbuf + i, PRNG_POOL_SIZE - i); 90 | 91 | /* invert and xor the original pool data into the pool */ 92 | for(i = 0; i < PRNG_POOL_SIZE; ++i) 93 | ctx->rbuf[i] ^= ~ctx->obuf[i]; 94 | 95 | /* mix the pool and the output buffer */ 96 | prng_mix(ctx->rbuf); 97 | prng_mix(ctx->obuf); 98 | } 99 | 100 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]) 101 | { int i; 102 | 103 | /* clear the buffers and the counter in the context */ 104 | memset(ctx, 0, sizeof(prng_ctx)); 105 | 106 | /* set the pointer to the entropy collection function */ 107 | ctx->entropy = fun; 108 | 109 | /* initialise the random data pool */ 110 | update_pool(ctx); 111 | 112 | /* mix the pool a minimum number of times */ 113 | for(i = 0; i < PRNG_MIN_MIX; ++i) 114 | prng_mix(ctx->rbuf); 115 | 116 | /* update the pool to prime the pool output buffer */ 117 | update_pool(ctx); 118 | } 119 | 120 | /* provide random bytes from the random data pool */ 121 | 122 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]) 123 | { unsigned char *rp = data; 124 | unsigned int len, pos = ctx->pos; 125 | 126 | while(data_len) 127 | { 128 | /* transfer 'data_len' bytes (or the number of bytes remaining */ 129 | /* the pool output buffer if less) into the output */ 130 | len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos); 131 | memcpy(rp, ctx->obuf + pos, len); 132 | rp += len; /* update ouput buffer position pointer */ 133 | pos += len; /* update pool output buffer pointer */ 134 | data_len -= len; /* update the remaining data count */ 135 | 136 | /* refresh the random pool if necessary */ 137 | if(pos == PRNG_POOL_SIZE) 138 | { 139 | update_pool(ctx); pos = 0; 140 | } 141 | } 142 | 143 | ctx->pos = pos; 144 | } 145 | 146 | void prng_end(prng_ctx ctx[1]) 147 | { 148 | /* ensure the data in the context is destroyed */ 149 | memset(ctx, 0, sizeof(prng_ctx)); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/prng.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This is the header file for an implementation of a random data pool based on 34 | the use of an external entropy function (inspired by Peter Gutmann's work). 35 | */ 36 | 37 | #ifndef _PRNG_H 38 | #define _PRNG_H 39 | 40 | #include "sha1.h" 41 | 42 | #define PRNG_POOL_LEN 256 /* minimum random pool size */ 43 | #define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */ 44 | 45 | /* ensure that pool length is a multiple of the SHA1 digest size */ 46 | 47 | #define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE)) 48 | 49 | #if defined(__cplusplus) 50 | extern "C" 51 | { 52 | #endif 53 | 54 | /* A function for providing entropy is a parameter in the prng_init() */ 55 | /* call. This function has the following form and returns a maximum */ 56 | /* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */ 57 | /* return less than 'len' bytes but will be repeatedly called for more */ 58 | /* data in this case. */ 59 | 60 | typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len); 61 | 62 | typedef struct 63 | { unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */ 64 | unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */ 65 | unsigned int pos; /* output buffer position */ 66 | prng_entropy_fn entropy; /* entropy function pointer */ 67 | } prng_ctx; 68 | 69 | /* initialise the random stream generator */ 70 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]); 71 | 72 | /* obtain random bytes from the generator */ 73 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]); 74 | 75 | /* close the random stream generator */ 76 | void prng_end(prng_ctx ctx[1]); 77 | 78 | #if defined(__cplusplus) 79 | } 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/pwd2key.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of RFC2898, which specifies key derivation from 33 | a password and a salt value. 34 | */ 35 | 36 | #include 37 | #include "hmac.h" 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void derive_key(const unsigned char pwd[], /* the PASSWORD */ 45 | unsigned int pwd_len, /* and its length */ 46 | const unsigned char salt[], /* the SALT and its */ 47 | unsigned int salt_len, /* length */ 48 | unsigned int iter, /* the number of iterations */ 49 | unsigned char key[], /* space for the output key */ 50 | unsigned int key_len)/* and its required length */ 51 | { 52 | unsigned int i, j, k, n_blk; 53 | unsigned char uu[HASH_OUTPUT_SIZE], ux[HASH_OUTPUT_SIZE]; 54 | hmac_ctx c1[1], c2[1], c3[1]; 55 | 56 | /* set HMAC context (c1) for password */ 57 | hmac_sha_begin(c1); 58 | hmac_sha_key(pwd, pwd_len, c1); 59 | 60 | /* set HMAC context (c2) for password and salt */ 61 | memcpy(c2, c1, sizeof(hmac_ctx)); 62 | hmac_sha_data(salt, salt_len, c2); 63 | 64 | /* find the number of SHA blocks in the key */ 65 | n_blk = 1 + (key_len - 1) / HASH_OUTPUT_SIZE; 66 | 67 | for(i = 0; i < n_blk; ++i) /* for each block in key */ 68 | { 69 | /* ux[] holds the running xor value */ 70 | memset(ux, 0, HASH_OUTPUT_SIZE); 71 | 72 | /* set HMAC context (c3) for password and salt */ 73 | memcpy(c3, c2, sizeof(hmac_ctx)); 74 | 75 | /* enter additional data for 1st block into uu */ 76 | uu[0] = (unsigned char)((i + 1) >> 24); 77 | uu[1] = (unsigned char)((i + 1) >> 16); 78 | uu[2] = (unsigned char)((i + 1) >> 8); 79 | uu[3] = (unsigned char)(i + 1); 80 | 81 | /* this is the key mixing iteration */ 82 | for(j = 0, k = 4; j < iter; ++j) 83 | { 84 | /* add previous round data to HMAC */ 85 | hmac_sha_data(uu, k, c3); 86 | 87 | /* obtain HMAC for uu[] */ 88 | hmac_sha_end(uu, HASH_OUTPUT_SIZE, c3); 89 | 90 | /* xor into the running xor block */ 91 | for(k = 0; k < HASH_OUTPUT_SIZE; ++k) 92 | ux[k] ^= uu[k]; 93 | 94 | /* set HMAC context (c3) for password */ 95 | memcpy(c3, c1, sizeof(hmac_ctx)); 96 | } 97 | 98 | /* compile key blocks into the key output */ 99 | j = 0; k = i * HASH_OUTPUT_SIZE; 100 | while(j < HASH_OUTPUT_SIZE && k < key_len) 101 | key[k++] = ux[j++]; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/pwd2key.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of RFC2898, which specifies key derivation from 33 | a password and a salt value. 34 | */ 35 | 36 | #ifndef PWD2KEY_H 37 | #define PWD2KEY_H 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void derive_key( 45 | const unsigned char pwd[], /* the PASSWORD, and */ 46 | unsigned int pwd_len, /* its length */ 47 | const unsigned char salt[], /* the SALT and its */ 48 | unsigned int salt_len, /* length */ 49 | unsigned int iter, /* the number of iterations */ 50 | unsigned char key[], /* space for the output key */ 51 | unsigned int key_len); /* and its required length */ 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | 32 | This is a byte oriented version of SHA1 that operates on arrays of bytes 33 | stored in memory. 34 | */ 35 | 36 | #include /* for memcpy() etc. */ 37 | 38 | #include "sha1.h" 39 | #include "brg_endian.h" 40 | 41 | #if defined(__cplusplus) 42 | extern "C" 43 | { 44 | #endif 45 | 46 | #if defined( _MSC_VER ) && ( _MSC_VER > 800 ) 47 | #pragma intrinsic(memcpy) 48 | #endif 49 | 50 | #if 0 && defined(_MSC_VER) 51 | #define rotl32 _lrotl 52 | #define rotr32 _lrotr 53 | #else 54 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) 55 | #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) 56 | #endif 57 | 58 | #if !defined(bswap_32) 59 | #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00)) 60 | #endif 61 | 62 | #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) 63 | #define SWAP_BYTES 64 | #else 65 | #undef SWAP_BYTES 66 | #endif 67 | 68 | #if defined(SWAP_BYTES) 69 | #define bsw_32(p,n) \ 70 | { int _i = (n); while(_i--) ((uint_32t*)p)[_i] = bswap_32(((uint_32t*)p)[_i]); } 71 | #else 72 | #define bsw_32(p,n) 73 | #endif 74 | 75 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) 76 | 77 | #if 0 78 | 79 | #define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) 80 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 81 | #define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 82 | 83 | #else /* Discovered by Rich Schroeppel and Colin Plumb */ 84 | 85 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) 86 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 87 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) 88 | 89 | #endif 90 | 91 | /* Compile 64 bytes of hash data into SHA1 context. Note */ 92 | /* that this routine assumes that the byte order in the */ 93 | /* ctx->wbuf[] at this point is in such an order that low */ 94 | /* address bytes in the ORIGINAL byte stream will go in */ 95 | /* this buffer to the high end of 32-bit words on BOTH big */ 96 | /* and little endian systems */ 97 | 98 | #ifdef ARRAY 99 | #define q(v,n) v[n] 100 | #else 101 | #define q(v,n) v##n 102 | #endif 103 | 104 | #define one_cycle(v,a,b,c,d,e,f,k,h) \ 105 | q(v,e) += rotr32(q(v,a),27) + \ 106 | f(q(v,b),q(v,c),q(v,d)) + k + h; \ 107 | q(v,b) = rotr32(q(v,b), 2) 108 | 109 | #define five_cycle(v,f,k,i) \ 110 | one_cycle(v, 0,1,2,3,4, f,k,hf(i )); \ 111 | one_cycle(v, 4,0,1,2,3, f,k,hf(i+1)); \ 112 | one_cycle(v, 3,4,0,1,2, f,k,hf(i+2)); \ 113 | one_cycle(v, 2,3,4,0,1, f,k,hf(i+3)); \ 114 | one_cycle(v, 1,2,3,4,0, f,k,hf(i+4)) 115 | 116 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]) 117 | { uint_32t *w = ctx->wbuf; 118 | 119 | #ifdef ARRAY 120 | uint_32t v[5]; 121 | memcpy(v, ctx->hash, 5 * sizeof(uint_32t)); 122 | #else 123 | uint_32t v0, v1, v2, v3, v4; 124 | v0 = ctx->hash[0]; v1 = ctx->hash[1]; 125 | v2 = ctx->hash[2]; v3 = ctx->hash[3]; 126 | v4 = ctx->hash[4]; 127 | #endif 128 | 129 | #define hf(i) w[i] 130 | 131 | five_cycle(v, ch, 0x5a827999, 0); 132 | five_cycle(v, ch, 0x5a827999, 5); 133 | five_cycle(v, ch, 0x5a827999, 10); 134 | one_cycle(v,0,1,2,3,4, ch, 0x5a827999, hf(15)); \ 135 | 136 | #undef hf 137 | #define hf(i) (w[(i) & 15] = rotl32( \ 138 | w[((i) + 13) & 15] ^ w[((i) + 8) & 15] \ 139 | ^ w[((i) + 2) & 15] ^ w[(i) & 15], 1)) 140 | 141 | one_cycle(v,4,0,1,2,3, ch, 0x5a827999, hf(16)); 142 | one_cycle(v,3,4,0,1,2, ch, 0x5a827999, hf(17)); 143 | one_cycle(v,2,3,4,0,1, ch, 0x5a827999, hf(18)); 144 | one_cycle(v,1,2,3,4,0, ch, 0x5a827999, hf(19)); 145 | 146 | five_cycle(v, parity, 0x6ed9eba1, 20); 147 | five_cycle(v, parity, 0x6ed9eba1, 25); 148 | five_cycle(v, parity, 0x6ed9eba1, 30); 149 | five_cycle(v, parity, 0x6ed9eba1, 35); 150 | 151 | five_cycle(v, maj, 0x8f1bbcdc, 40); 152 | five_cycle(v, maj, 0x8f1bbcdc, 45); 153 | five_cycle(v, maj, 0x8f1bbcdc, 50); 154 | five_cycle(v, maj, 0x8f1bbcdc, 55); 155 | 156 | five_cycle(v, parity, 0xca62c1d6, 60); 157 | five_cycle(v, parity, 0xca62c1d6, 65); 158 | five_cycle(v, parity, 0xca62c1d6, 70); 159 | five_cycle(v, parity, 0xca62c1d6, 75); 160 | 161 | #ifdef ARRAY 162 | ctx->hash[0] += v[0]; ctx->hash[1] += v[1]; 163 | ctx->hash[2] += v[2]; ctx->hash[3] += v[3]; 164 | ctx->hash[4] += v[4]; 165 | #else 166 | ctx->hash[0] += v0; ctx->hash[1] += v1; 167 | ctx->hash[2] += v2; ctx->hash[3] += v3; 168 | ctx->hash[4] += v4; 169 | #endif 170 | } 171 | 172 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]) 173 | { 174 | ctx->count[0] = ctx->count[1] = 0; 175 | ctx->hash[0] = 0x67452301; 176 | ctx->hash[1] = 0xefcdab89; 177 | ctx->hash[2] = 0x98badcfe; 178 | ctx->hash[3] = 0x10325476; 179 | ctx->hash[4] = 0xc3d2e1f0; 180 | } 181 | 182 | /* SHA1 hash data in an array of bytes into hash buffer and */ 183 | /* call the hash_compile function as required. */ 184 | 185 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) 186 | { uint_32t pos = (uint_32t)(ctx->count[0] & SHA1_MASK), 187 | space = SHA1_BLOCK_SIZE - pos; 188 | const unsigned char *sp = data; 189 | 190 | if((ctx->count[0] += len) < len) 191 | ++(ctx->count[1]); 192 | 193 | while(len >= space) /* tranfer whole blocks if possible */ 194 | { 195 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, space); 196 | sp += space; len -= space; space = SHA1_BLOCK_SIZE; pos = 0; 197 | bsw_32(ctx->wbuf, SHA1_BLOCK_SIZE >> 2); 198 | sha1_compile(ctx); 199 | } 200 | 201 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, len); 202 | } 203 | 204 | /* SHA1 final padding and digest calculation */ 205 | 206 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]) 207 | { uint_32t i = (uint_32t)(ctx->count[0] & SHA1_MASK); 208 | 209 | /* put bytes in the buffer in an order in which references to */ 210 | /* 32-bit words will put bytes with lower addresses into the */ 211 | /* top of 32 bit words on BOTH big and little endian machines */ 212 | bsw_32(ctx->wbuf, (i + 3) >> 2); 213 | 214 | /* we now need to mask valid bytes and add the padding which is */ 215 | /* a single 1 bit and as many zero bits as necessary. Note that */ 216 | /* we can always add the first padding byte here because the */ 217 | /* buffer always has at least one empty slot */ 218 | ctx->wbuf[i >> 2] &= 0xffffff80 << 8 * (~i & 3); 219 | ctx->wbuf[i >> 2] |= 0x00000080 << 8 * (~i & 3); 220 | 221 | /* we need 9 or more empty positions, one for the padding byte */ 222 | /* (above) and eight for the length count. If there is not */ 223 | /* enough space, pad and empty the buffer */ 224 | if(i > SHA1_BLOCK_SIZE - 9) 225 | { 226 | if(i < 60) ctx->wbuf[15] = 0; 227 | sha1_compile(ctx); 228 | i = 0; 229 | } 230 | else /* compute a word index for the empty buffer positions */ 231 | i = (i >> 2) + 1; 232 | 233 | while(i < 14) /* and zero pad all but last two positions */ 234 | ctx->wbuf[i++] = 0; 235 | 236 | /* the following 32-bit length fields are assembled in the */ 237 | /* wrong byte order on little endian machines but this is */ 238 | /* corrected later since they are only ever used as 32-bit */ 239 | /* word values. */ 240 | ctx->wbuf[14] = (ctx->count[1] << 3) | (ctx->count[0] >> 29); 241 | ctx->wbuf[15] = ctx->count[0] << 3; 242 | sha1_compile(ctx); 243 | 244 | /* extract the hash value as bytes in case the hash buffer is */ 245 | /* misaligned for 32-bit words */ 246 | for(i = 0; i < SHA1_DIGEST_SIZE; ++i) 247 | hval[i] = (unsigned char)(ctx->hash[i >> 2] >> (8 * (~i & 3))); 248 | } 249 | 250 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len) 251 | { sha1_ctx cx[1]; 252 | 253 | sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); 254 | } 255 | 256 | #if defined(__cplusplus) 257 | } 258 | #endif 259 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/aes/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | */ 32 | 33 | #ifndef _SHA1_H 34 | #define _SHA1_H 35 | 36 | #include 37 | #include "brg_types.h" 38 | 39 | #define SHA1_BLOCK_SIZE 64 40 | #define SHA1_DIGEST_SIZE 20 41 | 42 | #if defined(__cplusplus) 43 | extern "C" 44 | { 45 | #endif 46 | 47 | /* type to hold the SHA256 context */ 48 | 49 | typedef struct 50 | { uint_32t count[2]; 51 | uint_32t hash[5]; 52 | uint_32t wbuf[16]; 53 | } sha1_ctx; 54 | 55 | /* Note that these prototypes are the same for both bit and */ 56 | /* byte oriented implementations. However the length fields */ 57 | /* are in bytes or bits as appropriate for the version used */ 58 | /* and bit sequences are input as arrays of bytes in which */ 59 | /* bit sequences run from the most to the least significant */ 60 | /* end of each byte */ 61 | 62 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]); 63 | 64 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]); 65 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); 66 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]); 67 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len); 68 | 69 | #if defined(__cplusplus) 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for traditional PKWARE encryption 2 | Version 1.01e, February 12th, 2005 3 | 4 | Copyright (C) 1998-2005 Gilles Vollant 5 | Modifications for Info-ZIP crypting 6 | Copyright (C) 2003 Terry Thorsen 7 | 8 | This code is a modified version of crypting code in Info-ZIP distribution 9 | 10 | Copyright (C) 1990-2000 Info-ZIP. All rights reserved. 11 | 12 | See the Info-ZIP LICENSE file version 2000-Apr-09 or later for terms of use 13 | which also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 14 | 15 | The encryption/decryption parts of this source code (as opposed to the 16 | non-echoing password parts) were originally written in Europe. The 17 | whole source package can be freely distributed, including from the USA. 18 | (Prior to January 2000, re-export from the US was a violation of US law.) 19 | 20 | This encryption code is a direct transcription of the algorithm from 21 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 22 | file (appnote.txt) is distributed with the PKZIP program (even in the 23 | version without encryption capabilities). 24 | 25 | If you don't need crypting in your application, just define symbols 26 | NOCRYPT and NOUNCRYPT. 27 | */ 28 | 29 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 30 | 31 | /*********************************************************************** 32 | * Return the next byte in the pseudo-random sequence 33 | */ 34 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 35 | { 36 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 37 | * unpredictable manner on 16-bit systems; not a problem 38 | * with any known compiler so far, though */ 39 | 40 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 41 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 42 | } 43 | 44 | /*********************************************************************** 45 | * Update the encryption keys with the next byte of plain text 46 | */ 47 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 48 | { 49 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 50 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 51 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 52 | { 53 | register int keyshift = (int)((*(pkeys+1)) >> 24); 54 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 55 | } 56 | return c; 57 | } 58 | 59 | 60 | /*********************************************************************** 61 | * Initialize the encryption keys and the random header according to 62 | * the given password. 63 | */ 64 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 65 | { 66 | *(pkeys+0) = 305419896L; 67 | *(pkeys+1) = 591751049L; 68 | *(pkeys+2) = 878082192L; 69 | while (*passwd != 0) { 70 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 71 | passwd++; 72 | } 73 | } 74 | 75 | #define zdecode(pkeys,pcrc_32_tab,c) \ 76 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 77 | 78 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 79 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 80 | 81 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 82 | 83 | #define RAND_HEAD_LEN 12 84 | /* "last resort" source for second part of crypt seed pattern */ 85 | # ifndef ZCR_SEED2 86 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 87 | # endif 88 | 89 | static int crypthead(const char* passwd, /* password string */ 90 | unsigned char* buf, /* where to write header */ 91 | int bufSize, 92 | unsigned long* pkeys, 93 | const unsigned long* pcrc_32_tab, 94 | unsigned long crcForCrypting) 95 | { 96 | int n; /* index in random header */ 97 | int t; /* temporary */ 98 | int c; /* random byte */ 99 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 100 | static unsigned calls = 0; /* ensure different random header each time */ 101 | 102 | if (bufSize> 7) & 0xff; 117 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 118 | } 119 | /* Encrypt random header (last two bytes is high word of crc) */ 120 | init_keys(passwd, pkeys, pcrc_32_tab); 121 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 122 | { 123 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 124 | } 125 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 126 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 127 | return n; 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant 5 | http://www.winimage.com/zLibDll/minizip.html 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | http://result42.com 9 | 10 | This program is distributed under the terms of the same license as zlib. 11 | See the accompanying LICENSE file for the full text of the license. 12 | */ 13 | 14 | #ifndef _ZLIBIOAPI64_H 15 | #define _ZLIBIOAPI64_H 16 | 17 | #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 18 | # ifndef __USE_FILE_OFFSET64 19 | # define __USE_FILE_OFFSET64 20 | # endif 21 | # ifndef __USE_LARGEFILE64 22 | # define __USE_LARGEFILE64 23 | # endif 24 | # ifndef _LARGEFILE64_SOURCE 25 | # define _LARGEFILE64_SOURCE 26 | # endif 27 | # ifndef _FILE_OFFSET_BIT 28 | # define _FILE_OFFSET_BIT 64 29 | # endif 30 | #endif 31 | 32 | #include 33 | #include 34 | #include "zlib.h" 35 | 36 | #if defined(USE_FILE32API) 37 | # define fopen64 fopen 38 | # define ftello64 ftell 39 | # define fseeko64 fseek 40 | #else 41 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 42 | # define fopen64 fopen 43 | # define ftello64 ftello 44 | # define fseeko64 fseeko 45 | # endif 46 | # ifdef _MSC_VER 47 | # define fopen64 fopen 48 | # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 49 | # define ftello64 _ftelli64 50 | # define fseeko64 _fseeki64 51 | # else /* old MSC */ 52 | # define ftello64 ftell 53 | # define fseeko64 fseek 54 | # endif 55 | # endif 56 | #endif 57 | 58 | /* a type choosen by DEFINE */ 59 | #ifdef HAVE_64BIT_INT_CUSTOM 60 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 61 | #else 62 | # ifdef HAS_STDINT_H 63 | # include "stdint.h" 64 | typedef uint64_t ZPOS64_T; 65 | # else 66 | # if defined(_MSC_VER) || defined(__BORLANDC__) 67 | typedef unsigned __int64 ZPOS64_T; 68 | # else 69 | typedef unsigned long long int ZPOS64_T; 70 | # endif 71 | # endif 72 | #endif 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 79 | #define ZLIB_FILEFUNC_SEEK_END (2) 80 | #define ZLIB_FILEFUNC_SEEK_SET (0) 81 | 82 | #define ZLIB_FILEFUNC_MODE_READ (1) 83 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 84 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 85 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 86 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 87 | 88 | #ifndef ZCALLBACK 89 | # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \ 90 | defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 91 | # define ZCALLBACK CALLBACK 92 | # else 93 | # define ZCALLBACK 94 | # endif 95 | #endif 96 | 97 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 98 | typedef voidpf (ZCALLBACK *opendisk_file_func) OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 99 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 100 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 101 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 102 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 103 | 104 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 105 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 106 | 107 | /* here is the "old" 32 bits structure structure */ 108 | typedef struct zlib_filefunc_def_s 109 | { 110 | open_file_func zopen_file; 111 | opendisk_file_func zopendisk_file; 112 | read_file_func zread_file; 113 | write_file_func zwrite_file; 114 | tell_file_func ztell_file; 115 | seek_file_func zseek_file; 116 | close_file_func zclose_file; 117 | testerror_file_func zerror_file; 118 | voidpf opaque; 119 | } zlib_filefunc_def; 120 | 121 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 122 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 123 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 124 | typedef voidpf (ZCALLBACK *opendisk64_file_func)OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 125 | 126 | typedef struct zlib_filefunc64_def_s 127 | { 128 | open64_file_func zopen64_file; 129 | opendisk64_file_func zopendisk64_file; 130 | read_file_func zread_file; 131 | write_file_func zwrite_file; 132 | tell64_file_func ztell64_file; 133 | seek64_file_func zseek64_file; 134 | close_file_func zclose_file; 135 | testerror_file_func zerror_file; 136 | voidpf opaque; 137 | } zlib_filefunc64_def; 138 | 139 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 140 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 141 | 142 | /* now internal definition, only for zip.c and unzip.h */ 143 | typedef struct zlib_filefunc64_32_def_s 144 | { 145 | zlib_filefunc64_def zfile_func64; 146 | open_file_func zopen32_file; 147 | opendisk_file_func zopendisk32_file; 148 | tell_file_func ztell32_file; 149 | seek_file_func zseek32_file; 150 | } zlib_filefunc64_32_def; 151 | 152 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 153 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 154 | /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/ 155 | /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/ 156 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 157 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 158 | 159 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 160 | voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode)); 161 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 162 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 163 | 164 | void fill_zlib_filefunc64_32_def_from_filefunc32 OF((zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)); 165 | 166 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 167 | #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode))) 168 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 169 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/minizip/mztools.c: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | /* Code */ 8 | #include 9 | #include 10 | #include 11 | #include "zlib.h" 12 | #include "unzip.h" 13 | #include "mztools.h" 14 | 15 | #define READ_8(adr) ((unsigned char)*(adr)) 16 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) 17 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) 18 | 19 | #define WRITE_8(buff, n) do { \ 20 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ 21 | } while(0) 22 | #define WRITE_16(buff, n) do { \ 23 | WRITE_8((unsigned char*)(buff), n); \ 24 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ 25 | } while(0) 26 | #define WRITE_32(buff, n) do { \ 27 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ 28 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ 29 | } while(0) 30 | 31 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) 32 | const char* file; 33 | const char* fileOut; 34 | const char* fileOutTmp; 35 | uLong* nRecovered; 36 | uLong* bytesRecovered; 37 | { 38 | int err = Z_OK; 39 | FILE* fpZip = fopen(file, "rb"); 40 | FILE* fpOut = fopen(fileOut, "wb"); 41 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); 42 | if (fpZip != NULL && fpOut != NULL) { 43 | int entries = 0; 44 | uLong totalBytes = 0; 45 | char header[30]; 46 | char filename[256]; 47 | char extra[1024]; 48 | int offset = 0; 49 | int offsetCD = 0; 50 | while ( fread(header, 1, 30, fpZip) == 30 ) { 51 | int currentOffset = offset; 52 | 53 | /* File entry */ 54 | if (READ_32(header) == 0x04034b50) { 55 | unsigned int version = READ_16(header + 4); 56 | unsigned int gpflag = READ_16(header + 6); 57 | unsigned int method = READ_16(header + 8); 58 | unsigned int filetime = READ_16(header + 10); 59 | unsigned int filedate = READ_16(header + 12); 60 | unsigned int crc = READ_32(header + 14); /* crc */ 61 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ 62 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ 63 | unsigned int fnsize = READ_16(header + 26); /* file name length */ 64 | unsigned int extsize = READ_16(header + 28); /* extra field length */ 65 | filename[0] = extra[0] = '\0'; 66 | 67 | /* Header */ 68 | if (fwrite(header, 1, 30, fpOut) == 30) { 69 | offset += 30; 70 | } else { 71 | err = Z_ERRNO; 72 | break; 73 | } 74 | 75 | /* Filename */ 76 | if (fnsize > 0) { 77 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { 78 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { 79 | offset += fnsize; 80 | } else { 81 | err = Z_ERRNO; 82 | break; 83 | } 84 | } else { 85 | err = Z_ERRNO; 86 | break; 87 | } 88 | } else { 89 | err = Z_STREAM_ERROR; 90 | break; 91 | } 92 | 93 | /* Extra field */ 94 | if (extsize > 0) { 95 | if (fread(extra, 1, extsize, fpZip) == extsize) { 96 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { 97 | offset += extsize; 98 | } else { 99 | err = Z_ERRNO; 100 | break; 101 | } 102 | } else { 103 | err = Z_ERRNO; 104 | break; 105 | } 106 | } 107 | 108 | /* Data */ 109 | { 110 | int dataSize = cpsize; 111 | if (dataSize == 0) { 112 | dataSize = uncpsize; 113 | } 114 | if (dataSize > 0) { 115 | char* data = malloc(dataSize); 116 | if (data != NULL) { 117 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { 118 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { 119 | offset += dataSize; 120 | totalBytes += dataSize; 121 | } else { 122 | err = Z_ERRNO; 123 | } 124 | } else { 125 | err = Z_ERRNO; 126 | } 127 | free(data); 128 | if (err != Z_OK) { 129 | break; 130 | } 131 | } else { 132 | err = Z_MEM_ERROR; 133 | break; 134 | } 135 | } 136 | } 137 | 138 | /* Central directory entry */ 139 | { 140 | char centralDirectoryEntryHeader[46]; 141 | //char* comment = ""; 142 | //int comsize = (int) strlen(comment); 143 | WRITE_32(centralDirectoryEntryHeader, 0x02014b50); 144 | WRITE_16(centralDirectoryEntryHeader + 4, version); 145 | WRITE_16(centralDirectoryEntryHeader + 6, version); 146 | WRITE_16(centralDirectoryEntryHeader + 8, gpflag); 147 | WRITE_16(centralDirectoryEntryHeader + 10, method); 148 | WRITE_16(centralDirectoryEntryHeader + 12, filetime); 149 | WRITE_16(centralDirectoryEntryHeader + 14, filedate); 150 | WRITE_32(centralDirectoryEntryHeader + 16, crc); 151 | WRITE_32(centralDirectoryEntryHeader + 20, cpsize); 152 | WRITE_32(centralDirectoryEntryHeader + 24, uncpsize); 153 | WRITE_16(centralDirectoryEntryHeader + 28, fnsize); 154 | WRITE_16(centralDirectoryEntryHeader + 30, extsize); 155 | WRITE_16(centralDirectoryEntryHeader + 32, 0 /*comsize*/); 156 | WRITE_16(centralDirectoryEntryHeader + 34, 0); /* disk # */ 157 | WRITE_16(centralDirectoryEntryHeader + 36, 0); /* int attrb */ 158 | WRITE_32(centralDirectoryEntryHeader + 38, 0); /* ext attrb */ 159 | WRITE_32(centralDirectoryEntryHeader + 42, currentOffset); 160 | /* Header */ 161 | if (fwrite(centralDirectoryEntryHeader, 1, 46, fpOutCD) == 46) { 162 | offsetCD += 46; 163 | 164 | /* Filename */ 165 | if (fnsize > 0) { 166 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { 167 | offsetCD += fnsize; 168 | } else { 169 | err = Z_ERRNO; 170 | break; 171 | } 172 | } else { 173 | err = Z_STREAM_ERROR; 174 | break; 175 | } 176 | 177 | /* Extra field */ 178 | if (extsize > 0) { 179 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { 180 | offsetCD += extsize; 181 | } else { 182 | err = Z_ERRNO; 183 | break; 184 | } 185 | } 186 | 187 | /* Comment field */ 188 | /* 189 | if (comsize > 0) { 190 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { 191 | offsetCD += comsize; 192 | } else { 193 | err = Z_ERRNO; 194 | break; 195 | } 196 | } 197 | */ 198 | 199 | } else { 200 | err = Z_ERRNO; 201 | break; 202 | } 203 | } 204 | 205 | /* Success */ 206 | entries++; 207 | 208 | } else { 209 | break; 210 | } 211 | } 212 | 213 | /* Final central directory */ 214 | { 215 | int entriesZip = entries; 216 | char finalCentralDirectoryHeader[22]; 217 | //char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; 218 | //int comsize = (int) strlen(comment); 219 | if (entriesZip > 0xffff) { 220 | entriesZip = 0xffff; 221 | } 222 | WRITE_32(finalCentralDirectoryHeader, 0x06054b50); 223 | WRITE_16(finalCentralDirectoryHeader + 4, 0); /* disk # */ 224 | WRITE_16(finalCentralDirectoryHeader + 6, 0); /* disk # */ 225 | WRITE_16(finalCentralDirectoryHeader + 8, entriesZip); /* hack */ 226 | WRITE_16(finalCentralDirectoryHeader + 10, entriesZip); /* hack */ 227 | WRITE_32(finalCentralDirectoryHeader + 12, offsetCD); /* size of CD */ 228 | WRITE_32(finalCentralDirectoryHeader + 16, offset); /* offset to CD */ 229 | WRITE_16(finalCentralDirectoryHeader + 20, 0 /*comsize*/); /* comment */ 230 | 231 | /* Header */ 232 | if (fwrite(finalCentralDirectoryHeader, 1, 22, fpOutCD) == 22) { 233 | 234 | /* Comment field */ 235 | /* 236 | if (comsize > 0) { 237 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { 238 | err = Z_ERRNO; 239 | } 240 | } 241 | */ 242 | } else { 243 | err = Z_ERRNO; 244 | } 245 | } 246 | 247 | /* Final merge (file + central directory) */ 248 | fclose(fpOutCD); 249 | if (err == Z_OK) { 250 | fpOutCD = fopen(fileOutTmp, "rb"); 251 | if (fpOutCD != NULL) { 252 | int nRead; 253 | char buffer[8192]; 254 | while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { 255 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { 256 | err = Z_ERRNO; 257 | break; 258 | } 259 | } 260 | fclose(fpOutCD); 261 | } 262 | } 263 | 264 | /* Close */ 265 | fclose(fpZip); 266 | fclose(fpOut); 267 | 268 | /* Wipe temporary file */ 269 | (void)remove(fileOutTmp); 270 | 271 | /* Number of recovered entries */ 272 | if (err == Z_OK) { 273 | if (nRecovered != NULL) { 274 | *nRecovered = entries; 275 | } 276 | if (bytesRecovered != NULL) { 277 | *bytesRecovered = totalBytes; 278 | } 279 | } 280 | } else { 281 | err = Z_STREAM_ERROR; 282 | } 283 | return err; 284 | } 285 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/minizip/mztools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | #ifndef _zip_tools_H 8 | #define _zip_tools_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifndef _ZLIB_H 15 | #include "zlib.h" 16 | #endif 17 | 18 | #include "unzip.h" 19 | 20 | /* Repair a ZIP file (missing central directory) 21 | file: file to recover 22 | fileOut: output file after recovery 23 | fileOutTmp: temporary file name used for recovery 24 | */ 25 | extern int ZEXPORT unzRepair(const char* file, 26 | const char* fileOut, 27 | const char* fileOutTmp, 28 | uLong* nRecovered, 29 | uLong* bytesRecovered); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/SSZipArchive/minizip/zip.h: -------------------------------------------------------------------------------- 1 | /* zip.h -- IO on .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant 6 | http://www.winimage.com/zLibDll/minizip.html 7 | Modifications for Zip64 support 8 | Copyright (C) 2009-2010 Mathias Svensson 9 | http://result42.com 10 | 11 | This program is distributed under the terms of the same license as zlib. 12 | See the accompanying LICENSE file for the full text of the license. 13 | */ 14 | 15 | #ifndef _ZIP_H 16 | #define _ZIP_H 17 | 18 | #define HAVE_AES 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #ifndef _ZLIB_H 25 | # include "zlib.h" 26 | #endif 27 | 28 | #ifndef _ZLIBIOAPI_H 29 | # include "ioapi.h" 30 | #endif 31 | 32 | #ifdef HAVE_BZIP2 33 | # include "bzlib.h" 34 | #endif 35 | 36 | #define Z_BZIP2ED 12 37 | 38 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 39 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 40 | from (void*) without cast */ 41 | typedef struct TagzipFile__ { int unused; } zipFile__; 42 | typedef zipFile__ *zipFile; 43 | #else 44 | typedef voidp zipFile; 45 | #endif 46 | 47 | #define ZIP_OK (0) 48 | #define ZIP_EOF (0) 49 | #define ZIP_ERRNO (Z_ERRNO) 50 | #define ZIP_PARAMERROR (-102) 51 | #define ZIP_BADZIPFILE (-103) 52 | #define ZIP_INTERNALERROR (-104) 53 | 54 | #ifndef DEF_MEM_LEVEL 55 | # if MAX_MEM_LEVEL >= 8 56 | # define DEF_MEM_LEVEL 8 57 | # else 58 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 59 | # endif 60 | #endif 61 | /* default memLevel */ 62 | 63 | /* tm_zip contain date/time info */ 64 | typedef struct tm_zip_s 65 | { 66 | uInt tm_sec; /* seconds after the minute - [0,59] */ 67 | uInt tm_min; /* minutes after the hour - [0,59] */ 68 | uInt tm_hour; /* hours since midnight - [0,23] */ 69 | uInt tm_mday; /* day of the month - [1,31] */ 70 | uInt tm_mon; /* months since January - [0,11] */ 71 | uInt tm_year; /* years - [1980..2044] */ 72 | } tm_zip; 73 | 74 | typedef struct 75 | { 76 | tm_zip tmz_date; /* date in understandable format */ 77 | uLong dosDate; /* if dos_date == 0, tmu_date is used */ 78 | uLong internal_fa; /* internal file attributes 2 bytes */ 79 | uLong external_fa; /* external file attributes 4 bytes */ 80 | } zip_fileinfo; 81 | 82 | typedef const char* zipcharpc; 83 | 84 | #define APPEND_STATUS_CREATE (0) 85 | #define APPEND_STATUS_CREATEAFTER (1) 86 | #define APPEND_STATUS_ADDINZIP (2) 87 | 88 | /***************************************************************************/ 89 | /* Writing a zip file */ 90 | 91 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 92 | extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); 93 | /* Create a zipfile. 94 | 95 | pathname should contain the full pathname (by example, on a Windows XP computer 96 | "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". 97 | 98 | return NULL if zipfile cannot be opened 99 | return zipFile handle if no error 100 | 101 | If the file pathname exist and append == APPEND_STATUS_CREATEAFTER, the zip 102 | will be created at the end of the file. (useful if the file contain a self extractor code) 103 | If the file pathname exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing 104 | zip (be sure you don't add file that doesn't exist) 105 | 106 | NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile, 107 | you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy 108 | the file you did not want delete. */ 109 | 110 | extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, int append, zipcharpc* globalcomment, 111 | zlib_filefunc_def* pzlib_filefunc_def)); 112 | 113 | extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, int append, zipcharpc* globalcomment, 114 | zlib_filefunc64_def* pzlib_filefunc_def)); 115 | 116 | extern zipFile ZEXPORT zipOpen3 OF((const char *pathname, int append, ZPOS64_T disk_size, 117 | zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc_def)); 118 | /* Same as zipOpen2 but allows specification of spanned zip size */ 119 | 120 | extern zipFile ZEXPORT zipOpen3_64 OF((const void *pathname, int append, ZPOS64_T disk_size, 121 | zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)); 122 | 123 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 124 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 125 | uInt size_extrafield_global, const char* comment, int method, int level)); 126 | /* Open a file in the ZIP for writing. 127 | 128 | filename : the filename in zip (if NULL, '-' without quote will be used 129 | *zipfi contain supplemental information 130 | extrafield_local buffer to store the local header extra field data, can be NULL 131 | size_extrafield_local size of extrafield_local buffer 132 | extrafield_global buffer to store the global header extra field data, can be NULL 133 | size_extrafield_global size of extrafield_local buffer 134 | comment buffer for comment string 135 | method contain the compression method (0 for store, Z_DEFLATED for deflate) 136 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 137 | zip64 is set to 1 if a zip64 extended information block should be added to the local file header. 138 | this MUST be '1' if the uncompressed size is >= 0xffffffff. */ 139 | 140 | extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 141 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 142 | uInt size_extrafield_global, const char* comment, int method, int level, int zip64)); 143 | /* Same as zipOpenNewFileInZip with zip64 support */ 144 | 145 | extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 146 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 147 | uInt size_extrafield_global, const char* comment, int method, int level, int raw)); 148 | /* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */ 149 | 150 | extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 151 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 152 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int zip64)); 153 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 154 | 155 | extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 156 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 157 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 158 | int strategy, const char* password, uLong crcForCrypting)); 159 | /* Same as zipOpenNewFileInZip2, except 160 | windowBits, memLevel, strategy : see parameter strategy in deflateInit2 161 | password : crypting password (NULL for no crypting) 162 | crcForCrypting : crc of file to compress (needed for crypting) */ 163 | 164 | extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 165 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 166 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 167 | int strategy, const char* password, uLong crcForCrypting, int zip64)); 168 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 169 | 170 | extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 171 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 172 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 173 | int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)); 174 | /* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */ 175 | 176 | extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 177 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 178 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 179 | int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)); 180 | /* Same as zipOpenNewFileInZip4 with zip64 support */ 181 | 182 | extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, const void* buf, unsigned len)); 183 | /* Write data in the zipfile */ 184 | 185 | extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 186 | /* Close the current file in the zipfile */ 187 | 188 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, uLong uncompressed_size, uLong crc32)); 189 | extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, ZPOS64_T uncompressed_size, uLong crc32)); 190 | /* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2 191 | uncompressed_size and crc32 are value for the uncompressed size */ 192 | 193 | extern int ZEXPORT zipClose OF((zipFile file, const char* global_comment)); 194 | /* Close the zipfile */ 195 | 196 | /***************************************************************************/ 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif 201 | 202 | #endif /* _ZIP_H */ 203 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/bsdiff/bspatch.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2003-2005 Colin Percival 3 | * All rights reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted providing that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #if 0 28 | __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $"); 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | static off_t offtin(u_char *buf) 40 | { 41 | off_t y; 42 | 43 | y=buf[7]&0x7F; 44 | y=y*256;y+=buf[6]; 45 | y=y*256;y+=buf[5]; 46 | y=y*256;y+=buf[4]; 47 | y=y*256;y+=buf[3]; 48 | y=y*256;y+=buf[2]; 49 | y=y*256;y+=buf[1]; 50 | y=y*256;y+=buf[0]; 51 | 52 | if(buf[7]&0x80) y=-y; 53 | 54 | return y; 55 | } 56 | 57 | int bspatch(const char* oldfile, const char* newfile, const char* patchfile) 58 | { 59 | FILE * f, * cpf, * dpf, * epf; 60 | BZFILE * cpfbz2, * dpfbz2, * epfbz2; 61 | int cbz2err, dbz2err, ebz2err; 62 | int fd; 63 | ssize_t oldsize,newsize; 64 | ssize_t bzctrllen,bzdatalen; 65 | u_char header[32],buf[8]; 66 | u_char *old, *new; 67 | off_t oldpos,newpos; 68 | off_t ctrl[3]; 69 | off_t lenread; 70 | off_t i; 71 | 72 | // if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); 73 | 74 | /* Open patch file */ 75 | if ((f = fopen(patchfile, "r")) == NULL) 76 | // err(1, "fopen(%s)", patchfile); 77 | return -1; 78 | 79 | /* 80 | File format: 81 | 0 8 "BSDIFF40" 82 | 8 8 X 83 | 16 8 Y 84 | 24 8 sizeof(newfile) 85 | 32 X bzip2(control block) 86 | 32+X Y bzip2(diff block) 87 | 32+X+Y ??? bzip2(extra block) 88 | with control block a set of triples (x,y,z) meaning "add x bytes 89 | from oldfile to x bytes from the diff block; copy y bytes from the 90 | extra block; seek forwards in oldfile by z bytes". 91 | */ 92 | 93 | /* Read header */ 94 | if (fread(header, 1, 32, f) < 32) { 95 | if (feof(f)) 96 | // errx(1, "Corrupt patch\n"); 97 | return -1; 98 | // err(1, "fread(%s)", patchfile); 99 | return -1; 100 | } 101 | 102 | /* Check for appropriate magic */ 103 | if (memcmp(header, "BSDIFF40", 8) != 0) 104 | // errx(1, "Corrupt patch\n"); 105 | return -1; 106 | 107 | /* Read lengths from header */ 108 | bzctrllen=offtin(header+8); 109 | bzdatalen=offtin(header+16); 110 | newsize=offtin(header+24); 111 | if((bzctrllen<0) || (bzdatalen<0) || (newsize<0)) 112 | // errx(1,"Corrupt patch\n"); 113 | return -1; 114 | 115 | /* Close patch file and re-open it via libbzip2 at the right places */ 116 | if (fclose(f)) 117 | // err(1, "fclose(%s)", patchfile); 118 | return -1; 119 | if ((cpf = fopen(patchfile, "r")) == NULL) 120 | // err(1, "fopen(%s)", patchfile); 121 | return -1; 122 | if (fseeko(cpf, 32, SEEK_SET)) 123 | // err(1, "fseeko(%s, %lld)", patchfile, (long long)32); 124 | return -1; 125 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) 126 | // errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); 127 | return -1; 128 | if ((dpf = fopen(patchfile, "r")) == NULL) 129 | // err(1, "fopen(%s)", patchfile); 130 | return -1; 131 | if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) 132 | // err(1, "fseeko(%s, %lld)", patchfile,(long long)(32 + bzctrllen)); 133 | return -1; 134 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) 135 | // errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); 136 | return -1; 137 | if ((epf = fopen(patchfile, "r")) == NULL) 138 | // err(1, "fopen(%s)", patchfile); 139 | return -1; 140 | if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) 141 | // err(1, "fseeko(%s, %lld)", patchfile,(long long)(32 + bzctrllen + bzdatalen)); 142 | return -1; 143 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) 144 | // errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); 145 | return -1; 146 | 147 | if(((fd=open(oldfile,O_RDONLY,0))<0) || 148 | ((oldsize=lseek(fd,0,SEEK_END))==-1) || 149 | ((old=malloc(oldsize+1))==NULL) || 150 | (lseek(fd,0,SEEK_SET)!=0) || 151 | (read(fd,old,oldsize)!=oldsize) || 152 | (close(fd)==-1)) err(1,"%s",oldfile); 153 | if((new=malloc(newsize+1))==NULL) err(1,NULL); 154 | 155 | oldpos=0;newpos=0; 156 | while(newposnewsize) 169 | // errx(1,"Corrupt patch\n"); 170 | return -1; 171 | 172 | /* Read diff string */ 173 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); 174 | if ((lenread < ctrl[0]) || 175 | ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END))) 176 | // errx(1, "Corrupt patch\n"); 177 | return -1; 178 | 179 | /* Add old data to diff string */ 180 | for(i=0;i=0) && (oldpos+inewsize) 190 | // errx(1,"Corrupt patch\n"); 191 | return -1; 192 | 193 | /* Read extra string */ 194 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]); 195 | if ((lenread < ctrl[1]) || 196 | ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END))) 197 | // errx(1, "Corrupt patch\n"); 198 | return -1; 199 | 200 | /* Adjust pointers */ 201 | newpos+=ctrl[1]; 202 | oldpos+=ctrl[2]; 203 | }; 204 | 205 | /* Clean up the bzip2 reads */ 206 | BZ2_bzReadClose(&cbz2err, cpfbz2); 207 | BZ2_bzReadClose(&dbz2err, dpfbz2); 208 | BZ2_bzReadClose(&ebz2err, epfbz2); 209 | if (fclose(cpf) || fclose(dpf) || fclose(epf)) 210 | // err(1, "fclose(%s)", patchfile); 211 | return -1; 212 | 213 | /* Write the new file */ 214 | if(((fd=open(newfile,O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || 215 | (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) 216 | // err(1,"%s",newfile); 217 | return -1; 218 | 219 | free(new); 220 | free(old); 221 | 222 | return 0; 223 | } 224 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/bsdiff/bspatch.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2003-2005 Colin Percival 3 | * Copyright 2012 Matthew Endsley 4 | * All rights reserved 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted providing that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef BSPATCH_H 29 | #define BSPATCH_H 30 | 31 | # include 32 | //V4.3 33 | int bspatch(const char* oldfile, const char* newfile, const char* patchfile); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/md5/FileHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FileHash.h 3 | * FileMD5Hash 4 | * 5 | * Copyright © 2010-2014 Joel Lopes Da Silva. All rights reserved. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | #import 22 | 23 | @interface FileHash : NSObject 24 | 25 | + (NSString *)md5HashOfFileAtPath:(NSString *)filePath; 26 | + (NSString *)sha1HashOfFileAtPath:(NSString *)filePath; 27 | + (NSString *)sha512HashOfFileAtPath:(NSString *)filePath; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /ios/LDRNDiffUpdate/md5/FileHash.m: -------------------------------------------------------------------------------- 1 | /* 2 | * FileHash.m 3 | * FileMD5Hash 4 | * 5 | * Copyright © 2010-2014 Joel Lopes Da Silva. All rights reserved. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | // Header file 22 | #import "FileHash.h" 23 | 24 | // System framework and libraries 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | // Constants 31 | static const size_t FileHashDefaultChunkSizeForReadingData = 4096; 32 | 33 | // Function pointer types for functions used in the computation 34 | // of a cryptographic hash. 35 | typedef int (*FileHashInitFunction) (uint8_t *hashObjectPointer[]); 36 | typedef int (*FileHashUpdateFunction) (uint8_t *hashObjectPointer[], const void *data, CC_LONG len); 37 | typedef int (*FileHashFinalFunction) (unsigned char *md, uint8_t *hashObjectPointer[]); 38 | 39 | // Structure used to describe a hash computation context. 40 | typedef struct _FileHashComputationContext { 41 | FileHashInitFunction initFunction; 42 | FileHashUpdateFunction updateFunction; 43 | FileHashFinalFunction finalFunction; 44 | size_t digestLength; 45 | uint8_t **hashObjectPointer; 46 | } FileHashComputationContext; 47 | 48 | #define FileHashComputationContextInitialize(context, hashAlgorithmName) \ 49 | CC_##hashAlgorithmName##_CTX hashObjectFor##hashAlgorithmName; \ 50 | context.initFunction = (FileHashInitFunction)&CC_##hashAlgorithmName##_Init; \ 51 | context.updateFunction = (FileHashUpdateFunction)&CC_##hashAlgorithmName##_Update; \ 52 | context.finalFunction = (FileHashFinalFunction)&CC_##hashAlgorithmName##_Final; \ 53 | context.digestLength = CC_##hashAlgorithmName##_DIGEST_LENGTH; \ 54 | context.hashObjectPointer = (uint8_t **)&hashObjectFor##hashAlgorithmName 55 | 56 | 57 | @implementation FileHash 58 | 59 | + (NSString *)hashOfFileAtPath:(NSString *)filePath withComputationContext:(FileHashComputationContext *)context { 60 | NSString *result = nil; 61 | CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filePath, kCFURLPOSIXPathStyle, (Boolean)false); 62 | CFReadStreamRef readStream = fileURL ? CFReadStreamCreateWithFile(kCFAllocatorDefault, fileURL) : NULL; 63 | BOOL didSucceed = readStream ? (BOOL)CFReadStreamOpen(readStream) : NO; 64 | if (didSucceed) { 65 | 66 | // Use default value for the chunk size for reading data. 67 | const size_t chunkSizeForReadingData = FileHashDefaultChunkSizeForReadingData; 68 | 69 | // Initialize the hash object 70 | (*context->initFunction)(context->hashObjectPointer); 71 | 72 | // Feed the data to the hash object. 73 | BOOL hasMoreData = YES; 74 | while (hasMoreData) { 75 | uint8_t buffer[chunkSizeForReadingData]; 76 | CFIndex readBytesCount = CFReadStreamRead(readStream, (UInt8 *)buffer, (CFIndex)sizeof(buffer)); 77 | if (readBytesCount == -1) { 78 | break; 79 | } else if (readBytesCount == 0) { 80 | hasMoreData = NO; 81 | } else { 82 | (*context->updateFunction)(context->hashObjectPointer, (const void *)buffer, (CC_LONG)readBytesCount); 83 | } 84 | } 85 | 86 | // Compute the hash digest 87 | unsigned char digest[context->digestLength]; 88 | (*context->finalFunction)(digest, context->hashObjectPointer); 89 | 90 | // Close the read stream. 91 | CFReadStreamClose(readStream); 92 | 93 | // Proceed if the read operation succeeded. 94 | didSucceed = !hasMoreData; 95 | if (didSucceed) { 96 | char hash[2 * sizeof(digest) + 1]; 97 | for (size_t i = 0; i < sizeof(digest); ++i) { 98 | snprintf(hash + (2 * i), 3, "%02x", (int)(digest[i])); 99 | } 100 | result = [NSString stringWithUTF8String:hash]; 101 | } 102 | 103 | } 104 | if (readStream) CFRelease(readStream); 105 | if (fileURL) CFRelease(fileURL); 106 | return result; 107 | } 108 | 109 | + (NSString *)md5HashOfFileAtPath:(NSString *)filePath { 110 | FileHashComputationContext context; 111 | FileHashComputationContextInitialize(context, MD5); 112 | return [self hashOfFileAtPath:filePath withComputationContext:&context]; 113 | } 114 | 115 | + (NSString *)sha1HashOfFileAtPath:(NSString *)filePath { 116 | FileHashComputationContext context; 117 | FileHashComputationContextInitialize(context, SHA1); 118 | return [self hashOfFileAtPath:filePath withComputationContext:&context]; 119 | } 120 | 121 | + (NSString *)sha512HashOfFileAtPath:(NSString *)filePath { 122 | FileHashComputationContext context; 123 | FileHashComputationContextInitialize(context, SHA512); 124 | return [self hashOfFileAtPath:filePath withComputationContext:&context]; 125 | } 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /js/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xagreenpoint/LDReactNativeDiffUpdate/e9a99e87ede1086652abec9c20092e4c88c1cd40/js/index.js -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-diff-update", 3 | "version": "1.1.7", 4 | "description": "React native增量更新,支持多入口多业务。", 5 | "main": "js/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/xuwening/LDReactNativeDiffUpdate.git" 12 | }, 13 | "keywords": [ 14 | "react-native", 15 | "diff", 16 | "hot update" 17 | ], 18 | "author": "leadeon", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/xuwening/LDReactNativeDiffUpdate/issues" 22 | }, 23 | "homepage": "https://github.com/xuwening/LDReactNativeDiffUpdate#readme" 24 | } 25 | --------------------------------------------------------------------------------