react-native-update 10.53.0 → 10.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-CN.md +31 -31
- package/README.md +31 -31
- package/android/jni/HDiffPatch/.travis.yml +33 -0
- package/android/jni/HDiffPatch/builds/xcode/bestParams.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/hdiffz.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/android/jni/HDiffPatch/builds/xcode/hpatchz.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/lz4.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/lzma.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/testHashClash.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/android/jni/HDiffPatch/builds/xcode/unitTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/HDiffPatch/builds/xcode/zstd.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/android/jni/lzma/DOC/7zC.txt +187 -0
- package/android/jni/lzma/DOC/7zFormat.txt +469 -0
- package/android/jni/lzma/DOC/Methods.txt +173 -0
- package/android/jni/lzma/DOC/installer.txt +166 -0
- package/android/jni/lzma/DOC/lzma-history.txt +446 -0
- package/android/jni/lzma/DOC/lzma-sdk.txt +357 -0
- package/android/jni/lzma/DOC/lzma-specification.txt +1176 -0
- package/android/jni/lzma/DOC/lzma.txt +328 -0
- package/android/jni/lzma/bin/7zS2.sfx +0 -0
- package/android/jni/lzma/bin/7zS2con.sfx +0 -0
- package/android/jni/lzma/bin/7zSD.sfx +0 -0
- package/android/jni/lzma/bin/7zdec.exe +0 -0
- package/android/jni/lzma/bin/7zr.exe +0 -0
- package/android/jni/lzma/bin/installer/config.txt +5 -0
- package/android/jni/lzma/bin/installer/cr.bat +5 -0
- package/android/jni/lzma/bin/lzma.exe +0 -0
- package/android/jni/lzma/bin/x64/7zr.exe +0 -0
- package/android/lib/arm64-v8a/librnupdate.so +0 -0
- package/android/lib/armeabi-v7a/librnupdate.so +0 -0
- package/android/lib/x86/librnupdate.so +0 -0
- package/android/lib/x86_64/librnupdate.so +0 -0
- package/android/src/main/java/cn/reactnative/modules/update/ApkInstaller.java +62 -30
- package/android/src/main/java/cn/reactnative/modules/update/ArchiveLimits.java +44 -0
- package/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +124 -40
- package/android/src/main/java/cn/reactnative/modules/update/InstallRecord.java +125 -0
- package/android/src/main/java/cn/reactnative/modules/update/NativeCheckOrchestrator.java +43 -11
- package/android/src/main/java/cn/reactnative/modules/update/NativeUpdateFlow.java +2 -0
- package/android/src/main/java/cn/reactnative/modules/update/SafeZipFile.java +90 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +79 -19
- package/android/src/main/java/cn/reactnative/modules/update/UpdateFileUtils.java +21 -0
- package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleImpl.java +56 -17
- package/android/src/main/java/cn/reactnative/modules/update/UpdateModuleSupport.java +1 -0
- package/android/src/newarch/cn/reactnative/modules/update/UpdateModule.java +5 -0
- package/android/src/oldarch/cn/reactnative/modules/update/UpdateModule.java +5 -0
- package/cpp/patch_core/archive_limits.h +38 -0
- package/cpp/patch_core/install_record.h +36 -0
- package/cpp/update_flow_core/flow_json.h +1 -0
- package/cpp/update_flow_core/update_flow_core.cpp +41 -7
- package/cpp/update_flow_core/update_flow_core.h +9 -0
- package/cpp/update_flow_core/update_flow_jni.cpp +12 -0
- package/harmony/pushy/src/main/cpp/PushyTurboModule.cpp +2 -0
- package/harmony/pushy/src/main/cpp/pushy.cpp +37 -0
- package/harmony/pushy/src/main/ets/ArchiveLimits.ts +83 -0
- package/harmony/pushy/src/main/ets/DownloadTask.ts +126 -30
- package/harmony/pushy/src/main/ets/InstallRecord.ts +129 -0
- package/harmony/pushy/src/main/ets/NativeCheckOrchestrator.ts +24 -2
- package/harmony/pushy/src/main/ets/NativePatchCore.ts +5 -0
- package/harmony/pushy/src/main/ets/PushyTurboModule.ts +12 -0
- package/harmony/pushy/src/main/ets/UpdateContext.ts +78 -15
- package/harmony/pushy.har +0 -0
- package/ios/RCTPushy/RCTPushy.mm +384 -25
- package/ios/RCTPushy/RCTPushyDownloader.mm +32 -0
- package/package.json +25 -2
- package/src/NativePushy.ts +13 -0
- package/src/client.ts +160 -43
- package/src/core.ts +17 -3
- package/src/error.ts +3 -0
- package/src/index.ts +8 -0
- package/src/locales/en.ts +3 -0
- package/src/locales/zh.ts +2 -0
- package/src/metadata.ts +166 -0
- package/src/provider.tsx +52 -17
- package/src/type.ts +22 -0
- package/src/updateFlowCore.ts +95 -4
- package/src/utils.ts +31 -19
- package/.gitmodules +0 -6
- package/BUNDLEHASH_MIGRATION.md +0 -355
- package/NATIVE_CHECKUPDATE_DESIGN.md +0 -539
- package/NATIVE_CHECK_FOLLOWUPS.md +0 -514
- package/android/jni/HDiffPatch/test/_private_searchBestParams.cpp +0 -301
- package/android/jni/HDiffPatch/test/hpatchz_test.cpp +0 -292
- package/android/jni/HDiffPatch/test/testHashClash.cpp +0 -436
- package/android/jni/HDiffPatch/test/unit_test.cpp +0 -417
- package/biome.json +0 -59
- package/cpp/patch_core/tests/fixtures/rawstored.lzma2label.patch.bin +0 -0
- package/cpp/patch_core/tests/fixtures/rawstored.new.bin +0 -0
- package/cpp/patch_core/tests/fixtures/rawstored.old.bin +0 -0
- package/cpp/patch_core/tests/fixtures/v96.hbc +0 -0
- package/cpp/patch_core/tests/fixtures/v96.meta.json +0 -1
- package/cpp/patch_core/tests/fixtures/v96.streampatch.bin +0 -0
- package/cpp/patch_core/tests/fixtures/v96.t.hbc +0 -0
- package/cpp/patch_core/tests/fixtures/v96.tpatch.bin +0 -0
- package/cpp/patch_core/tests/fixtures/v96.tstreampatch.bin +0 -0
- package/cpp/patch_core/tests/fixtures/v96b.hbc +0 -0
- package/cpp/patch_core/tests/fixtures/v98.hbc +0 -0
- package/cpp/patch_core/tests/fixtures/v98.t.hbc +0 -0
- package/cpp/patch_core/tests/fixtures/v98b.hbc +0 -0
- package/cpp/patch_core/tests/fixtures/v98b.t.hbc +0 -0
- package/cpp/patch_core/tests/hbc_transform_test.cpp +0 -384
- package/cpp/patch_core/tests/patch_core_test.cpp +0 -970
- package/cpp/update_flow_core/tests/flow_vectors.json +0 -1401
- package/cpp/update_flow_core/tests/update_flow_core_test.cpp +0 -317
- package/scripts/check-expo-version.js +0 -92
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
//_private_searchBestParams.cpp
|
|
2
|
-
// tool for HDiff
|
|
3
|
-
//
|
|
4
|
-
/*
|
|
5
|
-
The MIT License (MIT)
|
|
6
|
-
Copyright (c) 2012-2017 HouSisong
|
|
7
|
-
|
|
8
|
-
Permission is hereby granted, free of charge, to any person
|
|
9
|
-
obtaining a copy of this software and associated documentation
|
|
10
|
-
files (the "Software"), to deal in the Software without
|
|
11
|
-
restriction, including without limitation the rights to use,
|
|
12
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
copies of the Software, and to permit persons to whom the
|
|
14
|
-
Software is furnished to do so, subject to the following
|
|
15
|
-
conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be
|
|
18
|
-
included in all copies of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
21
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
22
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
23
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
24
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
25
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
26
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
27
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
*/
|
|
29
|
-
#include <iostream>
|
|
30
|
-
#include <fstream>
|
|
31
|
-
#include <string>
|
|
32
|
-
#include <vector>
|
|
33
|
-
#include <sstream>
|
|
34
|
-
#include "assert.h"
|
|
35
|
-
#include <vector>
|
|
36
|
-
#include <math.h> //pow
|
|
37
|
-
#include <string.h>
|
|
38
|
-
#include <stdlib.h>
|
|
39
|
-
#include "../libHDiffPatch/HDiff/diff.h"
|
|
40
|
-
#include "../libHDiffPatch/HPatch/patch.h"
|
|
41
|
-
#include "../libHDiffPatch/HDiff/private_diff/suffix_string.h"
|
|
42
|
-
|
|
43
|
-
typedef unsigned char TByte;
|
|
44
|
-
typedef unsigned int TUInt32;
|
|
45
|
-
typedef ptrdiff_t TInt;
|
|
46
|
-
|
|
47
|
-
void readFile(std::vector<TByte>& data,const char* fileName){
|
|
48
|
-
std::ifstream file(fileName, std::ios::in | std::ios::binary | std::ios::ate);
|
|
49
|
-
std::streampos file_length=file.tellg();
|
|
50
|
-
file.seekg(0,std::ios::beg);
|
|
51
|
-
size_t needRead=(size_t)file_length;
|
|
52
|
-
if ((file_length<0)||((std::streamsize)needRead!=(std::streamsize)file_length)) {
|
|
53
|
-
file.close();
|
|
54
|
-
std::cout<<"open read file \""<<fileName<<"\" ERROR!\n";
|
|
55
|
-
exit(1);
|
|
56
|
-
}
|
|
57
|
-
data.resize(needRead);
|
|
58
|
-
file.read((char*)data.data(), needRead);
|
|
59
|
-
std::streamsize readed=file.gcount();
|
|
60
|
-
file.close();
|
|
61
|
-
if ((std::streamsize)needRead!=readed){
|
|
62
|
-
std::cout<<"read file \""<<fileName<<"\" ERROR!\n";
|
|
63
|
-
exit(1);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
void writeFile(const std::vector<TByte>& data,const char* fileName){
|
|
68
|
-
std::ofstream file(fileName, std::ios::out | std::ios::binary | std::ios::trunc);
|
|
69
|
-
file.write((const char*)data.data(), data.size());
|
|
70
|
-
file.close();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
#define IS_NOTICE_compress_canceled 0 //for test, close compress fail notice
|
|
74
|
-
#define IS_REUSE_compress_handle 1 //for test, must in single thread
|
|
75
|
-
|
|
76
|
-
//===== select compress plugin =====
|
|
77
|
-
#define _CompressPlugin_no
|
|
78
|
-
#define _CompressPlugin_zlib
|
|
79
|
-
#define _CompressPlugin_bz2
|
|
80
|
-
#define _CompressPlugin_lzma
|
|
81
|
-
|
|
82
|
-
#include "../compress_plugin_demo.h"
|
|
83
|
-
#include "../decompress_plugin_demo.h"
|
|
84
|
-
|
|
85
|
-
struct THDiffPrivateParams{
|
|
86
|
-
int out0;
|
|
87
|
-
int out1;
|
|
88
|
-
std::string asString()const{
|
|
89
|
-
std::stringstream str;
|
|
90
|
-
str<<out0;str<<',';
|
|
91
|
-
str<<out1;
|
|
92
|
-
return str.str();
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
struct TDiffInfo{
|
|
97
|
-
hdiff_private::TSuffixString sstring;
|
|
98
|
-
std::vector<TByte> oldData;
|
|
99
|
-
std::vector<TByte> newData;
|
|
100
|
-
std::string oldFileName;
|
|
101
|
-
size_t oldFileSize;
|
|
102
|
-
std::string newFileName;
|
|
103
|
-
size_t newFileSize;
|
|
104
|
-
THDiffPrivateParams kP;
|
|
105
|
-
size_t diffSize;
|
|
106
|
-
size_t zipSize;
|
|
107
|
-
size_t bz2Size;
|
|
108
|
-
size_t lzmaSize;
|
|
109
|
-
std::string asString()const{
|
|
110
|
-
std::stringstream str;
|
|
111
|
-
|
|
112
|
-
//str<<getFileName(oldFileName); str<<'\t';
|
|
113
|
-
//str<<getFileName(newFileName); str<<'\t';
|
|
114
|
-
//str<<oldFileSize; str<<'\t';
|
|
115
|
-
//str<<newFileSize; str<<'\t';
|
|
116
|
-
str<<kP.asString(); str<<'\t';
|
|
117
|
-
str<<diffSize; str<<'\t';
|
|
118
|
-
str<<zipSize; str<<'\t';
|
|
119
|
-
str<<bz2Size; str<<'\t';
|
|
120
|
-
str<<lzmaSize;
|
|
121
|
-
|
|
122
|
-
return str.str();
|
|
123
|
-
}
|
|
124
|
-
std::string getFileName(const std::string& fullFileName)const{
|
|
125
|
-
size_t pos=fullFileName.find_last_of('/');
|
|
126
|
-
if (pos==std::string::npos)
|
|
127
|
-
return fullFileName;
|
|
128
|
-
else
|
|
129
|
-
return fullFileName.c_str()+pos+1;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
static size_t _compress_diff(const TDiffInfo& di,const hdiff_TCompress* compressPlugin,
|
|
134
|
-
hpatch_TDecompress* decompressPlugin){
|
|
135
|
-
extern void __hdiff_private__create_compressed_diff(const TByte* newData,const TByte* newData_end,
|
|
136
|
-
const TByte* oldData,const TByte* oldData_end,
|
|
137
|
-
std::vector<TByte>& out_diff,
|
|
138
|
-
const hdiff_TCompress* compressPlugin,
|
|
139
|
-
int kMinSingleMatchScore,
|
|
140
|
-
const hdiff_private::TSuffixString* sstring);
|
|
141
|
-
std::vector<TByte> diffData;
|
|
142
|
-
const TByte* newData0=di.newData.data();
|
|
143
|
-
const TByte* oldData0=di.oldData.data();
|
|
144
|
-
__hdiff_private__create_compressed_diff(newData0,newData0+di.newData.size(),
|
|
145
|
-
oldData0,oldData0+di.oldData.size(),diffData,
|
|
146
|
-
compressPlugin,di.kP.out0,&di.sstring);
|
|
147
|
-
/*
|
|
148
|
-
if (!check_compressed_diff(newData0,newData0+di.newData.size(),
|
|
149
|
-
oldData0,oldData0+di.oldData.size(),
|
|
150
|
-
diffData.data(),diffData.data()+diffData.size(),
|
|
151
|
-
decompressPlugin)){
|
|
152
|
-
std::cout<<"\ncheck hdiffz data error!!!\n";
|
|
153
|
-
exit(1);
|
|
154
|
-
}//*/
|
|
155
|
-
return diffData.size();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
void doDiff(TDiffInfo& di){
|
|
159
|
-
if (di.sstring.SASize()==0){
|
|
160
|
-
readFile(di.oldData,di.oldFileName.c_str());
|
|
161
|
-
readFile(di.newData,di.newFileName.c_str());
|
|
162
|
-
di.oldFileSize=di.oldData.size();
|
|
163
|
-
di.newFileSize=di.newData.size();
|
|
164
|
-
const TByte* oldData0=di.oldData.data();
|
|
165
|
-
di.sstring.resetSuffixString(oldData0,oldData0+di.oldData.size());
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
di.diffSize=_compress_diff(di,0,0);
|
|
169
|
-
di.zipSize=_compress_diff(di,&zlibCompressPlugin.base,&zlibDecompressPlugin);
|
|
170
|
-
di.bz2Size=_compress_diff(di,&bz2CompressPlugin.base,&bz2DecompressPlugin);
|
|
171
|
-
di.lzmaSize=_compress_diff(di,&lzmaCompressPlugin.base,&lzmaDecompressPlugin);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
static std::string rToStr(double R){
|
|
175
|
-
char buf[256];
|
|
176
|
-
sprintf(buf,"%0.6f",R);
|
|
177
|
-
return buf;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
static std::string rToTag(double cur,double& best){
|
|
181
|
-
if (cur<best){
|
|
182
|
-
best=cur;
|
|
183
|
-
return "*";
|
|
184
|
-
}else if (cur==best){
|
|
185
|
-
return "-";
|
|
186
|
-
}else{
|
|
187
|
-
return " ";
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
void getBestHDiffPrivateParams(const std::vector<std::string>& fileNames){
|
|
192
|
-
const int kDoCount=(int)fileNames.size()/2;
|
|
193
|
-
std::vector<TDiffInfo> DiList(kDoCount);
|
|
194
|
-
for (int doi=0; doi<kDoCount; ++doi) {
|
|
195
|
-
TDiffInfo& curDi=DiList[doi];
|
|
196
|
-
curDi.oldFileName=fileNames[doi*2+0];
|
|
197
|
-
curDi.newFileName=fileNames[doi*2+1];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
double bestDiffR=1e308;
|
|
201
|
-
double bestZipDiffR=1e308;
|
|
202
|
-
double bestBz2DiffR=1e308;
|
|
203
|
-
double bestLzmaDiffR=1e308;
|
|
204
|
-
double bestCompressDiffR=1e308;
|
|
205
|
-
bool isOutSrcSize=false;
|
|
206
|
-
|
|
207
|
-
int kMinSingleMatchScore;
|
|
208
|
-
for (kMinSingleMatchScore=8; kMinSingleMatchScore>=0; kMinSingleMatchScore--){{
|
|
209
|
-
THDiffPrivateParams kP={kMinSingleMatchScore,0};
|
|
210
|
-
|
|
211
|
-
double sumDiffR=1;
|
|
212
|
-
double sumZipDiffR=1;
|
|
213
|
-
double sumBz2DiffR=1;
|
|
214
|
-
double sumLzmaDiffR=1;
|
|
215
|
-
size_t sumOldSize=0;
|
|
216
|
-
size_t sumNewSize=0;
|
|
217
|
-
size_t sumDiffSize=0;
|
|
218
|
-
size_t sumZipDiffSize=0;
|
|
219
|
-
size_t sumBz2DiffSize=0;
|
|
220
|
-
size_t sumLzmaDiffSize=0;
|
|
221
|
-
for (size_t doi=0; doi<DiList.size(); ++doi) {
|
|
222
|
-
TDiffInfo& curDi=DiList[doi];
|
|
223
|
-
curDi.kP=kP;
|
|
224
|
-
|
|
225
|
-
doDiff(curDi);
|
|
226
|
-
double curDiffRi=curDi.diffSize*1.0/curDi.newFileSize;
|
|
227
|
-
double curZipDiffRi=curDi.zipSize*1.0/curDi.newFileSize;
|
|
228
|
-
double curBz2DiffRi=curDi.bz2Size*1.0/curDi.newFileSize;
|
|
229
|
-
double curLzmaDiffRi=curDi.lzmaSize*1.0/curDi.newFileSize;
|
|
230
|
-
sumDiffR*=curDiffRi;
|
|
231
|
-
sumZipDiffR*=curZipDiffRi;
|
|
232
|
-
sumBz2DiffR*=curBz2DiffRi;
|
|
233
|
-
sumLzmaDiffR*=curLzmaDiffRi;
|
|
234
|
-
sumNewSize+=curDi.newFileSize;
|
|
235
|
-
sumOldSize+=curDi.oldFileSize;
|
|
236
|
-
sumDiffSize+=curDi.diffSize;
|
|
237
|
-
sumZipDiffSize+=curDi.zipSize;
|
|
238
|
-
sumBz2DiffSize+=curDi.bz2Size;
|
|
239
|
-
sumLzmaDiffSize+=curDi.lzmaSize;
|
|
240
|
-
//std::cout<<curDi.asString()<<"\t"<<curDiffRi<<"\n";
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const double curDiffR=pow(sumDiffR,1.0/kDoCount);
|
|
244
|
-
const double curZipDiffR=pow(sumZipDiffR,1.0/kDoCount);
|
|
245
|
-
const double curBz2DiffR=pow(sumBz2DiffR,1.0/kDoCount);
|
|
246
|
-
const double curLzmaDiffR=pow(sumLzmaDiffR,1.0/kDoCount);
|
|
247
|
-
const double curCompressDiffR=(curZipDiffR*1+curBz2DiffR*1+curLzmaDiffR*1)/(1+1+1);
|
|
248
|
-
{
|
|
249
|
-
TDiffInfo curDi;
|
|
250
|
-
curDi.oldFileName="";
|
|
251
|
-
curDi.newFileName="";
|
|
252
|
-
curDi.kP=kP;
|
|
253
|
-
curDi.oldFileSize=sumOldSize;
|
|
254
|
-
curDi.newFileSize=sumNewSize;
|
|
255
|
-
curDi.diffSize=sumDiffSize;
|
|
256
|
-
curDi.zipSize=sumZipDiffSize;
|
|
257
|
-
curDi.bz2Size=sumBz2DiffSize;
|
|
258
|
-
curDi.lzmaSize=sumLzmaDiffSize;
|
|
259
|
-
|
|
260
|
-
std:: string tag="";
|
|
261
|
-
tag+=rToTag(curDiffR,bestDiffR);
|
|
262
|
-
tag+=rToTag(curZipDiffR,bestZipDiffR);
|
|
263
|
-
tag+=rToTag(curBz2DiffR,bestBz2DiffR);
|
|
264
|
-
tag+=rToTag(curLzmaDiffR,bestLzmaDiffR);
|
|
265
|
-
tag+="| "+rToTag(curCompressDiffR,bestCompressDiffR);
|
|
266
|
-
if (!isOutSrcSize){
|
|
267
|
-
isOutSrcSize=true;
|
|
268
|
-
std::cout<<"null zlab bz2 lzma "<<"\t";
|
|
269
|
-
std::cout<<"diff( "<<curDi.oldFileSize<<", ";
|
|
270
|
-
std::cout<<curDi.newFileSize<<")\n";
|
|
271
|
-
}
|
|
272
|
-
std::cout<<tag<<"\t";
|
|
273
|
-
std::cout<<curDi.asString()<<"\t"
|
|
274
|
-
<<rToStr(curDiffR)<<"\t"
|
|
275
|
-
<<rToStr(curZipDiffR)<<"\t"
|
|
276
|
-
<<rToStr(curBz2DiffR)<<"\t"
|
|
277
|
-
<<rToStr(curLzmaDiffR);
|
|
278
|
-
|
|
279
|
-
std::cout<<"\n";
|
|
280
|
-
}
|
|
281
|
-
}}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
int main(int argc, const char * argv[]){
|
|
286
|
-
if ((argc<3)||((argc-1)%2!=0)) {
|
|
287
|
-
throw argc;
|
|
288
|
-
}
|
|
289
|
-
std::vector<std::string> fileNames;
|
|
290
|
-
for (int i=1; i<argc; ++i) {
|
|
291
|
-
std::cout<<argv[i]<<"\n";
|
|
292
|
-
fileNames.push_back(argv[i]);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
getBestHDiffPrivateParams(fileNames);
|
|
296
|
-
|
|
297
|
-
std::cout<<"\nok!\n";
|
|
298
|
-
return 0;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
// hpatchz_test.cpp
|
|
2
|
-
// Created by housisong on 2021/02/04.
|
|
3
|
-
/*
|
|
4
|
-
The MIT License (MIT)
|
|
5
|
-
Copyright (c) 2012-2021 HouSisong
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person
|
|
8
|
-
obtaining a copy of this software and associated documentation
|
|
9
|
-
files (the "Software"), to deal in the Software without
|
|
10
|
-
restriction, including without limitation the rights to use,
|
|
11
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
copies of the Software, and to permit persons to whom the
|
|
13
|
-
Software is furnished to do so, subject to the following
|
|
14
|
-
conditions:
|
|
15
|
-
|
|
16
|
-
The above copyright notice and this permission notice shall be
|
|
17
|
-
included in all copies of the Software.
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
20
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
21
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
22
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
23
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
24
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
25
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
26
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
27
|
-
*/
|
|
28
|
-
#include <stdio.h>
|
|
29
|
-
#include <iostream>
|
|
30
|
-
#include <string.h>
|
|
31
|
-
#include <string>
|
|
32
|
-
#include <fstream>
|
|
33
|
-
#include <math.h>
|
|
34
|
-
#include <vector>
|
|
35
|
-
#include <algorithm>
|
|
36
|
-
#include <stdio.h>
|
|
37
|
-
#include <assert.h>
|
|
38
|
-
#include <sstream>
|
|
39
|
-
#define _IS_NEED_MAIN 0
|
|
40
|
-
#define _IS_NEED_PRINT_LOG 0
|
|
41
|
-
#define _IS_NEED_ORIGINAL 0
|
|
42
|
-
#include "../hpatchz.c"
|
|
43
|
-
|
|
44
|
-
bool is_attack =true;
|
|
45
|
-
size_t kLoopCount = 1000;
|
|
46
|
-
const bool is_log_attack_tag=true;
|
|
47
|
-
size_t cache_size_memory=0;
|
|
48
|
-
int error_count=0;
|
|
49
|
-
size_t test_i=0;
|
|
50
|
-
size_t caseNum=0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const size_t kMaxSize=400*1024*1024;
|
|
54
|
-
|
|
55
|
-
template<class T> inline static
|
|
56
|
-
std::string _to_string(const T& v){
|
|
57
|
-
std::ostringstream os;
|
|
58
|
-
os<<v;
|
|
59
|
-
return os.str();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#define tcheck(v) { if (!(v)) { assert(false); throw "error!"; } }
|
|
63
|
-
|
|
64
|
-
void readFile(std::vector<TByte>& data,const char* fileName){
|
|
65
|
-
bool _isInClear=false;
|
|
66
|
-
int result=0;
|
|
67
|
-
const size_t kStepSize =1024*256;
|
|
68
|
-
size_t readPos=0;
|
|
69
|
-
size_t fileSize;
|
|
70
|
-
hpatch_TFileStreamInput fStream;
|
|
71
|
-
hpatch_TFileStreamInput_init(&fStream);
|
|
72
|
-
|
|
73
|
-
check(hpatch_TFileStreamInput_open(&fStream,fileName),-1,"open file");
|
|
74
|
-
fileSize=(size_t)fStream.base.streamSize;
|
|
75
|
-
check(fileSize==fStream.base.streamSize,-1,"file size");
|
|
76
|
-
try{
|
|
77
|
-
data.resize(fileSize);
|
|
78
|
-
}catch(...){
|
|
79
|
-
check(false,-1,"memory alloc");
|
|
80
|
-
}
|
|
81
|
-
while (readPos<fileSize){
|
|
82
|
-
size_t readLen=kStepSize;
|
|
83
|
-
if (readPos+readLen>fileSize)
|
|
84
|
-
readLen=fileSize-readPos;
|
|
85
|
-
check(fStream.base.read(&fStream.base,readPos,data.data()+readPos,
|
|
86
|
-
data.data()+readPos+readLen),-1,"read file data");
|
|
87
|
-
readPos+=readLen;
|
|
88
|
-
}
|
|
89
|
-
clear:
|
|
90
|
-
_isInClear=true;
|
|
91
|
-
check(hpatch_TFileStreamInput_close(&fStream),-1,"close file");
|
|
92
|
-
if (0!=result)
|
|
93
|
-
throw result;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
hpatch_BOOL _hpatchz(const hpatch_TStreamOutput* _out_newData,
|
|
98
|
-
const hpatch_TStreamInput* oldData,
|
|
99
|
-
const hpatch_TStreamInput* compressedDiff,
|
|
100
|
-
TByte* temp_cache,TByte* temp_cache_end){
|
|
101
|
-
hpatch_TStreamOutput out_newData=*_out_newData;
|
|
102
|
-
hpatch_TDecompress* decompressPlugin=0;
|
|
103
|
-
hpatch_compressedDiffInfo diffInfo;
|
|
104
|
-
if (!getCompressedDiffInfo(&diffInfo,compressedDiff))
|
|
105
|
-
return hpatch_FALSE;
|
|
106
|
-
if (oldData->streamSize!=diffInfo.oldDataSize)
|
|
107
|
-
return hpatch_FALSE;
|
|
108
|
-
out_newData.streamSize=diffInfo.newDataSize;
|
|
109
|
-
{
|
|
110
|
-
if (strlen(diffInfo.compressType)>0){
|
|
111
|
-
#ifdef _CompressPlugin_zlib
|
|
112
|
-
if ((!decompressPlugin)&&zlibDecompressPlugin.is_can_open(diffInfo.compressType))
|
|
113
|
-
decompressPlugin=&zlibDecompressPlugin;
|
|
114
|
-
#endif
|
|
115
|
-
#ifdef _CompressPlugin_bz2
|
|
116
|
-
if ((!decompressPlugin)&&bz2DecompressPlugin.is_can_open(diffInfo.compressType))
|
|
117
|
-
decompressPlugin=&bz2DecompressPlugin;
|
|
118
|
-
#endif
|
|
119
|
-
#ifdef _CompressPlugin_lzma
|
|
120
|
-
if ((!decompressPlugin)&&lzmaDecompressPlugin.is_can_open(diffInfo.compressType))
|
|
121
|
-
decompressPlugin=&lzmaDecompressPlugin;
|
|
122
|
-
#endif
|
|
123
|
-
#if (defined(_CompressPlugin_lz4) || (defined(_CompressPlugin_lz4hc)))
|
|
124
|
-
if ((!decompressPlugin)&&lz4DecompressPlugin.is_can_open(diffInfo.compressType))
|
|
125
|
-
decompressPlugin=&lz4DecompressPlugin;
|
|
126
|
-
#endif
|
|
127
|
-
#ifdef _CompressPlugin_zstd
|
|
128
|
-
if ((!decompressPlugin)&&zstdDecompressPlugin.is_can_open(diffInfo.compressType))
|
|
129
|
-
decompressPlugin=&zstdDecompressPlugin;
|
|
130
|
-
#endif
|
|
131
|
-
}
|
|
132
|
-
if (decompressPlugin==0)
|
|
133
|
-
return hpatch_FALSE;
|
|
134
|
-
}
|
|
135
|
-
return patch_decompress_with_cache(&out_newData,oldData,compressedDiff,decompressPlugin,
|
|
136
|
-
temp_cache,temp_cache_end);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
int _attack_seed=1111;
|
|
140
|
-
void testCaseByData(const std::string& tag,const std::vector<TByte>& oldData,const std::vector<TByte>& patData,
|
|
141
|
-
const std::vector<TByte>& newData,int& error_count){
|
|
142
|
-
double time0=clock_s();
|
|
143
|
-
static std::vector<TByte> out_newData;
|
|
144
|
-
static std::vector<TByte> temp_cache;
|
|
145
|
-
temp_cache.resize(cache_size_memory);
|
|
146
|
-
if (out_newData.empty()) out_newData.reserve(kMaxSize);
|
|
147
|
-
out_newData.resize(newData.size());
|
|
148
|
-
hpatch_TStreamOutput out_newStream;
|
|
149
|
-
mem_as_hStreamOutput(&out_newStream,out_newData.data(),out_newData.data()+out_newData.size());
|
|
150
|
-
std::cout << tag;
|
|
151
|
-
if (is_attack){
|
|
152
|
-
static std::vector<TByte> _oldData;
|
|
153
|
-
static std::vector<TByte> _patData;
|
|
154
|
-
if (_oldData.empty()) _oldData.reserve(kMaxSize);
|
|
155
|
-
if (_patData.empty()) _patData.reserve(kMaxSize);
|
|
156
|
-
_oldData.resize(oldData.size());
|
|
157
|
-
_patData.resize(patData.size());
|
|
158
|
-
hpatch_TStreamInput oldStream;
|
|
159
|
-
hpatch_TStreamInput patStream;
|
|
160
|
-
|
|
161
|
-
for (size_t i=0;i<kLoopCount;++i,++test_i){
|
|
162
|
-
srand(_attack_seed);
|
|
163
|
-
_attack_seed+=1;
|
|
164
|
-
//if (test_i<?) continue;
|
|
165
|
-
|
|
166
|
-
long in_codeSize=(long)patData.size();
|
|
167
|
-
memcpy(_oldData.data(),oldData.data(),_oldData.size());
|
|
168
|
-
memcpy(_patData.data(),patData.data(),in_codeSize);
|
|
169
|
-
mem_as_hStreamInput(&oldStream,_oldData.data(),_oldData.data()+_oldData.size());
|
|
170
|
-
mem_as_hStreamInput(&patStream,_patData.data(),_patData.data()+in_codeSize);
|
|
171
|
-
|
|
172
|
-
if (in_codeSize){
|
|
173
|
-
const long randCount=(long)(1+pow(rand()*(1.0/RAND_MAX),4)*1000);
|
|
174
|
-
for (long r=0; r<randCount; ++r){
|
|
175
|
-
_patData[rand()%in_codeSize]=rand();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
try{
|
|
179
|
-
if (is_log_attack_tag) std::cout <<tag;
|
|
180
|
-
_hpatchz(&out_newStream,&oldStream,&patStream,
|
|
181
|
-
temp_cache.data(),temp_cache.data()+temp_cache.size());
|
|
182
|
-
if (is_log_attack_tag) std::cout <<" | test_i=="<<test_i<<" , error_count=="<<error_count<<"\n";
|
|
183
|
-
}catch (...){
|
|
184
|
-
++error_count;
|
|
185
|
-
std::cout <<" | test_i=="<<test_i<<" , error_count=="<<error_count<<", throw error\n";
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}else{
|
|
189
|
-
hpatch_TStreamInput oldStream;
|
|
190
|
-
hpatch_TStreamInput patStream;
|
|
191
|
-
mem_as_hStreamInput(&oldStream,oldData.data(),oldData.data()+oldData.size());
|
|
192
|
-
mem_as_hStreamInput(&patStream,patData.data(),patData.data()+patData.size());
|
|
193
|
-
for (size_t i=0;i<kLoopCount;++i,++test_i){
|
|
194
|
-
memset(out_newData.data(),0,out_newData.size());
|
|
195
|
-
|
|
196
|
-
hpatch_BOOL result=_hpatchz(&out_newStream,&oldStream,&patStream,
|
|
197
|
-
temp_cache.data(),temp_cache.data()+temp_cache.size());
|
|
198
|
-
if (!result){
|
|
199
|
-
++error_count;
|
|
200
|
-
std::cout <<" | test_i=="<<test_i<<" , error_count=="<<error_count<<", return error_code=="<<result<<" \n";
|
|
201
|
-
}else if (0!=memcmp(out_newData.data(),newData.data(),out_newData.size())){
|
|
202
|
-
++error_count;
|
|
203
|
-
std::cout <<" | test_i=="<<test_i<<" , error_count=="<<error_count<<", out error data\n";
|
|
204
|
-
}else if (is_log_attack_tag){
|
|
205
|
-
std::cout <<" | test_i=="<<test_i<<" , error_count=="<<error_count<<"\n";
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
std::cout <<" | error_count=="<<error_count<<" , tescaseNum=="<<caseNum<<" , time: "<<(clock_s()-time0)<<" s\n";
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
void testCaseByFile(const std::string& tag,const std::string& oldPath,const std::string& patPath,const std::string& newPath,int& error_count){
|
|
213
|
-
static std::vector<TByte> oldData;
|
|
214
|
-
static std::vector<TByte> patData;
|
|
215
|
-
static std::vector<TByte> newData;
|
|
216
|
-
if (oldData.empty()) oldData.reserve(kMaxSize);
|
|
217
|
-
if (patData.empty()) patData.reserve(kMaxSize);
|
|
218
|
-
if (newData.empty()) newData.reserve(kMaxSize);
|
|
219
|
-
if (oldPath.empty())
|
|
220
|
-
oldData.resize(0);
|
|
221
|
-
else
|
|
222
|
-
readFile(oldData,oldPath.c_str());
|
|
223
|
-
readFile(patData,patPath.c_str());
|
|
224
|
-
readFile(newData,newPath.c_str());
|
|
225
|
-
|
|
226
|
-
testCaseByData(tag,oldData,patData,newData,error_count);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
void testCaseByLine(const std::string& dirPath,const std::string& line,int& error_count){
|
|
230
|
-
//1|12306_5.2.11.apk--12306_5.1.2.apk.hdiffz_-s-16.pat
|
|
231
|
-
size_t pos0=line.find_first_of('|');
|
|
232
|
-
if (pos0==std::string::npos) return;
|
|
233
|
-
pos0+=1;
|
|
234
|
-
const std::string patFile=line.substr(pos0);
|
|
235
|
-
size_t pos1=line.find(".apk--")+4;
|
|
236
|
-
const std::string newFile=line.substr(pos0,pos1-pos0);
|
|
237
|
-
pos0=pos1+2;
|
|
238
|
-
pos1=line.find(".hdiffz_");
|
|
239
|
-
const std::string oldFile=line.substr(pos0,pos1-pos0);
|
|
240
|
-
pos0=pos1+8;
|
|
241
|
-
pos1=line.size()-4;
|
|
242
|
-
const std::string diffOp=line.substr(pos0,pos1-pos0);
|
|
243
|
-
|
|
244
|
-
std::string tag=newFile + " <- " + oldFile + " " + diffOp;
|
|
245
|
-
testCaseByFile(tag,oldFile.empty()?oldFile:(dirPath+oldFile),dirPath+patFile,dirPath+newFile,error_count);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
size_t aToSize(const char* str) {
|
|
249
|
-
size_t result;
|
|
250
|
-
if (!kmg_to_size(str, strlen(str), &result))
|
|
251
|
-
throw str;
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
int main(int argc, const char* argv[]){
|
|
256
|
-
double time0=clock_s();
|
|
257
|
-
std::cout <<"hpatchz(attack code)\n";
|
|
258
|
-
std::cout <<"input \"patch_test.txt\" file path for test\n";
|
|
259
|
-
tcheck(argc==5);
|
|
260
|
-
std::string txt=argv[1];
|
|
261
|
-
is_attack = (1==aToSize(argv[2]));
|
|
262
|
-
kLoopCount= aToSize(argv[3]);
|
|
263
|
-
cache_size_memory=aToSize(argv[4]);
|
|
264
|
-
|
|
265
|
-
size_t pos=txt.find_last_of('\\');
|
|
266
|
-
if (pos==std::string::npos)
|
|
267
|
-
pos=txt.find_last_of('/');
|
|
268
|
-
std::string dirPath=txt.substr(0,(pos==std::string::npos)?0:pos+1);
|
|
269
|
-
|
|
270
|
-
std::vector<std::string> lines;
|
|
271
|
-
{
|
|
272
|
-
std::fstream fs(txt);
|
|
273
|
-
std::string line;
|
|
274
|
-
while(std::getline(fs,line)){
|
|
275
|
-
size_t strLen=line.size();
|
|
276
|
-
if ((strLen>0)&&(line[strLen-1]=='\r')) line.resize(strLen-1);
|
|
277
|
-
lines.push_back(line);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
for (size_t i=0;i<lines.size();++i){
|
|
282
|
-
const std::string& line=lines[i];
|
|
283
|
-
++caseNum;
|
|
284
|
-
testCaseByLine(dirPath,line,error_count);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
std::cout << "\n error_count=="<<error_count<<"\n";
|
|
288
|
-
std::cout <<"\ndone!\n";
|
|
289
|
-
std::cout <<"\n time: "<<(clock_s()-time0)<<" s\n";
|
|
290
|
-
return error_count;
|
|
291
|
-
}
|
|
292
|
-
|