21
21
import brut .androlib .exceptions .CantFindFrameworkResException ;
22
22
import brut .androlib .exceptions .InFileNotFoundException ;
23
23
import brut .androlib .exceptions .OutDirExistsException ;
24
- import brut .androlib .options .BuildOptions ;
25
24
import brut .common .BrutException ;
26
25
import brut .directory .DirectoryException ;
26
+ import brut .directory .ExtFile ;
27
27
import brut .util .AaptManager ;
28
28
import brut .util .OSDetection ;
29
29
import org .apache .commons .cli .*;
@@ -74,25 +74,28 @@ public static void main(String[] args) throws BrutException {
74
74
setAdvanceMode ();
75
75
}
76
76
77
+ Config config = Config .getDefaultConfig ();
78
+ initConfig (commandLine , config );
79
+
77
80
boolean cmdFound = false ;
78
81
for (String opt : commandLine .getArgs ()) {
79
82
if (opt .equalsIgnoreCase ("d" ) || opt .equalsIgnoreCase ("decode" )) {
80
- cmdDecode (commandLine );
83
+ cmdDecode (commandLine , config );
81
84
cmdFound = true ;
82
85
} else if (opt .equalsIgnoreCase ("b" ) || opt .equalsIgnoreCase ("build" )) {
83
- cmdBuild (commandLine );
86
+ cmdBuild (commandLine , config );
84
87
cmdFound = true ;
85
88
} else if (opt .equalsIgnoreCase ("if" ) || opt .equalsIgnoreCase ("install-framework" )) {
86
- cmdInstallFramework (commandLine );
89
+ cmdInstallFramework (commandLine , config );
87
90
cmdFound = true ;
88
91
} else if (opt .equalsIgnoreCase ("empty-framework-dir" )) {
89
- cmdEmptyFrameworkDirectory (commandLine );
92
+ cmdEmptyFrameworkDirectory (commandLine , config );
90
93
cmdFound = true ;
91
94
} else if (opt .equalsIgnoreCase ("list-frameworks" )) {
92
- cmdListFrameworks (commandLine );
95
+ cmdListFrameworks (commandLine , config );
93
96
cmdFound = true ;
94
97
} else if (opt .equalsIgnoreCase ("publicize-resources" )) {
95
- cmdPublicizeResources (commandLine );
98
+ cmdPublicizeResources (commandLine , config );
96
99
cmdFound = true ;
97
100
}
98
101
}
@@ -108,54 +111,55 @@ public static void main(String[] args) throws BrutException {
108
111
}
109
112
}
110
113
111
- private static void cmdDecode (CommandLine cli ) throws AndrolibException {
112
- ApkDecoder decoder = new ApkDecoder ();
114
+ private static void initConfig (CommandLine cli , Config config ) {
115
+ if (cli .hasOption ("p" ) || cli .hasOption ("frame-path" )) {
116
+ config .frameworkDirectory = cli .getOptionValue ("p" );
117
+ }
118
+ if (cli .hasOption ("t" ) || cli .hasOption ("tag" )) {
119
+ config .frameworkTag = cli .getOptionValue ("t" );
120
+ }
121
+ if (cli .hasOption ("api" ) || cli .hasOption ("api-level" )) {
122
+ config .apiLevel = Integer .parseInt (cli .getOptionValue ("api" ));
123
+ }
124
+ }
113
125
114
- int paraCount = cli .getArgList ().size ();
115
- String apkName = cli .getArgList ().get (paraCount - 1 );
116
- File outDir ;
126
+ private static void cmdDecode (CommandLine cli , Config config ) throws AndrolibException {
127
+ String apkName = getLastArg (cli );
117
128
118
- // check for options
129
+ // check decode options
119
130
if (cli .hasOption ("s" ) || cli .hasOption ("no-src" )) {
120
- decoder .setDecodeSources (ApkDecoder .DECODE_SOURCES_NONE );
131
+ config .setDecodeSources (Config .DECODE_SOURCES_NONE );
121
132
}
122
133
if (cli .hasOption ("only-main-classes" )) {
123
- decoder .setDecodeSources (ApkDecoder .DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES );
134
+ config .setDecodeSources (Config .DECODE_SOURCES_SMALI_ONLY_MAIN_CLASSES );
124
135
}
125
136
if (cli .hasOption ("d" ) || cli .hasOption ("debug" )) {
126
137
System .err .println ("SmaliDebugging has been removed in 2.1.0 onward. Please see: https://github.com/iBotPeaches/Apktool/issues/1061" );
127
138
System .exit (1 );
128
139
}
129
140
if (cli .hasOption ("b" ) || cli .hasOption ("no-debug-info" )) {
130
- decoder .setBaksmaliDebugMode (false );
131
- }
132
- if (cli .hasOption ("t" ) || cli .hasOption ("frame-tag" )) {
133
- decoder .setFrameworkTag (cli .getOptionValue ("t" ));
141
+ config .baksmaliDebugMode = false ;
134
142
}
135
143
if (cli .hasOption ("f" ) || cli .hasOption ("force" )) {
136
- decoder . setForceDelete ( true ) ;
144
+ config . forceDelete = true ;
137
145
}
138
146
if (cli .hasOption ("r" ) || cli .hasOption ("no-res" )) {
139
- decoder .setDecodeResources (ApkDecoder .DECODE_RESOURCES_NONE );
147
+ config .setDecodeResources (Config .DECODE_RESOURCES_NONE );
140
148
}
141
149
if (cli .hasOption ("force-manifest" )) {
142
- decoder .setForceDecodeManifest (ApkDecoder .FORCE_DECODE_MANIFEST_FULL );
150
+ config .setForceDecodeManifest (Config .FORCE_DECODE_MANIFEST_FULL );
143
151
}
144
152
if (cli .hasOption ("no-assets" )) {
145
- decoder .setDecodeAssets (ApkDecoder .DECODE_ASSETS_NONE );
153
+ config .setDecodeAssets (Config .DECODE_ASSETS_NONE );
146
154
}
147
155
if (cli .hasOption ("k" ) || cli .hasOption ("keep-broken-res" )) {
148
- decoder .setKeepBrokenResources (true );
149
- }
150
- if (cli .hasOption ("p" ) || cli .hasOption ("frame-path" )) {
151
- decoder .setFrameworkDir (cli .getOptionValue ("p" ));
156
+ config .keepBrokenResources = true ;
152
157
}
153
158
if (cli .hasOption ("m" ) || cli .hasOption ("match-original" )) {
154
- decoder .setAnalysisMode (true );
155
- }
156
- if (cli .hasOption ("api" ) || cli .hasOption ("api-level" )) {
157
- decoder .setApiLevel (Integer .parseInt (cli .getOptionValue ("api" )));
159
+ config .analysisMode = true ;
158
160
}
161
+
162
+ File outDir ;
159
163
if (cli .hasOption ("o" ) || cli .hasOption ("output" )) {
160
164
outDir = new File (cli .getOptionValue ("o" ));
161
165
} else {
@@ -169,8 +173,8 @@ private static void cmdDecode(CommandLine cli) throws AndrolibException {
169
173
outDir = new File (outName );
170
174
}
171
175
176
+ ApkDecoder decoder = new ApkDecoder (config , new ExtFile (apkName ));
172
177
decoder .setOutDir (outDir );
173
- decoder .setApkFile (new File (apkName ));
174
178
175
179
try {
176
180
decoder .decode ();
@@ -204,111 +208,88 @@ private static void cmdDecode(CommandLine cli) throws AndrolibException {
204
208
}
205
209
}
206
210
207
- private static void cmdBuild (CommandLine cli ) {
211
+ private static void cmdBuild (CommandLine cli , Config config ) {
208
212
String [] args = cli .getArgs ();
209
213
String appDirName = args .length < 2 ? "." : args [1 ];
210
- File outFile ;
211
- BuildOptions buildOptions = new BuildOptions ();
212
214
213
215
// check for build options
214
216
if (cli .hasOption ("f" ) || cli .hasOption ("force-all" )) {
215
- buildOptions .forceBuildAll = true ;
217
+ config .forceBuildAll = true ;
216
218
}
217
219
if (cli .hasOption ("d" ) || cli .hasOption ("debug" )) {
218
- buildOptions .debugMode = true ;
220
+ config .debugMode = true ;
219
221
}
220
222
if (cli .hasOption ("n" ) || cli .hasOption ("net-sec-conf" )) {
221
- buildOptions .netSecConf = true ;
223
+ config .netSecConf = true ;
222
224
}
223
225
if (cli .hasOption ("v" ) || cli .hasOption ("verbose" )) {
224
- buildOptions .verbose = true ;
226
+ config .verbose = true ;
225
227
}
226
228
if (cli .hasOption ("a" ) || cli .hasOption ("aapt" )) {
227
- buildOptions .aaptPath = cli .getOptionValue ("a" );
229
+ config .aaptPath = cli .getOptionValue ("a" );
228
230
}
229
231
if (cli .hasOption ("c" ) || cli .hasOption ("copy-original" )) {
230
232
System .err .println ("-c/--copy-original has been deprecated. Removal planned for v3.0.0 (#2129)" );
231
- buildOptions .copyOriginalFiles = true ;
232
- }
233
- if (cli .hasOption ("p" ) || cli .hasOption ("frame-path" )) {
234
- buildOptions .frameworkFolderLocation = cli .getOptionValue ("p" );
233
+ config .copyOriginalFiles = true ;
235
234
}
236
235
if (cli .hasOption ("nc" ) || cli .hasOption ("no-crunch" )) {
237
- buildOptions .noCrunch = true ;
236
+ config .noCrunch = true ;
238
237
}
239
238
240
239
// Temporary flag to enable the use of aapt2. This will transform in time to a use-aapt1 flag, which will be
241
240
// legacy and eventually removed.
242
241
if (cli .hasOption ("use-aapt2" )) {
243
- buildOptions .useAapt2 = true ;
244
- }
245
- if (cli .hasOption ("api" ) || cli .hasOption ("api-level" )) {
246
- buildOptions .forceApi = Integer .parseInt (cli .getOptionValue ("api" ));
242
+ config .useAapt2 = true ;
247
243
}
244
+
245
+ File outFile ;
248
246
if (cli .hasOption ("o" ) || cli .hasOption ("output" )) {
249
247
outFile = new File (cli .getOptionValue ("o" ));
250
248
} else {
251
249
outFile = null ;
252
250
}
253
251
254
- if (buildOptions .netSecConf && !buildOptions .useAapt2 ) {
252
+ if (config .netSecConf && !config .useAapt2 ) {
255
253
System .err .println ("-n / --net-sec-conf is only supported with --use-aapt2." );
256
254
System .exit (1 );
257
255
}
258
256
259
257
// try and build apk
260
258
try {
261
259
if (cli .hasOption ("a" ) || cli .hasOption ("aapt" )) {
262
- buildOptions .aaptVersion = AaptManager .getAaptVersion (cli .getOptionValue ("a" ));
260
+ config .aaptVersion = AaptManager .getAaptVersion (cli .getOptionValue ("a" ));
263
261
}
264
- new Androlib (buildOptions ).build (new File (appDirName ), outFile );
262
+ new Androlib (config ).build (new File (appDirName ), outFile );
265
263
} catch (BrutException ex ) {
266
264
System .err .println (ex .getMessage ());
267
265
System .exit (1 );
268
266
}
269
267
}
270
268
271
- private static void cmdInstallFramework (CommandLine cli ) throws AndrolibException {
272
- int paraCount = cli .getArgList ().size ();
273
- String apkName = cli .getArgList ().get (paraCount - 1 );
274
-
275
- brut .androlib .options .BuildOptions buildOptions = new BuildOptions ();
276
- if (cli .hasOption ("p" ) || cli .hasOption ("frame-path" )) {
277
- buildOptions .frameworkFolderLocation = cli .getOptionValue ("p" );
278
- }
279
- if (cli .hasOption ("t" ) || cli .hasOption ("tag" )) {
280
- buildOptions .frameworkTag = cli .getOptionValue ("t" );
281
- }
282
- new Androlib (buildOptions ).installFramework (new File (apkName ));
269
+ private static void cmdInstallFramework (CommandLine cli , Config config ) throws AndrolibException {
270
+ String apkName = getLastArg (cli );
271
+ new Androlib (config ).installFramework (new File (apkName ));
283
272
}
284
273
285
- private static void cmdListFrameworks (CommandLine cli ) throws AndrolibException {
286
- brut .androlib .options .BuildOptions buildOptions = new BuildOptions ();
287
- if (cli .hasOption ("p" ) || cli .hasOption ("frame-path" )) {
288
- buildOptions .frameworkFolderLocation = cli .getOptionValue ("p" );
289
- }
290
-
291
- new Androlib (buildOptions ).listFrameworks ();
274
+ private static void cmdListFrameworks (CommandLine cli , Config config ) throws AndrolibException {
275
+ new Androlib (config ).listFrameworks ();
292
276
}
293
277
294
- private static void cmdPublicizeResources (CommandLine cli ) throws AndrolibException {
295
- int paraCount = cli .getArgList ().size ();
296
- String apkName = cli .getArgList ().get (paraCount - 1 );
297
-
298
- new Androlib ().publicizeResources (new File (apkName ));
278
+ private static void cmdPublicizeResources (CommandLine cli , Config config ) throws AndrolibException {
279
+ String apkName = getLastArg (cli );
280
+ new Androlib (config ).publicizeResources (new File (apkName ));
299
281
}
300
282
301
- private static void cmdEmptyFrameworkDirectory (CommandLine cli ) throws AndrolibException {
302
- brut .androlib .options .BuildOptions buildOptions = new BuildOptions ();
303
-
283
+ private static void cmdEmptyFrameworkDirectory (CommandLine cli , Config config ) throws AndrolibException {
304
284
if (cli .hasOption ("f" ) || cli .hasOption ("force" )) {
305
- buildOptions .forceDeleteFramework = true ;
306
- }
307
- if (cli .hasOption ("p" ) || cli .hasOption ("frame-path" )) {
308
- buildOptions .frameworkFolderLocation = cli .getOptionValue ("p" );
285
+ config .forceDeleteFramework = true ;
309
286
}
287
+ new Androlib (config ).emptyFrameworkDirectory ();
288
+ }
310
289
311
- new Androlib (buildOptions ).emptyFrameworkDirectory ();
290
+ private static String getLastArg (CommandLine cli ) {
291
+ int paraCount = cli .getArgList ().size ();
292
+ return cli .getArgList ().get (paraCount - 1 );
312
293
}
313
294
314
295
private static void _version () {
0 commit comments