Last active
July 14, 2023 10:29
-
-
Save Ioan-Popovici/db8228de1d96def7a455fdbf1b59f165 to your computer and use it in GitHub Desktop.
Gets SQL product key from a binary string array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'.SYNOPSIS | |
' Gets SQL product key. | |
'.DESCRIPTION | |
' Gets SQL product key from a binary string array. | |
'.PARAMETER astrBinaryKey | |
' Specifies the obfuscated key. | |
'.PARAMETER intVersion | |
' Specifies the SQL version. | |
'.EXAMPLE | |
' Code.GetSQLProductKey(Fields!SomeField.Value, 12) (SSRS) | |
'.EXAMPLE | |
' GetSQLProductKey({1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0}, 12) (VB.Net) | |
'.NOTES | |
' Created by Ioan Popovici. | |
' Credit to Jakob Bindslet and Chrissy LeMaire. | |
' I only translated the script in Visual Basic, nothing else. | |
'.LINK | |
' http://mspowershell.blogspot.com/2010/11/sql-server-product-key.html (Jakob Bindslet) | |
' https://gallery.technet.microsoft.com/scriptcenter/Get-SQL-Server-Product-4b5bf4f8 (Chrissy LeMaire) | |
'.LINK | |
' https://MEM.Zone | |
'.LINK | |
' https://MEM.Zone/SW-SQL-Server-Products | |
'.LINK | |
' https://MEM.Zone/ISSUES | |
' | |
'/*##=============================================*/ | |
'/*## SCRIPT BODY */ | |
'/*##=============================================*/ | |
'/* #region FunctionBody */ | |
Function GetSQLProductKey(ByVal astrBinaryKey As String(), ByVal intVersion As Integer) As String | |
Dim achrKeyChars As Char() = {"B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9"} | |
Dim strSQLProductKey As String | |
Dim iastrBinaryKey As Long | |
Dim iachrKeyChars As Long | |
Dim iastrBinaryKeyOuterLoop As Long | |
Dim iastrBinaryKeyInnerLoop As Long | |
Try | |
If (intVersion >= 11) Then | |
iastrBinaryKey = 0 | |
Else | |
iastrBinaryKey = 52 | |
End If | |
For iastrBinaryKeyOuterLoop = 24 To 0 Step -1 | |
iachrKeyChars = 0 | |
For iastrBinaryKeyInnerLoop = 14 To 0 Step -1 | |
iachrKeyChars = iachrKeyChars * 256 Xor astrBinaryKey(iastrBinaryKeyInnerLoop + iastrBinaryKey) | |
astrBinaryKey(iastrBinaryKeyInnerLoop + iastrBinaryKey) = Math.Truncate(iachrKeyChars / 24) | |
iachrKeyChars = iachrKeyChars Mod 24 | |
Next iastrBinaryKeyInnerLoop | |
strSQLProductKey = achrKeyChars(iachrKeyChars) + strSQLProductKey | |
If (iastrBinaryKeyOuterLoop Mod 5) = 0 And iastrBinaryKeyOuterLoop <> 0 Then | |
strSQLProductKey = "-" + strSQLProductKey | |
End If | |
Next iastrBinaryKeyOuterLoop | |
Catch | |
strSQLProductKey = "Cannot decode product key." | |
End Try | |
GetSQLProductKey = strSQLProductKey | |
End Function | |
'/* #endregion */ | |
'/*##=============================================*/ | |
'/*## END SCRIPT BODY */ | |
'/*##=============================================*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment