Hola, os traigo una clase para obtener varia información sobre el sistema.

Information.cpp
#include "Information.hpp"

void Information::GetUsername(char* szUsername) {
    DWORD dwUsernameSize = MAX_STRING_SIZE;
    GetUserNameA(szUsername, &dwUsernameSize);
}

void Information::GetComputername(char* szComputerName) {
    DWORD dwComputerNameSize = MAX_STRING_SIZE;
    GetComputerNameA(szComputerName, &dwComputerNameSize);
}

void Information::GetWindowsName(char* szOperatingSystem) {
    OSVERSIONINFOEX osVersion;
    osVersion.dwOSVersionInfoSize = sizeof(osVersion);
    GetVersionEx((OSVERSIONINFO *)&osVersion);

    if(osVersion.dwMajorVersion == 6) {
        if(osVersion.dwMinorVersion == 0) {
            if(osVersion.wProductType != VER_NT_WORKSTATION) {
                strcpy(szOperatingSystem, "Windows Server 2008");
            } else {
                strcpy(szOperatingSystem, "Windows Vista");
            }
        } else if(osVersion.dwMinorVersion == 1) {
            if(osVersion.wProductType != VER_NT_WORKSTATION) {
                strcpy(szOperatingSystem, "Windows Server 2008 R2");
            } else {
                strcpy(szOperatingSystem, "Windows 7");
            }
        } else if(osVersion.dwMinorVersion == 2) {
            if(osVersion.wProductType != VER_NT_WORKSTATION) {
                strcpy(szOperatingSystem, "Windows Server 2012");
            } else {
                strcpy(szOperatingSystem, "Windows 8");
            }
        } else if(osVersion.dwMinorVersion == 3) {
            if(osVersion.wProductType != VER_NT_WORKSTATION) {
                strcpy(szOperatingSystem, "Windows Server 2012 R2");
            } else {
                strcpy(szOperatingSystem, "Windows 8.1");
            }
        }
    } else if(osVersion.dwMajorVersion == 5) {
        if(osVersion.dwMinorVersion == 0) {
            strcpy(szOperatingSystem, "Windows 2000");
        } else if(osVersion.dwMinorVersion == 1) {
            strcpy(szOperatingSystem, "Windows XP");
        } else if(osVersion.dwMinorVersion == 2) {
            if(GetSystemMetrics(SM_SERVERR2) == 0) {
                strcpy(szOperatingSystem, "Windows Server 2003");
            } else {
                strcpy(szOperatingSystem, "Windows Server 2003 R2");
            }
        }
    } else {
        strcpy(szOperatingSystem, "Unknown");
    }
}

void Information::IsUserAdmin(BOOL& IsAdmin) {
    IsAdmin = IsUserAnAdmin();
}

void Information::GetProcessor(char* szProcessorName) {
    Util::GetRegistryValue(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\\", "ProcessorNameString", szProcessorName);
}

void Information::GetGPU(char* szGPU) {
    Util::GetRegistryValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winsat", "PrimaryAdapterString", szGPU);
}

void Information:: GetCountry(char* szCountry) {
    GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGCOUNTRY, szCountry, MAX_STRING_SIZE);
}

void Information:: GetCountryShort(char* szCountryShort) {
    GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, szCountryShort, MAX_STRING_SIZE);
}

void Information::GetTotalRAM(char* szTotalRAM) {
    MEMORYSTATUSEX mem_stat;
    mem_stat.dwLength = sizeof(MEMORYSTATUSEX);
    GlobalMemoryStatusEx(&mem_stat);
    DWORDLONG dwRAM = (DWORDLONG )(mem_stat.ullTotalPhys/(1024*1024));
    wsprintf(szTotalRAM, "%u MB", dwRAM);
}
Information.hpp
#ifndef __INFORMATION__
#define __INFORMATION__

#define MAX_STRING_SIZE 256

#include <windows.h>
#include <Shlobj.h>
#include "Util.hpp"

class Information {
public:
    static void GetUsername(char* szUsername);
    static void GetComputername(char* szComputerName);
    static void GetWindowsName(char* szOperatingSystem);
    static void IsUserAdmin(BOOL& IsAdmin);
    static void GetProcessor(char* szProcessorName);
    static void GetGPU(char* szGPU);
    static void GetCountry(char* szCountry);
    static void GetCountryShort(char* szCountryShort);
    static void GetTotalRAM(char* szTotalRAM);
};

#endif // __INFORMATION__
Función GetRegistryValue (yo la tengo en la clase Util, vosotros podéis ponerla donde os de la gana)
void GetRegistryValue (HKEY hk, char* keyPath, char* keyName, char* keyData) {
    HKEY hKey;
    TCHAR lpData[1024];

    DWORD lpcbData= sizeof(lpData);

    if(RegOpenKeyExA(hk, keyPath, 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS) {
        if(RegQueryValueExA(hKey, keyName, NULL, NULL, (LPBYTE)lpData, &lpcbData) == ERROR_SUCCESS) {
            strcpy(keyData, lpData);
        } else strcpy(keyData, "Unknown");
    } else strcpy(keyData, "Unknown");

    RegCloseKey(hKey);
}
Tenéis que enlazar las librerías advapi32.lib, user32.lib y Shell32.lib.

Método de uso:
int main()
{
    printf("# Información del sistema:\n");
    char szUsername[1024], szComputerName[1024], szOsName[1024], szProcessor[1024], szGPU[1024], szCountry[1024], szCountryShort[1024], szTotalRAM[1024];
    BOOL IsAdmin;

    Information::GetUsername(szUsername);
    Information::GetComputername(szComputerName);
    Information::GetWindowsName(szOsName);
    Information::IsUserAdmin(IsAdmin);
    Information::GetProcessor(szProcessor);
    Information::GetGPU(szGPU);
    Information::GetCountry(szCountry);
    Information::GetCountryShort(szCountryShort);
    Information::GetTotalRAM(szTotalRAM);

    printf("Username: \t\t%s\n", szUsername);
    printf("ComputerName: \t\t%s\n", szComputerName);
    printf("OS: \t\t\t%s\n", szOsName);
    printf("IsUserAdmin: \t\t%d\n", IsAdmin);
    printf("Processor: \t\t%s\n", szProcessor);
    printf("GPU: \t\t\t%s\n", szGPU);
    printf("Country: \t\t%s\n", szCountry);
    printf("CountryShort: \t\t%s\n", szCountryShort);
    printf("RAM (MB): \t\t%s\n", szTotalRAM);

    return 0;
}
Pink escribió:Gracias por la clase Esta buena.
Saludos
¡Gracias! Si ves algo que se pueda mejorar no dudes en decírmelo. Ahora estoy haciendo una clase para detección de vm, sandbox, etc, y una de instalación. El propósito es brindar una serie de clases que se puedan utilizar en un bot/RAT.
Responder

Volver a “Fuentes”