[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转载教程] PowerShell 解决 Chrome 提示请停用开发者模式

enableallExtensions
Auto Add All Existing Chrome Extensions To ExtensionInstallWhitelist
requred a lgpo.exe from microsoft (included in Latest Release)
https://github.com/myfreeer/enableallExtensions


复制以下代码并且另存为 DevWarningPatch.bat 到任意位置,右键管理员运行即可。
  1. <# :
  2. @echo off
  3. copy/b "%~f0" "%temp%\%~n0.ps1" >nul
  4. powershell -Version 2 -ExecutionPolicy bypass -noprofile "%temp%\%~n0.ps1" "%cd% " "%~1"
  5. del "%temp%\%~n0.ps1"
  6. pause
  7. exit /b
  8. #>
  9. param([string]$cwd='.', [string]$dll)
  10. function main {
  11.     "Chrome 'developer mode extensions' warning disabler v1.0.10.20170114`n"
  12.     $pathsDone = @{}
  13.     if ($dll -and (gi -literal $dll)) {
  14.         doPatch "DRAG'n'DROPPED" ((gi -literal $dll).directoryName + '\')
  15.         exit
  16.     }
  17.     doPatch CURRENT ((gi -literal $cwd).fullName + '\')
  18.     ('HKLM', 'HKCU') | %{ $hive = $_
  19.         ('', '\Wow6432Node') | %{
  20.             $key = "${hive}:\SOFTWARE$_\Google\Update\Clients"
  21.             gci -ea silentlycontinue $key -r | gp | ?{ $_.CommandLine } | %{
  22.                 $path = $_.CommandLine -replace '"(.+?\\\d+\.\d+\.\d+\.\d+\\).+', '$1'
  23.                 doPatch REGISTRY $path
  24.             }
  25.         }
  26.     }
  27. }
  28. function doPatch([string]$pathLabel, [string]$path) {
  29.     if ($pathsDone[$path.toLower()]) { return }
  30.     $dll = $path + "chrome.dll"
  31.     if (!(test-path -literal $dll)) {
  32.         return
  33.     }
  34.     "======================="
  35.     "$pathLabel PATH $((gi -literal $dll).DirectoryName)"
  36.     "`tREADING Chrome.dll..."
  37.     $bytes = [IO.File]::ReadAllBytes($dll)
  38.     # process PE headers
  39.     $BC = [BitConverter]
  40.     $coff = $BC::ToUInt32($bytes,0x3C) + 4
  41.     $is64 = $BC::ToUInt16($bytes,$coff) -eq 0x8664
  42.     $opthdr = $coff+20
  43.     $codesize = $BC::ToUInt32($bytes,$opthdr+4)
  44.     $imagebase32 = $BC::ToUInt32($bytes,$opthdr+28)
  45.     # patch the flag in data section
  46.     $data = $BC::ToString($bytes,$codesize)
  47.     $flag = "ExtensionDeveloperModeWarning"
  48.     $stroffs = $data.IndexOf($BC::ToString($flag[1..99]))/3 - 1
  49.     if ($stroffs -lt 0) {
  50.         write-host -f red "`t$flag not found"
  51.         return
  52.     }
  53.     $stroffs += $codesize
  54.     if ($bytes[$stroffs] -eq 0) {
  55.         write-host -f darkgreen "`tALREADY PATCHED"
  56.         return
  57.     }
  58.     $exe = join-path (split-path $path) chrome.exe
  59.     $EA = $ErrorActionPreference
  60.     $ErrorActionPreference = 'silentlyContinue'
  61.     while ((get-process chrome -module | ?{ $_.FileName -eq $exe })) {
  62.         forEach ($timeout in 15..0) {
  63.             write-host -n -b yellow -f black `
  64.                 "`rChrome is running and will be terminated in $timeout sec. "
  65.             write-host -n -b yellow -f darkyellow "Press ENTER to do it now. "
  66.             if ([console]::KeyAvailable) {
  67.                 $key = $Host.UI.RawUI.ReadKey("AllowCtrlC,IncludeKeyDown,NoEcho")
  68.                 if ($key.virtualKeyCode -eq 13) { break }
  69.                 if ($key.virtualKeyCode -eq 27) { write-host; exit }
  70.             }
  71.             sleep 1
  72.         }
  73.         write-host
  74.         get-process chrome | ?{
  75.             $_.MainWindowHandle.toInt64() -and ($_ | gps -file).FileName -eq $exe
  76.         } | %{
  77.             "`tTrying to exit gracefully..."
  78.             if ($_.CloseMainWindow()) {
  79.                 sleep 1
  80.             }
  81.         }
  82.         $killLabelShown = 0
  83.         get-process chrome | ?{
  84.             ($_ | gps -file | select -expand FileName) -eq $exe
  85.         } | %{
  86.             if (!$killLabelShown++) {
  87.                 "`tTerminating background chrome processes..."
  88.             }
  89.             stop-process $_ -force
  90.         }
  91.         sleep -milliseconds 200
  92.     }
  93.     $ErrorActionPreference = $EA
  94.     $bytes[$stroffs] = 0
  95.     "`tPATCHED $flag flag"
  96.     # patch the channel restriction code for stable/beta
  97.     $code = $BC::ToString($bytes,0,$codesize)
  98.     $rxChannel = '83-F8-(?:03-7D|02-7F)'
  99.     # old code: cmp eax,3; jge ...
  100.     # new code: cmp eax,2; jg ...
  101.     $chanpos = 0
  102.     try {
  103.         if ($is64) {
  104.             $pos = 0
  105.             $rx = [regex]"$rxChannel-.{1,100}-48-8D"
  106.             do {
  107.                 $m = $rx.match($code,$pos)
  108.                 if (!$m.success) { break }
  109.                 $chanpos = $m.index/3 + 2
  110.                 $pos = $m.index + $m.length + 1
  111.                 $offs = $BC::ToUInt32($bytes,$pos/3+1)
  112.                 $diff = $pos/3+5+$offs - $stroffs
  113.             } until ($diff -ge 0 -and $diff -le 4096 -and $diff % 256 -eq 0)
  114.             if (!$m.success) {
  115.                 $rx = [regex]"84-C0.{18,48}($rxChannel)-.{30,60}84-C0"
  116.                 $m = $rx.matches($code)
  117.                 if ($m.count -ne 1) { throw }
  118.                 $chanpos = $m[0].groups[1].index/3 + 2
  119.             }
  120.         } else {
  121.             $flagOffs = [uint32]$stroffs + [uint32]$imagebase32
  122.             $flagOffsStr = $BC::ToString($BC::GetBytes($flagOffs))
  123.             $variants = "(?<channel>$rxChannel-.{1,100})-68-(?<flag>`$1-.{6}`$2)",
  124.                     "68-(?<flag>`$1-.{6}`$2).{300,500}E8.{12,32}(?<channel>$rxChannel)",
  125.                     "E8.{12,32}(?<channel>$rxChannel).{300,500}68-(?<flag>`$1-.{6}`$2)"
  126.             forEach ($variant in $variants) {
  127.                 $pattern = $flagOffsStr -replace '^(..)-.{6}(..)', $variant
  128.                 "`tLooking for $($pattern -replace '\?<.+?>', '')..."
  129.                 $minDiff = 65536
  130.                 foreach ($m in [regex]::matches($code, $pattern)) {
  131.                     $maybeFlagOffs = $BC::toUInt32($bytes, $m.groups['flag'].index/3)
  132.                     $diff = [Math]::abs($maybeFlagOffs - $flagOffs)
  133.                     if ($diff % 256 -eq 0 -and $diff -lt $minDiff) {
  134.                         $minDiff = $diff
  135.                         $chanpos = $m.groups['channel'].index/3 + 2
  136.                     }
  137.                 }
  138.             }
  139.             if (!$chanpos) { throw }
  140.         }
  141.     } catch {
  142.         write-host -f red "`tUnable to find the channel code, try updating me"
  143.         write-host -f red "`thttp://stackoverflow.com/a/30361260"
  144.         return
  145.     }
  146.     $bytes[$chanpos] = 9
  147.     "`tPATCHED Chrome release channel restriction"
  148.     "`tWriting to a temporary dll..."
  149.     [IO.File]::WriteAllBytes("$dll.new",$bytes)
  150.     "`tBacking up the original dll..."
  151.     move -literal $dll "$dll.bak" -force
  152.     "`tRenaming the temporary dll as the original dll..."
  153.     move -literal "$dll.new" $dll -force
  154.     $pathsDone[$path.toLower()] = $true
  155.     write-host -f green "`tDONE.`n"
  156.     [GC]::Collect()
  157. }
  158. main
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

厉害了

TOP

返回列表