code
stringlengths
1
1.73M
language
stringclasses
1 value
# 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 require 'gtk2' module Metasm module Gui module Protect @@lasterror = Time.now def protect yield rescue Object puts $!.message, $!.ba...
Ruby
# 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 require 'metasm/dynldr' module Metasm module Gui class XGui < DynLdr new_api_c <<EOS, 'libX11.so' #define KeyPressMask (1...
Ruby
# 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 require 'metasm/dynldr' module Metasm module Gui class Win32Gui < DynLdr new_api_c <<EOS #line #{__LINE__} typedef char CHAR; typedef unsign...
Ruby
# 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 module Gui class CStructWidget < DrawableWidget attr_accessor :dasm, :view_x, :view_y def initialize_widget(dasm, parent_widg...
Ruby
# 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 module Gui class HexWidget < DrawableWidget # data_size = size of data in bytes (1 => chars, 4 => dwords..) # line_size = nr o...
Ruby
# 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 module Gui class AsmListingWidget < DrawableWidget attr_accessor :dasm, :arrow_zone_w # nr of raw bytes to display next to eac...
Ruby
# 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 module Gui class CoverageWidget < DrawableWidget attr_accessor :dasm, :sections, :pixel_w, :pixel_h # TODO wheel -> zoom, dra...
Ruby
# 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 require 'Qt4' module Metasm module Gui module Protect @@lasterror = Time.now def protect yield rescue Object puts $!.message, $!.bac...
Ruby
# 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 require 'metasm/main' module Metasm class ExeFormat # encodes an Array of source (Label/Data/Instruction etc) to an EncodedData # resolves...
Ruby
# 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 require 'metasm/main' module Metasm # A source text preprocessor (C-like) # defines the methods nexttok, readtok and unreadtok # they spits...
Ruby
# 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 require 'metasm/main' require 'metasm/preprocessor' module Metasm class Data # keywords for data definition (used to recognize label names)...
Ruby
# 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 VERSION = 0x0001 # major major minor minor # superclass for all metasm exceptions class Exception < RuntimeError ; end # pars...
Ruby
backend = ENV['METASM_GUI'] || ( if RUBY_PLATFORM =~ /(i.86|x(86_)?64)-(mswin|mingw|cygwin)/i 'win32' else begin require 'gtk2' 'gtk' rescue LoadError raise LoadError, 'No GUI ruby binding installed - please install libgtk2-ruby' end end ) require "metasm/gui/#{backend}"
Ruby
# 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 require 'metasm/main' require 'metasm/preprocessor' module Metasm # c parser # inspired from http://www.math.grin.edu/~stone/courses/languag...
Ruby
# 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(...
Ruby
# 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 require 'test/unit' require 'metasm' class TestPreproc < Test::Unit::TestCase include Metasm def asm_dasm(src) @cpu ||= Ia32.new raw ...
Ruby
# 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 require 'test/unit' require 'metasm' class TestMips < Test::Unit::TestCase def test_enc sc = Metasm::Shellcode.assemble(Metasm::MIPS.new(...
Ruby
# 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 require 'test/unit' require 'metasm' class TestX86_64 < Test::Unit::TestCase @@cpu = Metasm::X86_64.new def assemble(src, cpu=@@cpu) Met...
Ruby
# 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 require 'test/unit' require 'metasm' class TestArc < Test::Unit::TestCase def test_arc_dec hex_stream = "\x0A\x23\x80\x0F\x80\x...
Ruby
# 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 Dir['tests/*.rb'].sort.each { |f| require f }
Ruby
# 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 require 'test/unit' require 'metasm/exe_format/shellcode' class TestEncodedData < Test::Unit::TestCase def compile(src) p = Metasm::Shell...
Ruby
# 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 require 'test/unit' require 'metasm' class TestDynldr < Test::Unit::TestCase def d; Metasm::DynLdr; end def test_new_api_c str = "1234" ...
Ruby
# 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 require 'test/unit' require 'metasm' class TestIa32 < Test::Unit::TestCase @@cpu32 = Metasm::Ia32.new @@cpu16 = Metasm::Ia32.new(16) def ...
Ruby
# 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 require 'test/unit' require 'metasm/preprocessor' require 'metasm/parse' # BEWARE OF TEH RUBY PARSER # use single-quoted source strings cla...
Ruby
# 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 # special file to test the graph layout engine # call this file directly to run require 'metasm' include Metasm def test_layout(lo) $cur |...
Ruby
# 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 require 'test/unit' require 'metasm' class TestDynldr < Test::Unit::TestCase def cp @cp ||= Metasm::Ia32.new.new_cparser end def test_p...
Ruby
# 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 require 'test/unit' require 'metasm' class TestExpression < Test::Unit::TestCase E = Metasm::Expression def test_encode assert_equal("\x...
Ruby
# 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 # # This exemple illustrates the usage of the C parser to compute the offset of members of a given structure # usage: struct_offset.rb <c file...
Ruby
# 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 # metasm dasm plugin # walks all disassembled instructions referencing an address # if this address points a C string, show that in the instr...
Ruby
# 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 # metasm gui plugin: change the colortheme used in the GUI # based on solarized: http://ethanschoonover.com/solarized/ if gui solarized = {...
Ruby
# 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 # metasm dasm plugin # decompose immediate values from C constants, adds a comment with the decomposition # find immediate exprs in the inst...
Ruby
# 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 # metasm dasm plugin # finds instances of indirect calls a la call [ecx+40h], backtraces ecx, comments with the C++ object function pointer n...
Ruby
# 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 # # To use your own patterns, create a script that defines Deobfuscate::Patterns, then eval() this file. # Use your script as argument to --p...
Ruby
# 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 # # This plugin will create a monitoring process running samples/hotfix_gtk_dbg.rb on the current process (to fix a GTK crash when closing a ...
Ruby
# 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 # metasm dasm plugin: create a function to export the currently displayed # dasm graph to a .svg file # in the gui, type E to export. Tested ...
Ruby
# This file is part of Metasm, the Ruby assembly manipulation suite # Copyright (C) 2006-2011 Yoann GUILLOT # # Licence is LGPL, see LICENCE in the top-level directory # metasm dasm plugin # scan for a given asm instruction sequence (all encodings) # add the G dasm-gui shortcut, the input change ';' for line...
Ruby
# 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 # metasm dasm plugin: asks to load a second program, and unleash the samples/bindiff fury # usage: load the plugin, and a 2nd binary, disassem...
Ruby
# 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 # metasm dasm GUI plugin: hilight lines of code based on the opcode name if gui @gui_opcode_color = { :call => :green_bg, :jmp => :red_...
Ruby
# 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 # metasm dasm plugin: allow loading library signature files (see samples/generate_libsigs.rb) class LibSignature attr_accessor :sigs, :sigle...
Ruby
# 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 # metasm dasm GUI plugin: # pops a list of bookmarked functions # also allows the custom coloration of blocks/functions if gui class Color...
Ruby
# 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 # metasm dasm plugin: try to demangle all labels as c++ names, add them as # comment if successful def demangle_all_cppnames cnt = 0 prog_...
Ruby
# 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 # metasm dasm plugin: scan for xrefs to the target address, incl. relative offsets (eg near call/jmp) def scanxrefs(target) ans = [] sectio...
Ruby
# 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 # metasm dasm GUI plugin: dumps the text of the current widget to a text file on 'D' keypress # the dump is appended to the file if it exists...
Ruby
# 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 # metasm dasm plugin: allow patching the file from the dasm interface # use P to assemble a new instruction at the current address # backup ...
Ruby
# 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 # metasm dasm plugin: retrieve a section section, and disassemble everything it can, skipping existing code and nops # usage: load the plugin...
Ruby
# 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 # metasm dasm plugin # walks all disassembled instructions referencing an address # if the address is a label, update the instruction to use ...
Ruby
# 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 # # This file tries to handle simple self-modifying code patterns # To be used as a --plugin for a Disassembler object # module SMC # a cop...
Ruby
# 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 # metasm dasm plugin: scan the memory for a 'ret' which could indicate the beginning of the current function # (x86 only) def scanfuncstart(a...
Ruby
# 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 # # this script takes a list of dll filenames as arguments, and outputs each lib export # libname, followed by the list of the exported symbol...
Ruby
#!/usr/bin/env ruby # 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 # # this sample shows how to compile an executable file from source # use --exe PE to compile a PE/ELF/MachO etc # use --c...
Ruby
#!/usr/bin/env ruby # 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 # # in this file, we open an existing PE, add some code to its last section and # patch the entrypoint so that we are exe...
Ruby
#!/usr/bin/env ruby # 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 # # quick demonstration that the disassembler's backtracker works # require 'metasm' Metasm.require 'samples/metasm-shel...
Ruby
#!/usr/bin/env ruby # 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 require 'metasm' $opts = { :execlass => Metasm::MachO } load File.join(File.dirname(__FILE__), 'exeencode.rb') __END__ ....
Ruby
# 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 # This creates/uses a ring0 driver for tracing a program # x86/windows/singlecore only # the scripts allows interacting with the driver # you ...
Ruby
# 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 # # this script scans a directory for PE files which export a given symbol name (regexp case-insensitive) # usage : ruby scanpeexports.rb <di...
Ruby
# 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 # a preleminary attempt to use MS dbghelp.dll to retrieve PE symbols require 'metasm' dll = 'C:\\Program Files\\Debugging Tools For Windows ...
Ruby
# 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 # # here we build a simple a.out executable # require 'metasm' Metasm::AOut.assemble(Metasm::Ia32.new, <<EOS).encode_file('m-a.out') .text ....
Ruby
# This file is part of Metasm, the Ruby assembly manipulation suite # Copyright (C) 2006-2009 Yoann GUILLOT # Original script and idea by Alexandre GAZET # # Licence is LGPL, see LICENCE in the top-level directory # # this script will load an upx-packed windows executable, find its # original entrypoint ...
Ruby
#!/usr/bin/env ruby # 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 # # this file takes preprocessor files as arguments # it preprocesses their content and dump the result to stdout # it als...
Ruby
# 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 # # this is a linux/x86 debugger with a console interface # require 'metasm' module Ansi CursHome = "\e[H".freeze ClearLineAfter = "\e[0K...
Ruby
#!/usr/bin/env ruby # 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 # # here we assemble a dummy MIPS PE # TODO autodetect header.machine from cpu, find something to put in # the MZ header, ...
Ruby
#!/usr/bin/env ruby # 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 require 'metasm' $opts = { :execlass => Metasm::PE, :srctype_data => 'c' } load File.join(File.dirname(__FILE__), 'exeenc...
Ruby
# # 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 # this file sets up the RUBYLIB environment variable for windows hosts # the variable is set for the current user only # the user session ma...
Ruby
# 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 # This samples generates a binary loader that will load and patch a Win32 program in memory # The patch data are read from assembly files name...
Ruby
#!/usr/bin/ruby # 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 # # this exemple illustrates the use of the PTrace class to hijack a syscall in a running process # the next syscall made is ...
Ruby
# 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 # # here we will build an executable file that will shut down the machine # when run # the header part comes from the factorize sample script...
Ruby
# 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 # # This script takes a C header or a path to a Visual Studio install and # outputs a ruby source file defining StackOffsets, a hash used by ...
Ruby
# 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 # This sample hacks in the ruby interpreter to allow dynamic loading of shellcodes as object methods # Also it allows raw modifications to the...
Ruby
# 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 # # this exemple illustrates the use of the cparser/preprocessor #factorize functionnality: # it generates code that references to the functio...
Ruby
# 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 # # this exemple illustrates the use of the cparser/preprocessor #factorize functionnality: # it generates code that references to the functio...
Ruby
#!/usr/bin/env ruby # 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 # # in this exemple we can write a shellcode using a C function # require 'metasm' # load and decode the file sc = Meta...
Ruby
#!/usr/bin/env ruby # 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 # # this script reads a list of elf files, and lists its dependencies recursively # libraries are searched in LD_LIBRARY_...
Ruby
# 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 require 'metasm' Metasm.require 'samples/metasm-shell' include Metasm # open target WinOS.get_debug_privilege if not pr = WinOS.find_proces...
Ruby
# 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 # # This sample defines an ApiHook class, that you can subclass to easily hook functions # in a debugged process. Your custom function will g...
Ruby
# 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 # # this sample script fixes a bug in some GTK libs (eg debian) where at some point # when you close a window an invalid memory dereference i...
Ruby
#!/usr/bin/env ruby # 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 # usage: test.rb < source.asm require 'metasm' dump = ARGV.delete '--dump' source = ARGF.read cpu = Metasm::Ia32.ne...
Ruby
#!/usr/bin/env ruby # 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 # # this script disassembles an executable (elf/pe) and dumps the output # ruby -h for help # require 'metasm' include M...
Ruby
# 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 # # in this exemple we will patch a process specified on the commandline (pid or part of the image name) # we will retrieve the user32.dll li...
Ruby
# 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 # this script compiles a source file (asm or C) into a shellcode that will # dynamically resolve the address of functions it uses # windows on...
Ruby
# 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 # metasm debugger plugin # adds some heap_* functions to interract with the target heap chunks # functions: # heap_scan, scan for malloc chu...
Ruby
# 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 # metasm debugger plugin # adds a 'trace_func' method to the debugger # the methods sets a breakpoint at the beginning of a function, and log...
Ruby
# 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 module Gui class GraphHeapWidget < GraphViewWidget attr_accessor :heap, :addr_struct, :snapped # addr_struct = 0x234 => Allo...
Ruby
# 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 class Heap attr_accessor :vm, :range, :ptsz attr_accessor :cp # hash chunk userdata pointer -> chunk userdata size attr_acc...
Ruby
#!/usr/bin/env ruby # 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 require 'metasm' $opts = { :execlass => Metasm::ELF, :exetype => :lib } load File.join(File.dirname(__FILE__), 'exeencode...
Ruby
#!/usr/bin/env ruby # 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 # # compiles a PE file with the specified resource directory # TODO build an icon or something # require 'metasm' pe = ...
Ruby
# 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 # shows the compilation phase step by step: c, simplified c, asm require 'metasm' require 'optparse' opts = { :cpu => 'Ia32', :exe => 'Shell...
Ruby
#!/usr/bin/env ruby # 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 # modifies the standard ruby class String to add #decode and #encode methods # they will respectively disassemble binary d...
Ruby
# 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 # # this exemple illustrates the use of the cparser/preprocessor #factorize functionnality: # we write some code using standard headers, and t...
Ruby
#!/usr/bin/env ruby # 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 # # in this sample we compile 2 PE files, one executable and one dll # with the same base address, to check if the base r...
Ruby
#!/usr/bin/env ruby # 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 # This sample implements a trivial binary diffing algorithm between two programs # the programs have first to be disassem...
Ruby
# 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 # this generates a signature file for all function in the given library # usage: gensigs.rb some_lib.a somefile.o somelib.lib > mylib.fsigs # ...
Ruby
# 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 # here we compile and inject a C stub into a running process # the sample stub will scan the whole process memory for a 32bit value (aligned) ...
Ruby
# 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 # # this script takes a list of dll filenames as arguments, and outputs each lib export # libname, followed by the list of the exported symbol...
Ruby
# 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 # # in this exemple we will patch a process specified on the commandline (pid or part of image name) # the IAT entry matching /WriteFile/ wil...
Ruby
#!/usr/bin/env ruby # 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 # # a sample application # require 'metasm' pe = Metasm::PE.assemble Metasm::Ia32.new, <<EOS .entrypoint push 0 push t...
Ruby
#!/usr/bin/env ruby # 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 # # this script scans directories recursively for ELF files which have a PT_GNU_STACK rwe or absent # usage : scan_pt_gnu...
Ruby
# 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 # # this is a simple executable tracer for Windows using the # Metasm windows debug api abstraction # all callbacks are full ruby, so this is...
Ruby
# 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 # # Map a PE file under another OS using DynLdr, API imports are redirected to ruby callback for emulation # require 'metasm' class PeLdr a...
Ruby
#!/usr/bin/env ruby # 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 # # this sample shows the compilation of a slightly more complex program # it displays in a messagebox the result of CPUI...
Ruby
# 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 # # this is a little script to navigate in a disassembler dump # # copypasted from lindebug.rb module Ansi CursHome = "\e[H".freeze ClearLi...
Ruby