08-03-2019, 10:16 AM
After searching for an easy way to find out if an executable or library were meant to be run on x86 alias i386 (or i486 or i586) or x64 alias amd64 OS, I stumbled upon perl and python scripts. Then I thought there got to be a way to do it with Ruby and I was right! 
I felt great for finding it out myself, when I opened another website and read how another github user had posted a similar script a few years ago...
Anyway, now you can use it to get an extensive list of what file has what kind of architecture!
Just replace "puts" with "print" or in case you're an experienced scripter, you might already know how to store the results in a TXT file you can read at anytime.
I think it can even run if you copy and paste it on the maker's script editor.

Code:
def arch_of(fn)
f = File.open(fn,"rb")
dos = f.read(64)
magic, padding, offset = dos.unpack("a2a58l")
if magic != "MZ"
puts "This is neither an executable or a library!"
return
end
f.pos = offset
hdr = f.read(6)
sig, padding, machine = hdr.unpack("a2a2v")
f.close
if sig != "PE"
return puts "File #{fn} has an unknown architecture..."
end
if machine == 0x014c
return puts fn + " architecture detected: i386"
elsif machine == 0x0200
return puts fn + " architecture detected: IA64"
elsif machine == 0x8664
return puts fn + " architecture detected: x64"
else
return puts "File #{fn} has an unknown architecture..."
end
end
filenames = Dir['*.exe'].sort + Dir['*.dll'].sort
filenames.each {|fn| arch_of(fn) }
I felt great for finding it out myself, when I opened another website and read how another github user had posted a similar script a few years ago...

Anyway, now you can use it to get an extensive list of what file has what kind of architecture!

Just replace "puts" with "print" or in case you're an experienced scripter, you might already know how to store the results in a TXT file you can read at anytime.

I think it can even run if you copy and paste it on the maker's script editor.
