Page 1 of 1

Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 7:34 am
by Randy Walker
Any way to look at a file to know if it is a 64 or 32 bit app?

And while we're at it -- are all apps compiled using 64 bit PB automatically 64 bit?

Antbody?

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 7:53 am
by Randy Walker
Randy Walker wrote: Mon Aug 12, 2024 7:34 am Any way to look at a file to know if it is a 64 or 32 bit app?

Antbody?
I found an answer on the web to part one above:

"The easiest way, without installing another program or running the file, is just to right click on the file, choose Properties, and then go the the Compatibility tab. If there are no greyed out options and Windows XP and 9x modes are offered, it's 32-bit. If there are greyed out options and Vista is the earliest mode offered, it's 64-bit. No need to start the application at all."

No telling if that is bullet proof, but seems to work.

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 7:59 am
by BarryG
Randy Walker wrote: Mon Aug 12, 2024 7:34 amare all apps compiled using 64 bit PB automatically 64 bit?
Yes. For your other question: I don't know.

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 8:03 am
by Demivec
Randy Walker wrote: Mon Aug 12, 2024 7:34 am And while we're at it -- are all apps compiled using 64 bit PB automatically 64 bit?
If compiled by a 64 bit compiler a program is 64 bit.
If compiled by a 32 bit compiler a program is 32 bit.
This is true whether or not the c compilers are used for the compilation.

It should be noted that you can also arrange for a 32 bit compiler to be used in a 64 bit version of the PureBasic IDE.

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 11:15 am
by Bitblazer
For PE executables, check the Machine Types of the header

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 11:44 am
by NicTheQuick
On Linux just use the `file` tool:

Code: Select all

~$ file /usr/bin/ls
/usr/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=36b86f957a1be53733633d184c3a3354f3fc7b12, for GNU/Linux 3.2.0, stripped

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 12:06 pm
by RASHAD
Hi Randy
You can use Detect It Easy v3.09 and get more information

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 12:57 pm
by Bitblazer
There are several free tools for windows to detect and display PE structures. For example my current favorite hex editor ImHex.

Re: Is it 32 or 64 bit?

Posted: Mon Aug 12, 2024 3:15 pm
by skywalk

Code: Select all

Procedure.i SL_IsApp64Bit(fnpath_dll_exe$)
  ; Mijikai, https://www.purebasic.fr/english/viewtopic.php?p=530113#p530113
  Protected.i ri, ri2
  ri = ReadFile(#PB_Any, fnpath_dll_exe$)
  If ri
    Protected.i pos
    Protected IDH.IMAGE_DOS_HEADER
    Protected INH.IMAGE_NT_HEADERS
    If IsFile(ri)
      pos = Loc(ri)
      FileSeek(ri, #Null, #PB_Absolute)
      If ReadData(ri, @IDH, SizeOf(IMAGE_DOS_HEADER)) = SizeOf(IMAGE_DOS_HEADER)
        If IDH\e_magic = $5A4D
          If (IDH\e_lfanew - 8) < Lof(ri)
            FileSeek(ri, IDH\e_lfanew, #PB_Absolute)
            If ReadData(ri, @INH, SizeOf(IMAGE_NT_HEADERS)) = SizeOf(IMAGE_NT_HEADERS)
              If INH\Signature = $4550
                Select (INH\FileHeader\Machine & $FFFF) ; Helles Code
                Case $014C
                  ri2 = 0 ;32
                Case $8664
                  ri2 = 1 ;64
                EndSelect
              EndIf
            EndIf
          EndIf
        EndIf
      EndIf
      FileSeek(ri, pos, #PB_Absolute)
    EndIf
    CloseFile(ri)
  EndIf
  ProcedureReturn ri2
EndProcedure
Debug SL_IsApp64Bit("C:\PureBasic-x86\Compilers\Scintilla.dll")
Debug SL_IsApp64Bit("C:\PureBasic-x64\Compilers\Scintilla.dll")

Re: Is it 32 or 64 bit?

Posted: Sat Aug 17, 2024 2:00 am
by Randy Walker
Bitblazer wrote: Mon Aug 12, 2024 12:57 pm There are several free tools for windows to detect and display PE structures. For example my current favorite hex editor ImHex.
Thank you BitBlazer, I've been using freewsare "WinVI" which has been great for a portable plain hex editor.
https://www.winvi.de/en/

Re: Is it 32 or 64 bit?

Posted: Fri Aug 30, 2024 12:18 am
by Randy Walker
skywalk wrote: Mon Aug 12, 2024 3:15 pm

Code: Select all

Procedure.i SL_IsApp64Bit(fnpath_dll_exe$)
Thanks for that skywalk!! Some very cool code.