Fixed Smali Assembler

This commit is contained in:
Konloch 2021-07-05 17:06:05 -07:00
parent 9eff9c331c
commit ce06cba71f
5 changed files with 64 additions and 45 deletions

View file

@ -441,7 +441,7 @@ public class BytecodeViewer
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
boolean noErrors = true; boolean noErrors = true;
boolean actuallyTried = false; boolean actuallyTried = false;
for (java.awt.Component c : BytecodeViewer.viewer.workPane.getLoadedViewers()) for (java.awt.Component c : BytecodeViewer.viewer.workPane.getLoadedViewers())
{ {
if (c instanceof ClassViewer) if (c instanceof ClassViewer)
@ -455,11 +455,11 @@ public class BytecodeViewer
if(noErrors && !cv.resourceViewPanel3.compile()) if(noErrors && !cv.resourceViewPanel3.compile())
noErrors = false; noErrors = false;
if(cv.resourceViewPanel1.textArea.isEditable()) if(cv.resourceViewPanel1.textArea != null && cv.resourceViewPanel1.textArea.isEditable())
actuallyTried = true; actuallyTried = true;
if(cv.resourceViewPanel2.textArea.isEditable()) if(cv.resourceViewPanel2.textArea != null && cv.resourceViewPanel2.textArea.isEditable())
actuallyTried = true; actuallyTried = true;
if(cv.resourceViewPanel3.textArea.isEditable()) if(cv.resourceViewPanel3.textArea != null && cv.resourceViewPanel3.textArea.isEditable())
actuallyTried = true; actuallyTried = true;
} }
} }
@ -476,7 +476,7 @@ public class BytecodeViewer
BytecodeViewer.showMessage("You have no editable panes opened, make one editable and try again."); BytecodeViewer.showMessage("You have no editable panes opened, make one editable and try again.");
} }
} }
BytecodeViewer.viewer.updateBusyStatus(false); BytecodeViewer.viewer.updateBusyStatus(false);
return true; return true;
} }

View file

@ -12,6 +12,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.compilers.InternalCompiler; import the.bytecode.club.bytecodeviewer.compilers.InternalCompiler;
import the.bytecode.club.bytecodeviewer.util.BCVFileUtils;
import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils;
@ -111,7 +112,7 @@ public class KrakatauAssembler extends InternalCompiler
log.append(nl).append(nl).append("Exit Value is ").append(exitValue); log.append(nl).append(nl).append("Exit Value is ").append(exitValue);
System.err.println(log); System.err.println(log);
byte[] b = FileUtils.readFileToByteArray(Objects.requireNonNull(findFile(tempDirectory, ".class"))); byte[] b = FileUtils.readFileToByteArray(Objects.requireNonNull(BCVFileUtils.findFile(tempDirectory, ".class")));
tempDirectory.delete(); tempDirectory.delete();
tempJar.delete(); tempJar.delete();
return b; return b;
@ -124,30 +125,4 @@ public class KrakatauAssembler extends InternalCompiler
return null; return null;
} }
/**
* Searches a directory until the extension is found
*/
public static File findFile(File basePath, String extension)
{
for(File f : basePath.listFiles())
{
if(f.isDirectory())
{
File child = findFile(f, extension);
if(child != null)
return child;
continue;
}
if(f.getName().endsWith(extension))
{
return f;
}
}
return null;
}
} }

View file

@ -61,8 +61,10 @@ public class SmaliAssembler extends InternalCompiler
} }
try { try {
com.googlecode.d2j.smali.SmaliCmd.main(new String[]{tempSmaliFolder.getAbsolutePath()});//, "-o", tempDex com.googlecode.d2j.smali.SmaliCmd.main(new String[]{
// .getAbsolutePath()}); tempSmaliFolder.getAbsolutePath(),
//"-o", tempDex.getAbsolutePath()
});
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
//new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); //new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
@ -73,7 +75,9 @@ public class SmaliAssembler extends InternalCompiler
Dex2Jar.dex2Jar(tempDex, tempJar); Dex2Jar.dex2Jar(tempDex, tempJar);
else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel())) else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel()))
Enjarify.apk2Jar(tempDex, tempJar); Enjarify.apk2Jar(tempDex, tempJar);
System.out.println("Temporary dex: " + tempDex.getAbsolutePath());
try { try {
System.out.println("Unzipping to " + tempJarFolder.getAbsolutePath()); System.out.println("Unzipping to " + tempJarFolder.getAbsolutePath());
ZipUtils.unzipFilesToPath(tempJar.getAbsolutePath(), tempJarFolder.getAbsolutePath()); ZipUtils.unzipFilesToPath(tempJar.getAbsolutePath(), tempJarFolder.getAbsolutePath());
@ -93,6 +97,8 @@ public class SmaliAssembler extends InternalCompiler
found = true; found = true;
} }
} }
System.out.println("Saved as: " + outputClass.getAbsolutePath());
return FileUtils.readFileToByteArray(outputClass); return FileUtils.readFileToByteArray(outputClass);
} catch (java.lang.NullPointerException ignored) { } } catch (java.lang.NullPointerException ignored) { }
@ -100,6 +106,10 @@ public class SmaliAssembler extends InternalCompiler
e.printStackTrace(); e.printStackTrace();
//new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); //new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
finally
{
tempDex.delete();
}
return null; return null;
} }

View file

@ -71,7 +71,7 @@ public class ResourceViewPanel
public boolean compile() public boolean compile()
{ {
if(!textArea.isEditable()) if(textArea == null || !textArea.isEditable())
return true; return true;
//WARNING: Any errors thrown will get swallowed by this class //WARNING: Any errors thrown will get swallowed by this class
@ -91,18 +91,16 @@ public class ResourceViewPanel
try { try {
ClassNode newNode = JarUtils.getNode(compiledClass); ClassNode newNode = JarUtils.getNode(compiledClass);
BytecodeViewer.updateNode(viewer.cn, newNode); BytecodeViewer.updateNode(viewer.cn, newNode);
errConsole.finished();
return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return true;
}
else
{
errConsole.pretty();
errConsole.setVisible(true);
errConsole.finished();
return false;
} }
errConsole.pretty();
errConsole.setVisible(true);
errConsole.finished();
return false;
} }
} }

View file

@ -0,0 +1,36 @@
package the.bytecode.club.bytecodeviewer.util;
import java.io.File;
/**
* @author Konloch
* @since 7/4/2021
*/
public class BCVFileUtils
{
/**
* Searches a directory until the extension is found
*/
public static File findFile(File basePath, String extension)
{
for(File f : basePath.listFiles())
{
if(f.isDirectory())
{
File child = findFile(f, extension);
if(child != null)
return child;
continue;
}
if(f.getName().endsWith(extension))
{
return f;
}
}
return null;
}
}