# Path: x86inst.py
# class OpcodeTooShort(Exception):pass
# class OpcodeNeedsModRM(Exception):pass # for /d info and SIB calculation
# class x86instError(Exception):pass
# class OpcodeDict(dict):
# class MnemonicDict(dict):
# class ModRM:
# class instruction:
# class instructionInstance:
#     def __getitem__(self,key):
#     def __setitem__(self,key,value):
#     def GetOp(self,opcode,modRM=None):
#     def __setitem__(self,key,val):
# def longToBytes(long, bytes=4):
# def longToString(long, bytes=4):
# def longToBytesRepr(long,bytes=4):
#     def __init__(self,byte=None):
#     def LoadFromByte(self,byte):
#     def SaveToByte(self):
#     def HasSIB(self):
#     def RegOpString(self,typ):
#     def RMString(self,typ=None):
#     def GetDisplacementSize(self):
#     def __init__(self,opstr,inststr,desc):
#     def loadRBWD(self,plus,reg):
#     def setOpcodeAndFlags(self):
#     def setHasFlags(self):
#     def GetInstance(self):
#     def __str__(self):
#     def __init__(self,inst):
#     def GetSymbolPatchins(self,modrm=None):
#     def GetSuffixSize(self,modrm=None):
#     def GetInstructionSize(self):
#     def NextInstructionLoc(self):
#     def LoadData(self, data):
#     def DataText(self,data,size,skip=False):
#     def LoadConcreteValues(self, toks):
#     def OpDataAsString(self):
#     def OpText(self):
#             OS = self.OpcodeString
#             IS = self.InstructionString
#             ID = self.Description
#             OS = OS.replace(plus,plus[1:])
#             OS = OS.replace("%X" % self.Opcode[0], '%X' % (self.Opcode[0] + i))
#             IS = IS.replace(reg, regOpcode[reg][i])
# RELATIVE,DIRECT = range(1,3)


from pyasm.coff import (coffError, coffFile, coffSection, coffRelocationEntry,
                        coffSymbolEntry, coffLineNumberEntry)
from pyasm.coffConst import *
from pyasm.coffSymbolEntries import (coffSymbolFile, coffSectionDef, coffFunctionDef,
                                     coffBf, coffLf, coffEf)
from binascii import crc32
from x86inst import RELATIVE, DIRECT
import logging, time
        self.coff = c        
        
    def linkDirectiveSection(self):
        sect = coffSection()
        sect.Name = '.drectve'
        sect.Flags = (SectionFlags.LNK_REMOVE |
                    SectionFlags.LNK_INFO |
                    SectionFlags.ALIGN_1BYTES)
        sect.RawData = self.directives

        sym = self.coff.Symbols.GetSymbol('.drectve')
        sym.RebuildAuxiliaries(len(sect.RawData),0,0,crc32(sect.RawData),0,0)
        
        return sect

    def textSection(self):
        sect = coffSection()
        sect.Name = '.text\x00\x00\x00'
        sect.Flags = (SectionFlags.CNT_CODE |
                    SectionFlags.LNK_COMDAT |
                    SectionFlags.MEM_EXECUTE |
                    SectionFlags.MEM_READ |
                    SectionFlags.ALIGN_16BYTES)
        sect.RawData = self.cp.Code

        for patchin in self.cp.CodePatchins:
            # How do I tell what type it is?
            addr = patchin[1]
            if patchin[2] == DIRECT:
                patchinType = RelocationTypes.I386_DIR32

# Path: x86inst.py
# class OpcodeTooShort(Exception):pass
# class OpcodeNeedsModRM(Exception):pass # for /d info and SIB calculation
# class x86instError(Exception):pass
# class OpcodeDict(dict):
# class MnemonicDict(dict):
# class ModRM:
# class instruction:
# class instructionInstance:
#     def __getitem__(self,key):
#     def __setitem__(self,key,value):
#     def GetOp(self,opcode,modRM=None):
#     def __setitem__(self,key,val):
# def longToBytes(long, bytes=4):
# def longToString(long, bytes=4):
# def longToBytesRepr(long,bytes=4):
#     def __init__(self,byte=None):
#     def LoadFromByte(self,byte):
#     def SaveToByte(self):
#     def HasSIB(self):
#     def RegOpString(self,typ):
#     def RMString(self,typ=None):
#     def GetDisplacementSize(self):
#     def __init__(self,opstr,inststr,desc):
#     def loadRBWD(self,plus,reg):
#     def setOpcodeAndFlags(self):
#     def setHasFlags(self):
#     def GetInstance(self):
#     def __str__(self):
#     def __init__(self,inst):
#     def GetSymbolPatchins(self,modrm=None):
#     def GetSuffixSize(self,modrm=None):
#     def GetInstructionSize(self):
#     def NextInstructionLoc(self):
#     def LoadData(self, data):
#     def DataText(self,data,size,skip=False):
#     def LoadConcreteValues(self, toks):
#     def OpDataAsString(self):
#     def OpText(self):
#             OS = self.OpcodeString
#             IS = self.InstructionString
#             ID = self.Description
#             OS = OS.replace(plus,plus[1:])
#             OS = OS.replace("%X" % self.Opcode[0], '%X' % (self.Opcode[0] + i))
#             IS = IS.replace(reg, regOpcode[reg][i])
# RELATIVE,DIRECT = range(1,3)


# Path: x86cpToCoff.py
from pyasm.coff import (coffError, coffFile, coffSection, coffRelocationEntry,
                        coffSymbolEntry, coffLineNumberEntry)
from pyasm.coffConst import *
from pyasm.coffSymbolEntries import (coffSymbolFile, coffSectionDef, coffFunctionDef,
                                     coffBf, coffLf, coffEf)
from binascii import crc32
from x86inst import RELATIVE, DIRECT
import logging, time

        self.coff = c        
        
    def linkDirectiveSection(self):
        sect = coffSection()
        sect.Name = '.drectve'
        sect.Flags = (SectionFlags.LNK_REMOVE |
                    SectionFlags.LNK_INFO |
                    SectionFlags.ALIGN_1BYTES)
        sect.RawData = self.directives

        sym = self.coff.Symbols.GetSymbol('.drectve')
        sym.RebuildAuxiliaries(len(sect.RawData),0,0,crc32(sect.RawData),0,0)
        
        return sect

    def textSection(self):
        sect = coffSection()
        sect.Name = '.text\x00\x00\x00'
        sect.Flags = (SectionFlags.CNT_CODE |
                    SectionFlags.LNK_COMDAT |
                    SectionFlags.MEM_EXECUTE |
                    SectionFlags.MEM_READ |
                    SectionFlags.ALIGN_16BYTES)
        sect.RawData = self.cp.Code

        for patchin in self.cp.CodePatchins:
            # How do I tell what type it is?
            addr = patchin[1]
            if patchin[2] == DIRECT:
                patchinType = RelocationTypes.I386_DIR32

            elif patchin[2] == RELATIVE: