Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

adbkit-apkreader

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adbkit-apkreader - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

CHANGELOG.md

115

lib/apkreader.js
(function() {
var ApkReader, BinaryXmlParser, ManifestParser, Zip;
var ApkReader, BinaryXmlParser, ManifestParser, Promise, Zip;
Zip = require('adm-zip');
Zip = require('yauzl');
Promise = require('bluebird');
ManifestParser = require('./apkreader/parser/manifest');

@@ -15,39 +17,94 @@

ApkReader.readFile = function(apk) {
return new ApkReader(apk);
ApkReader.open = function(apk) {
return Promise.resolve(new ApkReader(apk));
};
function ApkReader(apk) {
var err;
this.apk = apk;
try {
this.zip = new Zip(this.apk);
} catch (_error) {
err = _error;
if (typeof err === 'string') {
throw new Error(err);
} else {
throw err;
}
}
}
ApkReader.prototype.readManifestSync = function() {
var manifest;
if (manifest = this.zip.getEntry(MANIFEST)) {
return new ManifestParser(manifest.getData()).parse();
} else {
throw new Error("APK does not contain '" + MANIFEST + "'");
}
ApkReader.prototype._open = function() {
return Promise.fromCallback((function(_this) {
return function(callback) {
return Zip.open(_this.apk, {
lazyEntries: true
}, callback);
};
})(this));
};
ApkReader.prototype.readXmlSync = function(path) {
var file;
if (file = this.zip.getEntry(path)) {
return new BinaryXmlParser(file.getData()).parse();
} else {
throw new Error("APK does not contain '" + path + "'");
}
ApkReader.prototype.usingFile = function(file, action) {
return this.usingFileStream(file, function(stream) {
var endListener, errorListener, readableListener;
endListener = errorListener = readableListener = void 0;
return new Promise(function(resolve, reject) {
var chunks, totalLength, tryRead;
chunks = [];
totalLength = 0;
tryRead = function() {
var chunk;
while (chunk = stream.read()) {
chunks.push(chunk);
totalLength += chunk.length;
}
};
stream.on('readable', readableListener = function() {
return tryRead();
});
stream.on('error', errorListener = function(err) {
return reject(err);
});
return stream.on('end', endListener = function() {
return resolve(Buffer.concat(chunks, totalLength));
});
}).then(action)["finally"](function() {
stream.removeListener('readable', readableListener);
stream.removeListener('error', errorListener);
return stream.removeListener('end', endListener);
});
});
};
ApkReader.prototype.usingFileStream = function(file, action) {
return this._open().then(function(zipfile) {
var endListener, entryListener, errorListener;
endListener = errorListener = entryListener = void 0;
return new Promise(function(resolve, reject) {
zipfile.on('entry', entryListener = function(entry) {
if (entry.fileName === MANIFEST) {
return resolve(Promise.fromCallback(function(callback) {
return zipfile.openReadStream(entry, callback);
}));
} else {
return zipfile.readEntry();
}
});
zipfile.on('end', endListener = function() {
return reject(new Error("APK does not contain '" + file + "'"));
});
zipfile.on('error', errorListener = function(err) {
return reject(err);
});
return zipfile.readEntry();
}).then(action)["finally"](function() {
zipfile.removeListener('entry', entryListener);
zipfile.removeListener('error', errorListener);
zipfile.removeListener('end', endListener);
return zipfile.close();
});
});
};
ApkReader.prototype.readManifest = function() {
return this.usingFile(MANIFEST, function(content) {
return new ManifestParser(content).parse();
});
};
ApkReader.prototype.readXml = function(path) {
return this.usingFile(path, function(content) {
return new BinaryXmlParser(content).parse();
});
};
return ApkReader;

@@ -54,0 +111,0 @@

{
"name": "adbkit-apkreader",
"version": "1.0.0",
"version": "2.0.0",
"description": "Extracts information from APK files.",

@@ -14,14 +14,9 @@ "keywords": [

"bugs": {
"url": "https://github.com/CyberAgent/adbkit-apkreader/issues"
"url": "https://github.com/openstf/adbkit-apkreader/issues"
},
"license": "Apache-2.0",
"author": {
"name": "CyberAgent, Inc.",
"email": "npm@cyberagent.co.jp",
"url": "http://www.cyberagent.co.jp/"
},
"main": "./index",
"repository": {
"type": "git",
"url": "https://github.com/CyberAgent/adbkit-apkreader.git"
"url": "https://github.com/openstf/adbkit-apkreader.git"
},

@@ -34,4 +29,5 @@ "scripts": {

"dependencies": {
"adm-zip": "~0.4.4",
"debug": "~0.7.4"
"bluebird": "^3.4.7",
"debug": "~0.7.4",
"yauzl": "^2.7.0"
},

@@ -38,0 +34,0 @@ "engines": {

@@ -20,9 +20,8 @@ # adbkit-apkreader

```javascript
var util = require('util')
var ApkReader = require('adbkit-apkreader')
const util = require('util')
const ApkReader = require('adbkit-apkreader')
var reader = ApkReader.readFile('HelloApp.apk')
var manifest = reader.readManifestSync()
console.log(util.inspect(manifest, { depth: null }))
ApkReader.open('HelloApp.apk')
.then(reader => reader.readManifest())
.then(manifest => console.log(util.inspect(manifest, { depth: null })))
```

@@ -34,24 +33,16 @@

#### ApkReader.readFile(file)
#### 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.
* **file** The path to the APK file.
* Throws: `Error` on error (e.g. if the file is not valid)
* Returns: An `ApkReader` instance.
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.
#### constructor(file)
Manually construct an `ApkReader` instance. Useful for testing and/or playing around. Normally you would use `ApkReader.readFile(file)` to create the instance.
* **file** The path to the APK file.
* Throws: `Error` on error (e.g. if the file is not valid)
* Returns: N/A
* Returns: A `Promise` that resolves with an `ApkReader` instance.
#### reader.readManifestSync()
#### reader.readManifest()
Synchronously reads and parses the `AndroidManifest.xml` file inside the APK and returns a simplified object representation of it.
Reads and parses the `AndroidManifest.xml` file inside the APK and returns a simplified object representation of it.
* Throws: `Error` (e.g. if parsing was unsuccessful)
* Returns: A JavaScript `Object` representation of the manifest. See example output below:
* 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).

@@ -102,9 +93,8 @@ ```javascript

#### reader.readXmlSync(path)
#### reader.readXml(path)
Synchronously reads and parses the binary XML file at the given path inside the APK file. Attempts to be somewhat compatible with the DOM API.
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.readManifestSync()` instead).
* Throws: `Error` (e.g. if parsing was unsuccessful)
* Returns: A JavaScript `Object` representation of the root node of the XML file. All nodes including the root node have the following properties:
* 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.

@@ -143,2 +133,2 @@ - **nodeType** `1` for element nodes, `2` for attribute nodes, and `4` for CData sections.

Copyright © CyberAgent, Inc. All Rights Reserved.
Copyright © The OpenSTF Project. All Rights Reserved.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc