Files
reverse-engineering-anything/src/domain/android/decodedAndroidManifest.ts
T
morluto 61af8abeb6 fix(android): share decoded Android XML admission (#12158)
* fix(android): share decoded manifest root and package admission

Refs #12139

* fix(apktool): keep foreign XML out of decoded string entries

Refs #12139
2026-11-19 11:07:25 +08:00

28 lines
902 B
TypeScript

import type { Element } from "@xmldom/xmldom";
import { err, ok, type Result } from "../result.js";
import {
isUnqualifiedXmlElement,
parseXmlDocument,
type XmlParseFailure,
} from "../xmlDocument.js";
/** Read the decoded root and its package without validating package-name syntax. */
export const parseDecodedAndroidManifest = (
source: string,
doctype: "allow" | "reject",
): Result<
{ readonly root: Element; readonly packageName: string | null },
XmlParseFailure | { readonly kind: "unexpected-root" }
> => {
const parsed = parseXmlDocument(source, { doctype, lineEndings: "preserve" });
if (!parsed.ok) return parsed;
const root = parsed.value.documentElement;
if (!isUnqualifiedXmlElement(root) || root.localName !== "manifest")
return err({ kind: "unexpected-root" });
return ok({
root,
packageName: root.getAttributeNS(null, "package") || null,
});
};