1. 程式人生 > >檢測dll是32/64位?(直接讀dll文件包含的某幾個字節進行判斷)

檢測dll是32/64位?(直接讀dll文件包含的某幾個字節進行判斷)

tle toc 進行 too mach comm include hello urn

檢查dll是32位還是64位?

[cpp] view plain copy
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. int _tmain(int argc, _TCHAR* argv[])
  4. {
  5. BYTE buf[4];
  6. FILE *fp = fopen("D:\\plugin_d.dll", "rb");
  7. fseek(fp, 0x40-4, 0);
  8. fread(buf, sizeof(char), 4, fp);
  9. int a = int(buf[0]);
  10. int b = int(buf[1])*256;
  11. int c = int(buf[2])*256*256;
  12. int d = int(buf[3])*256*256*256;
  13. int sum = a+b+c+d;
  14. fseek(fp, sum+4, 0);
  15. BYTE bufMachine[2];
  16. fread(bufMachine, sizeof(char), 2, fp);
  17. int machine = (int)bufMachine[0] + (int)(bufMachine[1])*256;
  18. if(machine == 0x14C)//332
  19. {
  20. printf("32 bit\r\n");
  21. }
  22. else if(machine == 0x8664)//34404
  23. {
  24. printf("64 bit\r\n");
  25. }
  26. else
  27. {
  28. printf("Unknow bit\r\n");
  29. }
  30. //system("pause");
  31. getchar();
  32. return 0;
  33. }

https://blog.csdn.net/hellokandy/article/details/73863510

檢測dll是32/64位?(直接讀dll文件包含的某幾個字節進行判斷)