Python idaapi.get_input_file_path() Examples

The following are 10 code examples of idaapi.get_input_file_path(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module idaapi , or try the search function .
Example #1
Source File: idasec_core.py    From idasec with GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self):
        self.broker = Broker()
        self.trace_id = 0
        self.traces = {}
        self.configuration = configuration()
        self.solvers = []
        self.analyses = []
        self.nb_cpus = 1
        self.binsec_connected = False
        self.pinsec_connected = False
        self.seg_mapping = None
        self.fun_mapping = None
        self.update_mapping()
        self.nb_instr = self.compute_nb_instr()
        self.ftype = "ELF" if open(idaapi.get_input_file_path()).read(2) == ELF else "PE"
        self.imports = self.compute_imports() 
Example #2
Source File: utils.py    From UEFI_RETool with MIT License 6 votes vote down vote up
def get_header_file():
    """get file header from analysing file"""
    if os.path.isfile(idaapi.get_input_file_path()):
        with open(idaapi.get_input_file_path(), 'rb') as f:
            buf = f.read(512)
    else:
        buf = b'\x00'
    return bytearray(buf) 
Example #3
Source File: vxhunter_ida.py    From vxhunter with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def handler_auto_fix_idb(self):
        form = AutoFixIDBForm()
        ok = form.Execute()
        if ok == 1:
            vx_version = int(form.vx_version)
            print("vx_version:%s" % vx_version)
            firmware_path = idaapi.get_input_file_path()
            firmware = open(firmware_path, 'rb').read()
            target = VxTarget(firmware=firmware, vx_version=vx_version)
            # target.logger.setLevel(logging.DEBUG)
            target.quick_test()

            if target.load_address:
                print("Load Address is:%s" % target.load_address)
            else:
                target.find_loading_address()
                if target.load_address:
                    print("Load Address is:%s" % target.load_address)
            if not target.load_address:
                return
            symbol_table_start = target.symbol_table_start
            symbol_table_end = target.symbol_table_end
            load_address = target.load_address
            self.fix_vxworks_idb(load_address, vx_version, symbol_table_start, symbol_table_end)
        form.Free() 
Example #4
Source File: plugin_loader.py    From vt-ida-plugin with Apache License 2.0 5 votes vote down vote up
def __init__(self, cfgfile):
    self.vt_cfgfile = cfgfile
    self.file_path = idaapi.get_input_file_path()
    self.file_name = idc.get_root_filename()

    logging.getLogger(__name__).addHandler(logging.NullHandler())

    if config.DEBUG:
      logging.basicConfig(
          stream=sys.stdout,
          level=logging.DEBUG,
          format='%(message)s'
          )
    else:
      logging.basicConfig(
          stream=sys.stdout,
          level=logging.INFO,
          format='%(message)s'
          )

    logging.info(
        '\n** VT Plugin for IDA Pro v%s (c) Google, 2020',
        VT_IDA_PLUGIN_VERSION
    )
    logging.info('** VirusTotal integration plugin for Hex-Ray\'s IDA Pro 7')

    logging.info('\n** Select an area in the Disassembly Window and right')
    logging.info('** click to search on VirusTotal. You can also select a')
    logging.info('** string in the Strings Window.\n') 
Example #5
Source File: win_driver_plugin.py    From win_driver_plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def decode_angr():
	"""Attempts to locate all the IOCTLs in a function and decode them all using symbolic execution"""
	
	path = idaapi.get_input_file_path()
	addr = idc.ScreenEA()
	ioctls = angr_analysis.angr_find_ioctls(path, addr)
	track_ioctls(ioctls) 
Example #6
Source File: ida_debugger.py    From IDAngr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def input_file(self):
        path = idaapi.get_input_file_path()
        f = open(path, "rb")
        if self.remote:
            return RemoteFile(f, path)
        return f 
Example #7
Source File: DebugAPI.py    From DIE with MIT License 5 votes vote down vote up
def dbg_process_exit(self, pid, tid, ea, exit_code):
        """
        TODO: debugging, should be implemented fully.
        @return:
        """
        try:
            if self.is_dbg_profile:
                self.profile_stop()

        except Exception as ex:
            self.logger.error("Failed to stop profiling: %s", ex)

        try:
            self.end_time = time.time()
            self.bp_handler.unsetBPs()

            die_db = DIE.Lib.DIEDb.get_db()

            die_db.add_run_info(self.callStack,
                                self.start_time,
                                self.end_time,
                                idaapi.get_input_file_path(),
                                idautils.GetInputFileMD5())

            self.bp_handler.save_exceptions(die_db)

        except Exception as ex:
            self.logger.exception("Failed while finalizing DIE run: %s", ex) 
Example #8
Source File: DIEDb.py    From DIE with MIT License 5 votes vote down vote up
def get_default_db_filename(self):
        """
        Get the default DIE DB filename
        """
        filename, extension = os.path.splitext(idaapi.get_input_file_path())
        return filename + ".ddb" 
Example #9
Source File: data.py    From Sark with MIT License 5 votes vote down vote up
def apply_patches(output_path=None):
    to_patch = idaapi.get_input_file_path()

    if output_path:
        shutil.copyfile(to_patch, output_path)
        to_patch = output_path

    patches = get_patched_bytes()

    with open(to_patch, "r+b") as output:
        for patch in patches.values():
            output.seek(patch.fpos)
            patched_byte = bytes([patch.patched])
            output.write(patched_byte) 
Example #10
Source File: drop.py    From DROP-IDA-plugin with GNU General Public License v3.0 5 votes vote down vote up
def database_inited(self, is_new_db, idc_script):
        # A file was loaded, reset vars
        self.plugin.filename = idaapi.get_input_file_path()
        self.plugin.cfg = None
        self.plugin.angr_proj = None
        self.plugin.global_vars = None
        self.plugin.opaque_predicates = dict()
        self.plugin.extra_constraints = dict()
        self.plugin.symbolic_vars = dict()

        # Check if it (still) exists
        if not isfile(self.plugin.filename):
            print("### Drop error: original input file no longer exists, unable to load it into angr. ###")
            return

        # Load the file into angr
        try:
            # This is a bit inefficient, but figure out if it's PIC by loading twice
            p = angr.Project(self.plugin.filename, load_options={'auto_load_libs': False})
            if p.loader.main_bin.pic:
                # Load with IDA's imagebase as base_addr
                base_addr = idaapi.get_imagebase()
            else:
                # Load with 0 as base_addr
                base_addr = 0
            del p
            self.plugin.angr_proj = angr.Project(self.plugin.filename,
                load_options={'auto_load_libs': False, 'main_opts': {
                    'custom_base_addr': base_addr}})

            # get and store the file bitness
            # Don't use idaapi.get_inf_structure().is_32bit(), it will give True for MIPS64...
            self.plugin.bitness = self.plugin.angr_proj.arch.bits

            # Save the list of all recognized variables in .bss, .data and .rodata (TODO: why these? any others?)
            # TODO: Other segments as well?
            self.plugin.global_vars = [var for s in sark.segments() for var in get_segment_names(s) if s.name in [".bss", ".data", ".rodata"]]
            print("### Loaded file into angr succesfully! ###")
        except:
            import traceback
            print("ERROR: Failed to load file into angr: {}".format(traceback.format_exc()))