Fixed Smali Assembler
This commit is contained in:
parent
9eff9c331c
commit
ce06cba71f
5 changed files with 64 additions and 45 deletions
|
@ -441,7 +441,7 @@ public class BytecodeViewer
|
|||
BytecodeViewer.viewer.updateBusyStatus(true);
|
||||
boolean noErrors = true;
|
||||
boolean actuallyTried = false;
|
||||
|
||||
|
||||
for (java.awt.Component c : BytecodeViewer.viewer.workPane.getLoadedViewers())
|
||||
{
|
||||
if (c instanceof ClassViewer)
|
||||
|
@ -455,11 +455,11 @@ public class BytecodeViewer
|
|||
if(noErrors && !cv.resourceViewPanel3.compile())
|
||||
noErrors = false;
|
||||
|
||||
if(cv.resourceViewPanel1.textArea.isEditable())
|
||||
if(cv.resourceViewPanel1.textArea != null && cv.resourceViewPanel1.textArea.isEditable())
|
||||
actuallyTried = true;
|
||||
if(cv.resourceViewPanel2.textArea.isEditable())
|
||||
if(cv.resourceViewPanel2.textArea != null && cv.resourceViewPanel2.textArea.isEditable())
|
||||
actuallyTried = true;
|
||||
if(cv.resourceViewPanel3.textArea.isEditable())
|
||||
if(cv.resourceViewPanel3.textArea != null && cv.resourceViewPanel3.textArea.isEditable())
|
||||
actuallyTried = true;
|
||||
}
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ public class BytecodeViewer
|
|||
BytecodeViewer.showMessage("You have no editable panes opened, make one editable and try again.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BytecodeViewer.viewer.updateBusyStatus(false);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
|||
import the.bytecode.club.bytecodeviewer.Configuration;
|
||||
import the.bytecode.club.bytecodeviewer.Constants;
|
||||
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.MiscUtils;
|
||||
|
||||
|
@ -111,7 +112,7 @@ public class KrakatauAssembler extends InternalCompiler
|
|||
log.append(nl).append(nl).append("Exit Value is ").append(exitValue);
|
||||
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();
|
||||
tempJar.delete();
|
||||
return b;
|
||||
|
@ -124,30 +125,4 @@ public class KrakatauAssembler extends InternalCompiler
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,8 +61,10 @@ public class SmaliAssembler extends InternalCompiler
|
|||
}
|
||||
|
||||
try {
|
||||
com.googlecode.d2j.smali.SmaliCmd.main(new String[]{tempSmaliFolder.getAbsolutePath()});//, "-o", tempDex
|
||||
// .getAbsolutePath()});
|
||||
com.googlecode.d2j.smali.SmaliCmd.main(new String[]{
|
||||
tempSmaliFolder.getAbsolutePath(),
|
||||
//"-o", tempDex.getAbsolutePath()
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
|
||||
|
@ -73,7 +75,9 @@ public class SmaliAssembler extends InternalCompiler
|
|||
Dex2Jar.dex2Jar(tempDex, tempJar);
|
||||
else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel()))
|
||||
Enjarify.apk2Jar(tempDex, tempJar);
|
||||
|
||||
|
||||
System.out.println("Temporary dex: " + tempDex.getAbsolutePath());
|
||||
|
||||
try {
|
||||
System.out.println("Unzipping to " + tempJarFolder.getAbsolutePath());
|
||||
ZipUtils.unzipFilesToPath(tempJar.getAbsolutePath(), tempJarFolder.getAbsolutePath());
|
||||
|
@ -93,6 +97,8 @@ public class SmaliAssembler extends InternalCompiler
|
|||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Saved as: " + outputClass.getAbsolutePath());
|
||||
|
||||
return FileUtils.readFileToByteArray(outputClass);
|
||||
} catch (java.lang.NullPointerException ignored) { }
|
||||
|
@ -100,6 +106,10 @@ public class SmaliAssembler extends InternalCompiler
|
|||
e.printStackTrace();
|
||||
//new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
tempDex.delete();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class ResourceViewPanel
|
|||
|
||||
public boolean compile()
|
||||
{
|
||||
if(!textArea.isEditable())
|
||||
if(textArea == null || !textArea.isEditable())
|
||||
return true;
|
||||
|
||||
//WARNING: Any errors thrown will get swallowed by this class
|
||||
|
@ -91,18 +91,16 @@ public class ResourceViewPanel
|
|||
try {
|
||||
ClassNode newNode = JarUtils.getNode(compiledClass);
|
||||
BytecodeViewer.updateNode(viewer.cn, newNode);
|
||||
errConsole.finished();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
errConsole.pretty();
|
||||
errConsole.setVisible(true);
|
||||
errConsole.finished();
|
||||
return false;
|
||||
}
|
||||
|
||||
errConsole.pretty();
|
||||
errConsole.setVisible(true);
|
||||
errConsole.finished();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue