#!/usr/bin/perl


$binary=shift() || "/home/flip/download/linux-2.6.24.3-code_overlay/vmlinux";

# 3 characters per byte needed.
# I observed at least 24 bytes identical, so take a bit more.
$max_save=3*48; 

# With these additional parameters we get all bytes in the same line, not wrapped for long sequences.
open(HDL, "objdump --prefix-addresses --show-raw-insn -d $binary |") || die $!;
$hex="";
while(<HDL>)
{
	next unless ($adr, $name, $bytes, $instruction) = 
		(m/^
		 (\w+)			# Address
		 \s+
		 \<([\w+]+)\>		# Name+rel
		 \s+
		 (\w\w(?:\s\w\w)*)	# The bytes.
		 \s\s+			# at least two whitespace
		 (\w+)			# instruction
		 /x);  
	
	# We separate instructions.
	$hex .= "-".$bytes;
	# Restrict length
	$hex=substr($hex, -$max_save) if length($hex) > $max_save;

#	print STDERR "$instruction ... ", substr($hex, 0, 32),"\n" if $instruction;

# jmp is only valid for full adresses ... relative jumps don't work, do they?
	if (grep($_ eq $instruction, "ret", "ljmp", "iret") ||
			($instruction eq "jmp" && length($bytes) == 3*5) )
	{
# print last bytes; the block-border is after the last byte.
		print join(" ", $adr, $name, $instruction, $hex), "\n";
	}

#	last if $. > 1e6;
}


