Fixed Smali Assembler
This commit is contained in:
parent
9eff9c331c
commit
ce06cba71f
5 changed files with 64 additions and 45 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -74,6 +76,8 @@ public class SmaliAssembler extends InternalCompiler
|
||||||
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());
|
||||||
|
@ -94,12 +98,18 @@ public class SmaliAssembler extends InternalCompiler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) { }
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
tempDex.delete();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.pretty();
|
||||||
errConsole.setVisible(true);
|
errConsole.setVisible(true);
|
||||||
errConsole.finished();
|
errConsole.finished();
|
||||||
return false;
|
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