Advertisement
thedarkcoder

extensions.php

May 6th, 2021
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2. $tmppath="/tmp/manager/extensions";
  3. //$sn = rtrim(shell_exec('ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" \'/IOPlatformSerialNumber/{print $(NF-1)}\''), PHP_EOL);
  4.  
  5. $user = rtrim(shell_exec('stat -f "%Su" /dev/console'), PHP_EOL); //get current user
  6. $directory = '/Users/'.$user.'/Library/Application\ Support/Google/Chrome/';
  7. $output = shell_exec('ls '. $directory);
  8.  
  9. $dirs = explode(PHP_EOL, $output);
  10. $dirs_extensions = array();
  11.  
  12. foreach($dirs as $dir) { //find the directories that may contain extensions (Profile X or Default)
  13.     if(strpos($dir, "Profile ") !== false || strpos($dir, "Default") !== false) {
  14.         array_push($dirs_extensions, $dir);
  15.     }
  16. }
  17.  
  18. $extensions = array();
  19. foreach($dirs_extensions as $dir) {
  20.     $exec = 'find ' . $directory . str_replace(" ", "\ ", $dir) . '/Extensions$d -maxdepth 3 -name "manifest.json"';
  21.     $output = shell_exec($exec);
  22.     $jsons = explode(PHP_EOL, $output);
  23.    
  24.     foreach($jsons as $manifest) {
  25.         if($manifest != '') {
  26.             $json_exec = 'cat "' . $manifest. '"';
  27.             $str = shell_exec($json_exec);
  28.             $json = json_decode($str, true);
  29.            
  30.             $id_str = substr(strstr($json_exec, '/Extensions/'), 12);
  31.             $id = strstr($id_str, '/', true);
  32.            
  33.             $name = $json['name'];
  34.             $pos = strpos($name, '__');
  35.             if ($pos !== false) { //name is a placeholder
  36.                 $placeholder = $name = substr($json['name'], 6, -2);
  37.  
  38.                     $exec = 'find ' . $directory . str_replace(" ", "\ ", $dir) . '/Extensions/' . $id . '/*/_locales/en*$d -maxdepth 3 -name "messages.json"'; //find the json that contains the string constants
  39.                     $output = shell_exec($exec);
  40.                     if(!is_null($output)) {//found the file
  41.                         $messages = explode(PHP_EOL, $output);
  42.                         $exec = 'cat ' . str_replace(" ", "\ ", $messages[0]);
  43.                         $output = shell_exec($exec);
  44.                         $jsonName = json_decode($output, true);
  45.  
  46.                         if(isset($jsonName[$placeholder])){
  47.                             $name = $jsonName[$placeholder]['message'];
  48.                             if(is_null($name)) {
  49.                                 $name = $jsonName[strtolower($placeholder)]['message'];
  50.                             }
  51.                         }                        
  52.                     } else {
  53.                         $name = $json['name'];
  54.                     }
  55.             }//end if
  56.             $extensions[] = array('id' => $id, 'name' => $name, 'version' => $json['version']);
  57.         }//end if
  58.     }//end foreach
  59. }//end foreach
  60.  
  61. $extensions = json_encode($extensions, 128);
  62.  
  63. file_put_contents($tmppath.'/extensions.json', $extensions);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement