mirror of
https://github.com/cemu-project/idapython.git
synced 2024-11-28 03:54:18 +01:00
1258fab948
- IDA Pro 6.2 support - added set_idc_func_ex(): it is now possible to add new IDC functions using Python - added visit_patched_bytes() (see ex_patch.py) - added support for the multiline text input control in the Form class - added support for the editable/readonly dropdown list control in the Form class - added execute_sync() to register a function call into the UI message queue - added execute_ui_requests() / check ex_uirequests.py - added add_hotkey() / del_hotkey() to bind Python methods to hotkeys - added register_timer()/unregister_timer(). Check ex_timer.py - added the IDC (Arrays) netnode manipulation layer into idc.py - added idautils.Structs() and StructMembers() generator functions - removed the "Run Python Statement" menu item. IDA now has a unified dialog. Use RunPlugin("python", 0) to invoke it manually. - better error messages for script plugins, loaders and processor modules - bugfix: Dbg_Hooks.dbg_run_to() was receiving wrong input - bugfix: A few Enum related functions were not properly working in idc.py - bugfix: GetIdaDirectory() and GetProcessName() were broken in idc.py - bugfix: idaapi.get_item_head() / idc.ItemHead() were not working
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
#!/usr/bin/env python
|
|
# -----------------------------------------------------------------------
|
|
# IDAPython - Python plugin for Interactive Disassembler
|
|
#
|
|
# Copyright (c) The IDAPython Team <idapython@googlegroups.com>
|
|
#
|
|
# All rights reserved.
|
|
#
|
|
# For detailed copyright information see the file COPYING in
|
|
# the root of the distribution archive.
|
|
# -----------------------------------------------------------------------
|
|
# init.py - Essential init routines
|
|
# -----------------------------------------------------------------------
|
|
import os
|
|
import sys
|
|
import time
|
|
import warnings
|
|
import _idaapi
|
|
|
|
# __EA64__ is set if IDA is running in 64-bit mode
|
|
__EA64__ = _idaapi.BADADDR == 0xFFFFFFFFFFFFFFFFL
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Take over the standard text outputs
|
|
# -----------------------------------------------------------------------
|
|
class IDAPythonStdOut:
|
|
"""
|
|
Dummy file-like class that receives stout and stderr
|
|
"""
|
|
def write(self, text):
|
|
# Swap out the unprintable characters
|
|
text = text.decode('ascii', 'replace').encode('ascii', 'replace')
|
|
# Print to IDA message window
|
|
_idaapi.msg(text)
|
|
|
|
def flush(self):
|
|
pass
|
|
|
|
def isatty(self):
|
|
return False
|
|
|
|
# -----------------------------------------------------------------------
|
|
def runscript(script):
|
|
"""
|
|
Executes a script.
|
|
This function is present for backward compatiblity. Please use idaapi.IDAPython_ExecScript() instead
|
|
|
|
@param script: script path
|
|
|
|
@return: Error string or None on success
|
|
"""
|
|
|
|
import idaapi
|
|
return idaapi.IDAPython_ExecScript(script, globals())
|
|
|
|
# -----------------------------------------------------------------------
|
|
def print_banner():
|
|
banner = [
|
|
"Python %s " % sys.version,
|
|
"IDAPython" + (" 64-bit" if __EA64__ else "") + " v%d.%d.%d %s (serial %d) (c) The IDAPython Team <idapython@googlegroups.com>" % IDAPYTHON_VERSION
|
|
]
|
|
sepline = '-' * (max([len(s) for s in banner])+1)
|
|
|
|
print(sepline)
|
|
print("\n".join(banner))
|
|
print(sepline)
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# Redirect stderr and stdout to the IDA message window
|
|
sys.stdout = sys.stderr = IDAPythonStdOut()
|
|
|
|
# Assign a default sys.argv
|
|
sys.argv = [""]
|
|
|
|
# Have to make sure Python finds our modules
|
|
sys.path.append(_idaapi.idadir("python"))
|
|
|
|
# Remove current directory from the top of the patch search
|
|
if '' in sys.path: # On non Windows, the empty path is added
|
|
sys.path.remove('')
|
|
|
|
if os.getcwd() in sys.path:
|
|
sys.path.remove(os.getcwd())
|
|
|
|
# ...and add it to the end if needed
|
|
if not IDAPYTHON_REMOVE_CWD_SYS_PATH:
|
|
sys.path.append(os.getcwd())
|
|
|
|
# Import all the required modules
|
|
from idaapi import Choose, get_user_idadir, cvar, Choose2, Appcall, Form
|
|
from idc import *
|
|
from idautils import *
|
|
import idaapi
|
|
|
|
# Load the users personal init file
|
|
userrc = os.path.join(get_user_idadir(), "idapythonrc.py")
|
|
if os.path.exists(userrc):
|
|
idaapi.IDAPython_ExecScript(userrc, globals())
|
|
|
|
# All done, ready to rock. |