A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.
Java application-securityappsecbug-bountyburp-alternativeburp-suitedasthttp-proxyinfosecintercepting-proxyjavaowaspowasp-zappenetration-testingpentestingsecuritysecurity-toolsvulnerability-scannerweb-application-securityweb-security
package opensuite.ui;
import javax.swing.*;
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
import java.awt.*;
/**
* A line-number gutter for a text component, used as a scroll pane's row
* header. Numbers follow the document's paragraph elements, so wrapped lines
* keep one number and the gutter stays right when text is edited.
*/
public final class LineGutter extends JComponent {
/** The reference's line-number grey. */
private static final Color GUTTER_TEXT = Theme.dark ? new Color(0x8A, 0x8A, 0x8A) : new Color(0x78, 0x78, 0x78);
/** The rule between the numbers and the text. */
private static final Color RULE = Theme.dark ? new Color(0x4A, 0x4A, 0x4A) : new Color(0xDD, 0xDD, 0xDD);
private final JTextComponent text;
public LineGutter(JTextComponent text) {
this.text = text;
setFont(Ui.MONO);
setOpaque(true);
setBackground(Theme.CONTENT);
text.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {
public void insertUpdate(javax.swing.event.DocumentEvent e) { revalidate(); repaint(); }
public void removeUpdate(javax.swing.event.DocumentEvent e) { revalidate(); repaint(); }
public void changedUpdate(javax.swing.event.DocumentEvent e) { repaint(); }
});
text.addPropertyChangeListener("font", e -> { setFont(text.getFont()); revalidate(); repaint(); });
text.addPropertyChangeListener("document", e -> {
((javax.swing.text.Document) e.getNewValue()).addDocumentListener(new javax.swing.event.DocumentListener() {
public void insertUpdate(javax.swing.event.DocumentEvent ev) { revalidate(); repaint(); }
public void removeUpdate(javax.swing.event.DocumentEvent ev) { revalidate(); repaint(); }
public void changedUpdate(javax.swing.event.DocumentEvent ev) { repaint(); }
});
revalidate(); repaint();
});
}
private int lines() {
return text.getDocument().getDefaultRootElement().getElementCount();
}
/** The number each line carries, 0 for none; null to count every line. */
private int[] numbers;
/**
* Number the lines by a source they were laid out from: entry {@code i} is
* the number line {@code i} shows, or 0 for a line that continues the one
* above. Null, or a list that no longer fits the text, counts every line.
*/
public void setNumbers(int[] numbers) {
this.numbers = numbers;
revalidate();
repaint();
}
private int highest() {
int n = lines();
if (numbers == null || numbers.length != n) return n;
int top = 1;
for (int v : numbers) top = Math.max(top, v);
return top;
}
@Override public Dimension getPreferredSize() {
FontMetrics fm = getFontMetrics(getFont());
int digits = Math.max(2, String.valueOf(highest()).length());
// Two digits of room at least, then 7px that end in the rule.
return new Dimension(fm.charWidth('0') * digits + 7, text.getPreferredSize().height);
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setColor(getBackground());
g2.fillRect(0, 0, getWidth(), getHeight());
// An empty message that cannot be typed into shows nothing at all: no
// rule, no line "1". One that can shows its first line, ready for text.
if (text.getDocument().getLength() == 0 && !text.isEditable()) { g2.dispose(); return; }
g2.setColor(RULE);
g2.fillRect(getWidth() - 1, 0, 1, getHeight());
opensuite.ui.Theme.textSmoothing(g2);
g2.setFont(getFont());
g2.setColor(GUTTER_TEXT);
FontMetrics fm = g2.getFontMetrics();
Element root = text.getDocument().getDefaultRootElement();
Rectangle clip = g2.getClipBounds();
int n = root.getElementCount();
int[] shown = numbers != null && numbers.length == n ? numbers : null;
for (int i = 0; i < n; i++) {
if (shown != null && shown[i] == 0) continue;
try {
java.awt.geom.Rectangle2D r = text.modelToView2D(root.getElement(i).getStartOffset());
if (r == null) continue;
int y = (int) r.getY(), h = (int) r.getHeight();
if (y + h < clip.y) continue;
if (y > clip.y + clip.height) break;
String s = String.valueOf(shown != null ? shown[i] : i + 1);
g2.drawString(s, getWidth() - 5 - fm.stringWidth(s), y + fm.getAscent());
} catch (javax.swing.text.BadLocationException ignore) { }
}
g2.dispose();
}
}