Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Hasseds en 21 Junio 2011, 22:01 pm



Título: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 21 Junio 2011, 22:01 pm
Retorno = Seriales de Pen-Drives conectados

Código
  1.  
  2. Option Explicit
  3.  
  4. 'Function: FlashSerials
  5. 'Autor   : Sergio Desanti (Hasseds)
  6. 'Thank   : Seba , Cobein, A.Desanti
  7. 'Test    : XP (32 BIT) - W7/UAC (32 BIT)
  8. 'Return  : Serial(ESN) de Pen-Drives conectados
  9. '
  10. Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
  11. Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As GUID, ByVal Enumerator As Long, ByVal hwndParent As Long, ByVal flags As Long) As Long
  12. Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
  13. Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As Long
  14. Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long
  15.  
  16.  
  17. Private Type GUID
  18.    Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(7) As Byte
  19. End Type
  20.  
  21. Private Type SP_DEVICE_INTERFACE_DATA
  22.    cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
  23. End Type
  24.  
  25. Private Type SP_DEVINFO_DATA
  26.    cbSize As Long: ClassGuid As GUID: DevInst As Long: Reserved As Long
  27. End Type
  28.  
  29. Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
  30.    cbSize As Long: strDevicePath As String * 260
  31. End Type
  32.  
  33. Private Sub Form_Load()
  34.     AutoRedraw = True
  35.     Print FlashSerials
  36. End Sub
  37.  
  38. Public Function FlashSerials() As String
  39.  
  40.    Dim TGUID As GUID
  41.  
  42.    Call IIDFromString(StrPtr("{a5dcbf10-6530-11d2-901f-00c04fb951ed}"), TGUID)
  43.  
  44.    Dim hDev As Long
  45.    hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
  46.    If hDev = -1 Then Exit Function
  47.  
  48.    Dim lCount        As Long
  49.    Dim lSize         As Long
  50.    Dim DEV_DETAIL    As SP_DEVICE_INTERFACE_DETAIL_DATA
  51.    Dim DEV_INFO      As SP_DEVINFO_DATA
  52.    Dim DEV_DATA      As SP_DEVICE_INTERFACE_DATA
  53.  
  54.    DEV_DATA.cbSize = Len(DEV_DATA)
  55.  
  56.    While SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DEV_DATA) <> &H0
  57.      Call SetupDiGetDeviceInterfaceDetail(hDev, DEV_DATA, ByVal &H0, &H0, lSize, ByVal &H0)
  58.      DEV_DETAIL.cbSize = &H5
  59.      DEV_INFO.cbSize = Len(DEV_INFO)
  60.      Call SetupDiGetDeviceInterfaceDetail(hDev, DEV_DATA, DEV_DETAIL, ByVal lSize, &H0, DEV_INFO)
  61.      If UBound(Split(DEV_DETAIL.strDevicePath, "#")) > 1 Then
  62.        FlashSerials = FlashSerials & Split(UCase$(DEV_DETAIL.strDevicePath), "#")(2) & Chr$(&HD)
  63.      End If
  64.      lCount = lCount + 1
  65.    Wend
  66.  
  67.    Call SetupDiDestroyDeviceInfoList(hDev)
  68.  
  69. End Function
  70.  
  71.  






Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Elemental Code en 21 Junio 2011, 23:15 pm
CHAAAAAAAN.
Explicame que es el serial de un pendrive  :-[


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 21 Junio 2011, 23:34 pm
El numero de serie (Proporcionado por el frabricante) de un dispositivo, este deberiá ser unico y no cambiar al formatear, saludos


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 17 Septiembre 2011, 01:08 am
Agrego (por si el tema le interesó a alguien) un modulo para asociar la letra de unidad con su respectivo Serial (ESN) de Pen Drive.

Nota1: no pude probar como se comporta el código con Discos uSB externos ni con grabadoras USB, lo voy a hacer en cuanto tenga la oportunidad

Nota 2: es posible que no haya que llamar 2 veces a SetupDiGetDeviceInterfaceDetail, creo que RequiredSize As Long (lSize en el codigo) de esta api seria de &H7B para la clase "{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" pero solo pude probar en XP conectando de uno hasta seis PenDrive.

Saludos


MODULO:

Código
  1.  
  2. Option Explicit
  3.  
  4. 'Modulo: FlashSerial
  5. 'Autor: Sergio Desanti (Hasseds)
  6. 'Agradecimientos: Seba, Cobein, A.Desanti
  7. 'Test: XP (32 BIT) & W7 (32 BIT)
  8. 'Retorno:  Letra de unidad y Serial Number(ESN) de Pen Drive conectados
  9. '
  10. Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  11. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  12. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  13. Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
  14.  
  15. Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
  16.  
  17. Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As GUID, ByVal Enumerator As Long, ByVal hwndParent As Long, ByVal flags As Long) As Long
  18. Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
  19. Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As Long
  20. Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long
  21.  
  22. Private Type STORAGE_DEVICE_NUMBER
  23.    DeviceType As Long: DiskNumber As Long: PartNumber As Long
  24. End Type
  25.  
  26. Private Type GUID
  27.    Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(7) As Byte
  28. End Type
  29.  
  30. Private Type SP_DEVICE_INTERFACE_DATA
  31.    cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
  32. End Type
  33.  
  34. Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
  35.    cbSize As Long: strDevicePath As String * 260
  36. End Type
  37.  
  38. Public Function FlashSerial(ByVal sLetra As String) As String
  39.  
  40.  sLetra = Left$(UCase$(sLetra), 1) & ":"
  41.  
  42.  FlashSerial = sLetra & " NO USB"
  43.  
  44.  Dim RetDeviceIndex    As Long
  45.  RetDeviceIndex = DeviceIndex(sLetra)
  46.  If RetDeviceIndex < 0 Then Exit Function ' " -1 -2 -3 en DeviceIndex"
  47.  
  48.  Dim TGUID             As GUID
  49.  Call IIDFromString(StrPtr("{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"), TGUID)
  50.  
  51.  Dim hDev              As Long
  52.  hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
  53.  If hDev = -1 Then: Exit Function
  54.  
  55.  Dim lCount            As Long
  56.  Dim lSize             As Long
  57.  Dim DTA               As SP_DEVICE_INTERFACE_DATA
  58.  Dim DTL               As SP_DEVICE_INTERFACE_DETAIL_DATA
  59.  
  60.  DTA.cbSize = Len(DTA)
  61.  DTL.cbSize = &H5
  62.  
  63.  Do While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DTA) = &H0&)
  64.    Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, ByVal &H0&, &H0, lSize, ByVal &H0&)
  65.    Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, DTL, ByVal lSize, &H0&, ByVal &H0&)
  66.    If InStr(UCase$(DTL.strDevicePath), "USB") Then
  67.      If DeviceIndex(DTL.strDevicePath, True) = RetDeviceIndex Then
  68.        If UBound(Split(DTL.strDevicePath, "#")) > 1 Then
  69.          FlashSerial = sLetra & Split(UCase$(DTL.strDevicePath), "#")(2)
  70.          Exit Do
  71.        End If
  72.      End If
  73.    End If
  74.    lCount = lCount + 1
  75.  Loop
  76.  
  77.  Call SetupDiDestroyDeviceInfoList(hDev)
  78.  
  79. End Function
  80.  
  81. Public Function DeviceIndex(ByVal sLetra As String, Optional strDevicePath As Boolean) As Long
  82.  
  83.  Dim hdh As Long, br As Long, SDN As STORAGE_DEVICE_NUMBER
  84.  
  85.  If Not strDevicePath Then sLetra = "\\.\" & Left$(UCase$(sLetra), 1) & ":"
  86.  
  87.  hdh = CreateFile(sLetra, &H0&, &H3&, ByVal &H0&, &H3&, &H0&, &H0&) ': MsgBox hdh, , "hdh"
  88.  If Not (hdh = -1) Then
  89.      If DeviceIoControl(hdh, &H2D1080, &H0&, &H0&, SDN, Len(SDN), br, ByVal &H0&) Then
  90.          If SDN.DeviceType = 7 Then
  91.              DeviceIndex = SDN.DiskNumber  ' Retorno DeviceIndex
  92.          Else
  93.              DeviceIndex = -3   ' No es GUID 53f56307-b6bf-11d0-94f2-00a0c91efb8b
  94.          End If
  95.      Else
  96.          DeviceIndex = -2  ' Floppy o DeviceIoControl = 0 (GetLastError)
  97.      End If
  98.      Call CloseHandle(hdh)
  99.  Else
  100.      DeviceIndex = -1  ' Unidad sin dispositivo o CreateFile = -1 (GetLastError)
  101.  End If
  102.  
  103. End Function
  104.  
  105.  
  106.  



Código
  1.  
  2. Option Explicit
  3.  
  4. Private Sub Form_Load()
  5.  
  6.      MsgBox FlashSerial("f")
  7.  
  8. End Sub
  9.  
  10.  
  11.  









Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 6 Octubre 2011, 22:04 pm
Funciona en una cuenta de usuario, cuando usas WMI necesitas permisos  :D lo utilizaré, aún no entiendo que es eso de hook en el formulario. Pero averiguaré.

Saludos.


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 7 Octubre 2011, 02:57 am
Si , creo que tambien funciona con UAC activado (tal vez alguien que lo pueda probar en W7 nos informe de esto)

Un ejemplo de Hook de lo mas de lo mas simple, si te sirve... te toca optimizar y adaptar a lo tuyo.



MODULO

Código:

Option Explicit

'Function: FlashSerials
'Autor   : Sergio Desanti (Hasseds)
'Thank   : Seba , Cobein, A.Desanti
'Test    : XP (32 BIT) - W7 (32 BIT)
'Return  : Serial(ESN) de Pen-Drives conectados
'

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const GWL_WNDPROC = -4
Private Const WM_DEVICECHANGE As Long = 537              'Cambios en un dispositivo
Private Const DBT_DEVICEARRIVAL As Long = 32768          'Cuando se conecta uno nuevo
Private Const DBT_DEVICEREMOVECOMPLETE As Long = 32772   'Cuando se desconecta uno
Private Const DBT_DEVTYP_VOLUME As Integer = 2           'Logical volume, cualquier unidad de almacenamiento nueva.

Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As GUID, ByVal Enumerator As Long, ByVal hwndParent As Long, ByVal flags As Long) As Long
Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
Private Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As Long
Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long
 
Private Type GUID
   Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(7) As Byte
End Type
 
Private Type SP_DEVICE_INTERFACE_DATA
   cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
End Type

Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
   cbSize As Long: strDevicePath As String * 260
End Type

Dim hHook As Long

Public Sub StartHook(hWnd As Long)
    hHook = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub StopHook(hWnd As Long)
    SetWindowLong hWnd, GWL_WNDPROC, hHook
    hHook = 0
End Sub

Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    WindowProc = CallWindowProc(hHook, hWnd, uMsg, wParam, lParam)
    If uMsg = WM_DEVICECHANGE Then
      If wParam = DBT_DEVICEARRIVAL Then
        Form1.Cls
        Form1.Print "Conectaron", Time
        Form1.Print
        Form1.Print FlashSerials
      ElseIf wParam = DBT_DEVICEREMOVECOMPLETE Then
        Form1.Cls
        Form1.Print "Desconectaron", Time
        Form1.Print
        Form1.Print FlashSerials
      End If
    End If
End Function
 
Public Function FlashSerials() As String
 
   Dim TGUID As GUID
 
   Call IIDFromString(StrPtr("{a5dcbf10-6530-11d2-901f-00c04fb951ed}"), TGUID)
 
   Dim hDev As Long
   hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
   If hDev = -1 Then Exit Function
 
   Dim lCount       As Long
   Dim lSize        As Long
   Dim DTL          As SP_DEVICE_INTERFACE_DETAIL_DATA
   Dim DTA          As SP_DEVICE_INTERFACE_DATA
 
   DTA.cbSize = Len(DTA)
   DTL.cbSize = &H5
 
   While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DTA) = &H0)
     Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, ByVal &H0, &H0, lSize, ByVal &H0)
     Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, DTL, ByVal lSize, &H0, ByVal &H0)
     If UBound(Split(DTL.strDevicePath, "#")) > 1 Then
       FlashSerials = FlashSerials & Split(UCase$(DTL.strDevicePath), "#")(2) & Chr$(&HD)
     End If
     lCount = lCount + 1
   Wend
 
   Call SetupDiDestroyDeviceInfoList(hDev)
  
   If FlashSerials = "" Then FlashSerials = "No hay conexiones"
  
End Function




FORM

Código:

Option Explicit

Private Sub Form_Load()
 AutoRedraw = True
 Print FlashSerials
 Call SetWindowPos(Form1.hWnd, &HFFFF, &H0, &H0, &H0, &H0, &H3) 'form on top
 Call StartHook(hWnd)
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Call StopHook(hWnd)
End Sub





http://www.virustotal.com/file-scan/report.html?id=4e03da8a806215953259ea3291bc79d7cab8226fdabb14765efdd81b4b94eae1-1317934469






Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: BlackZeroX en 7 Octubre 2011, 03:30 am
.
No recuerdo bien pero ya habia visto un codigo asi hace tiempo... igual no recuerdo donde... jaja a mi biblioteca.

Dulces Lunas!Ą.


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 7 Octubre 2011, 03:40 am
Entendi que hook es detectar las acciones que el usuario realiza mientras el programa esta activo, en este caso el USB conectado o no.

Me sirve, claro que si, como decimos en mi barrio: Gracielas  ;D



Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 7 Octubre 2011, 03:43 am
mmm... me parece q me fuí al carajo  >:D




Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: .:UND3R:. en 7 Octubre 2011, 05:52 am
es una excelente herramienta para evitar el cracking de alguna forma, vender un software con dongle en donde el programa pide un serial y un pendrive conectado este serial es algún algoritmo del serial del pendrive por lo que si se coloca el serial este al pasar por algunos cálculos debería ser el mismo serial que el del pendrive, si no retorna serial incorrecto o llave USB incorrecta


aclaro que es una idea de la funcionalidad que se le puede dar, no necesariamente es para eso,Saludos

PD: un programa que permita una serie de pendrive determinados conectarce al PC

sistema de seguirdad para aislar troyanos.

etc

Saludos

Saludos


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 7 Octubre 2011, 21:36 pm
mmm... me parece q me fuí al carajo  >:D




?  :xD


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 7 Octubre 2011, 21:49 pm
Nada, leí mal y me equivoqué en una respuesta, pero ya está editado. xD





Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 8 Noviembre 2011, 17:58 pm
Intente pasar tu code a VB2005 yo utilizo el Sharpdevelop
Estoy averiguando como utilizar la API
SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)

me da problemas con AddressOf WindowProc si tienes alguna recomendación, algún link que puedas compartir te lo agradeceria. Seguiré averiguando.

Saludos




Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 8 Noviembre 2011, 19:05 pm
En VB.Net no tengo ni idea de como capturar los mensajes del Form, pero mirá este link, aparentemente es un hook al mouse... tal vez te sirva de ejemplo para AddressOf .

http://support.microsoft.com/kb/319524  (http://support.microsoft.com/kb/319524)








Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 9 Noviembre 2011, 04:11 am
Funciona muy bien, gracias por el dato, seria muy bueno pasar tu code de los seriales a VB2005. Yo uso el http://www.icsharpcode.net/OpenSource/SD/ para no pagar licencia.

Gracias.


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 4 Diciembre 2011, 20:09 pm
Hola tengo una consulta la clase: "{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" me detecta hasta las unidades de disco IDE, si alguien tuviera discos SATA para ver si los detecta
Código
  1. Public Function FlashSerials() As String
  2.    Dim cad As String
  3.   Dim TGUID As GUID
  4.  
  5.   Call IIDFromString(StrPtr("{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"), TGUID)
  6.  
  7.   Dim hDev As Long
  8.   ' puntero a la clase de los USB
  9.   hDev = SetupDiGetClassDevs(TGUID, &H0, &H0, &H12)
  10.  
  11.   If hDev = -1 Then Exit Function
  12.  
  13.   Dim lCount       As Long
  14.   Dim lSize        As Long
  15.   Dim DTL          As SP_DEVICE_INTERFACE_DETAIL_DATA
  16.   Dim DTA          As SP_DEVICE_INTERFACE_DATA
  17.  
  18.   DTA.cbSize = Len(DTA)
  19.   DTL.cbSize = &H5
  20.   lCount = &H0
  21.  
  22.   While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, lCount, DTA) = &H0)
  23.  
  24.     Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, ByVal &H0, &H0, lSize, ByVal &H0)
  25.  
  26.     Call SetupDiGetDeviceInterfaceDetail(hDev, DTA, DTL, ByVal lSize, lSize, ByVal &H0)
  27.  
  28.     If UBound(Split(DTL.strDevicePath, "#")) > 1 Then
  29.        cad = cad & Split(UCase$(DTL.strDevicePath), "#")(1) & _
  30.         " - " & Split(UCase$(DTL.strDevicePath), "#")(2) & Chr$(&HD)
  31.        'cad = cad & DTL.strDevicePath & Chr(10)
  32.     End If
  33.  
  34.     lCount = lCount + 1
  35.   Wend
  36.  
  37.   Call SetupDiDestroyDeviceInfoList(hDev)
  38.   FlashSerials = cad
  39.   If FlashSerials = "" Then FlashSerials = "No hay conexiones"
  40.  
  41. End Function
  42.  


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 4 Diciembre 2011, 22:24 pm
Hola Maurice_Lupin , la clase 53f56307-b6bf-11d0-94f2-00a0c91efb8b si detecta los discos Sata 1 y sata 2, todavia no pude probar con Sata 3 pero seguramente tambien los detecta ya que es la misma interface.

Esta clase tambien detecta (o enumera mejor dicho) Discos IDE, ZIP de interface IDE y Dispositivos de almacenamiento USB... por lo tanto deberás filtrar los retornos de acuerdo a lo que quieras listar, por ejemplo en el codigo original solo listé la interface USB

 If InStr(UCase$(DTL.strDevicePath), "USB") Then      

http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1664147#msg1664147 (http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1664147#msg1664147)



Nota: Las interfaces "IDE" & Sata no retornan el Serial verdadero por esta vía... A Diferencia de la interface USB que sí se puede obtener con este método


La clase a5dcbf10-6530-11d2-901f-00c04fb951ed solo enumera Dispositivos de almacenamiento USB, por lo tanto no hay que "filtrar retornos"
http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1629437#msg1629437 (http://foro.elhacker.net/programacion_visual_basic/seriales_de_pendrives_conectados_src-t331333.0.html;msg1629437#msg1629437)










Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 5 Diciembre 2011, 06:51 am
Gracias Hasseds, usando WMI me devuelve casi el mismo serial de IDE que utilizando la clase 53f56307-b6bf-11d0-94f2-00a0c91efb8b , estas seguro que no es el serial verdadero?  :-[

Saludos.



Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: BlackZeroX en 5 Diciembre 2011, 09:12 am
.
Aclarando un punto crucial es que NO SE LE CONOCE COMO CLASES son GUID esos identificadores...

Dulces Lunas!Ą.


Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Hasseds en 5 Diciembre 2011, 18:52 pm
Sí, en adelante será mejor referirse a estas clases de dispositivos como GUID.





estas seguro que no es el serial verdadero?  :-[


Segurísimo !!!


Seriales de Hard Disk conectados (Solo funciona como usuario Administrador ):


Código
  1.  
  2. Option Explicit
  3.  
  4. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  5. ' Function: SerialHD
  6. ' Autor: Adrian Desanti (Dessa)
  7. ' Creditos: es una adaptacion a mis necesidades de una clase de Antonio Giuliana
  8. ' Agradecimientos: Karcrak (IsAdministrador)
  9. ' Requisitos : Windows NT + Administrador
  10. ' Rertorno: retorna el serial verdadero de Discos IDE o S-ATA conectados
  11. ' Serial verdadero: Es el que figura en la etiqueta del Disco y no cambia al formatear
  12. ' Fecha : V.2 Septiembre 2010
  13. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  14.  
  15. Private Declare Function CheckTokenMembership Lib "ADVAPI32" (ByVal TokenHandle As Long, ByVal pSidToCheck As Long, ByRef IsMember As Boolean) As Long
  16.  
  17. Private Declare Function GetVersion Lib "KERNEL32" () As Long
  18. Private Declare Function CreateFile Lib "KERNEL32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  19. Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
  20. Private Declare Function DeviceIoControl Lib "KERNEL32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
  21. Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)
  22.  
  23. Private Type IDEREGS
  24.    bFeaturesReg As Byte: bSectorCountReg As Byte: bSectorNumberReg As Byte: bCylLowReg As Byte: bCylHighReg As Byte: bDriveHeadReg As Byte: bCommandReg As Byte: bReserved As Byte
  25. End Type
  26. Private Type SENDCMDINPARAMS
  27.    cBufferSize As Long: irDriveRegs As IDEREGS: bDriveNumber As Byte: bReserved(1 To 3) As Byte: dwReserved(1 To 4) As Long
  28. End Type
  29. Private Type DRIVERSTATUS
  30.    bDriveError As Byte: bIDEStatus As Byte: bReserved(1 To 2) As Byte: dwReserved(1 To 2) As Long
  31. End Type
  32. Private Type SENDCMDOUTPARAMS
  33.    cBufferSize As Long: DStatus As DRIVERSTATUS: bBuffer(1 To 512) As Byte
  34. End Type
  35.  
  36. Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As GUID) As Long
  37. Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByVal ClassGuid As Long, ByVal Enumerator As Long, ByVal HwndParent As Long, ByVal flags As Long) As Long
  38. Private Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Long
  39. Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long
  40.  
  41. Private Type GUID
  42.    Data1 As Long: Data2 As Integer: Data3 As Integer: Data4(0 To 7) As Byte
  43. End Type
  44.  
  45. Private Type SP_DEVICE_INTERFACE_DATA
  46.    cbSize As Long: InterfaceClassGuid As GUID: flags As Long: Reserved As Long
  47. End Type
  48.  
  49.  
  50. Private Sub Form_Load()
  51.  
  52.  If (GetVersion And &HFF) > &H5 Then
  53.    If App.LogMode = 0 Then
  54.        MsgBox "En Vista o Seven ejecutar compilado en modo Administrador"
  55.        End
  56.    End If
  57.  End If
  58.  
  59.  
  60.  AutoRedraw = True
  61.  FontBold = True
  62.  Caption = ""
  63.  Print SerialHD()
  64.  
  65.  
  66.  
  67. End Sub
  68.  
  69. Public Function SerialHD() As String
  70.  
  71.  If (GetVersion And &HFF) < 5 Then
  72.    SerialHD = "Sistema Operativo No válido"
  73.    Exit Function
  74.  End If
  75.  
  76.  If IsAdministrador = False Then
  77.    SerialHD = "Se requiere usuario Administrador"
  78.    Exit Function
  79.  End If
  80.  
  81.  Dim RetDiskCount  As Long
  82.  
  83.  RetDiskCount = DiskCount()
  84.  
  85.  If RetDiskCount < 0 Then
  86.    SerialHD = "DiskCount No válido"
  87.    Exit Function
  88.  End If
  89.  
  90.  Dim nDisco        As Long
  91.  Dim hdh           As Long
  92.  Dim hddfr         As Byte
  93.  Dim hddln         As Byte
  94.  Dim bin           As SENDCMDINPARAMS
  95.  Dim bout          As SENDCMDOUTPARAMS
  96.  Dim br            As Long
  97.  Dim x             As Byte
  98.  Dim s             As String
  99.  
  100.  For nDisco = 0 To RetDiskCount - 1 ' los ciclos del For serán solo la cantidad de "PhysicalDrive" conectados
  101.  
  102.      hdh = CreateFile("\\.\PhysicalDrive" & nDisco, &H3, &H0, &H0, &H3, &H0, &H0)
  103.  
  104.      If hdh = -1 Then
  105.          If nDisco = 0 Then
  106.              SerialHD = " IDE " & nDisco & " = " & "Error en CreateFile" & vbNewLine
  107.          Else
  108.              SerialHD = SerialHD & " IDE " & nDisco & " = " & "Error en CreateFile" & vbNewLine
  109.          End If
  110.      Else
  111.          hddfr = 21 ' Posicion en el buffer del SerialNumber
  112.          hddln = 20 ' Tamańo resrvado en el buffer para el SerialNumber
  113.  
  114.          Call ZeroMemory(bin, Len(bin))
  115.          Call ZeroMemory(bout, Len(bout))
  116.  
  117.          With bin
  118.              .bDriveNumber = nDisco
  119.              .cBufferSize = 512
  120.            With .irDriveRegs
  121.                If (nDisco And 1) Then
  122.                    .bDriveHeadReg = &HB0
  123.                Else
  124.                    .bDriveHeadReg = &HA0
  125.                End If
  126.                .bCommandReg = &HEC
  127.                .bSectorCountReg = 1
  128.                .bSectorNumberReg = 1
  129.            End With
  130.          End With
  131.  
  132.          'DFP_RECEIVE_DRIVE_DATA = &H7C088
  133.          Call DeviceIoControl(hdh, &H7C088, bin, Len(bin), bout, Len(bout), br, 0)
  134.  
  135.          s = ""
  136.          For x = hddfr To hddfr + hddln - 1 Step 2
  137.              If bout.bBuffer(x + 1) = 0 Then Exit For
  138.              s = s & Chr(bout.bBuffer(x + 1))
  139.              If bout.bBuffer(x) = 0 Then Exit For
  140.              s = s & Chr(bout.bBuffer(x))
  141.          Next x
  142.          Call CloseHandle(hdh)
  143.  
  144.          If Trim$(s) <> "" Then
  145.              SerialHD = SerialHD & " IDE " & nDisco & " = " & Trim$(s) & vbNewLine
  146.          End If
  147.      End If
  148.  
  149.  Next nDisco
  150.  
  151. End Function
  152.  
  153. Private Function DiskCount() As Long
  154.  
  155.    Dim TGUID   As GUID
  156.    Dim hDev    As Long
  157.  
  158.    Call IIDFromString(StrPtr("{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"), TGUID)
  159.  
  160.    '&H12 ===> DIGCF_PRESENT = &H10 Or DIGCF_DEVICEINTERFACE = &H2
  161.    hDev = SetupDiGetClassDevs(VarPtr(TGUID), &H0, &H0, &H12)
  162.  
  163.    If hDev = -1 Then
  164.      DiskCount = -1
  165.      Exit Function
  166.    End If
  167.  
  168.    Dim Cnt As Long
  169.    Dim DTA  As SP_DEVICE_INTERFACE_DATA
  170.    DTA.cbSize = Len(DTA)
  171.  
  172.    While Not (SetupDiEnumDeviceInterfaces(hDev, &H0, TGUID, Cnt, DTA) = &H0)
  173.        Cnt = Cnt + 1
  174.    Wend
  175.  
  176.    Call SetupDiDestroyDeviceInfoList(hDev)
  177.  
  178.    DiskCount = Cnt
  179.  
  180. End Function
  181.  
  182. Private Function IsAdministrador() As Boolean
  183.   Dim SID(1)  As Currency
  184.   SID(0) = 36028797018964.0193@
  185.   SID(1) = 233646220.9056@
  186.   Call CheckTokenMembership(&H0, VarPtr(SID(0)), IsAdministrador)
  187. End Function
  188.  
  189.  
  190.  





Título: Re: Seriales de Pen-Drives conectados (SRC)
Publicado por: Maurice_Lupin en 6 Diciembre 2011, 05:41 am
 :( pensé que eran verdaderos, gracias, habrá que ejecutar como administrador  :xD

Saludos.