Advertisement
Guest User

Untitled

a guest
Oct 8th, 2019
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. param([String]$OutputFolder=$null,[String]$ExtensionId=$null,[Switch]$Remove, [Switch]$WhatIf)
  2.  
  3. ##: Globals
  4. $retval = $false
  5.  
  6. ##: If OutputFolder param wasn't given, output the audit file to the desktop
  7. if(!$OutputFolder -or !(Test-Path -Path $OutputFolder)) {
  8. $auditfolderpath = "$($env:USERPROFILE)\Desktop"
  9. } else {
  10. $auditfolderpath = $OutputFolder
  11. }
  12.  
  13. ##: This is the file we will write the extension list to
  14. $auditfilepath = "$($auditfolderpath)\$($env:USERNAME)-$($env:COMPUTERNAME).txt"
  15. if( !(Test-Path -Path $auditfilepath) ) {
  16. echo "Creating: [$auditfilepath]"
  17. if(!($WhatIf)) {
  18. echo "" | Out-File -FilePath $auditfilepath
  19. }
  20. }
  21. if(!($WhatIf)) {
  22. Clear-Content $auditfilepath
  23. }
  24.  
  25. ##: The extensions folder is in local appdata
  26. $extension_folders = Get-ChildItem -Path "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default\Extensions"
  27.  
  28. ##: Loop through each extension folder
  29. foreach ($extension_folder in $extension_folders ) {
  30.  
  31. ##: Get the version specific folder within this extension folder
  32. $version_folders = Get-ChildItem -Path "$($extension_folder.FullName)"
  33.  
  34. ##: Loop through the version folders found
  35. foreach ($version_folder in $version_folders) {
  36. ##: The extension folder name is the app id in the Chrome web store
  37. $appid = $extension_folder.BaseName
  38.  
  39. ##: First check the manifest for a name
  40. $name = ""
  41. if( (Test-Path -Path "$($version_folder.FullName)\manifest.json") ) {
  42. try {
  43. $json = Get-Content -Raw -Path "$($version_folder.FullName)\manifest.json" | ConvertFrom-Json
  44. $name = $json.name
  45. } catch {
  46. #$_
  47. $name = ""
  48. }
  49. }
  50.  
  51. ##: If we find _MSG_ in the manifest it's probably an app
  52. if( $name -like "*MSG*" ) {
  53. ##: Sometimes the folder is en
  54. if( Test-Path -Path "$($version_folder.FullName)\_locales\en\messages.json" ) {
  55. try {
  56. $json = Get-Content -Raw -Path "$($version_folder.FullName)\_locales\en\messages.json" | ConvertFrom-Json
  57. $name = $json.appName.message
  58. ##: Try a lot of different ways to get the name
  59. if(!$name) {
  60. $name = $json.extName.message
  61. }
  62. if(!$name) {
  63. $name = $json.extensionName.message
  64. }
  65. if(!$name) {
  66. $name = $json.app_name.message
  67. }
  68. if(!$name) {
  69. $name = $json.application_title.message
  70. }
  71. } catch {
  72. #$_
  73. $name = ""
  74. }
  75. }
  76. ##: Sometimes the folder is en_US
  77. if( Test-Path -Path "$($version_folder.FullName)\_locales\en_US\messages.json" ) {
  78. try {
  79. $json = Get-Content -Raw -Path "$($version_folder.FullName)\_locales\en_US\messages.json" | ConvertFrom-Json
  80. $name = $json.appName.message
  81. ##: Try a lot of different ways to get the name
  82. if(!$name) {
  83. $name = $json.extName.message
  84. }
  85. if(!$name) {
  86. $name = $json.extensionName.message
  87. }
  88. if(!$name) {
  89. $name = $json.app_name.message
  90. }
  91. if(!$name) {
  92. $name = $json.application_title.message
  93. }
  94. } catch {
  95. #$_
  96. $name = ""
  97. }
  98. }
  99. }
  100.  
  101. ##: If we can't get a name from the extension use the app id instead
  102. if( !$name ) {
  103. $name = "[$($appid)]"
  104. }
  105.  
  106. ##: App id given on command line and this one matched it
  107. if( $ExtensionId -and ($appid -eq $ExtensionId) ) {
  108. if( $Remove ) {
  109. echo "Removing item: [$appid] at path: [$($extension_folder.FullName)]"
  110. if(!($WhatIf)) {
  111. ##: Remove the extension folder
  112. if (Test-Path -Path $extension_folder.FullName) {
  113. Remove-Item -Path $extension_folder.FullName -Recurse -Force
  114. }
  115.  
  116. ##: Remove the extension registry key
  117. if (Test-Path -Path "HKCU:\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings") {
  118. if( Get-ItemProperty -Name "$appid" -Path "HKCU:\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings" ) {
  119. Remove-ItemProperty -Name "$appid" -Path "HKCU:\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings"
  120. }
  121. }
  122. }
  123. } else {
  124. ##: Dump to a file
  125. echo "Appending: [$name ($($version_folder)) - $appid] to audit file: [$auditfilepath]"
  126. if(!($WhatIf)) {
  127. echo "$name ($($version_folder)) - $appid" | Out-File -Append $auditfilepath
  128. }
  129. ##: Exit with a TRUE value if the given extension id was found
  130. $retval = $true
  131. }
  132.  
  133. ##: App id given on command line and this did NOT match it
  134. } elseif( $ExtensionId -and ($appid -ne $ExtensionId) ) {
  135. ##: NOP
  136. #echo "Skipping: [$appid] output"
  137. ##: App id not given on command line
  138. } else {
  139. ##: Dump to audit file
  140. echo "Appending: [$name ($($version_folder)) - $appid] to audit file: [$auditfilepath]"
  141. if(!($WhatIf)) {
  142. echo "$name ($($version_folder)) - $appid" | Out-File -Append $auditfilepath
  143. }
  144. }
  145.  
  146. }
  147.  
  148. }
  149.  
  150. exit($retval)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement