ooRexx logo
../code/exebitness.orx/var/www/html/ooRexx/wip #!/usr/bin/rexx /* --------------------------------------------------------------------------------------- */ /* No freakin' copyright, no stinkin' license, no guarantees or warranties */ /* (implied, explicit or whatever). Usage is totally and completely at your own risk. */ /* Please keep this comment block as is when modifying this code. Thanks in advance, */ /* Ruurd Idenburg */ /* --------------------------------------------------------------------------------------- */ /* 2016/04/04 Initial version - Ruurd Idenburg */ /* --------------------------------------------------------------------------------------- */ /* Checks the architecture and bitness of a Windows executable ( EXE or DLL ) */ /* --------------------------------------------------------------------------------------- */ parse source os how name . parse arg file_name file_stream = .stream~new(file_name) -- read the DOS header, PE offset is a 32 bit little-endian integer parse value file_stream~charin(,64) with id 3 . 61 PE_offset -- header should start with the magic 'MZ' if id<>'MZ' then do raise syntax 88.917 array ("'"file_name"'", "is not a valid Windows executable") end -- read the PE header for 6 bytes at PE_offset (offset is little-endian base 0) -- the last two bytes indicate the architecture and resulting bitness parse value file_stream~charin(PE_offset~reverse~c2d+1,6) with id 3 . 5 arch -- header should start with 'PE' if id<>'PE' then do raise syntax 88.917 array ("'"file_name"'", "is not a PE conforming executable") end -- arch is little-endian arch = arch~reverse select when arch=='014c'x then res = 'i386->'32 when arch=='0200'x then res = 'ia64->'64 when arch=='8664'x then res = 'amd64->'64 otherwise res = 'unknown->unknown' end if how=='COMMAND' then do -- Assuming we're running in Windows (in upcoming release we can use .pathseparator) say "The machine architecture->bitness for ["file_name~makearray("\")~lastitem"] is:" res exit end return res
If you feel inclined to make corrections, suggestions etc., please mail me any.
All content © Ruurd Idenburg, 2007–, except where marked otherwise. All rights reserved. This page is primarily for non-commercial use only. The Idenburg website records no personal information and sets no ‘cookies’. This site is hosted on a VPS(Virtual Private System) rented from Transip.nl, a Dutch company, falling under Dutch (privacy) laws (I think).

This page updated on by Ruurd Idenburg.