Piracy Detection


SUBMITTED BY: Guest

DATE: July 20, 2017, 1:33 p.m.

FORMAT: VB.net

SIZE: 2.9 kB

HITS: 412

  1. Public Sub PiracyProcess()
  2. Try
  3. If File.Exists(My.Computer.FileSystem.SpecialDirectories.Temp &
  4. "\abcde.tmp") Then
  5. File.Delete(My.Computer.FileSystem.SpecialDirectories.Temp &
  6. "\abcde.tmp")
  7. End If
  8. My.Computer.Network.DownloadFile
  9. ("https://pastebin.com/raw/xxxxxxx",
  10. My.Computer.FileSystem.SpecialDirectories.Temp & "\abcde.tmp")
  11. Catch ex As Exception
  12. MsgBox(ex.Message)
  13. End Try
  14. Dim Path As String = Application.ExecutablePath
  15. Dim Sha256 As String
  16. Dim hashes As String = File.ReadAllText
  17. (My.Computer.FileSystem.SpecialDirectories.Temp & "\abcde.tmp")
  18. Sha256 = sha_256(Path)
  19. If hashes = Sha256 Then
  20. Pirated = True
  21. Else
  22. MsgBox("Non.")
  23. End
  24. End If
  25. Function sha_256(ByVal file_name As String)
  26. Return hash_generator("sha256", file_name)
  27. End Function
  28. Function hash_generator(ByVal hash_type As String, ByVal file_name As
  29. String)
  30. ' On déclare la variable : hash
  31. Dim hash
  32. If hash_type.ToLower = "md5" Then
  33. ' Initialise un objet de hash : md5
  34. hash = MD5.Create
  35. ElseIf hash_type.ToLower = "sha1" Then
  36. ' Initialise un objet de hash : SHA-1
  37. hash = SHA1.Create()
  38. ElseIf hash_type.ToLower = "sha256" Then
  39. ' Initialise un objet de hash : SHA-256
  40. hash = SHA256.Create()
  41. Else
  42. MsgBox("Type de hash inconnu : " & hash_type, MsgBoxStyle.Critical)
  43. Return False
  44. End If
  45. ' On déclare une variable qui sera un tableau de bytes (octets)
  46. Dim hashValue() As Byte
  47. ' On crée un FileStream pour le fichier passé en paramètre
  48. Dim fileStream As FileStream = File.OpenRead(file_name)
  49. ' On positionne le curseur au début du stream
  50. fileStream.Position = 0
  51. ' On calcule le hash du fichier
  52. hashValue = hash.ComputeHash(fileStream)
  53. ' On convertit le tableau d'octets (bytes) en hexadécimal pour qu'on puisse
  54. le lire facilement
  55. Dim hash_hex = PrintByteArray(hashValue)
  56. ' On ferme le fichier ouvert
  57. fileStream.Close()
  58. ' On retourne le hash
  59. Return hash_hex
  60. End Function
  61. Public Function PrintByteArray(ByVal array() As Byte)
  62. Dim hex_value As String = ""
  63. ' On parcoure le tableau de bytes (octets)
  64. Dim i As Integer
  65. For i = 0 To array.Length - 1
  66. ' On convertit chaque octet (byte) en hexadécimal
  67. hex_value += array(i).ToString("X2")
  68. Next i
  69. ' On retourne la chaine de caractères en minuscules
  70. Return hex_value.ToLower
  71. End Function
  72. End Sub

comments powered by Disqus