2009-03-29 07:30:54 +00:00
|
|
|
# This file is part of Metasm, the Ruby assembly manipulation suite
|
2010-09-09 18:19:35 +00:00
|
|
|
# Copyright (C) 2006-2009 Yoann GUILLOT
|
2009-03-29 07:30:54 +00:00
|
|
|
#
|
|
|
|
# Licence is LGPL, see LICENCE in the top-level directory
|
|
|
|
|
2010-09-09 18:19:35 +00:00
|
|
|
|
2009-03-29 07:30:54 +00:00
|
|
|
module Metasm
|
2010-09-09 18:19:35 +00:00
|
|
|
# root directory for metasm files
|
|
|
|
# used by some scripts, eg to find samples/dasm-plugin directory
|
|
|
|
Metasmdir = File.dirname(__FILE__)
|
2011-04-06 17:40:01 +00:00
|
|
|
# add it to the ruby library path
|
|
|
|
$: << Metasmdir
|
2010-09-09 18:19:35 +00:00
|
|
|
|
2011-04-06 17:40:01 +00:00
|
|
|
# constants defined in the same file as another
|
2010-09-09 18:19:35 +00:00
|
|
|
Const_autorequire_equiv = {
|
2009-03-29 07:30:54 +00:00
|
|
|
'X86' => 'Ia32', 'PPC' => 'PowerPC',
|
2010-09-09 18:19:35 +00:00
|
|
|
'X64' => 'X86_64', 'AMD64' => 'X86_64',
|
2009-03-29 07:30:54 +00:00
|
|
|
'UniversalBinary' => 'MachO', 'COFFArchive' => 'COFF',
|
2010-09-09 18:19:35 +00:00
|
|
|
'DEY' => 'DEX',
|
|
|
|
'PTrace' => 'LinOS', 'FatELF' => 'ELF',
|
2009-03-29 07:30:54 +00:00
|
|
|
'LoadedELF' => 'ELF', 'LoadedPE' => 'PE',
|
2010-09-09 18:19:35 +00:00
|
|
|
'LoadedAutoExe' => 'AutoExe',
|
2009-03-29 07:30:54 +00:00
|
|
|
'LinuxRemoteString' => 'LinOS',
|
2010-09-09 18:19:35 +00:00
|
|
|
'LinDebugger' => 'LinOS',
|
|
|
|
'WinAPI' => 'WinOS',
|
|
|
|
'WindowsRemoteString' => 'WinOS', 'WinDbgAPI' => 'WinOS',
|
|
|
|
'WinDebugger' => 'WinOS',
|
|
|
|
'GdbRemoteString' => 'GdbClient', 'GdbRemoteDebugger' => 'GdbClient',
|
|
|
|
'DecodedInstruction' => 'Disassembler', 'DecodedFunction' => 'Disassembler',
|
|
|
|
'InstructionBlock' => 'Disassembler',
|
|
|
|
}
|
|
|
|
|
2011-04-06 17:40:01 +00:00
|
|
|
# files to require to get the definition of those constants
|
2010-09-09 18:19:35 +00:00
|
|
|
Const_autorequire = {
|
|
|
|
'Ia32' => 'ia32', 'MIPS' => 'mips', 'PowerPC' => 'ppc', 'ARM' => 'arm',
|
|
|
|
'X86_64' => 'x86_64', 'Sh4' => 'sh4', 'Dalvik' => 'dalvik',
|
2011-04-06 17:40:01 +00:00
|
|
|
'C' => 'compile_c',
|
2009-03-29 07:30:54 +00:00
|
|
|
'MZ' => 'exe_format/mz', 'PE' => 'exe_format/pe',
|
2010-10-08 16:01:37 +00:00
|
|
|
'ELF' => 'exe_format/elf', 'COFF' => 'exe_format/coff',
|
2009-03-29 07:30:54 +00:00
|
|
|
'Shellcode' => 'exe_format/shellcode', 'AutoExe' => 'exe_format/autoexe',
|
|
|
|
'AOut' => 'exe_format/a_out', 'MachO' => 'exe_format/macho',
|
2010-09-09 18:19:35 +00:00
|
|
|
'DEX' => 'exe_format/dex',
|
2009-03-29 07:30:54 +00:00
|
|
|
'NDS' => 'exe_format/nds', 'XCoff' => 'exe_format/xcoff',
|
2010-09-09 18:19:35 +00:00
|
|
|
'Bflt' => 'exe_format/bflt', 'Dol' => 'exe_format/dol',
|
|
|
|
'Gui' => 'gui',
|
|
|
|
'WindowsExports' => 'os/windows_exports',
|
|
|
|
'GNUExports' => 'os/gnu_exports',
|
2009-03-29 07:30:54 +00:00
|
|
|
'LinOS' => 'os/linux', 'WinOS' => 'os/windows',
|
2010-09-09 18:19:35 +00:00
|
|
|
'GdbClient' => 'os/remote',
|
|
|
|
'Disassembler' => 'disassemble',
|
2009-03-29 07:30:54 +00:00
|
|
|
'Decompiler' => 'decompile',
|
2010-09-09 18:19:35 +00:00
|
|
|
'DynLdr' => 'dynldr',
|
|
|
|
}
|
2009-03-29 07:30:54 +00:00
|
|
|
|
2011-04-06 17:40:01 +00:00
|
|
|
# use the Module.autoload ruby functionnality to load framework components on demand
|
|
|
|
Const_autorequire.each { |cst, file|
|
|
|
|
autoload cst, File.join('metasm', file)
|
|
|
|
}
|
2009-03-29 07:30:54 +00:00
|
|
|
|
2011-04-06 17:40:01 +00:00
|
|
|
Const_autorequire_equiv.each { |cst, eqv|
|
|
|
|
file = Const_autorequire[eqv]
|
|
|
|
autoload cst, File.join('metasm', file)
|
|
|
|
}
|
2009-03-29 07:30:54 +00:00
|
|
|
end
|
|
|
|
|
2011-04-06 17:40:01 +00:00
|
|
|
# load Metasm core files
|
|
|
|
%w[main encode decode render exe_format/main os/main].each { |f|
|
|
|
|
require File.join('metasm', f)
|
|
|
|
}
|
2009-03-29 07:30:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
# remove an 1.9 warning, couldn't find a compatible way...
|
2011-04-06 17:40:01 +00:00
|
|
|
if Hash.new.respond_to?(:key)
|
2010-10-08 16:01:37 +00:00
|
|
|
puts "using ruby1.9 workaround for Hash#index warning" if $DEBUG
|
|
|
|
class Hash
|
|
|
|
alias index_premetasm index rescue nil
|
|
|
|
undef index rescue nil
|
|
|
|
alias index key
|
|
|
|
end
|
2009-03-29 07:30:54 +00:00
|
|
|
end
|