作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
IDApython 在命令行中的 IDA pro 中运行良好。但是,当我使用 import idautis 编译 python 程序时,在普通编辑器中的 IDA pro 之外出现错误:
“没有名为 _idaapi 的模块”
from idautils import *
from idaapi import *
ea = BeginEA()
for funcea in Functions(SegStart(ea), SegEnd(ea)):
functionName = GetFunctionName(funcea)
functionStart = paddAddr(hex(funcea)[2:])
functionEnd = paddAddr(hex(FindFuncEnd(funcea))[2:])
<REST OF THE CODE>
如何在IDA pro之外执行python代码?
最佳答案
你不能真正在 IDA 之外执行 IDAPython 脚本,但你可以让 IDA 静默运行并且不显示其 GUI。
在您的脚本中,您需要将stdout
重定向到一个文件,例如:
import sys
import idaapi
import idc
import os
def stdout_to_file(output_file_name, output_dir=None):
'''Set stdout to a file descriptor
param: output_file_name: name of the file where standard output is written.
param: output_dir: output directory for output file, default to script directory.
Returns: output file descriptor, original stdout descriptor
'''
# obtain this script path and build output path
if not output_dir:
output_dir = os.path.dirname(os.path.realpath(__file__))
output_file_path = os.path.join(output_dir, output_file_name)
# save original stdout descriptor
orig_stdout = sys.stdout
# create output file
f = file(output_file_path, "w")
# set stdout to output file descriptor
sys.stdout = f
return f, orig_stdout
def main(args):
# get original stdout and output file descriptor
f, orig_stdout = stdout_to_file("output.txt")
if idc.ARGV:
for i, arg in enumerate(idc.ARGV):
print "[*] arg[{}]: {}".format(i, arg)
# call something from IDA (get the original input file name from IDB)
print "[*] filename from IDB: {}".format(idaapi.get_root_filename())
print("[*] done, exiting.")
# restore stdout, close output file
sys.stdout = orig_stdout
f.close()
# exit IDA
idc.Exit(0)
if __name__ == "__main__":
main(sys.argv)
然后在命令行上您可以调用您的 IDAPython 脚本(假设 IDA 在您的 PATH 中):
idaq.exe -A -S"C:\tmp\test_script.py foo bar" "C:\tmp\mydatabase.idb"
-A
静默运行IDA-S
用于脚本路径和脚本参数-t
生成临时 idb)查看 IDA 帮助文件以获得所有可用选项的完整列表。
输出,在 output.txt 文件中(IDB 来自输入文件“calc.exe”):
[*] arg[0]: C:\tmp\test_script.py
[*] arg[1]: foo
[*] arg[2]: bar
[*] filename from IDB: calc.exe
[*] done, exiting.
您还可以查看标题为“Running scripts from the command line with idascript”的六角射线博客
关于python - 如何使用python在ida pro之外导入idautils,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32967702/
我是一名优秀的程序员,十分优秀!