Advertisement
sebbu

framework detection

Mar 8th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. /* windows-only */
  4. #include <windows.h>
  5.  
  6. char const * const netfx_1_0_key = "Software\\Microsoft\\Active Setup\\Installed Components\\{78705f0d-e8db-4b2d-8193-982bdda15ecd}";
  7. char const * const netfx_1_0_value = "Version";
  8.  
  9. typedef struct version
  10. {
  11.     char const * const key;
  12.     char const * const name;
  13.     DWORD type;
  14.     char exist;
  15.     int size;
  16.     char * value;
  17. } version;
  18.  
  19. version netfx_1_0 = { "Software\\Microsoft\\.NETFramework\\Policy\\v1.0", "3705", REG_SZ, '\0', 0, NULL };
  20. version netfx_1_0a = { "Software\\Microsoft\\Active Setup\\Installed Components\\{78705f0d-e8db-4b2d-8193-982bdda15ecd}", "Version", REG_SZ, '\0', 0, NULL };
  21. version netfx_1_0b = { "Software\\Microsoft\\Active Setup\\Installed Components\\{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}", "Version", REG_SZ, '\0', 0, NULL };
  22. version netfx_1_1 = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322", "Install", REG_DWORD, '\0', 0, NULL };
  23. version netfx_1_1b = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322", "SP", REG_DWORD, '\0', 0, NULL };
  24. version netfx_1_1x64 = { "Software\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322", "Install", REG_DWORD, '\0', 0, NULL };
  25. version netfx_1_1x64b = { "Software\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322", "SP", REG_DWORD, '\0', 0, NULL };
  26. version netfx_2_0 = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", "Install", REG_DWORD, '\0', 0, NULL };
  27. version netfx_2_0b = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", "SP", REG_DWORD, '\0', 0, NULL };
  28. version netfx_3_0 = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0", "Install", REG_DWORD, '\0', 0, NULL };
  29. version netfx_3_0b = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0", "SP", REG_DWORD, '\0', 0, NULL };
  30. version netfx_3_5 = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5", "Install", REG_DWORD, '\0', 0, NULL };
  31. version netfx_3_5b = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5", "SP", REG_DWORD, '\0', 0, NULL };
  32. version netfx_4_0c = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Client", "Install", REG_DWORD, '\0', 0, NULL };
  33. version netfx_4_0cb = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Client", "Version", REG_SZ, '\0', 0, NULL };
  34. version netfx_4_0f = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", "Install", REG_DWORD, '\0', 0, NULL };
  35. version netfx_4_0fb = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", "Version", REG_SZ, '\0', 0, NULL };
  36. version netfx_4_5 = { "Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", "Release", REG_DWORD, '\0', 0, NULL };
  37.  
  38. #define vc 18
  39. version* my_list[vc] = {
  40.     &netfx_1_0, /*+1*/
  41.     &netfx_1_0a,
  42.     &netfx_1_0b,
  43.     &netfx_1_1,
  44.     &netfx_1_1b,
  45.     &netfx_1_1x64,
  46.     &netfx_1_1x64b,
  47.     &netfx_2_0,
  48.     &netfx_2_0b,
  49.     &netfx_3_0,
  50.     &netfx_3_0b,
  51.     &netfx_3_5,
  52.     &netfx_3_5b,
  53.     &netfx_4_0c,
  54.     &netfx_4_0cb,
  55.     &netfx_4_0f,
  56.     &netfx_4_0fb,
  57.     &netfx_4_5 /*+1*/
  58. };
  59. char const * const my_ver[vc] = {
  60.     "1.0 ",
  61.     "1.0 (te)",
  62.     "1.0 (mc)",
  63.     "1.1",
  64.     "1.1",
  65.     "1.1 x64",
  66.     "1.1 x64",
  67.     "2.0",
  68.     "2.0",
  69.     "3.0",
  70.     "3.0",
  71.     "3.5",
  72.     "3.5",
  73.     "4.0 client",
  74.     "4.0 client",
  75.     "4.0 full",
  76.     "4.0 full",
  77.     "4.5"
  78. };
  79.  
  80. int my_init(version* ver)
  81. {
  82.     int res = 0;
  83.     HKEY hk;
  84.     char* data = (char*)calloc(32+1, sizeof(char*));
  85.     int dwSize = 32;
  86.     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, ver->key, 0, KEY_READ, &hk) != ERROR_SUCCESS)
  87.     {
  88.         res = 1;
  89.     }
  90.    
  91.     if (RegQueryValueEx(hk, ver->name, 0, &ver->type, (LPBYTE)data, &dwSize) != ERROR_SUCCESS)
  92.     {
  93.         free(data);
  94.         ver->value = NULL;
  95.         res = 2;
  96.     }
  97.     else
  98.     {
  99.         ver->exist = '\1';
  100.         ver->size = dwSize;
  101.         ver->value = data;
  102.     }
  103.     RegCloseKey(hk);
  104.     return res;
  105. }
  106.  
  107. int my_free(version* ver)
  108. {
  109.     if(ver==NULL) return 0;
  110.     if(ver->value==NULL) return 0;
  111.     free(ver->value);
  112.     return 0;
  113. }
  114.  
  115. int main(int argc, char* argv[])
  116. {
  117.     printf("%s\n", "Hello World!");
  118.     /* HINSTANCE dllPtr = LoadLibrary("kernel32.dll"); */
  119.    
  120.     int i = 0;
  121.    
  122.     for(i=0;i<vc;i++)
  123.     {
  124.         my_init(my_list[i]);
  125.     }
  126.    
  127.     for(i=0;i<vc;i++)
  128.     {
  129.         if(my_list[i]->exist == '\0') continue;
  130.         if (my_list[i]->type == REG_SZ) {
  131.             printf("VER %s = %.*s\n", my_ver[i], my_list[i]->size, my_list[i]->value);
  132.         }
  133.         else if (my_list[i]->type == REG_DWORD) {
  134.             /* printf("%d\n", my_list[i]->size); */
  135.             if(my_list[i]->size == 4) {
  136.                 printf("VER %s = %d\n", my_ver[i], *((int*)my_list[i]->value));
  137.             }
  138.             else {
  139.                 printf("VER %s\n", my_ver[i]);
  140.             }
  141.         }
  142.     }
  143.    
  144.     for(i=0;i<vc;i++)
  145.     {
  146.         my_free(my_list[i]);
  147.     }
  148.    
  149.     /* FreeLibrary(dllPtr); */
  150.     return 0;
  151. }
  152. /**/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement