Apply caller-selected analyzer opt-outs before Ghidra analysis, reject unknown or ineffective names, and commit raw/header imports to the same analyzer profile. Use supported x86 raw compiler specs and cover the real analyzer/readback and raw workflows. Adopts the original implementation from #1800 with validated corrections. Refs #1783, #1836. Co-authored-by: akushonkamen <74654766+akushonkamen@users.noreply.github.com> Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
91 lines
2.7 KiB
TypeScript
91 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
ghidraDisabledAnalyzersSchema,
|
|
MAX_GHIDRA_DISABLED_ANALYZER_NAMES,
|
|
} from "../config/ghidraDisabledAnalyzers.js";
|
|
import { parseConfig } from "../config/parseConfig.js";
|
|
|
|
const INSTALL = "/opt/ghidra_12.1.4_PUBLIC";
|
|
|
|
const configured = (setting?: string) => {
|
|
const config = parseConfig({
|
|
GHIDRA_INSTALL_DIR: INSTALL,
|
|
...(setting === undefined
|
|
? {}
|
|
: { REA_GHIDRA_DISABLED_ANALYZERS: setting }),
|
|
});
|
|
if (!config.ok) throw config.error;
|
|
return config.value.ghidraDisabledAnalyzers;
|
|
};
|
|
|
|
describe("REA_GHIDRA_DISABLED_ANALYZERS", () => {
|
|
it("stays unset without the setting", () => {
|
|
expect(configured(undefined)).toBeUndefined();
|
|
});
|
|
|
|
it("splits a comma-separated list and trims each name", () => {
|
|
expect(
|
|
configured(" Objective-C Message Analyzer,Decompiler Switch Analysis "),
|
|
).toEqual(["Objective-C Message Analyzer", "Decompiler Switch Analysis"]);
|
|
});
|
|
|
|
it("treats an empty or blank list as unset", () => {
|
|
expect(configured("")).toBeUndefined();
|
|
expect(configured(" , ")).toBeUndefined();
|
|
});
|
|
|
|
it("keeps empty names out of the list instead of failing", () => {
|
|
expect(
|
|
configured("Objective-C Message Analyzer,,Decompiler Switch Analysis"),
|
|
).toEqual(["Objective-C Message Analyzer", "Decompiler Switch Analysis"]);
|
|
});
|
|
|
|
it.each([
|
|
["a leading flag name", "-Decompiler Switch Analysis"],
|
|
["a name with command metacharacters", "Analyzer(&calc)"],
|
|
["a non-ASCII name", "分析器"],
|
|
["an over-long name", "A".repeat(121)],
|
|
])("rejects %s", (_label, setting) => {
|
|
const config = parseConfig({
|
|
GHIDRA_INSTALL_DIR: INSTALL,
|
|
REA_GHIDRA_DISABLED_ANALYZERS: setting,
|
|
});
|
|
expect(config.ok).toBe(false);
|
|
if (!config.ok)
|
|
expect(config.error).toMatchObject({
|
|
settings: [
|
|
expect.objectContaining({
|
|
setting: "REA_GHIDRA_DISABLED_ANALYZERS",
|
|
}),
|
|
],
|
|
});
|
|
});
|
|
|
|
it("rejects more than the admitted analyzer count", () => {
|
|
const setting = Array.from(
|
|
{ length: MAX_GHIDRA_DISABLED_ANALYZER_NAMES + 1 },
|
|
(_, index) => `Analyzer ${index}`,
|
|
).join(",");
|
|
const config = parseConfig({
|
|
GHIDRA_INSTALL_DIR: INSTALL,
|
|
REA_GHIDRA_DISABLED_ANALYZERS: setting,
|
|
});
|
|
expect(config.ok).toBe(false);
|
|
if (!config.ok)
|
|
expect(config.error).toMatchObject({
|
|
settings: [
|
|
expect.objectContaining({
|
|
setting: "REA_GHIDRA_DISABLED_ANALYZERS",
|
|
}),
|
|
],
|
|
});
|
|
});
|
|
|
|
it("admits the documented Objective-C analyzer name", () => {
|
|
expect(
|
|
ghidraDisabledAnalyzersSchema.parse("Objective-C Message Analyzer"),
|
|
).toEqual(["Objective-C Message Analyzer"]);
|
|
});
|
|
});
|