Skip to content

Commit

Permalink
Merge pull request #92 from sisong/dev
Browse files Browse the repository at this point in the history
fix some normalize apk fail
  • Loading branch information
sisong authored Dec 9, 2023
2 parents 9151d02 + e4903df commit a71c1c5
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 101 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [ApkDiffPatch]
[![release](https://img.shields.io/badge/release-v1.6.2-blue.svg)](https://github.com/sisong/ApkDiffPatch/releases)
[![release](https://img.shields.io/badge/release-v1.7.0-blue.svg)](https://github.com/sisong/ApkDiffPatch/releases)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sisong/ApkDiffPatch/blob/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/sisong/ApkDiffPatch/pulls)
[![+issue Welcome](https://img.shields.io/github/issues-raw/sisong/ApkDiffPatch?color=green&label=%2Bissue%20welcome)](https://github.com/sisong/ApkDiffPatch/issues)
Expand All @@ -17,7 +17,6 @@ You can use this library (and Android NDK) to delta update your Apk.
[zlib]: https://github.com/madler/zlib
[lzma]: https://www.7-zip.org/sdk.html
[Apk v2 sign]: https://source.android.com/security/apksigning/v2
[Apk v3 sign]: https://source.android.com/security/apksigning/v3
[Jar sign]: https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File
[BsDiff]: http://www.daemonology.net/bsdiff/
[archive-patcher]: https://github.com/google/archive-patcher
Expand All @@ -40,11 +39,11 @@ ZipPatch() support multi-thread parallel compress mode when writing zip file, wh
* NOTE:
if your need newZip(patch result) file byte by byte equal, `Released newZip` := **ApkNormalized**(newZip) before run ZipDiff, AND You should not modify the zlib version (unless it is certified compatible);
if your apk(or jar) file used [Jar sign](Apk v1 sign), is same as zip file;
if your apk used [Apk v2 sign](or [Apk v3 sign]), `Released newZip` := AndroidSDK#apksigner(**ApkNormalized**(AndroidSDK#apksigner(newZip))) before ZipDiff;
if your apk used [Apk v2 sign](or [later](https://source.android.com/security/apksigning/v3)), `Released newApk` := AndroidSDK#apksigner(**ApkNormalized**(newApk)) before ZipDiff;

* NOTE:
ApkDiffPath can't be used in the Android app store, because it requires re-signing apk;
[sfpatcher] like [archive-patcher], is designed for Android app store, but patch is much faster than archive-patcher.
ApkDiffPath can't be used by Android app store, because it requires re-signing apks before diff.
[sfpatcher] not require re-signing apks (like [archive-patcher]), is designed for Android app store, patch speed up by a factor of xx than archive-patcher & run with O(1) memory.

---
## Why [ApkDiffPatch]
Expand Down
20 changes: 16 additions & 4 deletions builds/vc/ApkNormalized.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,36 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<AdditionalOptions>/wd4819 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<AdditionalOptions>/wd4819 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
Expand All @@ -151,11 +157,14 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_IS_USED_MULTITHREAD=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
Expand All @@ -170,6 +179,9 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
20 changes: 16 additions & 4 deletions builds/vc/ZipDiff.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,36 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<AdditionalOptions>/wd4819 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<AdditionalOptions>/wd4819 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
Expand All @@ -171,11 +177,14 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
Expand All @@ -190,6 +199,9 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
20 changes: 16 additions & 4 deletions builds/vc/ZipPatch.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,36 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<AdditionalOptions>/wd4819 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<AdditionalOptions>/wd4819 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
Expand All @@ -156,11 +162,14 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAs>Default</CompileAs>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
Expand All @@ -175,6 +184,9 @@
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>..\..\HDiffPatch\builds\vc\longPathAware.exe.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
2 changes: 1 addition & 1 deletion lzma
Submodule lzma updated 1 files
+6 −2 C/Sha256Opt.c
45 changes: 30 additions & 15 deletions src/apk_normalized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#endif

static void printUsage(){
printf("usage: ApkNormalized srcApk out_newApk [-nce-isNotCompressEmptyFile] [-cl-compressLevel] [-as-alignSize] [-v] \n"
printf("usage: ApkNormalized srcApk normalizedApk [-cl-compressLevel]\n"
"options:\n"
" input srcApk file can *.zip *.jar *.apk file type;\n"
" ApkNormalized normalized zip file:\n"
Expand All @@ -52,19 +52,25 @@ static void printUsage(){
" remove all data descriptor, reserve & normalized Extra field and Comment,\n"
" compatible with jar sign(apk v1 sign), etc...\n"
" if apk file used apk v2 sign, must re sign apk file after ApkNormalized;\n"
" release newApk:=AndroidSDK#apksigner(out_newApk)\n"
" -nce-isNotCompressEmptyFile\n"
" if found compressed empty file in the zip, need change it to not compressed?\n"
" -nce-0 keep the original compress setting for empty file;\n"
" WARNING: if have compressed empty file,\n"
" it can't patch by old ZipPatch(version<v1.3.5)!\n"
" -nce-1 DEFAULT, not compress all empty file.\n"
" release signedApk:=AndroidSDK#apksigner(normalizedApk)\n"
" -cl-compressLevel\n"
" set zlib compress level, 0<=compressLevel<=9, DEFAULT -cl-6;\n"
" if set 9, compress rate is high, but compress speed is very slow when patching.\n"
" set zlib compress level [0..9], recommended 4,5,6, DEFAULT -cl-6;\n"
" WARNING: -cl not recommended 7,8,9, compress rate is high, but\n"
" compress speed is very slow when patching.\n"
" -as-alignSize\n"
" set align size for uncompressed file in zip for optimize app run speed,\n"
" 1 <= alignSize <= 4k, recommended 4,8, DEFAULT -as-8.\n"
" NOTE: if -ap-1, must 4096%%alignSize==0;\n"
" -ap-isPageAlignSoFile\n"
" if found uncompressed .so file in the zip, need align it to 4k page?\n"
" -ap-0 not page-align uncompressed .so files;\n"
" -ap-1 DEFAULT, page-align uncompressed .so files.\n"
" -nce-isNotCompressEmptyFile\n"
" if found compressed empty file in the zip, need change it to not compressed?\n"
" -nce-0 keep the original compress setting for empty file;\n"
" WARNING: if have compressed empty file,\n"
" it can't patch by old(version<v1.3.5) ZipPatch!\n"
" -nce-1 DEFAULT, not compress all empty file.\n"
" -v output Version info. \n"
);
}
Expand Down Expand Up @@ -97,6 +103,7 @@ int main(int argc,char* argv[]){

int normalized_cmd_line(int argc, const char * argv[]){
hpatch_BOOL isNotCompressEmptyFile=_kNULL_VALUE;
hpatch_BOOL isPageAlignSoFile=_kNULL_VALUE;
hpatch_BOOL isOutputVersion=_kNULL_VALUE;
size_t compressLevel = _kNULL_SIZE;
size_t alignSize = _kNULL_SIZE;
Expand Down Expand Up @@ -144,8 +151,11 @@ int normalized_cmd_line(int argc, const char * argv[]){
_options_check(kmg_to_size(pnum,strlen(pnum),&alignSize),"-as-?");
const size_t _kMaxAlignSize=4*1024;
_options_check((1<=alignSize)&&(alignSize<=_kMaxAlignSize),"-as-?");
}else if ((op[2]=='p')&&(op[3]=='-')&&((op[4]=='0')||(op[4]=='1'))){
_options_check(isPageAlignSoFile==_kNULL_VALUE,"-ap-?");
isPageAlignSoFile=(hpatch_BOOL)(op[4]=='1');
}else{
_options_check(hpatch_FALSE,"-as?");
_options_check(hpatch_FALSE,"-a?");
}
} break;
default: {
Expand All @@ -155,6 +165,8 @@ int normalized_cmd_line(int argc, const char * argv[]){
}
if (isNotCompressEmptyFile==_kNULL_VALUE)
isNotCompressEmptyFile=hpatch_TRUE;
if (isPageAlignSoFile==_kNULL_VALUE)
isPageAlignSoFile=hpatch_TRUE;
if (compressLevel==_kNULL_SIZE)
compressLevel=kDefaultZlibCompressLevel;
if (alignSize==_kNULL_SIZE)
Expand All @@ -166,22 +178,25 @@ int normalized_cmd_line(int argc, const char * argv[]){
if (arg_values_size==0)
return 0; //ok
}


if (compressLevel>6)
printf("WARNING: not recommended 7,8,9, compress rate is high, but compress speed is very slow when patching.\n");

_options_check(arg_values_size==2,"count");
const char* srcApk=arg_values[0];
const char* dstApk=arg_values[1];
printf("src: \"%s\"\nout: \"%s\"\n",srcApk,dstApk);
double time0=clock_s();
int apkV1SignFilesRemoved=0;
int apkFilesRemoved=0;
if (!ZipNormalized(srcApk,dstApk,(int)alignSize,(int)compressLevel,
isNotCompressEmptyFile?true:false,&apkV1SignFilesRemoved)){
(bool)isNotCompressEmptyFile,(bool)isPageAlignSoFile,&apkFilesRemoved)){
printf("\nrun ApkNormalized ERROR!\n");
return 1;
}
printf("run ApkNormalized ok!\n");

//check
if (!getZipIsSame(srcApk,dstApk,apkV1SignFilesRemoved)){
if (!getZipIsSame(srcApk,dstApk,apkFilesRemoved)){
printf("ApkNormalized result file check ERROR!\n");
return 1;
}
Expand Down
Loading

0 comments on commit a71c1c5

Please sign in to comment.