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 }
#2
This works fine to perform a test upon Game.Exe and the accompanying RGSS.dll, these being in the root directory of the project. So quite often, anyone running this will receive the same response as any other.

Would there be a script available to test the architecture of the computer running said program, testing if it is in a Windows, Mac or Linux environment?
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#3
Actually, that would be feasible indeed. It's not complicated at all.
"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 }
#4
Well... guess I'd have to provide an answer. Tongue sticking out

For those thinking that RUBY_PLATFORM would do the trick, nope. It falters when Java is in use, returning 'Java' even if the PC itself was Windows, Mac or Linux. So I had to dig further.

The main consensus is the use of RbConfig. Unfortunately, RPGMaker XP (or any) do not come supplied with it, and there are various versions as there are various versions of Ruby. But after examining various versions of RbConfig from versions 1.8.5 through to more modern 2., I determined that I had need of only a handful of lines.

Below is a scriptette that can determine what Operating System your PC is using, returning something like :windows, :linux, :unix or :macosx.

Code:
#==============================================================================
# ** OS Detection via Ruby
#------------------------------------------------------------------------------
#    by DerVVulfman (09/08/2019) MM/DD/YYYY
#    based on the work of Thomas Enebo (11/27/2012) MM/DD/YYYY
#==============================================================================



#==============================================================================
# ** RbConfig
#------------------------------------------------------------------------------
#  This module holds Configuration settings for Ruby Operations.
#  THIS IS NOT COMPLETE, BUT A BAREBONES EXERPT.  VARIOUS RBCONFIGS EXIST
#  BASED ON VERSION NUMBERS
#==============================================================================

module RbConfig
  CONFIG = {}  
  CONFIG["host_os"] = "mingw32msvc"
end



#==============================================================================
# ** Operating System Detection
#------------------------------------------------------------------------------
#  This module actively uses the RbConfig system to detect what operating
#  system is in use.  The below code is sound, the RbConfig used above is
#  merely a snippet of the whole.
#
#  Refer to OS_Detect::execute to perform the operation
#==============================================================================

module OS_Detect
  #--------------------------------------------------------------------------
  # * Methods/Functions Executable From Outside Call
  #--------------------------------------------------------------------------
  module_function  
  #--------------------------------------------------------------------------
  # * Object Execution
  #--------------------------------------------------------------------------
  def execute
    @os ||= (
      host_os = RbConfig::CONFIG['host_os']
      case host_os
      when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
        :windows
      when /darwin|mac os/
        :macosx
      when /linux/
        :linux
      when /solaris|bsd/
        :unix
      else
        raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
      end
    )
  end
end

  
# THIS prints the version
p OS_Detect::execute

You can replace the returned values (like :windows) with numeric values if it helps Winking

This will prove useful if one wishes to permit Win32DLL applications to run in their game for Windows Users, and perhaps have a workaround for those without.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#5
Use the more conventional Module.method notation instead, even for rubyists it's weird to use double colon for calling such module method.
"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 }


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



Users browsing this thread: 1 Guest(s)