24 lines
668 B
PowerShell
24 lines
668 B
PowerShell
|
|
$f = 'C:/Users/77338/Desktop/STM32-OTA/STM32F103_App1/Src/main.c'
|
||
|
|
$bytes = [System.IO.File]::ReadAllBytes($f)
|
||
|
|
|
||
|
|
# Count literal \r\n sequences (0x5C 0x72 0x5C 0x6E)
|
||
|
|
$pat = @(0x5C, 0x72, 0x5C, 0x6E)
|
||
|
|
$count = 0
|
||
|
|
$out = [byte[]]::new($bytes.Count)
|
||
|
|
$j = 0
|
||
|
|
$i = 0
|
||
|
|
while ($i -lt $bytes.Count) {
|
||
|
|
$match = $true
|
||
|
|
for ($k = 0; $k -lt 4; $k++) {
|
||
|
|
if ($i + $k -ge $bytes.Count -or $bytes[$i + $k] -ne $pat[$k]) { $match = $false; break }
|
||
|
|
}
|
||
|
|
if ($match) {
|
||
|
|
$i += 4
|
||
|
|
} else {
|
||
|
|
$out[$j++] = $bytes[$i++]
|
||
|
|
}
|
||
|
|
}
|
||
|
|
[Array]::Resize([ref]$out, $j)
|
||
|
|
[System.IO.File]::WriteAllBytes($f, $out)
|
||
|
|
Write-Host "Removed $count \r\n sequences, $j bytes written"
|