Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(managed): treat extension-only module scopes as unknown identity (#5674)

Ulises Millánc4b6aa3061d8
diff --git a/src/domain/managed/managedNativeVerificationMatch.ts b/src/domain/managed/managedNativeVerificationMatch.ts
index ef7c81747..9bccc56e8 100644
--- a/src/domain/managed/managedNativeVerificationMatch.ts
+++ b/src/domain/managed/managedNativeVerificationMatch.ts
@@ -113,12 +113,20 @@ const normalizeModule = (value: string): string =>
.toLowerCase()
.replace(/\.(dll|dylib|so|node|exe)$/u, "");
+/** A declared module identity, or null when normalization leaves no name. */
+const declaredModuleIdentity = (scope: string | null): string | null => {
+ if (scope === null || scope.trim().length === 0) return null;
+ const identity = normalizeModule(scope);
+ return identity.length > 0 ? identity : null;
+};
+
const nativeModuleIdentities = (value: string): ReadonlySet<string> => {
const filename = basename(value).toLowerCase();
const stem = normalizeModule(filename);
const identities = new Set([stem]);
if (/\.(dylib|so)$/u.test(filename) && stem.startsWith("lib"))
identities.add(stem.slice("lib".length));
+ identities.delete("");
return identities;
};
@@ -126,8 +134,8 @@ const moduleCompatible = (
scope: string | null,
symbol: NativeSymbol,
): boolean => {
- if (scope === null || scope.trim().length === 0) return false;
- const expected = normalizeModule(scope);
+ const expected = declaredModuleIdentity(scope);
+ if (expected === null) return false;
return [symbol.module_name, symbol.module_path]
.filter(
(value): value is string =>
@@ -200,9 +208,7 @@ const matchPinvoke = (
};
const candidates: [NativeSymbol, ...NativeSymbol[]] = [first, ...remaining];
- const scopeKnown =
- managed.import_scope_name !== null &&
- managed.import_scope_name.trim().length > 0;
+ const scopeKnown = declaredModuleIdentity(managed.import_scope_name) !== null;
const exact = candidates.find(
(symbol) =>
managed.import_name === normalizedSymbolName(symbol) &&
diff --git a/tests/conformance/providers/managed/managedNativeVerification.test.ts b/tests/conformance/providers/managed/managedNativeVerification.test.ts
index b15c720fd..bd39d4b27 100644
--- a/tests/conformance/providers/managed/managedNativeVerification.test.ts
+++ b/tests/conformance/providers/managed/managedNativeVerification.test.ts
@@ -263,6 +263,22 @@ it("keeps name candidates unresolved when a required module identity is absent",
);
}
+ for (const path of [
+ "/examples/lib.dylib",
+ "/examples/lib.so",
+ "/examples/foo.dll",
+ ]) {
+ const extensionOnly = verifyManagedNativeBoundaries({
+ ...inputWithImportScope(".dll"),
+ native_observations: [nativeEvidenceWithExports(["open_native"], path)],
+ });
+ expect(extensionOnly.pinvoke_imports[0]).toMatchObject({
+ status: "unresolved",
+ basis: "module-identity-unknown",
+ candidates: [{ name: "open_native", module_path: path }],
+ });
+ }
+
const subjectless = verifyManagedNativeBoundaries({
...inputWithImportScope("nativehelper.dll"),
native_observations: [