Moved CodeSequenceDiagram. -Bibl

This commit is contained in:
TheBiblMan 2015-06-01 15:07:05 +01:00
parent c888f42404
commit 6cf63674ad
3 changed files with 102 additions and 195 deletions

View file

@ -43,8 +43,8 @@ import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameClasses;
import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameFields; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameFields;
import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameMethods; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameMethods;
import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.plugin.PluginManager;
import the.bytecode.club.bytecodeviewer.plugin.preinstalled.CodeSequenceDiagram;
import the.bytecode.club.bytecodeviewer.plugins.AllatoriStringDecrypter; import the.bytecode.club.bytecodeviewer.plugins.AllatoriStringDecrypter;
import the.bytecode.club.bytecodeviewer.plugins.CodeSequenceDiagram;
import the.bytecode.club.bytecodeviewer.plugins.ShowAllStrings; import the.bytecode.club.bytecodeviewer.plugins.ShowAllStrings;
import the.bytecode.club.bytecodeviewer.plugins.ShowMainMethods; import the.bytecode.club.bytecodeviewer.plugins.ShowMainMethods;
import the.bytecode.club.bytecodeviewer.plugins.ZKMStringDecrypter; import the.bytecode.club.bytecodeviewer.plugins.ZKMStringDecrypter;

View file

@ -1,93 +1,102 @@
package the.bytecode.club.bytecodeviewer.plugin.preinstalled; package the.bytecode.club.bytecodeviewer.plugin.preinstalled;
import java.awt.Font; import java.awt.Font;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.UIManager; import javax.swing.UIManager;
import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.MethodNode;
import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph; import com.mxgraph.view.mxGraph;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Resources; import the.bytecode.club.bytecodeviewer.Resources;
import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.gui.ClassViewer; import the.bytecode.club.bytecodeviewer.gui.ClassViewer;
/** /**
* A simple code sequence diagram. * A simple code sequence diagram.
* *
* @author Konloch * @author Konloch
* *
*/ */
public class CodeSequenceDiagram extends Plugin { public class CodeSequenceDiagram extends Plugin {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList) {
if(BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) { if(BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) {
BytecodeViewer.showMessage("First open a class file."); BytecodeViewer.showMessage("First open a class file.");
return; return;
} }
ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn; ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn;
JFrame frame = new JFrame("Code Sequence Diagram - " +c.name); if(c == null) {
frame.setIconImages(Resources.iconList); BytecodeViewer.showMessage("ClassNode is null for CodeSequenceDiagram. Please report to @Konloch");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); return;
frame.setSize(400, 320); }
mxGraph graph = new mxGraph(); JFrame frame = null;
graph.setVertexLabelsMovable(false); if(c.name != null)
graph.setGridEnabled(true); frame = new JFrame("Code Sequence Diagram - "+c.name);
graph.setEnabled(false); else
graph.setCellsEditable(false); frame = new JFrame("Code Sequence Diagram - Unknown Name");
graph.setCellsSelectable(false);
graph.setCellsMovable(false); frame.setIconImages(Resources.iconList);
graph.setCellsLocked(true); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Object parent = graph.getDefaultParent(); frame.setSize(400, 320);
Font font = UIManager.getDefaults().getFont("TabbedPane.font"); mxGraph graph = new mxGraph();
AffineTransform affinetransform = new AffineTransform(); graph.setVertexLabelsMovable(false);
FontRenderContext frc = new FontRenderContext(affinetransform,true,true); graph.setGridEnabled(true);
graph.setEnabled(false);
graph.getModel().beginUpdate(); graph.setCellsEditable(false);
try graph.setCellsSelectable(false);
{ graph.setCellsMovable(false);
graph.setCellsLocked(true);
int testX = 10; Object parent = graph.getDefaultParent();
int testY = 0; Font font = UIManager.getDefaults().getFont("TabbedPane.font");
double magicNumber = 5.8; AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
for(MethodNode m : (ArrayList<MethodNode>)c.methods) {
String mIdentifier = c.name+"."+m.name+m.desc; graph.getModel().beginUpdate();
Object node = graph.insertVertex(parent, null, mIdentifier, testX, testY, mIdentifier.length() * magicNumber, 30); try
Object attach = node; {
testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
for (AbstractInsnNode i : m.instructions.toArray()) { int testX = 10;
if (i instanceof MethodInsnNode) { int testY = 0;
MethodInsnNode mi = (MethodInsnNode) i; double magicNumber = 5.8;
String identifier = mi.owner+"."+mi.name+mi.desc;
Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, identifier.length() * 5, 30); for(MethodNode m : (ArrayList<MethodNode>)c.methods) {
testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60; String mIdentifier = c.name+"."+m.name+m.desc;
graph.insertEdge(parent, null, null, attach, node2); Object node = graph.insertVertex(parent, null, mIdentifier, testX, testY, mIdentifier.length() * magicNumber, 30);
attach = node2; Object attach = node;
} testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
} for (AbstractInsnNode i : m.instructions.toArray()) {
testY += 60; if (i instanceof MethodInsnNode) {
testX = 10; MethodInsnNode mi = (MethodInsnNode) i;
} String identifier = mi.owner+"."+mi.name+mi.desc;
} finally { Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, identifier.length() * 5, 30);
graph.getModel().endUpdate(); testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60;
} graph.insertEdge(parent, null, null, attach, node2);
attach = node2;
mxGraphComponent graphComponent = new mxGraphComponent(graph); }
frame.getContentPane().add(graphComponent); }
frame.setVisible(true); testY += 60;
} testX = 10;
}
} finally {
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
frame.getContentPane().add(graphComponent);
frame.setVisible(true);
}
} }

View file

@ -1,102 +0,0 @@
package the.bytecode.club.bytecodeviewer.plugins;
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.UIManager;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Resources;
import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.gui.ClassViewer;
/**
* A simple code sequence diagram.
*
* @author Konloch
*
*/
public class CodeSequenceDiagram extends Plugin {
@SuppressWarnings("unchecked")
@Override
public void execute(ArrayList<ClassNode> classNodeList) {
if(BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) {
BytecodeViewer.showMessage("First open a class file.");
return;
}
ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn;
if(c == null) {
BytecodeViewer.showMessage("ClassNode is null for CodeSequenceDiagram. Please report to @Konloch");
return;
}
JFrame frame = null;
if(c.name != null)
frame = new JFrame("Code Sequence Diagram - "+c.name);
else
frame = new JFrame("Code Sequence Diagram - Unknown Name");
frame.setIconImages(Resources.iconList);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(400, 320);
mxGraph graph = new mxGraph();
graph.setVertexLabelsMovable(false);
graph.setGridEnabled(true);
graph.setEnabled(false);
graph.setCellsEditable(false);
graph.setCellsSelectable(false);
graph.setCellsMovable(false);
graph.setCellsLocked(true);
Object parent = graph.getDefaultParent();
Font font = UIManager.getDefaults().getFont("TabbedPane.font");
AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
graph.getModel().beginUpdate();
try
{
int testX = 10;
int testY = 0;
double magicNumber = 5.8;
for(MethodNode m : (ArrayList<MethodNode>)c.methods) {
String mIdentifier = c.name+"."+m.name+m.desc;
Object node = graph.insertVertex(parent, null, mIdentifier, testX, testY, mIdentifier.length() * magicNumber, 30);
Object attach = node;
testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
for (AbstractInsnNode i : m.instructions.toArray()) {
if (i instanceof MethodInsnNode) {
MethodInsnNode mi = (MethodInsnNode) i;
String identifier = mi.owner+"."+mi.name+mi.desc;
Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, identifier.length() * 5, 30);
testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60;
graph.insertEdge(parent, null, null, attach, node2);
attach = node2;
}
}
testY += 60;
testX = 10;
}
} finally {
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
frame.getContentPane().add(graphComponent);
frame.setVisible(true);
}
}