Spaces:
Running
Running
Commit ·
bf91e21
1
Parent(s): 52a9362
Add Faultless function search example
Browse filesFiles changed (9)
- demo/cases/README.md+3-1
- demo/cases/search_function/candidate.cAdded+14
- demo/cases/search_function/decompiled.cAdded+10
- demo/cases/search_function/metadata.jsonAdded+4
- demo/cases/search_function/original.cAdded+10
- demo/cases/search_function/runnable.jsonAdded+13
- demo/faultless.py+6-4
- tests/test_examples.py+2-2
- tests/test_faultless.py+2
5 unmodified lines678910111221 unmodified lines3435365 unmodified lines- `upper` (aaronokano/ecs150-hw1): The decompiled loop exits through an early break; Faultless loop pairing can be brittle around breaks.- `print_page_header` (achasse/cse220): The original uses a static local integer, represented as a global in the decompiled code; Faultless has difficulty with static integers.The three directories preserve `original.c`, `decompiled.c`, and `metadata.json`from `/tmp/decompile-verify-faultless-examples` unchanged. The metadata recordsthe dataset index, canonical function name, source repository, and Faultless'sreported failure. That failure is distinct from this verifier's result.21 unmodified linespossible; it does not demonstrate real libc string handling or loop equivalence.Agreement for the page header covers the bound counter and intercepted `printf`arguments on tested inputs.5 unmodified lines678910111221 unmodified lines34353637385 unmodified lines- `upper` (aaronokano/ecs150-hw1): The decompiled loop exits through an early break; Faultless loop pairing can be brittle around breaks.- `print_page_header` (achasse/cse220): The original uses a static local integer, represented as a global in the decompiled code; Faultless has difficulty with static integers.The three directories above preserve `original.c`, `decompiled.c`, and `metadata.json`from `/tmp/decompile-verify-faultless-examples` unchanged. The metadata recordsthe dataset index, canonical function name, source repository, and Faultless'sreported failure. That failure is distinct from this verifier's result.21 unmodified linespossible; it does not demonstrate real libc string handling or loop equivalence.Agreement for the page header covers the bound counter and intercepted `printf`arguments on tested inputs.- `search_function`: The supplied pair searches a linked list and returns the matching node. The runnable version assumes the decompiled 64-bit offsets for `Compiler.function_list` and `FunctionDefinition.next`, and restores the pointer return type. `get_current_compiler` and `strcmp` are bound as intercepted callees. Its verifier verdict has not yet been established.
1234567891011121314#include <stdint.h>#include <string.h>
extern void *sub_401A40(void);
void *sub_401B20(char *s2) { uintptr_t i; for (i = *(uintptr_t *)((uintptr_t)sub_401A40() + 8); i; i = *(uintptr_t *)(i + 48)) { if (!strcmp(*(const char **)i, s2)) break; } return (void *)i;}12345678910__int64 __fastcall sub_401B20(char *s2) { __int64 i; for (i = *(_QWORD *)(sub_401A40() + 8); i; i = *(_QWORD *)(i + 48)) { if (!strcmp(*(const char **)i, s2)) break; } return i;}1234{ "name": "search_function", "note": "The decompiled loop exits through a break and returns the matching list node."}12345678910FunctionDefinition * search_function(char *identifier) { Compiler *compiler = get_current_compiler(); FunctionDefinition *fd; for (fd = compiler->function_list; fd; fd = fd->next) { if (!strcmp(fd->name, identifier)) return fd; } return ((void *)0);}12345678910111213{ "original_symbol": "search_function", "candidate_symbol": "sub_401B20", "declarations": "#include <string.h>\ntypedef struct FunctionDefinition { char *name; char padding[40]; struct FunctionDefinition *next; } FunctionDefinition;\ntypedef struct Compiler { char padding[8]; FunctionDefinition *function_list; } Compiler;\nCompiler *get_current_compiler(void);\n", "stubs": "typedef struct Compiler Compiler;\nCompiler *get_current_compiler(void) { return 0; }\nint strcmp(const char *a, const char *b) { return 0; }\n", "callees": { "sub_401A40": "get_current_compiler", "strcmp": "strcmp" }, "interfaces": { "original_prototype": "void *search_function(char *identifier);" }}8 unmodified lines91011121314151617183 unmodified lines222324252627288 unmodified linesCASES = Path(__file__).with_name("cases")NAMES = ("faultless-my-putchar-count", "faultless-upper", "faultless-print-page-header")CASE_NAMES = ("my_putchar_count", "upper", "print_page_header")LABELS = ("Faultless: One-byte write", "Faultless: Uppercase loop","Faultless: Static page counter")def source(name, filename):3 unmodified linesdef metadata(name):info = json.loads(source(name, "metadata.json"))info.update(reference=source(name, "original.c"),expected_verdict="inconclusive" if name == NAMES[0] else "agree")return info8 unmodified lines9101112131415161718193 unmodified lines23242526272829308 unmodified linesCASES = Path(__file__).with_name("cases")NAMES = ("faultless-my-putchar-count", "faultless-upper", "faultless-print-page-header","faultless-search-function")CASE_NAMES = ("my_putchar_count", "upper", "print_page_header", "search_function")LABELS = ("Faultless: One-byte write", "Faultless: Uppercase loop","Faultless: Static page counter", "Faultless: Function search")def source(name, filename):3 unmodified linesdef metadata(name):info = json.loads(source(name, "metadata.json"))info.update(reference=source(name, "original.c"),expected_verdict=(None if name == "faultless-search-function" else"inconclusive" if name == NAMES[0] else "agree"))return info
4 unmodified lines5678910116 unmodified lines181920212223244 unmodified linesdef test_examples_prepare_from_core_checkout(tmp_path):rows = examples.prepare_examples(tmp_path)assert len(rows) == len(examples.EXAMPLE_NAMES) == 63assert len(examples.GHIDRA_EXAMPLE_NAMES) == 21assert all(Path(row[0]).is_file() for row in rows)assert all(Path(row[0]).is_relative_to(tmp_path) for row in rows)6 unmodified linesassert len(members) == len(set(members)) == len(examples.EXAMPLE_NAMES)assert set(members) == set(examples.EXAMPLE_NAMES)groups = examples.example_groups(examples.EXAMPLE_NAMES)assert [len(indices) for _, indices in groups] == [6, 7, 8, 3, 18, 21]for _, indices in groups:assert list(indices) == sorted(indices)4 unmodified lines5678910116 unmodified lines181920212223244 unmodified linesdef test_examples_prepare_from_core_checkout(tmp_path):rows = examples.prepare_examples(tmp_path)assert len(rows) == len(examples.EXAMPLE_NAMES) == 64assert len(examples.GHIDRA_EXAMPLE_NAMES) == 21assert all(Path(row[0]).is_file() for row in rows)assert all(Path(row[0]).is_relative_to(tmp_path) for row in rows)6 unmodified linesassert len(members) == len(set(members)) == len(examples.EXAMPLE_NAMES)assert set(members) == set(examples.EXAMPLE_NAMES)groups = examples.example_groups(examples.EXAMPLE_NAMES)assert [len(indices) for _, indices in groups] == [6, 7, 8, 3, 19, 21]for _, indices in groups:assert list(indices) == sorted(indices)
19 unmodified lines20212223242519 unmodified linesassert len(updates) == seed_count + 1assert report['completed'] == seed_countexpected = example_metadata(name)['expected_verdict']if name == 'faultless-byte-reinterpretation' and compiler == 'clang':# The original is built with gcc, so the escaped frames differ in layout.expected = 'inconclusive'19 unmodified lines202122232425262719 unmodified linesassert len(updates) == seed_count + 1assert report['completed'] == seed_countexpected = example_metadata(name)['expected_verdict']if expected is None:returnif name == 'faultless-byte-reinterpretation' and compiler == 'clang':# The original is built with gcc, so the escaped frames differ in layout.expected = 'inconclusive'
demo/cases/README.md+3-1
demo/cases/search_function/candidate.cAdded+14
demo/cases/search_function/decompiled.cAdded+10
demo/cases/search_function/metadata.jsonAdded+4
demo/cases/search_function/original.cAdded+10
demo/cases/search_function/runnable.jsonAdded+13
demo/faultless.py+6-4
tests/test_examples.py+2-2
tests/test_faultless.py+2