本帖最后由 zaqmlp 于 2020-11-19 13:52 编辑
bat- <# :
- cls
- @echo off
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'"
- pause
- exit
- #>
- $file1=".\a.txt";
- $file2=".\IDS.txt";
- $file3=".\dump.txt";
- $file4=".\结果.txt";
-
- $self=get-item -liter $args[0];
- $path=$self.Directory.FullName;
- $file1=$file1 -replace '^\.',$path;
- $file2=$file2 -replace '^\.',$path;
- $file3=$file3 -replace '^\.',$path;
- $file4=$file4 -replace '^\.',$path;
- if(-not (test-path -liter $file1)){write-host ('"'+$file1+'" not found');exit;};
- if(-not (test-path -liter $file2)){write-host ('"'+$file2+'" not found');exit;};
- if(-not (test-path -liter $file3)){write-host ('"'+$file3+'" not found');exit;};
-
- $enc=[Text.Encoding]::UTF8;
- $text1=[IO.File]::ReadAllLines($file1, $enc);
- $text2=[IO.File]::ReadAllLines($file2, $enc);
- $text3=[IO.File]::ReadAllLines($file3, $enc);
-
- write-host 'Laoding……';
-
- $dic1=New-Object 'System.Collections.Generic.Dictionary[string,string]';
- $dic2=New-Object 'System.Collections.Generic.Dictionary[string,string]';
- for($i=0;$i -lt $text2.count;$i++){
- $line=$text2[$i].trim() -split '\s',2;
- if(-not $dic1.ContainsKey($line[1])){$dic1.add($line[1], $line[0])};
- if(-not $dic2.ContainsKey($line[0])){$dic2.add($line[0], $line[1])};
- };
-
- $dic3=New-Object 'System.Collections.Generic.Dictionary[string,object]';
- for($i=0;$i -lt $text3.count;$i++){
- $line=$text3[$i].trimstart() -split '\s',2;
- $m=[regex]::matches($line[1], '(?i)u[\da-f]+');
- if($m.count -ge 1){
- [System.Collections.ArrayList]$crr=@();
- foreach($k in $m){
- [void]$crr.add($k.groups[0].value);
- };
- $drr=@($crr|sort);
- $tmpline=$drr -join ':';
- if(-not $dic3.ContainsKey($tmpline)){
- [System.Collections.ArrayList]$key=@();
- $dic3.add($tmpline, $key);
- };
- if($dic3[$tmpline] -notcontains $line[0]){
- [void]$dic3[$tmpline].add($line[0]);
- };
- };
- };
-
- write-host 'Searching……';
-
- $fs=New-Object System.IO.FileStream($file4, [System.IO.FileMode]::Create);
- $sw=New-Object System.IO.StreamWriter($fs, $enc);
- for($i=0;$i -lt $text1.count;$i++){
- $line=$text1[$i].trim() -split '\s',2;
- $m=[regex]::matches($line[1].trim('[]'),'[\ud800-\udbff][\udc00-\udfff]|[\u0000-\uffff]');
- [System.Collections.ArrayList]$arr=@();
- if($m.count -ge 1){
- foreach($k in $m){
- if($dic1.ContainsKey($k.groups[0].value)){
- [void]$arr.add($dic1[$k.groups[0].value]);
- };
- };
- };
- $line=$text1[$i];
- if($arr.count -ge 1){
- $err=@($arr|sort);
- $tmpline=$err -join ':';$tmpline
- if($dic3.ContainsKey($tmpline)){
- for($j=0;$j -lt $dic3[$tmpline].count;$j++){
- if($dic2.ContainsKey($dic3[$tmpline][$j])){
- $line+=(' '+$dic3[$tmpline][$j]+'('+$dic2[$dic3[$tmpline][$j]]+')')
- };
- };
- };
- };
- write-host $line;
- $sw.WriteLine($line);
- $sw.Flush();
- };
- $sw.Close();
- $fs.Close();
复制代码
|