mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Operation Change IP Format: added Little Endian format
This commit is contained in:
parent
8509af2105
commit
a61feb00d1
2 changed files with 56 additions and 2 deletions
|
@ -29,12 +29,12 @@ class ChangeIPFormat extends Operation {
|
||||||
{
|
{
|
||||||
"name": "Input format",
|
"name": "Input format",
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
|
"value": ["Dotted Decimal", "Decimal", "Decimal (Little Endian)", "Octal", "Octal (Little Endian)", "Hex"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Output format",
|
"name": "Output format",
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
|
"value": ["Dotted Decimal", "Decimal", "Decimal (Little Endian)", "Octal", "Octal (Little Endian)", "Hex"]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,15 @@ class ChangeIPFormat extends Operation {
|
||||||
case "Decimal":
|
case "Decimal":
|
||||||
baIp = this.fromNumber(lines[i].toString(), 10);
|
baIp = this.fromNumber(lines[i].toString(), 10);
|
||||||
break;
|
break;
|
||||||
|
case "Decimal (Little Endian)":
|
||||||
|
baIp = Utils.intToByteArray(parseInt(lines[i].toString(), 10), 4, "little");
|
||||||
|
break;
|
||||||
case "Octal":
|
case "Octal":
|
||||||
baIp = this.fromNumber(lines[i].toString(), 8);
|
baIp = this.fromNumber(lines[i].toString(), 8);
|
||||||
break;
|
break;
|
||||||
|
case "Octal (Little Endian)":
|
||||||
|
baIp = Utils.intToByteArray(parseInt(lines[i].toString(), 8), 4, "little");
|
||||||
|
break;
|
||||||
case "Hex":
|
case "Hex":
|
||||||
baIp = fromHex(lines[i]);
|
baIp = fromHex(lines[i]);
|
||||||
break;
|
break;
|
||||||
|
@ -98,10 +104,18 @@ class ChangeIPFormat extends Operation {
|
||||||
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
||||||
output += decIp.toString() + "\n";
|
output += decIp.toString() + "\n";
|
||||||
break;
|
break;
|
||||||
|
case "Decimal (Little Endian)":
|
||||||
|
decIp = Utils.byteArrayToInt(baIp, "little");
|
||||||
|
output += decIp.toString() + "\n";
|
||||||
|
break;
|
||||||
case "Octal":
|
case "Octal":
|
||||||
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
|
||||||
output += "0" + decIp.toString(8) + "\n";
|
output += "0" + decIp.toString(8) + "\n";
|
||||||
break;
|
break;
|
||||||
|
case "Octal (Little Endian)":
|
||||||
|
decIp = Utils.byteArrayToInt(baIp, "little");
|
||||||
|
output += "0" + decIp.toString(8) + "\n";
|
||||||
|
break;
|
||||||
case "Hex":
|
case "Hex":
|
||||||
hexIp = "";
|
hexIp = "";
|
||||||
for (j = 0; j < baIp.length; j++) {
|
for (j = 0; j < baIp.length; j++) {
|
||||||
|
|
|
@ -48,5 +48,45 @@ TestRegister.addTests([
|
||||||
args: ["Octal", "Decimal"],
|
args: ["Octal", "Decimal"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
}, {
|
||||||
|
name: "Change IP format: Decimal (Little Endian) to Dotted Decimal",
|
||||||
|
input: "16885952",
|
||||||
|
expectedOutput: "192.168.1.1",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Change IP format",
|
||||||
|
args: ["Decimal (Little Endian)", "Dotted Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
name: "Change IP format: Dotted Decimal to Decimal (Little Endian)",
|
||||||
|
input: "192.168.1.1",
|
||||||
|
expectedOutput: "16885952",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Change IP format",
|
||||||
|
args: ["Dotted Decimal", "Decimal (Little Endian)"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
name: "Change IP format: Octal (Little Endian) to Dotted Decimal",
|
||||||
|
input: "0100324300",
|
||||||
|
expectedOutput: "192.168.1.1",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Change IP format",
|
||||||
|
args: ["Octal (Little Endian)", "Dotted Decimal"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
name: "Change IP format: Dotted Decimal to Octal (Little Endian)",
|
||||||
|
input: "192.168.1.1",
|
||||||
|
expectedOutput: "0100324300",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Change IP format",
|
||||||
|
args: ["Dotted Decimal", "Octal (Little Endian)"],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue