TizzyT

RangeCompare -TizzyT

Jul 15th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.40 KB | None | 0 0
  1. ' There might be a bug somewhere too lazy to care
  2. Imports System.Text
  3. Imports System.IO
  4. Module Main
  5.     Private File1() As Byte
  6.     Private File2() As Byte
  7.     Dim PrevWasDif As Boolean = False
  8.     Dim PrevWasSame As Boolean = False
  9.     Dim lastAddress As Integer = 0
  10.     Dim info As New StringBuilder
  11.     Dim WithEvents comparetimer As New Timers.Timer
  12.     Dim i As Integer = 0
  13.     Sub main()
  14.         comparetimer.Interval = 1000
  15.         Dim selector As New OpenFileDialog
  16.         selector.Title = "Select File1"
  17.         selector.Multiselect = False
  18.         Dim r As Windows.Forms.DialogResult = selector.ShowDialog()
  19.         Select Case r
  20.             Case Windows.Forms.DialogResult.OK
  21.                 File1 = System.IO.File.ReadAllBytes(selector.FileName)
  22.             Case Else
  23.                 Exit Sub
  24.         End Select
  25.         selector.Title = "Select File2"
  26.         r = selector.ShowDialog()
  27.         Select Case r
  28.             Case Windows.Forms.DialogResult.OK
  29.                 File2 = System.IO.File.ReadAllBytes(selector.FileName)
  30.                 If File1(0) = File2(0) Then
  31.                     PrevWasSame = True
  32.                     PrevWasDif = False
  33.                 Else
  34.                     PrevWasDif = True
  35.                     PrevWasSame = False
  36.                 End If
  37.                 Dim length As Integer = 0
  38.                 If File1.Length <= File2.Length Then length = File1.Length - 1 Else length = File2.Length - 1
  39.                 comparetimer.Start()
  40.                 While i < length
  41.                     Application.DoEvents()
  42.                     If File1(i) = File2(i) Then
  43.                         If PrevWasDif Then
  44.                             If lastAddress = i - 1 Then
  45.                                 info.AppendLine("Byte at 0x" & Convert.ToString(i - 1, 16).ToUpper & " is different")
  46.                             Else
  47.                                 info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(i - 1, 16).ToUpper & " are different")
  48.                             End If
  49.                             lastAddress = i
  50.                         End If
  51.                         PrevWasSame = True
  52.                         PrevWasDif = False
  53.                     Else
  54.                         If PrevWasSame Then
  55.                             If lastAddress = i - 1 Then
  56.                                 info.AppendLine("Byte at 0x" & Convert.ToString(i - 1, 16).ToUpper & " is same")
  57.                             Else
  58.                                 info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(i - 1, 16).ToUpper & " are same")
  59.                             End If
  60.                             lastAddress = i
  61.                         End If
  62.                         PrevWasSame = False
  63.                         PrevWasDif = True
  64.                     End If
  65.                     i += 1
  66.                 End While
  67.                 If PrevWasDif = True Then
  68.                     If lastAddress = length - 1 Then
  69.                         info.AppendLine("Byte at 0x" & Convert.ToString(length - 1, 16).ToUpper & " is different")
  70.                     Else
  71.                         info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(length - 1, 16).ToUpper & " are different")
  72.                     End If
  73.                 Else
  74.                     If lastAddress = length - 1 Then
  75.                         info.AppendLine("Byte at 0x" & Convert.ToString(length - 1, 16).ToUpper & " is same")
  76.                     Else
  77.                         info.AppendLine("Bytes from 0x" & Convert.ToString(lastAddress, 16).ToUpper & " to 0x" & Convert.ToString(length - 1, 16).ToUpper & " are same")
  78.                     End If
  79.                 End If
  80.                 comparetimer.Stop()
  81.                 Console.Clear()
  82.                 Console.WriteLine("Compare completed at 0x" & Convert.ToString(length, 16).ToUpper)
  83.                 Console.WriteLine("Saving Comparison.txt")
  84.                 System.IO.File.WriteAllText(Directory.GetCurrentDirectory() + "\Comparison.txt", info.ToString)
  85.         End Select
  86.     End Sub
  87.     Private Sub comparetimer_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles comparetimer.Elapsed
  88.         Console.Clear()
  89.         Console.WriteLine("Compared upto 0x" & Convert.ToString(i, 16).ToUpper)
  90.     End Sub
  91. End Module
Advertisement
Add Comment
Please, Sign In to add comment