summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/generator.cpp10
-rw-r--r--python/log.py12
-rw-r--r--python/plugin.py35
3 files changed, 33 insertions, 24 deletions
diff --git a/python/generator.cpp b/python/generator.cpp
index afc77254..39e45aea 100644
--- a/python/generator.cpp
+++ b/python/generator.cpp
@@ -391,6 +391,16 @@ int main(int argc, char* argv[])
}
fprintf(out, "\t]\n");
}
+ else
+ {
+ // As of writing this, only BNLog's have variable instruction lengths, but in an attempt not to break in the future:
+ if (funcName.compare(0, 6, "_BNLog") == 0)
+ {
+ fprintf(out, "def %s(*args):\n", name.c_str());
+ fprintf(out, "\treturn %s(*[cstr(arg) for arg in args])\n\n", funcName.c_str());
+ continue;
+ }
+ }
if (stringResult)
{
diff --git a/python/log.py b/python/log.py
index 9a5e1358..4997b222 100644
--- a/python/log.py
+++ b/python/log.py
@@ -55,7 +55,7 @@ def log(level, text):
:param str text: message to print
:rtype: None
"""
- core.BNLog(level,text)
+ core.BNLog(level, '%s', text)
def log_debug(text):
@@ -70,7 +70,7 @@ def log_debug(text):
>>> log_debug("Hotdogs!")
Hotdogs!
"""
- core.BNLogDebug(text)
+ core.BNLogDebug('%s', text)
def log_info(text):
@@ -85,7 +85,7 @@ def log_info(text):
Saucisson!
>>>
"""
- core.BNLogInfo(text)
+ core.BNLogInfo('%s', text)
def log_warn(text):
@@ -101,7 +101,7 @@ def log_warn(text):
Chilidogs!
>>>
"""
- core.BNLogWarn(text)
+ core.BNLogWarn('%s', text)
def log_error(text):
@@ -117,7 +117,7 @@ def log_error(text):
Spanferkel!
>>>
"""
- core.BNLogError(text)
+ core.BNLogError('%s', text)
def log_alert(text):
@@ -133,7 +133,7 @@ def log_alert(text):
Kielbasa!
>>>
"""
- core.BNLogAlert(text)
+ core.BNLogAlert('%s', text)
def log_to_stdout(min_level=LogLevel.InfoLog):
diff --git a/python/plugin.py b/python/plugin.py
index 2fc30052..6ca930c9 100644
--- a/python/plugin.py
+++ b/python/plugin.py
@@ -24,7 +24,6 @@ import threading
# Binary Ninja components
import binaryninja
-from binaryninja import log
from binaryninja import _binaryninjacore as core
from binaryninja.enums import PluginCommandType
from binaryninja import filemetadata
@@ -96,7 +95,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
action(view_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _address_action(cls, view, addr, action):
@@ -105,7 +104,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
action(view_obj, addr)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _range_action(cls, view, addr, length, action):
@@ -114,7 +113,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
action(view_obj, addr, length)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _function_action(cls, view, func, action):
@@ -124,7 +123,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = function.Function(view_obj, core.BNNewFunctionReference(func))
action(view_obj, func_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _low_level_il_function_action(cls, view, func, action):
@@ -135,7 +134,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner)
action(view_obj, func_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _low_level_il_instruction_action(cls, view, func, instr, action):
@@ -146,7 +145,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner)
action(view_obj, func_obj[instr])
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _medium_level_il_function_action(cls, view, func, action):
@@ -157,7 +156,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner)
action(view_obj, func_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _medium_level_il_instruction_action(cls, view, func, instr, action):
@@ -168,7 +167,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner)
action(view_obj, func_obj[instr])
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@classmethod
def _default_is_valid(cls, view, is_valid):
@@ -179,7 +178,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
return is_valid(view_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -191,7 +190,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
return is_valid(view_obj, addr)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -203,7 +202,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
return is_valid(view_obj, addr, length)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -216,7 +215,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = function.Function(view_obj, core.BNNewFunctionReference(func))
return is_valid(view_obj, func_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -230,7 +229,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner)
return is_valid(view_obj, func_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -244,7 +243,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner)
return is_valid(view_obj, func_obj[instr])
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -258,7 +257,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner)
return is_valid(view_obj, func_obj)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -272,7 +271,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
func_obj = binaryninja.mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner)
return is_valid(view_obj, func_obj[instr])
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return False
@classmethod
@@ -552,7 +551,7 @@ class MainThreadActionHandler(object):
try:
self.add_action(MainThreadAction(action))
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def add_action(self, action):
pass