Skip to content

Commit

Permalink
feat: allow to reconstruct without hashmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbesler committed Oct 24, 2023
1 parent 93b27f6 commit 57b86b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pytwingrind/pytwingrind/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

reconstruct_parser = ArgumentParser("""Converts a callstack, as it has been read of the fetch command together with the
hashmap that has been created for the PLC with the prepare command, to the callgrind format.""")
reconstruct_parser.add_argument("-m", "--hashmap", help="Hashmap that is created with the prepare command", required=True)
reconstruct_parser.add_argument("-m", "--hashmap", help="Hashmap that is created with the prepare command", required=False)
reconstruct_parser.add_argument("-c", "--callstack", help="Callstack that was read out with the fetch command", required=True)
reconstruct_parser.add_argument("-d", "--directory", help="Output directory", default="./", required=False)
reconstruct_parser.add_argument("-q", "--masquarade", help="Obfuscate names of functionblocks, functions and methods", action="store_true", required=False)
Expand Down
6 changes: 4 additions & 2 deletions pytwingrind/pytwingrind/reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build_graph(network, hashmap, roots, data, sid=-1, eid=-1):
endid = np.where(np.logical_and(data[sid+1:eid, StackRow.HASH] == data[sid, StackRow.HASH],
data[sid+1:eid, StackRow.DEPTH] == data[sid, StackRow.DEPTH]))[0][0] + sid + 1
dt_100ns = data[endid, StackRow.END_100NS] - data[sid, StackRow.START_100NS]
fb, method = hashmap[data[endid, StackRow.HASH]]
fb, method = hashmap[data[endid, StackRow.HASH]] if hashmap is not None else (hex(data[endid, StackRow.HASH]), hex(data[endid, StackRow.HASH]))
depth = int(data[endid, StackRow.DEPTH])+1

roots = roots[0:depth]
Expand Down Expand Up @@ -126,7 +126,9 @@ def run(hashmap: str, file: str, dest: str, outputname: str):

logging.debug(f"Callstack size={callstack.size}")

hm = pickle.load(open(hashmap, 'rb'))
hm = None
if hashmap is not None:
hm = pickle.load(open(hashmap, 'rb'))

data = extract_stack(callstack.stack, hm)
n = networkx.DiGraph()
Expand Down

0 comments on commit 57b86b1

Please sign in to comment.