Spaces:
Sleeping
Sleeping
Commit ·
8d598a4
1
Parent(s): d3b7f65
Improve artifact workspace and remove quickstart
Browse filesFiles changed (6)
- Dockerfile-14
- README.md+3-3
- app.py+131-44
- catalog.md-1
- ccs.py+5-3
- runner.py+1-13
18 unmodified lines19202122232425262728293031323322232485 unmodified lines11011111212511312711411511618 unmodified lines rm -f /etc/apt/apt.conf.d/docker-clean \ && apt-get update && apt-get install -y --no-install-recommends libncurses-dev
FROM foxdec-build AS quickstartRUN fetch https://raw.githubusercontent.com/ssrg-vt/FoxDec/0abd8c85cda0ccf3da9ef6683acb77a99c04b8b6/foxdec/release/FoxDec.zip \ 783ab34ac419fb00646994db520ab1c943382773002f0797bdbf80592b7ed262 FoxDec.zip \ && unzip -q FoxDec.zip 'FoxDec/foxdec_v0.7.zip' 'FoxDec/binary/wc*' \ && unzip -q FoxDec/foxdec_v0.7.zip 'foxdec_v0.7/*'WORKDIR /build/foxdec_v0.7RUN --mount=type=cache,id=foxdec-ghc-9.6.4,target=/root/.stack/programs,sharing=locked \ --mount=type=cache,id=foxdec-pantry,from=hackage-index,source=/root/.stack/pantry,target=/root/.stack/pantry \ --mount=type=cache,id=foxdec-stack-snapshots,target=/root/.stack/snapshots \ stack --install-ghc --jobs 4 --local-bin-path /opt/quickstart/bin install \ && cp -r config /build/FoxDec/binary /opt/quickstart/
FROM haskell-build AS pldiRUN apt-get update && apt-get install -y --no-install-recommends \ autoconf libtool libcapstone-dev libz3-dev pkg-config \85 unmodified linesCOPY requirements.txt /tmp/requirements.txtRUN --mount=type=cache,id=foxdec-pip,target=/root/.cache/pip \ pip install -r /tmp/requirements.txtCOPY --from=quickstart /opt/quickstart /opt/foxdec/quickstartCOPY --from=pldi /opt/pldi /opt/foxdec/pldiCOPY --from=quickstart --chmod=644 /build/foxdec_v0.7/LICENSE /opt/foxdec/quickstart/LICENSECOPY --from=pldi --chmod=644 /build/construct-ssm/LICENSE /opt/foxdec/pldi/LICENSEWORKDIR /home/user/appCOPY app.py catalog.md ./8 unmodified lines9101112121314156 unmodified lines22232425252627272829308 unmodified lines
# FoxDec research artifacts
Run the FoxDec v0.7 `wc` quickstart, PLDI 2022 `simple_local_array`, or the CCS 2024 certificate workflow. The app runs one job at a time and displays the results in the page. Quickstart and PLDI have five-minute deadlines. CCS has an eight-minute deadline after completing in about four minutes on two CPUs and 16 GB of memory. The [artifact catalog](catalog.md) links to the original papers and reproduction packages.Run the PLDI 2022 `simple_local_array` example or the CCS 2024 certificate workflow. The app runs one job at a time and displays the results in the page. PLDI has a five-minute deadline. CCS has an eight-minute deadline after completing in about four minutes on two CPUs and 16 GB of memory. The [artifact catalog](catalog.md) links to the original papers and reproduction packages.
## Run locally
6 unmodified lines
## Analyze a new binary
All three runnable artifacts accept Linux x86-64 ELF executables and shared objects up to 16 MiB. Choose **Upload a binary**. The tools analyze the file as data without running it as a program.Both runnable artifacts accept Linux x86-64 ELF executables and shared objects up to 16 MiB. Choose **Upload a binary**. The tools analyze the file as data without running it as a program.
The ELF entry point is used by default. Enter a hexadecimal address such as `0x401000` to choose a starting point for PLDI or to add a function entry for FoxDec. Both FoxDec versions accept multiple addresses separated by spaces or commas. The CCS runner displays the last completed stage if an uploaded binary cannot be recompiled or verified.The ELF entry point is used by default. Enter a hexadecimal address such as `0x401000` to choose a starting point for PLDI or to add a function entry for FoxDec. The CCS workflow accepts multiple addresses separated by spaces or commas. The CCS runner displays the last completed stage if an uploaded binary cannot be recompiled or verified.
## CCS 2024 certificate validation
12334567892 unmodified lines12131413151617161819208 unmodified lines293031313232333435343536373839404142434445464748495051525354555657583637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868714 unmodified lines10210310410510610710810911011111211311411511611711811912012112212312412512612712812913013118 unmodified lines15015115210310410515315415515615715815916016116216316416516610716716816917017117217317417517617717817918018118218318418518611 unmodified lines198199200127201202203204205132133134135206207208209210211212213214215216217218219220221222223224225139226227141228229230231145146147232233234235236237import base64import loggingimport subprocessimport refrom queue import Empty, Queuefrom threading import Threadimport subprocessfrom html import escapefrom pathlib import Pathfrom tempfile import TemporaryDirectory2 unmodified linesimport gradio as gr
from ccs import stages as ccs_stagesfrom runner import DEADLINE, MAX_UPLOAD, pldi, quickstart, read_preview, stage_uploadfrom runner import DEADLINE, MAX_UPLOAD, pldi, read_preview, stage_upload
ARTIFACTS = { "FoxDec v0.7": ("wc", DEADLINE, quickstart), "PLDI 2022 · SSM Construction": ("simple_local_array", DEADLINE, pldi), "CCS 2024 · Verified lifting": ("wc", 480, ccs_stages),}8 unmodified lines
def display_results(work, files): sections = [] def priority(path): groups = {name: [] for name in ("Functions", "Overview", "Assembly", "Graphs", "Certificate", "Diagnostics")} functions = {} for path in sorted(files): name = path.relative_to(work).as_posix() return (0 if name.endswith(".asm") else 1 if name.endswith(".dot") else 2 if name.startswith("certificate/") or name == "verification.log" else 3, name)
for path in sorted(files, key=priority): name = escape(path.relative_to(work).as_posix()) with path.open("rb") as stream: data = stream.read(DISPLAY_LIMIT + 1) truncated = len(data) > DISPLAY_LIMIT data = data[:DISPLAY_LIMIT] content = escape(data.decode(errors="replace")) or "No output." if truncated: content += "\n[Display limit reached for this file]" graph = "" if path.suffix == ".dot" and not truncated: try: rendered = subprocess.run( ["dot", "-Tpng"], input=data, capture_output=True, timeout=15, check=True, ).stdout encoded = base64.b64encode(rendered).decode("ascii") graph = f'<img class="foxdec-graph" alt="Graph: {name}" src="data:image/png;base64,{encoded}">' except (OSError, subprocess.SubprocessError): graph = '<p>Graph rendering unavailable; DOT source follows.</p>' source = f'<pre>{content}</pre>' if not graph else f'<details><summary>DOT source</summary><pre>{content}</pre></details>' sections.append(f'<section><h2>{name}</h2>{graph}{source}</section>') return '<div class="foxdec-results">' + "".join(sections) + "</div>" parts = path.relative_to(work).parts if len(parts) >= 3 and parts[0] == "functions": functions.setdefault(parts[1], []).append(path) continue group = ("Assembly" if name.endswith(".asm") else "Graphs" if name.endswith(".dot") else "Certificate" if name.startswith("certificate/") or name == "verification.log" else "Diagnostics" if name.endswith((".log", ".err")) else "Overview") groups[group].append((name, [path])) groups["Functions"] = list(functions.items())
tabs, panels = [], [] for group_index, (group, entries) in enumerate((g, e) for g, e in groups.items() if e): checked = " checked" if group_index == 0 else "" tabs.append(f'<input type="radio" name="view" id="view-{group_index}"{checked}>' f'<label for="view-{group_index}">{group} <span>{len(entries)}</span></label>') choices, contents = [], [] for index, (name, paths) in enumerate(entries): safe_name = escape(name) selected = " checked" if index == 0 else "" rendered_files = [] for path in paths: with path.open("rb") as stream: data = stream.read(DISPLAY_LIMIT + 1) truncated = len(data) > DISPLAY_LIMIT data = data[:DISPLAY_LIMIT] content = escape(data.decode(errors="replace")) or "No output." if truncated: content += "\n[Display limit reached for this file]" graph = "" if path.suffix == ".dot" and not truncated: try: rendered = subprocess.run(["dot", "-Tpng"], input=data, capture_output=True, timeout=2, check=True).stdout encoded = base64.b64encode(rendered).decode("ascii") graph = f'<div class="graph-scroll"><img alt="Graph: {safe_name}" src="data:image/png;base64,{encoded}"></div>' except (OSError, subprocess.SubprocessError): graph = "<p>Graph rendering unavailable. DOT source is shown below.</p>" source = f'<pre>{content}</pre>' if not graph else f'<details><summary>DOT source</summary><pre>{content}</pre></details>' rendered_files.append(f'<section><h4>{escape(path.name)}</h4>{graph}{source}</section>') ident = f"file-{group_index}-{index}" choices.append(f'<input type="radio" name="files-{group_index}" id="{ident}"{selected}>' f'<label for="{ident}">{safe_name}</label>') contents.append(f'<article class="file-content file-{index}"><h3>{safe_name}</h3>{"".join(rendered_files)}</article>') rules = ''.join(f'.files-{group_index}:has(#file-{group_index}-{i}:checked) .file-{i}{{display:block}}' for i in range(len(entries))) panels.append(f'<div class="panel panel-{group_index}"><div class="files files-{group_index}">' f'<aside>{"".join(choices)}</aside><main>{"".join(contents)}</main></div><style>{rules}</style></div>') rules = ''.join(f'.workspace:has(#view-{i}:checked) .panel-{i}{{display:block}}' for i in range(len(panels))) return f'<div class="foxdec-results"><h2>Results</h2><div class="workspace"><nav>{"".join(tabs)}</nav>{"".join(panels)}<style>{rules}</style></div></div>'
def entry_addresses(text, workflow):14 unmodified lines return gr.update(choices=choices, value=EXAMPLE), gr.update(visible=False), None, ""
def updates(workflow): queue = Queue() def run(): try: for item in workflow: queue.put(("item", item)) except Exception as error: queue.put(("error", error)) finally: queue.put(("done", None)) Thread(target=run, daemon=True).start() while True: try: kind, value = queue.get(timeout=2) except Empty: yield None continue if kind == "done": return if kind == "error": raise value yield value
def run_example(artifact, mode=EXAMPLE, upload=None, addresses=""): yield "Running", "", gr.update(interactive=False) if artifact not in ARTIFACTS:18 unmodified lines case _: raise ValueError("Choose a built-in example or upload a binary.") files = () for phase, files in workflow(work, log, deadline, **arguments): if phase: phases.append(phase) current = "" def progress(action): return "\n".join([*(f"✓ {step}" for step in phases), f"▶ {action} · {monotonic() - started:.0f}s elapsed"]) for update in updates(workflow(work, log, deadline, **arguments)): if update is None: yield progress(current or "Starting analysis"), gr.update(), gr.update(interactive=False) continue phase, files = update if phase and not files: if current: phases.append(current.rstrip("…")) current = phase if not files: yield "\n".join(phases), "", gr.update(interactive=False) available = (sorted((work / "nasm").glob("*.asm")) + sorted((work / "certificate").glob("*.thy"))) verification = work / "verification.log" if verification.is_file(): available.append(verification) yield progress(current or "Starting analysis"), display_results(work, available) if available else gr.update(), gr.update(interactive=False) if not files: raise RuntimeError("The job produced no results.") if current: phases.append(current.rstrip("…")) if phase: phases.append(phase) immediate = [path for path in files if path.suffix == ".asm"] if immediate: yield progress("Preparing graphs and other results…"), display_results(work, immediate), gr.update(interactive=False) else: yield progress("Preparing results…"), "", gr.update(interactive=False) results = display_results(work, files) if monotonic() >= deadline: raise TimeoutError("The job reached its time limit.")11 unmodified lines diagnostics = (log, work / "simple_local_array.err", work / "verification.log") message = "\n".join(filter(None, (read_preview(path, tail=True) for path in diagnostics))) results = f'<div class="foxdec-results"><pre>{escape(message)}</pre></div>' if message else "" yield "\n".join([status, *phases]), results, gr.update(interactive=True) yield "\n".join([*(f"✓ {step}" for step in phases), status]), results, gr.update(interactive=True)
with gr.Blocks( title="FoxDec research artifacts", css=".foxdec-results pre { max-height: 32rem; overflow: auto; } " ".foxdec-results section { margin: 1.5rem 0; } " ".foxdec-results h2 { overflow-wrap: anywhere; } " ".foxdec-graph { max-width: 100%; height: auto; background: white; }", css=""" .foxdec-results nav { display:flex; flex-wrap:wrap; gap:.4rem; border-bottom:1px solid var(--border-color-primary); } .foxdec-results input { position:absolute; opacity:0; pointer-events:none; } .foxdec-results label { display:block; cursor:pointer; padding:.65rem .9rem; border-radius:.4rem; overflow-wrap:anywhere; } .foxdec-results input:checked + label { background:var(--background-fill-secondary); color:var(--link-text-color); font-weight:600; } .foxdec-results input:focus-visible + label { outline:2px solid var(--link-text-color); } .foxdec-results nav span { opacity:.65; font-size:.8em; } .foxdec-results .panel, .foxdec-results .file-content { display:none; } .foxdec-results .files { display:grid; grid-template-columns:minmax(12rem, 22%) minmax(0, 1fr); gap:1rem; margin-top:1rem; } .foxdec-results aside { max-height:40rem; overflow:auto; border-right:1px solid var(--border-color-primary); } .foxdec-results main { min-width:0; } .foxdec-results h3 { overflow-wrap:anywhere; } .foxdec-results pre { max-height:40rem; overflow:auto; padding:1rem; border-radius:.5rem; background:var(--background-fill-secondary); white-space:pre; } .graph-scroll { overflow:auto; background:white; padding:1rem; border-radius:.5rem; } .graph-scroll img { max-width:none; height:auto; } @media(max-width:700px) { .foxdec-results .files { grid-template-columns:1fr; } .foxdec-results aside { max-height:12rem; border-right:0; border-bottom:1px solid var(--border-color-primary); } } """, analytics_enabled=False, delete_cache=(60, 3600),) as demo: gr.Markdown("# FoxDec research artifacts") gr.Markdown("# FoxDec research artifacts\nAnalyze a Linux x86-64 binary, inspect the generated assembly and graphs, or verify a lifting certificate.") artifact = gr.Dropdown(list(ARTIFACTS), value=next(iter(ARTIFACTS)), label="Artifact") mode = gr.Radio([(f"{EXAMPLE} · wc", EXAMPLE), (UPLOAD, UPLOAD)], value=EXAMPLE, label="Input") mode = gr.Radio([(f"{EXAMPLE} · simple_local_array", EXAMPLE), (UPLOAD, UPLOAD)], value=EXAMPLE, label="Input") with gr.Column(visible=False) as upload_inputs: upload = gr.File(label="Linux x86-64 ELF binary", type="filepath") addresses = gr.Textbox(label="Entry addresses (optional)", placeholder="0x401000") run = gr.Button("Run", variant="primary") status = gr.Textbox(label="Status", lines=2, max_lines=6, interactive=False) results = gr.HTML() run = gr.Button("Run analysis", variant="primary") status = gr.Textbox(label="Status", lines=5, max_lines=12, interactive=False) results = gr.HTML(value="<p>Run an analysis to see its results here.</p>") with gr.Accordion("Artifact catalog", open=False): gr.Markdown(Path(__file__).with_name("catalog.md").read_text())
1 unmodified line23455671 unmodified line
| Example or paper | What it covers | Availability || --- | --- | --- || FoxDec v0.7 quickstart | Lifts the bundled `wc` to NASM and generates metrics, a call graph and per-function results. [Quickstart](https://ssrg-vt.github.io/FoxDec/#how-to-use) · [Pinned release ZIP](https://github.com/ssrg-vt/FoxDec/blob/0abd8c85cda0ccf3da9ef6683acb77a99c04b8b6/foxdec/release/FoxDec.zip) | Built-in example and binary uploads || PLDI 2022 · Formally Verified Lifting of C-compiled x86-64 Binaries | Runs the symbolic state analysis on the bundled `simple_local_array` example. [Paper](https://doi.org/10.1145/3519939.3523702) · [Tagged artifact](https://github.com/jabocken/SSM-Construction/releases/tag/v2.0.0.2) · [Benchmark instructions](https://github.com/jabocken/SSM-Construction/tree/v2.0.0.2#running-test-cases) · [Isabelle instructions](https://github.com/jabocken/SSM-Construction/blob/v2.0.0.2/isabelle/README) | Built-in example and binary uploads. Full benchmark and proofs available upstream. || CCS 2024 · Verifiably Correct Lifting of Position-Independent x86-64 Binaries to Symbolized Assembly | Lifts the paper’s `wc` with FoxDec v0.5, recompiles it, generates an equivalence certificate with Ghidra and checks it in Isabelle2023. [Paper](https://doi.org/10.1145/3658644.3690244) · [Archived artifact and instructions](https://zenodo.org/records/12721325) | Built-in example and binary uploads. Checks a newly generated certificate. || ICSE 2025 · Formally Verified Binary-level Pointer Analysis | Binary-level pointer analysis, benchmark cases and Isabelle/HOL proofs. [Paper](https://arxiv.org/abs/2501.17766) · [Artifact](https://doi.org/10.5281/zenodo.14223108) | Catalog only |12 unmodified lines131415161718197 unmodified lines27282929303132332 unmodified lines36373838394041422 unmodified lines45464747484950513 unmodified lines5556575859606112 unmodified lines
def stages(work, log, deadline, *, binary=None, entries=()): env = dict(os.environ, LD_LIBRARY_PATH=str(TOOL)) yield "Lifting the binary to assembly…", () name = lift(TOOL, work, log, deadline, ["--GNASM"], env=env, binary=binary, entries=entries) run = partial(run_command, deadline=deadline, limit_output=binary is not None) nasm = work / "nasm"7 unmodified lines if not (opening and addresses and closing): raise RuntimeError("FoxDec did not emit the address mapping in the NASM output.") mapping.write_text(addresses + "\n") yield f"Lifted {name} to NASM", () yield "Assembling and linking the lifted program…", ()
run(["nasm", "-felf64", "-g", "-F", "dwarf", "-o", obj, assembly.name], nasm, log) run(["gcc", "-c", "__gmon_start__.c", "-o", "__gmon_start__.o"], nasm, log)2 unmodified lines run(["gcc", "-g", "-m64", "-nostartfiles", "-fgnu-tm", "-Wl,-T,layout.ld", "-o", "a.out", obj, "__gmon_start__.o"], nasm, log) require_outputs(nasm / "a.out") yield "Recompiled the NASM", () yield "Generating the certificate with Ghidra…", ()
certificate = work / "certificate" certificate.mkdir()2 unmodified lines if not blocks: raise RuntimeError("The generator produced no block theories.") require_outputs(certificate / f"{theory}.thy", certificate / f"{theory}_mapping.thy", *blocks) yield "Generated the certificate with Ghidra", () yield "Preparing Isabelle verification…", ()
shutil.copyfile(TOOL / "PCode.thy", certificate / "PCode.thy") (certificate / "ROOT").write_text(3 unmodified lines f' theories {theory}\n' ) verification = work / "verification.log" yield "Checking the certificate with Isabelle (this may take several minutes)…", () run( ["/opt/Isabelle2023/bin/isabelle", "build", "-c", "-v", "-o", "threads=2", "-d", "/opt/Word_Lib", "-D", ".", "FoxDec_Certificate"],95 unmodified lines969798991001011021031041051061071081091101119910010110210395 unmodified lines return binary.name
def quickstart(work, log, deadline, *, binary=None, entries=()): name = lift( ROOT / "quickstart", work, log, deadline, ["--Gmetrics", "--Gcallgraph", "--Gfuncs", "--GNASM"], binary=binary, entries=entries, ) files = [work / f"{name}.metrics.txt", work / f"{name}.callgraph.dot", work / f"nasm/{name}.asm"] functions = sorted((work / "functions").glob("*/*")) if not functions: raise RuntimeError("FoxDec produced no per-function results.") require_outputs(*files, *functions) yield "", [*files, *functions, log]
def pldi(work, log, deadline, *, binary=None, entries=()): yield "Constructing the state-space model…", () tool = ROOT / "pldi" if binary is not None: analysis = work / "analysis.txt"Dockerfile-14
README.md+3-3
app.py+131-44
catalog.md-1
ccs.py+5-3
runner.py+1-13