Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Find out what's your file's architecture using Ruby!
#1
Shocked 
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! Shocked


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... Sad

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

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. Laughing + Tongue sticking out

I think it can even run if you copy and paste it on the maker's script editor. Happy with a sweat
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Messages In This Thread
Find out what's your file's architecture using Ruby! - by kyonides - 08-03-2019, 10:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Ruby Builder v 0.2 Narzew 2 5,448 10-10-2012, 06:11 AM
Last Post: Narzew
   Rubular - a Ruby regular expression editor zecomeia 2 5,624 03-14-2010, 02:44 PM
Last Post: zecomeia



Users browsing this thread: