Files
reverse-engineering-anything/src/domain/native/bytePattern.test.ts
T
morlutoandCursor Agent 887b99888e fix(ghidra)!: distinguish skipped overlays in byte search (#8608)
* fix(ghidra)!: distinguish skipped overlays in byte search

BREAKING CHANGE: Byte search results require skipped_overlays; loaded overlays no longer appear in skipped_not_loaded. The Ghidra profile changes so prior snapshots are not replayed.

* fix(cli): explain overlay byte search scope

* test(ghidra): exercise overlay search cursor handoff

* test(ghidra): avoid freezing byte search help wording

* test(ghidra): classify search start as an address bound

* docs(ghidra): match the raw lane's overlay coverage

The raw Ghidra lane checks a manually created overlay block through MCP.
Say that, and do not claim an overlapping-load ELF, CLI search, or snapshot
cursor handoff.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-11-08 01:49:58 +00:00

136 lines
3.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { z } from "zod";
import {
bytePatternFields,
validateBytePattern,
byteSearchResultSchema,
} from "./bytePattern.js";
const patternSchema = z
.strictObject(bytePatternFields)
.superRefine(validateBytePattern);
it.each(["0x20", "overlay:0x10", "invalid"])(
"rejects a match outside reported searched coverage: %s",
(address) => {
const page = {
matches: [
{ address, segment: ".text", file_offset: null, procedure: null },
],
searched: {
blocks: [{ segment: ".text", start: "0x10", end: "0x1f", bytes: 16 }],
bytes: 16,
skipped_uninitialized: [],
skipped_not_loaded: [],
skipped_overlays: [],
},
complete: true,
next_cursor: null,
};
expect(byteSearchResultSchema.safeParse(page).success).toBe(false);
page.matches[0]!.address = "0x10";
expect(byteSearchResultSchema.safeParse(page).success).toBe(true);
page.matches[0]!.segment = ".bss";
expect(byteSearchResultSchema.safeParse(page).success).toBe(false);
},
);
it.each(["", "overlay:"])(
"accepts matches at both inclusive coverage boundaries in address space %s",
(space) => {
const start = `${space}0x10`;
const end = `${space}0x1f`;
expect(
byteSearchResultSchema.safeParse({
matches: [start, end].map((address) => ({
address,
segment: ".text",
file_offset: null,
procedure: null,
})),
searched: {
blocks: [{ segment: ".text", start, end, bytes: 16 }],
bytes: 16,
skipped_uninitialized: [],
skipped_not_loaded: [],
skipped_overlays: [],
},
complete: true,
next_cursor: null,
}).success,
).toBe(true);
},
);
describe("masked byte patterns", () => {
it("preserves whole-byte wildcards and combines explicit bit masks", () => {
for (const input of [
{ pattern: "48 8b\t??89", mask: "ff f0 ff 0f" },
{ pattern: "Aa\u00a000" },
{ pattern: "00" },
{ pattern: "????aa", mask: "000001" },
])
expect(patternSchema.parse(input)).toEqual(input);
});
it.each([
["", undefined, "pattern"],
["4", undefined, "pattern"],
["4?", undefined, "pattern"],
["gg", undefined, "pattern"],
["?? ??", undefined, "pattern"],
["ff", "00", "pattern"],
["ffff", "ff", "mask"],
["ff", "??", "mask"],
["aa ??", "00 ff", "pattern"],
["??", "0000", "mask"],
["aa", "00gg", "mask"],
["??gg", "00gg", "pattern"],
])("rejects invalid pattern %s with typed issues", (pattern, mask, field) => {
const parsed = patternSchema.safeParse({ pattern, mask });
expect(parsed.success).toBe(false);
if (parsed.success) throw new Error("Expected a rejected pattern");
expect(parsed.error.issues).toMatchObject([
{ path: [field], code: "custom" },
]);
});
it("accepts ECMAScript whitespace only between complete byte pairs", () => {
const whitespace = [
"\t",
"\n",
"\v",
"\f",
"\r",
" ",
"\u00a0",
"\u1680",
...Array.from({ length: 11 }, (_, i) => String.fromCharCode(0x2000 + i)),
"\u2028",
"\u2029",
"\u202f",
"\u205f",
"\u3000",
"\ufeff",
];
for (const separator of whitespace) {
expect(
patternSchema.safeParse({
pattern: `aa${separator}??`,
mask: `ff${separator}ff`,
}).success,
).toBe(true);
for (const pattern of [
`${separator}aa`,
`aa${separator}`,
`a${separator}a`,
])
expect(patternSchema.safeParse({ pattern }).success).toBe(false);
}
for (const separator of ["\u0085", "\u180e", "\u200b", "\u200c", "\u200d"])
expect(
patternSchema.safeParse({ pattern: `aa${separator}bb` }).success,
).toBe(false);
});
});