Advertisement
FlyFar

DoubleAgent/OS.c

Jan 2nd, 2024
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | Cybersecurity | 0 0
  1. /* Includes ******************************************************************/
  2. #include <Windows.h>
  3. #include "Status.h"
  4. #include "OS.h"
  5.  
  6. /* Public Function Definitions ***********************************************/
  7. DOUBLEAGENT_STATUS OS_GetArchitecture(OUT POS_ARCHITECTURE peOsArchitecture)
  8. {
  9.     DOUBLEAGENT_STATUS eStatus = DOUBLEAGENT_STATUS_INVALID_VALUE;
  10.     OS_ARCHITECTURE eOsArchitectureLocal = OS_ARCHITECTURE_INVALID_VALUE;
  11. #ifndef _WIN64
  12.     BOOL bIsWow64 = FALSE;
  13. #endif
  14.  
  15.     /* Validates the parameters */
  16.     if (NULL == peOsArchitecture)
  17.     {
  18.         DOUBLEAGENT_SET(eStatus, DOUBLEAGENT_STATUS_DOUBLEAGENT_OS_GETARCHITECTURE_INVALID_PARAMS);
  19.         goto lbl_cleanup;
  20.     }
  21.  
  22. #ifdef _WIN64
  23.     /* The program is executing 64 bit code, the OS must be 64 bit */
  24.     eOsArchitectureLocal = OS_ARCHITECTURE_X64;
  25. #else
  26.     /* The program is executing 32 bit code, checks the OS architecture */
  27.     if (FALSE == IsWow64Process(GetCurrentProcess(), &bIsWow64))
  28.     {
  29.         DOUBLEAGENT_SET(eStatus, DOUBLEAGENT_STATUS_DOUBLEAGENT_OS_GETARCHITECTURE_ISWOW64PROCESS_FAILED);
  30.         goto lbl_cleanup;
  31.     }
  32.  
  33.     if (FALSE != bIsWow64)
  34.     {
  35.         /* The process is running under WOW64, the OS is 64 bit */
  36.         eOsArchitectureLocal = OS_ARCHITECTURE_X64;
  37.     }
  38.     else
  39.     {
  40.         /* The process is not running under WOW64, the OS is 32 bit */
  41.         eOsArchitectureLocal = OS_ARCHITECTURE_X86;
  42.     }
  43. #endif
  44.  
  45.     /* Sets the received parameters */
  46.     *peOsArchitecture = eOsArchitectureLocal;
  47.  
  48.     /* Succeeded */
  49.     DOUBLEAGENT_SET(eStatus, DOUBLEAGENT_STATUS_SUCCESS);
  50.  
  51. lbl_cleanup:
  52.     /* Returns status */
  53.     return eStatus;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement