Skip to content

Instantly share code, notes, and snippets.

@sirdarckcat
Last active January 21, 2024 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirdarckcat/a26175d6c4c08e519974d69764b8c62d to your computer and use it in GitHub Desktop.
Save sirdarckcat/a26175d6c4c08e519974d69764b8c62d to your computer and use it in GitHub Desktop.

get vmlinux path from https://syzkaller.appspot.com/upstream/manager/ci2-upstream-kcsan-gce then run https://github.com/torvalds/linux/blob/master/scripts/extract-vmlinux then use r2 to generate a global callgraph https://reverseengineering.stackexchange.com/questions/16081/how-to-generate-the-call-graph-of-a-binary-file

grep ' \[label="' output.dot | sort -u | sed 's/ URL=.*//g' | sed 's/ .label=/,/g' > ../symbols.csv
grep ' -> ' output.dot | grep -v 'sym.__' | sed 's/ .color.*//g' | sed 's/ -> /,/g' > callgraph.csv
cat ../symbols.csv | sed s/,.*//g | grep 0xffff |  xargs addr2line -f -e ../vmlinux.bin | paste -d ","  - - > ../sym2file.csv
dwarfdump -d -i vmlinux.bin | grep DW_AT_name | grep DW_TAG_member | sed 's/.*DW_TAG_member>//g' | sed 's/<<*/":"/g' | sed 's/>>*/",/g' | sed 's/ DW_AT_/"/g' | awk '{print("{" $0 " \"\":0}")}' | grep '{' | jq -c --slurp 'unique_by(.name)[]'  > dwarf.json
#!/bin/bash
COVERAGE_HTML="6.6-ci2-upstream-kcsan-gce-ffc25326.html"
grep '<a'.*'id='.*onFileClick ${COVERAGE_HTML} | sed 's/.* id=\(.*\?\) onclick=\(.*\?\)>/\1,\2/' > ${COVERAGE_HTML}.files.csv
#!/usr/bin/python3
import csv
import html
import sys
csv_prog = csv.writer(sys.stdout)
haystack = open("6.6-ci2-upstream-kcsan-gce-ffc25326.html").read()
pos = -1
while True:
prog_section = '<pre class="file" id="prog_'
pos = haystack.find(prog_section, pos + 1)
if pos == -1:
break
index_pos = pos + len(prog_section)
pos = haystack.find('"', index_pos + 1)
if pos == -1:
break
index = haystack[index_pos:pos]
program_pos = pos + len('">')
pos=haystack.find("</pre>", program_pos)
program=html.unescape(haystack[program_pos:pos].strip())
csv_prog.writerow((index, program))
#!/usr/bin/python3
haystack = open("6.6-ci2-upstream-kcsan-gce-ffc25326.html").read()
pos = -1
while True:
file_section = 'class="file" id="contents_'
pos = haystack.find(file_section, pos + 1)
if pos == -1:
break
index_pos = pos + len(file_section)
pos = haystack.find('"', index_pos + 1)
if pos == -1:
break
index = haystack[index_pos:pos]
prefix_pos = pos + len('"')
prefix = "><table><tr><td class='count'>"
coverage_pos = pos + len('"') + len(prefix)
if haystack[prefix_pos:coverage_pos]!=prefix:
# error
continue
pos=haystack.find("</td>", coverage_pos)
coverage=haystack[coverage_pos:pos].splitlines()
covered_lines = []
for idx, line in enumerate(coverage):
idx += 1 # 0-indexed
program_event = "onProgClick("
if program_event in line:
comma_pos = line.find(",", len(program_event))
prog_id = line[line.find(program_event)+len(program_event):comma_pos]
covered_lines.append((idx, prog_id))
print("%s,%s,%s"%(index, idx, prog_id*1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment