Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现apk获取架构列表 #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/apk.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Zip = require('./zip')
const { mapInfoResource, findApkIconPath, getBase64FromBuffer } = require('./utils')
const ManifestName = /^androidmanifest\.xml$/
const ResourceName = /^resources\.arsc$/
const LibName = /^lib[\\/]/

const ManifestXmlParser = require('./xml-parser/manifest')
const ResourceFinder = require('./resource-finder')
Expand All @@ -19,7 +20,12 @@ class ApkParser extends Zip {
}
parse () {
return new Promise((resolve, reject) => {
this.getEntries([ManifestName, ResourceName]).then(buffers => {
this.getEntries([ManifestName, ResourceName, LibName]).then(buffers => {
for (let key of [ManifestName, ResourceName]) {
if (buffers[key]) {
buffers[key] = buffers[key][0].buffer
}
}
if (!buffers[ManifestName]) {
throw new Error('AndroidManifest.xml can\'t be found.')
}
Expand All @@ -32,7 +38,9 @@ class ApkParser extends Zip {
resourceMap = this._parseResourceMap(buffers[ResourceName])
// update apkInfo with resourceMap
apkInfo = mapInfoResource(apkInfo, resourceMap)

if (buffers[LibName]) {
apkInfo.arch = [...new Set(buffers[LibName].map(item => item.fileName.match(/^lib[\\/](.*)[\\/]/)[1]))]
}
// find icon path and parse icon
const iconPath = findApkIconPath(apkInfo)
if (iconPath) {
Expand Down
5 changes: 4 additions & 1 deletion lib/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Zip {
getEntries (regexps, type = 'buffer') {
regexps = regexps.map(regex => decodeNullUnicode(regex))
return new Promise((resolve, reject) => {
this.unzip.getBuffer(regexps, { type }, (err, buffers) => {
this.unzip.getBuffer(regexps, {
type,
multiple: true
}, (err, buffers) => {
err ? reject(err) : resolve(buffers)
})
})
Expand Down