Esempio n. 1
1
def pragmaIncbin(ppt, line, result):
    "Includes a binary file"
    filename = line.expect("STRING").value
    offset = IR.ConstantExpr(0)
    size = None
    if str(line.lookahead(0)) == ",":
        line.pop()
        offset = FE.parse_expr(line)
        if str(line.lookahead(0)) == ",":
            line.pop()
            size = FE.parse_expr(line)
    line.expect("EOL")
    if type(filename) == str:
        try:
            f = file(os.path.join(FE.context_directory, filename), "rb")
            if offset.hardcoded and (size is None or size.hardcoded):
                # We know how big it will be, we can just use the values.
                # First check to make sure they're sane
                if offset.value() < 0:
                    Err.log("Offset may not be negative")
                    f.close()
                    return
                f.seek(0, 2)  # Seek to end of file
                if offset.value() > f.tell():
                    Err.log("Offset runs past end of file")
                    f.close()
                    return
                if size is not None:
                    if size.value() < 0:
                        Err.log("Length may not be negative")
                        f.close()
                        return
                    if offset.value() + size.value() > f.tell():
                        Err.log(".incbin length too long")
                        f.close()
                        return
                if size is None:
                    size = IR.ConstantExpr(-1)
                f.seek(offset.value())
                bytes = f.read(size.value())
                bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
                result.append(IR.Node(ppt, "Byte", *bytes))
            else:
                # offset or length could change based on label placement.
                # This seems like an unbelievably bad idea, but since we
                # don't have constant prop it will happen for any symbolic
                # alias. Don't use symbolic aliases when extracting tiny
                # pieces out of humongous files, I guess.
                bytes = f.read()
                bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
                if size is None:
                    size = IR.SequenceExpr([IR.ConstantExpr(len(bytes)),
                                            "-",
                                            offset])
                result.append(IR.Node(ppt, "ByteRange", offset, size, *bytes))
            f.close()
        except IOError:
            Err.log("Could not read " + filename)
            return
Esempio n. 2
0
def main():
    # runs Front End over 3 transaction sessions
    number_of_transaction_sessions = 3
    # save the output Transaction Summary File for each session in a separate file
    for i in range(number_of_transaction_sessions):
        sys.argv = [
            'Frontend.py', 'ValidAccountListFile.txt',
            'DailySession/TransactionSummaryFile' + str(i + 1) + '.txt'
        ]
        Frontend.main()

    # concatenates the separate Transaction Summary Files into a Merged Transaction Summary file
    files = os.listdir("DailySession/")
    with open('TransactionSummaryFile.txt', 'w') as result:
        for f in files:
            for line in open("DailySession/" + f, 'r'):
                if "EOS" not in line:
                    result.write(line)
        result.write("EOS 0000000 000 0000000 ***\n")
        result.close()

    # remove separate Transaction Summary Files
    file = os.listdir("DailySession/")
    for i in file:
        os.remove("DailySession/" + i)

    # runs your Back Office with the Merged Transaction Summary File as input
    sys.argv = [
        'Backend.py', 'MasterAccountsFile.txt', 'TransactionSummaryFile.txt'
    ]
    Backend.main()
Esempio n. 3
0
def pragmaIncbin(ppt, line, result):
    "Includes a binary file"
    filename = line.expect("STRING").value
    offset = IR.ConstantExpr(0)
    size = None
    if str(line.lookahead(0)) == ",":
        line.pop()
        offset = FE.parse_expr(line)
        if str(line.lookahead(0)) == ",":
            line.pop()
            size = FE.parse_expr(line)
    line.expect("EOL")
    if type(filename) == str:
        try:
            f = file(os.path.join(FE.context_directory, filename), "rb")
            if offset.hardcoded and (size is None or size.hardcoded):
                # We know how big it will be, we can just use the values.
                # First check to make sure they're sane
                if offset.value() < 0:
                    Err.log("Offset may not be negative")
                    f.close()
                    return
                f.seek(0, 2)  # Seek to end of file
                if offset.value() > f.tell():
                    Err.log("Offset runs past end of file")
                    f.close()
                    return
                if size is not None:
                    if size.value() < 0:
                        Err.log("Length may not be negative")
                        f.close()
                        return
                    if offset.value() + size.value() > f.tell():
                        Err.log(".incbin length too long")
                        f.close()
                        return
                if size is None:
                    size = IR.ConstantExpr(-1)
                f.seek(offset.value())
                bytes = f.read(size.value())
                bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
                result.append(IR.Node(ppt, "Byte", *bytes))
            else:
                # offset or length could change based on label placement.
                # This seems like an unbelievably bad idea, but since we
                # don't have constant prop it will happen for any symbolic
                # alias. Don't use symbolic aliases when extracting tiny
                # pieces out of humongous files, I guess.
                bytes = f.read()
                bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
                if size is None:
                    size = IR.SequenceExpr(
                        [IR.ConstantExpr(len(bytes)), "-", offset])
                result.append(IR.Node(ppt, "ByteRange", offset, size, *bytes))
            f.close()
        except IOError:
            Err.log("Could not read " + filename)
            return
Esempio n. 4
0
def pragmaAdvance(ppt, line, result):
    "Outputs filler until reaching the target PC"
    newPC = FE.parse_expr(line)
    if str(line.lookahead(0)) == ",":
        line.pop()
        fillexpr = FE.parse_expr(line)
    else:
        fillexpr = IR.ConstantExpr(0)
    line.expect("EOL")
    result.append(IR.Node(ppt, "Advance", newPC, fillexpr))
Esempio n. 5
0
def pragmaAdvance(ppt, line, result):
    "Outputs filler until reaching the target PC"
    newPC = FE.parse_expr(line)
    if str(line.lookahead(0)) == ",":
        line.pop()
        fillexpr = FE.parse_expr(line)
    else:
        fillexpr = IR.ConstantExpr(0)
    line.expect("EOL")
    result.append(IR.Node(ppt, "Advance", newPC, fillexpr))
Esempio n. 6
0
def readData(line):
    "Read raw data from a comma-separated list"
    if line.lookahead(0).type == "STRING":
        data = [IR.ConstantExpr(ord(x))
                for x in line.expect("STRING").value.translate(currentcharmap)]
    else:
        data = [FE.parse_expr(line)]
    next = line.expect(',', 'EOL').type
    while next == ',':
        if line.lookahead(0).type == "STRING":
            data.extend([IR.ConstantExpr(ord(x))
                         for x in line.expect("STRING").value])
        else:
            data.append(FE.parse_expr(line))
        next = line.expect(',', 'EOL').type
    return data
Esempio n. 7
0
def readData(line):
    "Read raw data from a comma-separated list"
    if line.lookahead(0).type == "STRING":
        data = [
            IR.ConstantExpr(ord(x))
            for x in line.expect("STRING").value.translate(currentcharmap)
        ]
    else:
        data = [FE.parse_expr(line)]
    next = line.expect(',', 'EOL').type
    while next == ',':
        if line.lookahead(0).type == "STRING":
            data.extend(
                [IR.ConstantExpr(ord(x)) for x in line.expect("STRING").value])
        else:
            data.append(FE.parse_expr(line))
        next = line.expect(',', 'EOL').type
    return data
Esempio n. 8
0
def OnEnable(**kwargs):
    args = []

    for conf in ['Server', 'Port', 'Name', 'NamePass', 'Chan']:
        item = kwargs["conf"]['IRC.' + conf]

        if item == None:
            Severe('No IRC.' + conf + ' in config')

            raise Exception('No IRC.' + conf + ' in config')

        args.append(item)

    Frontend.Init(*args)
Esempio n. 9
0
def OnDisable(**kwargs):
    Frontend.Terminate()
Esempio n. 10
0
def pragmaOrg(ppt, line, result):
    "Relocates the PC with no output"
    newPC = FE.parse_expr(line)
    line.expect("EOL")
    result.append(IR.Node(ppt, "SetPC", newPC))
Esempio n. 11
0
def pragmaOrg(ppt, line, result):
    "Relocates the PC with no output"
    newPC = FE.parse_expr(line)
    line.expect("EOL")
    result.append(IR.Node(ppt, "SetPC", newPC))
Esempio n. 12
0
def run_all():
    """Transforms the source infiles to a binary outfile.

    Returns a shell-style exit code: 1 if there were errors, 0 if there
    were no errors.

    """
    Err.count = 0
    Tamagotchi.process(CmdLine.infiles)
    z = Frontend.parse(CmdLine.infiles)
    env = Environment.Environment()

    m = Passes.ExpandMacros()
    i = Passes.InitLabels()
    l_basic = Passes.UpdateLabels()
    l = Passes.FixPoint("label update", [l_basic],
                              lambda: not l_basic.changed)

    # The instruction selector is a bunch of fixpoints, and which
    # passes run depends on the command line options a bit.
    c_basic = Passes.Collapse()
    c = Passes.FixPoint("instruction selection 1", [l, c_basic],
                              lambda: not c_basic.changed)

    if CmdLine.enable_branch_extend:
        b = Passes.ExtendBranches()
        instruction_select = Passes.FixPoint("instruction selection 2",
                                                   [c, b],
                                                   lambda: not b.changed)
    else:
        instruction_select = c
    a = Passes.Assembler()

    passes = []
    passes.append(Passes.DefineMacros())
    passes.append(Passes.FixPoint("macro expansion", [m],
                                        lambda: not m.changed))
    passes.append(Passes.FixPoint("label initialization", [i],
                                        lambda: not i.changed))
    passes.extend([Passes.CircularityCheck(),
                   Passes.CheckExprs(),
                   Passes.EasyModes()])
    passes.append(instruction_select)
    passes.extend([Passes.NormalizeModes(),
                   Passes.UpdateLabels(),
                   a])

    for p in passes:
        p.go(z, env)

    if Err.count == 0:
        try:
            outfile = CmdLine.outfile
            if outfile == '-':
                output = sys.stdout
                if sys.platform == "win32":
                    # We can't dump our binary in text mode; that would be
                    # disastrous. So, we'll do some platform-specific
                    # things here to force our stdout to binary mode.
                    import msvcrt
                    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
            elif outfile is None:
                output = file('bin', 'wb')
            else:
                output = file(outfile, 'wb')
            f = open("template.txt", "rb")
            t = f.read()
            head = t[:0x40000]
            if (len("".join(map(chr, a.output))) > 0x400):
                print "too large"
                return 1
            tail = t[(0x40000 + len("".join(map(chr, a.output)))):]
            output.write(head + "".join(map(chr, a.output)) + tail)
            output.flush()
            if outfile != '-':
                output.close()
            return 0
        except IOError:
                print>>sys.stderr, "Could not write to " + outfile
                return 1
    else:
        Err.report()
        return 1
Esempio n. 13
0
def pragmaInclude(ppt, line, result):
    "Includes a source file"
    filename = line.expect("STRING").value
    line.expect("EOL")
    if type(filename) == str:
        result.append(FE.parse_file(ppt, filename))
Esempio n. 14
0
def pragmaRequire(ppt, line, result):
    "Includes a source file at most one time"
    filename = line.expect("STRING").value
    line.expect("EOL")
    if type(filename) == str:
        result.append(FE.parse_file(ppt, filename, True))
Esempio n. 15
0
def pragmaAlias(ppt, line, result):
    "Assigns an arbitrary label"
    lbl = line.expect("LABEL").value
    target = FE.parse_expr(line)
    result.append(IR.Node(ppt, "Label", lbl, target))
Esempio n. 16
0
def pragmaCheckpc(ppt, line, result):
    "Enforces that the PC has not exceeded a certain point"
    target = FE.parse_expr(line)
    line.expect("EOL")
    result.append(IR.Node(ppt, "CheckPC", target))
Esempio n. 17
0
def pragmaCheckpc(ppt, line, result):
    "Enforces that the PC has not exceeded a certain point"
    target = FE.parse_expr(line)
    line.expect("EOL")
    result.append(IR.Node(ppt, "CheckPC", target))
Esempio n. 18
0
def OnEnable(**kwargs):
	Map.Config      = kwargs["conf"]
	Manager.Config  = kwargs["conf"]
	Frontend.Config = kwargs["conf"]
	Frontend.InitManagers()
Esempio n. 19
0
def pragmaAlias(ppt, line, result):
    "Assigns an arbitrary label"
    lbl = line.expect("LABEL").value
    target = FE.parse_expr(line)
    result.append(IR.Node(ppt, "Label", lbl, target))
Esempio n. 20
0
def pragmaInclude(ppt, line, result):
    "Includes a source file"
    filename = line.expect("STRING").value
    line.expect("EOL")
    if type(filename) == str:
        result.append(FE.parse_file(ppt, filename))
Esempio n. 21
0
def pragmaRequire(ppt, line, result):
    "Includes a source file at most one time"
    filename = line.expect("STRING").value
    line.expect("EOL")
    if type(filename) == str:
        result.append(FE.parse_file(ppt, filename, True))
Esempio n. 22
0
File: Gui.py Progetto: logitah2/pycc
    def __init__(self):
        ''' creating and packing elements of the GUI '''
        tk.Tk.__init__(self)
        self.title("PYCC")
        self.openChats = []
        self.curChat = ''

        # initiate preferences
        self.Preferences = Preferences.Preferences('preferences.cfg')
        self.username = self.Preferences.prefs['username']
        self.textcolor = self.Preferences.prefs['textcolor']

        # chat selection
        self.fChatSelection = tk.Frame(self)
        self.fChatSelection.grid(row=0, column=0, sticky='w')
        # set current selected button to None
        self.activeButton = None

        # selection between contact list and preferences
        self.fMenue = tk.Frame(self)
        self.fMenue.grid(row=0, column=1)
        self.bContacts = tk.Button(self.fMenue,
                                   text='Contacts',
                                   command=self.displayContacts,
                                   width=6,
                                   fg=self.textcolor)
        self.bContacts.config(relief=tk.SUNKEN)
        self.bContacts.pack(side='left')
        self.bPreferences = tk.Button(self.fMenue,
                                      text='Prefs',
                                      command=self.displayPreferences,
                                      width=6,
                                      fg=self.textcolor)
        self.bPreferences.pack(side='left')

        # chat window
        self.fChatWindow = tk.Frame(self)
        self.fChatWindow.grid(row=1, column=0, sticky='nswe')
        self.sChatWindow = tk.Scrollbar(self.fChatWindow)
        self.sChatWindow.pack(side='right', fill='y')
        # read-only; switch back to state = 'normal' to insert text
        self.tChatWindow = tk.Text(self.fChatWindow,
                                   yscrollcommand=self.sChatWindow.set,
                                   height=20,
                                   state='disabled',
                                   fg=self.textcolor)
        self.tChatWindow.pack(side='left', fill='both', expand=True)
        self.sChatWindow.config(command=self.tChatWindow.yview)

        # input window
        self.fText = tk.Frame(self)
        self.fText.grid(row=2, column=0, sticky='nswe')
        self.sText = tk.Scrollbar(self.fText)
        self.sText.pack(side='right', fill='y')
        self.tText = tk.Text(self.fText,
                             yscrollcommand=self.sText.set,
                             height=4,
                             state='disabled',
                             fg=self.textcolor)
        self.tText.pack(side='left', fill='x', expand=True)
        self.sText.config(command=self.tText.yview)

        # preferences
        self.fPreferences = tk.Frame(self)
        self.sPreferences = tk.Scrollbar(self.fPreferences)
        self.sPreferences.pack(side='right', fill='y')
        # username
        self.fUserName = tk.Frame(self.fPreferences)
        self.fUserName.pack(padx=10, pady=10, anchor='w')
        self.lUserName = tk.Label(self.fUserName,
                                  text='Username:'******'w', pady=5)
        self.eUserName = tk.Entry(self.fUserName, width=15, fg=self.textcolor)
        self.eUserName.insert('end', self.username)
        self.eUserName.pack(anchor='w')
        # textcolor
        self.tc = tk.StringVar()
        self.fColors = tk.Frame(self.fPreferences)
        self.fColors.pack(padx=10, anchor='w')
        self.fColors2 = tk.Frame(self.fPreferences)
        self.fColors2.pack(padx=10, anchor='w')
        self.lColors = tk.Label(self.fColors,
                                text='Textcolor:',
                                fg=self.textcolor)
        self.lColors.pack(anchor='w', pady=5)
        self.rbBlack = tk.Radiobutton(self.fColors,
                                      width=3,
                                      variable=self.tc,
                                      value='#000000',
                                      indicatoron=0,
                                      activebackground='#000000',
                                      selectcolor='#000000',
                                      bg='#444444')
        self.rbBlack.pack(side='left')
        self.rbRed = tk.Radiobutton(self.fColors,
                                    width=3,
                                    variable=self.tc,
                                    value='#FF0000',
                                    indicatoron=0,
                                    activebackground='#FF0000',
                                    selectcolor='#FF0000',
                                    bg='#DD4444')
        self.rbRed.pack(side='left')
        self.rbBlue = tk.Radiobutton(self.fColors,
                                     width=3,
                                     variable=self.tc,
                                     value='#0000FF',
                                     indicatoron=0,
                                     activebackground='#0000FF',
                                     selectcolor='#0000FF',
                                     bg='#4444BB')
        self.rbBlue.pack(side='left')
        self.rbGreen = tk.Radiobutton(self.fColors,
                                      width=3,
                                      variable=self.tc,
                                      value='#00FF00',
                                      indicatoron=0,
                                      activebackground='#00FF00',
                                      selectcolor='#00FF00',
                                      bg='#44DD44')
        self.rbGreen.pack(side='left')
        self.rbWhite = tk.Radiobutton(self.fColors2,
                                      width=3,
                                      variable=self.tc,
                                      value='#FFFFFF',
                                      indicatoron=0,
                                      activebackground='#FFFFFF',
                                      selectcolor='#FFFFFF',
                                      bg='#EEEEEE')
        self.rbWhite.pack(side='left')
        self.rbYellow = tk.Radiobutton(self.fColors2,
                                       width=3,
                                       variable=self.tc,
                                       value='#FFFF00',
                                       indicatoron=0,
                                       activebackground='#FFFF00',
                                       selectcolor='#FFFF00',
                                       bg='#DDDD44')
        self.rbYellow.pack(side='left')
        self.rbViolet = tk.Radiobutton(self.fColors2,
                                       width=3,
                                       variable=self.tc,
                                       value='#FF00FF',
                                       indicatoron=0,
                                       activebackground='#FF00FF',
                                       selectcolor='#FF00FF',
                                       bg='#DD44DD')
        self.rbViolet.pack(side='left')
        self.rbTurquoise = tk.Radiobutton(self.fColors2,
                                          width=3,
                                          variable=self.tc,
                                          value='#00FFFF',
                                          indicatoron=0,
                                          activebackground='#00FFFF',
                                          selectcolor='#00FFFF',
                                          bg='#44DDDD')
        self.rbTurquoise.pack(side='left')

        self.bSave = tk.Button(self.fPreferences,
                               text='Save',
                               width=8,
                               command=self.savePrefs,
                               fg=self.textcolor)
        self.bSave.pack(padx=10, pady=20, anchor='w')

        # contact list
        self.fContacts = tk.Frame(self)
        self.fContacts.grid(row=1, column=1, rowspan=3, sticky='nswe')
        self.sContacts = tk.Scrollbar(self.fContacts)
        self.sContacts.pack(side='right', fill='y')
        self.lContacts = tk.Listbox(self.fContacts,
                                    yscrollcommand=self.sContacts.set,
                                    fg=self.textcolor)
        self.lContacts.pack(side='left', fill='y')
        self.sContacts.config(command=self.lContacts.yview)

        # chat buttons
        self.fChatButtons = tk.Frame(self)
        self.fChatButtons.grid(row=3, column=0, sticky='w')

        self.bSend = tk.Button(self.fChatButtons,
                               text='Send',
                               command=self.sendMessage,
                               width=10,
                               state='disabled',
                               fg=self.textcolor)
        self.bSend.pack(side='left')
        self.bCloseChat = tk.Button(self.fChatButtons,
                                    text='Close Chat',
                                    command=self.closeChat,
                                    width=10,
                                    state='disabled',
                                    fg=self.textcolor)
        self.bCloseChat.pack(side='left')

        # define expanding rows and columns
        self.rowconfigure(1, weight=1)
        self.columnconfigure(0, weight=1)
        self.columnconfigure(1, minsize=177)

        # define events
        self.lContacts.bind('<Double-ButtonPress-1>', self.startChat)
        self.tText.bind('<KeyRelease-Return>', self.sendMessage)
        self.tText.bind('<Shift-KeyRelease-Return>', self.newline)
        self.protocol('WM_DELETE_WINDOW', self.windowClosing)

        self.frontend = Frontend.Frontend()
        started = self.frontend.startBackend()
        if not started:
            print('Fehler!!!!')
        else:
            self.frontend.updateLoopTkinter(self)

        # add callback to be raised when new message is received
        self.frontend.addCallback('newMessage', self.gotNewMessage)

        #load contact list from pycc/.contacts
        self.frontend.sendRequest('getAccounts', self.gotAccounts)
Esempio n. 23
0
def OnDisable(**kwargs):
	Frontend.SaveData()