Parse Android binary XML (AXML) and resources.arsc into readable node trees, attributes, string pools and resolved resource values, with format-level encoders.
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.xmlpub 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)pub suberror AxmlError {
UnexpectedEof(Int)
BadChunkType(Int, UInt)
BadHeaderSize(Int, Int)
BadStringPool(Int, String)
InvalidStringIndex(Int)
InvalidNodeIndex(Int)
UnsupportedEncoding(String)
VendorVariant(String)
} derive(Debug)pub(all) struct AxmlDoc {
pool : StringPool
nodes : Array[XmlNode]
roots : Array[Int]
resource_map : Array[UInt]
}pub(all) enum ChunkType {
StringPool
XmlTree
StartNamespace
EndNamespace
StartElement
EndElement
CData
ResourceMap
}pub(all) struct DynamicRefView {
origin_id : UInt
runtime_package_id : Int
library_name : String?
}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
}pub(all) enum ResDataType {
Null
Reference
Attribute
String
Float
Dimension
Fraction
DynamicReference
DynamicAttribute
IntDec
IntHex
IntBoolean
IntColorArgb8
IntColorRgb8
IntColorArgb4
IntColorRgb4
Unknown(Int)
}pub(all) struct ResLibrary {
package_id : Int
name : String
}pub(all) struct ResPackage {
id : Int
name : String
type_id_offset : Int
type_pool : StringPool
key_pool : StringPool
types : Array[ResTypeSpec]
libraries : Array[ResLibrary]
}pub(all) struct ResTable {
global_pool : StringPool
packages : Array[ResPackage]
package_count : Int
}fn ResTable::flatten_bag(self : ResTable, id : UInt, device : ResConfig) -> FlattenedBag raise ArscErrorpub(all) struct ResTypeSpec {
id : Int
types_count : Int
entry_count : Int
spec_flags : Array[UInt]
configs : Array[ResTypeConfig]
}pub(all) enum ResolveOrigin {
Literal
FromId
FromName
FromTheme
Unresolved(String)
}pub(all) enum StringEncoding {
Utf8
Utf16
}pub(all) enum ValueType {
Null
Reference
Attribute
String
Float
Dimension
Fraction
IntDec
IntHex
IntBoolean
Unknown(Int)
}pub(all) struct XmlAttribute {
ns : String?
name : String
raw_value : String?
value_type : ValueType
res0 : Byte
raw_data : UInt
line : Int
}pub(all) struct XmlNode {
line : Int
ns : String?
name : String
attributes : Array[XmlAttribute]
children : Array[Int]
parent : Int?
chunk : ChunkType
}fn resolve_attr_value_with_config(doc : AxmlDoc, table : ResTable, attr : XmlAttribute, device : ResConfig) -> ResolvedAttrfn resolve_attr_value_with_theme(doc : AxmlDoc, table : ResTable, attr : XmlAttribute, theme_id : UInt, device : ResConfig) -> ResolvedAttrInstall
Download zipParse Android binary XML (AXML) and resources.arsc into readable node trees, attributes, string pools and resolved resource values, with format-level encoders.