# Path: coffSymbolEntries.py
# def attemptNameLookup(const,id):
#     """ Doesn't necessarily belong here but this avoids circular imports"""
#     return const.get(id, "UNDEF??[%0X]" % id)
# 
# class coffSymbolEntry:
#     def __init__(self,name="",value=0x0,sec=0x0,typ=0x0,cls=0x0,aux='',fullname=None):
#         self.Name = name
#         self.Value = value
#         self.SectionNumber = sec
#         self.Type = typ
#         self.StorageClass = cls
#         self.NumberAuxiliary = 0x0
#         self.Auxiliaries = aux
#         self.Location = 0
#         if fullname:
#             self.Fullname = fullname
#         else:
#             self.Fullname = name
# 
#     def InitFromFile(self,f):
#         self.Name = stringFromFile(8,f)
#         self.Value = ulongFromFile(f)
#         self.SectionNumber = shortFromFile(f)
#         self.Type = ushortFromFile(f)
#         self.StorageClass = ucharFromFile(f)
#         self.NumberAuxiliary = ucharFromFile(f)
#         self.Auxiliaries = ''
# 
#         for i in range(self.NumberAuxiliary):
#             aux = stringFromFile(18,f)
#             self.Auxiliaries += aux
# 
# 
#     def WriteToFile(self,f):
#         stringToFile(f, 8, self.Name)
#         ulongToFile(f, self.Value)
#         shortToFile(f, self.SectionNumber)
#         ushortToFile(f, self.Type)
#         ucharToFile(f, self.StorageClass)
#         ucharToFile(f, self.NumberAuxiliaries)
#         stringToFile(f, len(self.Auxiliaries), self.Auxiliaries)
# 
#     def SetSizes(self):
#         assert not len(self.Auxiliaries) % 18, "Invalid Aux length"
#         self.NumberAuxiliaries =  (len(self.Auxiliaries) // 18)
#         
#     def Rows(self):
#         self.SetSizes()
#         return self.NumberAuxiliaries + 1
# 
#     def DumpInfo(self):
#         print "%20s\t%10s\t%10s\t%10s\t%10s\t" % (repr(self.Name),
#                     attemptNameLookup(SymbolValues.NAME,self.Value),
#                     repr(self.SectionNumber),
#                     attemptNameLookup(SymbolTypes.NAME,self.Type),
#                     attemptNameLookup(SymbolClass.NAME,self.StorageClass))
#         tail = repr(self.Auxiliaries)
#         head,tail = tail[:70],tail[70:]
#         while head:
#             print "\t%s" % head
#             head,tail = tail[:70],tail[70:]


import logging, sys
from coffConst import *
from x86PackUnpack import *
from coffSymbolEntries import attemptNameLookup, coffSymbolEntry
        return 20

    def SetSizes(self):
        for sec in self.Sections:
            sec.SetSizes()
        self.NumberOfSections = len(self.Sections)
        self.SymbolCount = 0
        for sym in self.Symbols:
            sym.SetSizes()
            self.SymbolCount += sym.Rows()

    def SetOffsets(self):
        offset = self.Sizeof()
        offset += len(self.Sections) * 40
        i = 1
        for sec in self.Sections:
            tmpOffset = offset
            offset = sec.SetOffsets(offset)
            assert tmpOffset == sec.RawDataLoc, "section %s data out of sync" % i
            i += 1
        self.SymbolTableLoc = offset
        
    def AddSymbol(self,name="",value=0x0,sec=0x0,typ=0x0,cls=0x0,aux=''):
##        fullname = name
##        if len(name) > 8: #add name to symbol table and reference
##            if name[-1] != '\x00':
##                name += '\x00'
##            pos = len(self.StringTable) + 4
##            self.StringTable += name
##            name = '\x00\x00\x00\x00' + ulongToString(pos)        

# Path: coffSymbolEntries.py
# def attemptNameLookup(const,id):
#     """ Doesn't necessarily belong here but this avoids circular imports"""
#     return const.get(id, "UNDEF??[%0X]" % id)
# 
# class coffSymbolEntry:
#     def __init__(self,name="",value=0x0,sec=0x0,typ=0x0,cls=0x0,aux='',fullname=None):
#         self.Name = name
#         self.Value = value
#         self.SectionNumber = sec
#         self.Type = typ
#         self.StorageClass = cls
#         self.NumberAuxiliary = 0x0
#         self.Auxiliaries = aux
#         self.Location = 0
#         if fullname:
#             self.Fullname = fullname
#         else:
#             self.Fullname = name
# 
#     def InitFromFile(self,f):
#         self.Name = stringFromFile(8,f)
#         self.Value = ulongFromFile(f)
#         self.SectionNumber = shortFromFile(f)
#         self.Type = ushortFromFile(f)
#         self.StorageClass = ucharFromFile(f)
#         self.NumberAuxiliary = ucharFromFile(f)
#         self.Auxiliaries = ''
# 
#         for i in range(self.NumberAuxiliary):
#             aux = stringFromFile(18,f)
#             self.Auxiliaries += aux
# 
# 
#     def WriteToFile(self,f):
#         stringToFile(f, 8, self.Name)
#         ulongToFile(f, self.Value)
#         shortToFile(f, self.SectionNumber)
#         ushortToFile(f, self.Type)
#         ucharToFile(f, self.StorageClass)
#         ucharToFile(f, self.NumberAuxiliaries)
#         stringToFile(f, len(self.Auxiliaries), self.Auxiliaries)
# 
#     def SetSizes(self):
#         assert not len(self.Auxiliaries) % 18, "Invalid Aux length"
#         self.NumberAuxiliaries =  (len(self.Auxiliaries) // 18)
#         
#     def Rows(self):
#         self.SetSizes()
#         return self.NumberAuxiliaries + 1
# 
#     def DumpInfo(self):
#         print "%20s\t%10s\t%10s\t%10s\t%10s\t" % (repr(self.Name),
#                     attemptNameLookup(SymbolValues.NAME,self.Value),
#                     repr(self.SectionNumber),
#                     attemptNameLookup(SymbolTypes.NAME,self.Type),
#                     attemptNameLookup(SymbolClass.NAME,self.StorageClass))
#         tail = repr(self.Auxiliaries)
#         head,tail = tail[:70],tail[70:]
#         while head:
#             print "\t%s" % head
#             head,tail = tail[:70],tail[70:]


# Path: coff.py
import logging, sys
from coffConst import *
from x86PackUnpack import *
from coffSymbolEntries import attemptNameLookup, coffSymbolEntry

        return 20

    def SetSizes(self):
        for sec in self.Sections:
            sec.SetSizes()
        self.NumberOfSections = len(self.Sections)
        self.SymbolCount = 0
        for sym in self.Symbols:
            sym.SetSizes()
            self.SymbolCount += sym.Rows()

    def SetOffsets(self):
        offset = self.Sizeof()
        offset += len(self.Sections) * 40
        i = 1
        for sec in self.Sections:
            tmpOffset = offset
            offset = sec.SetOffsets(offset)
            assert tmpOffset == sec.RawDataLoc, "section %s data out of sync" % i
            i += 1
        self.SymbolTableLoc = offset
        
    def AddSymbol(self,name="",value=0x0,sec=0x0,typ=0x0,cls=0x0,aux=''):
##        fullname = name
##        if len(name) > 8: #add name to symbol table and reference
##            if name[-1] != '\x00':
##                name += '\x00'
##            pos = len(self.StringTable) + 4
##            self.StringTable += name
##            name = '\x00\x00\x00\x00' + ulongToString(pos)        

        self.AddExistingSymbol(coffSymbolEntry(name,value,sec,typ,cls,aux))#,fullname))