Sha256: 34f0ca8a4e54197a856a9ad98242d3b07327d930d9eb72841583a670827fbf4a

Contents?: true

Size: 751 Bytes

Versions: 6

Compression:

Stored size: 751 Bytes

Contents

#!/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 = Metasm::Shellcode.new(Metasm::Ia32.new)
sc.parse <<EOS
jmp c_func

some_func:
mov eax, 42
ret
EOS

cp = sc.cpu.new_cparser
cp.parse <<EOS
void some_func(void);
/* __declspec(naked) */ void c_func() {
	int i;
	for (i=0 ; i<10 ; ++i)
		some_func();
}
EOS
asm = sc.cpu.new_ccompiler(cp, sc).compile

sc.parse asm
sc.assemble

sc.encode_file 'shellcode.raw'

puts Metasm::Shellcode.load_file('shellcode.raw', Metasm::Ia32.new).disassemble

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metasm-1.0.5 samples/shellcode-c.rb
metasm-1.0.4 samples/shellcode-c.rb
metasm-1.0.3 samples/shellcode-c.rb
metasm-1.0.2 samples/shellcode-c.rb
metasm-1.0.1 samples/shellcode-c.rb
metasm-1.0.0 samples/shellcode-c.rb