Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Extension resource loading

Mehrdad 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?


Mehrdad 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();
}

Paul Johnston Sep 13, 2017 11:34AM UTC Support Center agent

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:

    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.


Post Your public answer

Your name
Your email address
Answer