Spaces:
Sleeping
Sleeping
Commit ·
f9afae4
1
Parent(s): 83a9a5a
Put SEFM first and accept binary uploads with a decompiler config
Browse filesUploads are disassembled with objdump after normalizing the prefixes and
endbr64 that the artifact's parser cannot read.
Files changed (4)
- README.md+2-2
- app.py+23-12
- catalog.md+1-1
- sefm.py+56-9
21 unmodified lines2223242526272829303132333421 unmodified lines## Analyze a new binaryPLDI and CCS 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. 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.## SEFM 2020 decompilation to CThe build downloads the paper artifact from Zenodo and checks its hash. It is distributed under CC BY 4.0 by Freek Verbeek, Pierre Olivier and Binoy Ravindran. The build compiles the artifact’s Haskell decompiler against Z3 and runs it on the artifact’s own `wc` disassembly, data dump and configuration. The generated C is then recompiled with `gcc`. The decompiler needs a hand-written configuration that lists each function’s argument registers, so this workflow offers only the built-in example. [SEFM 2020 artifact](https://doi.org/10.5281/zenodo.3952034)## CCS 2024 certificate validation21 unmodified lines2223242526272829303132333421 unmodified lines## Analyze a new binaryPLDI, CCS and SEFM 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. 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.## SEFM 2020 decompilation to CThe build downloads the paper artifact from Zenodo and checks its hash. It is distributed under CC BY 4.0 by Freek Verbeek, Pierre Olivier and Binoy Ravindran. The build compiles the artifact’s Haskell decompiler against Z3 and runs it on the artifact’s own `wc` disassembly, data dump and configuration. The generated C is then recompiled with `gcc`. The decompiler needs a hand-written configuration that lists the functions to decompile and their argument registers. Uploads therefore take a binary and a configuration file in the format of the artifact’s `wc.config`. The binary is disassembled with the Space’s `objdump`, and entry addresses do not apply. The configuration’s `Preamble:` section must include the headers the generated C needs, such as `stdint.h` and `stdbool.h`. [SEFM 2020 artifact](https://doi.org/10.5281/zenodo.3952034)## CCS 2024 certificate validation
12 unmodified lines131415161718192021222324252670 unmodified lines97989910010110210310410510610710810920 unmodified lines13013113213313413513611 unmodified lines14814915015115215315415515673 unmodified lines23023123223323423523623723823924024124224324424524624724824925012 unmodified linesfrom ccs import stages as ccs_stagesfrom runner import DEADLINE, MAX_UPLOAD, pldi, read_preview, stage_uploadfrom sefm import stages as sefm_stagesARTIFACTS = {"PLDI 2022 · SSM Construction": ("simple_local_array", DEADLINE, pldi),"CCS 2024 · Verified lifting": ("wc", 480, ccs_stages),"SEFM 2020 · C decompilation": ("wc", 120, sefm_stages),}EXAMPLE_ONLY = {sefm_stages}EXAMPLE = "Built-in example"UPLOAD = "Upload a binary"DISPLAY_LIMIT = 4 * 1024 * 102470 unmodified linesraise ValueError("Enter valid positive entry addresses.")if workflow is pldi and len(entries) > 1:raise ValueError("PLDI accepts one starting address.")return entriesdef input_controls(artifact):example_name, _, _ = ARTIFACTS[artifact]choices = [(f"{EXAMPLE} · {example_name}", EXAMPLE), (UPLOAD, UPLOAD)][:1 if ARTIFACTS[artifact][2] in EXAMPLE_ONLY else 2]return gr.update(choices=choices, value=EXAMPLE), gr.update(visible=False), None, ""def updates(workflow):20 unmodified linesyield valuedef run_example(artifact, mode=EXAMPLE, upload=None, addresses=""):yield "Running", "", gr.update(interactive=False)if artifact not in ARTIFACTS:yield "Choose an available artifact.", "", gr.update(interactive=True)11 unmodified linesmatch mode:case "Built-in example":passcase "Upload a binary" if upload and workflow not in EXAMPLE_ONLY:entries = entry_addresses(addresses or "", workflow)arguments = {"binary": stage_upload(upload, work, entries), "entries": entries}case _:raise ValueError("Choose a built-in example or upload a binary.")files = ()73 unmodified lines) as demo: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} · 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 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())artifact.input(input_controls, artifact, [mode, upload_inputs, upload, addresses], queue=False, api_name=False)mode.input(lambda choice: gr.update(visible=choice == UPLOAD), mode, upload_inputs, queue=False, api_name=False)outputs = [status, results, run]run.click(prepare, outputs=outputs, queue=False, api_name=False).then(run_example, [artifact, mode, upload, addresses], outputs, concurrency_limit=1, api_name="run",)12 unmodified lines1314151617181920212223242570 unmodified lines9697989910010110210310410510610710810911011111211311411520 unmodified lines13613713813914014114211 unmodified lines15415515615715815916016116216316416516673 unmodified lines24024124224324424524624724824925025125225325425525625725825926026112 unmodified linesfrom ccs import stages as ccs_stagesfrom runner import DEADLINE, MAX_UPLOAD, pldi, read_preview, stage_uploadfrom sefm import stage_config, stages as sefm_stagesARTIFACTS = {"SEFM 2020 · C decompilation": ("wc", 120, sefm_stages),"PLDI 2022 · SSM Construction": ("simple_local_array", DEADLINE, pldi),"CCS 2024 · Verified lifting": ("wc", 480, ccs_stages),}EXAMPLE = "Built-in example"UPLOAD = "Upload a binary"DISPLAY_LIMIT = 4 * 1024 * 102470 unmodified linesraise ValueError("Enter valid positive entry addresses.")if workflow is pldi and len(entries) > 1:raise ValueError("PLDI accepts one starting address.")if workflow is sefm_stages and entries:raise ValueError("SEFM takes its functions from the configuration file.")return entriesdef input_choices(example_name):return [(f"{EXAMPLE} · {example_name}", EXAMPLE), (UPLOAD, UPLOAD)]def input_controls(artifact):example_name, _, workflow = ARTIFACTS[artifact]needs_config = workflow is sefm_stagesreturn (gr.update(choices=input_choices(example_name), value=EXAMPLE), gr.update(visible=False), None,gr.update(value="", visible=not needs_config), gr.update(value=None, visible=needs_config))def updates(workflow):20 unmodified linesyield valuedef run_example(artifact, mode=EXAMPLE, upload=None, addresses="", config=None):yield "Running", "", gr.update(interactive=False)if artifact not in ARTIFACTS:yield "Choose an available artifact.", "", gr.update(interactive=True)11 unmodified linesmatch mode:case "Built-in example":passcase "Upload a binary" if upload:entries = entry_addresses(addresses or "", workflow)arguments = {"binary": stage_upload(upload, work, entries), "entries": entries}if workflow is sefm_stages:if not config:raise ValueError("Upload the decompiler configuration file as well.")arguments["config"] = stage_config(config, work)case _:raise ValueError("Choose a built-in example or upload a binary.")files = ()73 unmodified lines) as demo: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(input_choices(next(iter(ARTIFACTS.values()))[0]), value=EXAMPLE, label="Input")with gr.Column(visible=False) as upload_inputs:upload = gr.File(label="Linux x86-64 ELF binary", type="filepath")config = gr.File(label="Decompiler configuration (see wc.config in the SEFM artifact)", type="filepath")addresses = gr.Textbox(label="Entry addresses (optional)", placeholder="0x401000", visible=False)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())artifact.input(input_controls, artifact, [mode, upload_inputs, upload, addresses, config], queue=False, api_name=False)mode.input(lambda choice: gr.update(visible=choice == UPLOAD), mode, upload_inputs, queue=False, api_name=False)outputs = [status, results, run]run.click(prepare, outputs=outputs, queue=False, api_name=False).then(run_example, [artifact, mode, upload, addresses, config], outputs, concurrency_limit=1, api_name="run",)
8 unmodified lines91011128 unmodified lines| CCS 2024 poster · Formally Verified Binary Lifting to P-Code | Uses Isabelle to study whether lifting x86-64 assembly to Ghidra P-Code preserves instruction behavior. [Poster paper](https://doi.org/10.1145/3658644.3691386) | Catalog only || TAP 2023 · BIRD | Coq formalization of an intermediate representation for x86-64 decompilation. [Paper](https://ssrg.ece.vt.edu/papers/tap23-bird.pdf) · [Coq artifact](https://zenodo.org/records/7928216) | Catalog only || VSTTE 2022 · A Formal Semantics for P-Code | Defines an executable semantics for extended Ghidra P-Code. [Paper](https://doi.org/10.1007/978-3-031-25803-9_7) · [Haskell interpreter](https://github.com/niconaus/pcode-interpreter) · [Ghidra export script](https://github.com/niconaus/PCode-Dump) | Catalog only || SEFM 2020 · Sound C Code Decompilation for a Subset of x86-64 Binaries | Formalizes three phases of x86-64 decompilation to C. Decompiles the paper’s `wc` disassembly to C and recompiles it. [Paper](https://www.ssrg.ece.vt.edu/papers/sefm20.pdf) · [Archived artifact](https://doi.org/10.5281/zenodo.3952034) · [Project materials](https://ssrg-vt.github.io/FoxDec/#foxdec-10-decompilation-to-c) | Built-in example. Uploads need a hand-written configuration, so they are not offered. Isabelle proof available upstream. |8 unmodified lines91011128 unmodified lines| CCS 2024 poster · Formally Verified Binary Lifting to P-Code | Uses Isabelle to study whether lifting x86-64 assembly to Ghidra P-Code preserves instruction behavior. [Poster paper](https://doi.org/10.1145/3658644.3691386) | Catalog only || TAP 2023 · BIRD | Coq formalization of an intermediate representation for x86-64 decompilation. [Paper](https://ssrg.ece.vt.edu/papers/tap23-bird.pdf) · [Coq artifact](https://zenodo.org/records/7928216) | Catalog only || VSTTE 2022 · A Formal Semantics for P-Code | Defines an executable semantics for extended Ghidra P-Code. [Paper](https://doi.org/10.1007/978-3-031-25803-9_7) · [Haskell interpreter](https://github.com/niconaus/pcode-interpreter) · [Ghidra export script](https://github.com/niconaus/PCode-Dump) | Catalog only || SEFM 2020 · Sound C Code Decompilation for a Subset of x86-64 Binaries | Formalizes three phases of x86-64 decompilation to C. Decompiles the paper’s `wc` disassembly to C and recompiles it. [Paper](https://www.ssrg.ece.vt.edu/papers/sefm20.pdf) · [Archived artifact](https://doi.org/10.5281/zenodo.3952034) · [Project materials](https://ssrg-vt.github.io/FoxDec/#foxdec-10-decompilation-to-c) | Built-in example and binary uploads with a configuration file. Isabelle proof available upstream. |
123456789101112131415161718192021import osimport shutilfrom runner import ROOT, require_outputs, run_commandTOOL = ROOT / "sefm"def stages(work, log, deadline, **_):env = dict(os.environ, LANG="C.UTF-8")for source in (*(TOOL / "example").iterdir(), TOOL / "preamble.c", TOOL / "bit_operations.c"):shutil.copy(source, work)yield "Decompiling the disassembly to C…", ()analysis = work / "decompilation.txt"run_command([TOOL / "bin/main", "wc.objdump", "wc.data", "wc.config", "-c"],work, log, deadline, env=env, stdout=analysis)generated = work / "generated.c"require_outputs(analysis, generated)yield "Recompiling the generated C…", ()run_command(["gcc", "-c", "-w", generated.name, "-o", "generated.o"], work, log, deadline)yield "The generated C recompiles.", [generated, analysis, work / "wc.config", log]1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import osimport reimport shutilfrom runner import ROOT, read_preview, require_outputs, run_commandTOOL = ROOT / "sefm"MAX_CONFIG = 1024 * 1024DISASSEMBLY = {"objdump": ["-M", "intel", "-M", "hex", "--no-show-raw-insn", "-d"],"data": ["-s"],}# The artifact's parser targets binutils 2.26. Newer objdump adds instruction prefixes# and endbr64, a no-op hint, which it cannot parse.PREFIXES = re.compile(r"\t(?:(?:cs|data16|notrack|bnd) )+")ENDBR = re.compile(r"\tendbr64\b")def normalize(disassembly):disassembly.write_text(ENDBR.sub("\tnop", PREFIXES.sub("\t", disassembly.read_text(errors="replace"))))def stage_config(source, work):with open(source, "rb") as stream:data = stream.read(MAX_CONFIG + 1)if len(data) > MAX_CONFIG:raise ValueError("Choose a configuration file no larger than 1 MiB.")try:text = data.decode()except UnicodeDecodeError:raise ValueError("The configuration must be a UTF-8 text file.") from Noneif not text.startswith("Text sections:"):raise ValueError("The configuration must start with “Text sections:”. See wc.config in the artifact.")config = work / "uploaded.config"config.write_text(text)return configdef stages(work, log, deadline, *, binary=None, config=None, entries=()):env = dict(os.environ, LANG="C.UTF-8")custom = binary is not Nonefor source in (TOOL / "preamble.c", TOOL / "bit_operations.c"):shutil.copy(source, work)if custom:name = binary.nameyield "Disassembling the binary…", ()for suffix, flags in DISASSEMBLY.items():run_command(["objdump", *flags, name], work, log, deadline,stdout=work / f"{name}.{suffix}", limit_output=True)normalize(work / f"{name}.objdump")else:name = "wc"for source in (TOOL / "example").iterdir():shutil.copy(source, work)yield "Decompiling the disassembly to C…", ()analysis, generated = work / "decompilation.txt", work / "generated.c"run_command([TOOL / "bin/main", f"{name}.objdump", f"{name}.data", f"{name}.config", "-c"],work, log, deadline, env=env, stdout=analysis, limit_output=custom)if not generated.is_file():with log.open("a") as diagnostics:print(read_preview(analysis, tail=True)[-2000:], file=diagnostics)raise RuntimeError("The decompiler produced no C code. Check the configuration and that the binary stays within the paper’s subset.")require_outputs(analysis, generated)yield "Recompiling the generated C…", ()run_command(["gcc", "-c", "-w", generated.name, "-o", "generated.o"], work, log, deadline, limit_output=custom)yield "The generated C recompiles.", [generated, analysis, work / f"{name}.config", log]
README.md+2-2
app.py+23-12
catalog.md+1-1
sefm.py+56-9