summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2018-07-16 15:56:28 -0400
committerKyleMiles <krm504@nyu.edu>2018-07-16 15:56:28 -0400
commitf9d7cc83105d6cbfe03409c6eddbc039b0d9839c (patch)
tree73ad748088574ad5b97c19453c01db82eb7eb78c
parent2c7f443ce0b3d92ea44acb440c1891344eacc6d4 (diff)
Fix format of strings in python/log.py
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--python/generator.cpp10
-rw-r--r--python/log.py12
-rw-r--r--python/plugin.py35
5 files changed, 37 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index fca3f67d..088713e7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,7 @@ api-docs/build/*
.env
api-docs/source/binaryninja.*
bin/
+suite/unit.py
# CMake
CMakeCache.txt
CMakeFiles
diff --git a/Makefile b/Makefile
index e1576dcf..8480c05a 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,7 @@ all: $(TARGET).a
$(TARGET).a: $(OBJECTS)
@mkdir -p $(TARGETDIR)
$(AR) rcs $@ $^
-
+
%.o: %.cpp
@echo " Compiling... $@ $<"
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
@@ -86,7 +86,7 @@ environment_clean:
@echo "Removing 'binaryninja' Packages..."
rm -rf suite/binaryninja/
rm -rf python/examples/binaryninja/
-
+
@echo "Removing libs..."
rm -f libbinaryninjacore.so.1
rm -f python/libbinaryninjacore.so.1
@@ -97,7 +97,7 @@ environment_clean:
rm -rf python/types/
rm -rf python/plugins/
-clean:
+clean:
@echo " Cleaning...";
$(RM) -r *.o $(TARGETDIR) generator
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