Skip to content

Commit

Permalink
Fix 2 bugs
Browse files Browse the repository at this point in the history
Bug 1 windows files are not resolved correctly TLDR.. fuck windows
Bug 2 log files could have basic blocks with no parent module and they
get module number 65535. I would ignore them for now.
  • Loading branch information
oddcoder committed Mar 24, 2019
1 parent 731233a commit 3d66b3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cutterDRcovPlugin/drcov.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from pathlib import Path
import struct

from .extras import file_name

MIN_DRCOV_FILE_SIZE = 20
DRCOV_VERSION = 2
Expand Down Expand Up @@ -52,9 +51,9 @@ def parse_module_entry(f, version):
#XXX now put commas and spaces in the file path and this gets fucked up
entry = re.split(",\s+", entry)
if version == 2:
return {"start": int(entry[1], 16), "name": Path(entry[-1]).name}
return {"start": int(entry[1], 16), "name": file_name(entry[-1])}
else:
return {"start": int(entry[2], 16), "name": Path(entry[-1]).name}
return {"start": int(entry[2], 16), "name": file_name(entry[-1])}

def read_module_list(f):
modules = []
Expand All @@ -79,6 +78,11 @@ def read_bb_list(f, module_count):
# size of struct is 64 bit
bb = f.read(8)
offset, size, mod_num = struct_unpack(bb)
if mod_num > module_count:
# we have a case where dynamocov failed to capture which modules
# does this basic block belongs to
print("Warning: we have unknown module number:", mod_num)
continue
bblist[mod_num][offset] = size
return bblist

Expand Down
17 changes: 17 additions & 0 deletions cutterDRcovPlugin/extras.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from PySide2.QtWidgets import QTableWidgetItem
from PySide2.QtCore import Qt
import ntpath

class PercentWidgetItem(QTableWidgetItem):
def __lt__(self, other):
Expand All @@ -25,3 +26,19 @@ def centered_text(x):
def hexPad(num, pad):
return "{0:#0{1}x}".format(num,pad + 2)


# https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format
# cuz windows sucks :( .. hard
def file_name(path):
# There's one caveat: Linux filenames may contain backslashes. So on linux,
# r'a/b\c' always refers to the file b\c in the a folder, while on Windows,
# it always refers to the c file in the b subfolder of the a folder. So when
# both forward and backward slashes are used in a path, you need to know the
# associated platform to be able to interpret it correctly. In practice it's
# usually safe to assume it's a windows path since backslashes are seldom
# used in Linux filenames, but keep this in mind when you code so you don't
# create accidental security holes.

head, tail = ntpath.split(path)
return tail or ntpath.basename(head)

0 comments on commit 3d66b3e

Please sign in to comment.