├── .gitignore
├── README.md
├── demo.gif
├── jbeditor.iml
├── pom.xml
└── src
└── main
├── java
├── com
│ └── sun
│ │ └── xml
│ │ └── internal
│ │ └── messaging
│ │ └── saaj
│ │ └── util
│ │ └── ByteInputStream.java
└── net
│ └── ptnkjke
│ └── jbeditor
│ ├── Configutation.java
│ ├── Main.java
│ ├── MissingInstruction.java
│ ├── gui
│ ├── about
│ │ ├── Controller.java
│ │ └── View.fxml
│ ├── error
│ │ ├── Controller.java
│ │ └── View.fxml
│ ├── main
│ │ ├── Controller.java
│ │ ├── FlowListCell.java
│ │ ├── Static.java
│ │ ├── View.fxml
│ │ ├── constantpanes
│ │ │ ├── constantpane_class
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_double
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_fieldref
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_float
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_integer
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_interfacemethodref
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_long
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_methodhandle
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_methodref
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_methodtype
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_nameandtype
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_string
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ ├── constantpane_utf8
│ │ │ │ ├── Controller.java
│ │ │ │ └── View.fxml
│ │ │ └── table
│ │ │ │ ├── ConstantTableCell.java
│ │ │ │ ├── Controller.java
│ │ │ │ ├── Static.java
│ │ │ │ └── View.fxml
│ │ ├── model
│ │ │ ├── ConsoleMessage.java
│ │ │ ├── MessageType.java
│ │ │ └── classtree
│ │ │ │ ├── Attribute.java
│ │ │ │ ├── Attributes.java
│ │ │ │ ├── Constant.java
│ │ │ │ ├── ConstantPool.java
│ │ │ │ ├── Field.java
│ │ │ │ ├── Fields.java
│ │ │ │ ├── GeneralInformation.java
│ │ │ │ ├── Info.java
│ │ │ │ ├── Interface.java
│ │ │ │ ├── Interfaces.java
│ │ │ │ ├── Method.java
│ │ │ │ ├── Methods.java
│ │ │ │ └── Root.java
│ │ └── panes
│ │ │ ├── defaultpane
│ │ │ ├── Controller.java
│ │ │ └── View.fxml
│ │ │ ├── descriptionerror
│ │ │ ├── Controller.java
│ │ │ ├── Static.java
│ │ │ └── View.fxml
│ │ │ ├── generalinfopane
│ │ │ ├── Controller.java
│ │ │ ├── Utils.java
│ │ │ └── View.fxml
│ │ │ └── methodpane
│ │ │ ├── Controller.java
│ │ │ ├── MethodController.java
│ │ │ ├── MethodModel.java
│ │ │ ├── MethodUtils.java
│ │ │ ├── Utils.java
│ │ │ └── View.fxml
│ └── preferences
│ │ ├── Controller.java
│ │ └── View.fxml
│ ├── logic
│ ├── Core.java
│ ├── asm
│ │ ├── ASMCore.java
│ │ ├── JAsmByteParser.java
│ │ └── bytecode
│ │ │ ├── BCClassVisitor.java
│ │ │ └── BCMethodVisitor.java
│ ├── bcel
│ │ ├── BCELCore.java
│ │ ├── GraphVizCreator.java
│ │ ├── JBcelByteParser.java
│ │ └── bytecode
│ │ │ ├── CellConstantWorker.java
│ │ │ ├── ConstanstWorker.java
│ │ │ ├── Editor.java
│ │ │ ├── InstructionHandleWorker.java
│ │ │ └── TextConstantWorker.java
│ └── own
│ │ └── bytecode
│ │ ├── AbstractConstant.java
│ │ ├── ConstantClass.java
│ │ ├── ConstantDouble.java
│ │ ├── ConstantFieldref.java
│ │ ├── ConstantFloat.java
│ │ ├── ConstantInteger.java
│ │ ├── ConstantInterfaceMethodref.java
│ │ ├── ConstantInvokeDynamic.java
│ │ ├── ConstantLong.java
│ │ ├── ConstantMethodHandle.java
│ │ ├── ConstantMethodType.java
│ │ ├── ConstantMethodref.java
│ │ ├── ConstantNameAndType.java
│ │ ├── ConstantPool.java
│ │ ├── ConstantString.java
│ │ ├── ConstantUtf8.java
│ │ ├── Constants.java
│ │ └── OClass.java
│ └── utils
│ ├── CellConstantWorker.java
│ ├── ConstanstWorker.java
│ ├── Editor.java
│ ├── GraphVizCreator.java
│ ├── InstructionHandleWorker.java
│ ├── JByteParser.java
│ ├── JarClassLoader.java
│ ├── TextConstantWorker.java
│ └── Utils.java
└── resources
├── messages_en.properties
└── messages_ru.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | jbedit
2 | ======
3 |
4 | jbedit is a tool that visualizes information about Java class file.
5 | With this tool you can modify bytecode and cosntruct a graph of bytecode instructions.
6 |
7 |
8 |
9 | This requires java8.
10 |
11 | mini demonstration:
12 | 
13 |
14 |
15 |
16 | Step for using:
17 |
18 | 1) Install maven
19 | 2) to do mvn clean install
20 | 3) mvn package and run
21 |
22 |
23 | I recommend to run this project in ide, because its not finished.
24 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ptnkjke/Java-Bytecode-Editor/0564b99dcfc8ef461eac23a506a19890b6b8ea26/demo.gif
--------------------------------------------------------------------------------
/jbeditor.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | jbeditor
8 | jbeditor
9 | 1.0
10 | jar
11 |
12 |
13 | 1.8
14 | 1.8
15 |
16 |
17 |
18 |
19 |
20 | org.apache.bcel
21 | bcel
22 | 6.0
23 |
24 |
25 |
26 | net.lingala.zip4j
27 | zip4j
28 | 1.3.2
29 |
30 |
31 |
32 | org.ow2.asm
33 | asm-debug-all
34 | 5.0.3
35 |
36 |
37 |
38 | org.codehaus.groovy
39 | groovy-all
40 | 2.4.0-beta-4
41 |
42 |
43 |
44 |
45 |
46 |
47 | src/main/resources
48 |
49 |
50 | src/main/java
51 |
52 | **/*.java
53 |
54 |
55 |
56 |
57 |
58 | org.apache.maven.plugins
59 | maven-jar-plugin
60 | 2.4
61 |
62 |
63 |
64 | net.ptnkjke.jbeditor.Main
65 | lib/
66 | true
67 |
68 |
69 |
70 |
71 |
72 |
73 | maven-dependency-plugin
74 |
75 |
76 | package
77 |
78 | copy-dependencies
79 |
80 |
81 | ${project.build.directory}/lib
82 |
83 |
84 |
85 |
86 |
87 |
88 | org.codehaus.gmaven
89 | gmaven-plugin
90 |
91 |
92 |
93 | compile
94 |
95 |
96 |
97 |
98 | ${pom.basedir}/src/main/script
99 |
100 | **/*.groovy
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/src/main/java/com/sun/xml/internal/messaging/saaj/util/ByteInputStream.java:
--------------------------------------------------------------------------------
1 | //
2 | // Source code recreated from a .class file by IntelliJ IDEA
3 | // (powered by Fernflower decompiler)
4 | //
5 |
6 | package com.sun.xml.internal.messaging.saaj.util;
7 |
8 | import java.io.ByteArrayInputStream;
9 | import java.io.IOException;
10 |
11 | public class ByteInputStream extends ByteArrayInputStream {
12 | private static final byte[] EMPTY_ARRAY = new byte[0];
13 |
14 | public ByteInputStream() {
15 | this(EMPTY_ARRAY, 0);
16 | }
17 |
18 | public ByteInputStream(byte[] buf, int length) {
19 | super(buf, 0, length);
20 | }
21 |
22 | public ByteInputStream(byte[] buf, int offset, int length) {
23 | super(buf, offset, length);
24 | }
25 |
26 | public byte[] getBytes() {
27 | return this.buf;
28 | }
29 |
30 | public int getCount() {
31 | return this.count;
32 | }
33 |
34 | public void close() throws IOException {
35 | this.reset();
36 | }
37 |
38 | public void setBuf(byte[] buf) {
39 | this.buf = buf;
40 | this.pos = 0;
41 | this.count = buf.length;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/Configutation.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.util.Properties;
8 |
9 | public class Configutation {
10 | public static String graphVizPath = "C:\\soft\\graphviz\\bin\\dot.exe";
11 | public static String workDir = "C:\\temp";
12 |
13 | private static final String config = "config.ini";
14 |
15 | public static void save() {
16 | File f = new File(config);
17 | Properties properties = new Properties();
18 |
19 | properties.setProperty("graphVizPath", graphVizPath);
20 | properties.setProperty("workDir", workDir);
21 | try {
22 | properties.store(new FileOutputStream(f), "jbedit file options");
23 | } catch (IOException e) {
24 | e.printStackTrace();
25 | }
26 | }
27 |
28 | public static void read() {
29 | File con = new File(config);
30 | if (!con.exists()) {
31 | save();
32 | }
33 |
34 | Properties properties = new Properties();
35 |
36 | try {
37 | properties.load(new FileInputStream(con));
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | }
41 |
42 | graphVizPath = properties.getProperty("graphVizPath");
43 | workDir = properties.getProperty("workDir");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/Main.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.fxml.JavaFXBuilderFactory;
6 | import javafx.scene.Parent;
7 | import javafx.scene.Scene;
8 | import javafx.scene.input.Dragboard;
9 | import javafx.scene.input.TransferMode;
10 | import javafx.stage.Stage;
11 | import net.ptnkjke.jbeditor.gui.main.Controller;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 | import java.util.List;
16 |
17 | public class Main extends Application {
18 |
19 | @Override
20 | public void start(Stage primaryStage) throws Exception {
21 |
22 | // Считываем параметры по умолчанию
23 | Configutation.read();
24 |
25 | //
26 | Parent root = null;
27 | FXMLLoader fxmlLoader = null;
28 | fxmlLoader = new FXMLLoader();
29 | fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
30 |
31 | Controller controller = null;
32 |
33 | try {
34 | root = fxmlLoader.load(getClass().getResource("gui/main/View.fxml").openStream());
35 | controller = fxmlLoader.getController();
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | }
39 |
40 | primaryStage.setTitle("Java Byte Editor rc1");
41 |
42 |
43 | // Вешаем dragAndDrop
44 | final Controller finalController = controller;
45 |
46 | root.setOnDragOver(event -> {
47 | event.consume();
48 | event.acceptTransferModes(TransferMode.ANY);
49 | });
50 |
51 | root.setOnDragDropped(event -> {
52 | Dragboard db = event.getDragboard();
53 |
54 | if (db.hasFiles()) {
55 | List files = db.getFiles();
56 | File file = files.get(0);
57 |
58 | if (!file.isFile()) {
59 | return;
60 | }
61 |
62 | finalController.openFile(file);
63 |
64 | event.consume();
65 | }
66 | });
67 | primaryStage.setScene(new Scene(root, 300, 275));
68 |
69 | primaryStage.show();
70 |
71 | }
72 |
73 |
74 | public static void main(String[] args) {
75 | try {
76 | launch(args);
77 | } catch (Throwable t) {
78 | t.printStackTrace();
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/MissingInstruction.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor;
2 |
3 |
4 | public class MissingInstruction extends Exception {
5 | public MissingInstruction(String msg) {
6 | super(msg);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/about/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.about;
2 |
3 | /**
4 | * Created by Lopatin on 25.06.2014.
5 | */
6 | public class Controller {
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/about/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/error/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.error;
2 |
3 | /**
4 | * Created by Lopatin on 09.07.2014.
5 | */
6 | public class Controller {
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/error/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main;
2 |
3 | import javafx.collections.FXCollections;
4 | import javafx.event.EventHandler;
5 | import javafx.fxml.FXML;
6 | import javafx.fxml.FXMLLoader;
7 | import javafx.fxml.JavaFXBuilderFactory;
8 | import javafx.scene.Parent;
9 | import javafx.scene.Scene;
10 | import javafx.scene.control.ListView;
11 | import javafx.scene.control.TabPane;
12 | import javafx.scene.control.TreeItem;
13 | import javafx.scene.control.TreeView;
14 | import javafx.scene.layout.GridPane;
15 | import javafx.scene.layout.VBox;
16 | import javafx.stage.*;
17 | import net.ptnkjke.jbeditor.Configutation;
18 | import net.ptnkjke.jbeditor.gui.main.model.ConsoleMessage;
19 | import net.ptnkjke.jbeditor.gui.main.model.MessageType;
20 | import net.ptnkjke.jbeditor.gui.main.model.classtree.*;
21 | import net.ptnkjke.jbeditor.gui.main.model.classtree.ConstantPool;
22 | import net.ptnkjke.jbeditor.gui.main.panes.methodpane.MethodModel;
23 | import net.ptnkjke.jbeditor.gui.main.panes.methodpane.MethodUtils;
24 | import net.ptnkjke.jbeditor.gui.main.panes.generalinfopane.Utils;
25 | import net.ptnkjke.jbeditor.logic.Core;
26 | import org.apache.bcel.Const;
27 | import org.apache.bcel.classfile.*;
28 | import org.apache.bcel.generic.ClassGen;
29 |
30 | import java.io.File;
31 | import java.io.FileInputStream;
32 | import java.io.IOException;
33 | import java.util.jar.JarInputStream;
34 | import java.util.zip.ZipEntry;
35 |
36 | /**
37 | * Created by Lopatin on 25.06.2014.
38 | */
39 | public class Controller {
40 |
41 | @FXML
42 | private VBox root;
43 | @FXML
44 | private GridPane firstPane;
45 | @FXML
46 | private GridPane secondPane;
47 | @FXML
48 | private TreeView mainTree;
49 | @FXML
50 | private ListView consoleid;
51 |
52 | private ClassGen classGen;
53 |
54 | private boolean classFile = false;
55 |
56 | private File source;
57 |
58 | @FXML
59 | private void initialize() {
60 | //
61 | Static.setConsoleid(consoleid);
62 |
63 | // Загружаем по умолчанию mainPain
64 | GridPane root = null;
65 | FXMLLoader fxmlLoader = null;
66 |
67 | fxmlLoader = new FXMLLoader();
68 | fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
69 |
70 | try {
71 | root = (GridPane) fxmlLoader.load(getClass().getResource("/net/ptnkjke/jbeditor/gui/main/panes/defaultpane/View.fxml").openStream());
72 | } catch (IOException e) {
73 | e.printStackTrace();
74 | }
75 |
76 | root.setMaxWidth(10000);
77 | root.setMaxHeight(10000);
78 | secondPane.getChildren().add(root);
79 |
80 |
81 | // Вешаем слушателя
82 | mainTree.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
83 | if (newValue == null) {
84 | return;
85 | }
86 |
87 | if (newValue.getValue() instanceof net.ptnkjke.jbeditor.gui.main.model.classtree.Method) {
88 | net.ptnkjke.jbeditor.gui.main.model.classtree.Method method = (net.ptnkjke.jbeditor.gui.main.model.classtree.Method) newValue.getValue();
89 |
90 | // Загружаем для правой части
91 | MethodModel m = new MethodModel(method.getClassGen().getClassName(), method.getMethodIndex());
92 |
93 | GridPane gridPane = MethodUtils.loadView(m);
94 |
95 | secondPane.getChildren().clear();
96 | secondPane.getChildren().add(gridPane);
97 | } else if (newValue.getValue() instanceof ConstantPool) {
98 | ConstantPool constantPool = (ConstantPool) newValue.getValue();
99 | TabPane pane = net.ptnkjke.jbeditor.gui.main.constantpanes.table.Static.loadView(constantPool.getClassGen());
100 | secondPane.getChildren().clear();
101 | secondPane.getChildren().add(pane);
102 | } else if (newValue.getValue() instanceof net.ptnkjke.jbeditor.gui.main.model.classtree.Constant) {
103 | net.ptnkjke.jbeditor.gui.main.model.classtree.Constant constant = (net.ptnkjke.jbeditor.gui.main.model.classtree.Constant) newValue.getValue();
104 | org.apache.bcel.classfile.Constant const_bcel = constant.getConstant();
105 | switch (constant.getConstant().getTag()) {
106 | case Const.CONSTANT_Utf8:
107 | ConstantUtf8 utf8 = (ConstantUtf8) const_bcel;
108 | break;
109 | case Const.CONSTANT_Integer:
110 | ConstantInteger integer = (ConstantInteger) const_bcel;
111 | break;
112 | case Const.CONSTANT_Float:
113 | ConstantFloat constantFloat = (ConstantFloat) const_bcel;
114 | break;
115 | case Const.CONSTANT_Long:
116 | ConstantLong constantLong = (ConstantLong) const_bcel;
117 | break;
118 | case Const.CONSTANT_Double:
119 | ConstantDouble constantDouble = (ConstantDouble) const_bcel;
120 | break;
121 | case Const.CONSTANT_Class:
122 | ConstantClass constantClass = (ConstantClass) const_bcel;
123 | break;
124 | case Const.CONSTANT_Fieldref:
125 | ConstantFieldref fieldref = (ConstantFieldref) const_bcel;
126 | break;
127 | case Const.CONSTANT_String:
128 | ConstantString string = (ConstantString) const_bcel;
129 | break;
130 | case Const.CONSTANT_Methodref:
131 | ConstantMethodref methodref = (ConstantMethodref) const_bcel;
132 | break;
133 | case Const.CONSTANT_InterfaceMethodref:
134 | ConstantInterfaceMethodref interfaceMethodref = (ConstantInterfaceMethodref) const_bcel;
135 | break;
136 | case Const.CONSTANT_NameAndType:
137 | ConstantNameAndType nameAndType = (ConstantNameAndType) const_bcel;
138 | break;
139 | case Const.CONSTANT_MethodHandle:
140 | ConstantMethodHandle methodHandle = (ConstantMethodHandle) const_bcel;
141 | break;
142 | case Const.CONSTANT_MethodType:
143 | ConstantMethodType methodType = (ConstantMethodType) const_bcel;
144 | break;
145 | default:
146 | try {
147 | throw new Exception("");
148 | } catch (Exception e) {
149 | e.printStackTrace();
150 | }
151 | }
152 | } else if (newValue.getValue() instanceof GeneralInformation) {
153 | ClassGen cg = ((GeneralInformation) newValue.getValue()).getClassGen();
154 |
155 | // Загружаем для правой части
156 | VBox vbox = Utils.loadView(cg);
157 | secondPane.getChildren().clear();
158 | secondPane.getChildren().add(vbox);
159 | }
160 | });
161 |
162 | // Свой виджет
163 | consoleid.setCellFactory(param -> new FlowListCell());
164 | }
165 |
166 | public void onButtonLoadClass() {
167 | // Вызываем диалоговое окно для выбора файла
168 |
169 | FileChooser fileChooser = new FileChooser();
170 | fileChooser.getExtensionFilters()
171 | .addAll(
172 | new FileChooser.ExtensionFilter("Java Class", "*.class"),
173 | new FileChooser.ExtensionFilter("Jar", "*.jar")
174 | );
175 |
176 | source = fileChooser.showOpenDialog(null);
177 |
178 | // Если файл не пустой, то производим открытие
179 | if (source == null) {
180 | return;
181 | }
182 |
183 | // Заполняем дерево
184 | openFile(source);
185 | }
186 |
187 | public void openFile(File file) {
188 |
189 | TreeItem rootNode = Info.createInfo(file.getName(), Root.class);
190 | mainTree.setRoot(rootNode);
191 |
192 | Core.INSTANCE.read(file.getAbsolutePath());
193 |
194 | if (file.getName().contains(".jar")) {
195 | openJarFile(file);
196 | } else {
197 | classFile = true;
198 | openClassFile(file);
199 | }
200 | }
201 |
202 | private void openJarFile(File file) {
203 | // Принудительно загружаем класс
204 | //JarClassLoader classLoader = new JarClassLoader(file.getAbsolutePath());
205 |
206 | JarInputStream jarInputStream = null;
207 |
208 | try{
209 | jarInputStream = new JarInputStream(new FileInputStream(file));
210 | } catch (IOException e) {
211 | ConsoleMessage consoleMessage = new ConsoleMessage(
212 | e.getClass().getName() + " " + e.getMessage(),
213 | MessageType.WARNING,
214 | "exception.openJarfile.IOException",
215 | e);
216 | Static.addMessage(consoleMessage);
217 | }
218 |
219 | try {
220 | ZipEntry next = jarInputStream.getNextEntry();
221 | while (next != null) {
222 | if (next.getName().contains(".class")) {
223 | JavaClass javaClass = new ClassParser(file.getAbsolutePath(), next.getName()).parse();
224 |
225 | addClassToTree(javaClass, false);
226 | }
227 | next = jarInputStream.getNextEntry();
228 | }
229 |
230 | // Сортируем дерево на выходе
231 | FXCollections.sort(mainTree.getRoot().getChildren(), (o1, o2) -> o1.getValue().getTitle().compareTo(o2.getValue().getTitle()));
232 |
233 | } catch (IOException e) {
234 | ConsoleMessage consoleMessage = new ConsoleMessage(
235 | e.getClass().getName() + " " + e.getMessage(),
236 | MessageType.WARNING,
237 | "exception.openJarfile.IOException2",
238 | e);
239 | Static.addMessage(consoleMessage);
240 | }
241 |
242 | try {
243 | jarInputStream.close();
244 | } catch (IOException e) {
245 | ConsoleMessage consoleMessage = new ConsoleMessage(
246 | e.getClass().getName() + " " + e.getMessage(),
247 | MessageType.WARNING,
248 | "exception.openJarfile.IOException3",
249 | e);
250 | Static.addMessage(consoleMessage);
251 | }
252 | }
253 |
254 | private void openClassFile(final File file) {
255 |
256 | JavaClass javaClass;
257 | try {
258 | javaClass = new ClassParser(file.getAbsolutePath()).parse();
259 | } catch (IOException e) {
260 | e.printStackTrace();
261 | return;
262 | }
263 | addClassToTree(javaClass, false);
264 |
265 |
266 | }
267 |
268 | private void addClassToTree(JavaClass javaClass, boolean toRoot) {
269 | ClassGen classGen = new ClassGen(javaClass);
270 | TreeItem rootNode = mainTree.getRoot();
271 |
272 | TreeItem classNode = Info.createInfo(javaClass.getClassName(), Root.class);
273 | rootNode.getChildren().add(classNode);
274 | rootNode = classNode;
275 |
276 | TreeItem node = null;
277 | // GENERAL INFORMATION
278 | node = Info.createInfo("General Information", GeneralInformation.class);
279 | ((GeneralInformation) node.getValue()).setClassGen(classGen);
280 | rootNode.getChildren().add(node);
281 |
282 | // CONSTANT POOL
283 | node = Info.createInfo("Constant Pool", ConstantPool.class);
284 | rootNode.getChildren().add(node);
285 | ((ConstantPool) node.getValue()).setClassGen(classGen);
286 |
287 | org.apache.bcel.classfile.Constant[] constants = javaClass.getConstantPool().getConstantPool();
288 | for (int i = 0; i < constants.length; i++) {
289 | org.apache.bcel.classfile.Constant constant = constants[i];
290 | if (constant == null) {
291 | continue;
292 | }
293 | TreeItem inner = Info.createInfo("[" + i + "] " + constant.toString(), net.ptnkjke.jbeditor.gui.main.model.classtree.Constant.class);
294 | ((net.ptnkjke.jbeditor.gui.main.model.classtree.Constant) inner.getValue()).setConstant(constant);
295 | node.getChildren().add(inner);
296 | }
297 |
298 | // INTERFACES
299 | node = Info.createInfo("Interfaces", Interfaces.class);
300 | rootNode.getChildren().add(node);
301 |
302 | try {
303 | JavaClass[] intrefaces = javaClass.getInterfaces();
304 | for (JavaClass inter : intrefaces) {
305 | TreeItem inner = Info.createInfo(inter.toString(), Interface.class);
306 | node.getChildren().add(inner);
307 | }
308 | } catch (ClassNotFoundException e) {
309 | ConsoleMessage consoleMessage = new ConsoleMessage(
310 | e.getMessage(),
311 | MessageType.WARNING,
312 | "exception.addClassToTree.ClassNotFound",
313 | e);
314 | Static.addMessage(consoleMessage);
315 | }
316 |
317 | // METHODS
318 | node = Info.createInfo("Methods", Methods.class);
319 | rootNode.getChildren().add(node);
320 |
321 | org.apache.bcel.classfile.Method[] methods = javaClass.getMethods();
322 | int methodIndex = 0;
323 | for (org.apache.bcel.classfile.Method method : methods) {
324 | TreeItem inner = Info.createInfo(method.toString(), net.ptnkjke.jbeditor.gui.main.model.classtree.Method.class);
325 | ((net.ptnkjke.jbeditor.gui.main.model.classtree.Method) inner.getValue()).setMethodIndex(methodIndex);
326 | ((net.ptnkjke.jbeditor.gui.main.model.classtree.Method) inner.getValue()).setClassGen(classGen);
327 |
328 | node.getChildren().add(inner);
329 | methodIndex++;
330 | }
331 |
332 | // ATTRIBUTES
333 | node = Info.createInfo("Attributes", Attributes.class);
334 | rootNode.getChildren().add(node);
335 |
336 | org.apache.bcel.classfile.Attribute[] attributes = javaClass.getAttributes();
337 | for (org.apache.bcel.classfile.Attribute attribute : attributes) {
338 | TreeItem inner = Info.createInfo(attribute.toString(), net.ptnkjke.jbeditor.gui.main.model.classtree.Attribute.class);
339 | node.getChildren().add(inner);
340 | }
341 | }
342 |
343 | /**
344 | * Save Change
345 | */
346 | public void saveChange() {
347 | Core.INSTANCE.save();
348 | }
349 |
350 | // Окно с настройками
351 | public void openPreferences() {
352 | Parent root = null;
353 | try {
354 | FXMLLoader fxmlLoader = new FXMLLoader();
355 | //fxmlLoader.setResources(ResourceBundle.getBundle("translation"));
356 |
357 | root = fxmlLoader.load(this.getClass().getResource("/net/ptnkjke/jbeditor/gui/preferences/View.fxml").openStream());
358 | } catch (IOException e) {
359 | e.printStackTrace();
360 | }
361 | Stage dialog = new Stage();
362 | dialog.initStyle(StageStyle.UTILITY);
363 | dialog.setResizable(false);
364 | dialog.initModality(Modality.APPLICATION_MODAL);
365 | dialog.setScene(new Scene(root));
366 | dialog.setTitle("preferences");
367 |
368 | // Событие на закрытие окна
369 | dialog.setOnCloseRequest(new EventHandler() {
370 | @Override
371 | public void handle(WindowEvent windowEvent) {
372 | Configutation.save();
373 | }
374 | });
375 |
376 | dialog.show();
377 | }
378 |
379 | public void onAbout() {
380 |
381 | }
382 | }
383 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/FlowListCell.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main;
2 |
3 | import javafx.scene.control.Hyperlink;
4 | import javafx.scene.control.ListCell;
5 | import javafx.scene.paint.Color;
6 | import javafx.scene.text.Text;
7 | import javafx.scene.text.TextFlow;
8 | import net.ptnkjke.jbeditor.gui.main.model.ConsoleMessage;
9 | import net.ptnkjke.jbeditor.gui.main.model.MessageType;
10 |
11 | /**
12 | * Created by Lopatin on 08.07.2014.
13 | */
14 | public class FlowListCell extends ListCell {
15 |
16 | @Override
17 | protected void updateItem(ConsoleMessage item, boolean empty) {
18 | super.updateItem(item, empty);
19 |
20 | if (item != null) {
21 | TextFlow textFlow = new TextFlow();
22 | Text text = new Text(item.getMessage());
23 |
24 | if (item.getType() == MessageType.CRITICAL) {
25 | text.setFill(Color.RED);
26 | } else if (item.getType() == MessageType.WARNING) {
27 | text.setFill(Color.DARKBLUE);
28 | }
29 |
30 | Hyperlink hyperlink = new Hyperlink("[description]");
31 |
32 |
33 | textFlow.getChildren().addAll(text);
34 | textFlow.getChildren().add(hyperlink);
35 |
36 | setGraphic(textFlow);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/Static.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main;
2 |
3 | import javafx.scene.control.ListView;
4 | import net.ptnkjke.jbeditor.gui.main.model.ConsoleMessage;
5 |
6 | /**
7 | * Created by Lopatin on 09.07.2014.
8 | */
9 | public class Static {
10 | private static ListView consoleid;
11 |
12 | public static void setConsoleid(ListView consoleid_) {
13 | consoleid = consoleid_;
14 | }
15 |
16 | public static void addMessage(ConsoleMessage consoleMessage) {
17 | consoleid.getItems().addAll(consoleMessage);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
17 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_class/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_class;
2 |
3 | import org.apache.bcel.classfile.ConstantClass;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantClass constant;
10 |
11 | public void setConstant(ConstantClass constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_class/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_double/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_double;
2 |
3 | import org.apache.bcel.classfile.ConstantDouble;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantDouble constant;
10 |
11 | public void setConstant(ConstantDouble constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_double/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_fieldref/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_fieldref;
2 |
3 | import org.apache.bcel.classfile.ConstantFieldref;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantFieldref constant;
10 |
11 | public void setConstant(ConstantFieldref constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_fieldref/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_float/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_float;
2 |
3 | import org.apache.bcel.classfile.ConstantFloat;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantFloat constant;
10 |
11 | public void setConstant(ConstantFloat constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_float/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_integer/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_integer;
2 |
3 | import org.apache.bcel.classfile.ConstantInteger;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantInteger constant;
10 |
11 | public void setConstant(ConstantInteger constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_integer/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_interfacemethodref/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_interfacemethodref;
2 |
3 | import org.apache.bcel.classfile.ConstantInterfaceMethodref;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantInterfaceMethodref constant;
10 |
11 | public void setConstant(ConstantInterfaceMethodref constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_interfacemethodref/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_long/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_long;
2 |
3 | import org.apache.bcel.classfile.ConstantLong;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantLong constant;
10 |
11 | public void setConstant(ConstantLong constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_long/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_methodhandle/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_methodhandle;
2 |
3 | import org.apache.bcel.classfile.ConstantMethodHandle;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantMethodHandle constant;
10 |
11 | public void setConstant(ConstantMethodHandle constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_methodhandle/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_methodref/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_methodref;
2 |
3 | import org.apache.bcel.classfile.ConstantMethodref;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantMethodref constant;
10 |
11 | public void setConstant(ConstantMethodref constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_methodref/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_methodtype/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_methodtype;
2 |
3 | import org.apache.bcel.classfile.ConstantMethodType;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantMethodType constant;
10 |
11 | public void setConstant(ConstantMethodType constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_methodtype/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_nameandtype/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_nameandtype;
2 |
3 | import org.apache.bcel.classfile.ConstantNameAndType;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantNameAndType constant;
10 |
11 | public void setConstant(ConstantNameAndType constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_nameandtype/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_string/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_string;
2 |
3 | import org.apache.bcel.classfile.ConstantString;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantString constant;
10 |
11 | public void setConstant(ConstantString constant) {
12 | this.constant = constant;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_string/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_utf8/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.constantpane_utf8;
2 |
3 | import org.apache.bcel.classfile.ConstantUtf8;
4 |
5 | /**
6 | * Created by Lopatin on 16.07.2014.
7 | */
8 | public class Controller {
9 | private ConstantUtf8 constant;
10 |
11 | public void setConstant(ConstantUtf8 constant) {
12 | this.constant = constant;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/constantpane_utf8/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/table/ConstantTableCell.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.table;
2 |
3 | import javafx.beans.property.SimpleIntegerProperty;
4 | import javafx.beans.property.SimpleStringProperty;
5 |
6 | /**
7 | * Created by Lopatin on 09.07.2014.
8 | */
9 | public class ConstantTableCell {
10 | private SimpleIntegerProperty id = new SimpleIntegerProperty();
11 | private SimpleStringProperty type = new SimpleStringProperty();
12 | private SimpleStringProperty value = new SimpleStringProperty();
13 | // Пользователь в таблице сделал изменение
14 | private boolean changed = false;
15 | // Тип константы
16 | private byte const_type;
17 |
18 | public Integer getId() {
19 | return id.get();
20 | }
21 |
22 | public void setId(Integer id) {
23 | this.id.set(id);
24 | }
25 |
26 | public String getType() {
27 | return type.get();
28 | }
29 |
30 | public void setType(String type) {
31 | this.type.set(type);
32 | }
33 |
34 | public String getValue() {
35 | return value.get();
36 | }
37 |
38 | public void setValue(String value) {
39 | this.value.set(value);
40 | }
41 |
42 | public boolean isChanged() {
43 | return changed;
44 | }
45 |
46 | public void setChanged(boolean changed) {
47 | this.changed = changed;
48 | }
49 |
50 |
51 | public byte getConst_type() {
52 | return const_type;
53 | }
54 |
55 | public void setConst_type(byte const_type) {
56 | this.const_type = const_type;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/table/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.table;
2 |
3 | import javafx.event.EventHandler;
4 | import javafx.fxml.FXML;
5 | import javafx.scene.control.*;
6 | import javafx.scene.control.cell.PropertyValueFactory;
7 | import javafx.scene.input.KeyCode;
8 | import javafx.scene.input.KeyEvent;
9 | import net.ptnkjke.jbeditor.logic.Core;
10 | import net.ptnkjke.jbeditor.logic.bcel.bytecode.CellConstantWorker;
11 | import net.ptnkjke.jbeditor.logic.own.bytecode.ConstantPool;
12 | import net.ptnkjke.jbeditor.logic.own.bytecode.OClass;
13 | import org.apache.bcel.Const;
14 | import org.apache.bcel.classfile.Constant;
15 | import org.apache.bcel.classfile.Method;
16 | import org.apache.bcel.generic.*;
17 |
18 | import java.io.IOException;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * TODO: Интересные невероятности. BCEL не имеет возможности удалнеия константы, нет возможности контроирования пулов....
24 | * Нельзя взять просто так и отредактриовать сущесвующую.. всё это происходид через дополнительные методы.
25 | */
26 |
27 | /**
28 | * Created by Lopatin on 09.07.2014.
29 | */
30 | public class Controller {
31 | @FXML
32 | private TableView table;
33 | @FXML
34 | private TextArea cpEditor;
35 |
36 | private ClassGen classGen;
37 | private OClass oClass;
38 |
39 | @FXML
40 | public void initialize() {
41 | TableColumn column = (TableColumn) table.getColumns().get(0);
42 | column.setCellValueFactory(new PropertyValueFactory("id"));
43 |
44 | TableColumn column1 = (TableColumn) table.getColumns().get(1);
45 | column1.setCellValueFactory(new PropertyValueFactory("type"));
46 |
47 | TableColumn column2 = (TableColumn) table.getColumns().get(2);
48 | column2.setCellValueFactory(new PropertyValueFactory("value"));
49 | table.setEditable(true);
50 |
51 | // Добавляем поле, которое будет появляться для редактирования
52 | column2.setCellFactory(param -> new EditingCell());
53 | // Автосохранение изменений
54 | column2.setOnEditCommit(
55 | t -> {
56 | t.getRowValue().setValue(t.getNewValue());
57 | t.getRowValue().setChanged(true);
58 | /* ((ConstantTableCell) t.getTableView().getItems().get(
59 | t.getTablePosition().getRow())).setValue(t.getNewValue());*/
60 | });
61 | }
62 |
63 | public void setClassGen(ClassGen cg) {
64 | this.classGen = cg;
65 | ConstantPoolGen cpg = cg.getConstantPool();
66 | int length = cpg.getConstantPool().getLength();
67 | for (int i = 1; i < length; i++) {
68 | Constant constant = cpg.getConstant(i);
69 | if (constant == null) {
70 | continue;
71 | }
72 | ConstantTableCell ctb;
73 |
74 | CellConstantWorker cellConstantWorker = new CellConstantWorker(cpg.getConstantPool());
75 |
76 | try {
77 | cellConstantWorker.visit(constant);
78 | } catch (Exception e) {
79 | e.printStackTrace();
80 | }
81 |
82 | ctb = cellConstantWorker.getConstantTableCell();
83 | if (ctb == null) {
84 | continue;
85 | }
86 | ctb.setConst_type(constant.getTag());
87 | ctb.setId(i);
88 | table.getItems().add(ctb);
89 | }
90 |
91 | // Преобразуем константу в текст
92 | // TODO: А нахуя этот кусок?
93 | /* StringBuilder sb = new StringBuilder();
94 | for (int i = 1; i < length; i++) {
95 | Constant constant = cpg.getConstant(i);
96 | if (constant == null) {
97 | continue;
98 | }
99 | TextConstantWorker textConstantWorker = new TextConstantWorker(cpg.getConstantPool());
100 |
101 | try {
102 | textConstantWorker.visit(constant);
103 | } catch (Exception e) {
104 | e.printStackTrace();
105 | }
106 |
107 | sb.append(textConstantWorker.getText()).append("\n");
108 | }*/
109 |
110 | oClass = new OClass();
111 | try {
112 | oClass.readFromBytes(Core.INSTANCE.getClassMap().get(cg.getClassName()));
113 | } catch (Exception e) {
114 | e.printStackTrace();
115 | }
116 | cpEditor.setText(ConstantPool.getConstantPoolCode(oClass.getConstantPool()));
117 | }
118 |
119 | // Сохранение констант
120 | public void saveConstants() throws Exception {
121 |
122 | ConstantPoolGen constantPoolGen =
123 | classGen.getConstantPool();
124 |
125 | for (ConstantTableCell cell : table.getItems()) {
126 |
127 | if (!cell.isChanged()) {
128 | continue;
129 | }
130 |
131 | int old_id = cell.getId();
132 | int new_id = -1;
133 |
134 | // Получаем новый id-шник
135 | switch (cell.getConst_type()) {
136 | case Const.CONSTANT_Utf8:
137 | new_id = constantPoolGen.addUtf8(cell.getValue());
138 | break;
139 | case Const.CONSTANT_Integer:
140 | new_id = constantPoolGen.addInteger(Integer.parseInt(cell.getValue()));
141 | break;
142 | case Const.CONSTANT_Float:
143 | new_id = constantPoolGen.addFloat(Float.parseFloat(cell.getValue()));
144 | break;
145 | case Const.CONSTANT_Long:
146 | new_id = constantPoolGen.addLong(Integer.parseInt(cell.getValue()));
147 | break;
148 | case Const.CONSTANT_Double:
149 | new_id = constantPoolGen.addDouble(Double.parseDouble(cell.getValue()));
150 | break;
151 | case Const.CONSTANT_Class:
152 | // TODO:
153 | break;
154 | case Const.CONSTANT_Fieldref:
155 | // TODO:
156 | break;
157 | case Const.CONSTANT_String:
158 | new_id = constantPoolGen.addString(cell.getValue());
159 | break;
160 | case Const.CONSTANT_Methodref:
161 | // TODO:
162 | break;
163 | case Const.CONSTANT_InterfaceMethodref:
164 | // TODO:
165 | break;
166 | case Const.CONSTANT_NameAndType:
167 | // TODO:
168 | break;
169 | case Const.CONSTANT_MethodHandle:
170 | // TODO:
171 | // break;
172 | case Const.CONSTANT_MethodType:
173 | // TODO:
174 | // break;
175 | default:
176 | throw new Exception("");
177 | }
178 |
179 | List changes = new ArrayList<>();
180 |
181 | // Обхоим все инструкции и меняем страый id-шник на новый
182 | for (int i = 0; i < classGen.getMethods().length; i++) {
183 | MethodGen methodGen = new MethodGen(classGen.getMethodAt(i), classGen.getClassName(), classGen.getConstantPool());
184 | InstructionHandle handle = methodGen.getInstructionList().getStart();
185 |
186 | do {
187 | Instruction instr = handle.getInstruction();
188 | if (instr instanceof CPInstruction) {
189 | CPInstruction cpInstruction = (CPInstruction) instr;
190 | if (cpInstruction.getIndex() == old_id) {
191 | cpInstruction.setIndex(new_id);
192 | }
193 | }
194 | handle = handle.getNext();
195 | } while (handle != null);
196 | changes.add(methodGen.getMethod());
197 | }
198 |
199 | // Вставляем обновлённые методы обратно и радуемся
200 | classGen.setMethods(changes.toArray(new Method[changes.size()]));
201 |
202 | // Update bytes in Core
203 | Core.INSTANCE.getClassMap().put(classGen.getClassName(), classGen.getJavaClass().getBytes());
204 | }
205 | }
206 |
207 | // Сохранение констант из текстового редактора
208 | public void saveConstantsFromEditor() {
209 | String code = cpEditor.getText();
210 | oClass.setConstantPool(ConstantPool.parseCode(code));
211 |
212 | // Update bytes in Core
213 | try {
214 | Core.INSTANCE.getClassMap().put(classGen.getClassName(), oClass.dump());
215 | } catch (IOException e) {
216 | e.printStackTrace();
217 | }
218 | }
219 |
220 | // Приватный класс для представление в таблице
221 | class EditingCell extends TableCell {
222 |
223 | private TextField textField;
224 |
225 | public EditingCell() {
226 | }
227 |
228 | @Override
229 | public void startEdit() {
230 | super.startEdit();
231 |
232 | /* if (textField == null) {*/
233 | createTextField();
234 | /* }*/
235 |
236 | setGraphic(textField);
237 | setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
238 | textField.selectAll();
239 | }
240 |
241 | @Override
242 | public void cancelEdit() {
243 | super.cancelEdit();
244 |
245 | setText(String.valueOf(getItem()));
246 | setContentDisplay(ContentDisplay.TEXT_ONLY);
247 | }
248 |
249 | @Override
250 | public void updateItem(String item, boolean empty) {
251 | super.updateItem(item, empty);
252 |
253 | if (empty) {
254 | setText(null);
255 | setGraphic(null);
256 | } else {
257 | if (isEditing()) {
258 | if (textField != null) {
259 | textField.setText(getString());
260 | }
261 | setGraphic(textField);
262 | setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
263 | } else {
264 | setText(getString());
265 | setContentDisplay(ContentDisplay.TEXT_ONLY);
266 | }
267 | }
268 | }
269 |
270 | private void createTextField() {
271 | textField = new TextField(getString());
272 | textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
273 | textField.setOnKeyPressed(new EventHandler() {
274 |
275 | @Override
276 | public void handle(KeyEvent t) {
277 | if (t.getCode() == KeyCode.ENTER) {
278 | commitEdit(textField.getText());
279 | } else if (t.getCode() == KeyCode.ESCAPE) {
280 | cancelEdit();
281 | }
282 | }
283 | });
284 | }
285 |
286 | private String getString() {
287 | return getItem() == null ? "" : getItem().toString();
288 | }
289 | }
290 | }
291 |
292 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/table/Static.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.constantpanes.table;
2 |
3 | import javafx.fxml.FXMLLoader;
4 | import javafx.fxml.JavaFXBuilderFactory;
5 | import javafx.scene.control.TabPane;
6 | import net.ptnkjke.jbeditor.gui.main.panes.methodpane.MethodUtils;
7 | import org.apache.bcel.generic.ClassGen;
8 |
9 | import java.io.IOException;
10 |
11 | public class Static {
12 | public static TabPane loadView(ClassGen cg) {
13 |
14 | TabPane pane = null;
15 |
16 | FXMLLoader fxmlLoader = null;
17 |
18 | fxmlLoader = new FXMLLoader();
19 | fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
20 |
21 | try {
22 | pane = (TabPane) fxmlLoader.load(MethodUtils.class.getResource("/net/ptnkjke/jbeditor/gui/main/constantpanes/table/View.fxml").openStream());
23 | } catch (IOException e) {
24 | e.printStackTrace();
25 | }
26 | pane.setMaxWidth(10000);
27 | pane.setMaxHeight(10000);
28 |
29 | Controller controller = fxmlLoader.getController();
30 | controller.setClassGen(cg);
31 | return pane;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/constantpanes/table/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/ConsoleMessage.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model;
2 |
3 | /**
4 | * Created by Lopatin on 08.07.2014.
5 | */
6 | public class ConsoleMessage {
7 | private String message;
8 | private String descritionPropertie;
9 | private MessageType type;
10 | private Exception exception;
11 |
12 | public ConsoleMessage(String message, MessageType type, String descritionPropertie, Exception e) {
13 | this.message = message;
14 | this.type = type;
15 | this.descritionPropertie = descritionPropertie;
16 | this.exception = exception;
17 | }
18 |
19 | public String getMessage() {
20 | return message;
21 | }
22 |
23 | public void setMessage(String message) {
24 | this.message = message;
25 | }
26 |
27 | public MessageType getType() {
28 | return type;
29 | }
30 |
31 | public void setType(MessageType type) {
32 | this.type = type;
33 | }
34 |
35 | public String getDescritionPropertie() {
36 | return descritionPropertie;
37 | }
38 |
39 | public void setDescritionPropertie(String descritionPropertie) {
40 | this.descritionPropertie = descritionPropertie;
41 | }
42 |
43 | public Exception getException() {
44 | return exception;
45 | }
46 |
47 | public void setException(Exception exception) {
48 | this.exception = exception;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/MessageType.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model;
2 |
3 | /**
4 | * Created by Lopatin on 08.07.2014.
5 | */
6 | public enum MessageType {
7 | WARNING, CRITICAL
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Attribute.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Attribute extends Info {
7 | public Attribute(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Attributes.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Attributes extends Info {
7 | public Attributes(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Constant.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Constant extends Info {
7 | private org.apache.bcel.classfile.Constant constant;
8 |
9 | public Constant(String title) {
10 | super(title);
11 | }
12 |
13 | public org.apache.bcel.classfile.Constant getConstant() {
14 | return constant;
15 | }
16 |
17 | public void setConstant(org.apache.bcel.classfile.Constant constant) {
18 | this.constant = constant;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/ConstantPool.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | import org.apache.bcel.generic.ClassGen;
4 |
5 | /**
6 | * Created by Lopatin on 03.07.2014.
7 | */
8 | public class ConstantPool extends Info {
9 | private ClassGen classGen;
10 |
11 | public ConstantPool(String title) {
12 | super(title);
13 | }
14 |
15 | public ClassGen getClassGen() {
16 | return classGen;
17 | }
18 |
19 | public void setClassGen(ClassGen classGen) {
20 | this.classGen = classGen;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Field.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Field extends Info {
7 | public Field(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Fields.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Fields extends Info {
7 | public Fields(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/GeneralInformation.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | import org.apache.bcel.generic.ClassGen;
4 |
5 | /**
6 | * Created by Lopatin on 03.07.2014.
7 | */
8 | public class GeneralInformation extends Info {
9 | private ClassGen classGen;
10 |
11 | public GeneralInformation(String title) {
12 | super(title);
13 | }
14 |
15 | public ClassGen getClassGen() {
16 | return classGen;
17 | }
18 |
19 | public void setClassGen(ClassGen classGen) {
20 | this.classGen = classGen;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Info.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | import javafx.beans.property.SimpleStringProperty;
4 | import javafx.scene.control.TreeItem;
5 |
6 | import java.lang.reflect.Constructor;
7 | import java.lang.reflect.InvocationTargetException;
8 |
9 | /**
10 | * Created by Lopatin on 03.07.2014.
11 | */
12 | public abstract class Info {
13 | protected SimpleStringProperty title;
14 |
15 | public Info(String title) {
16 | this.title = new SimpleStringProperty(title);
17 | }
18 |
19 | public String getTitle() {
20 | return title.get();
21 | }
22 |
23 | public void setTitle(String title) {
24 | this.title.set(title);
25 | }
26 |
27 | @Override
28 | public String toString() {
29 | return title.get();
30 | }
31 |
32 |
33 | /**
34 | * Создающий метод, чтобы не писать каждый раз лишнии строчки кода
35 | *
36 | * @param title
37 | * @param type
38 | * @return
39 | */
40 | public static TreeItem createInfo(String title, Class type) {
41 | try {
42 | Constructor constructor = type.getConstructor(String.class);
43 | Info info = (Info) constructor.newInstance(title);
44 |
45 | TreeItem infoTreeItem = new TreeItem(info);
46 | return new TreeItem(info);
47 | } catch (NoSuchMethodException e) {
48 | e.printStackTrace();
49 | } catch (InvocationTargetException e) {
50 | e.printStackTrace();
51 | } catch (InstantiationException e) {
52 | e.printStackTrace();
53 | } catch (IllegalAccessException e) {
54 | e.printStackTrace();
55 | }
56 |
57 | return null;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Interface.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Interface extends Info {
7 | public Interface(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Interfaces.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Interfaces extends Info {
7 | public Interfaces(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Method.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | import org.apache.bcel.generic.ClassGen;
4 |
5 | /**
6 | * Created by Lopatin on 03.07.2014.
7 | */
8 | public class Method extends Info {
9 | // Класс, к которому относится данный метод
10 | private ClassGen classGen;
11 | // Индекс метода
12 | private int methodIndex;
13 |
14 | public Method(String title) {
15 | super(title);
16 | }
17 |
18 | public ClassGen getClassGen() {
19 | return classGen;
20 | }
21 |
22 | public void setClassGen(ClassGen classGen) {
23 | this.classGen = classGen;
24 | }
25 |
26 | public int getMethodIndex() {
27 | return methodIndex;
28 | }
29 |
30 | public void setMethodIndex(int methodIndex) {
31 | this.methodIndex = methodIndex;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Methods.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Methods extends Info {
7 | public Methods(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/model/classtree/Root.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.model.classtree;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Root extends Info {
7 | public Root(String title) {
8 | super(title);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/defaultpane/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.defaultpane;
2 |
3 | /**
4 | * Created by Lopatin on 03.07.2014.
5 | */
6 | public class Controller {
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/defaultpane/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/descriptionerror/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.descriptionerror;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.TextArea;
5 |
6 | /**
7 | * Created by Lopatin on 14.07.2014.
8 | */
9 | public class Controller {
10 | @FXML
11 | private TextArea textArea;
12 |
13 | public void onSendInfoAboutError() {
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/descriptionerror/Static.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.descriptionerror;
2 |
3 | import javafx.stage.Stage;
4 |
5 | /**
6 | * Created by Lopatin on 14.07.2014.
7 | */
8 | public class Static {
9 |
10 | public Stage getDescriptionError() {
11 | return null;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/descriptionerror/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/generalinfopane/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.generalinfopane;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.Label;
5 | import org.apache.bcel.generic.ClassGen;
6 |
7 | /**
8 | * Created by dalopatin on 27.08.2014.
9 | */
10 | public class Controller {
11 | @FXML
12 | private Label l_className;
13 | @FXML
14 | private Label l_superClassName;
15 | @FXML
16 | private Label l_fileName;
17 | @FXML
18 | private Label l_major;
19 | @FXML
20 | private Label l_minor;
21 |
22 | private ClassGen classGen;
23 |
24 | public void setClassGen(ClassGen classGen) {
25 | this.classGen = classGen;
26 |
27 | this.l_className.setText(classGen.getClassName());
28 | this.l_superClassName.setText(classGen.getSuperclassName());
29 | this.l_fileName.setText(classGen.getFileName());
30 | this.l_major.setText(Integer.toString(classGen.getMajor()));
31 | this.l_minor.setText(Integer.toString(classGen.getMinor()));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/generalinfopane/Utils.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.generalinfopane;
2 |
3 | import javafx.fxml.FXMLLoader;
4 | import javafx.fxml.JavaFXBuilderFactory;
5 | import javafx.scene.layout.VBox;
6 | import org.apache.bcel.generic.ClassGen;
7 |
8 | import java.io.IOException;
9 |
10 | /**
11 | * Created by dalopatin on 27.08.2014.
12 | */
13 | public class Utils {
14 |
15 | public static VBox loadView(ClassGen classGen){
16 | VBox gridPane = null;
17 |
18 | FXMLLoader fxmlLoader = null;
19 |
20 | fxmlLoader = new FXMLLoader();
21 | fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
22 |
23 | try {
24 | gridPane = (VBox) fxmlLoader.load(Utils.class.getResource("/net/ptnkjke/jbeditor/gui/main/panes/generalinfopane/View.fxml").openStream());
25 |
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 | gridPane.setMaxWidth(10000);
30 | gridPane.setMaxHeight(10000);
31 |
32 | Controller controller = fxmlLoader.getController();
33 | controller.setClassGen(classGen);
34 | return gridPane;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/generalinfopane/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/methodpane/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.methodpane;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.TextArea;
5 | import javafx.scene.web.WebView;
6 | import net.ptnkjke.jbeditor.gui.main.model.classtree.Method;
7 | import net.ptnkjke.jbeditor.utils.Editor;
8 | import net.ptnkjke.jbeditor.utils.GraphVizCreator;
9 | import net.ptnkjke.jbeditor.utils.JByteParser;
10 | import org.apache.bcel.generic.*;
11 |
12 | import java.io.File;
13 | import java.net.MalformedURLException;
14 |
15 |
16 | /**
17 | * Created by Lopatin on 05.07.2014.
18 | */
19 | public class Controller {
20 | @FXML
21 | private TextArea textArea;
22 | @FXML
23 | private WebView webview;
24 |
25 | private GraphVizCreator graphVizCreator;
26 |
27 | private ClassGen classGen;
28 | private Method method;
29 |
30 | public void setMethod(Method method) {
31 | this.method = method;
32 | classGen = method.getClassGen();
33 | int num = method.getMethodIndex();
34 |
35 | MethodGen methodGen = new MethodGen(classGen.getMethodAt(num),
36 | classGen.getClassName(),
37 | classGen.getConstantPool());
38 |
39 | StringBuilder sb = new StringBuilder();
40 | InstructionHandle handle = methodGen.getInstructionList().getStart();
41 |
42 | if (handle != null) {
43 | do {
44 | Editor editor = new Editor();
45 | try {
46 | editor.visit(handle);
47 | } catch (Exception e) {
48 | e.printStackTrace();
49 | }
50 |
51 | sb.append(editor.getResult()).append("\n");
52 | handle = handle.getNext();
53 | } while (handle != null);
54 | }
55 |
56 | textArea.setText(sb.toString());
57 |
58 | graphVizCreator = new GraphVizCreator(methodGen.getInstructionList(), classGen.getConstantPool());
59 | File image = graphVizCreator.getImage();
60 |
61 | if(image != null) {
62 | try {
63 | webview.getEngine().load(image.toURI().toURL().toString());
64 | } catch (MalformedURLException e) {
65 | e.printStackTrace();
66 | }
67 | }
68 | }
69 |
70 | public void testSave() {
71 | JByteParser jByteParser = new JByteParser();
72 | ConstantPoolGen constantPoolGen = classGen.getConstantPool();
73 |
74 | jByteParser.parse(textArea.getText(), constantPoolGen);
75 | InstructionList instructionList = jByteParser.getInstructions();
76 |
77 | int num = method.getMethodIndex();
78 | org.apache.bcel.classfile.Method old = classGen.getMethodAt(num);
79 |
80 | MethodGen mg = new MethodGen(old, classGen.getClassName(), classGen.getConstantPool());
81 | mg.removeLineNumbers();
82 | mg.removeLocalVariables();
83 | mg.setInstructionList(instructionList);
84 | classGen.setMethodAt(mg.getMethod(), num);
85 | }
86 |
87 | public TextArea getTextArea() {
88 | return textArea;
89 | }
90 |
91 | public void setTextArea(TextArea textArea) {
92 | this.textArea = textArea;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/methodpane/MethodController.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.methodpane;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.TextArea;
5 | import javafx.scene.web.WebView;
6 | import net.ptnkjke.jbeditor.logic.bcel.BCELCore;
7 |
8 |
9 | /**
10 | * Created by Lopatin on 05.07.2014.
11 | */
12 | public class MethodController {
13 | // code[bcel]
14 | @FXML
15 | private TextArea codeBcel;
16 | @FXML
17 | private TextArea codeAsm;
18 | @FXML
19 | private WebView webview;
20 |
21 | private MethodModel model;
22 |
23 |
24 | public void setModel(MethodModel model) {
25 | this.model = model;
26 |
27 | if (model.getGraphPath() != null) {
28 | webview.getEngine().load(model.getGraphPath());
29 | }
30 | if (model.getCodeBCEL() != null) {
31 | codeBcel.setText(model.getCodeBCEL());
32 | }
33 | if (model.getCodeASM() != null) {
34 | codeAsm.setText(model.getCodeASM());
35 | }
36 | }
37 |
38 | public void acceptBCELChange() {
39 | BCELCore.updateClassMethod(model.getClassName(), model.getMethodIndex(), codeBcel.getText());
40 | }
41 |
42 | public void acceptASMChange() {
43 |
44 | }
45 |
46 | public TextArea getCodeBcel() {
47 | return codeBcel;
48 | }
49 |
50 | public void setCodeBcel(TextArea codeBcel) {
51 | this.codeBcel = codeBcel;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/methodpane/MethodModel.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.methodpane;
2 |
3 | import net.ptnkjke.jbeditor.logic.asm.ASMCore;
4 | import net.ptnkjke.jbeditor.logic.bcel.BCELCore;
5 |
6 | /**
7 | * Представление
8 | */
9 | public class MethodModel {
10 | /**
11 | * Байт-код для BCEL
12 | */
13 | private String codeBCEL;
14 | /**
15 | * Байт-код для ASM
16 | */
17 | private String codeASM;
18 | /**
19 | * Путь до граф-файла
20 | */
21 | private String graphPath;
22 | /**
23 | * Порядковый нмоер метода
24 | */
25 | private int methodIndex;
26 | /**
27 | * ClassName in format: net.ptnkjke.class
28 | */
29 | private String className;
30 |
31 |
32 | public MethodModel(String className, int methodIndex) {
33 | this.className = className;
34 | this.methodIndex = methodIndex;
35 |
36 | this.codeBCEL = BCELCore.getMethodsCode(className, methodIndex);
37 | this.codeASM = ASMCore.getMethodsCode(className, methodIndex);
38 | this.graphPath = BCELCore.getGraphVizFile(className, methodIndex);
39 | }
40 |
41 | public String getCodeBCEL() {
42 | return codeBCEL;
43 | }
44 |
45 | public void setCodeBCEL(String codeBCEL) {
46 | this.codeBCEL = codeBCEL;
47 | }
48 |
49 | public String getCodeASM() {
50 | return codeASM;
51 | }
52 |
53 | public void setCodeASM(String codeASM) {
54 | this.codeASM = codeASM;
55 | }
56 |
57 | public String getGraphPath() {
58 | return graphPath;
59 | }
60 |
61 | public void setGraphPath(String graphPath) {
62 | this.graphPath = graphPath;
63 | }
64 |
65 | public int getMethodIndex() {
66 | return methodIndex;
67 | }
68 |
69 | public void setMethodIndex(int methodIndex) {
70 | this.methodIndex = methodIndex;
71 | }
72 |
73 | public String getClassName() {
74 | return className;
75 | }
76 |
77 | public void setClassName(String className) {
78 | this.className = className;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/methodpane/MethodUtils.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.methodpane;
2 |
3 | import javafx.fxml.FXMLLoader;
4 | import javafx.fxml.JavaFXBuilderFactory;
5 | import javafx.scene.layout.GridPane;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * Created by Lopatin on 05.07.2014.
11 | */
12 | public class MethodUtils {
13 |
14 | public static GridPane loadView(MethodModel model) {
15 | GridPane gridPane = null;
16 |
17 | FXMLLoader fxmlLoader = null;
18 |
19 | fxmlLoader = new FXMLLoader();
20 | fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
21 |
22 | try {
23 | gridPane = (GridPane) fxmlLoader.load(MethodUtils.class.getResource("View.fxml").openStream());
24 |
25 | } catch (IOException e) {
26 | e.printStackTrace();
27 | }
28 | gridPane.setMaxWidth(10000);
29 | gridPane.setMaxHeight(10000);
30 |
31 | MethodController controller = fxmlLoader.getController();
32 | controller.setModel(model);
33 | return gridPane;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/methodpane/Utils.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.main.panes.methodpane;
2 |
3 | import javafx.fxml.FXMLLoader;
4 | import javafx.fxml.JavaFXBuilderFactory;
5 | import javafx.scene.layout.GridPane;
6 | import net.ptnkjke.jbeditor.gui.main.model.classtree.Method;
7 |
8 | import java.io.IOException;
9 |
10 | /**
11 | * Created by Lopatin on 05.07.2014.
12 | */
13 | public class Utils {
14 |
15 | public static GridPane loadView(Method method) {
16 | GridPane gridPane = null;
17 |
18 | FXMLLoader fxmlLoader = null;
19 |
20 | fxmlLoader = new FXMLLoader();
21 | fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
22 |
23 | try {
24 | gridPane = (GridPane) fxmlLoader.load(Utils.class.getResource("/net/ptnkjke/gui/main/panes/methodpane/View.fxml").openStream());
25 |
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 | gridPane.setMaxWidth(10000);
30 | gridPane.setMaxHeight(10000);
31 |
32 | Controller controller = fxmlLoader.getController();
33 | controller.setMethod(method);
34 | return gridPane;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/main/panes/methodpane/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/preferences/Controller.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.gui.preferences;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.TextField;
5 | import javafx.stage.DirectoryChooser;
6 | import javafx.stage.FileChooser;
7 | import net.ptnkjke.jbeditor.Configutation;
8 |
9 |
10 | import java.io.File;
11 |
12 | /**
13 | * Created by Lopatin on 07.07.2014.
14 | */
15 | public class Controller {
16 | @FXML
17 | private TextField graphViz;
18 | @FXML
19 | private TextField workDir;
20 |
21 | @FXML
22 | private void initialize() {
23 | graphViz.setText(Configutation.graphVizPath);
24 | workDir.setText(Configutation.workDir);
25 | }
26 |
27 | public void chooseGraphVizFile() {
28 | FileChooser fileChooser = new FileChooser();
29 | fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("EXE","*.exe"));
30 |
31 | File file = fileChooser.showOpenDialog(null);
32 |
33 | if (file != null) {
34 | graphViz.setText(file.getAbsolutePath());
35 | }
36 | }
37 |
38 | public void chooseWorkDir() {
39 | DirectoryChooser directoryChooser = new DirectoryChooser();
40 |
41 | File f = directoryChooser.showDialog(null);
42 |
43 | if (f != null) {
44 | workDir.setText(f.getAbsolutePath());
45 | }
46 | }
47 |
48 | public void save() {
49 | Configutation.workDir = workDir.getText();
50 | Configutation.graphVizPath = graphViz.getText();
51 |
52 | Configutation.save();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/gui/preferences/View.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/logic/Core.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.logic;
2 |
3 | import net.lingala.zip4j.exception.ZipException;
4 | import net.lingala.zip4j.model.FileHeader;
5 | import net.lingala.zip4j.model.ZipParameters;
6 | import net.ptnkjke.jbeditor.Configutation;
7 | import net.ptnkjke.jbeditor.utils.Utils;
8 |
9 | import java.io.*;
10 | import java.util.HashMap;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | import net.lingala.zip4j.core.ZipFile;
15 | import org.apache.bcel.classfile.ClassParser;
16 | import org.apache.bcel.classfile.JavaClass;
17 |
18 | /**
19 | * CORE
20 | */
21 | public class Core {
22 | public static Core INSTANCE = new Core();
23 |
24 | /**
25 | * key= ClassName, value = byte class represent
26 | */
27 | private Map classMap = new HashMap();
28 |
29 | /**
30 | * is .jar file loaded or simple .class file?
31 | */
32 | private boolean isJarFileLoaded = false;
33 | /**
34 | * Original .jar byte-contant for saving change in new jar
35 | */
36 | private byte[] originalJar;
37 |
38 | /**
39 | * Read file
40 | *
41 | * @param inPath
42 | */
43 | public void read(String inPath) {
44 | // Clear Class Map
45 | classMap.clear();
46 |
47 | File file = new File(inPath);
48 |
49 | if (file.getName().contains(".jar")) {
50 | readJar(file);
51 | isJarFileLoaded = true;
52 | } else if (file.getName().contains(".class")) {
53 | readClassFile(file);
54 | isJarFileLoaded = false;
55 | }
56 | }
57 |
58 | /**
59 | * Read .jar file
60 | */
61 | private void readJar(File jarFile) {
62 | ZipFile zipFile = null;
63 | try {
64 | zipFile = new ZipFile(jarFile);
65 | } catch (ZipException e) {
66 | e.printStackTrace();
67 | }
68 |
69 | List fileHeaderList = null;
70 | try {
71 | fileHeaderList = zipFile.getFileHeaders();
72 | } catch (ZipException e) {
73 | e.printStackTrace();
74 | }
75 | for (FileHeader fh : fileHeaderList) {
76 | String fileName = fh.getFileName();
77 |
78 | if (fileName.contains(".class")) {
79 | JavaClass javaClass = null;
80 | try {
81 | javaClass = new ClassParser(zipFile.getInputStream(fh), fileName).parse();
82 | } catch (IOException e) {
83 | e.printStackTrace();
84 | } catch (ZipException e) {
85 | e.printStackTrace();
86 | }
87 | classMap.put(fileName.replace("/", ".").replace(".class", ""), javaClass.getBytes());
88 | }
89 | }
90 |
91 | try {
92 | FileInputStream inputStream = new FileInputStream(jarFile);
93 | this.originalJar = Utils.readAllFromInputStream(inputStream);
94 | inputStream.close();
95 | } catch (FileNotFoundException e) {
96 | e.printStackTrace();
97 | } catch (IOException e) {
98 | e.printStackTrace();
99 | }
100 | }
101 |
102 | /**
103 | * Read .class file
104 | */
105 | private void readClassFile(File classFile) {
106 | try {
107 | JavaClass javaClass = new ClassParser(classFile.getAbsolutePath()).parse();
108 | classMap.put(javaClass.getClassName(), javaClass.getBytes());
109 | } catch (IOException e) {
110 | e.printStackTrace();
111 | }
112 | }
113 |
114 | /**
115 | * SaveAll
116 | */
117 | public void save() {
118 | if (isJarFileLoaded) {
119 | saveJar();
120 | } else {
121 | saveClassFile();
122 | }
123 | }
124 |
125 | /**
126 | * Save .jar file
127 | */
128 | private void saveJar() {
129 | File workDir = new File(Configutation.workDir, Utils.getRandomName());
130 | workDir.mkdirs();
131 |
132 | // CreateTmpFile
133 | File tFile = new File(workDir, Utils.getRandomName() + ".jar");
134 |
135 | try {
136 | tFile.createNewFile();
137 | } catch (IOException e) {
138 | e.printStackTrace();
139 | }
140 |
141 | OutputStream outputStream = null;
142 | try {
143 | outputStream = new FileOutputStream(tFile);
144 | outputStream.write(originalJar);
145 | } catch (FileNotFoundException e) {
146 | e.printStackTrace();
147 | } catch (IOException e) {
148 | e.printStackTrace();
149 | } finally {
150 | try {
151 | outputStream.close();
152 | } catch (IOException e) {
153 | e.printStackTrace();
154 | }
155 | }
156 |
157 | // CreateZipFile
158 | ZipFile zipFile = null;
159 | try {
160 | zipFile = new ZipFile(tFile);
161 | } catch (ZipException e) {
162 | e.printStackTrace();
163 | }
164 |
165 | workDir = new File(workDir, "classes");
166 | // UpdateAllClassFile
167 | for (Map.Entry entry : classMap.entrySet()) {
168 | String className = entry.getKey();
169 | byte[] content = entry.getValue();
170 |
171 | className = className.replace(".", "/");
172 |
173 | String path = className + ".class";
174 |
175 | File f = new File(workDir, path);
176 | f.getParentFile().mkdirs();
177 |
178 | try {
179 | outputStream = new FileOutputStream(f);
180 | outputStream.write(content);
181 | } catch (FileNotFoundException e) {
182 | e.printStackTrace();
183 | } catch (IOException e) {
184 | e.printStackTrace();
185 | } finally {
186 | try {
187 | outputStream.close();
188 | } catch (IOException e) {
189 | e.printStackTrace();
190 | }
191 | }
192 | }
193 | File[] allPackages = workDir.listFiles(new FilenameFilter() {
194 | @Override
195 | public boolean accept(File dir, String name) {
196 | return new File(dir, name).isDirectory();
197 | }
198 | });
199 |
200 | File[] allFiles = workDir.listFiles(new FilenameFilter() {
201 | @Override
202 | public boolean accept(File dir, String name) {
203 | return new File(dir, name).isFile();
204 | }
205 | });
206 |
207 | for (File f : allPackages) {
208 | try {
209 | zipFile.addFolder(f, new ZipParameters());
210 | } catch (ZipException e) {
211 | e.printStackTrace();
212 | }
213 | }
214 |
215 | for (File f : allFiles) {
216 | try {
217 | zipFile.addFile(f, new ZipParameters());
218 | } catch (ZipException e) {
219 | e.printStackTrace();
220 | }
221 | }
222 | }
223 |
224 | /**
225 | * Save .class file
226 | */
227 | private void saveClassFile() {
228 | File workDir = new File(Configutation.workDir, Utils.getRandomName());
229 |
230 | for (Map.Entry entry : classMap.entrySet()) {
231 | String className = entry.getKey();
232 | byte[] content = entry.getValue();
233 |
234 | className = className.replace(".", "/");
235 | String path = className.replace(".", "/") + ".class";
236 |
237 | File f = new File(workDir, path);
238 |
239 | f.getParentFile().mkdirs();
240 |
241 | OutputStream outputStream = null;
242 |
243 | try {
244 | outputStream = new FileOutputStream(f);
245 | outputStream.write(content);
246 | } catch (FileNotFoundException e) {
247 | e.printStackTrace();
248 | } catch (IOException e) {
249 | e.printStackTrace();
250 | } finally {
251 | try {
252 | outputStream.close();
253 | } catch (IOException e) {
254 | e.printStackTrace();
255 | }
256 | }
257 | }
258 | }
259 |
260 |
261 | public byte[] getOriginalJar() {
262 | return originalJar;
263 | }
264 |
265 | public void setOriginalJar(byte[] originalJar) {
266 | this.originalJar = originalJar;
267 | }
268 |
269 | public boolean isJarFileLoaded() {
270 | return isJarFileLoaded;
271 | }
272 |
273 | public void setJarFileLoaded(boolean isJarFileLoaded) {
274 | this.isJarFileLoaded = isJarFileLoaded;
275 | }
276 |
277 | public Map getClassMap() {
278 | return classMap;
279 | }
280 |
281 | public void setClassMap(Map classMap) {
282 | this.classMap = classMap;
283 | }
284 | }
285 |
--------------------------------------------------------------------------------
/src/main/java/net/ptnkjke/jbeditor/logic/asm/ASMCore.java:
--------------------------------------------------------------------------------
1 | package net.ptnkjke.jbeditor.logic.asm;
2 |
3 | import net.ptnkjke.jbeditor.logic.asm.bytecode.BCMethodVisitor;
4 | import net.ptnkjke.jbeditor.logic.Core;
5 | import net.ptnkjke.jbeditor.logic.asm.bytecode.BCClassVisitor;
6 | import org.objectweb.asm.ClassReader;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Утилитарный класс для ASM
12 | */
13 | public class ASMCore {
14 | /**
15 | * Получить байт-код определённого метода
16 | *
17 | * @return
18 | */
19 | public static String getMethodsCode(String classFile, int indexMethod) {
20 | byte[] classBytes = Core.INSTANCE.getClassMap().get(classFile);
21 |
22 | ClassReader classReader = new ClassReader(classBytes);
23 | BCClassVisitor visitor = new BCClassVisitor();
24 | classReader.accept(visitor, 0);
25 |
26 | BCMethodVisitor method = visitor.methods.get(indexMethod);
27 | List