Detect 32 or 64 bitness of an executable

Posted by Patrick Tingen on 06-Jul-2015 06:25

Some brilliant mind in our company decided that it would be a good idea to install 64 bit progress in exactly the same place where our 32 bit versions are located. 

In our tooling, we often start a _progres.exe to perform some tasks for us, but now that some of the installs have been replaced with 64 bit versions, this tasks often fail without any indication of what is wrong. I would like to be able to test whether the .exe is a 32 or 64 bit exe-file before I start it. Is there any way to do that from within Progress itself?

I found a post on SuperUser.com that addresses this, but I could not get it to work in Progress. Any suggestions are welcome. Preferably a 4GL solution since installing new tools raises a lot of eyebrows here. 

Posted by Brian K. Maher on 06-Jul-2015 07:25

Patrick,

This works...

DEFINE VARIABLE iOffset AS INTEGER   NO-UNDO.
DEFINE VARIABLE cFile   AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPart   AS CHARACTER NO-UNDO.
DEFINE VARIABLE mExe    AS MEMPTR    NO-UNDO.

cFile = "c:\dlc\bin\_progres.exe" .
COPY-LOB FILE cFile TO mExe.

DO iOffset = 1 TO 100000 BY 2:
  cPart = GET-STRING(mExe,iOffset,2).
  
  IF CAPS(cPart) = "PE" THEN
  DO:
    MESSAGE "Offset:" iOffset
       SKIP "String:" cPart 
       SKIP "Type:" GET-STRING(mExe,(iOffset + 4),1)
       VIEW-AS ALERT-BOX INFO BUTTONS OK.
    LEAVE. 
  END.     
END.


All Replies

Posted by bronco on 06-Jul-2015 06:40

How about PROCESS-ARCHITECTURE?

Posted by bronco on 06-Jul-2015 06:42

btw, this function was introduced in 11.3

Posted by Rob Fitzpatrick on 06-Jul-2015 06:43

It would be helpful to know which version you're using.  There is a pre-processor called process-architecture in later releases that might help you. And if you search for "{ } Preprocessor name reference" in the ABL reference there is a code sample showing the use of the kernel32 function IsWow64Process that might help you.

Posted by bronco on 06-Jul-2015 06:44

Sorry, I read poorly. You want to know before the session starts...

Posted by Jurjen Dijkstra on 06-Jul-2015 06:45

This article here suggest a hack: simply search the first occurence of "PE" in the exeutable file.

superuser.com/.../how-to-check-if-a-binary-is-32-or-64-bit-on-windows

Posted by Brian K. Maher on 06-Jul-2015 07:00

 
How about this one .. https://etechgoodness.wordpress.com/2014/12/11/powershell-determine-if-an-exe-is-32-or-64-bit-and-other-tricks/
 
 

Posted by Patrick Tingen on 06-Jul-2015 07:13

We are running 11.3 but we need to launch a character session of 10.2b.

The one Jurjen mentions is the one I found as well, but I cannot seem to get it to work in the 4GL. I am probably doing something wrong:

DEFINE VARIABLE iOffset AS INTEGER   NO-UNDO.
DEFINE VARIABLE cFile   AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPart   AS CHARACTER NO-UNDO.
DEFINE VARIABLE mExe    AS MEMPTR    NO-UNDO.

cFile = "d:\dlc102B\bin\_progres.exe" .
COPY-LOB FILE cFile TO mExe.

DO iOffset = 1 TO 100000 BY 2:
  cPart = GET-STRING(mExe,iOffset, 2).
  
  IF CAPS(cPart) = "PE" THEN
  DO:
    MESSAGE "Offset:" iOffset
       SKIP "String:" cPart GET-STRING(mExe,iOffset + 2)
       VIEW-AS ALERT-BOX INFO BUTTONS OK.
    LEAVE. 
  END.     
END.

Posted by Brian K. Maher on 06-Jul-2015 07:25

Patrick,

This works...

DEFINE VARIABLE iOffset AS INTEGER   NO-UNDO.
DEFINE VARIABLE cFile   AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPart   AS CHARACTER NO-UNDO.
DEFINE VARIABLE mExe    AS MEMPTR    NO-UNDO.

cFile = "c:\dlc\bin\_progres.exe" .
COPY-LOB FILE cFile TO mExe.

DO iOffset = 1 TO 100000 BY 2:
  cPart = GET-STRING(mExe,iOffset,2).
  
  IF CAPS(cPart) = "PE" THEN
  DO:
    MESSAGE "Offset:" iOffset
       SKIP "String:" cPart 
       SKIP "Type:" GET-STRING(mExe,(iOffset + 4),1)
       VIEW-AS ALERT-BOX INFO BUTTONS OK.
    LEAVE. 
  END.     
END.


Posted by gus on 06-Jul-2015 08:17

v 11.3 and later has

if process-architecture = 65 then
. . .
else
. . .

regards, knower of even more obscure things than chris.
gus

I’d tell you a UDP joke, but you might not get it.

Posted by Tim Kuehn on 06-Jul-2015 09:08

On Mon, Jul 6, 2015 at 9:17 AM, gus wrote:
> I’d tell you a UDP joke, but you might not get it.

r r r....

--
Tim Kuehn: Senior Consultant - TDK Consulting Services
President - Ontario PUG
Program Committee Chair - PUG Challenge Americas,
Course Instructor: Intro to OO Concepts for Procedural Programmers

Skype: timothy.kuehn
Ph: 519-576-8100
Cell: 519-781-0081

Posted by Patrick Tingen on 06-Jul-2015 09:10

Brian, thanks a ton, this works like a charm!

This thread is closed