Make it so you can have two classes of the same name from different jars open.
This commit is contained in:
parent
75841417c8
commit
b70002e9d5
13 changed files with 87 additions and 63 deletions
|
@ -427,21 +427,22 @@ public class BytecodeViewer {
|
|||
/**
|
||||
* Returns the ClassNode by the specified name
|
||||
*
|
||||
* @param containerName name of the FileContainer that this class is in
|
||||
* @param name the class name
|
||||
* @return the ClassNode instance
|
||||
*/
|
||||
public static ClassNode getClassNode(String name) {
|
||||
public static ClassNode getClassNode(String containerName, String name) {
|
||||
for (FileContainer container : files) {
|
||||
if (container.getData().containsKey(name + ".class")) {
|
||||
if (container.name.equals(containerName) && container.getData().containsKey(name + ".class")) {
|
||||
return container.getClassNode(name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static byte[] getClassBytes(String name) {
|
||||
public static byte[] getClassBytes(String containerName, String name) {
|
||||
for (FileContainer container : files) {
|
||||
if (container.getData().containsKey(name)) {
|
||||
if (container.name.equals(containerName) && container.getData().containsKey(name)) {
|
||||
return container.getData().get(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,13 +160,14 @@ public class CommandLineInput {
|
|||
|
||||
System.out.println("Decompiling " + input.getAbsolutePath() + " with " + use.getName());
|
||||
BytecodeViewer.openFiles(new File[]{input}, false);
|
||||
String containerName = BytecodeViewer.files.get(0).name;
|
||||
Thread.sleep(5 * 1000);
|
||||
if (target.equalsIgnoreCase("all")) {
|
||||
use.decompileToZip(output.getAbsolutePath());
|
||||
} else {
|
||||
try {
|
||||
ClassNode cn = BytecodeViewer.getClassNode(target);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(target);
|
||||
ClassNode cn = BytecodeViewer.getClassNode(containerName, target);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(containerName, target);
|
||||
String contents = use.decompileClassNode(cn, bytes);
|
||||
FileUtils.write(output, contents, "UTF-8", false);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -28,6 +28,6 @@ import org.objectweb.asm.tree.ClassNode;
|
|||
*/
|
||||
|
||||
public interface FileChangeNotifier {
|
||||
void openClassFile(String name, ClassNode cn);
|
||||
void openFile(String name, byte[] contents);
|
||||
void openClassFile(String name, String container, ClassNode cn);
|
||||
void openFile(String name, String container, byte[] contents);
|
||||
}
|
|
@ -154,8 +154,8 @@ public class BytecodeViewer {
|
|||
* the full name of the ClassNode
|
||||
* @return the ClassNode
|
||||
*/
|
||||
public static ClassNode getClassNode(String name) {
|
||||
return the.bytecode.club.bytecodeviewer.BytecodeViewer.getClassNode(name);
|
||||
public static ClassNode getClassNode(String containerName, String name) {
|
||||
return the.bytecode.club.bytecodeviewer.BytecodeViewer.getClassNode(containerName, name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.objectweb.asm.tree.InnerClassNode;
|
|||
import org.objectweb.asm.tree.MethodNode;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.DecompilerSettings;
|
||||
import the.bytecode.club.bytecodeviewer.FileContainer;
|
||||
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -51,10 +52,20 @@ public class ClassNodeDecompiler extends Decompiler {
|
|||
}
|
||||
|
||||
public String decompileClassNode(ClassNode cn, byte[] b) {
|
||||
return decompile(new PrefixedStringBuilder(), new ArrayList<String>(), cn).toString();
|
||||
String containerName = null;
|
||||
for (FileContainer container : BytecodeViewer.files) {
|
||||
String name = cn.name + ".class";
|
||||
if (container.getData().containsKey(name)) {
|
||||
if (container.getClassNode(name) == cn)
|
||||
containerName = container.name;
|
||||
}
|
||||
}
|
||||
System.out.println(containerName);
|
||||
|
||||
return decompile(new PrefixedStringBuilder(), new ArrayList<String>(), containerName, cn).toString();
|
||||
}
|
||||
|
||||
protected static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, ArrayList<String> decompiledClasses, ClassNode cn) {
|
||||
protected static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, ArrayList<String> decompiledClasses, String containerName, ClassNode cn) {
|
||||
ArrayList<String> unableToDecompile = new ArrayList<String>();
|
||||
decompiledClasses.add(cn.name);
|
||||
sb.append(getAccessString(cn.access));
|
||||
|
@ -97,11 +108,11 @@ public class ClassNodeDecompiler extends Decompiler {
|
|||
String innerClassName = innerClassNode.name;
|
||||
if ((innerClassName != null) && !decompiledClasses.contains(innerClassName)) {
|
||||
decompiledClasses.add(innerClassName);
|
||||
ClassNode cn1 = BytecodeViewer.getClassNode(innerClassName);
|
||||
ClassNode cn1 = BytecodeViewer.getClassNode(containerName, innerClassName);
|
||||
if (cn1 != null) {
|
||||
sb.appendPrefix(" ");
|
||||
sb.append(BytecodeViewer.nl + BytecodeViewer.nl);
|
||||
sb = decompile(sb, decompiledClasses, cn1);
|
||||
sb = decompile(sb, decompiledClasses, containerName,cn1);
|
||||
sb.trimPrefix(5);
|
||||
sb.append(BytecodeViewer.nl);
|
||||
} else {
|
||||
|
|
|
@ -120,6 +120,7 @@ public class ClassViewer extends Viewer {
|
|||
}
|
||||
|
||||
String name;
|
||||
String container;
|
||||
JSplitPane sp;
|
||||
JSplitPane sp2;
|
||||
public List<Decompiler> decompilers = Arrays.asList(null, null, null);
|
||||
|
@ -273,7 +274,7 @@ public class ClassViewer extends Viewer {
|
|||
}
|
||||
}
|
||||
|
||||
public ClassViewer(final String name, final ClassNode cn) {
|
||||
public ClassViewer(final String name, final String container, final ClassNode cn) {
|
||||
for (int i = 0; i < panels.size(); i++) {
|
||||
final JTextField textField = fields.get(i);
|
||||
JPanel searchPanel = searches.get(i);
|
||||
|
@ -318,12 +319,13 @@ public class ClassViewer extends Viewer {
|
|||
}
|
||||
|
||||
this.name = name;
|
||||
this.container = container;
|
||||
this.cn = cn;
|
||||
this.setName(name);
|
||||
this.setName(name + "(" + container + ")");
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panels.get(0), panels.get(1));
|
||||
JHexEditor hex = new JHexEditor(BytecodeViewer.getClassBytes(cn.name + ".class"));
|
||||
JHexEditor hex = new JHexEditor(BytecodeViewer.getClassBytes(container, cn.name + ".class"));
|
||||
this.sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, panels.get(2));
|
||||
this.add(sp2, BorderLayout.CENTER);
|
||||
|
||||
|
@ -365,7 +367,7 @@ public class ClassViewer extends Viewer {
|
|||
}
|
||||
|
||||
public void startPaneUpdater(final JButton button) {
|
||||
this.cn = BytecodeViewer.getClassNode(cn.name); //update the classnode
|
||||
this.cn = BytecodeViewer.getClassNode(container, cn.name); //update the classnode
|
||||
setPanes();
|
||||
|
||||
for (JPanel jpanel : panels) {
|
||||
|
|
|
@ -234,12 +234,12 @@ public class FileNavigationPane extends VisibleComponent implements FileDrop.Lis
|
|||
new FileDrop(this, this);
|
||||
}
|
||||
|
||||
public void openClassFileToWorkSpace(final String name, final ClassNode node) {
|
||||
fcn.openClassFile(name, node);
|
||||
public void openClassFileToWorkSpace(final String name, final String container, final ClassNode node) {
|
||||
fcn.openClassFile(name, container, node);
|
||||
}
|
||||
|
||||
public void openFileToWorkSpace(String name, byte[] contents) {
|
||||
fcn.openFile(name, contents);
|
||||
public void openFileToWorkSpace(String name, final String container, byte[] contents) {
|
||||
fcn.openFile(name, container, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -454,13 +454,14 @@ public class FileNavigationPane extends VisibleComponent implements FileDrop.Lis
|
|||
}
|
||||
|
||||
String name = nameBuffer.toString();
|
||||
String containerName = path.getPathComponent(1).toString();
|
||||
if (name.endsWith(".class")) {
|
||||
final ClassNode cn = BytecodeViewer.getClassNode(name.substring(0, name.length() - ".class".length()));
|
||||
final ClassNode cn = BytecodeViewer.getClassNode(containerName, name.substring(0, name.length() - ".class".length()));
|
||||
if (cn != null) {
|
||||
openClassFileToWorkSpace(nameBuffer.toString(), cn);
|
||||
openClassFileToWorkSpace(nameBuffer.toString(), containerName, cn);
|
||||
}
|
||||
} else {
|
||||
openFileToWorkSpace(nameBuffer.toString(), BytecodeViewer.getFileContents(nameBuffer.toString()));
|
||||
openFileToWorkSpace(nameBuffer.toString(), containerName, BytecodeViewer.getFileContents(nameBuffer.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ public class FileViewer extends Viewer {
|
|||
private static final long serialVersionUID = 6103372882168257164L;
|
||||
|
||||
String name;
|
||||
String container;
|
||||
private byte[] contents;
|
||||
RSyntaxTextArea panelArea = new RSyntaxTextArea();
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
|
@ -189,8 +190,9 @@ public class FileViewer extends Viewer {
|
|||
return asciiEncoder.canEncode(v);
|
||||
}
|
||||
|
||||
public FileViewer(final String name, final byte[] contents) {
|
||||
public FileViewer(final String name, final String container, final byte[] contents) {
|
||||
this.name = name;
|
||||
this.container = container;
|
||||
this.contents = contents;
|
||||
this.setName(name);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
|
|
@ -791,14 +791,15 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
|||
int result = -1;
|
||||
for (int k = 0; k < options.length; k++)
|
||||
if (options[k].equals(obj)) result = k;
|
||||
String containerName = BytecodeViewer.files.get(0).name;
|
||||
|
||||
if (result == 0) {
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ClassNode cn = BytecodeViewer.getClassNode(s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(s);
|
||||
ClassNode cn = BytecodeViewer.getClassNode(containerName, s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(containerName, s);
|
||||
String contents = Decompiler.PROCYON.decompileClassNode(cn, bytes);
|
||||
FileUtils.write(new File(path), contents, "UTF-8", false);
|
||||
BytecodeViewer.viewer.setIcon(false);
|
||||
|
@ -814,8 +815,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ClassNode cn = BytecodeViewer.getClassNode(s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(s);
|
||||
ClassNode cn = BytecodeViewer.getClassNode(containerName, s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(containerName, s);
|
||||
String contents = Decompiler.CFR.decompileClassNode(cn, bytes);
|
||||
FileUtils.write(new File(path), contents, "UTF-8", false);
|
||||
BytecodeViewer.viewer.setIcon(false);
|
||||
|
@ -831,8 +832,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ClassNode cn = BytecodeViewer.getClassNode(s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(s);
|
||||
ClassNode cn = BytecodeViewer.getClassNode(containerName, s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(containerName, s);
|
||||
String contents = Decompiler.FERNFLOWER.decompileClassNode(cn, bytes);
|
||||
FileUtils.write(new File(path), contents, "UTF-8", false);
|
||||
BytecodeViewer.viewer.setIcon(false);
|
||||
|
@ -848,8 +849,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ClassNode cn = BytecodeViewer.getClassNode(s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(s);
|
||||
ClassNode cn = BytecodeViewer.getClassNode(containerName, s);
|
||||
byte[] bytes = BytecodeViewer.getClassBytes(containerName, s);
|
||||
String contents = Decompiler.KRAKATAU.decompileClassNode(cn, bytes);
|
||||
FileUtils.write(new File(path), contents, "UTF-8", false);
|
||||
BytecodeViewer.viewer.setIcon(false);
|
||||
|
@ -1258,16 +1259,16 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void openClassFile(final String name, final ClassNode cn) {
|
||||
public void openClassFile(final String name, String container, final ClassNode cn) {
|
||||
for (final VisibleComponent vc : rfComps) {
|
||||
vc.openClassFile(name, cn);
|
||||
vc.openClassFile(name, container, cn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFile(final String name, byte[] content) {
|
||||
public void openFile(final String name, String container, byte[] content) {
|
||||
for (final VisibleComponent vc : rfComps) {
|
||||
vc.openFile(name, content);
|
||||
vc.openFile(name, container, content);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class PaneUpdaterThread extends Thread {
|
|||
|
||||
public void run() {
|
||||
try {
|
||||
final byte[] b = BytecodeViewer.getClassBytes(viewer.cn.name + ".class");
|
||||
final byte[] b = BytecodeViewer.getClassBytes(viewer.container, viewer.cn.name + ".class");
|
||||
if (decompiler != Decompiler.HEXCODE) {
|
||||
RSyntaxTextArea panelArea = new RSyntaxTextArea();
|
||||
panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
|
||||
|
|
|
@ -195,12 +195,13 @@ public class SearchingPane extends VisibleComponent {
|
|||
@Override
|
||||
public void valueChanged(final TreeSelectionEvent arg0) {
|
||||
String path = arg0.getPath().toString();
|
||||
String containerName = arg0.getPath().getPathComponent(1).toString();
|
||||
|
||||
String className = path.split(", ")[1].split("\\.")[0];
|
||||
final ClassNode fN = BytecodeViewer.getClassNode(className);
|
||||
final ClassNode fN = BytecodeViewer.getClassNode(containerName, className);
|
||||
if (fN != null) {
|
||||
MainViewerGUI.getComponent(FileNavigationPane.class)
|
||||
.openClassFileToWorkSpace(className + ".class", fN);
|
||||
.openClassFileToWorkSpace(className + ".class", containerName, fN);
|
||||
}
|
||||
|
||||
System.out.println(className);
|
||||
|
@ -232,7 +233,7 @@ public class SearchingPane extends VisibleComponent {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void openFile(String name, byte[] contents) {
|
||||
public void openFile(String name, String container, byte[] contents) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -49,10 +49,10 @@ public abstract class VisibleComponent extends JInternalFrame implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void openClassFile(final String name, final ClassNode cn) {
|
||||
public void openClassFile(final String name, String container, final ClassNode cn) {
|
||||
}
|
||||
@Override
|
||||
public void openFile(final String name, byte[] contents) {
|
||||
public void openFile(final String name, String container, byte[] contents) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,10 +85,12 @@ public class WorkPane extends VisibleComponent implements ActionListener {
|
|||
public void componentRemoved(final ContainerEvent e) {
|
||||
final Component c = e.getChild();
|
||||
if (c instanceof ClassViewer) {
|
||||
workingOn.remove(((ClassViewer) c).name);
|
||||
ClassViewer cv = (ClassViewer) c;
|
||||
workingOn.remove(cv.name + "$" + cv.name);
|
||||
}
|
||||
if (c instanceof FileViewer) {
|
||||
workingOn.remove(((FileViewer) c).name);
|
||||
FileViewer fv = (FileViewer) c;
|
||||
workingOn.remove(fv.name + "$" + fv.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,43 +108,45 @@ public class WorkPane extends VisibleComponent implements ActionListener {
|
|||
|
||||
int tabCount = 0;
|
||||
|
||||
public void addWorkingFile(final String name, final ClassNode cn) {
|
||||
if (!workingOn.containsKey(name)) {
|
||||
final JPanel tabComp = new ClassViewer(name, cn);
|
||||
public void addWorkingFile(final String name, String container, final ClassNode cn) {
|
||||
String key = container + "$" + name;
|
||||
if (!workingOn.containsKey(key)) {
|
||||
final JPanel tabComp = new ClassViewer(name, container, cn);
|
||||
tabs.add(tabComp);
|
||||
final int tabCount = tabs.indexOfComponent(tabComp);
|
||||
workingOn.put(name, tabCount);
|
||||
tabs.setTabComponentAt(tabCount, new TabbedPane(name,tabs));
|
||||
workingOn.put(key, tabCount);
|
||||
tabs.setTabComponentAt(tabCount, new TabbedPane(name, tabs));
|
||||
tabs.setSelectedIndex(tabCount);
|
||||
} else {
|
||||
tabs.setSelectedIndex(workingOn.get(name));
|
||||
tabs.setSelectedIndex(workingOn.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
public void addFile(final String name, byte[] contents) {
|
||||
public void addFile(final String name, String container, byte[] contents) {
|
||||
if(contents == null) //a directory
|
||||
return;
|
||||
|
||||
if (!workingOn.containsKey(name)) {
|
||||
final Component tabComp = new FileViewer(name, contents);
|
||||
|
||||
String key = container + "$" + name;
|
||||
if (!workingOn.containsKey(key)) {
|
||||
final Component tabComp = new FileViewer(name, container, contents);
|
||||
tabs.add(tabComp);
|
||||
final int tabCount = tabs.indexOfComponent(tabComp);
|
||||
workingOn.put(name, tabCount);
|
||||
tabs.setTabComponentAt(tabCount, new TabbedPane(name,tabs));
|
||||
workingOn.put(key, tabCount);
|
||||
tabs.setTabComponentAt(tabCount, new TabbedPane(name, tabs));
|
||||
tabs.setSelectedIndex(tabCount);
|
||||
} else {
|
||||
tabs.setSelectedIndex(workingOn.get(name));
|
||||
tabs.setSelectedIndex(workingOn.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openClassFile(final String name, final ClassNode cn) {
|
||||
addWorkingFile(name, cn);
|
||||
public void openClassFile(final String name, String container, final ClassNode cn) {
|
||||
addWorkingFile(name, container, cn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFile(final String name, byte[] content) {
|
||||
addFile(name, content);
|
||||
public void openFile(final String name, String container, byte[] content) {
|
||||
addFile(name, container, content);
|
||||
}
|
||||
|
||||
public Viewer getCurrentViewer() {
|
||||
|
|
Loading…
Reference in a new issue