本帖最后由 smss 于 2019-5-23 20:49 编辑
回复 34# netbenton
不要替换成运算符号 无法识别这个 效率是个大问题
PS 1~2秒 电脑好像没费什么事 BAT开了CPU和风扇都感觉有压力 可以想像 两者有很大差距的
还有我已支付 zaqmlp一半钱 但过程不完美 而且他还要加价 在期间还有中伤WHY代码因为没有加UTF8 而乱码的行为 而在那WHY发贴之前zaqmlp给的代码同样效率低下 因此放弃zaqmlp的任何方式方法
以下放上代码 有心可以比对 供交流 不涉及人身攻击 善恶自有分辨
WHY 5.22- $global:n = 65; $h = @{};
- $s = [IO.File]::ReadAllText('manifest.xml', [Text.Encoding]::UTF8);
- $s = [regex]::Replace($s, '(?<=\bname=")[^"]+(?=")',{param($m);$a=$m.Value; if(!$h.ContainsKey($a)){$h[$a]=[char]($global:n++)}; $h[$a]});
- $s = [regex]::Replace($s, '(?<=")[^@#]*[@#][^"]+(?=")',{param($m);$a=$m.Value;forEach($k In $h.Keys){$a=$a.Replace('@'+$k,'@'+$h[$k]).Replace('#'+$k,'#'+$h[$k])};$a});
- [IO.File]::WriteAllText('manifest2.xml', $s, [Text.Encoding]::UTF8);
复制代码 WHY5.22 15:10- @echo off
- PowerShell "$h=@{};$s=[regex]::Replace([IO.File]::ReadAllText('manifest.xml',[Text.Encoding]::UTF8),'(?<=\bname=\")[^^\"]+(?=\")',{param($m);$a=$m.Value;if(!$h.ContainsKey($a)){$x=[Math]::floor($global:n/26);if(!$x){$c=''}else{$c=[char](64+[int]$x)};$h[$a]=$c+[char](65+$global:n++%%26)};$h[$a]});$s=[regex]::Replace($s, '(?^<=\")[^\"@#]*[@#][^^\"]+(?=\")',{param($m);$a=$m.Value;forEach($k In $h.Keys){$a=$a.Replace('@'+$k,'@'+$h[$k]).Replace('#'+$k,'#'+$h[$k])};$a});sc b.txt -Value $s -Enc utf8"
- pause
复制代码 WHY 5.23- $global:n = 0; $Hash=@{};
- $str = [IO.File]::ReadAllText('manifest.xml',[Text.Encoding]::UTF8);
-
- #修改name属性的值
- #如果name属性的值以music_prev或music_display或music_next等开头,或者节点名为Extra,则排除
- $str = [regex]::Replace($str, '(?<=<(?!Extra)[^<>]*\sname=")(?!music_(?:prev|display|next|play|pause))[^"]+(?=")', {
- param($m);
- $key = $m.Value;
- if( !$Hash.ContainsKey($key) ){
- $x = [Math]::floor( $global:n / 26 );
- if($x) { $chr1 = [char]( 64 + [int]$x ) } else { $chr1 = '' }
- $Hash[$key] = $chr1 + [char]( 65 + $global:n++ % 26 );
- }
- $Hash[$key];
- })
-
- #如果属性值包含@#字符,或者属性值以 .animation或.visibility 结尾,则修改
- $str = [regex]::Replace($str, '(?<=")([^"@#]*[@#][^"]+|[^"]+(?:\.animation|\.visibility))(?=")', {
- param($m);
- $s = $m.Groups[1].Value;
- forEach( $key In $Hash.Keys ) {
- $s = $s.Replace( '@' + $key, '@' + $Hash[$key] );
- $s = $s.Replace( '#' + $key, '#' + $Hash[$key] );
- $s = $s.Replace( $key + '.animation', $Hash[$key] + '.animation' );
- $s = $s.Replace( $key + '.visibility', $Hash[$key] + '.visibility' );
- }
- $s;
- })
-
- [IO.File]::WriteAllText('manifest2.xml', $str, [Text.Encoding]::UTF8);
-
- echo 'Done';
- [Console]::ReadKey()
复制代码 zaqmlp5.22- @echo off
- cd /d "%~dp0"
- set "folder=结果"
- md "%folder%" 2>nul
- powershell -NoProfile -ExecutionPolicy bypass ^
- $files=@(dir^|?{($_ -is [System.IO.FileInfo]) -and ($_.Extension -eq '.xml')});^
- $arr='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.toCharArray();^
- for($i=0;$i -lt $files.length;$i++){^
- write-host $files[$i].Name;^
- $dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
- $list=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
- $text=[IO.File]::ReadAllText($files[$i].FullName, [Text.Encoding]::UTF8);^
- $m=[regex]::matches($text,'name=\""([^^\""]+)\""');^
- $n=65;^
- $newtext=$text;^
- if($m.Count -ge 1){^
- for($j=0;$j -lt $m.Count;$j++){^
- $kw=$m[$j].groups[0].value;^
- if(-not $dic.ContainsKey($kw)){^
- $c=@(get-random -input $arr -count 3) -join '';^
- while($list.ContainsKey($c)){$c=@(get-random -input $arr -count 3) -join '';};^
- $list.add($c,'');^
- $newtext=$newtext.replace($kw,'name=\"'+$c+'\"');^
- $newtext=[regex]::replace($newtext,'(?^<==)\""[^^\""]+?\""',{param($a);if($a.value.Contains($m[$j].groups[1].value)){$a.value.replace($m[$j].groups[1].value,$c);}else{$a.value}});^
- $dic.add($kw,[char]$n);^
- $n++;^
- };^
- };^
- [IO.File]::WriteAllText(('%folder%\'+$files[$i].Name), $newtext, [Text.Encoding]::UTF8);^
- };^
- }
- pause
复制代码 zaqmlp5.23- @echo off
- cd /d "%~dp0"
- set "folder=结果"
- md "%folder%" 2>nul
- powershell -NoProfile -ExecutionPolicy bypass ^
- $files=@(dir^|?{($_ -is [System.IO.FileInfo]) -and ($_.Extension -eq '.xml')});^
- $arr='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.toCharArray();^
- for($i=0;$i -lt $files.length;$i++){^
- write-host $files[$i].Name;^
- $dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
- $list=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
- $text=[IO.File]::ReadAllText($files[$i].FullName, [Text.Encoding]::UTF8);^
- $m=[regex]::matches($text,'name=\""([^^\""]+)\""');^
- $n=65;^
- $newtext=$text;^
- if($m.Count -ge 1){^
- for($j=0;$j -lt $m.Count;$j++){^
- $kw=$m[$j].groups[0].value;^
- if(-not $dic.ContainsKey($kw)){^
- $c=@(get-random -input $arr -count 3) -join '';^
- while($list.ContainsKey($c)){$c=@(get-random -input $arr -count 3) -join '';};^
- $list.add($c,'');^
- $newtext=$newtext.replace($kw,'name=\"'+$c+'\"');^
- $newtext=[regex]::replace($newtext,'(?^<==)\""[^^\""]+?\""',{param($a);if($a.value.Contains($m[$j].groups[1].value)){$a.value.replace($m[$j].groups[1].value,$c);}else{$a.value}});^
- $dic.add($kw,[char]$n);^
- $n++;^
- };^
- };^
- [IO.File]::WriteAllText(('%folder%\'+$files[$i].Name), $newtext, [Text.Encoding]::UTF8);^
- };^
- }
- pause
复制代码 zaqmlp5.23- @echo off
- cd /d "%~dp0"
- set "folder=结果"
- md "%folder%" 2>nul
- powershell -NoProfile -ExecutionPolicy bypass ^
- $files=@(dir^|?{($_ -is [System.IO.FileInfo]) -and ($_.Extension -eq '.xml')});^
- $arr='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.toCharArray();^
- for($i=0;$i -lt $files.length;$i++){^
- write-host $files[$i].Name;^
- $dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
- $list=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
- $text=[IO.File]::ReadAllText($files[$i].FullName, [Text.Encoding]::UTF8);^
- $m=[regex]::matches($text,'(?^<!^<Extra )name=\""([^^\""]+)\""');^
- $newtext=$text;^
- if($m.Count -ge 1){^
- for($j=0;$j -lt $m.Count;$j++){^
- $kw=$m[$j].groups[1].value;^
- if(@('=','%%') -notcontains $kw){^
- if(-not $dic.ContainsKey($kw)){^
- $c=@(get-random -input $arr -count 3) -join '';^
- while($list.ContainsKey($c)){$c=@(get-random -input $arr -count 3) -join '';};^
- $list.add($c,'');^
- $newtext=$newtext.replace($m[$j].groups[0].value,'name=\"'+$c+'\"');^
- $dic.add($kw,$c);^
- $n++;^
- };^
- };^
- };^
- $k=@($dic.keys^|sort {$_.length} -des);^
- $newtext=[regex]::replace($newtext,'(?^<==)\""[^^\""]+?\""',{param($a);$b=$a.value;foreach($it in $k){$b=$b.replace(('@'+$it),('@'+$dic[$it])).replace(('#'+$it),('#'+$dic[$it])).replace(($it+'.animation'),($dic[$it]+'.animation')).replace(($it+'.visibility'),($dic[$it]+'.visibility'));};$b});^
- [IO.File]::WriteAllText(('%folder%\'+$files[$i].Name), $newtext, [Text.Encoding]::UTF8);^
- };^
- }
- pause
复制代码
|