import sys
import os
import sre

class DisassSectionHEADERS:
	header = []
	table = []
	parent = None
	
	def __init__(self,filename,parent):
		self.parent = parent
		self.init(os.popen('objdump -h %s'%(filename)).readlines())
	
	def __str__(self):
		#return "".join(self.table)
		string = self.header[-1]
		for i in self.table:
			string += "%s"%(i.strip())
			if (i.find("**")>=0):
				string += "\t"
			else:
				string += "\n"
		return string

		
	def init(self,lines):
		self.header = lines[0:5]
		self.table = lines[5:]
		for line in self.table:
			parts = line.split()
			if (sre.search('^[0-9]', parts[0]) != None and len(parts)>3):
				#print >>sys.stderr,("SecHdrs: %s:%s" %(parts[3],parts[1]))
				self.parent.registerLookup(parts[3],parts[1])
		
	def printTXT(self,outfile=sys.stdout):
		print >>outfile,("\n\nSECTION HEADERS:")
		print >>outfile,(self)
