* * *

Author Topic: [SOLVED] How to tell if dll is 32-bit or 64-bit  (Read 1743 times)

ASerge

  • Sr. Member
  • ****
  • Posts: 339
Re: [SOLVED] How to tell if dll is 32-bit or 64-bit
« Reply #15 on: May 20, 2017, 01:19:49 am »
Test
Code: Pascal  [Select]
  1. program Project1;
  2. {$APPTYPE CONSOLE}
  3.  
  4. // Code above paste here
  5.  
  6. function PEBitnessAsText(V: TPEBitness): string;
  7. const
  8.   CValue: array [TPEBitness] of string = (
  9.     'Unknown', '16 bit', '32 bit', '64 bit');
  10. begin
  11.   Result := CValue[V];
  12. end;
  13.  
  14. procedure WritelnBitness(const FileName: WideString);
  15. begin
  16.   Writeln(FileName, ' is ', PEBitnessAsText(GetPEBitness(FileName)));
  17. end;
  18.  
  19. const
  20.   CDlls: array [1..5] of WideString = (
  21.     'c:\Windows\SysWOW64\netmsg.dll',
  22.     'c:\Windows\System32\netmsg.dll',
  23.     'c:\Windows\Sysnative\netmsg.dll',
  24.     'c:\Windows\twain.dll',
  25.     'c:\Windows\twain_32.dll');
  26. var
  27.   i: Integer;
  28. begin
  29.   for i := Low(CDlls) to High(CDlls) do
  30.     WritelnBitness(CDlls[i]);
  31.   Readln;
  32. end.

Result with 64 compiler:
c:\Windows\SysWOW64\netmsg.dll is 32 bit
c:\Windows\System32\netmsg.dll is 64 bit
c:\Windows\Sysnative\netmsg.dll is Unknown
c:\Windows\twain.dll is 16 bit
c:\Windows\twain_32.dll is 32 bit

Result with 32 compiler:
c:\Windows\SysWOW64\netmsg.dll is 32 bit
c:\Windows\System32\netmsg.dll is 32 bit
c:\Windows\Sysnative\netmsg.dll is 64 bit
c:\Windows\twain.dll is 16 bit
c:\Windows\twain_32.dll is 32 bit

GetMem

  • Hero Member
  • *****
  • Posts: 2135
Re: [SOLVED] How to tell if dll is 32-bit or 64-bit
« Reply #16 on: May 20, 2017, 08:09:54 am »
Quote
@Zoran
I'm asking because in the first version (see this post), there was a protective block, and I'm affraid that it was maybe inserted when the function returned 16-bit when it was not a valid 16-bit dll (I don't know, but it just looks like that...).
No, that was a logical error. My original code would fail to detect a 16 bit PE as you correctly pointed out in one of your previous post. I don't think it's a way to detect a corrupted 16/32/64 PE other then checking if a valid  IMAGE_DOS_SIGNATURE,  IMAGE_NT_SIGNATURE, etc... exist. I meant PE_UNKNOWN for special cases when the path to file is invalid or the memory map could not be crated or something else.

Quote
@ASerge
Multiple CloseHandle calls can be excluded.
Yes, your code is more compact, however I prefer a slightly verbose approach. It's much easier this way  to figure out what the code does at a later time. For example instead of:
Code: Pascal  [Select]
  1. if (Something) then
  2.   if (SomethingElse) then
  3.     DoThis
  4.   else
  5.     DoThat;
I always do:
Code: Pascal  [Select]
  1. if (Something) then
  2. begin
  3.   if (SomethingElse) then
  4.     DoThis
  5.   else
  6.     DoThat;
  7. end;
Which is code redundancy, but visually is more appealing to me, but I guess is just a personal preference.
« Last Edit: May 20, 2017, 08:12:46 am by GetMem »

Thaddy

  • Hero Member
  • *****
  • Posts: 3971
Re: [SOLVED] How to tell if dll is 32-bit or 64-bit
« Reply #17 on: May 20, 2017, 09:10:44 am »
That's why I like editors with a line length of at least 1024. So I definitely know that my Pascal code intended to have a linebreak and not white  :o 8-) space, but I guess is just a personal preference.  >:( ;D
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus