Skip to content

Commit

Permalink
quick search in decompiler panel
Browse files Browse the repository at this point in the history
  • Loading branch information
GraxCode committed Sep 28, 2020
1 parent 30be3fe commit 47ede49
Showing 1 changed file with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -37,24 +39,18 @@

public class DecompilerPanel extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;

private DecompilerTextArea textArea;

private int searchIndex = -1;
private String lastSearchText = null;

private static int preferredDecompilerIndex = 0;
private final AnalysisFrame analysisFrame;
public File archive;
public Clazz clazz;

private final JComboBox<DecompilerInfo> decompilerSelection;
private final JComboBox<DecompilerInfo<?>> decompilerSelection;
private final JComboBox<String> conversionMethod;
private final JCheckBox ignoreTCB;
private final JCheckBox ignoreMon;
private final JCheckBox aggressive;

private static int preferredDecompilerIndex = 0;
private IDecompilerBridge decompilerBridge;
public File archive;
public Clazz clazz;
private DecompilerTextArea textArea;
private int searchIndex = -1;
private String lastSearchText = null;

public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) {
this.analysisFrame = analysisFrame;
Expand All @@ -64,7 +60,7 @@ public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) {
this.setLayout(new BorderLayout(4, 4));
JPanel leftActionPanel = new JPanel();
leftActionPanel.setLayout(new GridBagLayout());
decompilerSelection = new JComboBox<>(DecompilerInfo.getDecompilerInfos().toArray(new DecompilerInfo[0]));
decompilerSelection = new JComboBox<DecompilerInfo<?>>(DecompilerInfo.getDecompilerInfos().toArray(new DecompilerInfo[0]));
decompilerSelection.setSelectedIndex(preferredDecompilerIndex);
decompilerSelection.addActionListener(this);
leftActionPanel.add(decompilerSelection);
Expand All @@ -86,6 +82,7 @@ public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) {
ReloadButton reload = new ReloadButton();
reload.addActionListener(this);
SearchTextField search = new SearchTextField();

search.putClientProperty(DarkTextUI.KEY_DEFAULT_TEXT, "Search for text or regex");
search.setPreferredSize(new Dimension(200, reload.getPreferredSize().height));
search.addSearchListener(l -> {
Expand Down Expand Up @@ -145,6 +142,20 @@ public DecompilerPanel(AnalysisFrame analysisFrame, File archive, Clazz cn) {
this.add(topPanel, BorderLayout.NORTH);
Threadtear.getInstance().statusBar.runWithLoadIndicator("Decompiling class file... ", () -> {
this.textArea = new DecompilerTextArea();
this.textArea.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0)
if (e.getKeyCode() == KeyEvent.VK_F) {
search.requestFocusInWindow();
String text = textArea.getSelectedText();
if (text != null && !text.trim().isEmpty()) {
search.setText(text);
search.postActionEvent();
}
}
}
});
this.update();
this.add(SwingUtils.withBorder(
SwingUtils.wrap(SwingUtils.createRSyntaxOverlayScrollPane(textArea)),
Expand Down Expand Up @@ -195,7 +206,7 @@ public void update() {
.forEach(i -> m.instructions.set(i, new InsnNode(POP))));
}
bytes = Conversion.toBytecode0(copy);
decompilerBridge = decompilerSelection.getModel()
IDecompilerBridge decompilerBridge = decompilerSelection.getModel()
.getElementAt(decompilerSelection.getSelectedIndex())
.createDecompilerBridge();
preferredDecompilerIndex = decompilerSelection.getSelectedIndex();
Expand Down

0 comments on commit 47ede49

Please sign in to comment.