Skip to content

Commit

Permalink
Merge pull request hackvertor#109 from CoreyD97/master
Browse files Browse the repository at this point in the history
Performance improvements and bugfixes.
  • Loading branch information
hackvertor authored Jan 4, 2024
2 parents d99d356 + e0a6ae6 commit 7aa3862
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 2,791 deletions.
23 changes: 16 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
apply plugin: 'java'
plugins {
id 'java'
id "org.javacc.javacc" version "3.0.2"
}

targetCompatibility = 1.8
sourceCompatibility = 1.8
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_17

compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
Expand Down Expand Up @@ -37,14 +40,16 @@ dependencies {
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'src'
srcDir compileJavacc.outputDirectory
}
}
}

compileJavacc {
inputDirectory = file('src/main/javacc')
include '**/*.java'
}

jar{
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archivesBaseName = project.name + '-all'
Expand All @@ -60,4 +65,8 @@ jar{

tasks.withType(Jar) {
destinationDirectory = file("$rootDir/releases/")
}

test {
useJUnitPlatform()
}
37 changes: 1 addition & 36 deletions hackvertor.iml
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
<orderEntry type="library" name="Maven: org.unbescape:unbescape:1.1.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: net.portswigger.burp.extender:burp-extender-api:1.7.22" level="project" />
<orderEntry type="library" name="Maven: org.bouncycastle:bcpkix-jdk15on:1.60" level="project" />
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.60" level="project" />
<orderEntry type="library" name="Maven: com.auth0:java-jwt:3.4.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" />
<orderEntry type="library" name="Maven: org.brotli:dec:0.1.2" level="project" />
<orderEntry type="library" name="Maven: org.python:jython-standalone:2.7.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.20" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.4.20" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.20" level="project" />
</component>
</module>
5 changes: 5 additions & 0 deletions src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -1733,4 +1733,9 @@ public void alert(String msg) {
public Component getUiComponent() {
return extensionPanel;
}

//Used in tests
public static void setHelpers(IExtensionHelpers helpers) {
BurpExtender.helpers = helpers;
}
}
49 changes: 27 additions & 22 deletions src/main/java/burp/Convertors.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static String callTag(HashMap<String, String> variableMap, JSONArray cust
tagCount.put(tag, count + 1);
}
for(int i=0;i<arguments.size();i++) {
arguments.set(i, convert(variableMap, customTags, arguments.get(i)));
arguments.set(i, weakConvert(variableMap, customTags, arguments.get(i), hackvertor));
}

switch (tag) {
Expand Down Expand Up @@ -635,11 +635,11 @@ public static String[] generateTagStartEnd(Tag tagObj) {
* Recursive conversion, ensuring tags are properly matched.
* Does not treat mismatched tags as text.
*/
public static String convert(HashMap<String, String> variables, JSONArray customTags, String input){
public static String strictConvert(HashMap<String, String> variables, JSONArray customTags, String input, Hackvertor hackvertor){
Queue<Element> tagElements;
try {
tagElements = HackvertorParser.parse(input);
return convert(variables, customTags, "", new Stack<>(), tagElements);
return strictConvert(variables, customTags, "", new Stack<>(), tagElements, hackvertor);
}catch (Exception e){
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
Expand All @@ -654,7 +654,7 @@ public static String weakConvert(HashMap<String, String> variables, JSONArray cu
Queue<Element> tagElements;
try {
tagElements = HackvertorParser.parse(input);
tagElements = weakConvertProcessSetTags(variables, customTags, tagElements);
tagElements = weakConvertPreProcessSetTags(variables, customTags, tagElements);
return weakConvert(variables, customTags, new Stack<>(), tagElements, hackvertor);
}catch (Exception e){
StringWriter sw = new StringWriter();
Expand All @@ -665,7 +665,7 @@ public static String weakConvert(HashMap<String, String> variables, JSONArray cu

/**
* Recursive conversion, ensuring tags are properly matched.
* Does not treat mismatched tags as text.
* Does not treat mismatched tags as text. Will throw an error instead.
* @param variables
* @param customTags
* @param textBuffer
Expand All @@ -674,11 +674,11 @@ public static String weakConvert(HashMap<String, String> variables, JSONArray cu
* @return
* @throws ParseException
*/
private static String convert(HashMap<String, String> variables,
JSONArray customTags,
String textBuffer,
Stack<Element.StartTag> stack,
Queue<Element> elements) throws ParseException{
private static String strictConvert(HashMap<String, String> variables,
JSONArray customTags,
String textBuffer,
Stack<Element.StartTag> stack,
Queue<Element> elements, Hackvertor hackvertor) throws ParseException{
if(elements.size() == 0) {
if(stack.size() > 0){
String error = String.format("Unclosed tag%s - %s",stack.size()>1?"s":"",
Expand All @@ -694,11 +694,11 @@ private static String convert(HashMap<String, String> variables,
textBuffer+= ((Element.TextElement) element).getContent();
}else if(element instanceof Element.SelfClosingTag){ //Self closing tag. Just add its output to textbuffer.
Element.SelfClosingTag selfClosingTag = (Element.SelfClosingTag) element;
String tagOutput = callTag(variables, customTags, selfClosingTag.getIdentifier(), "", selfClosingTag.getArguments(), null);
String tagOutput = callTag(variables, customTags, selfClosingTag.getIdentifier(), "", selfClosingTag.getArguments(), hackvertor);
textBuffer+= tagOutput;
}else if(element instanceof Element.StartTag){ //Start of a conversion.
stack.push((Element.StartTag) element);
textBuffer+= convert(variables, customTags, "", stack, elements);
textBuffer+= strictConvert(variables, customTags, "", stack, elements, hackvertor);
}else if(element instanceof Element.EndTag){ //End of a conversion. Convert and update textbuffer.
Element.StartTag startTag;
Element.EndTag endTag = (Element.EndTag) element;
Expand All @@ -711,15 +711,23 @@ private static String convert(HashMap<String, String> variables,
throw new ParseException(String.format("Mismatched opening and closing tags, %s and %s.",
startTag.getIdentifier(), endTag.getIdentifier()));
}
return callTag(variables, customTags, startTag.getIdentifier(), textBuffer, startTag.getArguments(), null);
return callTag(variables, customTags, startTag.getIdentifier(), textBuffer, startTag.getArguments(), hackvertor);
}

return convert(variables, customTags, textBuffer, stack, elements);
return strictConvert(variables, customTags, textBuffer, stack, elements, hackvertor);
}

private static Queue<Element> weakConvertProcessSetTags(HashMap<String, String> variables,
JSONArray customTags,
Queue<Element> elements) throws ParseException{
/**
* Process all variable setting tags in a list of tokens, and update the variables map with their values
* @param variables The map of variables and their values
* @param customTags Any custom tags to be processed
* @param elements A list of lexical tokens
* @return
* @throws ParseException
*/
private static Queue<Element> weakConvertPreProcessSetTags(HashMap<String, String> variables,
JSONArray customTags,
Queue<Element> elements) throws ParseException{
Queue<Element> elementQueue = new LinkedList<>();
Iterator<Element> iter = elements.iterator();
while(iter.hasNext()) {
Expand Down Expand Up @@ -2611,13 +2619,10 @@ static String substring(String str, int start, int end) {
}

static String repeat(String str, int amount) {
String output = "";
if (amount > 0 && amount < 10000) {
for (int i = 0; i < amount; i++) {
output += str;
}
return str.repeat(amount);
}
return output;
return "";
}

static String split_join(String str, String splitChar, String joinChar) {
Expand Down
Loading

0 comments on commit 7aa3862

Please sign in to comment.