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

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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);
@ -74,6 +76,8 @@ public class SmaliAssembler extends InternalCompiler
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());
@ -94,12 +98,18 @@ public class SmaliAssembler extends InternalCompiler
}
}
System.out.println("Saved as: " + outputClass.getAbsolutePath());
return FileUtils.readFileToByteArray(outputClass);
} catch (java.lang.NullPointerException ignored) { }
} catch (Exception e) {
e.printStackTrace();
//new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
finally
{
tempDex.delete();
}
return null;
}

View file

@ -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;
}
}
}

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;
}
}