From c64ef1d70b78894949acb44777c8bf337ad207f1 Mon Sep 17 00:00:00 2001 From: Felix Buschbeck Date: Fri, 13 Dec 2024 15:59:56 +0100 Subject: [PATCH] Refactor Substring Operation --- .../usd/cstchef/operations/string/Substring.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/usd/cstchef/operations/string/Substring.java b/src/main/java/de/usd/cstchef/operations/string/Substring.java index 49bccd6..92c9ca8 100644 --- a/src/main/java/de/usd/cstchef/operations/string/Substring.java +++ b/src/main/java/de/usd/cstchef/operations/string/Substring.java @@ -1,6 +1,7 @@ package de.usd.cstchef.operations.string; import javax.swing.JSpinner; +import javax.swing.SpinnerNumberModel; import org.bouncycastle.util.Arrays; @@ -23,12 +24,8 @@ 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; @@ -36,10 +33,12 @@ protected ByteArray perform(ByteArray input, MessageType messageType) throws Exc @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); }