-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move pytest_ofrak ELF objects to LFS instead of written on every func…
…tion
- Loading branch information
Showing
11 changed files
with
165 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
CC=gcc | ||
|
||
default: program | ||
|
||
program.o: program.c $(HEADERS) | ||
$(CC) -c program.c -fno-asynchronous-unwind-tables -o program.o | ||
|
||
program: program.o | ||
$(CC) program.o -o program | ||
|
||
program_no_reloc: program.o | ||
$(CC) program.o -no-pie -o program_no_reloc | ||
|
||
program_relocated: program_relocated.o | ||
$(CC) program_relocated.o -o program_relocated | ||
|
||
large_elf.o: large_elf.c $(HEADERS) | ||
$(CC) -c large_elf.c -o large_elf.o | ||
|
||
large_elf: large_elf.o | ||
$(CC) large_elf.o -no-pie -o large_elf |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
#include <stdio.h> | ||
|
||
int foo(); | ||
int bar(); | ||
|
||
int main() { | ||
printf("Hello, World!\n"); | ||
return foo(); | ||
} | ||
|
||
int foo() { | ||
return 12; | ||
} | ||
|
||
int bar() { | ||
return 24; | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
int noop0(); | ||
|
||
int baz() | ||
{ | ||
noop0(); | ||
return 36; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,164 @@ | ||
import os | ||
import subprocess | ||
|
||
# import subprocess | ||
|
||
import pytest | ||
|
||
|
||
MAKEFILE_CONTENTS = """ | ||
CC=gcc | ||
# MAKEFILE_CONTENTS = """ | ||
# CC=gcc | ||
|
||
# default: program | ||
|
||
default: program | ||
# program.o: program.c $(HEADERS) | ||
# $(CC) -c program.c -fno-asynchronous-unwind-tables -o program.o | ||
|
||
program.o: program.c $(HEADERS) | ||
$(CC) -c program.c -fno-asynchronous-unwind-tables -o program.o | ||
# program: program.o | ||
# $(CC) program.o -o program | ||
|
||
program: program.o | ||
$(CC) program.o -o program | ||
# program_no_reloc: program.o | ||
# $(CC) program.o -no-pie -o program_no_reloc | ||
|
||
program_no_reloc: program.o | ||
$(CC) program.o -no-pie -o program_no_reloc | ||
# program_relocated: program_relocated.o | ||
# $(CC) program_relocated.o -o program_relocated | ||
|
||
program_relocated: program_relocated.o | ||
$(CC) program_relocated.o -o program_relocated | ||
# large_elf.o: large_elf.c $(HEADERS) | ||
# $(CC) -c large_elf.c -o large_elf.o | ||
|
||
large_elf.o: large_elf.c $(HEADERS) | ||
$(CC) -c large_elf.c -o large_elf.o | ||
# large_elf: large_elf.o | ||
# $(CC) large_elf.o -no-pie -o large_elf | ||
# """ | ||
|
||
large_elf: large_elf.o | ||
$(CC) large_elf.o -no-pie -o large_elf | ||
""" | ||
# C_SOURCE_CONTENTS = """ | ||
# #include <stdio.h> | ||
|
||
C_SOURCE_CONTENTS = """ | ||
#include <stdio.h> | ||
# int foo(); | ||
# int bar(); | ||
|
||
int foo(); | ||
int bar(); | ||
# int main() { | ||
# printf("Hello, World!\\n"); | ||
# return foo(); | ||
# } | ||
|
||
int main() { | ||
printf("Hello, World!\\n"); | ||
return foo(); | ||
} | ||
# int foo() { | ||
# return 12; | ||
# } | ||
|
||
int foo() { | ||
return 12; | ||
} | ||
# int bar() { | ||
# return 24; | ||
# } | ||
|
||
int bar() { | ||
return 24; | ||
} | ||
|
||
# """ | ||
|
||
""" | ||
# LARGE_SOURCE_CONTENTS_HEADER = """ | ||
# int foo(); | ||
# int bar(); | ||
|
||
LARGE_SOURCE_CONTENTS_HEADER = """ | ||
int foo(); | ||
int bar(); | ||
# int main() { | ||
# return bar(); | ||
# } | ||
|
||
int main() { | ||
return bar(); | ||
} | ||
# """ | ||
|
||
""" | ||
# LARGE_SOURCE_CONTENTS_FOOTER = """ | ||
|
||
LARGE_SOURCE_CONTENTS_FOOTER = """ | ||
# int foo() { | ||
# return 12; | ||
# } | ||
|
||
int foo() { | ||
return 12; | ||
} | ||
# int bar() { | ||
# return 24; | ||
# } | ||
|
||
int bar() { | ||
return 24; | ||
} | ||
|
||
# """ | ||
|
||
""" | ||
# PATCH_CONTENTS = """ | ||
# int noop0(); | ||
|
||
PATCH_CONTENTS = """ | ||
int noop0(); | ||
# int baz() | ||
# { | ||
# noop0(); | ||
# return 36; | ||
# } | ||
# """ | ||
|
||
int baz() | ||
{ | ||
noop0(); | ||
return 36; | ||
} | ||
""" | ||
|
||
# def create_noops(): | ||
# noops = [] | ||
|
||
def create_noops(): | ||
noops = [] | ||
# i = 0 | ||
|
||
i = 0 | ||
# for i in range(8000): | ||
# instruction = f"int noop{i}(){{}}" | ||
# noops.append(instruction) | ||
|
||
for i in range(8000): | ||
instruction = f"int noop{i}(){{}}" | ||
noops.append(instruction) | ||
# return noops | ||
|
||
return noops | ||
|
||
@pytest.fixture(scope="session") | ||
def elf_test_directory(): | ||
return os.path.join(os.path.dirname(__file__), "assets") | ||
|
||
@pytest.fixture | ||
def elf_test_directory(tmpdir): | ||
makefile_path = os.path.join(tmpdir, "Makefile") | ||
c_source_path = os.path.join(tmpdir, "program.c") | ||
large_source_path = os.path.join(tmpdir, "large_elf.c") | ||
# makefile_path = os.path.join(tmpdir, "Makefile") | ||
# c_source_path = os.path.join(tmpdir, "program.c") | ||
# large_source_path = os.path.join(tmpdir, "large_elf.c") | ||
|
||
patch_dir = os.path.join(tmpdir, "source_dir") | ||
if not os.path.exists(patch_dir): | ||
os.mkdir(patch_dir) | ||
patch_path = os.path.join(patch_dir, "patch.c") | ||
# patch_dir = os.path.join(tmpdir, "source_dir") | ||
# if not os.path.exists(patch_dir): | ||
# os.mkdir(patch_dir) | ||
# patch_path = os.path.join(patch_dir, "patch.c") | ||
|
||
noops = create_noops() | ||
# noops = create_noops() | ||
|
||
LARGE_SOURCE_CONTENTS = LARGE_SOURCE_CONTENTS_HEADER | ||
for noop in noops: | ||
LARGE_SOURCE_CONTENTS += noop | ||
LARGE_SOURCE_CONTENTS += LARGE_SOURCE_CONTENTS_FOOTER | ||
# LARGE_SOURCE_CONTENTS = LARGE_SOURCE_CONTENTS_HEADER | ||
# for noop in noops: | ||
# LARGE_SOURCE_CONTENTS += noop | ||
# LARGE_SOURCE_CONTENTS += LARGE_SOURCE_CONTENTS_FOOTER | ||
|
||
with open(makefile_path, "w") as f: | ||
f.write(MAKEFILE_CONTENTS) | ||
with open(c_source_path, "w") as f: | ||
f.write(C_SOURCE_CONTENTS) | ||
with open(large_source_path, "w") as f: | ||
f.write(LARGE_SOURCE_CONTENTS) | ||
with open(patch_path, "w") as f: | ||
f.write(PATCH_CONTENTS) | ||
# with open(makefile_path, "w") as f: | ||
# f.write(MAKEFILE_CONTENTS) | ||
# with open(c_source_path, "w") as f: | ||
# f.write(C_SOURCE_CONTENTS) | ||
# with open(large_source_path, "w") as f: | ||
# f.write(LARGE_SOURCE_CONTENTS) | ||
# with open(patch_path, "w") as f: | ||
# f.write(PATCH_CONTENTS) | ||
|
||
return tmpdir | ||
# return tmpdir | ||
|
||
|
||
@pytest.fixture | ||
def elf_object_file(elf_test_directory, skipif_windows): | ||
subprocess.run(["make", "-C", elf_test_directory, "program.o"]) | ||
@pytest.fixture(scope="session") | ||
def elf_object_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "program.o") | ||
|
||
|
||
@pytest.fixture | ||
def elf_executable_file(elf_test_directory, skipif_windows): | ||
subprocess.run(["make", "-C", elf_test_directory, "program"]) | ||
@pytest.fixture(scope="session") | ||
def elf_executable_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "program") | ||
|
||
|
||
@pytest.fixture | ||
def elf_no_pie_executable_file(elf_test_directory, skipif_windows): | ||
subprocess.run(["make", "-C", elf_test_directory, "program_no_reloc"]) | ||
@pytest.fixture(scope="session") | ||
def elf_no_pie_executable_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "program_no_reloc") | ||
|
||
|
||
@pytest.fixture | ||
@pytest.fixture(scope="session") | ||
def large_elf_source_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "large_elf.c") | ||
|
||
|
||
@pytest.fixture | ||
def large_elf_object_file(elf_test_directory, skipif_windows): | ||
subprocess.run(["make", "-C", elf_test_directory, "large_elf.o"]) | ||
@pytest.fixture(scope="session") | ||
def large_elf_object_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "large_elf.o") | ||
|
||
|
||
@pytest.fixture | ||
def large_elf_file(elf_test_directory, skipif_windows): | ||
subprocess.run(["make", "-C", elf_test_directory, "large_elf"]) | ||
@pytest.fixture(scope="session") | ||
def large_elf_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "large_elf") | ||
|
||
|
||
@pytest.fixture | ||
@pytest.fixture(scope="session") | ||
def patch_file(elf_test_directory): | ||
return os.path.join(elf_test_directory, "source_dir", "patch.c") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters