Check the Arquitecture of Files and DLLs

Check the Arquitecture of Files and DLLs with a Ruby script!

I'm posting this scriptlet here because it's not RGSS based but a common Ruby script so it might work on any version of RGSS in theory. You can also run it as a typical Ruby script on your PC in case you have already installed the Ruby interpreter there. Place the script in the same directory as the executable or DLL's and run it! Or paste it in the script editor as you'd do with any RGSS script, save your project and run it! 😮

Usually the results would be either 32 bit (i386) or 64 bit (x64). I doubt any of you is currently running any Itanium based PC. 😀

Code:
#!/usr/bin/env ruby
# Find out if your executables and libraries are compiled for a 32 or 64 bit architecture!
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 nor 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
    puts fn + " architecture detected: i386"
  elsif machine == 0x0200
    puts fn + " architecture detected: IA64"
  elsif machine == 0x8664
    puts fn + " architecture detected: x64"
  else
    puts "File #{fn} has an unknown architecture..."
  end
end

filenames = Dir['*.exe'].sort + Dir['*.dll'].sort
filenames.each {|fn| arch_of(fn) }

NOTE: #!/usr/bin/env ruby line included in the script above means it can be run on Linux as well, just in case you ever wanted to know that...

Terms

You're free to use, it's free as in speech and as in beer!
I would appreciate if you include me in your credits.

Original thread: https://forums.rpgmakerweb.com/threads/check-the-arquitecture-of-files-and-dlls.116748/