Ejemplo n.º 1
0
 def load_script(self, bap, ea):
     idc.SetStatus(idc.IDA_STATUS_WORK)
     idaapi.IDAPython_ExecScript(bap.script.name, globals())
     self._do_callbacks(ea)
     idc.Refresh()
     # do we really need to call this?
     idaapi.refresh_idaview_anyway()
     idc.SetStatus(idc.IDA_STATUS_READY)
Ejemplo n.º 2
0
def main():
    global OUTPUT_PROLOGUE, OUTPUT_EPILOGUE, OFFSET_TMPL
    Message('\nbincode.py started.\n')
    Message('Prompting user for C identifier...\n> ')
    idc.SetStatus(idc.IDA_STATUS_WAITING)
    ident = AskStr('CODE_', 'Please enter the C identifier you\'d like used..')
    Message(ident + '\n')

    writer = StringIO()
    writer.write(OUTPUT_PROLOGUE % ident)
    lengetter = operator.attrgetter('c_bytes_len')

    placeholders = []
    Message('Generating code... ')
    idc.SetStatus(idc.IDA_STATUS_WORK)
    for seg in segms_by_class('CODE'):
        insns = tuple(segm_insn_exs(seg))
        bytes_just = max(map(lengetter, insns)) + 1
        for insn in insns:
            writer.write(insn.c_line(bytes_just))
            placeholder = insn.placeholder
            if placeholder is not None:
                placeholders.append(placeholder)
                Message('\nLocated a placeholder at offset: {:2X}h'.format(
                    placeholder))

    writer.write(OUTPUT_EPILOGUE)
    if len(placeholders) > 0:
        writer.write('\n')
        Message('\nAdding placeholder offset macros..')
        for idx, offset in enumerate(placeholders):
            line = OFFSET_TMPL.format(ident, idx, offset)
            writer.write(line)

    text = writer.getvalue()

    Message('\nGeneration complete.')
    output_code(text)

    Message('\nCopying generated code to clipboard...')
    set_clipboard_text(text)
    Message('\nDone.\n')

    idc.SetStatus(idc.IDA_STATUS_READY)
    writer.close()
Ejemplo n.º 3
0
def wait_ready():
    global already_loaded
    if menu is None:
        if os.path.dirname(idautils.GetIdbDir()) == os.getcwd():
            create_menu()

    # Couldn't find a better way: IDA Hooks do not provide any event to
    # know when this happens. To be improved.
    prev_status = idc.SetStatus(IDA_STATUS_READY)
    idc.SetStatus(prev_status)

    if prev_status == IDA_STATUS_READY and (menu is not None):
        if not already_loaded:
            already_loaded = True
            menu.insert_hooks()
        return 0

    return 1000
Ejemplo n.º 4
0
 def _do_run(self):
     try:
         super(BapIda, self).run()
         BapIda.instances.append(self)
         idaapi.register_timer(self.poll_interval_ms, self.update)
         idc.SetStatus(idc.IDA_STATUS_THINKING)
         self.run_handlers('instance_created')
         idc.Message("BAP> created new instance with PID {0}\n".format(
             self.proc.pid))
     except:  # pylint: disable=bare-except
         idc.Message("BAP> failed to create instance\nError: {0}\n".format(
             str(sys.exc_info()[1])))
         traceback.print_exc()
Ejemplo n.º 5
0
 def update(self):
     if all(bap.finished() for bap in BapIda.instances):
         idc.SetStatus(idc.IDA_STATUS_READY)
     if self.finished():
         if self.proc.returncode == 0:
             self.run_handlers('instance_finished')
             self.close()
             idc.Message("BAP> finished " + self.action + '\n')
         elif self.proc.returncode > 0:
             self.run_handlers('instance_failed')
             self.close()
             idc.Message("BAP> an error has occured while {0}\n".format(
                 self.action))
         else:
             if not self.closed:
                 self.run_handlers('instance_canceled')
             idc.Message("BAP> was killed by signal {0}\n".format(
                 -self.proc.returncode))
         return -1
     else:
         self.run_handlers('instance_updated')
         return self.poll_interval_ms