9119
03-08-2021, 14:26
Разобрался:
Так запускаю скрипт:
$list = Get-content C:\Users\Administrator\Desktop\list.txt
$number = 0
$my_data = ($list)[$number]
While ($my_data -ne $null)
{
$file = Get-ChildItem -Path "C:\Windows\Temp" -recurse -include *.tmp | Sort-Object LastAccessTime -Descending | Sort-Object -Descending -Property length | Select-Object -First 1 |%{$_.FullName}
$my_data_byte = $([byte[]]($my_data -split ','))
.\find_replace.ps1 -fin (0x08,0x3A,0x35,0x32,0x88,0x65,0x59,0x18,0x01) -rep ($my_data_byte)
$current_stroke = $number + 1
echo "Строка с данными в документе - $current_stroke"
echo "Данные - $my_data"
echo "Временный файл - $file"
pause
$list = Get-content C:\Users\Administrator\Desktop\list.txt
$number = $number + 1
$my_data = ($list)[$number]
if ($my_data -eq $null){
Write-Host "Список данных пустой!"
break
}
}
Сам скрипт:
param(
[byte[]]$fin = (0x08,0x3A,0x35,0x32,0x88,0x65,0x59,0x18,0x01),
[byte[]]$rep = (0x08,0x8A,0x34,0x31,0x87,0x64,0x58,0x17,0x00)
)
$file = Get-ChildItem -Path "C:\Windows\Temp" -recurse -include *.tmp | Sort-Object LastAccessTime -Descending | Sort-Object -Descending -Property length | Select-Object -First 1 |%{$_.FullName}
$fout = Get-ChildItem -Path "C:\Windows\Temp" -recurse -include *.tmp | Sort-Object LastAccessTime -Descending | Sort-Object -Descending -Property length | Select-Object -First 1 |%{$_.FullName}
$bytes = [io.file]::readallbytes($file)
$i = -1
$a = -join $fin
do {
$i = [byte[]]::indexof($bytes,$fin[0],($i+1))
[byte[]]$tmp = @()
for ($k = $i; $k -lt ($i+$fin.count);$k++){
$tmp += $bytes[$k]
}
$b = -join $tmp
} while ($a -ne $b)
for ($j,$n=0,$i;$j -lt $rep.count;$n++,$j++){
$bytes[$n] = $rep[$j]
}
[io.file]::writeallbytes($fout, $bytes)
Спасибо огромное всем кто откликнулся!
Так запускаю скрипт:
$list = Get-content C:\Users\Administrator\Desktop\list.txt
$number = 0
$my_data = ($list)[$number]
While ($my_data -ne $null)
{
$file = Get-ChildItem -Path "C:\Windows\Temp" -recurse -include *.tmp | Sort-Object LastAccessTime -Descending | Sort-Object -Descending -Property length | Select-Object -First 1 |%{$_.FullName}
$my_data_byte = $([byte[]]($my_data -split ','))
.\find_replace.ps1 -fin (0x08,0x3A,0x35,0x32,0x88,0x65,0x59,0x18,0x01) -rep ($my_data_byte)
$current_stroke = $number + 1
echo "Строка с данными в документе - $current_stroke"
echo "Данные - $my_data"
echo "Временный файл - $file"
pause
$list = Get-content C:\Users\Administrator\Desktop\list.txt
$number = $number + 1
$my_data = ($list)[$number]
if ($my_data -eq $null){
Write-Host "Список данных пустой!"
break
}
}
Сам скрипт:
param(
[byte[]]$fin = (0x08,0x3A,0x35,0x32,0x88,0x65,0x59,0x18,0x01),
[byte[]]$rep = (0x08,0x8A,0x34,0x31,0x87,0x64,0x58,0x17,0x00)
)
$file = Get-ChildItem -Path "C:\Windows\Temp" -recurse -include *.tmp | Sort-Object LastAccessTime -Descending | Sort-Object -Descending -Property length | Select-Object -First 1 |%{$_.FullName}
$fout = Get-ChildItem -Path "C:\Windows\Temp" -recurse -include *.tmp | Sort-Object LastAccessTime -Descending | Sort-Object -Descending -Property length | Select-Object -First 1 |%{$_.FullName}
$bytes = [io.file]::readallbytes($file)
$i = -1
$a = -join $fin
do {
$i = [byte[]]::indexof($bytes,$fin[0],($i+1))
[byte[]]$tmp = @()
for ($k = $i; $k -lt ($i+$fin.count);$k++){
$tmp += $bytes[$k]
}
$b = -join $tmp
} while ($a -ne $b)
for ($j,$n=0,$i;$j -lt $rep.count;$n++,$j++){
$bytes[$n] = $rep[$j]
}
[io.file]::writeallbytes($fout, $bytes)
Спасибо огромное всем кто откликнулся!