Skip to content
mt-altsPublic

About

AXML Reader

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

AxmlNet

.NET Standard 2.1 MIT License

AxmlNet is a high-performance .NET Standard 2.1 library designed to decode Android Binary XML (AXML) files and extract them directly from APK or APKS (Split APK) containers. It supports both binary and plain text XML files with advanced format detection and optimized performance.

🚀 Features

  • Smart Decoding: Automatically detects and decodes Binary AXML or plain text XML formats transparently.
  • APK & APKS Support: Extract XML files seamlessly from standard .apk files and .apks (Split APK) bundles.
  • Specialized Manifest Extraction: Dedicated ApkManifestExtractor for robust extraction and conversion of AndroidManifest.xml files, including handling multi-APK split containers.
  • High-Performance Sniffing: Utilizes ReadOnlySpan<byte> and BinaryPrimitives for zero-allocation, fast header parsing and format identification.

📦 Installation

Install via the .NET CLI:

dotnet add package AxmlNet

🛠 Usage Examples

1. ApkManifestExtractor

Extract and convert manifests from APK or APKS containers, including all splits in a .apks bundle:

// Extract all manifests (for example, from an .apks split APK bundle)
var manifests = ApkManifestExtractor.ExtractBinaryManifests("app.apks");

foreach (var manifest in manifests)
{
    Console.WriteLine($"Manifest extracted from: {manifest.SourceName}");
    string xml = manifest.ConvertToXml();
    Console.WriteLine(xml);
}

// Extract and convert the main manifest from a single APK file
string mainManifestXml = ApkManifestExtractor.ConvertManifestToXml("app.apk");
Console.WriteLine(mainManifestXml);

2. ApkBinaryXmlExtractor

Extract any XML file (layouts, configs) from an APK or APKS:

string xmlContent = ApkBinaryXmlExtractor.GetXmlContent("app.apk", "res/xml/network_security_config.xml");
Console.WriteLine(xmlContent);

3. AxmlConverter

Manually convert a binary AXML stream to a formatted XML string:

using var stream = File.OpenRead("binary_layout.xml");
var options = new AxmlConverterOptions { Indent = true, WriteXmlDeclaration = true };

string xml = AxmlConverter.ConvertToXmlString(stream, options);
Console.WriteLine(xml);

🔍 Technical Details

Binary Header Validation

The library identifies Binary AXML files by validating the Android resource chunk header (ResChunk_header):

  • Chunk Type: 0x0003 (RES_XML_TYPE)
  • Header Size: 0x0008
  • Data Integrity: The internal totalSize field is checked to ensure consistency with the actual byte stream length.

Encoding Heuristics

For non-binary files, AxmlNet applies a heuristic approach to determine the text encoding:

  1. Attempts to detect standard Byte Order Marks (BOM) for UTF-8 and UTF-16 (LE/BE).
  2. If BOM is absent, analyzes the first 512 bytes for null-byte frequency.
  3. If null bytes exceed 10% within the sample, assumes UTF-16 LE encoding; otherwise, defaults to UTF-8.

⚙️ Requirements

  • .NET Standard 2.1
  • Dependencies: System.Memory, System.IO.Compression

Licensed under the MIT License.

About

AXML Reader

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages