Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gaasedelen committed Dec 12, 2018
2 parents a81aa6d + 1ab2212 commit 675cc87
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -201,7 +201,7 @@ Example usage:
pin.exe -t CodeCoverage64.dll -- boombox.exe
```

For convenience, binaries for the Windows pintool can be found on the [releases](https://github.com/gaasedelen/lighthouse/releases/tag/v0.8.0) page. macOS and Linux users need to compile the pintool themselves following the [instructions](coverage/pin#compilation) included with the pintool for their respective platforms.
For convenience, binaries for the Windows pintool can be found on the [releases](https://github.com/gaasedelen/lighthouse/releases) page. macOS and Linux users need to compile the pintool themselves following the [instructions](coverage/pin#compilation) included with the pintool for their respective platforms.

## Frida (Experimental)

Expand Down
4 changes: 2 additions & 2 deletions coverage/pin/Makefile
@@ -1,10 +1,10 @@
CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config
include $(CONFIG_ROOT)/makefile.config

TOOL_CXXFLAGS += -std=c++11 -Wno-format
TOOL_CXXFLAGS += -std=c++11 -Wno-format -Wno-aligned-new
TOOL_ROOTS := CodeCoverage

$(OBJDIR)CodeCoverage$(PINTOOL_SUFFIX): $(OBJDIR)CodeCoverage$(OBJ_SUFFIX) $(OBJDIR)ImageManager$(OBJ_SUFFIX)
$(LINKER) $(TOOL_LDFLAGS) $(LINK_EXE)$@ $^ $(TOOL_LPATHS) $(TOOL_LIBS)

include $(TOOLS_ROOT)/Config/makefile.default.rules
include $(TOOLS_ROOT)/Config/makefile.default.rules
3 changes: 2 additions & 1 deletion coverage/pin/README.md
Expand Up @@ -22,6 +22,7 @@ cd ~/lighthouse/coverage/pin
export PIN_ROOT=~/pin
export PATH=$PATH:$PIN_ROOT
make
make TARGET=ia32
```

The resulting binaries will be placed inside a directory whose name depends on the arch/platform/build type.
Expand Down Expand Up @@ -68,7 +69,7 @@ The resulting binaries will be labaled based on their architecture (eg, 64 is th
* CodeCoverage.dll
* CodeCoverage64.dll

Compiling a pintool on Windows can be more arduous. Because of this, we have provided compiled binaries for Windows on the [releases](https://github.com/gaasedelen/lighthouse/releases/tag/v0.7.0) page.
Compiling a pintool on Windows can be more arduous. Because of this, we have provided compiled binaries for Windows on the [releases](https://github.com/gaasedelen/lighthouse/releases) page. Please be sure to use the pintool that matches your version of Pin.

# Usage

Expand Down
18 changes: 18 additions & 0 deletions dev_scripts/reload_BINJA_personal.bat
@@ -0,0 +1,18 @@
set LIGHTHOUSE_LOGGING=1
REM - Close any running instances of Binja
call close_BINJA.bat

REM - Purge old lighthouse log files
del /F /Q "C:\Users\user\AppData\Roaming\Binary Ninja\lighthouse_logs\*"

REM - Delete the old plugin bits
del /F /Q "C:\Users\user\AppData\Roaming\Binary Ninja\plugins\*lighthouse_plugin.py"
rmdir "C:\Users\user\AppData\Roaming\Binary Ninja\plugins\lighthouse" /s /q

REM - Copy over the new plugin bits
xcopy /s/y "..\plugin\*" "C:\Users\user\AppData\Roaming\Binary Ninja\plugins\"
del /F /Q "C:\Users\user\AppData\Roaming\Binary Ninja\plugins\.#lighthouse_plugin.py"

REM - Launch a new Binja session
start "" "C:\tools\disassemblers\BinaryNinja_Personal\binaryninja.exe" "..\..\testcase\boombox.bndb"

6 changes: 3 additions & 3 deletions plugin/lighthouse/binja_integration.py
Expand Up @@ -32,23 +32,23 @@ def interactive_load_batch(self, bv):

def _install_load_file(self):
PluginCommand.register(
"Lighthouse - Load code coverage file...",
r"Lighthouse\Load code coverage file...",
"Load individual code coverage file(s)",
self.interactive_load_file
)
logger.info("Installed the 'Code coverage file' menu entry")

def _install_load_batch(self):
PluginCommand.register(
"Lighthouse - Load code coverage batch...",
r"Lighthouse\Load code coverage batch...",
"Load and aggregate code coverage files",
self.interactive_load_batch
)
logger.info("Installed the 'Code coverage batch' menu entry")

def _install_open_coverage_overview(self):
PluginCommand.register(
"Lighthouse - Coverage Overview",
r"Lighthouse\Coverage Overview",
"Open the database code coverage overview",
self.interactive_load_batch
)
Expand Down
5 changes: 3 additions & 2 deletions plugin/lighthouse/core.py
Expand Up @@ -20,7 +20,7 @@
# Plugin Metadata
#------------------------------------------------------------------------------

PLUGIN_VERSION = "0.8.2"
PLUGIN_VERSION = "0.8.3"
AUTHORS = "Markus Gaasedelen"
DATE = "2018"

Expand Down Expand Up @@ -476,7 +476,8 @@ def warn_module_missing():
" Possible reasons:\n"
" - You selected a coverage file for the wrong binary.\n"
" - The name of the executable file used to generate this database\n"
" is different than the one you collected coverage against.\n\n"
" is different than the one you collected coverage against.\n"
" - Your DBI failed to collect any coverage for this binary.\n\n"
"Please see the disassembler console for more info..."
)

Expand Down
2 changes: 2 additions & 0 deletions plugin/lighthouse/coverage.py
Expand Up @@ -191,6 +191,8 @@ def suspicious(self):
"""
bad = 0
total = len(self.nodes)
if not total:
return 0.0

#
# count the number of nodes (basic blocks) that allegedly were executed
Expand Down
5 changes: 5 additions & 0 deletions plugin/lighthouse/director.py
Expand Up @@ -440,6 +440,11 @@ def create_coverage_from_drcov_list(self, drcov_list):
errors.append((self.ERROR_COVERAGE_SUSPICIOUS, drcov_data.filepath))
lmsg("Badly mapped coverage %s" % drcov_data.filepath)

# warn when loaded coverage (for this module) appears to be empty
if not len(coverage.nodes):
errors.append((self.ERROR_COVERAGE_ABSENT, drcov_data.filepath))
lmsg("No relevant coverage data in %s" % drcov_data.filepath)

#
# resume the director's aggregation service, triggering an update to
# recompute the aggregate with the newly loaded coverage
Expand Down
11 changes: 5 additions & 6 deletions plugin/lighthouse/painting/ida_painter.py
Expand Up @@ -410,7 +410,7 @@ def _priority_paint(self):
"""
Immediately repaint regions of the database visible to the user.
"""
cursor_address = idaapi.get_screen_ea()
cursor_address = disassembler.execute_read(idaapi.get_screen_ea)()

# paint functions around the cursor address
if not self._priority_paint_functions(cursor_address):
Expand Down Expand Up @@ -446,17 +446,16 @@ def _priority_paint_functions(self, target_address):
# select the range of functions around us that we would like to paint
func_num = db_metadata.get_function_index(function_metadata.address)
func_num_start = max(func_num - FUNCTION_BUFFER, 0)
func_num_end = func_num + FUNCTION_BUFFER + 1
func_num_end = min(func_num + FUNCTION_BUFFER + 1, len(db_metadata.functions))

# repaint the specified range of functions
for current_num in xrange(func_num_start, func_num_end):

# get the next function to paint
try:
function_metadata = db_metadata.get_function_by_index(current_num)
function_address = function_metadata.address
except IndexError:
function_metadata = db_metadata.get_function_by_index(current_num)
if not function_metadata:
continue
function_address = function_metadata.address

# get the function coverage data for the target address
function_coverage = db_coverage.functions.get(function_address, None)
Expand Down
4 changes: 2 additions & 2 deletions plugin/lighthouse/parsers/drcov.py
Expand Up @@ -407,7 +407,7 @@ def _parse_module_v3(self, data):
self.base = int(data[2], 16)
self.end = int(data[3], 16)
self.entry = int(data[4], 16)
if len(data) == 7: # Windows Only
if len(data) > 7: # Windows Only
self.checksum = int(data[5], 16)
self.timestamp = int(data[6], 16)
self.path = str(data[-1])
Expand All @@ -424,7 +424,7 @@ def _parse_module_v4(self, data):
self.end = int(data[3], 16)
self.entry = int(data[4], 16)
self.offset = int(data[5], 16)
if len(data) == 7: # Windows Only
if len(data) > 8: # Windows Only
self.checksum = int(data[6], 16)
self.timestamp = int(data[7], 16)
self.path = str(data[-1])
Expand Down
14 changes: 7 additions & 7 deletions plugin/lighthouse/util/disassembler/binja_api.py
Expand Up @@ -22,7 +22,7 @@
#

DEPENDENCY_PATH = os.path.join(
binaryninja.user_plugin_path,
binaryninja.user_plugin_path(),
"Lib",
"site-packages"
)
Expand Down Expand Up @@ -110,14 +110,14 @@ def __init__(self, bv=None):
self._python = _binja_get_scripting_instance()

def _init_version(self):
version_string = binaryninja.core_version()

# retrieve Binja's version #
if "-" in binaryninja.core_version: # dev
disassembler_version = binaryninja.core_version.split("-", 1)[0]
if "-" in version_string: # dev
disassembler_version = version_string.split("-", 1)[0]
else: # commercial, personal
binaryninja.core_version.split(" ", 1)[0]
disassembler_version = version_string.split(" ", 1)[0]

disassembler_version = binaryninja.core_version.split("-", 1)[0]
major, minor, patch = map(int, disassembler_version.split("."))

# save the version number components for later use
Expand Down Expand Up @@ -155,7 +155,7 @@ def version_patch(self):

@property
def headless(self):
return not binaryninja.core_ui_enabled
return not binaryninja.core_ui_enabled()

#--------------------------------------------------------------------------
# Synchronization Decorators
Expand Down Expand Up @@ -220,7 +220,7 @@ def get_database_directory(self):
return os.path.dirname(self.bv.file.filename)

def get_disassembler_user_directory(self):
return os.path.split(binaryninja.user_plugin_path)[0]
return os.path.split(binaryninja.user_plugin_path())[0]

@not_mainthread
def get_function_addresses(self):
Expand Down

0 comments on commit 675cc87

Please sign in to comment.