Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' There might be a bug somewhere too lazy to care
- Imports System.Text
- Imports System.IO
- Module Main
- Private File1() As Byte
- Private File2() As Byte
- Dim PrevWasDif As Boolean = False
- Dim PrevWasSame As Boolean = False
- Dim lastAddress As Integer = 0
- Dim info As New StringBuilder
- Dim WithEvents comparetimer As New Timers.Timer
- Dim i As Integer = 0
- Sub main()
- comparetimer.Interval = 1000
- Dim selector As New OpenFileDialog
- selector.Title = "Select File1"
- selector.Multiselect = False
- Dim r As Windows.Forms.DialogResult = selector.ShowDialog()
- Select Case r
- Case Windows.Forms.DialogResult.OK
- File1 = System.IO.File.ReadAllBytes(selector.FileName)
- Case Else
- Exit Sub
- End Select
- selector.Title = "Select File2"
- r = selector.ShowDialog()
- Select Case r
- Case Windows.Forms.DialogResult.OK
- File2 = System.IO.File.ReadAllBytes(selector.FileName)
- If File1(0) = File2(0) Then
- PrevWasSame = True
- PrevWasDif = False
- Else
- PrevWasDif = True
- PrevWasSame = False
- End If
- Dim length As Integer = 0
- If File1.Length <= File2.Length Then length = File1.Length - 1 Else length = File2.Length - 1
- comparetimer.Start()
- While i < length
- Application.DoEvents()
- If File1(i) = File2(i) Then
- If PrevWasDif Then
- If lastAddress = i - 1 Then
- info.AppendLine("Byte at 0x" & Convert.ToString(i - 1, 16).ToUpper & " is different")
- Else
- info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(i - 1, 16).ToUpper & " are different")
- End If
- lastAddress = i
- End If
- PrevWasSame = True
- PrevWasDif = False
- Else
- If PrevWasSame Then
- If lastAddress = i - 1 Then
- info.AppendLine("Byte at 0x" & Convert.ToString(i - 1, 16).ToUpper & " is same")
- Else
- info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(i - 1, 16).ToUpper & " are same")
- End If
- lastAddress = i
- End If
- PrevWasSame = False
- PrevWasDif = True
- End If
- i += 1
- End While
- If PrevWasDif = True Then
- If lastAddress = length - 1 Then
- info.AppendLine("Byte at 0x" & Convert.ToString(length - 1, 16).ToUpper & " is different")
- Else
- info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(length - 1, 16).ToUpper & " are different")
- End If
- Else
- If lastAddress = length - 1 Then
- info.AppendLine("Byte at 0x" & Convert.ToString(length - 1, 16).ToUpper & " is same")
- Else
- info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(length - 1, 16).ToUpper & " are same")
- End If
- End If
- comparetimer.Stop()
- Console.Clear()
- Console.WriteLine("Compare completed at 0x" & Convert.ToString(length, 16).ToUpper)
- Console.WriteLine("Saving Comparison.txt")
- System.IO.File.WriteAllText(Directory.GetCurrentDirectory() + "\Comparison.txt", info.ToString)
- End Select
- End Sub
- Private Sub comparetimer_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles comparetimer.Elapsed
- Console.Clear()
- Console.WriteLine("Compared upto 0x" & Convert.ToString(i, 16).ToUpper)
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment