Public Sub PiracyProcess()
Try
If File.Exists(My.Computer.FileSystem.SpecialDirectories.Temp &
"\abcde.tmp") Then
File.Delete(My.Computer.FileSystem.SpecialDirectories.Temp &
"\abcde.tmp")
End If
My.Computer.Network.DownloadFile
("https://pastebin.com/raw/xxxxxxx",
My.Computer.FileSystem.SpecialDirectories.Temp & "\abcde.tmp")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim Path As String = Application.ExecutablePath
Dim Sha256 As String
Dim hashes As String = File.ReadAllText
(My.Computer.FileSystem.SpecialDirectories.Temp & "\abcde.tmp")
Sha256 = sha_256(Path)
If hashes = Sha256 Then
Pirated = True
Else
MsgBox("Non.")
End
End If
Function sha_256(ByVal file_name As String)
Return hash_generator("sha256", file_name)
End Function
Function hash_generator(ByVal hash_type As String, ByVal file_name As
String)
' On déclare la variable : hash
Dim hash
If hash_type.ToLower = "md5" Then
' Initialise un objet de hash : md5
hash = MD5.Create
ElseIf hash_type.ToLower = "sha1" Then
' Initialise un objet de hash : SHA-1
hash = SHA1.Create()
ElseIf hash_type.ToLower = "sha256" Then
' Initialise un objet de hash : SHA-256
hash = SHA256.Create()
Else
MsgBox("Type de hash inconnu : " & hash_type, MsgBoxStyle.Critical)
Return False
End If
' On déclare une variable qui sera un tableau de bytes (octets)
Dim hashValue() As Byte
' On crée un FileStream pour le fichier passé en paramètre
Dim fileStream As FileStream = File.OpenRead(file_name)
' On positionne le curseur au début du stream
fileStream.Position = 0
' On calcule le hash du fichier
hashValue = hash.ComputeHash(fileStream)
' On convertit le tableau d'octets (bytes) en hexadécimal pour qu'on puisse
le lire facilement
Dim hash_hex = PrintByteArray(hashValue)
' On ferme le fichier ouvert
fileStream.Close()
' On retourne le hash
Return hash_hex
End Function
Public Function PrintByteArray(ByVal array() As Byte)
Dim hex_value As String = ""
' On parcoure le tableau de bytes (octets)
Dim i As Integer
For i = 0 To array.Length - 1
' On convertit chaque octet (byte) en hexadécimal
hex_value += array(i).ToString("X2")
Next i
' On retourne la chaine de caractères en minuscules
Return hex_value.ToLower
End Function
End Sub