Skip to content

Commit c729242

Browse files
committed
Adding support for loading scripts from file
1 parent c8252ae commit c729242

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

gui.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from javax.swing import JTabbedPane, JPanel, JButton, JLabel, SwingConstants, BorderFactory, JOptionPane, GroupLayout, JCheckBox, JSplitPane, JRadioButton, ButtonGroup, JFileChooser
1+
from javax.swing import JTabbedPane, JPanel, JButton, JLabel, SwingConstants, JOptionPane, GroupLayout, JCheckBox, JSplitPane, JRadioButton, ButtonGroup, JFileChooser
22
from javax.swing.event import ChangeListener, DocumentListener
33
from javax.swing.LayoutStyle.ComponentPlacement import RELATED, UNRELATED
4-
from java.awt import BorderLayout, Font, Component, Color
4+
from java.awt import BorderLayout, Font, Component
55
from java.beans import PropertyChangeListener
66
from org.python.core.util import StringUtil
77
from burp import IExtensionStateListener
@@ -119,6 +119,7 @@ def __init__(self, callbacks, script):
119119
self.scriptEditor = callbacks.createTextEditor()
120120
self.scriptEditor.text = script.content
121121
self.scriptText = self.scriptEditor.component
122+
self.loadButton = JButton('Load', actionPerformed=self.load)
122123
self.compileButton = JButton('Compile', actionPerformed=self.compile, enabled=False)
123124

124125
editingLayout = GroupLayout(self, autoCreateGaps=True, autoCreateContainerGaps=True)
@@ -129,7 +130,10 @@ def __init__(self, callbacks, script):
129130
)
130131
.addGroup(editingLayout.createParallelGroup()
131132
.addComponent(self.scriptText)
132-
.addComponent(self.compileButton)
133+
)
134+
.addGroup(editingLayout.createSequentialGroup()
135+
.addComponent(self.loadButton)
136+
.addComponent(self.compileButton)
133137
)
134138
)
135139

@@ -138,8 +142,11 @@ def __init__(self, callbacks, script):
138142
.addComponent(self.enabledCheckbox)
139143
)
140144
.addGroup(editingLayout.createSequentialGroup()
141-
.addComponent(self.scriptText)
142-
.addComponent(self.compileButton)
145+
.addComponent(self.scriptText)
146+
)
147+
.addGroup(editingLayout.createParallelGroup()
148+
.addComponent(self.loadButton)
149+
.addComponent(self.compileButton)
143150
)
144151
)
145152
self.layout = editingLayout
@@ -149,6 +156,13 @@ def __init__(self, callbacks, script):
149156
def enabled_changed(self, event):
150157
self.script.enabled = self.enabledCheckbox.isSelected()
151158

159+
def load(self, event):
160+
file_chooser = JFileChooser()
161+
choice = file_chooser.showOpenDialog(None)
162+
if choice == JFileChooser.APPROVE_OPTION:
163+
with open(file_chooser.selectedFile.path, 'r') as input_file:
164+
self.scriptEditor.text = ''.join(input_file.readlines())
165+
152166
def compile(self, event):
153167
self.script.compile()
154168
self.compileButton.enabled = False

0 commit comments

Comments
 (0)