Skip to content

Commit 3afa93f

Browse files
authored
add parsePerms() method to obtain app permissions #6
Merge pull request #6 from IzzySoft/gperms
2 parents 85dc360 + c440e37 commit 3afa93f

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,74 @@ Array
141141
)
142142
```
143143

144+
### Obtaining app permissions
145+
Using `$google->parsePerms($packageName)` you can obtain permissions for a given app. As with the structures returned for apps, the keys `success` and `message` are used to indicate the status. For data itself, you'll find a list by permission groups behind the `grouped` key – and "unified permissions" behind the `perms` key. Example output:
146+
147+
```
148+
Array
149+
(
150+
[success] => 1
151+
[grouped] => Array
152+
(
153+
[storage] => Array
154+
(
155+
[group_name] => Storage
156+
[perms] => Array
157+
(
158+
[0] => Array
159+
(
160+
[0] =>
161+
[1] => modify or delete the contents of your USB storage
162+
)
163+
[1] => Array
164+
(
165+
[0] =>
166+
[1] => read the contents of your USB storage
167+
)
168+
)
169+
)
170+
[perm_media] => Array
171+
(
172+
[group_name] => Photos/Media/Files
173+
[perms] => Array
174+
(
175+
[0] => Array
176+
(
177+
[0] =>
178+
[1] => modify or delete the contents of your USB storage
179+
)
180+
[1] => Array
181+
(
182+
[0] =>
183+
[1] => read the contents of your USB storage
184+
)
185+
)
186+
)
187+
[perm_camera_mic] => Array
188+
(
189+
[group_name] => Microphone
190+
[perms] => Array
191+
(
192+
[0] => Array
193+
(
194+
[0] =>
195+
[1] => record audio
196+
)
197+
)
198+
)
199+
)
200+
[perms] => Array
201+
(
202+
[0] => modify or delete the contents of your USB storage
203+
[1] => read the contents of your USB storage
204+
[4] => record audio
205+
)
206+
)
207+
```
208+
209+
The `grouped` keys are the IDs given to the permission groups by Google. The empty `[0]` key for permissions in the `grouped` tree is as shipped by Google; no idea what it is reserved for until some values show up here.
210+
211+
144212
### TODO
145213

146214
- Unit test

google-play.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,43 @@ public function parse($link=null) {
166166
return $values;
167167
}
168168

169+
public function parsePerms($packageName) {
170+
$opts = ['http' => array(
171+
'method' => 'POST',
172+
'header' => 'Content-type: application/x-www-form-urlencoded;charset=utf-8'
173+
."\r\n".'Referer: https://play.google.com/',
174+
'content' => 'f.req=%5B%5B%5B%22xdSrCf%22%2C%22%5B%5Bnull%2C%5B%5C%22'.$packageName.'%5C%22%2C7%5D%2C%5B%5D%5D%5D%22%2Cnull%2C%221%22%5D%5D%5D',
175+
'ignore_errors' => TRUE
176+
)
177+
];
178+
$context = stream_context_create($opts);
179+
if ( $proto = @file_get_contents('https://play.google.com/_/PlayStoreUi/data/batchexecute?rpcids=xdSrCf&bl=boq_playuiserver_20201201.06_p0&hl=en&authuser&soc-app=121&soc-platform=1&soc-device=1&rt=c&f.sid=-8792622157958052111&_reqid=257685', false, $context) ) { // raw proto_buf data
180+
preg_match("!HTTP/1\.\d\s+(\d{3})\s+(.+)$!i",$http_response_header[0],$match);
181+
$response_code = $match[1];
182+
switch ($response_code) {
183+
case "200" : // HTTP/1.0 200 OK
184+
break;
185+
case "400" : // echo "! No XHR for '$pkg'\n";
186+
case "404" : // app no longer on play
187+
default:
188+
return ['success'=>0,'message'=>$http_response_header[0]];
189+
break;
190+
}
191+
} else { // network error (e.g. "failed to open stream: Connection timed out")
192+
return ['success'=>0,'message'=>'network error'];
193+
}
194+
195+
$perms = $perms_unique = [];
196+
$json = preg_replace('!.*?(\[.+?\])\s*\d.*!ims','$1',$proto);
197+
$arr = json_decode($json)[0][2];
198+
foreach (json_decode($arr)[0] as $group) { // 0: group name, 1: group icon, 2: perms, 3: group_id
199+
$perms[$group[3][0]] = ['group_name'=>$group[0], 'perms'=>$group[2]];
200+
foreach($group[2] as $perm) $perms_unique[] = $perm[1];
201+
}
202+
203+
return ['success'=>1,'grouped'=>$perms,'perms'=>array_unique($perms_unique)];
204+
}
205+
169206
public function parseCategory($category) {
170207
$link="https://play.google.com/store/apps/category/".$category;
171208
return $this->parse($link);

0 commit comments

Comments
 (0)