elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 03:03  


Tema destacado: Últimos eventos sobre seguridad/inseguridad

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse)
| | |-+  Seriales PenDrive DevC++ (SRC)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Seriales PenDrive DevC++ (SRC)  (Leído 147 veces)
Maurice_Lupin

Desconectado Desconectado

Mensajes: 110


GPS


Ver Perfil
Seriales PenDrive DevC++ (SRC)
« en: 17 Noviembre 2011, 17:27 »

Buscando código para VB.NET encontré esto, hice pequeñas modificaciones para que funcione en Dev C++ y googleando encontré la función Split, comparto el resultado

Hay que linkear: -lsetupapi
Código
 
#include <windows.h>
#include <Setupapi.h>
#include <stdio.h>
 
static /*const*/ GUID hidGUID = { 0xA5DCBF10L, 0x6530, 0x11D2,
{ 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };
 
char **split ( char *string, const char sep) {
 
   char       **lista;
   char       *p = string;
   int         i = 0;
 
   int         pos;
   const int   len = strlen (string);
 
   lista = (char **) malloc (sizeof (char *));
   if (lista == NULL) {                      /* Cannot allocate memory */
       return NULL;
   }
 
   lista[pos=0] = NULL;
 
   while (i <len) {
 
       while ((p[i] == sep) && (i <len))
           i++;
 
       if (i <len) {
 
           char **tmp = (char **) realloc (lista , (pos + 2) * sizeof (char *));
           if (tmp == NULL) {       /* Cannot allocate memory */
               free (lista);
               return NULL;
           }
           lista = tmp;
           tmp = NULL;
 
           lista[pos + 1] = NULL;
           lista[pos] = (char *) malloc (sizeof (char));
           if (lista[pos] == NULL) {         /* Cannot allocate memory */
               for (i = 0; i <pos; i++)
                   free (lista[i]);
               free (lista);
               return NULL;
           }
 
           int j = 0;
           for (i; ((p[i] != sep) && (i <len)); i++) {
               lista[pos][j] = p[i];
               j++;
 
               char *tmp2 = (char *) realloc (lista[pos],(j + 1) * sizeof (char));
               if (lista[pos] == NULL) {     /* Cannot allocate memory */
                   for (i = 0; i <pos; i++)
                       free (lista[i]);
                   free (lista);
                   return NULL;
               }
               lista[pos] = tmp2;
               tmp2 = NULL;
           }
           lista[pos][j] = '\0';
           pos++;
       }
   }
 
   return lista;
}
 
HANDLE connectDeviceNumber(DWORD deviceIndex)
{
   //GUID hidGUID;  
 
 
   HDEVINFO hardwareDeviceInfoSet;
   SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
   PSP_INTERFACE_DEVICE_DETAIL_DATA deviceDetail;
   ULONG requiredSize;
   HANDLE deviceHandle = INVALID_HANDLE_VALUE;
   DWORD result;
 
   //Get the HID GUID value - used as mask to get list of devices
   //HidD_GetHidGuid (&hidGUID);
   //hidGUID = new GUID(GUID GUID_DEVINTERFACE_USB_DEVICE);
 
   //Get a list of devices matching the criteria (hid interface, present)
   hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID,
                                                NULL, // Define no enumerator (global)
                                                NULL, // Define no
                                                (DIGCF_PRESENT | // Only Devices present
                                                DIGCF_DEVICEINTERFACE)); // Function class devices.
 
   deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
 
   //Go through the list and get the interface data
   result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet,
                                         NULL, //infoData,
                                         &hidGUID, //interfaceClassGuid,
                                         deviceIndex,
                                         &deviceInterfaceData);
 
   /* Failed to get a device - possibly the index is larger than the number of devices */
   if (result == FALSE)
   {
       SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
       printf("hidin: -- failed to get specified device number");
       return INVALID_HANDLE_VALUE;
   }
 
   //Get the details with null values to get the required size of the buffer
   SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                    &deviceInterfaceData,
                                    NULL, //interfaceDetail,
                                    0, //interfaceDetailSize,
                                    &requiredSize,
                                    0); //infoData))
 
   //Allocate the buffer
   deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
   deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
 
   //Fill the buffer with the device details
   if (!SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                         &deviceInterfaceData,
                                         deviceDetail,
                                         requiredSize,
                                         &requiredSize,
                                         NULL))
   {
       SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
       free (deviceDetail);
       printf("hidin: -- failed to get device info");
       return INVALID_HANDLE_VALUE;
   }
 
   char  **listSplit;
 
   listSplit = split(deviceDetail->DevicePath,'#');
 
   //printf("Opening device with path: %s", deviceDetail->DevicePath);
   printf("Serial: %s\n",listSplit[2] );
}
 
int main(int argc, char* argv[]) {
   connectDeviceNumber(0);
 
   getchar();
  return 0;
}
 


« Última modificación: 17 Noviembre 2011, 17:38 por Maurice_Lupin » En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Sobre seriales
Software
Randomize 5 601 Último mensaje 16 Agosto 2004, 15:53
por Luis_Kano
seriales
Dispositivos Móviles (PDA's, Smartphones)
Raspi 6 1,007 Último mensaje 1 Octubre 2004, 04:35
por phreackgsm
Seriales
Software
Trashin 2 461 Último mensaje 22 Octubre 2005, 04:28
por Trashin
Sistema de seriales
Programación Visual Basic
Saok Dagon 5 567 Último mensaje 1 Noviembre 2006, 21:49
por WarGhost
Ya no sirven los seriales de oro???
Windows
djtopo18 4 835 Último mensaje 26 Septiembre 2008, 16:29
por seba123neo
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines