21
21
import brut .androlib .exceptions .OutDirExistsException ;
22
22
import brut .androlib .apk .ApkInfo ;
23
23
import brut .androlib .res .ResourcesDecoder ;
24
- import brut .androlib .res .data .*;
25
- import brut .androlib .res .xml .ResXmlPatcher ;
26
24
import brut .androlib .src .SmaliDecoder ;
27
25
import brut .directory .Directory ;
28
26
import brut .directory .ExtFile ;
@@ -41,9 +39,7 @@ public class ApkDecoder {
41
39
private final static Logger LOGGER = Logger .getLogger (ApkDecoder .class .getName ());
42
40
43
41
private final Config mConfig ;
44
- private final ExtFile mApkFile ;
45
- protected final ResUnknownFiles mResUnknownFiles ;
46
- private ApkInfo mApkInfo ;
42
+ private final ApkInfo mApkInfo ;
47
43
private int mMinSdkVersion = 0 ;
48
44
49
45
private final static String SMALI_DIRNAME = "smali" ;
@@ -73,17 +69,17 @@ public ApkDecoder(Config config, File apkFile) {
73
69
74
70
public ApkDecoder (Config config , ExtFile apkFile ) {
75
71
mConfig = config ;
76
- mApkFile = apkFile ;
77
- mResUnknownFiles = new ResUnknownFiles ();
72
+ mApkInfo = new ApkInfo (apkFile );
78
73
}
79
74
80
75
public ApkInfo decode (File outDir ) throws AndrolibException , IOException , DirectoryException {
76
+ ExtFile apkFile = mApkInfo .getApkFile ();
81
77
try {
82
78
if (!mConfig .forceDelete && outDir .exists ()) {
83
79
throw new OutDirExistsException ();
84
80
}
85
81
86
- if (!mApkFile .isFile () || !mApkFile .canRead ()) {
82
+ if (!apkFile .isFile () || !apkFile .canRead ()) {
87
83
throw new InFileNotFoundException ();
88
84
}
89
85
@@ -94,11 +90,9 @@ public ApkInfo decode(File outDir) throws AndrolibException, IOException, Direct
94
90
}
95
91
outDir .mkdirs ();
96
92
97
- LOGGER .info ("Using Apktool " + ApktoolProperties .getVersion () + " on " + mApkFile . getName () );
93
+ LOGGER .info ("Using Apktool " + ApktoolProperties .getVersion () + " on " + mApkInfo . apkFileName );
98
94
99
- mApkInfo = new ApkInfo (mApkFile );
100
-
101
- ResourcesDecoder resourcesDecoder = new ResourcesDecoder (mConfig , mApkFile , mApkInfo );
95
+ ResourcesDecoder resourcesDecoder = new ResourcesDecoder (mConfig , mApkInfo );
102
96
103
97
if (mApkInfo .hasResources ()) {
104
98
switch (mConfig .decodeResources ) {
@@ -136,7 +130,7 @@ public ApkInfo decode(File outDir) throws AndrolibException, IOException, Direct
136
130
137
131
if (mApkInfo .hasMultipleSources ()) {
138
132
// foreach unknown dex file in root, lets disassemble it
139
- Set <String > files = mApkFile .getDirectory ().getFiles (true );
133
+ Set <String > files = apkFile .getDirectory ().getFiles (true );
140
134
for (String file : files ) {
141
135
if (file .endsWith (".dex" )) {
142
136
if (!file .equalsIgnoreCase ("classes.dex" )) {
@@ -174,7 +168,7 @@ public ApkInfo decode(File outDir) throws AndrolibException, IOException, Direct
174
168
return mApkInfo ;
175
169
} finally {
176
170
try {
177
- mApkFile .close ();
171
+ apkFile .close ();
178
172
} catch (IOException ignored ) {}
179
173
}
180
174
}
@@ -186,7 +180,7 @@ private void writeApkInfo(File outDir) throws AndrolibException {
186
180
private void copyManifestRaw (File outDir ) throws AndrolibException {
187
181
try {
188
182
LOGGER .info ("Copying raw manifest..." );
189
- mApkFile .getDirectory ().copyToDir (outDir , APK_MANIFEST_FILENAMES );
183
+ mApkInfo . getApkFile () .getDirectory ().copyToDir (outDir , APK_MANIFEST_FILENAMES );
190
184
} catch (DirectoryException ex ) {
191
185
throw new AndrolibException (ex );
192
186
}
@@ -195,7 +189,7 @@ private void copyManifestRaw(File outDir) throws AndrolibException {
195
189
private void copyResourcesRaw (File outDir ) throws AndrolibException {
196
190
try {
197
191
LOGGER .info ("Copying raw resources..." );
198
- mApkFile .getDirectory ().copyToDir (outDir , APK_RESOURCES_FILENAMES );
192
+ mApkInfo . getApkFile () .getDirectory ().copyToDir (outDir , APK_RESOURCES_FILENAMES );
199
193
} catch (DirectoryException ex ) {
200
194
throw new AndrolibException (ex );
201
195
}
@@ -204,7 +198,7 @@ private void copyResourcesRaw(File outDir) throws AndrolibException {
204
198
private void copySourcesRaw (File outDir , String filename ) throws AndrolibException {
205
199
try {
206
200
LOGGER .info ("Copying raw " + filename + " file..." );
207
- mApkFile .getDirectory ().copyToDir (outDir , filename );
201
+ mApkInfo . getApkFile () .getDirectory ().copyToDir (outDir , filename );
208
202
} catch (DirectoryException ex ) {
209
203
throw new AndrolibException (ex );
210
204
}
@@ -222,7 +216,7 @@ private void decodeSourcesSmali(File outDir, String filename) throws AndrolibExc
222
216
//noinspection ResultOfMethodCallIgnored
223
217
smaliDir .mkdirs ();
224
218
LOGGER .info ("Baksmaling " + filename + "..." );
225
- DexFile dexFile = SmaliDecoder .decode (mApkFile , smaliDir , filename ,
219
+ DexFile dexFile = SmaliDecoder .decode (mApkInfo . getApkFile () , smaliDir , filename ,
226
220
mConfig .baksmaliDebugMode , mConfig .apiLevel );
227
221
int minSdkVersion = dexFile .getOpcodes ().api ;
228
222
if (mMinSdkVersion == 0 || mMinSdkVersion > minSdkVersion ) {
@@ -236,7 +230,7 @@ private void decodeSourcesSmali(File outDir, String filename) throws AndrolibExc
236
230
private void copyRawFiles (File outDir ) throws AndrolibException {
237
231
LOGGER .info ("Copying assets and libs..." );
238
232
try {
239
- Directory in = mApkFile .getDirectory ();
233
+ Directory in = mApkInfo . getApkFile () .getDirectory ();
240
234
241
235
if (mConfig .decodeAssets == Config .DECODE_ASSETS_FULL ) {
242
236
if (in .containsDir ("assets" )) {
@@ -270,7 +264,7 @@ private void copyUnknownFiles(File outDir) throws AndrolibException {
270
264
LOGGER .info ("Copying unknown files..." );
271
265
File unknownOut = new File (outDir , UNK_DIRNAME );
272
266
try {
273
- Directory unk = mApkFile .getDirectory ();
267
+ Directory unk = mApkInfo . getApkFile () .getDirectory ();
274
268
275
269
// loop all items in container recursively, ignoring any that are pre-defined by aapt
276
270
Set <String > files = unk .getFiles (true );
@@ -281,11 +275,9 @@ private void copyUnknownFiles(File outDir) throws AndrolibException {
281
275
unk .copyToDir (unknownOut , file );
282
276
// let's record the name of the file, and its compression type
283
277
// so that we may re-include it the same way
284
- mResUnknownFiles .addUnknownFileInfo (file , String .valueOf (unk .getCompressionLevel (file )));
278
+ mApkInfo .addUnknownFileInfo (file , String .valueOf (unk .getCompressionLevel (file )));
285
279
}
286
280
}
287
- // update apk info
288
- mApkInfo .unknownFiles = mResUnknownFiles .getUnknownFiles ();
289
281
} catch (DirectoryException ex ) {
290
282
throw new AndrolibException (ex );
291
283
}
@@ -300,7 +292,7 @@ private void copyOriginalFiles(File outDir) throws AndrolibException {
300
292
}
301
293
302
294
try {
303
- Directory in = mApkFile .getDirectory ();
295
+ Directory in = mApkInfo . getApkFile () .getDirectory ();
304
296
if (in .containsFile ("AndroidManifest.xml" )) {
305
297
in .copyToDir (originalDir , "AndroidManifest.xml" );
306
298
}
@@ -326,7 +318,7 @@ private void copyOriginalFiles(File outDir) throws AndrolibException {
326
318
private void recordUncompressedFiles (Map <String , String > resFileMapping ) throws AndrolibException {
327
319
try {
328
320
List <String > uncompressedFilesOrExts = new ArrayList <>();
329
- Directory unk = mApkFile .getDirectory ();
321
+ Directory unk = mApkInfo . getApkFile () .getDirectory ();
330
322
Set <String > files = unk .getFiles (true );
331
323
332
324
for (String file : files ) {
0 commit comments