Beispiel #1
0
 def run(self, arg):
     """
     run function for XML Importer plugin.
     
     Args:
         arg: Integer, a non-zero value enables auto-run feature for
              IDA batch (no gui) processing mode. Default is 0.
     """
     st = idc.set_ida_state(idc.IDA_STATUS_WORK)
     xml = idaxml.XmlImporter(idaxml.PLUGIN, arg)
     try:
         try:
             xml.import_xml()
         except idaxml.Cancelled:
             msg = "XML Import cancelled!"
             print "\n" + msg
             idc.warning(msg)
         except idaxml.MultipleAddressSpacesNotSupported:
             msg = "XML Import cancelled!"
             msg += "\n\nXML Import does not currently support"
             msg += "\nimporting multiple address spaces."
             print "\n" + msg
             idc.warning(msg)
         except:
             msg = "***** Exception occurred: XML Importer failed! *****"
             print "\n" + msg + "\n", sys.exc_type, sys.exc_value
             idc.warning(msg)
     finally:
         xml.cleanup()
         idc.set_ida_state(st)
Beispiel #2
0
def main():
    log("plugin run")
    if not is_jni_header_loaded():
        idaapi.warning('Please load jni.h first')
        load_jni_header()
    st = idc.set_ida_state(idc.IDA_STATUS_WORK)
    infos = load_methods()
    failed = []
    succ = 0
    for ea in idautils.Functions():
        fname = idc.get_func_name(ea)
        if fname.startswith('Java_'):
            info = infos.get(fname)
            if info is None:
                failed.append(name)
            else:
                succ += 1
            apply_signature(ea, info)
        if fname == 'JNI_OnLoad':
            apply_load_unload(ea, True)
            succ += 1
        if fname == 'JNI_OnUnload':
            apply_load_unload(ea, False)
            succ += 1
    idaapi.info('JNI functions loaded, {} success. {} failed. \n{}'.format(
        succ,
        len(failed),
        '\n'.join(failed)
    ))
    idc.set_ida_state(st)
Beispiel #3
0
 def run(self, arg):
     """
     :param arg: Integer, a non-zero value enables auto-run feature for
          IDA batch (no gui) processing mode. Default is 0.
     """
     log("plugin run")
     if not is_jni_header_loaded():
         idaapi.warning('Please load jni.h first')
         load_jni_header()
     st = idc.set_ida_state(idc.IDA_STATUS_WORK)
     infos = load_methods()
     failed = []
     succ = 0
     for ea in idautils.Functions():
         fname = idc.GetFunctionName(ea)
         if fname.startswith('Java_'):
             info = infos.get(fname)
             if info is None:
                 failed.append(fname)
             else:
                 succ += 1
             apply_signature(ea, info)
         if fname == 'JNI_OnLoad':
             apply_load_unload(ea, True)
             succ += 1
         if fname == 'JNI_OnUnload':
             apply_load_unload(ea, False)
             succ += 1
     idaapi.info('JNI functions loaded, {} success. {} failed. \n{}'.format(
         succ,
         len(failed),
         '\n'.join(failed)
     ))
     idc.set_ida_state(st)
Beispiel #4
0
 def run(self, arg):
     """
     run function for XML Importer plugin.
     
     Args:
         arg: Integer, a non-zero value enables auto-run feature for
              IDA batch (no gui) processing mode. Default is 0.
     """
     st = idc.set_ida_state(idc.IDA_STATUS_WORK)
     xml = idaxml.XmlImporter(idaxml.PLUGIN, arg)
     try:
         try:
             xml.import_xml()
         except idaxml.Cancelled:
             msg = "XML Import cancelled!"
             print "\n" + msg
             idc.warning(msg)
         except idaxml.MultipleAddressSpacesNotSupported:
             msg  = "XML Import cancelled!"
             msg += "\n\nXML Import does not currently support"
             msg += "\nimporting multiple address spaces."
             print "\n" + msg
             idc.warning(msg)
         except:
             msg = "***** Exception occurred: XML Importer failed! *****"
             print "\n" + msg + "\n", sys.exc_type, sys.exc_value
             idc.warning(msg)
     finally:
         xml.cleanup()
         idc.set_ida_state(st)
Beispiel #5
0
 def run(self, arg):
     """
     run function for XML Exporter plugin.
     
     Args:
         arg: Integer, non-zero value enables auto-run feature for
             IDA batch (no gui) processing mode. Default is 0.
     """
     st = idc.set_ida_state(idc.IDA_STATUS_WORK)
     xml = idaxml.XmlExporter(arg)
     try:
         try:
             xml.export_xml()
         except idaxml.Cancelled:
             ida_kernwin.hide_wait_box()
             msg = "XML Export cancelled!"
             print "\n" + msg
             idc.warning(msg)
         except:
             ida_kernwin.hide_wait_box()
             msg = "***** Exception occurred: XML Exporter failed! *****"
             print "\n" + msg + "\n", sys.exc_type, sys.exc_value
             idc.warning(msg)
     finally:
         xml.cleanup()
         ida_auto.set_ida_state(st)
Beispiel #6
0
 def run(self, arg):
     """
     run function for XML Exporter plugin.
     
     Args:
         arg: Integer, non-zero value enables auto-run feature for
             IDA batch (no gui) processing mode. Default is 0.
     """
     st = idc.set_ida_state(idc.IDA_STATUS_WORK)
     xml = idaxml.XmlExporter(arg)
     try:
         try:
             xml.export_xml()
         except idaxml.Cancelled:
             ida_kernwin.hide_wait_box()
             msg = "XML Export cancelled!"
             print "\n" + msg
             idc.warning(msg)
         except:
             ida_kernwin.hide_wait_box()
             msg = "***** Exception occurred: XML Exporter failed! *****"
             print "\n" + msg + "\n", sys.exc_type, sys.exc_value
             idc.warning(msg)
     finally:
         xml.cleanup()
         ida_auto.set_ida_state(st)
Beispiel #7
0
def main():
    if not is_jni_header_loaded():
        idaapi.warning('Please load jni.h first')
        load_jni_header()
    st = idc.set_ida_state(idc.IDA_STATUS_WORK)
    infos = load_methods()
    failed = []
    succ = 0
    for ea in idautils.Functions():
        fname = idc.GetFunctionName(ea)
        if fname.startswith('Java_') or fname in [
                'JNI_OnLoad', 'JNI_OnUnload'
        ]:
            sig = infos.get(fname)
            if sig is None:
                failed.append(fname)
            else:
                succ += 1
                apply_signature(ea, sig)
    idaapi.info('JNI functions loaded, {} success. {} failed. \n{}'.format(
        succ, len(failed), '\n'.join(failed)))
    idc.set_ida_state(st)
Beispiel #8
0
def export_ida_project_to_xml():
    """
    Export the current project into XML format
    """
    global EXPORT_XML_FILE

    xml_file_path, bin_file_path = get_ida_exported_files()
    print("GhIDA:: [DEBUG] EXPORT_XML_FILE: %s" % EXPORT_XML_FILE)

    # Check if files are alredy available
    if os.path.isfile(xml_file_path) and \
            os.path.isfile(bin_file_path) and \
            not EXPORT_XML_FILE:
        return xml_file_path, bin_file_path

    EXPORT_XML_FILE = False

    # Otherwise call the XML exporter IDA plugin
    print("GhIDA:: [DEBUG] Exporting IDA project into XML format")
    st = idc.set_ida_state(idc.IDA_STATUS_WORK)
    xml = XmlExporter(1)

    try:
        xml.export_xml(xml_file_path)
        print("GhIDA:: [INFO] XML exporting completed")
    except Cancelled:
        ida_kernwin.hide_wait_box()
        msg = "GhIDA:: [!] XML Export cancelled!"
        print("\n" + msg)
        idc.warning(msg)
    except Exception:
        ida_kernwin.hide_wait_box()
        msg = "GhIDA:: [!] Exception occurred: XML Exporter failed!"

        excinfo = sys.exc_info()
        tb = excinfo[2]
        print("\n" + msg + "\n", excinfo[:2], tb)
        traceback.print_tb(tb)

        idc.warning(msg)
    finally:
        xml.cleanup()
        ida_auto.set_ida_state(st)

    # check if both xml and binary format exist
    if not os.path.isfile(xml_file_path) or \
            not os.path.isfile(bin_file_path):
        raise Exception("GhIDA:: [!] XML or bytes file non existing.")
    return xml_file_path, bin_file_path
Beispiel #9
0
def load_file(li, neflags, format):
    """
    Load the file into database

    @param li: a file-like object which can be used to access the input data
    @param neflags: options selected by the user, see loader.hpp
    @return: 0-failure, 1-ok
    """
    global event, element
    if ida_idp.get_idp_name() == None:
        ida_idp.set_processor_type("metapc", ida_idp.SETPROC_LOADER)
    status = 0
    st = idc.set_ida_state(idc.IDA_STATUS_WORK)
    xml = idaxml.XmlImporter(idaxml.LOADER, 0)
    try:
        status = xml.import_xml()
    except idaxml.Cancelled:
        msg = "XML PROGRAM import cancelled!"
        print "\n" + msg
        idc.warning(msg)
    except idaxml.MultipleAddressSpacesNotSupported:
        msg = "XML Import cancelled!"
        msg += "\n\nXML Import does not currently support"
        msg += "\nimporting multiple address spaces."
        print "\n" + msg
        idc.warning(msg)
    except:
        print "\nHouston, we have a problem!"
        msg = "***** Exception occurred: XML loader failed! *****"
        print "\n" + msg + "\n", sys.exc_type, sys.exc_value
        print event, element.tag, element.attrib
        idc.warning(msg)
    finally:
        idc.set_ida_state(st)
        xml.cleanup()
        return status