fix(ghidra): classify modern Swift manglings in swift type analysis (#1208)
* fix(ghidra): classify modern Swift manglings in swift type analysis Categorize modern Swift 4.2+ manglings ($s, _$s) instead of dropping them in analyze_swift_types. The classifier only accepted the legacy _Tt marker, so procedure names reported by current providers produced an empty inventory. Legacy _Tt families and behavior are unchanged. Fixes #1187. * fix(swift): retain provider aliases and category unknowns --------- Co-authored-by: Saim Shafique <sx4imm@gmail.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
Saim Shafique
morluto
parent
04a516b1e3
commit
6935dc7fe1
@@ -80,4 +80,165 @@ describe("symbol analysis", () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("classifies modern Swift manglings reported by current providers", () => {
|
||||
const result = categorizeSwiftTypes([
|
||||
{ address: "0x1000009f8", name: "$s4main4PairVMa" },
|
||||
{ address: "0x100000ac4", name: "$s4main6ScorerVMa" },
|
||||
{ address: "0x100000ab4", name: "_$s4main4PairVMa" },
|
||||
{ address: "0x1", name: "_TtCClass" },
|
||||
{ address: "0x1000009f8", name: "$s4main4PairVMa" },
|
||||
]);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
total: 4,
|
||||
categories: {
|
||||
classes: { count: 1 },
|
||||
structs: {
|
||||
count: 3,
|
||||
items: [
|
||||
{ address: "0x1000009f8", name: "$s4main4PairVMa" },
|
||||
{ address: "0x100000ac4", name: "$s4main6ScorerVMa" },
|
||||
{ address: "0x100000ab4", name: "_$s4main4PairVMa" },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps non-Swift procedure names out of the Swift inventory", () => {
|
||||
const result = categorizeSwiftTypes([
|
||||
{ address: "0x1", name: "printf" },
|
||||
{ address: "0x2", name: "_OBJC_CLASS_$_App" },
|
||||
{ address: "0x3", name: "std::vector<int>::push_back" },
|
||||
]);
|
||||
|
||||
expect(result).toMatchObject({ total: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("modern Swift category evidence", () => {
|
||||
it.each([
|
||||
["$s4main4PairVMa", "structs"],
|
||||
["_$s4main6ScorerVMa", "structs"],
|
||||
["$s4main7ServiceCMa", "classes"],
|
||||
["$s4main5StateOMa", "enums"],
|
||||
["$s4main7ScoringPMp", "protocols"],
|
||||
["$s4main5OuterV5InnerCMa", "classes"],
|
||||
["$s4main4PairV5otherE7doubledSiyF", "extensions"],
|
||||
["$S4main4PairVMa", "structs"],
|
||||
["_T04main4PairVMa", "structs"],
|
||||
["$s4_TtX4PairVMa", "structs"],
|
||||
] as const)("decodes nominal contexts for %s", (name, category) => {
|
||||
expect(
|
||||
categorizeSwiftTypes([{ address: "0x1", name }], { category }),
|
||||
).toMatchObject({
|
||||
total: 1,
|
||||
categories: { [category]: { count: 1 } },
|
||||
unclassified: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("retains unresolved Swift observations under category filters", () => {
|
||||
const names = [
|
||||
"$s4main13swiftIndirectySiAA7Scoring_p_SitF",
|
||||
"$sSi4mainE7doubledSiyF",
|
||||
"$s9999999999999999999999BadVMa",
|
||||
"$s4main04PairVMa",
|
||||
];
|
||||
const result = categorizeSwiftTypes(
|
||||
names.map((name, index) => ({ address: String(index), name })),
|
||||
{ category: "structs" },
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
total: 0,
|
||||
unclassified: names.map((name) => ({
|
||||
name,
|
||||
mangled_names: [name],
|
||||
reason: "category_not_decoded",
|
||||
})),
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining("could not be established"),
|
||||
]),
|
||||
});
|
||||
expect(
|
||||
categorizeSwiftTypes([{ address: "0x1", name: names[0] ?? "" }], {
|
||||
category: "structs",
|
||||
pattern: "missing",
|
||||
}),
|
||||
).toMatchObject({ total: 0, unclassified: [] });
|
||||
});
|
||||
|
||||
it("joins Swift aliases only at the exact procedure address", () => {
|
||||
const result = categorizeSwiftTypes(
|
||||
[
|
||||
{ address: "0x1", name: "main::Pair::typeMetadataAccessor" },
|
||||
{ address: "0x2", name: "std::vector<int>::push_back" },
|
||||
{ address: "0x3", name: "main::Pair::other" },
|
||||
],
|
||||
{ category: "structs", pattern: "Pair" },
|
||||
[
|
||||
{ address: "0x1", name: "_$s4main4PairVMa" },
|
||||
{ address: "0x4", name: "$s4main4PairVMa" },
|
||||
],
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
total: 1,
|
||||
categories: {
|
||||
structs: {
|
||||
items: [
|
||||
{
|
||||
address: "0x1",
|
||||
name: "main::Pair::typeMetadataAccessor",
|
||||
mangled_names: ["_$s4main4PairVMa"],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
unclassified: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("deduplicates display names after selecting a category", () => {
|
||||
expect(
|
||||
categorizeSwiftTypes(
|
||||
[
|
||||
{ address: "0x1", name: "shared" },
|
||||
{ address: "0x2", name: "shared" },
|
||||
],
|
||||
{ category: "structs" },
|
||||
[
|
||||
{ address: "0x1", name: "$s4main7ServiceCMa" },
|
||||
{ address: "0x2", name: "$s4main4PairVMa" },
|
||||
],
|
||||
),
|
||||
).toMatchObject({
|
||||
total: 1,
|
||||
categories: { structs: { items: [{ address: "0x2", name: "shared" }] } },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Swift alias ambiguity", () => {
|
||||
it("reports conflicting aliases rather than choosing a category", () => {
|
||||
expect(
|
||||
categorizeSwiftTypes(
|
||||
[{ address: "0x1", name: "shared" }],
|
||||
{ category: "structs" },
|
||||
[
|
||||
{ address: "0x1", name: "$s4main4PairVMa" },
|
||||
{ address: "0x1", name: "$s4main7ServiceCMa" },
|
||||
],
|
||||
),
|
||||
).toMatchObject({
|
||||
total: 0,
|
||||
unclassified: [
|
||||
{
|
||||
name: "shared",
|
||||
reason: "conflicting_categories",
|
||||
mangled_names: ["$s4main4PairVMa", "$s4main7ServiceCMa"],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user