[reglé]Du VB vers PB.... besoin d'aide.

Sujets variés concernant le développement en PureBasic
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

[reglé]Du VB vers PB.... besoin d'aide.

Message par Ar-S »

Salut,

j'en appelle aux connaisseurs en VB car j'aimerai convertir ce code en PB afin de pouvoir afficher la clé d'XP en fonction du ProductID affiché dans la base de registre. Je n'y connais rien en VB. (hein KCC :D)

P.S : Je sais que des softs le font, moi j'aimerai savoir ce que donnerai ce prog en PB.

Voilà le code :

Code : Tout sélectionner

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that If you declare the lpData parameter as String, you must pass it By Value.
    Private Const REG_BINARY = 3
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const ERROR_SUCCESS = 0&
   
Public xpcdkeyview As String
Public Function sGetXPCDKey() As String
    'Read the value of:
    'HKLM\SOFTWARE\MICROSOFT\Windows NT\Curr
    '   entVersion\DigitalProductId
    Dim bDigitalProductID() As Byte
    Dim bProductKey() As Byte
    Dim ilByte As Long
    Dim lDataLen As Long
    Dim hKey As Long
    'Open the registry key: HKLM\SOFTWARE\MI
    '   CROSOFT\Windows NT\CurrentVersion


    If RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\MICROSOFT\Windows NT\CurrentVersion", hKey) = ERROR_SUCCESS Then
        lDataLen = 164
        ReDim Preserve bDigitalProductID(lDataLen)
        'Read the value of DigitalProductID


        If RegQueryValueEx(hKey, "DigitalProductId", 0&, REG_BINARY, bDigitalProductID(0), lDataLen) = ERROR_SUCCESS Then
            'Get the Product Key, 15 bytes long, off
            '   set by 52 bytes
            ReDim Preserve bProductKey(14)


            For ilByte = 52 To 66
                bProductKey(ilByte - 52) = bDigitalProductID(ilByte)
            Next ilByte
        Else
            'ERROR: Could not read "DigitalProductID
            '   "
            sGetXPCDKey = ""
            Exit Function
        End If
    Else
        'ERROR: Could not open "HKLM\SOFTWARE\MI
        '   CROSOFT\Windows NT\CurrentVersion"
        sGetXPCDKey = ""
        Exit Function
    End If
    'Now we are going to 'base24' decode the
    '   Product Key
    Dim bKeyChars(0 To 24) As Byte
    'Possible characters in the CD Key:
    bKeyChars(0) = Asc("B")
    bKeyChars(1) = Asc("C")
    bKeyChars(2) = Asc("D")
    bKeyChars(3) = Asc("F")
    bKeyChars(4) = Asc("G")
    bKeyChars(5) = Asc("H")
    bKeyChars(6) = Asc("J")
    bKeyChars(7) = Asc("K")
    bKeyChars(8) = Asc("M")
    bKeyChars(9) = Asc("P")
    bKeyChars(10) = Asc("Q")
    bKeyChars(11) = Asc("R")
    bKeyChars(12) = Asc("T")
    bKeyChars(13) = Asc("V")
    bKeyChars(14) = Asc("W")
    bKeyChars(15) = Asc("X")
    bKeyChars(16) = Asc("Y")
    bKeyChars(17) = Asc("2")
    bKeyChars(18) = Asc("3")
    bKeyChars(19) = Asc("4")
    bKeyChars(20) = Asc("6")
    bKeyChars(21) = Asc("7")
    bKeyChars(22) = Asc("8")
    bKeyChars(23) = Asc("9")
    Dim nCur As Integer
    Dim sCDKey As String
    Dim ilKeyByte As Long
    Dim ilBit As Long


    For ilByte = 24 To 0 Step -1
        'Step through each character in the CD k
        '   ey
        nCur = 0


        For ilKeyByte = 14 To 0 Step -1
            'Step through each byte in the Product K
            '   ey
            nCur = nCur * 256 Xor bProductKey(ilKeyByte)
            bProductKey(ilKeyByte) = Int(nCur / 24)
            nCur = nCur Mod 24
        Next ilKeyByte
        sCDKey = Chr(bKeyChars(nCur)) & sCDKey
        If ilByte Mod 5 = 0 And ilByte <> 0 Then sCDKey = "-" & sCDKey
    Next ilByte
    sGetXPCDKey = sCDKey
     xpcdkeyview = sGetXPCDKey
End Function
Vous pouvez voir que le product ID est ici :

Code : Tout sélectionner

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Ayant la valeur ProductID

En fait c'est surtout cette partie dont j'ai besoin (enfin je crois)



D'avance merci

Code : Tout sélectionner

'Now we are going to 'base24' decode the
    '   Product Key
    Dim bKeyChars(0 To 24) As Byte
    'Possible characters in the CD Key:
    bKeyChars(0) = Asc("B")
    bKeyChars(1) = Asc("C")
    bKeyChars(2) = Asc("D")
    bKeyChars(3) = Asc("F")
    bKeyChars(4) = Asc("G")
    bKeyChars(5) = Asc("H")
    bKeyChars(6) = Asc("J")
    bKeyChars(7) = Asc("K")
    bKeyChars(8) = Asc("M")
    bKeyChars(9) = Asc("P")
    bKeyChars(10) = Asc("Q")
    bKeyChars(11) = Asc("R")
    bKeyChars(12) = Asc("T")
    bKeyChars(13) = Asc("V")
    bKeyChars(14) = Asc("W")
    bKeyChars(15) = Asc("X")
    bKeyChars(16) = Asc("Y")
    bKeyChars(17) = Asc("2")
    bKeyChars(18) = Asc("3")
    bKeyChars(19) = Asc("4")
    bKeyChars(20) = Asc("6")
    bKeyChars(21) = Asc("7")
    bKeyChars(22) = Asc("8")
    bKeyChars(23) = Asc("9")
    Dim nCur As Integer
    Dim sCDKey As String
    Dim ilKeyByte As Long
    Dim ilBit As Long


    For ilByte = 24 To 0 Step -1
        'Step through each character in the CD k
        '   ey
        nCur = 0


        For ilKeyByte = 14 To 0 Step -1
            'Step through each byte in the Product K
            '   ey
            nCur = nCur * 256 Xor bProductKey(ilKeyByte)
            bProductKey(ilKeyByte) = Int(nCur / 24)
            nCur = nCur Mod 24
        Next ilKeyByte
        sCDKey = Chr(bKeyChars(nCur)) & sCDKey
        If ilByte Mod 5 = 0 And ilByte <> 0 Then sCDKey = "-" & sCDKey
    Next ilByte
    sGetXPCDKey = sCDKey
     xpcdkeyview = sGetXPCDKey
End Function 
Dernière modification par Ar-S le mar. 20/mai/2008 20:11, modifié 1 fois.
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

voila :D

ce prg récupère le serial et le copy dans un fichier txt (key.txt)
juste a coté de lui
moralité , tu met ce prg dans une clef usb , tu vas en grande surface
tu met ta clef dans un ordi, tu lance ton prg (en auto a l'insertion)
et hop te voila avec un serial neuf et valable :lol:



;**************************************

Declare.s sGetXPCDKey()

Txt.s=sGetXPCDKey() ; recupere le cd key
MessageRequester ( "voila" , "le serial est :" +Txt.s, #PB_MessageRequester_Ok )


; sauvegarde sur un fichier txt
If Txt.s<> ""
     OpenFile (1, "key.txt" )
     WriteString (1,Txt.s)
     CloseFile (1)
Else
     MessageRequester ( "Erreur" , "aucun serial" , #PB_MessageRequester_Ok )
EndIf

End

Procedure.s sGetXPCDKey()
    
     ;Read the value of:
     ;HKLM\SOFTWARE\MICROSOFT\Windows NT\Curr
     ; entVersion\DigitalProductId
    *bDigitalProductID = AllocateMemory (164)
    *bProductKey.b = AllocateMemory (15)
    ilByte.l
    lDataLen.l
    hKey.l
     ;Open the registry key: HKLM\SOFTWARE\MI
     ; CROSOFT\Windows NT\CurrentVersion
     If RegOpenKey_ ( #HKEY_LOCAL_MACHINE , "SOFTWARE\MICROSOFT\Windows NT\CurrentVersion" , @hKey) = #ERROR_SUCCESS
        lDataLen = 164
         ;ReDim Preserve bDigitalProductID(lDataLen)
         ;Read the value of DigitalProductID
        
         If RegQueryValueEx_ (hKey, "DigitalProductId" , 0, "REG_BINARY" , *bDigitalProductID, @lDataLen) = #ERROR_SUCCESS
             ;Get the Product Key, 15 bytes long, off
             ; set by 52 bytes
            
             For ilByte = 52 To 66
                Byte.l = PeekB (*bDigitalProductID + ilByte) & 255
                 PokeB (*bProductKey + ilByte - 52, Byte)
             Next ilByte
             RegCloseKey_ (hKey)
         Else
             ;ERROR: Could not Read "DigitalProductID
             RegCloseKey_ (hKey)
             ProcedureReturn ""
         EndIf
     Else
         ;ERROR: Could not open "HKLM\SOFTWARE\MI
         ; CROSOFT\Windows NT\CurrentVersion"
         ProcedureReturn ""
     EndIf
     ;Now we are going To 'base24' decode the
     ; Product Key
     Dim bKeyChars.l(23)
     ;Possible characters in the CD Key:
    bKeyChars(0) = Asc ( "B" )
    bKeyChars(1) = Asc ( "C" )
    bKeyChars(2) = Asc ( "D" )
    bKeyChars(3) = Asc ( "F" )
    bKeyChars(4) = Asc ( "G" )
    bKeyChars(5) = Asc ( "H" )
    bKeyChars(6) = Asc ( "J" )
    bKeyChars(7) = Asc ( "K" )
    bKeyChars(8 ) = Asc ( "M" )
    bKeyChars(9) = Asc ( "P" )
    bKeyChars(10) = Asc ( "Q" )
    bKeyChars(11) = Asc ( "R" )
    bKeyChars(12) = Asc ( "T" )
    bKeyChars(13) = Asc ( "V" )
    
    bKeyChars(14) = Asc ( "W" )
    bKeyChars(15) = Asc ( "X" )
    bKeyChars(16) = Asc ( "Y" )
    bKeyChars(17) = Asc ( "2" )
    bKeyChars(18 ) = Asc ( "3" )
    bKeyChars(19) = Asc ( "4" )
    bKeyChars(20) = Asc ( "6" )
    bKeyChars(21) = Asc ( "7" )
    bKeyChars(22) = Asc ( "8" )
    bKeyChars(23) = Asc ( "9" )
    nCur.l
    sCDKey.s
    ilKeyByte.l
    ilByte.l
    Byte.l
     For ilByte = 24 To 0 Step -1
         ;Step through each character in the CD k
         ; ey
        nCur = 0
         For ilKeyByte = 14 To 0 Step -1
             ;Step through each byte in the Product K
             ; ey
            Byte = PeekB (*bProductKey + ilKeyByte) & 255
            nCur = ((nCur & 255) * 256) ! Byte
             PokeB (*bProductKey + ilKeyByte, ( Int (nCur / 24)))
            nCur = nCur % 24
         Next ilKeyByte
        sCDKey = Chr (bKeyChars(nCur)) + sCDKey
         If ilByte % 5 = 0 And ilByte <> 0
            sCDKey = "-" + sCDKey
         EndIf
     Next ilByte
     ProcedureReturn sCDKey
    
EndProcedure
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Message par Ar-S »

Tout simplement GRANDIOSE mon bon Dobro !
Merci beaucoup.

Le code PB est tout de même plus claire. :P :P :P
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

Ar-S a écrit :Tout simplement GRANDIOSE mon bon Dobro !
Merci beaucoup.

Le code PB est tout de même plus claire. :P :P :P
le code n'est pas de moi :D sauf la partie ecriture du code sur disque :lol:
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Ar-S a écrit :Tout simplement GRANDIOSE mon bon Dobro !
Merci beaucoup.

Le code PB est tout de même plus claire. :P :P :P
et il est encore plus clair comme çà, du moins plus court :wink:

Code : Tout sélectionner

Procedure.s GetXPCDKey() ; Ascii / Unicode compatible
  
  Protected Dim DigitalProductId.b(164)
  Protected hKey.l, i.l, j.l, n.l, result.s, nByte.l = 164
  
  If RegOpenKey_(#HKEY_LOCAL_MACHINE, "SOFTWARE\MICROSOFT\Windows NT\CurrentVersion", @hKey) = #ERROR_SUCCESS
    If RegQueryValueEx_(hKey, "DigitalProductId", 0, "REG_BINARY", @DigitalProductId(), @nByte) = #ERROR_SUCCESS
      For i = 24 To 0 Step -1
        n = 0
        For j = 14 To 0 Step -1
          n = ( n << 8 ) ! ( DigitalProductId(52 + j) & 255 )
          DigitalProductId(52 + j) = n / 24
          n % 24
        Next
        result = Mid("BCDFGHJKMPQRTVWXY2346789", n + 1, 1) + result
        If i And Not i % 5
          result = "-" + result
        EndIf
      Next
    EndIf
    RegCloseKey_(hKey)
  EndIf
  
  ProcedureReturn result
  
EndProcedure

MessageRequester("GetXPCDKey()", GetXPCDKey())

End
Dernière modification par Flype le mar. 20/mai/2008 22:46, modifié 2 fois.
Image
Backup
Messages : 14526
Inscription : lun. 26/avr./2004 0:40

Message par Backup »

pfff ! Frimeur :lol:
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

N'empêche, mine de rien il y a pas mal d'optimisations dans ce code.

Frimeur ?
Je préfère Psychorigide comme beaucoup de programmeurs :lol:
Image
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Message par Ar-S »

Very bien joué Flype :D
Répondre