Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change bytes in a binary file and save the file?

Status
Not open for further replies.

egstatus

Programmer
Apr 14, 2005
143
0
0
US
Hi all,
How do I change bytes in a binary file?

I have a little function that read bytes 335-343 [For Keyer] and bytes 344-352 [for verifier] and displays it.

These bytes store who the keyerID and VerifierID of a data entry file are. From time to time the Verifier Resumes the file [to insert new records], and her name gets stored in the KeyerID bytes. So if the original keyer had lots of errors, the new verifier now becomes the owner of this file and the errors are attributed to him/her [not fair]. He/She gets penalized when there are lots of errors.

My question to you is, how do I change the content of those bytes and save it to the file, without damaging any part of the file? I want to save 'H345' in those bytes, [345 is an example of a Keyer/Verifier ID]

note - as of now I am using 010 Editor to manually change those bytes.

I am using vb.net 2008

Here is the function I use to find out who the keyer and Verifier of the date entry file are.

Code:
Sub FindInfoFromFile(ByRef strFileToCheck As String)

        Dim bYes As Boolean
        Dim strOpName As String = ""
        Dim strVerName As String = ""
        Dim strKeyer As String = ""
        Dim strVerifier As String = ""
        Dim strFileFlag As String = ""

        Dim intMyPos As Short
        Dim intMyPos2 As Short

        On Error GoTo ErrorHandler

        If strFileToCheck <> "" Then
            Fname = Fname & strFileToCheck

            strOpName = ""
            strVerName = ""
            strFileFlag = ""
            sNewFile = Fname

            Using fs As New FileStream(sNewFile, FileMode.Open)

                Dim strOutofBFlag As String = ""
                Using br As New BinaryReader(fs)

                    'Check The file type to see it it is an ezc file
                    fs.Position = 0
                    'For x As Integer = 1 To 2
                    strFileFlag &= br.ReadChar
                    'Next
                    If strFileFlag <> "d" Then
                        'Exit the loop because this is not an ezc file
                        MsgBox("Invalid File Type Being Checked: " & sNewFile)
                        GoTo ExitFileCheck
                    End If

                    fs.Position = 335
                    'Get Keyers Name - this info is stored in bytes 335 to 344
                    For x As Integer = 335 To 343
                        strOpName &= br.ReadChar
                    Next x
                    'Verifier are bytes 344-352
                    fs.Position = 344
                    For x As Integer = 344 To 352
                        strVerName &= br.ReadChar
                    Next x

                End Using
            End Using

            'Parse the Keyers name by removing unwanted characters
            intMyPos2 = 0
            intMyPos2 = FindNonBlankPos(strOpName, Chr(0))
            strKeyer = Mid(strOpName, 1, intMyPos2 - 1)
            Text5.Text = strKeyer

            'Parse the Verifyer name by removing unwanted characters
            intMyPos2 = 0
            intMyPos2 = FindNonBlankPos(strVerName, Chr(0))
            strVerifier = Mid(strVerName, 1, intMyPos2 - 1)
            'Text8.Text = StatusDB.GetNameByEmpID(strVerifier)
            Text8.Text = strVerifier
        End If
ExitFileCheck:

ExitHere:
        Exit Sub

ErrorHandler:
        Select Case Err.Number
            Case 5
                MsgBox("Invalid File Type " & Err.Number & " :-: " & Err.Description)
                'Resume Next
            Case Else
                'cout Err.Number & Err.Description, endl
                Call HandleUnexpectedError(Err.Number, Err.Description)
        End Select

        Resume ExitHere
        'GoTo ExitHere
        Resume Next

    End Sub

Thanks in advance.

EG.
 
Here is what the begining of a file looks like.

Code:
d€€€€€€€€€€ô€€€æÅ€€<€€’€¸LØ€€€€ÿÿÿÿÂÿÿ€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€JWTRAD-C€€€JWTEDITC€€€FIXYR€€€€€€H578€€€€€€€H356€€€€€ED€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€f:/ezc/files/T9214054€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€JWT-1C€€€€€€€€€€€€JWT2RC€€€€€€€€€€€€JWTTOR-3€€€€€€€€€€JWT-3A€€€€€€€€€€	€€JWT2E€€€€€€€€€€€€€€€€€€€€€€€€€€€THBA051000000001751€á¬Ï€€u€€0901100218P30 THBA051000000001751€á¬ü€€¢€€0901100418P30 THBA051000000001751€á¬)€€Ï€€0901100618P30 THBA051000000001751€á¬V€€ü€€0902100653A30 THBA051000000001751€á¬ƒ€€)€€0902101143A30 THBA051000000001751€á¬°€€V€€0902100718P30 THBA051000000001751€á¬Ý€€ƒ€€0903100741A30 THBA051000000001751€á¬
	€€°€€0903100143P30 THBA051000000001751€á¬7	€€Ý€€0903100343P30 THBA051000000001751€á¬d	€€

About 4-5 lines down, you can see H578 and H356.
H578 [bytes 335-343] is the ID for the keyer and H356 [bytes 344-352] is the ID for the verifier.

I would like to be able to change both of these ID's without damaging the file.

Please help.

Thanks

EG.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top