etc.git


etc

~ scripts and random things
git clone https://github.com/djnnvx/etc.git
log | files | refs | archive

osinfo.c (1361B)

      1 #include <windows.h>
      2 #include <psapi.h>
      3 #include "osinfo.h"
      4 #include "logger.h"
      5 #include "api.h"
      6 #include "defs.h"
      7 
      8 // =====================================================
      9 // OS Information Functions
     10 // =====================================================
     11 
     12 unsigned long long getKBAddr() {
     13     DWORD cbNeeded = 0;
     14     PVOID* base = NULL;
     15 
     16     if (pEDD(NULL, 0, &cbNeeded)) {
     17         base = (PVOID*)malloc(cbNeeded);
     18         if (base) {
     19             if (pEDD(base, cbNeeded, &cbNeeded)) {
     20                 unsigned long long addr = (unsigned long long)base[0];
     21                 free(base);
     22                 return addr;
     23             }
     24             free(base);
     25         }
     26     }
     27 
     28     return 0;
     29 }
     30 
     31 // Function to get the OS version
     32 int GetOSVersion() {
     33     wchar_t CurrentBuild[255] = { 0 };
     34     DWORD bufferSize = sizeof(CurrentBuild);
     35     LONG ret = RegGetValueW(
     36         HKEY_LOCAL_MACHINE,
     37         L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
     38         L"CurrentBuild",
     39         RRF_RT_REG_SZ,
     40         NULL,
     41         CurrentBuild,
     42         &bufferSize
     43     );
     44     if (ret == ERROR_SUCCESS) {
     45         log_info("Windows Build %ls detected", CurrentBuild);
     46         return _wtoi(CurrentBuild);
     47     }
     48     else {
     49         log_error("Unable to retrieve Windows Build. Error code: %ld", ret);
     50         return -1;
     51     }
     52 }
     53