找到你要的答案

Q:how do i split large binary file on certain byte header in vb.net 2010

Q:我怎么分在vb.net 2010某些字节的头大的二进制文件

I have a very large binary file 250 gigs working to split this file into smaller files starting from a certain bytes header until a new header or end-of-file is reached i want this part to be stored as a separate new file for each case like this.

  1. looking for certain byte pattern.(header)
  2. have to save all the data till first occurrence (excluding the header).
  3. starting from the first occurrence of header all data will be save until a second header is found in a separate file.
  4. all the data from first occurrence till end of file will be stored as separate file.

    Sub hexDumpFile(fil As String)
        Using reader As New BinaryReader(File.Open(fil, FileMode.Open))
            ' Loop through length of file.
            Dim pos As Integer = 0
            Dim length As Long = reader.BaseStream.Length
            'looking up for 00 00 01 BA 44 00 04 00 04
            Dim header(9) As Byte
            Dim buff(18) As Byte   
            header = {&H0, &H0, &H1, &HBA, &H44, &H0, &H4, &H0, &H4}
            buff.Initialize()
            Dim i As Integer
            While pos < length - buff.Length
                '--- Read the integer.
                buff.Initialize()
                buff = reader.ReadBytes(buff.length)
                Console.Write(Hex(pos) & ":")
                ' Write to screen.
                Try
                    For i = 0 To buff.Length
                        Console.Write(Hex(buff(i))) hex value
                        Console.Write(" ") ' space
                    Next
                    Console.WriteLine("") ' line break
    
                Catch EX As Exception
                    Console.WriteLine(EX.Source.ToString)
                    Console.WriteLine(EX.Message)
                End Try
                ' Add length of integer in bytes to position.
                pos += 1
            End While
        End Using
    End Sub
    

Problems:

  1. can not avoid exceptions --> Index was outside the bounds of the array.
  2. can not find first match
  3. can not save separate files

我有一个非常大的二进制文件250演出工作把这个文件成较小的文件从某个字节的头直到一个新的标题或文件结束了我想这部分被存储为一个单独的新文件为每个这样的情况。

  1. looking for certain byte pattern.(header)
  2. have to save all the data till first occurrence (excluding the header).
  3. starting from the first occurrence of header all data will be save until a second header is found in a separate file.
  4. 所有从第一次出现到结束的数据将被存储为单独的文件。

    Sub hexDumpFile(fil As String)
        Using reader As New BinaryReader(File.Open(fil, FileMode.Open))
            ' Loop through length of file.
            Dim pos As Integer = 0
            Dim length As Long = reader.BaseStream.Length
            'looking up for 00 00 01 BA 44 00 04 00 04
            Dim header(9) As Byte
            Dim buff(18) As Byte   
            header = {&H0, &H0, &H1, &HBA, &H44, &H0, &H4, &H0, &H4}
            buff.Initialize()
            Dim i As Integer
            While pos < length - buff.Length
                '--- Read the integer.
                buff.Initialize()
                buff = reader.ReadBytes(buff.length)
                Console.Write(Hex(pos) & ":")
                ' Write to screen.
                Try
                    For i = 0 To buff.Length
                        Console.Write(Hex(buff(i))) hex value
                        Console.Write(" ") ' space
                    Next
                    Console.WriteLine("") ' line break
    
                Catch EX As Exception
                    Console.WriteLine(EX.Source.ToString)
                    Console.WriteLine(EX.Message)
                End Try
                ' Add length of integer in bytes to position.
                pos += 1
            End While
        End Using
    End Sub
    

Problems:

  1. can not avoid exceptions --> Index was outside the bounds of the array.
  2. can not find first match
  3. can not save separate files
vb.net