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
|
2013-08-30 21:28:33 +00:00
|
|
|
# root directory for metasm files
|
|
|
|
# used by some scripts, eg to find samples/dasm-plugin directory
|
|
|
|
Metasmdir = File.dirname(__FILE__)
|
|
|
|
# add it to the ruby library path
|
|
|
|
$: << Metasmdir
|
2010-09-09 18:19:35 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
# constants defined in the same file as another
|
|
|
|
Const_autorequire_equiv = {
|
|
|
|
'X86' => 'Ia32', 'PPC' => 'PowerPC',
|
|
|
|
'X64' => 'X86_64', 'AMD64' => 'X86_64',
|
|
|
|
'UniversalBinary' => 'MachO', 'COFFArchive' => 'COFF',
|
|
|
|
'DEY' => 'DEX',
|
|
|
|
'PTrace' => 'LinOS', 'FatELF' => 'ELF',
|
|
|
|
'LoadedELF' => 'ELF', 'LoadedPE' => 'PE',
|
|
|
|
'LoadedAutoExe' => 'AutoExe',
|
|
|
|
'LinuxRemoteString' => 'LinOS',
|
|
|
|
'LinDebugger' => 'LinOS',
|
|
|
|
'WinAPI' => 'WinOS',
|
|
|
|
'WindowsRemoteString' => 'WinOS', 'WinDbgAPI' => 'WinOS',
|
|
|
|
'WinDebugger' => 'WinOS',
|
|
|
|
'GdbRemoteString' => 'GdbClient', 'GdbRemoteDebugger' => 'GdbClient',
|
|
|
|
'DecodedInstruction' => 'Disassembler', 'DecodedFunction' => 'Disassembler',
|
|
|
|
'InstructionBlock' => 'Disassembler',
|
|
|
|
}
|
2010-09-09 18:19:35 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
# files to require to get the definition of those constants
|
|
|
|
Const_autorequire = {
|
|
|
|
'Ia32' => 'ia32', 'MIPS' => 'mips', 'PowerPC' => 'ppc', 'ARM' => 'arm',
|
|
|
|
'X86_64' => 'x86_64', 'Sh4' => 'sh4', 'Dalvik' => 'dalvik',
|
|
|
|
'C' => 'compile_c',
|
|
|
|
'MZ' => 'exe_format/mz', 'PE' => 'exe_format/pe',
|
|
|
|
'ELF' => 'exe_format/elf', 'COFF' => 'exe_format/coff',
|
|
|
|
'Shellcode' => 'exe_format/shellcode', 'AutoExe' => 'exe_format/autoexe',
|
|
|
|
'AOut' => 'exe_format/a_out', 'MachO' => 'exe_format/macho',
|
|
|
|
'DEX' => 'exe_format/dex',
|
|
|
|
'NDS' => 'exe_format/nds', 'XCoff' => 'exe_format/xcoff',
|
|
|
|
'Bflt' => 'exe_format/bflt', 'Dol' => 'exe_format/dol',
|
|
|
|
'Gui' => 'gui',
|
|
|
|
'WindowsExports' => 'os/windows_exports',
|
|
|
|
'GNUExports' => 'os/gnu_exports',
|
|
|
|
'LinOS' => 'os/linux', 'WinOS' => 'os/windows',
|
|
|
|
'GdbClient' => 'os/remote',
|
|
|
|
'Disassembler' => 'disassemble',
|
|
|
|
'Decompiler' => 'decompile',
|
|
|
|
'DynLdr' => 'dynldr',
|
|
|
|
}
|
2009-03-29 07:30:54 +00:00
|
|
|
|
2013-08-30 21:28:33 +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
|
|
|
|
2013-08-30 21:28:33 +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|
|
2013-08-30 21:28:33 +00:00
|
|
|
require File.join('metasm', f)
|
2011-04-06 17:40:01 +00:00
|
|
|
}
|
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)
|
2013-08-30 21:28:33 +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
|