# Path: awake/address.py
# BANK_SIZE = 0x4000
# class BadAddressException(Exception):
# class Address(object):
#     def __init__(self, addr):
#     def __str__(self):
# def fromVirtual(virtual):
# def fromVirtualAndBank(virtual, bank):
# def fromVirtualAndCurrent(virtual, current):
# def fromPhysical(physical):
# def fromConventional(conventional):
#     def __init__(self, address):
#     def virtual(self):
#     def bank(self):
#     def isAmbiguous(self):
#     def inBankedSpace(self):
#     def inPhysicalMem(self):
#     def physical(self):
#     def offset(self, offset):
#     def withBankSpecified(self, bank):
#     def __lt__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def __repr__(self):
# 
# Path: awake/depend.py
# def decodeDependencySet(text):
#     if not text:
#         return DependencySet()
#     r, w = text.split("->")
#     reads = set(x.strip() for x in r.split(","))
#     writes = set(x.strip() for x in w.split(","))
#     return DependencySet(splitRegisters(reads), splitRegisters(writes))
# 
# def encodeDependencySet(depset):
#     return ", ".join(str(x) for x in joinRegisters(depset.reads)) + " -> " + ", ".join(str(x) for x in joinRegisters(depset.writes))
# 
# def unknownDependencySet():
#     return DependencySet(ALL_REGS - set(['FZ', 'FC', 'FN', 'FH']), ALL_REGS - set(['ROMBANK']))
# 
# Path: awake/operand.py
# class ProcAddress(AddressConstant):
#     link_prefix = "/proc/"
#     html_class = "proc-addr"
# 
# Path: awake/textrenderer.py
# class HtmlRenderer(Renderer):
#     def __init__(self, database):
#         super(HtmlRenderer, self).__init__(database)
#         self.content = []
# 
#     def getContents(self):
#         return '<pre>' + (''.join(self.content)) + '</pre>'
# 
#     def _add(self, text, klass=None, url=None):
#         text = str(text)
#         if klass:
#             text = '<span class="{1}">{0}</span>'.format(text, klass)
#         if url:
#             text = '<a href="{1}">{0}</a>'.format(text, url)
#         self.content.append(text)


import sqlite3
        import Image
from contextlib import closing
from awake import address
from awake.depend import decodeDependencySet, encodeDependencySet, unknownDependencySet
from awake.operand import ProcAddress
from awake.textrenderer import HtmlRenderer

sqlite3.register_converter('address', convert_address)
sqlite3.register_adapter(address.Address, adapt_address)

def getFirst(x, alt=None):
    if x:
        return x[0]
    else:
        return alt

class ProcInfo(object):
    def __init__(self, connection, addr, result=None):

        c = connection.cursor()
        c.execute('select type, depset, has_switch, suspicious_switch, has_suspicious_instr, has_nop, has_ambig_calls, length from procs where addr=?', (addr,))
        assert c.rowcount <= 1
        result = c.fetchone()

        self.addr = addr
        if result:
            self.type = result[0]
            self.depset = decodeDependencySet(result[1])
            self.has_switch = result[2]
            self.suspicious_switch = result[3]
            self.has_suspicious_instr = result[4]
            self.has_nop = result[5]
            self.has_ambig_calls = result[6]
            self.length = result[7]
        else:
            self.type = "proc"

# Path: awake/address.py
# BANK_SIZE = 0x4000
# class BadAddressException(Exception):
# class Address(object):
#     def __init__(self, addr):
#     def __str__(self):
# def fromVirtual(virtual):
# def fromVirtualAndBank(virtual, bank):
# def fromVirtualAndCurrent(virtual, current):
# def fromPhysical(physical):
# def fromConventional(conventional):
#     def __init__(self, address):
#     def virtual(self):
#     def bank(self):
#     def isAmbiguous(self):
#     def inBankedSpace(self):
#     def inPhysicalMem(self):
#     def physical(self):
#     def offset(self, offset):
#     def withBankSpecified(self, bank):
#     def __lt__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def __repr__(self):
# 
# Path: awake/depend.py
# def decodeDependencySet(text):
#     if not text:
#         return DependencySet()
#     r, w = text.split("->")
#     reads = set(x.strip() for x in r.split(","))
#     writes = set(x.strip() for x in w.split(","))
#     return DependencySet(splitRegisters(reads), splitRegisters(writes))
# 
# def encodeDependencySet(depset):
#     return ", ".join(str(x) for x in joinRegisters(depset.reads)) + " -> " + ", ".join(str(x) for x in joinRegisters(depset.writes))
# 
# def unknownDependencySet():
#     return DependencySet(ALL_REGS - set(['FZ', 'FC', 'FN', 'FH']), ALL_REGS - set(['ROMBANK']))
# 
# Path: awake/operand.py
# class ProcAddress(AddressConstant):
#     link_prefix = "/proc/"
#     html_class = "proc-addr"
# 
# Path: awake/textrenderer.py
# class HtmlRenderer(Renderer):
#     def __init__(self, database):
#         super(HtmlRenderer, self).__init__(database)
#         self.content = []
# 
#     def getContents(self):
#         return '<pre>' + (''.join(self.content)) + '</pre>'
# 
#     def _add(self, text, klass=None, url=None):
#         text = str(text)
#         if klass:
#             text = '<span class="{1}">{0}</span>'.format(text, klass)
#         if url:
#             text = '<a href="{1}">{0}</a>'.format(text, url)
#         self.content.append(text)


# Path: awake/database.py
import sqlite3
        import Image
from contextlib import closing
from awake import address
from awake.depend import decodeDependencySet, encodeDependencySet, unknownDependencySet
from awake.operand import ProcAddress
from awake.textrenderer import HtmlRenderer


sqlite3.register_converter('address', convert_address)
sqlite3.register_adapter(address.Address, adapt_address)

def getFirst(x, alt=None):
    if x:
        return x[0]
    else:
        return alt

class ProcInfo(object):
    def __init__(self, connection, addr, result=None):

        c = connection.cursor()
        c.execute('select type, depset, has_switch, suspicious_switch, has_suspicious_instr, has_nop, has_ambig_calls, length from procs where addr=?', (addr,))
        assert c.rowcount <= 1
        result = c.fetchone()

        self.addr = addr
        if result:
            self.type = result[0]
            self.depset = decodeDependencySet(result[1])
            self.has_switch = result[2]
            self.suspicious_switch = result[3]
            self.has_suspicious_instr = result[4]
            self.has_nop = result[5]
            self.has_ambig_calls = result[6]
            self.length = result[7]
        else:
            self.type = "proc"

            self.depset = unknownDependencySet()