a shellcode is a simple sequence of instructions
the base address of the shellcode (nil if unspecified)
the array of source elements (Instr/Data etc)
# File metasm/exe_format/shellcode.rb, line 85 def self.disassemble(cpu, str, eip=0) sc = decode(str, cpu) sc.disassemble(eip) end
# File metasm/exe_format/shellcode.rb, line 17 def initialize(cpu=nil, base_addr=nil) @base_addr = base_addr @source = [] super(cpu) end
returns a virtual subclass of Shellcode whose cpu_from_headers will return cpu
# File metasm/exe_format/shellcode.rb, line 108 def self.withcpu(cpu) c = Class.new(self) c.send(:define_method, :cpu_from_headers) { cpu = Metasm.const_get(cpu) if cpu.kind_of?(::String) cpu = cpu.new if cpu.kind_of?(::Class) and cpu.ancestors.include?(CPU) cpu } c end
# File metasm/exe_format/shellcode.rb, line 55 def addr_to_fileoff(addr) addr - (base_addr || 0) end
encodes the source found in self.source appends it to self.encoded clears self.source the optional parameter may contain a binding used to fixup! self.encoded uses self.base_addr if it exists
# File metasm/exe_format/shellcode.rb, line 68 def assemble(*a) parse(*a) if not a.empty? @encoded << assemble_sequence(@source, @cpu) @source.clear self end
# File metasm/exe_format/shellcode.rb, line 96 def compile_setsection(src, section) end
# File metasm/exe_format/shellcode.rb, line 82 def decode end
# File metasm/exe_format/shellcode.rb, line 99 def dump_section_header(addr, edata) '' end
# File metasm/exe_format/shellcode.rb, line 51 def each_section yield @encoded, (@base_addr || 0) end
# File metasm/exe_format/shellcode.rb, line 75 def encode(binding={}) @encoded.fixup! binding if binding.kind_of? Hash @encoded.fixup @encoded.binding(@base_addr) @encoded.fill @encoded.rawsize self end
# File metasm/exe_format/shellcode.rb, line 59 def fileoff_to_addr(foff) foff + (base_addr || 0) end
# File metasm/exe_format/shellcode.rb, line 103 def get_default_entrypoints [@base_addr || 0] end
# File metasm/exe_format/shellcode.rb, line 41 def get_section_at(addr) base = @base_addr || 0 if not addr.kind_of? Integer [@encoded, addr] if @encoded.ptr = @encoded.export[addr] elsif addr >= base and addr < base + @encoded.virtsize @encoded.ptr = addr - base [@encoded, addr] end end
# File metasm/exe_format/shellcode.rb, line 90 def init_disassembler d = super() d.function[:default] = @cpu.disassembler_default_func d end
# File metasm/exe_format/shellcode.rb, line 23 def parse_init @cursource = @source super() end
allows definition of the base address
# File metasm/exe_format/shellcode.rb, line 29 def parse_parser_instruction(instr) case instr.raw.downcase when '.base', '.baseaddr', '.base_addr' # ".base_addr <expression>" # expression should #reduce to integer @lexer.skip_space raise instr, 'syntax error' if not @base_addr = Expression.parse(@lexer).reduce raise instr, 'syntax error' if tok = @lexer.nexttok and tok.type != :eol else super(instr) end end