Skip to content

Instantly share code, notes, and snippets.

@Pipeliner
Last active December 15, 2015 09:18
Show Gist options
  • Save Pipeliner/5236873 to your computer and use it in GitHub Desktop.
Save Pipeliner/5236873 to your computer and use it in GitHub Desktop.
linux-0.2.img
x86-linux.log
wget http://wiki.qemu.org/download/linux-0.2.img.bz2
bunzip2 linux-0.2.img.bz2
#!/usr/bin/env ruby
require 'awesome_print'
lens = []
curlen = 0
prev_line = ""
opcodes = Hash.new(0)
open("x86-linux.log").read.lines do |line|
line.chomp!
if line =~ /^0x/
curlen += 1
elsif line == "IN: "
curlen = 0
elsif curlen != 0
lens << curlen
end
if line == ""
# last instruction of block
# alike "0xfffffff0: ljmp $0xf000,$0xe05b"
last_opcode = prev_line[13,7]
opcodes[last_opcode] += 1
#p prev_line if prev_line[13,7] == "mov "
end
prev_line = line
end
#p lens.length
#p lens.inject(:+)
#p lens.inject(:+) / (lens.length + 0.0)
opcodes_r = Hash[opcodes.map{|k, v| [v,k]}]
ap opcodes_r, :sort_keys => true
[ -r x86-linux.log ] || qemu -d in_asm -D x86-linux.log linux-0.2.img
./qemu_in_asm_parser.rb | sort -k1 -rn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment