|
Re: Read and search through a binary file If I misunderstood your question and you only need to check the previous byte's bits, try this:
# v1
$file = <file's path>
$pattern = '131B1B087C156108AE151B'
$bytes = [string]::join('', (gc $file -en byte | % {'{0:X2}' -f $_}))
[regex]::matches($bytes,$pattern) |
% {
$i = $_.index - 2
$byte = [string]::join('', $bytes[$i++..$i])
[convert]::toString(([int]"0x$byte"), 2)
}
# v2 CTP
$file = <file's path>
$pattern = '131B1B087C156108AE151B'
$bytes = (gc $file -en byte | % {'{0:X2}' -f $_}) -join ''
select-string $pattern -inp $bytes -all |
% {$_.matches |
% {
$i = $_.index - 2
$byte = $bytes[$i++..$i] -join ''
[convert]::toString(([int]"0x$byte"), 2)
}
}
--
Kiron |