Skip to content

Commit

Permalink
feat: add locate support for apk
Browse files Browse the repository at this point in the history
  • Loading branch information
lianghx-319 committed Jan 11, 2021
1 parent 79c91a6 commit 8e3ca0a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 31,393 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/
package-lock.json
yarn.lock
yarn-error.log
dist/
31,121 changes: 0 additions & 31,121 deletions dist/app-info-parser.js

This file was deleted.

259 changes: 0 additions & 259 deletions dist/app-info-parser.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions dist/app-info-parser.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/app-info-parser.min.js.map

This file was deleted.

3 changes: 3 additions & 0 deletions example/basic-use.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<span style="width: 0; flex: 1; overflow-wrap: break-word; word-wrap: break-word;">${ result['versionName'] || result['CFBundleShortVersionString'] }</span>
</p>
</div>
<pre>
<code>${JSON.stringify(result, null, 2)}</code>
</pre>
`
document.getElementById('result-list').appendChild(div)
}).catch(e => {
Expand Down
51 changes: 45 additions & 6 deletions lib/resource-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ ResourceFinder.prototype.processPackage = function(bb) {

this.package_id = id;

// name 256 个字节
for (var i = 0; i < 256; ++i) {
bb.readUint8();
}
Expand Down Expand Up @@ -233,6 +234,37 @@ ResourceFinder.prototype.processPackage = function(bb) {
}
};

ResourceFinder.prototype.processConfig = function(bb) {
var config_mcc = bb.readShort(),
config_mnc = bb.readShort(),
config_language = [bb.readByte(), bb.readByte()],
config_region = [bb.readByte(), bb.readByte()]

var config = {
language: '',
region: '',
locate: 'default'
}

if (config_language.every(Boolean)) {
config.language = config_language.map(byte => String.fromCharCode(byte)).join('')
}

if (config_region.every(Boolean)) {
config.region = config_region.map(byte => String.fromCharCode(byte)).join('')
}

if (config.language) {
config.locate = config.language
}

if (config.region) {
config.locate += `-r${config.region}`
}

return config
}

/**
*
* @param {ByteBuffer} bb
Expand All @@ -248,9 +280,13 @@ ResourceFinder.prototype.processType = function(bb) {
entriesStart = bb.readInt();

var refKeys = {};



var config_size = bb.readInt();

var configBuffer = ResourceFinder.readBytes(bb, config_size)

var res_config = this.processConfig(configBuffer)

// Skip the config data
bb.offset = headerSize;

Expand Down Expand Up @@ -334,7 +370,7 @@ ResourceFinder.prototype.processType = function(bb) {
}
}

this.putIntoMap("@" + idStr, data);
this.putIntoMap("@" + idStr, data, res_config);
} else {
// Complex case
var entry_parent = bb.readInt();
Expand Down Expand Up @@ -369,7 +405,7 @@ ResourceFinder.prototype.processType = function(bb) {
];
if (values != null && Object.keys(values).length < 1000) {
for (var value in values) {
this.putIntoMap("@" + refK, value);
this.putIntoMap("@" + refK, value, res_config);
}
}
}
Expand Down Expand Up @@ -487,11 +523,14 @@ ResourceFinder.prototype.processTypeSpec = function(bb) {
}
};

ResourceFinder.prototype.putIntoMap = function(resId, value) {
ResourceFinder.prototype.putIntoMap = function(resId, value, config) {
if (this.responseMap[resId.toUpperCase()] == null) {
this.responseMap[resId.toUpperCase()] = []
}
this.responseMap[resId.toUpperCase()].push(value)
this.responseMap[resId.toUpperCase()].push({
value,
locate: config.locate
})
};

module.exports = ResourceFinder;
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function findApkIconPath (info) {
const maxDpiIcon = { dpi: 120, icon: '' }

for (const i in rulesMap) {
info.application.icon.some((icon) => {
info.application.icon.some(({ value: icon }) => {
if (icon && icon.indexOf(i) !== -1) {
resultMap['application-icon-' + rulesMap[i]] = icon
return true
Expand All @@ -109,7 +109,7 @@ function findApkIconPath (info) {

if (Object.keys(resultMap).length === 0 || !maxDpiIcon.icon) {
maxDpiIcon.dpi = 120
maxDpiIcon.icon = info.application.icon[0] || ''
maxDpiIcon.icon = info.application.icon[0].value || ''
resultMap['applicataion-icon-120'] = maxDpiIcon.icon
}
return maxDpiIcon.icon
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "app-info-parser",
"name": "@bytrace/app-info-parser",
"version": "1.0.0",
"description": "Exact info from apk or ipa file.",
"main": "./src/index.js",
"main": "dist/app-info-parser.js",
"files": [
"dist"
],
"scripts": {
"test": "node ./example/node.js",
"build": "rimraf src/* && babel lib -d src",
Expand Down

0 comments on commit 8e3ca0a

Please sign in to comment.