-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathtestraw.rb
45 lines (33 loc) · 842 Bytes
/
testraw.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
#!/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.new
shellcode = Metasm::Shellcode.assemble(cpu, source).encode_string
shellstring = shellcode.unpack('C*').map { |b| '\\x%02x' % b }.join
if dump
puts shellstring
exit
end
File.open('test-testraw.c', 'w') { |fd|
fd.puts <<EOS
unsigned char sc[] = "#{shellstring}";
int main(void)
{
((void (*)())sc)();
return 42;
}
EOS
}
system 'gcc -W -Wall -o test-testraw test-testraw.c'
system 'chpax -psm test-testraw'
puts "running"
system './test-testraw'
puts "done"
#File.unlink 'test-testraw'
File.unlink 'test-testraw.c'