返回列表 发帖
$a=(gc test.reg) -join "`n"
$a -split '(?=\[.*\])'|%{
$_ -split '(?=".+"=.*)'|%{
if($_ -match '^\s*\[([^\\]+)\\(.+)\]\s*$'){$b=$matches[1..2];";$_"}
if($_ -match '"(?s)([^"]+)"=(.+)'){
$c=$matches[1..2]|%{$_.trim()}
if($c[1] -match '^"'){$s='T'}elseif($c[1] -match '^dword:(.*)'){$s='D';$c[1]=$matches[1]}elseif($c[1] -match '(?s)^hex:(.*)'){$s='H';$c[1]=$matches[1]}
if($s -eq 'H'){$c[1]=$c[1] -replace ',\\\s*|,',' ';$d='.str(1 "';$e='")'}else{$d='=';$e=''}
"{0} {1}{4}{2}{5}`n{3}`n" -f $s,$c[0],($c[1] -replace '\\\\','\'),$('set {0} "{1}" "{2}" {3}' -f $c[0],$c[0],$b[1],$b[0]),$d,$e
}
}
}COPY
1

评分人数

    • 5i365: 技术牛X, 乐于分享技术 + 1

TOP

$a=(gc test.reg) -join "`n"
$a -split '(?=\[.*\])'|%{
$_ -split '(?=".+"=.*)'|%{
if($_ -match '^\s*\[([^\\]+)\\(.+)\]\s*$'){$b=$matches[1..2];";$_"}
if($_ -match '"(?s)([^"]+)"=(.+)'){
$c=$matches[1..2]|%{$_.trim()}
if($c[1] -match '^"'){$s='T'}elseif($c[1] -match '^dword:(.*)'){$s='D';$c[1]=$matches[1]}elseif($c[1] -match '(?s)^hex:(.*)'){$s='H';$c[1]=$matches[1]}
if($s -eq 'H'){$c[1]=$c[1] -replace ',\\\s*|,',' ';$d="`n{0}{1}" -f $c[0],'.str(1 "';$e='")'}else{$d='=';$e=''}
$c[1]=$c[1] -replace '\\\\','\'
$g="`n"
if($c[1] -match '.*\n.*\n'){$c[1]=$c[1] -replace '^"|"$' -split '\n'|%{if($_.trim() -ne ''){'',$_.trim()}};$c[1]=$c[1]|out-string;$g=''}
"{0} {1}{4}{2}{5}{6}{3}`n" -f $s,$c[0],$c[1],$('set {0} "{1}" "{2}" {3}' -f $c[0],$c[0],$b[1],$b[0]),$d,$e,$g
}
}
}COPY
回复 3# 5i365

TOP

返回列表