Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $tmppath="/tmp/manager/extensions";
- //$sn = rtrim(shell_exec('ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" \'/IOPlatformSerialNumber/{print $(NF-1)}\''), PHP_EOL);
- $user = rtrim(shell_exec('stat -f "%Su" /dev/console'), PHP_EOL); //get current user
- $directory = '/Users/'.$user.'/Library/Application\ Support/Google/Chrome/';
- $output = shell_exec('ls '. $directory);
- $dirs = explode(PHP_EOL, $output);
- $dirs_extensions = array();
- foreach($dirs as $dir) { //find the directories that may contain extensions (Profile X or Default)
- if(strpos($dir, "Profile ") !== false || strpos($dir, "Default") !== false) {
- array_push($dirs_extensions, $dir);
- }
- }
- $extensions = array();
- foreach($dirs_extensions as $dir) {
- $exec = 'find ' . $directory . str_replace(" ", "\ ", $dir) . '/Extensions$d -maxdepth 3 -name "manifest.json"';
- $output = shell_exec($exec);
- $jsons = explode(PHP_EOL, $output);
- foreach($jsons as $manifest) {
- if($manifest != '') {
- $json_exec = 'cat "' . $manifest. '"';
- $str = shell_exec($json_exec);
- $json = json_decode($str, true);
- $id_str = substr(strstr($json_exec, '/Extensions/'), 12);
- $id = strstr($id_str, '/', true);
- $name = $json['name'];
- $pos = strpos($name, '__');
- if ($pos !== false) { //name is a placeholder
- $placeholder = $name = substr($json['name'], 6, -2);
- $exec = 'find ' . $directory . str_replace(" ", "\ ", $dir) . '/Extensions/' . $id . '/*/_locales/en*$d -maxdepth 3 -name "messages.json"'; //find the json that contains the string constants
- $output = shell_exec($exec);
- if(!is_null($output)) {//found the file
- $messages = explode(PHP_EOL, $output);
- $exec = 'cat ' . str_replace(" ", "\ ", $messages[0]);
- $output = shell_exec($exec);
- $jsonName = json_decode($output, true);
- if(isset($jsonName[$placeholder])){
- $name = $jsonName[$placeholder]['message'];
- if(is_null($name)) {
- $name = $jsonName[strtolower($placeholder)]['message'];
- }
- }
- } else {
- $name = $json['name'];
- }
- }//end if
- $extensions[] = array('id' => $id, 'name' => $name, 'version' => $json['version']);
- }//end if
- }//end foreach
- }//end foreach
- $extensions = json_encode($extensions, 128);
- file_put_contents($tmppath.'/extensions.json', $extensions);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement