mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Add output field to Parse IPv4 Header
This commit is contained in:
parent
bab366e699
commit
cdaefe9f6e
1 changed files with 23 additions and 6 deletions
|
@ -33,6 +33,12 @@ class ParseIPv4Header extends Operation {
|
|||
"name": "Input format",
|
||||
"type": "option",
|
||||
"value": ["Hex", "Raw"]
|
||||
},
|
||||
{
|
||||
"name": "Output format",
|
||||
"type": "option",
|
||||
"value": ["Table", "Data (hex)", "Data (raw)"],
|
||||
defaultIndex: 0,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -44,6 +50,8 @@ class ParseIPv4Header extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
const format = args[0];
|
||||
const outputFormat = args[1];
|
||||
|
||||
let output;
|
||||
|
||||
if (format === "Hex") {
|
||||
|
@ -98,6 +106,9 @@ class ParseIPv4Header extends Operation {
|
|||
checksumResult = givenChecksum + " (incorrect, should be " + correctChecksum + ")";
|
||||
}
|
||||
|
||||
const data = input.slice(ihl * 4);
|
||||
|
||||
if (outputFormat == "Table") {
|
||||
output = `<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Field</th><th>Value</th></tr>
|
||||
<tr><td>Version</td><td>${version}</td></tr>
|
||||
<tr><td>Internet Header Length (IHL)</td><td>${ihl} (${ihl * 4} bytes)</td></tr>
|
||||
|
@ -116,13 +127,19 @@ class ParseIPv4Header extends Operation {
|
|||
<tr><td>Protocol</td><td>${protocol}, ${protocolInfo.protocol} (${protocolInfo.keyword})</td></tr>
|
||||
<tr><td>Header checksum</td><td>${checksumResult}</td></tr>
|
||||
<tr><td>Source IP address</td><td>${ipv4ToStr(srcIP)}</td></tr>
|
||||
<tr><td>Destination IP address</td><td>${ipv4ToStr(dstIP)}</td></tr>`;
|
||||
<tr><td>Destination IP address</td><td>${ipv4ToStr(dstIP)}</td></tr>
|
||||
<tr><td>Data (hex)</td><td>${toHex(data)}</td></tr>`;
|
||||
|
||||
if (ihl > 5) {
|
||||
output += `<tr><td>Options</td><td>${toHex(options)}</td></tr>`;
|
||||
}
|
||||
|
||||
return output + "</table>";
|
||||
} else if (outputFormat === "Data (hex)") {
|
||||
return toHex(data);
|
||||
} else if (outputFormat == "Data (raw)") {
|
||||
return Utils.byteArrayToChars(data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue