Skip to content

Commit

Permalink
Refactor Substring Operation
Browse files Browse the repository at this point in the history
  • Loading branch information
felixb1515 committed Dec 13, 2024
1 parent a209bc6 commit c64ef1d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main/java/de/usd/cstchef/operations/string/Substring.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.usd.cstchef.operations.string;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import org.bouncycastle.util.Arrays;

Expand All @@ -23,23 +24,21 @@ protected ByteArray perform(ByteArray input, MessageType messageType) throws Exc
int start = (int) startSpinner.getValue();
int end = (int) endSpinner.getValue();

if( start < 0 )
start = input.length() + start;
if( end < 0 )
end = input.length() + end;
if( end > input.length() )
end = input.length() + 1;
if(input.length() + start < 0) throw new IllegalArgumentException("Start index out of bounds for input length " + input.length() + ".");
if(end > input.length()) throw new IllegalArgumentException("End index out of bounds for input length " + input.length() + ".");

ByteArray slice = BurpUtils.subArray(input, start, end);
return slice;
}

@Override
public void createUI() {
this.startSpinner = new JSpinner();
SpinnerNumberModel startIndexModel = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1);
this.startSpinner = new JSpinner(startIndexModel);
this.addUIElement("Start", this.startSpinner);

this.endSpinner = new JSpinner();
SpinnerNumberModel endIndexModel = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1);
this.endSpinner = new JSpinner(endIndexModel);
this.addUIElement("End", this.endSpinner);
}

Expand Down

0 comments on commit c64ef1d

Please sign in to comment.