30
30
import brut .directory .ExtFile ;
31
31
import brut .directory .FileDirectory ;
32
32
import brut .util .Duo ;
33
+ import com .sun .org .apache .xpath .internal .operations .And ;
33
34
import org .xmlpull .v1 .XmlSerializer ;
34
35
35
36
import java .io .File ;
@@ -48,10 +49,6 @@ public class ResourcesDecoder {
48
49
private final ApkInfo mApkInfo ;
49
50
private final Map <String , String > mResFileMapping = new HashMap <>();
50
51
51
- private final static String [] APK_RESOURCES_FILENAMES = new String [] {
52
- "resources.arsc" , "res" , "r" , "R" };
53
- private final static String [] APK_MANIFEST_FILENAMES = new String [] {
54
- "AndroidManifest.xml" };
55
52
private final static String [] IGNORED_PACKAGES = new String [] {
56
53
"android" , "com.htc" , "com.lge" , "com.lge.internal" , "yi" , "flyme" , "air.com.adobe.appentry" ,
57
54
"FFFFFFFFFFFFFFFFFFFFFF" };
@@ -85,9 +82,9 @@ public ResTable getResTable() throws AndrolibException {
85
82
throw new AndrolibException (
86
83
"Apk doesn't contain either AndroidManifest.xml file or resources.arsc file" );
87
84
}
88
- if (hasResources () && !mResTable .isMainPkgLoaded ()) {
89
- mResTable .loadMainPkg (mApkFile );
90
- }
85
+ // if (hasResources() && !mResTable.isMainPkgLoaded()) {
86
+ // mResTable.loadMainPkg(mApkFile);
87
+ // }
91
88
return mResTable ;
92
89
}
93
90
@@ -101,38 +98,31 @@ public Map<String, String> getResFileMapping() {
101
98
102
99
public void decodeManifest (File outDir ) throws AndrolibException {
103
100
if (hasManifest ()) {
104
- if (mConfig .decodeResources == Config .DECODE_RESOURCES_FULL ||
105
- mConfig .forceDecodeManifest == Config .FORCE_DECODE_MANIFEST_FULL ) {
106
- decodeManifest (getResTable (), mApkFile , outDir );
107
- if (hasResources ()) {
108
- if (!mConfig .analysisMode ) {
109
- // Remove versionName / versionCode (aapt API 16)
110
- //
111
- // check for a mismatch between resources.arsc package and the package listed in AndroidManifest
112
- // also remove the android::versionCode / versionName from manifest for rebuild
113
- // this is a required change to prevent aapt warning about conflicting versions
114
- // it will be passed as a parameter to aapt like "--min-sdk-version" via apktool.yml
115
- adjustPackageManifest (getResTable (), outDir .getAbsolutePath () + File .separator + "AndroidManifest.xml" );
116
-
117
- ResXmlPatcher .removeManifestVersions (new File (
118
- outDir .getAbsolutePath () + File .separator + "AndroidManifest.xml" ));
119
-
120
- // update apk info
121
- mApkInfo .packageInfo .forcedPackageId = String .valueOf (mResTable .getPackageId ());
122
- }
123
- }
124
- }
125
- else {
126
- try {
127
- LOGGER .info ("Copying raw manifest..." );
128
- mApkFile .getDirectory ().copyToDir (outDir , APK_MANIFEST_FILENAMES );
129
- } catch (DirectoryException ex ) {
130
- throw new AndrolibException (ex );
101
+ decodeManifest (getResTable (), mApkFile , outDir );
102
+ if (hasResources ()) {
103
+ if (!mConfig .analysisMode ) {
104
+ // Remove versionName / versionCode (aapt API 16)
105
+ //
106
+ // check for a mismatch between resources.arsc package and the package listed in AndroidManifest
107
+ // also remove the android::versionCode / versionName from manifest for rebuild
108
+ // this is a required change to prevent aapt warning about conflicting versions
109
+ // it will be passed as a parameter to aapt like "--min-sdk-version" via apktool.yml
110
+ adjustPackageManifest (getResTable (), outDir .getAbsolutePath () + File .separator + "AndroidManifest.xml" );
111
+
112
+ ResXmlPatcher .removeManifestVersions (new File (
113
+ outDir .getAbsolutePath () + File .separator + "AndroidManifest.xml" ));
114
+
115
+ // update apk info
116
+ mApkInfo .packageInfo .forcedPackageId = String .valueOf (mResTable .getPackageId ());
131
117
}
132
118
}
133
119
}
134
120
}
135
121
122
+ public void updateApkInfo (File outDir ) throws AndrolibException {
123
+ mResTable .initApkInfo (mApkInfo , outDir );
124
+ }
125
+
136
126
private void decodeManifest (ResTable resTable , ExtFile apkFile , File outDir )
137
127
throws AndrolibException {
138
128
@@ -191,22 +181,14 @@ private ExtMXSerializer getResXmlSerializer() {
191
181
return serial ;
192
182
}
193
183
184
+ public void load () throws AndrolibException {
185
+ mResTable .loadMainPkg (mApkFile );
186
+ }
187
+
194
188
public ResTable decodeResources (File outDir ) throws AndrolibException {
195
189
if (hasResources ()) {
196
- switch (mConfig .decodeResources ) {
197
- case Config .DECODE_RESOURCES_NONE :
198
- try {
199
- LOGGER .info ("Copying raw resources..." );
200
- mApkFile .getDirectory ().copyToDir (outDir , APK_RESOURCES_FILENAMES );
201
- } catch (DirectoryException ex ) {
202
- throw new AndrolibException (ex );
203
- }
204
- break ;
205
- case Config .DECODE_RESOURCES_FULL :
206
- decodeResources (getResTable (), mApkFile , outDir );
207
- break ;
208
- }
209
- mResTable .initApkInfo (mApkInfo , outDir );
190
+ load ();
191
+ decodeResources (getResTable (), mApkFile , outDir );
210
192
}
211
193
return mResTable ;
212
194
}
0 commit comments