Last active
December 30, 2016 16:56
-
-
Save veeven/600e799a597c0efd22d0d11a4cc27e50 to your computer and use it in GitHub Desktop.
Andriod Permission Decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const permissionsFile = 'https://raw.githubusercontent.com/android/platform_frameworks_base/master/core/res/AndroidManifest.xml'; | |
const stringsFile = 'https://raw.githubusercontent.com/android/platform_frameworks_base/master/core/res/res/values/strings.xml'; | |
const permissions = new Map(); | |
const permissionGroups = new Map(); | |
const strings = new Map(); | |
const q = d3.queue() | |
.defer(d3.xml, permissionsFile) | |
.defer(d3.xml, stringsFile) | |
.awaitAll(function(error, results) { | |
if (error) throw error; | |
doMagic(results); | |
}); | |
function doMagic(arr) { | |
const x2js = new X2JS(); | |
let data = arr.map(a => x2js.xml2json(a)); | |
data[0].manifest.permission.forEach(p => { | |
permissions.set(p['_android:name'], { | |
label: p['_android:label'] ? p['_android:label'].replace('@string/', '') : '', | |
description: p['_android:description'] ? p['_android:description'].replace('@string/', '') : '', | |
protectionLevel: p['_android:protectionLevel'], | |
group: p['_android:permissionGroup'], | |
}); | |
}); | |
data[0].manifest['permission-group'].forEach(pg => { | |
permissionGroups.set(pg['_android:name'], { | |
label: pg['_android:label'] ? pg['_android:label'].replace('@string/', '') : '', | |
description: pg['_android:description'] ? pg['_android:description'].replace('@string/', '') : '', | |
priority: pg['_android:priority'], | |
icon: pg['_android:icon'], | |
}); | |
}); | |
data[1].resources.string.forEach(s => { | |
strings.set(s['_name'], s['__text']); | |
//strings.set(s['_name'], s['__text'] ? s['__text'].replace(/\n\s{2,}/g, ' ') : ''); | |
}); | |
// results | |
console.log('permissions:', permissions.size); | |
console.log('permission-groups:', permissionGroups.size) | |
console.log('strings:', strings.size); | |
query(); | |
} | |
function query(q) { | |
q = q || 'android.permission.ACCESS_COARSE_LOCATION'; | |
console.log(q); | |
let perm = permissions.get(q); | |
const $out = document.querySelector('#out'); | |
if (!perm) { | |
$out.textContent = 'No such permission! Try something else.'; | |
return; | |
} | |
$out.innerHTML = '<i>Label: </i>' + '<b>' + strings.get(perm.label) + '</b>' | |
+ '<br>' | |
+ '<i>Description: </i>' + strings.get(perm.description) | |
+ '<br>' | |
+ '<i>Protenction Level: </i>' + perm.protectionLevel | |
+ '<br>' | |
+ '<i>Group: </i>' + (perm.group ? strings.get(permissionGroups.get(perm.group).label) : '') | |
; | |
} | |
const $i = document.querySelector('input'); | |
$i.addEventListener('input', function() { | |
query(this.value); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<title>Andrioid Permission Decoder</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<style type="text/css"> | |
body { | |
width: 960px; | |
margin: 1em auto; | |
} | |
input { | |
width: 24em; | |
} | |
i { | |
color: #666; | |
font-size: .8em; | |
font-style: normal; | |
background: #f0f0f0; | |
} | |
</style> | |
</head> | |
<body> | |
<p>Android permission: <input type="text" placeholder="android.permission.ACCESS_COARSE_LOCATION"></p> | |
<p id="out"></p> | |
<script type="text/javascript" src="https://d3js.org/d3.v4.min.js"></script> | |
<script type="text/javascript" src="https://cdn.rawgit.com/abdmob/x2js/master/xml2json.js"></script> | |
<script type="text/javascript" src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment