This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Enaium/develop
Develop
- Loading branch information
Showing
19 changed files
with
672 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/cn/enaium/joe/dialog/search/SearchLdcDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2022 Enaium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.enaium.joe.dialog.search; | ||
|
||
import cn.enaium.joe.JavaOctetEditor; | ||
import cn.enaium.joe.dialog.SearchDialog; | ||
import cn.enaium.joe.gui.panel.search.ResultNode; | ||
import cn.enaium.joe.jar.Jar; | ||
import cn.enaium.joe.util.ASyncUtil; | ||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.LdcInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Enaium | ||
*/ | ||
public class SearchLdcDialog extends SearchDialog { | ||
public SearchLdcDialog() { | ||
setTitle("Search LDC"); | ||
add(new JPanel(new FlowLayout()) {{ | ||
JTextField text = new JTextField(15); | ||
add(text); | ||
add(new JButton("Search") {{ | ||
addActionListener(e -> { | ||
if (!text.getText().replace(" ", "").isEmpty()) { | ||
Jar jar = JavaOctetEditor.getInstance().jar; | ||
ASyncUtil.execute(() -> { | ||
float loaded = 0; | ||
float total = 0; | ||
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) { | ||
for (MethodNode method : stringClassNodeEntry.getValue().methods) { | ||
total += method.instructions.size(); | ||
} | ||
} | ||
|
||
for (Map.Entry<String, ClassNode> stringClassNodeEntry : jar.classes.entrySet()) { | ||
for (MethodNode method : stringClassNodeEntry.getValue().methods) { | ||
|
||
for (AbstractInsnNode instruction : method.instructions) { | ||
if (instruction instanceof LdcInsnNode) { | ||
String ldc = ((LdcInsnNode) instruction).cst.toString(); | ||
if (ldc.contains(text.getText())) { | ||
((DefaultListModel<ResultNode>) result.getList().getModel()).addElement(new ResultNode(stringClassNodeEntry.getValue(), ldc)); | ||
} | ||
} | ||
JavaOctetEditor.getInstance().bottomPanel.setProcess((int) ((loaded++ / total) * 100f)); | ||
} | ||
} | ||
} | ||
JavaOctetEditor.getInstance().bottomPanel.setProcess(0); | ||
}); | ||
} | ||
}); | ||
}}); | ||
}}, BorderLayout.SOUTH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2022 Enaium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.enaium.joe.gui.panel; | ||
|
||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; | ||
import org.fife.ui.rsyntaxtextarea.Theme; | ||
import org.fife.ui.rtextarea.RTextScrollPane; | ||
import org.fife.ui.rtextarea.SearchContext; | ||
import org.fife.ui.rtextarea.SearchEngine; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author Enaium | ||
*/ | ||
public class CodeAreaPanel extends JPanel implements ActionListener { | ||
|
||
private RSyntaxTextArea textArea; | ||
private JTextField searchField; | ||
private JCheckBox regexCB; | ||
private JCheckBox matchCaseCB; | ||
|
||
public CodeAreaPanel() { | ||
super(new BorderLayout()); | ||
textArea = new RSyntaxTextArea(); | ||
textArea.setCodeFoldingEnabled(true); | ||
textArea.setEditable(false); | ||
Theme theme = null; | ||
try { | ||
theme = Theme.load(getClass().getResourceAsStream("/org/fife/ui/rsyntaxtextarea/themes/dark.xml")); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
theme.apply(textArea); | ||
|
||
add(new RTextScrollPane(textArea), BorderLayout.CENTER); | ||
JToolBar toolBar = new JToolBar(); | ||
searchField = new JTextField(30); | ||
toolBar.add(searchField); | ||
final JButton nextButton = new JButton("Find Next"); | ||
nextButton.setActionCommand("FindNext"); | ||
nextButton.addActionListener(this); | ||
toolBar.add(nextButton); | ||
searchField.addActionListener(e -> nextButton.doClick(0)); | ||
JButton prevButton = new JButton("Find Previous"); | ||
prevButton.setActionCommand("FindPrev"); | ||
prevButton.addActionListener(this); | ||
toolBar.add(prevButton); | ||
regexCB = new JCheckBox("Regex"); | ||
toolBar.add(regexCB); | ||
matchCaseCB = new JCheckBox("Match Case"); | ||
toolBar.add(matchCaseCB); | ||
add(toolBar, BorderLayout.NORTH); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
|
||
// "FindNext" => search forward, "FindPrev" => search backward | ||
String command = e.getActionCommand(); | ||
boolean forward = "FindNext".equals(command); | ||
|
||
// Create an object defining our search parameters. | ||
SearchContext context = new SearchContext(); | ||
String text = searchField.getText(); | ||
if (text.length() == 0) { | ||
return; | ||
} | ||
context.setSearchFor(text); | ||
context.setMatchCase(matchCaseCB.isSelected()); | ||
context.setRegularExpression(regexCB.isSelected()); | ||
context.setSearchForward(forward); | ||
context.setWholeWord(false); | ||
|
||
SearchEngine.find(textArea, context); | ||
} | ||
|
||
public RSyntaxTextArea getTextArea() { | ||
return textArea; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.