VB.Net binary reader of a QuickBooks binary file
by Mountain Computers Inc., Publication Date: Saturday, February 19, 2022
View Count: 1013, Keywords: VB.Net, Read Binary, Quickbooks, Signature, Hashtags: #VB.Net #ReadBinary #Quickbooks #Signature
had to write a quick piece of code to read the first 1024 bytes of a QBW file to see the recovery code marker signature. it was MAUI now its something else; depending I guess on the QB version. had to use a fixed font called Consolas for windows 10 since other sans serif's did not work as expected in formatting for readability.
tip: to create some fast example text, launch word for windows, on a blank like type =rand() and press enter key. i did the 0 through 9 and A through F for the data.txt and data.dat is a copy of a QBW binary.
working on the API to access the QBW in a few. that will be fun. If you go out of bounds on the Bytes to Read and the Chr() function you will have to add some catch error handling and look at the debugger. I wanted something quick and fast to read a header. I adjusted the code to read more and handle a few of the uncertain hex and val and chr values in the byte read.
That was interesting and quick to create. see the REF1 at the bottom for reference to MAUI.
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
If My.Computer.FileSystem.FileExists(TextBox1.Text) Then
Debug.Print("file exists")
Label3.Text = "Yes"
Call CheckQBWfile()
Else
Debug.Print("file does not exist")
Label3.Text = "No"
End If
End Sub
Private Sub CheckQBWfile()
Try
Using reader As New BinaryReader(File.Open(TextBox1.Text, FileMode.Open, FileAccess.Read))
' Loop through length of file.
Dim buf As String = ""
Dim buf2 As String = ""
Dim pos As Integer = 1
Dim length As Integer = reader.BaseStream.Length
Dim qbwposition As Integer = Val(TextBox2.Text)
While pos < qbwposition
Dim value As Integer = reader.ReadByte
buf = buf & Hex(value).PadLeft(2, "0") & " "
Select Case value
Case 32 To 127
buf2 = buf2 & Chr(value)
Case Else
buf2 = buf2 & "."
End Select
If pos Mod 16 = 0 Then
ListBox1.Items.Add(Hex(pos - 16).PadLeft(8, "0") & ": " & buf & " | " & buf2)
buf = ""
buf2 = ""
End If
pos += 1
End While
End Using
Catch
'do nothing
Finally
'do nothing
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Text = "Filename:"
Label2.Text = "File Exists?"
Label3.Text = "?"
Label4.Text = "Bytes to Read:"
ListBox1.Font = New Drawing.Font("Consolas", 12, FontStyle.Regular)
TextBox1.Text = "data.dat"
TextBox2.Text = "1024"
Button1.Text = "Read File"
End Sub
End Class
more to come...
if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.
© 2024 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.