* feat(apktool): decode Android resource tables through a caller-supplied launcher Add an Apktool family with two operations over the caller's apktool launcher (REA_APKTOOL_COMMAND, absolute, or apktool on PATH): - inspect_apktool_client: resolved launcher, selection source, and version; decodes nothing. - decode_android_resources: apktool d --no-src in a provider-owned workspace that is removed before the result returns. Projects the decoded AndroidManifest.xml (bounded at 512 KiB), apktool.yml version and SDK facts exactly as printed, string resources verbatim (default or one locale, bounded at 2000 entries, nested-markup entries counted as unparsed), available string locales, and the decoded file count with a hard cap. The target APK is digested with SHA-256 before decoding so Evidence binds the observation to the exact input. Smali production is skipped by design: Java-source recovery belongs to the JADX family. Workspace cleanup happens before results return; an unremovable workspace is named in the limitations instead of abandoned. Verified against apktool 2.7.0-dirty (Debian packaging) on Linux with OpenJDK 25 against a signed aapt2-built probe APK with two resource locales: launcher version, on-disk digest agreement, metadata projection, manifest package agreement, and both string tables (default and de). Parser goldens come from the same decode. READMEs carry the new 'Android resources' row in every supported language. * fix(apktool): own snapshots and bound decoded resource reads * docs(apktool): describe owned resources and bounded projection --------- Co-authored-by: REA Contributor <contributor@rea.tools> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
/**
|
|
* Parsers for the decoded workspace `apktool d --no-src` produces.
|
|
*
|
|
* Apktool's apktool.yml is a small YAML document; the facts REA projects
|
|
* are flat enough that line-oriented extraction stays honest without a
|
|
* YAML dependency, and unrecognized content is ignored rather than guessed.
|
|
*/
|
|
|
|
export interface ApktoolMetadata {
|
|
readonly versionName: string | null;
|
|
readonly versionCode: string | null;
|
|
readonly minSdkVersion: string | null;
|
|
readonly targetSdkVersion: string | null;
|
|
}
|
|
|
|
/**
|
|
* Project version and SDK facts from apktool.yml. Values keep apktool's
|
|
* own spelling (version codes can print as `45` or `45.1`).
|
|
*/
|
|
export const parseApktoolYml = (yml: string): ApktoolMetadata => {
|
|
const metadata: {
|
|
versionName: string | null;
|
|
versionCode: string | null;
|
|
minSdkVersion: string | null;
|
|
targetSdkVersion: string | null;
|
|
} = {
|
|
versionName: null,
|
|
versionCode: null,
|
|
minSdkVersion: null,
|
|
targetSdkVersion: null,
|
|
};
|
|
for (const line of yml.split(/\r?\n/u)) {
|
|
const versionName = /^\s*versionName:\s*(?:'([^']*)'|(.*))$/u.exec(line);
|
|
if (versionName !== null && metadata.versionName === null)
|
|
metadata.versionName = (versionName[1] ?? versionName[2] ?? "").trim();
|
|
const versionCode = /^\s*versionCode:\s*(?:'([^']*)'|(.*))$/u.exec(line);
|
|
if (versionCode !== null && metadata.versionCode === null)
|
|
metadata.versionCode = (versionCode[1] ?? versionCode[2] ?? "").trim();
|
|
const minSdk = /minSdkVersion:\s*'?([0-9]+)'?/u.exec(line);
|
|
if (minSdk !== null && metadata.minSdkVersion === null)
|
|
metadata.minSdkVersion = minSdk[1]!;
|
|
const targetSdk = /targetSdkVersion:\s*'?([0-9]+)'?/u.exec(line);
|
|
if (targetSdk !== null && metadata.targetSdkVersion === null)
|
|
metadata.targetSdkVersion = targetSdk[1]!;
|
|
}
|
|
return metadata;
|
|
};
|
|
|
|
/** Read the package attribute from decoded AndroidManifest.xml text. */
|
|
export const parseManifestPackage = (manifest: string): string | null => {
|
|
const match = /<manifest[^>]*\spackage="([^"]+)"/u.exec(manifest);
|
|
return match === null ? null : match[1]!;
|
|
};
|
|
|
|
export interface DecodedStringEntry {
|
|
readonly name: string;
|
|
readonly value: string;
|
|
}
|
|
|
|
/**
|
|
* Project `<string name="...">value</string>` entries from one decoded
|
|
* strings.xml. Values are preserved exactly as apktool printed them —
|
|
* escaped entities stay escaped — and entries containing nested markup
|
|
* are counted as unparsed rather than flattened.
|
|
*/
|
|
export const parseDecodedStrings = (
|
|
stringsXml: string,
|
|
): {
|
|
entries: readonly DecodedStringEntry[];
|
|
unparsedCount: number;
|
|
} => {
|
|
const entries: DecodedStringEntry[] = [];
|
|
let unparsedCount = 0;
|
|
const pattern = /<string\s+name="([^"]+)"[^>]*>([\s\S]*?)<\/string>/gu;
|
|
for (
|
|
let match = pattern.exec(stringsXml);
|
|
match !== null;
|
|
match = pattern.exec(stringsXml)
|
|
) {
|
|
const value = match[2]!;
|
|
if (value.includes("<")) {
|
|
unparsedCount += 1;
|
|
continue;
|
|
}
|
|
entries.push({ name: match[1]!, value: value.trim() });
|
|
}
|
|
return { entries, unparsedCount };
|
|
};
|