elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  IsVirtualPCPresent (no WMI) [Source]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: IsVirtualPCPresent (no WMI) [Source]  (Leído 5,897 veces)
cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
IsVirtualPCPresent (no WMI) [Source]
« en: 3 Julio 2008, 01:57 am »

Bueno aca va mi humilde aporte, es una implemetacion del codigo de MadAntrax sin utilizar WMI, le agregue una funcion mas para detectar Sun VirtualBox.

Codigo original: http://foro.elhacker.net/programacion_vb/source_isvirtualpcpresent_sistema_antivirtualpc-t218845.0.html

Código
  1. '---------------------------------------------------------------------------------------
  2. ' Module      : mVM_Detect
  3. ' DateTime    : 02/07/2008 20:46
  4. ' Author      : Cobein
  5. ' Mail        : cobein27@hotmail.com
  6. ' WebPage     : http://cobein27.googlepages.com/vb6
  7. ' Purpose     : Detect Virtual Machines
  8. ' Usage       : At your own risk
  9. ' Requirements: None
  10. ' Distribution: You can freely use this code in your own
  11. '               applications, but you may not reproduce
  12. '               or publish this code on any web site,
  13. '               online service, or distribute as source
  14. '               on any media without express permission.
  15. '
  16. ' Reference   : http://foro.elhacker.net/programacion_vb/source_isvirtualpcpresent_sistema_antivirtualpc-t218845.0.html
  17. '
  18. ' Credits     : This code is completely based on MadAntrax submission, I just implemented
  19. '               a non WMI version.
  20. '
  21. ' History     : 02/07/2008 First Cut....................................................
  22. '---------------------------------------------------------------------------------------
  23. Option Explicit
  24.  
  25. Private Const INVALID_HANDLE_VALUE  As Long = (-1)
  26. Private Const OPEN_EXISTING         As Long = 3
  27. Private Const FILE_SHARE_READ       As Long = &H1
  28. Private Const FILE_SHARE_WRITE      As Long = &H2
  29.  
  30. Private Const DIGCF_PRESENT         As Long = &H2
  31. Private Const DIGCF_DEVICEINTERFACE As Long = &H10
  32.  
  33. Private Type STORAGE_DEVICE_NUMBER
  34.    dwDeviceType                    As Long
  35.    dwDeviceNumber                  As Long
  36.    dwPartitionNumber               As Long
  37. End Type
  38.  
  39. Private Type GUID
  40.    Data1                           As Long
  41.    Data2                           As Integer
  42.    Data3                           As Integer
  43.    Data4(0 To 7)                   As Byte
  44. End Type
  45.  
  46. Private Type SP_DEVICE_INTERFACE_DATA
  47.    cbSize                          As Long
  48.    InterfaceClassGuid              As GUID
  49.    flags                           As Long
  50.    Reserved                        As Long
  51. End Type
  52.  
  53. Private Type SP_DEVINFO_DATA
  54.    cbSize                          As Long
  55.    ClassGuid                       As GUID
  56.    DevInst                         As Long
  57.    Reserved                        As Long
  58. End Type
  59.  
  60. Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
  61.    cbSize                          As Long
  62.    strDevicePath                   As String * 260
  63. End Type
  64.  
  65. 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
  66. 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, lpOverlapped As Any) As Long
  67. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  68. 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
  69. 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
  70. 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
  71. Private Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long
  72. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
  73. Private Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpTargetPath As String, ByVal ucchMax As Long) As Long
  74. Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
  75. Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
  76.  
  77. Public Function IsVirtualPCPresent() As Boolean
  78.    Dim lBitMask    As Long
  79.    Dim i           As Long
  80.    Dim sData       As String
  81.  
  82.    lBitMask = GetLogicalDrives
  83.  
  84.    For i = 0 To 25
  85.        If (lBitMask Or 2 ^ i) = lBitMask Then
  86.            sData = sData & UCase(GetPNPDeviceID(Chr$(65 + i)))
  87.        End If
  88.    Next
  89.  
  90.    Select Case True
  91.        Case sData Like "*VIRTUAL*"
  92.            IsVirtualPCPresent = True
  93.        Case sData Like "*VBOX*"
  94.            IsVirtualPCPresent = True
  95.    End Select
  96.  
  97. End Function
  98.  
  99. Private Function GetPNPDeviceID(ByVal sDevice As String) As String
  100.    Dim tGUID                               As GUID
  101.    Dim hDevInfo                            As Long
  102.    Dim tSP_DEVICE_INTERFACE_DATA           As SP_DEVICE_INTERFACE_DATA
  103.    Dim tSP_DEVICE_INTERFACE_DETAIL_DATA    As SP_DEVICE_INTERFACE_DETAIL_DATA
  104.    Dim tSP_DEVINFO_DATA                    As SP_DEVINFO_DATA
  105.    Dim lDevNumb                            As Long
  106.  
  107.    lDevNumb = GetDeviceNumber("\\.\" & Left$(sDevice, 1) & ":")
  108.    If lDevNumb = -1 Then Exit Function
  109.  
  110.    sDevice = Left$(sDevice, 1) & ":"
  111.  
  112.    With tGUID
  113.        .Data2 = &HB6BF:        .Data3 = &H11D0&
  114.        .Data4(0) = &H94&:      .Data4(1) = &HF2&
  115.        .Data4(2) = &H0&:       .Data4(3) = &HA0&
  116.        .Data4(4) = &HC9&:      .Data4(5) = &H1E&
  117.        .Data4(6) = &HFB&:      .Data4(7) = &H8B&
  118.  
  119.        Select Case GetDriveType(sDevice)
  120.            Case 2
  121.                Dim sDosDev As String * 260
  122.                Call QueryDosDevice(sDevice, sDosDev, 260)
  123.                If InStr(sDosDev, "\Floppy") Then
  124.                    .Data1 = &H53F56311
  125.                Else
  126.                    .Data1 = &H53F56307
  127.                End If
  128.            Case 3: .Data1 = &H53F56307
  129.            Case 5: .Data1 = &H53F56308
  130.        End Select
  131.    End With
  132.  
  133.    hDevInfo = SetupDiGetClassDevs(VarPtr(tGUID), 0, 0, _
  134.       DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)
  135.    If hDevInfo = -1 Then Exit Function
  136.  
  137.    tSP_DEVICE_INTERFACE_DATA.cbSize = Len(tSP_DEVICE_INTERFACE_DATA)
  138.  
  139.    Dim lIndex  As Long
  140.    Dim lSize   As Long
  141.    Dim lReturn As Long
  142.  
  143.    Do
  144.        If SetupDiEnumDeviceInterfaces(hDevInfo, 0, tGUID, _
  145.           lIndex, tSP_DEVICE_INTERFACE_DATA) Then
  146.  
  147.            If SetupDiGetDeviceInterfaceDetail(hDevInfo, _
  148.               tSP_DEVICE_INTERFACE_DATA, ByVal 0&, 0, lSize, ByVal 0&) = 0 Then
  149.  
  150.                If Not lSize = 0 Then
  151.                    tSP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = 5
  152.                    tSP_DEVINFO_DATA.cbSize = Len(tSP_DEVINFO_DATA)
  153.  
  154.                    If SetupDiGetDeviceInterfaceDetail(hDevInfo, _
  155.                       tSP_DEVICE_INTERFACE_DATA, tSP_DEVICE_INTERFACE_DETAIL_DATA, _
  156.                       ByVal lSize, lReturn, tSP_DEVINFO_DATA) Then
  157.                        If lDevNumb = _
  158.                           GetDeviceNumber(tSP_DEVICE_INTERFACE_DETAIL_DATA.strDevicePath) Then
  159.                            Call SetupDiDestroyDeviceInfoList(hDevInfo)
  160.                            GetPNPDeviceID = Left$(tSP_DEVICE_INTERFACE_DETAIL_DATA.strDevicePath, _
  161.                               lstrlen(tSP_DEVICE_INTERFACE_DETAIL_DATA.strDevicePath))
  162.                            Exit Function
  163.                        End If
  164.                    End If
  165.                End If
  166.            End If
  167.            lIndex = lIndex + 1
  168.        Else
  169.            Exit Function
  170.        End If
  171.    Loop
  172.    Call SetupDiDestroyDeviceInfoList(hDevInfo)
  173.  
  174. End Function
  175.  
  176. Private Function GetDeviceNumber(ByVal sDrive As String) As Long
  177.    Dim hVolume                 As Long
  178.    Dim lRetBytes               As Long
  179.    Dim tSTORAGE_DEVICE_NUMBER  As STORAGE_DEVICE_NUMBER
  180.  
  181.    hVolume = CreateFile(sDrive, 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, _
  182.       ByVal 0&, OPEN_EXISTING, 0, 0)
  183.  
  184.    GetDeviceNumber = -1
  185.  
  186.    If Not hVolume = INVALID_HANDLE_VALUE Then
  187.        If DeviceIoControl(hVolume, &H2D1080, ByVal 0&, ByVal 0&, _
  188.           tSTORAGE_DEVICE_NUMBER, Len(tSTORAGE_DEVICE_NUMBER), _
  189.           lRetBytes, ByVal 0&) Then
  190.            GetDeviceNumber = tSTORAGE_DEVICE_NUMBER.dwDeviceNumber
  191.        End If
  192.        Call CloseHandle(hVolume)
  193.    End If
  194. End Function
  195.  
  196.  


En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
‭‭‭‭jackl007


Desconectado Desconectado

Mensajes: 1.403


[UserRPL]


Ver Perfil WWW
Re: IsVirtualPCPresent (no WMI) [Source]
« Respuesta #1 en: 3 Julio 2008, 02:29 am »

y esto no hace lo mismo?
http://foro.elhacker.net/programacion_vb/source_isvirtualpcpresent_sistema_antivirtualpc-t218845.0.html;msg1037935#msg1037935
o depende de algo para funcionar?




En línea

cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: IsVirtualPCPresent (no WMI) [Source]
« Respuesta #2 en: 3 Julio 2008, 02:36 am »

Si, el fin del codigo es el mismo, si miras el titulo dice NO WMI (Windows Management Instrumentation), lo hice asi porque como comente en el post original de MadAntrax, tube problemas con WMI y cuentas restringidas.
En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
‭‭‭‭jackl007


Desconectado Desconectado

Mensajes: 1.403


[UserRPL]


Ver Perfil WWW
Re: IsVirtualPCPresent (no WMI) [Source]
« Respuesta #3 en: 3 Julio 2008, 02:54 am »

tube problemas con WMI y cuentas restringidas.

eso queria saber, osea ese codigo de mad no era fiable para todas las pcs? ....
En línea

cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: IsVirtualPCPresent (no WMI) [Source]
« Respuesta #4 en: 3 Julio 2008, 03:27 am »

En vista con cuenta de invitado obtengo un esto al intentar conectar WMI (error 70: Permission Denied)
En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
Mad Antrax
Colaborador
***
Desconectado Desconectado

Mensajes: 2.164


Cheats y Trainers para todos!


Ver Perfil WWW
Re: IsVirtualPCPresent (no WMI) [Source]
« Respuesta #5 en: 3 Julio 2008, 11:43 am »

Jaque-mate.

Tu código es más estable al no usar WMI, pero algo extenso (para mi gusto) si lo implementas en stubs o similares.

De todas formas, seguro que ay otro método más sencillo y sin utilizar WMI para detectarlo... hay que investigar más!!

--------------

Por cierto, puedes discriminar un poco más la función, me explico:

"*VIRTUAL*" = VirtualPC
"*VMWARE*" = VMWare
"*VBOX*" = VirtualBox

Puedes hacer que la función de vuelva un Integer, ejemplo:

Código
  1.   Select Case True
  2.        Case sData Like "*VIRTUAL*"
  3.           IsVirtualPCPresent = 1
  4.        Case sData Like "*VMWARE*"
  5.           IsVirtualPCPresent = 2
  6.        Case sData Like "*VBOX*"
  7.            IsVirtualPCPresent = 3
  8.        Case Else
  9.            IsVirtualPCPresent = 0
  10.    End Select

Así el usuari podrá determinar si finaliza su ejecución solo si nos encontramos en VMWARE o solo en VirtualPC, etc...

Saludos, muy buen código.
« Última modificación: 3 Julio 2008, 11:47 am por ||MadAntrax|| » En línea

No hago hacks/cheats para juegos Online.
Tampoco ayudo a nadie a realizar hacks/cheats para juegos Online.
cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: IsVirtualPCPresent (no WMI) [Source]
« Respuesta #6 en: 3 Julio 2008, 12:19 pm »

@||MadAntrax||

Gracias por el comentario, se que es un poco extenso pero queria mantenerlo entendible y fiel al original.

Creo que el metodo mas simple para hacer esto es leer el valor de la clave HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Disk\Enum\0\   y compararla los los 3 patrones mencionados.
No lo probe con diferentes cuentas ni OSs pero por lo poco que vi funciona perfectamente.

Saludos y gracias por el feedback.


Edit:

Bueno Aca esta el codigo de la idea anterior

Código
  1. '---------------------------------------------------------------------------------------
  2. ' Module      : mDetectVM
  3. ' DateTime    : 03/07/2008 07:32
  4. ' Author      : Cobein
  5. ' Mail        : cobein27@hotmail.com
  6. ' WebPage     : http://cobein27.googlepages.com/vb6
  7. ' Purpose     : Mini Virtual Machine detection module
  8. ' Usage       : At your own risk
  9. ' Requirements: None
  10. ' Distribution: You can freely use this code in your own
  11. '               applications, but you may not reproduce
  12. '               or publish this code on any web site,
  13. '               online service, or distribute as source
  14. '               on any media without express permission.
  15. '
  16. ' History     : 03/07/2008 First Cut....................................................
  17. '---------------------------------------------------------------------------------------
  18. Option Explicit
  19.  
  20. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  21. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  22. 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
  23.  
  24. Public Function IsVirtualPCPresent() As Long
  25.    Dim lhKey       As Long
  26.    Dim sBuffer     As String
  27.    Dim lLen        As Long
  28.  
  29.    If RegOpenKeyEx(&H80000002, "SYSTEM\ControlSet001\Services\Disk\Enum", _
  30.       0, &H20019, lhKey) = 0 Then
  31.        sBuffer = Space$(255): lLen = 255
  32.        If RegQueryValueEx(lhKey, "0", 0, 1, ByVal sBuffer, lLen) = 0 Then
  33.            sBuffer = UCase(Left$(sBuffer, lLen - 1))
  34.            Select Case True
  35.                Case sBuffer Like "*VIRTUAL*":   IsVirtualPCPresent = 1
  36.                Case sBuffer Like "*VMWARE*":    IsVirtualPCPresent = 2
  37.                Case sBuffer Like "*VBOX*":      IsVirtualPCPresent = 3
  38.            End Select
  39.        End If
  40.        Call RegCloseKey(lhKey)
  41.    End If
  42. End Function
  43.  
« Última modificación: 3 Julio 2008, 12:36 pm por cobein » En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines