Burp Suite User Forum

Create new post

Extension resource loading

Mehrdad | Last updated: Sep 10, 2017 04:35AM UTC

I've embedded some static files inside the extension, in the folder named `assets`. Trying to access them fails, using following code: InputStream in = DataUtils.class.getClassLoader().getResourceAsStream("/assets/" + filename); Maybe it fails because "/" refers to root of `burp.jar`, not my `ext.jar`. How can I access the assets?

Burp User | Last updated: Sep 12, 2017 04:16AM UTC

This code works for me, assuming assets are not loaded in classpath: public static String readAsset(String filename) throws IOException { URL url = new URL("jar:file:/"+BurpExtender.getInstance().getCallbacks().getExtensionFilename()+"!/assets/"+ filename); InputStream in = url.openStream(); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, StandardCharsets.UTF_8); return writer.toString(); }

PortSwigger Agent | Last updated: Sep 13, 2017 10:54AM UTC

Hi Mehrdad, Thanks for your message. I presume DataUtils is within your extension? DataUtils.class.getClassLoader should return the loader for your extension. You can check this with: bc. URLClassLoader ucl = (URLClassLoader) DataUtils.class.getClassLoader(); for(URL url : ucl.getURLs()) { callbacks.printOutput(url.toString()); } I just did some testing, and I think you need to remove the leading / from your file name. Also, use "jar -tf" to double check your assets location within your jar file. Please let us know if you need any further assistance.

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