|
@@ -1,9 +1,12 @@
|
|
|
package de.tudarmstadt.informatik.hostage.wrapper;
|
|
|
|
|
|
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
|
+
|
|
|
/**
|
|
|
* Wrapper class for the payload of a network packet.
|
|
|
*
|
|
|
* @author Mihai Plasoianu
|
|
|
+ * @author Wulf Pfeiffer
|
|
|
*/
|
|
|
public class Packet {
|
|
|
|
|
@@ -40,20 +43,22 @@ public class Packet {
|
|
|
|
|
|
/**
|
|
|
* Returns a String representation of the payload.
|
|
|
+ * If the payload contains a ASCII character the whole
|
|
|
+ * String will be represented as a String of a byte values.
|
|
|
+ * E.g.: the byte[] {0x01, 0x4A, 0x03} would look like
|
|
|
+ * the String "01, 4A, 03".
|
|
|
+ * Otherwise a normal String will be created with the payload.
|
|
|
*
|
|
|
* @return String representation.
|
|
|
*/
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
- StringBuilder builder = new StringBuilder(payload.length);
|
|
|
for (int i = 0; i < payload.length; ++i) {
|
|
|
- if (payload[i] < 10) {
|
|
|
- builder.append("{0x").append(payload[i]).append("}");
|
|
|
- } else {
|
|
|
- builder.append(Character.toString((char) payload[i]));
|
|
|
+ if (((char) payload[i]) < 9) {
|
|
|
+ return HelperUtils.bytesToHexString(payload);
|
|
|
}
|
|
|
}
|
|
|
- return builder.toString();
|
|
|
+ return new String(payload);
|
|
|
}
|
|
|
|
|
|
}
|