![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #11 (permalink) |
| | Re: Read and search through a binary file "Robertico" <Nomail@xxxxxx> wrote in message news:eJZVatZmIHA.5084@xxxxxx Quote: > Kiron, > > Thanks for the explanation. I'am running version 1.0. > I didn't notice the meaning off v1 and v2. I thought that is was just an > other approach. > > I need to convert the returning 'prevoius bytes' from "Big Endian" to > 'Little Endian'' . The binary file is in "Big Endian". > The code " [bitConverter]::toString($byteArray) -replace '-' " indeed > doesn't convert to "Little Endian". > So i need some advice to fix this. > are running on an x86 based platform, this will convert big endian to little endian. -- Keith |
My System Specs![]() |
| | #12 (permalink) |
| | Re: Read and search through a binary file Another attempt, this time using the System.Text.Encoding Class to convert each [byte[]] from BigEndian encoding to LittleEndian encoding. $file = <file's path> $pattern = '131B1B087C156108AE151B' $prevBytes = 8 $bytes = [string]::join('', (gc $file -en byte | % {'{0:X2}' -f $_})) $bigEndian = [text.encoding]::bigEndianUnicode $littleEndian = [text.encoding]::unicode [regex]::matches($bytes, $pattern, 1) | % { $i = $_.index - $prevBytes * 2 [string]::join('', $bytes[$i..($i + $prevBytes * 2 - 1)]) | % { $hexBytes = $_ $byteArray = 0..($hexBytes.length - 1) | ? {!($_ -band 1)} | % { $i = $_ "0x$($hexBytes.subString($i,2))" } $littleEndianBytes = [text.encoding]::convert($bigEndian, $littleEndian, $byteArray) [string]::join('', ($littleEndianBytes | % {'{0:X2}' -f $_})) # next line produces same output as the previous line # [bitConverter]::toString($littleEndianBytes) -replace '-' } } -- Kiron |
My System Specs![]() |
| | #13 (permalink) |
| | Re: Read and search through a binary file Krion, This one does the trick :-)) e.g. the return value in Big Endian is '097AD6060956354F' en after the conversion to Little Endian it becomes '4F35560906D67A09'. Thanks a lot ! Now it's working and time to study why it's working :-)) Robertico "Kiron" <Kiron@xxxxxx> wrote in message news:C4D22AE4-2DCE-426E-B53B-77E2A3D4B68E@xxxxxx Robertico, I'm no expert on Endianness but I understand the difference is in the order of the bytes, so maybe by reversing the $byteArray you get what you want. If not, I hope someone with more knowledge on Endianness provides the correct or a better method. Try this: $file = <file's path> $pattern = '131B1B087C156108AE151B' $prevBytes = 8 $bytes = [string]::join('', (gc $file -en byte | % {'{0:X2}' -f $_})) [regex]::matches($bytes, $pattern, 1) | % { $i = $_.index - $prevBytes * 2 [string]::join('', $bytes[$i..($i + $prevBytes * 2 - 1)]) | % { $hexBytes = $_ $byteArray = 0..($hexBytes.length - 1) | ? {!($_ -band 1)} | % { $i = $_ "0x$($hexBytes.subString($i,2))" } [array]::reverse($byteArray) [bitConverter]::toString($byteArray) -replace '-' } } -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Binary search and replace | General Discussion | |||
| Re: Altering a binary file on the fly | .NET General | |||
| writing an binary file from sql to the disk with vb.net | .NET General | |||
| search and replace in binary file | VB Script | |||
| How to embed manifest in TCL binary? - mt.exe corrupting my binary | Vista General | |||