Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(dotnet): treat ambiguous undecoded members as possible counterparts

Kaoru082273370e1c0648
diff --git a/docs/managed-code-analysis.md b/docs/managed-code-analysis.md
index 762ad0a1b..043a9c1dc 100644
--- a/docs/managed-code-analysis.md
+++ b/docs/managed-code-analysis.md
@@ -289,8 +289,8 @@ same exact tiers. The raw signature is exact whether or not REA decoded it, so
undecoded signatures pair by that tuple too, but they never enter structural
rounds. An unmatched member is therefore reported as `unknown`, not added or
removed, when its own signature was not decoded or when the other side has an
-unmatched member with the same declared type and name whose signature was not
-decoded.
+unpaired member, one-sided or ambiguous, with the same declared type and name
+whose signature was not decoded.
For a matched method, an unavailable or partial body makes body-shape facets
unknown while preserving observed signature differences. Structural identity
diff --git a/src/domain/managedMemberComparisonItems.ts b/src/domain/managedMemberComparisonItems.ts
index 61dc71058..fbd6edaa3 100644
--- a/src/domain/managedMemberComparisonItems.ts
+++ b/src/domain/managedMemberComparisonItems.ts
@@ -28,7 +28,7 @@ interface ComparisonItemContext {
readonly rightComplete: boolean;
}
-/** Declared type and name of each unmatched member, per side, whose signature was not decoded. */
+/** Declared type and name of each unpaired member, per side, whose signature was not decoded. */
interface UndecodedOneSidedNames {
readonly left: ReadonlySet<string>;
readonly right: ReadonlySet<string>;
@@ -162,8 +162,9 @@ const methodOnlyItem = (
* Why a one-sided member's absence from the other inventory was not
* observed: that inventory is incomplete, the member's own signature was not
* decoded, so no shape round could seek a changed counterpart, or the other
- * inventory has an unmatched same-named member whose signature was not
- * decoded, which may be this member with a changed signature.
+ * inventory has an unpaired (one-sided or ambiguous) same-named member whose
+ * signature was not decoded, which may be this member with a changed
+ * signature.
*/
const absenceLimitations = (
member: Method | Field,
@@ -187,7 +188,7 @@ const absenceLimitations = (
...(member.signature.parse_status === "decoded" &&
opposite.oppositeUndecodedNames.has(declaredName(member))
? [
- `counterpart-signature-not-decoded: The ${opposite.opposite} ${opposite.inventory} inventory has an unmatched member with the same declared type and name whose signature was not decoded, so it may be this member with a changed signature.`,
+ `counterpart-signature-not-decoded: The ${opposite.opposite} ${opposite.inventory} inventory has an unpaired member with the same declared type and name whose signature was not decoded, so it may be this member with a changed signature.`,
]
: []),
];
@@ -195,9 +196,17 @@ const absenceLimitations = (
const declaredName = (member: Method | Field): string =>
JSON.stringify([member.declaring_type, member.name]);
+/**
+ * Declared names of unpaired members whose signature was not decoded: one-sided
+ * members and candidates of ambiguous groups, which also remain unpaired.
+ */
const undecodedOneSidedNames = (members: {
readonly leftOnly: readonly { readonly item: Method | Field }[];
readonly rightOnly: readonly { readonly item: Method | Field }[];
+ readonly ambiguous: readonly {
+ readonly left: readonly { readonly item: Method | Field }[];
+ readonly right: readonly { readonly item: Method | Field }[];
+ }[];
}): UndecodedOneSidedNames => {
const names = (side: readonly { readonly item: Method | Field }[]) =>
new Set(
@@ -205,7 +214,16 @@ const undecodedOneSidedNames = (members: {
.filter(({ item }) => item.signature.parse_status !== "decoded")
.map(({ item }) => declaredName(item)),
);
- return { left: names(members.leftOnly), right: names(members.rightOnly) };
+ return {
+ left: names([
+ ...members.leftOnly,
+ ...members.ambiguous.flatMap(({ left }) => left),
+ ]),
+ right: names([
+ ...members.rightOnly,
+ ...members.ambiguous.flatMap(({ right }) => right),
+ ]),
+ };
};
const fieldOnlyItem = (
diff --git a/tests/boundary/providers/managed/managedMemberComparisonFromMetadata.test.ts b/tests/boundary/providers/managed/managedMemberComparisonFromMetadata.test.ts
index eb6db22c5..ced9314f4 100644
--- a/tests/boundary/providers/managed/managedMemberComparisonFromMetadata.test.ts
+++ b/tests/boundary/providers/managed/managedMemberComparisonFromMetadata.test.ts
@@ -337,6 +337,60 @@ describe("managed member comparison of undecoded signatures", () => {
});
});
+describe("managed member comparison of ambiguous undecoded signatures", () => {
+ it("keeps a decoded member unknown beside an ambiguous same-named undecoded group", () => {
+ const undecoded = { methodSignature: Buffer.from([0x00, 0x00, 0x7f]) };
+ const decoded = inspect(buildManagedPeFixture(), "/tmp/decoded.dll");
+ const left = inspect(buildManagedPeFixture(undecoded), "/tmp/left.dll");
+ const right = inspect(buildManagedPeFixture(undecoded), "/tmp/right.dll");
+ const [undecodedMethod] = left.result.methods;
+ const [decodedMethod] = decoded.result.methods;
+ if (undecodedMethod === undefined || decodedMethod === undefined)
+ throw new Error("Expected fixture methods");
+ expect(decodedMethod.name).toBe(undecodedMethod.name);
+ // One undecoded T.M on the left meets two identical undecoded T.M on the
+ // right, so that group stays ambiguous; the left also has a decoded T.M.
+ const result = compareManagedMembers(
+ {
+ ...left,
+ result: {
+ ...left.result,
+ methods: [undecodedMethod, { ...decodedMethod, token: "0x06000002" }],
+ },
+ },
+ {
+ ...right,
+ result: {
+ ...right.result,
+ methods: [
+ undecodedMethod,
+ { ...undecodedMethod, token: "0x06000002" },
+ ],
+ },
+ },
+ );
+
+ expect(result.methods).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ status: "unknown",
+ match: expect.objectContaining({ status: "ambiguous" }),
+ }),
+ expect.objectContaining({
+ status: "unknown",
+ left: expect.objectContaining({ token: "0x06000002" }),
+ limitations: [
+ expect.stringMatching(
+ /^counterpart-signature-not-decoded: The right method inventory has an unpaired member/u,
+ ),
+ ],
+ }),
+ ]),
+ );
+ expect(result.summary).toMatchObject({ removed: 0, added: 0 });
+ });
+});
+
const inspect = (bytes: Buffer, path: string) => {
const target = managedPeFixtureTarget(bytes, path);
const result = inspectManagedMembersBytes(bytes, target);