VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple way to detect if your file has been edited with hexeditor or any other way. You can enhance

by Labuneba (2 Submissions)
Category: Encryption
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 14th February 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Simple way to detect if your file has been edited with hexeditor or any other way. You can enhance it with encryption and many other ways.

Rate Simple way to detect if your file has been edited with hexeditor or any other way. You can enhance



'This code is simple way to detect if your file has been edited with
'hexeditor or otherway.
'This saves the listbox file to same direct as the application with
'the name test.txt it checks the data and creates a checknumber out of them
'and saves it to first line of file.
'when loading file it loads the number from the file and calculates a new one
'if the numbers does not match, file has been edited

'this is actually tutorial purposes only so it only uses the first letter of the
'list item so if you edit the second letter in row it doesn't know that
'you can also encrypt the file before saving and then decrypt and check.

'any comments? E-mail me at [email protected]
'if you wish to use this code in your apps.
'please let me know. I'd like to know what kind of app
'you make that has use for my lil app


'Add Command button named Command1 to the form  (Load button)
'Add Command button named Command2 to the form  (Save Button)
'Add Listbox named List1 to the form            (Data showing)

'Then just simply add the following code to your form

Private Sub Command1_Click() 'Load button
On Error GoTo error
List1.Clear

Dim Buffa As Integer
Buffa = 0
Dim Checknum As Integer
Dim i As Integer
Dim a As String

Open App.Path & "\test.txt" For Input As #1
Input #1, Checknum  'retrieve first line of file which is the Checknumber
Do Until EOF(1)
Input #1, a         'retrieve rest of the data to the list box
List1.AddItem a
Loop
Close 1

For i = 0 To List1.ListCount - 1
Buffa = Buffa * 1 + Asc(List1.List(i))  'calculates the new checknumber
Next

If Buffa = Checknum Then        'if Buffa and Checknum matches the file has not been eidited
MsgBox ("Not edited")
Else
MsgBox ("File has been edited") 'and if doesn't match then file has been edited
End If

Exit Sub
error:
Dim x As Integer

x = MsgBox("File Not Found", vbOKOnly, "Error")

End Sub

Private Sub Command2_Click() 'Save button
On Error GoTo error
Dim Buffer As Integer
Dim i As Integer

For i = 0 To List1.ListCount - 1
Buffer = Buffer * 1 + Asc(List1.List(i))    'creates the checknumber for the file
Next
Dim a As String
Open App.Path & "\test.txt" For Output As #1
Print #1, Buffer                            'saves the checknumber for the first row of the file

For i = 0 To List1.ListCount - 1
a = List1.List(i)                       'saves rest of the data
Print #1, a
Next

Close 1
Exit Sub
error:
Dim x As Integer

x = MsgBox("There has been a error!", vbOKOnly, "Error")
End Sub

Private Sub Form_Load()
'adds just some data to save
List1.AddItem ("Info 1")
List1.AddItem ("Info 2")
List1.AddItem ("Info 3")
List1.AddItem ("Info 4")
List1.AddItem ("More Info")
List1.AddItem ("Just info")
List1.AddItem ("last info")
End Sub


Download this snippet    Add to My Saved Code

Simple way to detect if your file has been edited with hexeditor or any other way. You can enhance Comments

No comments have been posted about Simple way to detect if your file has been edited with hexeditor or any other way. You can enhance . Why not be the first to post a comment about Simple way to detect if your file has been edited with hexeditor or any other way. You can enhance .

Post your comment

Subject:
Message:
0/1000 characters