forked from jjyg/metasm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
metasm.rb
88 lines (79 loc) · 3.09 KB
/
metasm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# This file is part of Metasm, the Ruby assembly manipulation suite
# Copyright (C) 2006-2009 Yoann GUILLOT
#
# Licence is LGPL, see LICENCE in the top-level directory
module Metasm
# 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
# constants defined in the same file as another
Const_autorequire_equiv = {
'X86' => 'Ia32', 'PPC' => 'PowerPC',
'X64' => 'X86_64', 'AMD64' => 'X86_64',
'MIPS64' => 'MIPS', 'AArch64' => 'ARM64',
'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',
}
# files to require to get the definition of those constants
Const_autorequire = {
'Ia32' => 'cpu/ia32', 'MIPS' => 'cpu/mips', 'PowerPC' => 'cpu/ppc', 'ARM' => 'cpu/arm',
'X86_64' => 'cpu/x86_64', 'Sh4' => 'cpu/sh4', 'Dalvik' => 'cpu/dalvik', 'ARC' => 'cpu/arc',
'Python' => 'cpu/python', 'Z80' => 'cpu/z80', 'CY16' => 'cpu/cy16', 'BPF' => 'cpu/bpf',
'MSP430' => 'cpu/msp430', 'ARM64' => 'cpu/arm64',
'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',
'GameBoyRom' => 'exe_format/gb',
'Bflt' => 'exe_format/bflt', 'Dol' => 'exe_format/dol',
'PYC' => 'exe_format/pyc', 'JavaClass' => 'exe_format/javaclass',
'SWF' => 'exe_format/swf', 'ZIP' => 'exe_format/zip',
'Shellcode_RWX' => 'exe_format/shellcode_rwx',
'Gui' => 'gui',
'WindowsExports' => 'os/windows_exports',
'GNUExports' => 'os/gnu_exports',
'Debugger' => 'debug',
'LinOS' => 'os/linux', 'WinOS' => 'os/windows',
'GdbClient' => 'os/gdbremote',
'Disassembler' => 'disassemble',
'Decompiler' => 'decompile',
'DynLdr' => 'dynldr',
}
# use the Module.autoload ruby functionnality to load framework components on demand
Const_autorequire.each { |cst, file|
autoload cst, File.join('metasm', file)
}
Const_autorequire_equiv.each { |cst, eqv|
file = Const_autorequire[eqv]
autoload cst, File.join('metasm', file)
}
end
# load Metasm core files
%w[main encode decode render exe_format/main os/main].each { |f|
require File.join('metasm', f)
}
# remove an 1.9 warning, couldn't find a compatible way...
if Hash.new.respond_to?(:key)
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
end