Visual Basic 6 Read/Edit Binary (HEX) [CODE SAMPLE]

Discussion in 'Mixed Languages' started by Mazzif, Oct 24, 2013.

  1. Mazzif

    Mazzif Elitebook Pwner

    Oct 18, 2013
    322
    443
    10
    #1 Mazzif, Oct 24, 2013
    Last edited by a moderator: Apr 20, 2017
    for my HP Probook/Elitebook Password patch program, I did some hex editing in program. Here is some basics that may help someone else down the road. I tried to document what i was doing and why as best i could, may not be the best, but it works.

    To open a file as binary and display an offset location in a textbox

    Code:
    Sub GetData()
    Dim nFileNum As Integer, sLocation1 As String, sLocation2 As String 'declarations
    nFileNum = FreeFile 'get file ID
    Open App.Path & "\filename.bin" For Binary Access Read Lock Read Write As #nFileNum 'file to open
    sLocation1 = Space$(10) 'my first offset is 10 chars long, set a string placeholder must equal the size of data you want to hold
    sLocation2 = Space$(32) 'my second offset is 32 chars longs, set a string placeholder must equal the size of data you want to hold
    Get #nFileNum, 12000, sLocation1 'The offset location in Binary of the data I want to show (+1 to offset because we start at 0!)
    Text1.Text = sLocation1  'display the 10 chars data in a textbox
    Get #nFileNum, 12500, sLoation2 ' The offset location in Binary of the data I want to show (+1 to offset because we start at 0!)
    Text2.Text = sLocation2  'display the 32 chars data in a textbox
    Close #nFileNum  'Cloase the file
    End Sub  'Call GetData()
    To open a file as binary and edit an offset location with data from a textbox

    Code:
    Sub WriteBin()
    Dim sFileText As String 'declarations
    Dim iFileNo As Integer
    iFileNo = FreeFile
    Dim nFileNum As Integer
    nFileNum = FreeFile 'get random file number
    Open App.Path & "filename.bin" For Binary Access Write Lock Read Write As #nFileNum 'open file for edit
    Put #nFileNum, 12000, Text1.Text 'Offset is +1 because we start at 0! write data from textbox1 to offset location
    Put #nFileNum, 12500, Text2.Text 'Offset is +1 because we start at 0! write data from textbox2 to offset location
    Close #nFileNum 'Call WriteBin()
    End Sub
    
    Hope this was informative. Yes I know VB6 is old and dated, but it is still quite effective, and often times less complicated then .NET. I work in VB6 and VB Stuido 2013, I often prefer VB6. :rolleyes:
     
  2. osamab40

    osamab40 MDL Novice

    Nov 19, 2011
    8
    0
    0
    Attach Source !:macwheel: