Skip to content

Commit

Permalink
Merge branch 'master' into theme-auto-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
a3957273 authored Feb 12, 2025
2 parents bce0460 + 13f94a2 commit feaf3dd
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 38 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"chromedriver": "^130.0.0",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^12.0.2",
"core-js": "^3.37.1",
"css-loader": "7.1.2",
Expand Down
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"Parse IP range",
"Parse IPv6 address",
"Parse IPv4 header",
"Strip IPv4 header",
"Parse TCP",
"Strip TCP header",
"Parse TLS record",
Expand Down
11 changes: 9 additions & 2 deletions src/core/operations/AddLineNumbers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ class AddLineNumbers extends Operation {
this.description = "Adds line numbers to the output.";
this.inputType = "string";
this.outputType = "string";
this.args = [];
this.args = [
{
"name": "Offset",
"type": "number",
"value": 0
}
];
}

/**
Expand All @@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
run(input, args) {
const lines = input.split("\n"),
width = lines.length.toString().length;
const offset = args[0] ? parseInt(args[0], 10) : 0;
let output = "";

for (let n = 0; n < lines.length; n++) {
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n";
output += (n+1+offset).toString().padStart(width, " ") + " " + lines[n] + "\n";
}
return output.slice(0, output.length-1);
}
Expand Down
57 changes: 57 additions & 0 deletions src/core/operations/StripIPv4Header.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import Stream from "../lib/Stream.mjs";

/**
* Strip IPv4 header operation
*/
class StripIPv4Header extends Operation {

/**
* StripIPv4Header constructor
*/
constructor() {
super();

this.name = "Strip IPv4 header";
this.module = "Default";
this.description = "Strips the IPv4 header from an IPv4 packet, outputting the payload.";
this.infoURL = "https://wikipedia.org/wiki/IPv4";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [];
}

/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const MIN_HEADER_LEN = 20;

const s = new Stream(new Uint8Array(input));
if (s.length < MIN_HEADER_LEN) {
throw new OperationError("Input length is less than minimum IPv4 header length");
}

const ihl = s.readInt(1) & 0x0f;
const dataOffsetBytes = ihl * 4;
if (s.length < dataOffsetBytes) {
throw new OperationError("Input length is less than IHL");
}

s.moveTo(dataOffsetBytes);

return s.getBytes().buffer;
}

}

export default StripIPv4Header;
72 changes: 36 additions & 36 deletions tests/browser/01_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,42 +675,42 @@ module.exports = {
}
},

"Loading from URL": browser => {
utils.clear(browser);

/* Side panel displays correct info */
utils.uploadFile(browser, "files/TowelDay.jpeg");

browser
.waitForElementVisible("#input-text .cm-file-details")
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
.waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
.waitForElementVisible("#input-text .cm-file-details .file-details-name")
.waitForElementVisible("#input-text .cm-file-details .file-details-size")
.waitForElementVisible("#input-text .cm-file-details .file-details-type")
.waitForElementVisible("#input-text .cm-file-details .file-details-loaded");

/* Complex deep link populates the input correctly (encoding, eol, input) */
browser
.urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS")
.waitForElementVisible("#rec-list li.operation");

browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^.{65}$/);
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("66");
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");

browser.expect.element("#input-text .chr-enc-value").text.that.equals("KOI8-U Ukrainian Cyrillic");
browser.expect.element("#output-text .chr-enc-value").text.that.equals("UTF-16BE");

browser.expect.element("#input-text .eol-value").text.that.equals("FF");
browser.expect.element("#output-text .eol-value").text.that.equals("PS");

utils.bake(browser);

browser.expect.element(`#output-text .cm-content`).to.have.property("textContent").match(/^.{44}$/);
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("44");
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
},
// "Loading from URL": browser => {
// utils.clear(browser);

// /* Side panel displays correct info */
// utils.uploadFile(browser, "files/TowelDay.jpeg");

// browser
// .waitForElementVisible("#input-text .cm-file-details")
// .waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
// .waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
// .waitForElementVisible("#input-text .cm-file-details .file-details-name")
// .waitForElementVisible("#input-text .cm-file-details .file-details-size")
// .waitForElementVisible("#input-text .cm-file-details .file-details-type")
// .waitForElementVisible("#input-text .cm-file-details .file-details-loaded");

// /* Complex deep link populates the input correctly (encoding, eol, input) */
// browser
// .urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=FF&oeol=PS")
// .waitForElementVisible("#rec-list li.operation");

// browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^.{65}$/);
// browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("66");
// browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");

// browser.expect.element("#input-text .chr-enc-value").text.that.equals("KOI8-U Ukrainian Cyrillic");
// browser.expect.element("#output-text .chr-enc-value").text.that.equals("UTF-16BE");

// browser.expect.element("#input-text .eol-value").text.that.equals("FF");
// browser.expect.element("#output-text .eol-value").text.that.equals("PS");

// utils.bake(browser);

// browser.expect.element(`#output-text .cm-content`).to.have.property("textContent").match(/^.{44}$/);
// browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("44");
// browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
// },

"Replace input with output": browser => {
/* Input is correctly populated */
Expand Down
1 change: 1 addition & 0 deletions tests/operations/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import "./tests/SIGABA.mjs";
import "./tests/SM4.mjs";
// import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet
import "./tests/StrUtils.mjs";
import "./tests/StripIPv4Header.mjs";
import "./tests/StripTCPHeader.mjs";
import "./tests/StripUDPHeader.mjs";
import "./tests/Subsection.mjs";
Expand Down
126 changes: 126 additions & 0 deletions tests/operations/tests/StripIPv4Header.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Strip IPv4 header tests.
*
* @author c65722 []
* @copyright Crown Copyright 2024
* @license Apache-2.0
*/

import TestRegister from "../../lib/TestRegister.mjs";

TestRegister.addTests([
{
name: "Strip IPv4 header: No options, No payload",
input: "450000140005400080060000c0a80001c0a80002",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: No options, Payload",
input: "450000140005400080060000c0a80001c0a80002ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Options, No payload",
input: "460000140005400080060000c0a80001c0a8000207000000",
expectedOutput: "",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Options, Payload",
input: "460000140005400080060000c0a80001c0a8000207000000ffffffffffffffff",
expectedOutput: "ffffffffffffffff",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Input length lesss than minimum header length",
input: "450000140005400080060000c0a80001c0a800",
expectedOutput: "Input length is less than minimum IPv4 header length",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
},
{
name: "Strip IPv4 header: Input length less than IHL",
input: "460000140005400080060000c0a80001c0a80000",
expectedOutput: "Input length is less than IHL",
recipeConfig: [
{
op: "From Hex",
args: ["None"]
},
{
op: "Strip IPv4 header",
args: [],
},
{
op: "To Hex",
args: ["None", 0]
}
]
}
]);
17 changes: 17 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { ModifySourcePlugin, ReplaceOperation } = require("modify-source-webpack-plugin");
const path = require("path");
const zlib = require("zlib");

/**
* Webpack configuration details for use with Grunt.
Expand Down Expand Up @@ -64,6 +66,21 @@ module.exports = {
new MiniCssExtractPlugin({
filename: "assets/[name].css"
}),
new CompressionPlugin({
filename: "[path][base].gz",
algorithm: "gzip",
test: /\.(js|css|html)$/,
}),
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
}),
new CopyWebpackPlugin({
patterns: [
{
Expand Down

0 comments on commit feaf3dd

Please sign in to comment.