Plugin - How to resolve Out of memory #3575
Answered
by
baikaishiuc
baikaishiuc
asked this question in
Q&A
|
I wrote a plugin to load vmp trace file(10MB) and render corresponding instruction to red. The plugin code is below: from binaryninja import *
from binaryninja.log import log_warn, log_debug, log_info, log_error
from pathlib import Path
from time import sleep
import binaryninja.interaction as interaction
import binaryninja.filemetadata as filemetadata
import re
# 设置具体某个地址行的颜色
#current_function.set_user_instr_highlight(0x1236a, highlight.HighlightColor(red=0xff,blue=0,green=0))
tline="( libc.so[0xCBD52000])[08 B5 ]0xCBD602F8:0x0000e2f8: PUSH {R3, LR} ;(SP=0x100FEAA8 R3=0x00000000 LR=0x03000000 )"
def paint_trace(bv:BinaryView,function):
trace_filename= interaction.get_open_filename_input("Filename:")
if trace_filename is None:
print("No file specified")
sys.exit(1)
#
watch_so = Path(bv.file.filename).stem + ".so"
print("watch so " + watch_so)
# https://stackoverflow.com/questions/12476804/how-i-can-get-the-peak-memory-on-mac-os/30124747#30124747
# 在BN上调用这个插件会显示内存错误,关键就在于load这个文件的地方,可以用上面的链接来测试内存峰值
with open(trace_filename) as trace_file:
for line in trace_file:
if line[0] != '(':
continue
m = re.match(r'\( +([^\[]+)\[([^\[]+)\]\)\[([^\]]+)\]([^:]+):([^:]+).*',line)
so_name = m.groups()[0]
so_baseaddr = m.groups()[1]
inst = m.groups()[2]
inst_va = m.groups()[3]
inst_rva = m.groups()[4]
print(so_name + ", " + inst_rva)
break
if so_name != watch_so:
continue
bv.get_functions_containing(inst_rva)[0].set_user_instr_highlight(inst_rva, highlight.HighlightColor(red=0xff,blue=0,green=0))
#
PluginCommand.register_for_address("PaintTrace", "Color Trace Instruction", paint_trace)when i invoke it , the binary ninja crashed: it seems the OOM, after my debug, the script crash on iterate trace_file for line in trace_file:I write a demo python file test memory issue , open 10MB file , iterate line and print to stdout, test memory peakge according this link(https://stackoverflow.com/questions/12476804/how-i-can-get-the-peak-memory-on-mac-os/30124747#30124747): I reload a 2kb file , and crash again. so i think it the crash reason is not OOM how can I to resolve it ? |
Answered by
baikaishiuc
Oct 21, 2022
Replies: 1 comment
|
resolved it, close. it crash on another line. |
0 replies
Answer selected by
baikaishiuc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

resolved it, close.
it crash on another line.