🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More
Socket
Book a DemoSign in
Socket

@taoya7/apk-parse

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@taoya7/apk-parse

A TypeScript library for parsing Android APK files

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

@taoya7/apk-parse

npm version

一个用于解析 Android APK 文件的 TypeScript 库。

功能特性

  • 解析 APK 基本信息(包名、版本、应用名称等)
  • 提取应用图标并转换为 base64 格式
  • 获取权限列表
  • 支持文件路径和 Buffer 两种输入方式
  • 支持资源混淆的 APK 文件
  • 完整的 TypeScript 类型支持

安装

npm install @taoya7/apk-parse

快速开始

基本用法

import { parseApk } from '@taoya7/apk-parse'

// 从文件路径解析
const info = await parseApk('/path/to/app.apk')

console.log(info.packageName)      // com.example.app
console.log(info.versionName)      // 1.0.0
console.log(info.applicationLabel) // 我的应用
console.log(info.icon)             // data:image/png;base64,...

从 Buffer 解析

import { parseApk } from '@taoya7/apk-parse'
import * as fs from 'fs/promises'

const buffer = await fs.readFile('/path/to/app.apk')
const info = await parseApk(buffer)

高级用法

import { createApkParser } from '@taoya7/apk-parse'

const { info, parser } = await createApkParser('/path/to/app.apk')

// 获取 APK 中的文件列表
const files = await parser.getFileList()

// 读取 APK 中的文件
const fileContent = await parser.readFile('assets/config.json')

// 单独获取图标
const iconBuffer = await parser.getIcon()
const iconBase64 = await parser.getIconBase64()

返回数据结构

interface ApkInfo {
  packageName: string      // 包名 (例如: com.example.app)
  versionCode: number      // 版本号 (整数)
  versionName: string      // 版本名称 (例如: "1.0.0")
  applicationLabel: string // 应用名称
  minSdkVersion: number    // 最低 SDK 版本
  targetSdkVersion: number // 目标 SDK 版本
  compileSdkVersion?: number // 编译 SDK 版本 (可选)
  permissions: string[]    // 权限列表
  icon?: string            // 应用图标 base64 (data URI 格式)
}

示例输出

Package Name:     com.github.metacubex.clash.meta
Version Code:     211016
Version Name:     2.11.16.Meta
Application:      Clash Meta for Android
Min SDK:          21
Target SDK:       35
Compile SDK:      35
Permissions:      9
Icon:             data:image/png;base64,iVBORw0KGgo...

在 HTML 中使用图标

<img :src="info.icon" alt="App Icon" />

API 参考

parseApk(input, options?)

快速解析 APK 文件。

  • input: 文件路径 (string) 或 Buffer
  • options: 可选配置
  • 返回: Promise<ApkInfo>

createApkParser(input, options?)

创建解析器实例,可进行更多操作。

  • input: 文件路径 (string) 或 Buffer
  • options: 可选配置
  • 返回: Promise<{ info: ApkInfo, parser: ApkParser }>

ApkParser 类方法

  • parseFromFile(filePath): 从文件解析
  • parseFromBuffer(buffer): 从 Buffer 解析
  • getIcon(): 获取图标 Buffer
  • getIconBase64(): 获取图标 base64 字符串
  • getFileList(): 获取文件列表
  • readFile(path): 读取指定文件

开发

# 安装依赖
npm install

# 运行测试
npm run test

# 构建
npm run build

技术实现

  • 使用 jszip 解压 APK 文件
  • 实现了 Android 二进制 XML (AXML) 解析器
  • 实现了 resources.arsc 资源表解析器
  • 支持递归解析资源引用

License

MIT

Keywords

apk

FAQs

Package last updated on 24 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts