2525import com .reandroid .dex .model .DexDirectory ;
2626import com .reandroid .dex .model .DexFile ;
2727import com .reandroid .dex .sections .SectionType ;
28- import com .reandroid .dex .smali .SmaliWriter ;
2928import com .reandroid .dex .smali .SmaliWriterSetting ;
3029import com .reandroid .dex .smali .formatters .ResourceIdComment ;
3130import org .jf .baksmali .Baksmali ;
@@ -59,7 +58,6 @@ public SmaliDecompiler(TableBlock tableBlock, DecompileOptions decompileOptions)
5958
6059 @ Override
6160 public void decodeDex (DexFileInputSource inputSource , File mainDir ) throws IOException {
62- logMessage ("Baksmali: " + inputSource .getAlias ());
6361 if (DecompileOptions .DEX_LIB_INTERNAL .equals (decompileOptions .dexLib )) {
6462 disassembleWithInternalDexLib (inputSource , mainDir );
6563 } else {
@@ -78,10 +76,14 @@ public void decodeDex(ApkModule apkModule, File mainDirectory) throws IOExceptio
7876 int size = apkModule .listDexFiles ().size ();
7977 logMessage ("Dex files: " + size );
8078 if (size > decompileOptions .loadDex ) {
79+ DexDirectory dexDirectory = null ;
8180 if (size < decompileOptions .loadDex * 5 ) {
82- loadMinimalDexForComment (apkModule );
81+ dexDirectory = loadMinimalDexForComment (apkModule );
8382 }
8483 DexDecoder .super .decodeDex (apkModule , mainDirectory );
84+ if (dexDirectory != null ) {
85+ dexDirectory .close ();
86+ }
8587 return ;
8688 }
8789 logMessage ("Loading full dex files ..." );
@@ -96,10 +98,7 @@ public void decodeDex(ApkModule apkModule, File mainDirectory) throws IOExceptio
9698
9799 File smali = toSmaliRoot (mainDirectory );
98100 SmaliWriterSetting setting = getSmaliWriterSetting (directory );
99- SmaliWriter smaliWriter = new SmaliWriter ();
100- smaliWriter .setWriterSetting (setting );
101- logMessage ("Baksmali ..." );
102- directory .writeSmali (smaliWriter , smali );
101+ directory .writeSmali (setting , smali , this ::logBaksmaliDex );
103102 setting .clearClassComments ();
104103 setting .clearMethodComments ();
105104 directory .close ();
@@ -111,21 +110,27 @@ public void decodeDex(ApkModule apkModule, File mainDirectory) throws IOExceptio
111110 }
112111 }
113112 }
113+ boolean logBaksmaliDex (DexFile dexFile ) {
114+ logMessage ("Baksmali<" + dexFile .getDexClassesCount () + ">: " + dexFile .getSimpleName ());
115+ return true ;
116+ }
114117
115- private void loadMinimalDexForComment (ApkModule apkModule ) throws IOException {
118+ private DexDirectory loadMinimalDexForComment (ApkModule apkModule ) throws IOException {
116119 String commentLevel = decompileOptions .commentLevel ;
117120 if (!DecompileOptions .COMMENT_LEVEL_DETAIL .equals (commentLevel ) &&
118121 !DecompileOptions .COMMENT_LEVEL_FULL .equals (commentLevel )) {
119- return ;
122+ return null ;
120123 }
121124 logMessage ("Loading basic structures of dex ..." );
122125 DexDirectory dexDirectory = DexDirectory .fromZip (
123126 apkModule .getZipEntryMap (), SectionType .minimal ());
124127 mDexForCommentLoaded = false ;
125128 getSmaliWriterSetting (dexDirectory );
126129 mDexForCommentLoaded = true ;
130+ return dexDirectory ;
127131 }
128132 private void disassembleWithJesusFrekeLib (DexFileInputSource inputSource , File mainDir ) throws IOException {
133+ logMessage ("Baksmali: " + inputSource .getAlias ());
129134 File dir = toOutDir (inputSource , mainDir );
130135 BaksmaliOptions options = new BaksmaliOptions ();
131136 options .localsDirective = true ;
@@ -146,14 +151,14 @@ private void disassembleWithInternalDexLib(DexFileInputSource inputSource, File
146151 }
147152 DexFile dexFile = DexFile .read (inputSource .openStream (), filter );
148153 dexFile .setSimpleName (inputSource .getAlias ());
154+ logBaksmaliDex (dexFile );
149155 if (dexFile .isMultiLayout ()) {
150156 logMessage ("Multi layout dex file: " + inputSource .getAlias ()
151157 + "version = " + dexFile .getVersion () + ", layouts = " + dexFile .size ());
152158 }
153159 SmaliWriterSetting setting = getSmaliWriterSetting (dexFile );
154- SmaliWriter smaliWriter = new SmaliWriter ();
155- smaliWriter .setWriterSetting (setting );
156- dexFile .writeSmali (smaliWriter , toSmaliRoot (mainDir ));
160+ File dir = new File (toSmaliRoot (mainDir ), dexFile .buildSmaliDirectoryName ());
161+ dexFile .writeSmali (setting , dir );
157162 if (!mDexForCommentLoaded ) {
158163 setting .clearClassComments ();
159164 setting .clearMethodComments ();
@@ -247,8 +252,7 @@ private void initializeSmaliComment(SmaliWriterSetting setting) {
247252 }
248253 setting .setEnableComments (true );
249254 if (tableBlock != null ) {
250- // TODO fix from ARCLib side
251- setting .setResourceIdComment (ResourceIdComment .of (tableBlock .pickOne (), new Locale (Locale .getDefault ().getLanguage ())));
255+ setting .setResourceIdComment (ResourceIdComment .of (tableBlock .pickOne (), Locale .getDefault ()));
252256 }
253257 if (DecompileOptions .COMMENT_LEVEL_FULL .equals (commentLevel )) {
254258 setting .setMaximumCommentLines (-1 );
0 commit comments