• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extracts information from APK files.

Warning

This project along with other ones in OpenSTF organisation is provided as is for community, without active development.

You can check any other forks that may be actively developed and offer new/different features here.

Active development has been moved to DeviceFarmer organisation.

adbkit-apkreader

adbkit-apkreader provides a Node.js API for extracting information from Android APK files. For example, it allows you to read the AndroidManifest.xml of an existing APK file.

Requirements

  • Node.js 4.x or newer. Older versions are not supported.

Getting started

Install via NPM:

npm install --save adbkit-apkreader

Examples

Read the AndroidManifest.xml of an APK

const util = require('util')
const ApkReader = require('adbkit-apkreader')

ApkReader.open('HelloApp.apk')
  .then(reader => reader.readManifest())
  .then(manifest => console.log(util.inspect(manifest, { depth: null })))

API

ApkReader

ApkReader.MANIFEST

A convenience constant with the value 'AndroidManifest.xml'. Can use useful with other API methods in certain circumstances.

ApkReader.open(file)

Alternate syntax to manually creating an ApkReader instance. Currently, only files are supported, but support for streams might be added at some point.

Note that currently this method cannot reject as the file is opened lazily, but this may change in the future and therefore returns a Promise for fewer future compatibility issues. On a related node, calling the constructor directly is still possible, but discouraged.

  • file The path to the APK file.
  • Returns: A Promise that resolves with an ApkReader instance.

reader.readContent(path)

Reads the content of the given file inside the APK.

  • path The path to the file. For example, giving 'META-INF/MANIFEST.MF' as the path would read the content of that file.
  • Returns: A Promise that resolves with a Buffer containing the full contents of the file.

reader.readManifest()

Reads and parses the AndroidManifest.xml file inside the APK and returns a simplified object representation of it.

  • Returns: A Promise that resolves with a JavaScript Object representation of the manifest. See example output below. Rejects on error (e.g. if parsing was unsuccessful).
{ versionCode: 1,
  versionName: '1.0',
  package: 'com.example.hello.helloapp.app',
  usesPermissions: [],
  permissions: [],
  permissionTrees: [],
  permissionGroups: [],
  instrumentation: null,
  usesSdk: { minSdkVersion: 7, targetSdkVersion: 19 },
  usesConfiguration: null,
  usesFeatures: [],
  supportsScreens: null,
  compatibleScreens: [],
  supportsGlTextures: [],
  application:
   { theme: 'resourceId:0x7f0b0000',
     label: 'resourceId:0x7f0a000e',
     icon: 'resourceId:0x7f020057',
     debuggable: true,
     allowBackup: true,
     activities:
      [ { label: 'resourceId:0x7f0a000e',
          name: 'com.example.hello.helloapp.app.MainActivity',
          intentFilters:
           [ { actions: [ { name: 'android.intent.action.MAIN' } ],
               categories: [ { name: 'android.intent.category.LAUNCHER' } ],
               data: [] } ],
          metaData: [] } ],
     activityAliases: [],
     launcherActivities:
      [ { label: 'resourceId:0x7f0a000e',
          name: 'com.example.hello.helloapp.app.MainActivity',
          intentFilters:
           [ { actions: [ { name: 'android.intent.action.MAIN' } ],
               categories: [ { name: 'android.intent.category.LAUNCHER' } ],
               data: [] } ],
          metaData: [] } ],
     services: [],
     receivers: [],
     providers: [],
     usesLibraries: [] } }

reader.readXml(path)

Reads and parses the binary XML file at the given path inside the APK file. Attempts to be somewhat compatible with the DOM API.

  • path The path to the binary XML file inside the APK. For example, giving 'AndroidManifest.xml' as the path would parse the manifest (but you'll probably want to use reader.readManifest() instead).
  • Returns: A Promise that resolves with a JavaScript Object representation of the root node of the XML file. All nodes including the root node have the properties listed below. Rejects on error (e.g. if parsing was unsuccessful).
    • namespaceURI The namespace URI or null if none.
    • nodeType 1 for element nodes, 2 for attribute nodes, and 4 for CData sections.
    • nodeName The node name.
    • For element nodes, the following additional properties are present:
      • attributes An array of attribute nodes.
      • childNodes An array of child nodes.
    • For attribute nodes, the following additional properties are present:
      • name The attribute name.
      • value The attribute value, if possible to represent as a simple value.
      • typedValue May be available when the attribute represents a complex value. See android.util.TypedValue for more information. Has the following properties:
        • value The value, which might null, String, Boolean, Number or even an Object for the most complex types.
        • type A String representation of the type of the value.
        • rawType A raw integer presentation of the type of the value.
    • For CData nodes, the following additional properties are present:
      • data The CData.
      • typedValue May be available if the section represents a more complex type. See above for details.

reader.usingFileStream(path, action)

Opens a readable Stream to the given file inside the APK and runs the given action with it. The APK file is kept open while the action runs, allowing you to process the stream. Once the action finishes, the APK will be automatically closed.

  • path The path to the file. For example, giving 'META-INF/MANIFEST.MF' as the path would open that file.
  • action(stream) A function that processes the stream somehow. MUST return a Promise that resolves when you're done processing the stream. The value that the Promise resolves with will also be the value that usingFileStream() resolves with.
    • stream A readable Stream of the file content. You should either consume or end the stream yourself before resolving the action.
  • Returns: A Promise that resolves with whatever action resolves with.

More information

Contributing

See CONTRIBUTING.md.

License

See LICENSE.

Copyright ยฉ The OpenSTF Project. All Rights Reserved.

More Repositories

1

stf

Control and manage Android devices from your browser.
JavaScript
13,308
star
2

minicap

Stream real-time screen capture data out of Android devices.
C++
1,715
star
3

adbkit

A pure Node.js client for the Android Debug Bridge.
CoffeeScript
826
star
4

minitouch

Minimal multitouch event producer for Android.
C
630
star
5

ios-minicap

iOS Minicap provides a socket interface for streaming realtime screen capture data out of iOS devices.
C++
433
star
6

STFService.apk

Monitor and perform various actions on your Android device. Not meant for actual user devices.
Java
235
star
7

android-libjpeg-turbo

Standalone Android.mk configuration for libjpeg-turbo.
Makefile
152
star
8

stf-appium-example

Run Appium test on OpenSTF Device
Ruby
110
star
9

stf-device-db

A JSON-based database of smartphones, tablets and wearables.
Makefile
73
star
10

docker-aosp

Docker images for checking out AOSP branches and building external code inside the source tree.
Shell
50
star
11

adbkit-monkey

A Node.js interface to the Android monkey tool.
CoffeeScript
47
star
12

setup-examples

STF Setup Examples using Vagrant and Docker
45
star
13

minirev

Minimal reverse port forwarding implementation for Android.
C
45
star
14

adbkit-logcat

A Node.js interface for working with Android's logcat output.
JavaScript
41
star
15

RotationWatcher.apk

Small CLI app for tracking Android rotation changes in real time.
Java
25
star
16

openstf.github.io

Public site for STF
JavaScript
22
star
17

stf-syrup

Provides a minimal Promise-based dependency injection framework for Node.js.
CoffeeScript
20
star
18

node-minicap

A minicap driver for Node.
JavaScript
15
star
19

stf-appium

Placeholder repository for any future stf-appium integration
11
star
20

docker-openstf-base

ABANDONED in favor of doing the whole thing in the main Dockerfile of openstf/stf.
6
star
21

stf-appstore-db

A small collection of different app stores for STF.
Makefile
6
star
22

docker-ambassador

Our own glorious ambassador to avoid external breakage.
Shell
3
star
23

stf-browser-db

A simple browser database for STF.
Makefile
3
star
24

eslint-config-stf

STF - ESLint Shareable Config
JavaScript
1
star