разбор разреженного изображения VB

#vb.net #sparse-matrix #android-image #sparse-file

Вопрос:

Я пытаюсь разобрать sparse.img на unsparse.img я успешно получил общий кусок и первый кусок , и проблема в том, что когда я пытаюсь получить заголовок 2-го куска, это означает, что не могу получить тип заголовка куска вопрос в том, где я получу следующий кусок заголовка

мой код предназначен для получения буфера

 Dim hSparseImage = -1  Dim bSparseImage = False  Dim openfile = "userdata.img"  Dim infos As New FileInfo(openfile)  Dim fileLength = infos.Length  Dim count = 1048576  Dim EXT4_CHUNK_HEADER_SIZE = 12  Dim sparseheader As SPARSE_HEADER  Dim chunkheader As CHUNK_HEADER  Dim stream As New FileStream(openfile, FileMode.Open, FileAccess.Read)  Using reader As New BinaryReader(stream)  Dim buffer(fileLength) As Byte  reader.BaseStream.Seek(0, SeekOrigin.Begin)  reader.Read(buffer, 0, 28)  sparseheader = parsingheader(buffer)  Dim magic = sparseheader.dwMagic   Dim header_magic = (Val("amp;HE" amp; Hex(magic)))  Dim dwChunkSize As Long = 0  Dim offsetnya As Long = 0  Dim nextt = 0  Dim chunkh As Integer  Dim hexchunktype As Int32  If header_magic = SPARSE_MAGIC Then  Dim totalchunk = sparseheader.dwTotalChunks  If totalchunk gt; 0 Then  For i = 0 To totalchunk - 1  reader.Read(buffer, 0, 12)  chunkheader = parsingchunk(buffer)    Dim chunktype = chunkheader.wChunkType  hexchunktype = (Val("amp;HE" amp; Hex(chunktype)))  If hexchunktype = SPARSE_RAW_CHUNK Then  dwChunkSize = chunkheader.dwChunkSize * sparseheader.dwBlockSize  RichTextBox1.Text  = "chunk total size " amp; chunkheader.dwTotalSize amp; vbNewLine  ElseIf hexchunktype = SPARSE_FILL_CHUNK Then  RichTextBox1.Text  = "fill" amp; vbNewLine  ElseIf hexchunktype = SPARSE_DONT_CARE Then  RichTextBox1.Text  = "DoNT care" amp; vbNewLine  Else  RichTextBox1.Text  = "Invalid data" amp; vbNewLine  End If  chunkh = chunkh   chunkheader.dwTotalSize  RichTextBox1.Text  = i amp; chunkh amp; vbNewLine amp; vbNewLine  Next  Else  RichTextBox1.Text  = "Pailit get total chunk"  End If  End If   End Using  stream.Close()  

и для получения структуры и получения буферного массива для структурирования

 Private Function parsingheader(ByVal bytes As Byte()) As SPARSE_HEADER  Dim stuff As SPARSE_HEADER  Dim handle As GCHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned)   Try  stuff = CType(Marshal.PtrToStructure(handle.AddrOfPinnedObject(), GetType(SPARSE_HEADER)), SPARSE_HEADER)  Finally  handle.Free()  End Try   Return stuff End Function  Private Function parsingchunk(ByVal bytes As Byte()) As CHUNK_HEADER  Dim stuff As CHUNK_HEADER  Dim handle As GCHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned)   Try  stuff = CType(Marshal.PtrToStructure(handle.AddrOfPinnedObject(), GetType(CHUNK_HEADER)), CHUNK_HEADER)  Finally  handle.Free()  End Try   Return stuff End Function  Private Structure SPARSE_HEADER  Public dwMagic As Int32  Public wVerMajor As Int16  Public wVerMinor As Int16  Public wSparseHeaderSize As Int16  Public wChunkHeaderSize As Int16  Public dwBlockSize As Int32  Public dwTotalBlocks As Int32  Public dwTotalChunks As Int32  Public dwImageChecksum As Int32   End Structure Private Structure CHUNK_HEADER  Public wChunkType As Int16  Public wReserved As Int16  Public dwChunkSize As Int32  Public dwTotalSize As Int32   End Structur