axml

    Parse Android binary XML (AXML) and resources.arsc into readable node trees, attributes, string pools and resolved resource values, with format-level encoders.

    android
    axml
    arsc
    binary-xml
    parser
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    8 hours ago
    Downloads
    4

    No dependencies

    #hnlyxiaobing/axml

    把 Android 二进制 XML(AXML)与 resources.arsc 解析成可读的节点树、属性、字符串池与资源引用值,并提供格式级回编(AXML / ARSC 值级)。

    • 解析:AXML chunk、字符串池、resource map、命名空间、元素与属性,支持 tree / sem / pool 三种视图
    • 资源表:resources.arsc 的 package / typeSpec / type entry / 字符串池,bag 压平,?attr 主题求值
    • 解析辅助:qualifier 最优匹配、ResTableSet 多表联合解析、--config 设备限定符取值
    • 回编:encode 生成 AXML、encode_arsc 生成 resources.arsc(值级语义往返)
    • 零第三方依赖;preferred_target = wasm,wasm/native 双目标通过同一套测试

    #安装

    moon add hnlyxiaobing/axml

    #快速开始

    ///|
    fn dump_names(raw : Bytes) -> Unit raise {
    let doc = @axml.parse(raw)
    for node in doc.elements() {
    guard node.chunk is StartElement else { continue }
    println(node.name)
    for attr in node.attrs() {
    println("\{attr.name} = \{attr.raw_value.unwrap_or("")}")
    }
    }
    }

    ///|
    fn resolve_label(raw_axml : Bytes, raw_arsc : Bytes) -> Unit raise {
    let doc = @axml.parse(raw_axml)
    let table = @axml.parse_arsc(raw_arsc)
    for node in doc.elements() {
    for attr in node.attrs() {
    let resolved = @axml.resolve_attr_value(doc, table, attr)
    println("\{attr.name} -> \{resolved}")
    }
    }
    }

    #命令行

    axml-cli dump --view sem --resolve --arsc resources.arsc AndroidManifest.xml axml-cli dump --json --config zh-rCN-sw600dp AndroidManifest.xml

    #链接

    • 完整说明(能力边界、公开 API、验证、风险):仓库 README.md
    • 公开签名以 pkg.generated.mbti 为准
    • 许可:Apache-2.0

    NodeIndex

    type NodeIndex = Int

    节点表索引。

    StringIndex

    type StringIndex = Int

    字符串池索引。

    ArscError

    pub suberror ArscError {
    Eof(Int)
    BadChunk(Int, UInt)
    BadHeader(Int, Int)
    BadPool(Int, String)
    BadIndex(Int)
    BadTable(Int, String)
    BadQualifier(String)
    BagNotComplex(UInt)
    BagMissingParent(UInt)
    BagCycle(UInt)
    AttrMissing(UInt)
    AttrCycle(UInt)
    } derive(
    Debug
    )

    resources.arsc 解析错误。

    字节层/字符串池层错误映射自 AxmlError(构造一一对应,见 axml_err), 资源表结构语义错误以 BadTable(offset, detail) 报告,offset 为输入缓冲区 中的绝对字节偏移。全部可恢复、可定位,禁止 panic。

    AxmlError

    pub suberror AxmlError {
    UnexpectedEof(Int)
    BadChunkType(Int, UInt)
    BadHeaderSize(Int, Int)
    BadStringPool(Int, String)
    InvalidStringIndex(Int)
    InvalidNodeIndex(Int)
    UnsupportedEncoding(String)
    VendorVariant(String)
    } derive(
    Debug
    )

    AXML 错误模型:全部为可恢复、可定位到字节偏移的显式错误,禁止 panic。

    AxmlDoc

    pub(all) struct AxmlDoc {
    pool : StringPool
    nodes : Array[XmlNode]
    roots : Array[Int]
    resource_map : Array[UInt]
    }

    AXML 解析结果:已解码字符串池 + 线性节点表 + 根索引 + 原始 resource map。

    AxmlDoc::elements

    fn AxmlDoc::elements(self : AxmlDoc) -> Array[XmlNode] raise AxmlError

    按 chunk 顺序返回全部元素节点。XmlTree / CData 等非元素节点不在此列表中。 先校验 roots / parent / children 索引,越界返回 InvalidNodeIndex。

    AxmlDoc::node_at

    fn AxmlDoc::node_at(self : AxmlDoc, index : Int) -> XmlNode raise AxmlError

    读取节点表第 index 项;越界返回 InvalidNodeIndex。

    AxmlDoc::string_at

    fn AxmlDoc::string_at(self : AxmlDoc, index : Int) -> String raise AxmlError

    读取字符串池第 index 项;越界返回 InvalidStringIndex。

    ChunkType

    pub(all) enum ChunkType {
    StringPool
    XmlTree
    StartNamespace
    EndNamespace
    StartElement
    EndElement
    CData
    ResourceMap
    }

    AXML chunk 类型(AOSP RES_STRING_POOL_TYPE / RES_XML_*_TYPE)。 仅作节点来源标注,暂不参与解析决策。

    DynamicRefView

    pub(all) struct DynamicRefView {
    origin_id : UInt
    runtime_package_id : Int
    library_name : String?
    }

    动态引用映射视图(W5):暴露 RES_TABLE_LIBRARY_TYPE 映射的忠实事实, 上层据此改写动态引用;本库不改写。未命中时 library_name=None (值化降级,不抛错)。

    FlattenedBag

    pub(all) struct FlattenedBag {
    id : UInt
    attrs : Array[ResMap]
    }

    bag 压平结果:自根到子覆盖同名 map 后的最终属性映射(保序,子值原地覆盖)。

    ResBag

    pub(all) struct ResBag {
    parent : UInt
    maps : Array[ResMap]
    }

    复杂条目(bag):父资源 id + 映射数组(AOSP ResTable_map_entry)。 parent 为 0 表示无父;AOSP 视其为 TYPE_DYNAMIC_REFERENCE,本库保留原值。

    ResConfig

    pub(all) struct ResConfig {
    size : Int
    mcc : Int
    mnc : Int
    language : String
    country : String
    orientation : Int
    touchscreen : Int
    density : Int
    keyboard : Int
    navigation : Int
    input_flags : Int
    screen_width : Int
    screen_height : Int
    sdk_version : Int
    screen_layout : Int
    ui_mode : Int
    smallest_screen_width_dp : Int
    screen_width_dp : Int
    screen_height_dp : Int
    locale_script : String
    color_mode : Int
    raw : Bytes
    }

    一个资源配置(AOSP ResTable_config)。 常用 qualifier 字段逐项解出;未覆盖字段完整保留在 raw(原始 config 字节)中, 按字段偏移解码,size 大于 36 时追加 localeScript 等扩展字段(降级见 docs/API.md)。

    ResConfig::from_qualifiers

    fn ResConfig::from_qualifiers(s : String) -> ResConfig raise ArscError

    按限定符文本构造设备/资源配置(aapt2 qualifier 子集): mcc310、mnc004、en、en-rUS、sw600dp、w1024dp、h768dp、 port/land、night/notnight、car/desk/television/watch、 ldpi/mdpi/hdpi/xhdpi/xxhdpi/xxxhdpi/nodpi/anydpi/NNNdpi。 未知 token 报 BadQualifier(token);空串返回默认配置。

    ResConfig::from_qualifiers_ext

    fn ResConfig::from_qualifiers_ext(s : String) -> ResConfig raise ArscError

    限定符扩展版:在 from_qualifiers 子集基础上增加 vNN(sdk_version)、long/notlong、round/notround、 widecg/nowidecg、highdr/lowdr、 b+<lang>[+<region>](BCP47 子集)、 navhidden/navexposed、keysexposed/keyssoft/keyshidden、 qwerty/12key、dpad/wheel/nonav、 finger/nofinger、stylus/nostylus、trackball/notouch。 未知 token 仍复用 BadQualifier。

    ResConfig::is_better_than

    fn ResConfig::is_better_than(self : ResConfig, other : ResConfig, device : ResConfig) -> Bool

    逐维「更优」比较:返回 1 = self 更优,-1 = other 更优,0 = 平手。 前提:两者均已通过 matches(调用方保证)。

    ResConfig::is_default

    fn ResConfig::is_default(self : ResConfig) -> Bool

    该配置是否为默认配置(全部 qualifier 字段为 0)。 多配置选择策略据此实现「默认配置优先」(见 ResTable::lookup)。

    ResConfig::matches

    fn ResConfig::matches(self : ResConfig, device : ResConfig) -> Bool

    该配置能否作用于给定设备配置(self 为资源侧,全零/未指定维度 = 任意)。

    ResDataType

    pub(all) enum ResDataType {
    Null
    Reference
    Attribute
    String
    Float
    Dimension
    Fraction
    DynamicReference
    DynamicAttribute
    IntDec
    IntHex
    IntBoolean
    IntColorArgb8
    IntColorRgb8
    IntColorArgb4
    IntColorRgb4
    Unknown(Int)
    }

    Res_value.dataType 的完整枚举(AOSP Res_value::TYPE_* 全集)。 Unknown 保留原始类型字节以便上层降级而不丢失信息。

    语义标注:DynamicReference / DynamicAttribute(0x07/0x08)是需要经 RES_TABLE_LIBRARY_TYPE 动态包映射改写后才能使用的引用;本库不做改写, 只按原样保留 id 并如实标注(见 docs/API.md 降级项)。

    ResEntry

    pub(all) struct ResEntry {
    key : Int
    key_name : String
    flags : Int
    value : ResEntryValue
    }

    单个资源条目(AOSP ResTable_entry)。 key 为键名池下标,key_name 为解码后的键名(便捷冗余); flags 保留 FLAG_COMPLEX/FLAG_PUBLIC/FLAG_WEAK/FLAG_COMPACT 原始位。

    ResEntryValue

    pub(all) enum ResEntryValue {
    Simple(ResValue)
    Complex(ResBag)
    }

    条目取值:简单值(含 compact 编码)或复杂 bag。

    ResLibrary

    pub(all) struct ResLibrary {
    package_id : Int
    name : String
    }

    RES_TABLE_LIBRARY_TYPE 动态包映射项(仅供展示;本库不改写动态引用)。

    ResLookup

    pub(all) struct ResLookup {
    package_name : String
    type_name : String
    entry_name : String
    type_id : Int
    entry_id : Int
    config : ResConfig
    entry : ResEntry
    }

    资源 id 查询命中:包/类型/条目名 + 最优配置与该配置下的条目。

    ResMap

    pub(all) struct ResMap {
    name : UInt
    value : ResValue
    }

    复杂条目(bag)内的一对 name/value 映射(AOSP ResTable_map)。 name 通常是属性资源 id;attr bag 中可能是 ATTR_TYPE(0x01000000)等内部 id。

    ResPackage

    pub(all) struct ResPackage {
    id : Int
    name : String
    type_id_offset : Int
    type_pool : StringPool
    key_pool : StringPool
    types : Array[ResTypeSpec]
    libraries : Array[ResLibrary]
    }

    一个资源包(AOSP ResTable_package)。 type_pool / key_pool 为类型名池与键名池;types 按 chunk 顺序排列。

    ResTable

    pub(all) struct ResTable {
    global_pool : StringPool
    packages : Array[ResPackage]
    package_count : Int
    }

    resources.arsc 解析结果:全局值字符串池 + 包数组。 package_count 为 ResTable_header.packageCount 声明值(校验实际包数不超过它)。

    ResTable::dynamic_ref_view

    fn ResTable::dynamic_ref_view(self : ResTable, origin_id : UInt) -> DynamicRefView

    动态引用映射视图(W5):从 origin_id 中提取运行时包字节(高 8 位), 然后在 library 映射中查找对应的名字。只暴露映射事实,不改写引用。 未命中时 library_name=None(值化降级)。

    ResTable::eval_theme_attr

    fn ResTable::eval_theme_attr(self : ResTable, theme_id : UInt, attr_id : UInt, device : ResConfig) -> ResValue raise ArscError

    求值主题里的 ?attr 引用:在压平后的 theme bag 中找 attr_id, 若其值是 Attribute/DynamicAttribute(即 ?attr/…)则沿链继续; 普通 Reference(@…)视为终点返回值。 缺失 → AttrMissing;引用链成环 → AttrCycle。

    ResTable::find_id

    fn ResTable::find_id(self : ResTable, type_name : String, entry_name : String) -> UInt?

    按名字查资源 id:(类型名, 条目名) → id。

    多个包命中时取 packages 顺序中的第一个;同名类型存在于多个类型 id 时 (如 framework 的 attr 与 ^attr-private)按类型 id 升序取第一个命中。 未命中返回 None。

    ResTable::flatten_bag

    fn ResTable::flatten_bag(self : ResTable, id : UInt, device : ResConfig) -> FlattenedBag raise ArscError

    压平一个复杂条目(bag)的 parent 继承链:自根向子覆盖同名 map。 目标不存在/是简单值 → BagNotComplex;parent 缺失 → BagMissingParent; parent 链成环 → BagCycle。全部不 panic。

    ResTable::format_value

    fn ResTable::format_value(self : ResTable, value : ResValue) -> String

    Res_value → 人类可读文本(aapt2 dump resources 风格)。

    渲染规则(文档化):dimension/fraction/float 用 6 位小数(如 48.000000dp、 3.000000%);颜色为小写 #aarrggbb/#rrggbb/#argb/#rgb(AOSP printf 最小宽度语义,高位非零时输出更多数位);布尔 true/false; 整数十进制、十六进制 0x%08x;字符串取原值(aapt2 在 dump 中会额外加引号); 引用渲染为 @type/name(表内可解析时)或 @0x%08x;动态引用以 (dynamic) 后缀如实标注(不改写 id)。

    ResTable::library_by_id

    fn ResTable::library_by_id(self : ResTable, id : Int) -> ResLibrary?

    在全部包的 libraries 中查找给定 package_id 的共享库映射项。 跨包顺序扫描(所有 ResPackage.libraries 拼接搜索); 未命中返回 None(值化降级,不抛错)。

    ResTable::lookup

    fn ResTable::lookup(self : ResTable, id : UInt) -> ResLookup?

    资源 id(0xPPTTNNNN)→ (package, type, name, 最优值) 查询。

    选择策略(文档化):默认配置优先——同一 (包,类型,条目) 存在多个 ResTable_type 配置变体时,返回 qualifier 全零(ResConfig::is_default)的 配置中的条目;无默认配置时返回 chunk 顺序中的第一个命中配置。 降级:不做 aapt2 式 locale/density/SDK 的最优匹配(qualifier 选择属降级项,见 docs/API.md)。 未命中返回 None(包/类型/条目任一缺失均视为未命中,不报错)。

    ResTable::lookup_all

    fn ResTable::lookup_all(self : ResTable, id : UInt) -> Array[ResLookup]

    资源 id 的全部配置命中(按 chunk 顺序)。用于观察多配置差异。

    ResTable::lookup_with

    fn ResTable::lookup_with(self : ResTable, id : UInt, device : ResConfig) -> ResLookup?

    资源 id 在给定设备配置下的最优命中(aapt2 式 qualifier 最优匹配)。 无配置匹配设备时返回 None(上层可回退默认配置)。

    ResTable::package_by_id

    fn ResTable::package_by_id(self : ResTable, id : Int) -> ResPackage?

    按包 id 查找包。

    ResTable::resolve_id

    fn ResTable::resolve_id(self : ResTable, id : UInt) -> String

    资源 id → 人类可读值:跟随引用链到最终值(无环检测,深度上限 16 保护)。

    • 简单值:返回 format_value 文本(字符串直接是其值,如 app_name → MyApp)。
    • 引用:递归解析;超深(> 16)以 @0x%08x (too deep) 标注。无 visited 集环检测—— 引用链环检测仅 bag/attr 链(flatten_bag / eval_theme_attr)覆盖;单表引用链 若成环则依赖深度上限保护。
    • 复杂条目(bag):渲染为 @type/name(bag 无法压平成单一文本,属文档化降级)。
    • 未命中:@0x%08x。不抛错——全部缺口以文本如实标注。

    ResTableSet

    pub(all) struct ResTableSet {
    tables : Array[ResTable]
    }

    多表联合资源表(W6):显式提供框架/共享库资源表通道, 使 0x01… 引用在调用方提供框架表时可解析。 单表 API 语义不变;调用方负责组合(不自动加载/内置框架资源)。

    ResTypeConfig

    pub(all) struct ResTypeConfig {
    id : Int
    flags : Int
    config : ResConfig
    entries : Array[ResEntry?]
    }

    一个(类型, 配置)资源组(AOSP ResTable_type)。 flags 保留 FLAG_SPARSE(0x01)/FLAG_OFFSET16(0x02) 原始位; entries 下标即 entry index,None 表示该配置下此条目不存在(NO_ENTRY)。

    ResTypeSpec

    pub(all) struct ResTypeSpec {
    id : Int
    types_count : Int
    entry_count : Int
    spec_flags : Array[UInt]
    configs : Array[ResTypeConfig]
    }

    一个资源类型(AOSP ResTable_typeSpec + 其全部配置变体)。 id 为 chunk 内原始类型 id(1-based);资源 id 中的类型字节 = id + type_id_offset。 spec_flags 为每条目的配置掩码(含 SPEC_PUBLIC=0x40000000)。

    ResValue

    pub(all) struct ResValue {
    data_type : ResDataType
    data : UInt
    }

    单个 Res_value:32 位数据 + 数据类型。

    ResolveOrigin

    pub(all) enum ResolveOrigin {
    Literal
    FromId
    FromName
    FromTheme
    Unresolved(String)
    }

    属性值解析路径标注。

    ResolvedAttr

    pub(all) struct ResolvedAttr {
    text : String
    id : UInt?
    origin : ResolveOrigin
    }

    属性值解析结果:text 为解析后的人类可读值;id 为识别到的资源 id(非引用为 None); origin 标注解析路径或未解析原因。

    StringEncoding

    pub(all) enum StringEncoding {
    Utf8
    Utf16
    }

    字符串池编码;UTF8_FLAG(0x100) 置位为 Utf8,否则 Utf16。

    StringPool

    pub(all) struct StringPool {
    encoding : StringEncoding
    strings : Array[String]
    styles : Bytes
    }

    字符串池视图;strings 下标与 chunk 内 string index 一一对应。 styles 保留原始字节,暂不做样式解析。

    ValueType

    pub(all) enum ValueType {
    Null
    Reference
    Attribute
    String
    Float
    Dimension
    Fraction
    IntDec
    IntHex
    IntBoolean
    Unknown(Int)
    }

    Res_value.dataType 的枚举化子集;Unknown 保留原始字节以便上层降级。

    XmlAttribute

    pub(all) struct XmlAttribute {
    ns : String?
    name : String
    raw_value : String?
    value_type : ValueType
    res0 : Byte
    raw_data : UInt
    line : Int
    }

    单个 typed attribute。 raw_data 保留 32 位原始 data;本库不解释 @ref / ?attr 等资源引用语义。

    XmlNode

    pub(all) struct XmlNode {
    line : Int
    ns : String?
    name : String
    attributes : Array[XmlAttribute]
    children : Array[Int]
    parent : Int?
    chunk : ChunkType
    }

    文档树节点。children / parent 使用 AxmlDoc::nodes() 的索引, 避免递归结构带来的所有权与生命周期歧义。

    XmlNode::attrs

    fn XmlNode::attrs(self : XmlNode) -> Array[XmlAttribute]

    返回某节点的属性列表(保持 chunk 内原始顺序,不做去重、不做命名空间解析)。

    encode

    fn encode(doc : AxmlDoc) -> Bytes raise AxmlError

    AXML 格式级回编(M8-2):字符串池 + resource map + 元素/属性/CDATA 节点。

    往返律定义为 parse(encode(doc)) 与规范化后的 doc 语义等价,不要求与 aapt2 产物逐字节一致。命名空间声明 chunk 不做重建:AxmlDoc 只保留解析后 的 ns URI,不保留前缀与声明位置,解析侧本就跳过这两类 chunk。

    • 参数:doc 来自 parse 或上层构造,pool.strings 为已解码字符串。
    • 返回:完整 AXML 字节流(含 RES_XML_TYPE 外层头),编码为独立拷贝。
    • 错误:样式块非空、非元素/非 CDATA 节点 → VendorVariant;节点引用的 字符串不在池中或节点索引非法 → BadStringPool / InvalidNodeIndex; 字符串长度超过 UTF-8 池前缀上限(0x7FFF 字节)→ BadStringPool。

    encode_arsc

    fn encode_arsc(table : ResTable) -> Bytes raise ArscError

    resources.arsc 值级回编(W9):ResTable → Bytes,补全「解析→修改→回编」闭环。

    往返律定义为 parse_arsc(encode_arsc(t)) 与规范化后的 t 语义等价(同包/ 类型/条目与值内容,键名池、类型池、全局池字符串一致),不要求与 aapt2 产物字节级一致(值级回编,非构建期资源编译)。

    写出口径(文档化,见 docs/API.md D14):
    • entry offsets 一律写 dense u32 槽(ResTypeConfig.flags 位 0x01/0x02 置位 的 sparse/offset16 原始布局显式拒绝,不静默改写标志位);
    • compact 条目(ResEntry.flags & 0x0008)显式拒绝(dense 规范化会丢失 compact 标志位);
    • ResConfig.raw:raw.length() >= size 时取前 size 字节原样回写; 空/短 raw(构造型配置)按已解码 qualifier 字段序列化 size 字节镜像 (size 字段自描述 + 其余零填充),见 encode_config_bytes 与 docs/API.md D14;
    • 字符串池按解析侧编码(UTF-8/UTF-16)与顺序重建。

    拒绝一律复用 BadTable(0, detail),不新增错误变体(API 冻结硬约束)。

    parse

    fn parse(data : Bytes) -> AxmlDoc raise AxmlError

    解析一段完整 AXML 字节流(含 RES_XML_TYPE 头,不含 ZIP 封装)为文档树。

    • 参数:data 为只读字节切片,调用方持有所有权,本函数不转移、不缓存; styles 原始字节在返回值中是独立拷贝。
    • 返回:AxmlDoc 纯值,无句柄、无需释放。
    • 错误:越界 / 非法 headerSize / 非法字符串索引均以 AxmlError 传播并带 字节偏移。偏移语义:UnexpectedEof(offset) 指被截断项的起始偏移; BadChunkType / BadHeaderSize 的 offset 指 chunk 起始(外层头部为 0)。
    • 线程:无可变全局状态,可并发调用;返回值为只读,可跨线程共享。
    • 降级策略(见 docs/API.md §1):未知 chunk 类型按 headerSize/size 跳过; 厂商变体布局(attributeStart/attributeSize < 20)以 VendorVariant 报告; 未知字符串池标志位以 UnsupportedEncoding 报告。
    • 非目标:不解析资源引用、不提供 manifest 语义、不处理 resources.arsc (格式级回编见 encode,不做 XML 文本编译与打包)。
    • TODO:res0/data 的语义解释(当前按 docs/API.md 保留原值,语义确定后再实现)。

    parse_arsc

    fn parse_arsc(data : Bytes) -> ResTable raise ArscError

    解析一段完整 resources.arsc 字节流(含 RES_TABLE_TYPE 头,不含 ZIP 封装)。

    • 参数:data 只读,调用方持有所有权,本函数不转移、不缓存。
    • 返回:ResTable 纯值;无句柄、无需释放、可跨线程共享。
    • 错误:ArscError,带字节偏移。偏移语义与 AXML 侧一致:Eof(off) 指被截断项 起始偏移;BadChunk/BadHeader/BadTable 的 offset 指出错结构起始。
    • 校验:外层 header、全局字符串池、包头、类型池/键名池、typeSpec/type 的 entry offsets(dense u32 / FLAG_OFFSET16 u16 / FLAG_SPARSE 二分表)与 entry 边界均按 AOSP LoadedArsc.cpp 校验;违反即报错,不 panic。
    • 降级:未知 chunk(如 overlayable/staged alias)按 headerSize/size 跳过; 未知 Res_value.dataType 保留在 Unknown;动态引用不改写(见 docs/API.md §降级)。

    resolve_attr_value

    fn resolve_attr_value(doc : AxmlDoc, table : ResTable, attr : XmlAttribute) -> ResolvedAttr

    AXML 属性值 → 人类可读值(AXML 文档 + 资源表联合解析)。

    解析顺序(文档化):
    1. value_type 为 Reference/Attribute/动态引用:按 raw_data 中的 0xPPTTNNNN 解析(FromId,id 是权威来源);
    2. raw_value 形如 @type/name / @pkg:type/name / @0x...:按名字/十六进制 定位后解析(FromName / FromId),覆盖 @string/xxx 文本形式输入;
    3. value_type 为 String:取 AXML 文档字符串池中的字面量(Literal);
    4. 其余类型(int/bool/color/dimension 等):按 format_value 文本化(Literal)。

    任何缺口(id 不在表、名字未命中、字符串索引越界)都不抛错,返回 Unresolved(原因) 并保留可读的原始文本。不解析 ?attr/theme 引用链 (属性引用的语义解析属降级项,见 docs/API.md)。

    resolve_attr_value_multi

    fn resolve_attr_value_multi(doc : AxmlDoc, set : ResTableSet, attr : XmlAttribute) -> ResolvedAttr

    多表联合属性解析(W6):在 ResTableSet.tables 中按引用 id 的包字节选表, 找到后走 resolve_attr_value;全部未命中 → Unresolved,不抛错。 覆盖三条路径:① raw_data 为 id 的引用类型(Reference/Attribute/动态引用); ② raw_value 形如 @type/name / @0x... 的文本引用(Null/String/IntBoolean 等均可); ③ 纯字面量(不依赖任何表,直接返回)。

    resolve_attr_value_with_config

    fn resolve_attr_value_with_config(doc : AxmlDoc, table : ResTable, attr : XmlAttribute, device : ResConfig) -> ResolvedAttr

    带设备配置的属性值解析(W3 修复):与 resolve_attr_value 同构,但引用取值 主路径改走 lookup_best——lookup_with(id, device)(qualifier 最优匹配) 命中优先,未命中回退 lookup(默认配置优先),再未命中 Unresolved。 非 --config 场景请继续使用 resolve_attr_value(既有语义冻结不变)。 字面量路径(String/数值等)与配置无关,行为同 resolve_attr_value。

    resolve_attr_value_with_theme

    fn resolve_attr_value_with_theme(doc : AxmlDoc, table : ResTable, attr : XmlAttribute, theme_id : UInt, device : ResConfig) -> ResolvedAttr

    主题感知属性解析(W4):与 resolve_attr_value 同构,但对 ?attr(Attribute/ DynamicAttribute)值沿 theme_id 指定的 theme bag 链求值(eval_theme_attr)。 其他类型(Reference、String、Literal 等)行为与 resolve_attr_value 完全相同。 求值失败(theme 缺失/非 bag/parent 链成环/attr 缺失或成环)→ 捕获并降级为 Unresolved(原因),保持不抛错契约(签名不含 raise)。