Burp Suite User Forum

Create new post

Highlighting in IMessageEditor

Eddie | Last updated: Jan 02, 2019 04:33PM UTC

Hello, I am trying to create an extension in which you can highlight single or multiple lines of text in the request or response tabs. I am having an issue when you add a “Graphic” to the IMessageEditor text area that it disappears when it is either selected or you highlight a new line of text. Highlight Method: /* * Graphics g: Takes components graphics object. * IMessageEditor req: Request Text Area * IMessageEditor res: Response Text Area * String text: Selected line to highlight * Int x,y,width,height: Dimensions */ public Graphics highlight(Graphics g, IMessageEditor req, IMessageEditor res, String text, int x, int y, int width, int height) { Graphics2D gr = (Graphics2D) g; FontRenderContext context = gr.getFontRenderContext(); Font font = gr.getFont(); int textWidth = (int) font.getStringBounds(text, context).getWidth(); LineMetrics ln = font.getLineMetrics(text, context); int textHeight = (int)(ln.getAscent() + ln.getDescent()); int x1 = x + (width - textWidth)/2; int y1 = (int)(y + (height + textHeight)/2 - ln.getDescent()); gr.setComposite(alphaComp); gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gr.setColor(Color.YELLOW); gr.setBackground(Color.YELLOW); gr.fillRect(x, y, width, height); return g; } I am accessing the text area component with the following methods: IMessageEditor requestViewer = messageEditor.getRequestViewer(); JTabbedPane requestViewerPane = (JTabbedPane) requestViewer.getComponent(); //Request Tab JPanel jCompPanel = (JPanel) requestViewerPane.getComponent(0); //Get Request’s Raw Tab JComponent jComp2 = (JComponent) jCompPanel.getComponent(1); //Get Layout JComponent txtArea = (JComponent) jComp2.getComponent(0); //Request text area Highlight Call: highlightUtils.highlight(txtArea.getGraphics(), requestViewer, responseViewer, "Cookie: 12345", e.getX(), e.getY(), strw, strh); How would I got about fixing this issue and is there a better way to implement this type of highlighting?

PortSwigger Agent | Last updated: Jan 03, 2019 07:57AM UTC

Unfortunately, the approach you've taken of drawing on the graphics object won't survive repaint events, and dealing with that is not straightforward. One way to deal with this is to create a custom IMessageEditorTab. You can use a JTextComponent within this, which has support for highlighting. However, the component lacks some of the nice features of Burp's ITextEditor. It may be possible to hook the repaint events on ITextEditor and redraw your highlight as required. Unfortunately, there isn't a public API for this, so anything you figure out will be a bit of a hack.

You must be an existing, logged-in customer to reply to a thread. Please email us for additional support.