Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
#57
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Jan 18, 2023
1 parent 8a9500a commit c2e8424
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Others:
- [feat] 应该对两种搜索方式给出提示 #37
- [bug] 提示框多屏情况下不在同屏显示 #46
- [bug] CFR反编译有时候不工作 #36
- [improve] 更优雅地查看字节码和ASM代码 #56
- [improve] 所有方法的显示应该进行排序以区分重载 #57
- [improve] 搜索结果应该去重 #53
- [improve] 给反编译代码使用更优雅的字体 #55
- [improve] 当选择反编译类时应该清空方法调用信息 #39
4 changes: 3 additions & 1 deletion build/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Use Launch4j
Use Launch4j

JDK 11 generate JRE: `jlink.exe --module-path jmods --add-modules java.desktop --output jre`
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class AllMethodMouseAdapter extends MouseAdapter {
private final JarAnalyzerForm form;
Expand Down Expand Up @@ -232,9 +229,26 @@ public void mouseClicked(MouseEvent evt) {
}

List<MethodReference> mList = JarAnalyzerForm.methodsInClassMap.get(handle.getClassReference());

Map<String, MethodObj> tempResults = new LinkedHashMap<>();

for (MethodReference m : mList) {
MethodObj resObj = new MethodObj(m.getHandle(), m.getClassReference().getName());
allMethodsList.addElement(resObj);
tempResults.put(resObj.toString(), resObj);
}

List<String> keySet = new ArrayList<>(tempResults.keySet());
Collections.sort(keySet);

for (String s : keySet) {
MethodObj obj = tempResults.get(s);
if(obj.getMethod().getName().startsWith("lambda$")){
continue;
}
if(obj.getMethod().getName().equals("<clinit>")){
continue;
}
allMethodsList.addElement(tempResults.get(s));
}

JarAnalyzerForm.curRes = new ResObj(res.getMethod(), res.getClassName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class MappingMouseAdapter extends MouseAdapter {

Expand Down Expand Up @@ -259,9 +256,26 @@ public void mouseClicked(MouseEvent evt) {
}

List<MethodReference> mList = JarAnalyzerForm.methodsInClassMap.get(handle.getClassReference());

Map<String, MethodObj> tempResults = new LinkedHashMap<>();

for (MethodReference m : mList) {
MethodObj resObj = new MethodObj(m.getHandle(), m.getClassReference().getName());
allMethodsList.addElement(resObj);
tempResults.put(resObj.toString(), resObj);
}

List<String> keySet = new ArrayList<>(tempResults.keySet());
Collections.sort(keySet);

for (String s : keySet) {
MethodObj obj = tempResults.get(s);
if (obj.getMethod().getName().startsWith("lambda$")) {
continue;
}
if (obj.getMethod().getName().equals("<clinit>")) {
continue;
}
allMethodsList.addElement(tempResults.get(s));
}

JarAnalyzerForm.curRes = res.getResObj();
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/chaitin/jar/analyzer/form/BytecodeForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
<properties/>
<border type="none"/>
<children>
<component id="1e3b5" class="javax.swing.JTextArea" binding="byteText">
<component id="8f9e5" class="javax.swing.JEditorPane" binding="editPanel">
<constraints/>
<properties>
<background color="-12828863"/>
<font size="16" style="0"/>
<foreground color="-13247"/>
</properties>
<properties/>
</component>
</children>
</scrollpane>
Expand Down
43 changes: 8 additions & 35 deletions src/main/java/com/chaitin/jar/analyzer/form/BytecodeForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
import com.chaitin.jar.analyzer.asm.ASMPrint;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import jsyntaxpane.syntaxkits.JavaSyntaxKit;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Locale;

public class BytecodeForm {
public JPanel parentPanel;
private JScrollPane scroll;
private JTextArea byteText;
private JEditorPane editPanel;

public BytecodeForm(String className, boolean flag) {
editPanel.setEditorKit(new JavaSyntaxKit());

className = className.replace("/", File.separator);
className = className.replace(".", File.separator);
String targetPath;
Expand All @@ -34,8 +34,8 @@ public BytecodeForm(String className, boolean flag) {
try {
InputStream is = Files.newInputStream(Paths.get(targetPath));
String data = ASMPrint.getPrint(is, flag);
byteText.setText(data);
byteText.setCaretPosition(0);
editPanel.setText(data);
editPanel.setCaretPosition(0);
} catch (Exception ignored) {
}
}
Expand All @@ -60,34 +60,8 @@ public BytecodeForm(String className, boolean flag) {
parentPanel.setBorder(BorderFactory.createTitledBorder(null, "Show Bytecode", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
scroll = new JScrollPane();
parentPanel.add(scroll, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(800, 800), null, 0, false));
byteText = new JTextArea();
byteText.setBackground(new Color(-12828863));
Font byteTextFont = this.$$$getFont$$$(null, Font.PLAIN, 16, byteText.getFont());
if (byteTextFont != null) byteText.setFont(byteTextFont);
byteText.setForeground(new Color(-13247));
scroll.setViewportView(byteText);
}

/**
* @noinspection ALL
*/
private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
if (currentFont == null) return null;
String resultName;
if (fontName == null) {
resultName = currentFont.getName();
} else {
Font testFont = new Font(fontName, Font.PLAIN, 10);
if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
resultName = fontName;
} else {
resultName = currentFont.getName();
}
}
Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac");
Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize());
return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback);
editPanel = new JEditorPane();
scroll.setViewportView(editPanel);
}

/**
Expand All @@ -96,5 +70,4 @@ public BytecodeForm(String className, boolean flag) {
public JComponent $$$getRootComponent$$$() {
return parentPanel;
}

}
38 changes: 36 additions & 2 deletions src/main/java/com/chaitin/jar/analyzer/form/JarAnalyzerForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,26 @@ private void coreClassInternal(ClassObj res) {
}

List<MethodReference> mList = methodsInClassMap.get(res.getHandle());

Map<String, MethodObj> tempResults = new LinkedHashMap<>();

for (MethodReference m : mList) {
MethodObj resObj = new MethodObj(m.getHandle(), m.getClassReference().getName());
allMethodsList.addElement(resObj);
tempResults.put(resObj.toString(), resObj);
}

List<String> keySet = new ArrayList<>(tempResults.keySet());
Collections.sort(keySet);

for (String s : keySet) {
MethodObj obj = tempResults.get(s);
if (obj.getMethod().getName().startsWith("lambda$")) {
continue;
}
if (obj.getMethod().getName().equals("<clinit>")) {
continue;
}
allMethodsList.addElement(tempResults.get(s));
}

currentLabel.setText(res.toString());
Expand Down Expand Up @@ -763,9 +780,26 @@ public void core(MouseEvent evt, JList<?> list) {
}

List<MethodReference> mList = methodsInClassMap.get(handle.getClassReference());

Map<String, MethodObj> tempResults = new LinkedHashMap<>();

for (MethodReference m : mList) {
MethodObj resObj = new MethodObj(m.getHandle(), m.getClassReference().getName());
allMethodsList.addElement(resObj);
tempResults.put(resObj.toString(), resObj);
}

List<String> keySet = new ArrayList<>(tempResults.keySet());
Collections.sort(keySet);

for (String s : keySet) {
MethodObj obj = tempResults.get(s);
if (obj.getMethod().getName().startsWith("lambda$")) {
continue;
}
if (obj.getMethod().getName().equals("<clinit>")) {
continue;
}
allMethodsList.addElement(tempResults.get(s));
}

curRes = res;
Expand Down

0 comments on commit c2e8424

Please sign in to comment.