@@ -35,3 +35,31 @@ test("keeps the installed application available offline", async ({
|
||||
await context.setOffline(false);
|
||||
}
|
||||
});
|
||||
|
||||
test("edits, interprets and searches a larger buffer in a bounded worker", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/");
|
||||
await page.locator('input[type="file"]').evaluate((input) => {
|
||||
const bytes = new Uint8Array(70_000);
|
||||
bytes.fill(0x41);
|
||||
bytes[69_999] = 0x42;
|
||||
const transfer = new DataTransfer();
|
||||
transfer.items.add(
|
||||
new File([bytes], "large.bin", { type: "application/octet-stream" }),
|
||||
);
|
||||
(input as HTMLInputElement).files = transfer.files;
|
||||
input.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
});
|
||||
await page
|
||||
.getByRole("textbox", { name: "Pattern", exact: true })
|
||||
.fill("41 41 42");
|
||||
await page.getByRole("button", { name: "Search", exact: true }).click();
|
||||
await expect(page.getByRole("status")).toContainText("1 match");
|
||||
await page.getByLabel("Replacement bytes (hex)").fill("ff");
|
||||
await page.getByRole("button", { name: "Apply byte edit" }).click();
|
||||
await expect(page.getByLabel("hex output")).toHaveValue(/^ff/u);
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Typed interpretations" }),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("keeps the primary workspace inside a narrow viewport", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/deep/nested/binary/");
|
||||
await expect(page.locator("main").first()).toBeVisible();
|
||||
await expect(
|
||||
page.locator("main .loading, main .workbench-loading"),
|
||||
).toHaveCount(0);
|
||||
|
||||
const widths = await page.evaluate(() => ({
|
||||
content: document.documentElement.scrollWidth,
|
||||
viewport: document.documentElement.clientWidth,
|
||||
}));
|
||||
expect(widths.viewport).toBeLessThanOrEqual(430);
|
||||
expect(widths.content).toBeLessThanOrEqual(widths.viewport + 1);
|
||||
});
|
||||
@@ -18,8 +18,23 @@ describe("Workbench", () => {
|
||||
it("shows malformed decoder errors without clearing bytes", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Workbench />);
|
||||
await user.click(screen.getByRole("tab", { name: "ASN.1 DER" }));
|
||||
await user.click(screen.getByRole("button", { name: "ASN.1 DER" }));
|
||||
expect(screen.getByRole("alert")).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Byte 20: 0a" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("edits and searches the canonical byte buffer", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Workbench />);
|
||||
const editOffset = screen.getAllByLabelText("Offset (decimal or 0x…)")[0]!;
|
||||
await user.clear(editOffset);
|
||||
await user.type(editOffset, "0");
|
||||
await user.type(screen.getByLabelText("Replacement bytes (hex)"), "41");
|
||||
await user.click(screen.getByRole("button", { name: "Apply byte edit" }));
|
||||
expect(
|
||||
(screen.getByLabelText("hex output") as HTMLTextAreaElement).value,
|
||||
).toMatch(/^41/u);
|
||||
await user.click(screen.getByRole("button", { name: "Search" }));
|
||||
expect(await screen.findByText(/1 match/u)).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
applyBinaryTemplate,
|
||||
deleteBytes,
|
||||
findBytePattern,
|
||||
insertBytes,
|
||||
interpretBytes,
|
||||
parseSearchPattern,
|
||||
replaceByteRange,
|
||||
validateBookmarks,
|
||||
} from "../../src/core/workbench";
|
||||
|
||||
describe("byte workbench primitives", () => {
|
||||
it("edits checked ranges without mutating the source", () => {
|
||||
const source = Uint8Array.from([1, 2, 3, 4]);
|
||||
expect([
|
||||
...replaceByteRange(source, 1, 2, Uint8Array.from([9, 8])),
|
||||
]).toEqual([1, 9, 8, 4]);
|
||||
expect([...insertBytes(source, 2, Uint8Array.from([7]))]).toEqual([
|
||||
1, 2, 7, 3, 4,
|
||||
]);
|
||||
expect([...deleteBytes(source, 1, 2)]).toEqual([1, 4]);
|
||||
expect([...source]).toEqual([1, 2, 3, 4]);
|
||||
expect(() => deleteBytes(source, 3, 2)).toThrow(/Edit range/u);
|
||||
});
|
||||
|
||||
it("searches exact and wildcard byte patterns with a bounded result set", () => {
|
||||
const bytes = new TextEncoder().encode("hello hallo hello");
|
||||
const pattern = parseSearchPattern("68 ?? 6c 6c 6f", "hex");
|
||||
expect(findBytePattern(bytes, pattern).offsets).toEqual([0, 6, 12]);
|
||||
expect(
|
||||
findBytePattern(bytes, parseSearchPattern("hello", "utf8"), {
|
||||
maximumMatches: 1,
|
||||
}),
|
||||
).toMatchObject({ offsets: [0], truncated: true });
|
||||
});
|
||||
|
||||
it("interprets typed values with explicit byte order", () => {
|
||||
const bytes = Uint8Array.from([1, 2, 3, 4, 0, 0, 0, 0]);
|
||||
const little = interpretBytes(bytes, 0, "little");
|
||||
const big = interpretBytes(bytes, 0, "big");
|
||||
expect(little.find((item) => item.type === "unsigned 32-bit")?.value).toBe(
|
||||
"67305985",
|
||||
);
|
||||
expect(big.find((item) => item.type === "unsigned 32-bit")?.value).toBe(
|
||||
"16909060",
|
||||
);
|
||||
});
|
||||
|
||||
it("applies built-in templates and validates bookmark ranges", () => {
|
||||
const png = Uint8Array.from([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13, 0x49, 0x48,
|
||||
0x44, 0x52, 0, 0, 0, 2, 0, 0, 0, 3,
|
||||
]);
|
||||
const result = applyBinaryTemplate(png, "png-header");
|
||||
expect(result.recognized).toBe(true);
|
||||
expect(result.fields.find((field) => field.name === "width")?.value).toBe(
|
||||
"2",
|
||||
);
|
||||
expect(
|
||||
validateBookmarks(
|
||||
[{ id: "ihdr", name: "IHDR", offset: 8, length: 16 }],
|
||||
png.length,
|
||||
),
|
||||
).toHaveLength(1);
|
||||
expect(() =>
|
||||
validateBookmarks(
|
||||
[{ id: "bad", name: "Bad", offset: 23, length: 2 }],
|
||||
png.length,
|
||||
),
|
||||
).toThrow(/Bookmark range/u);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user