Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
williballenthin authored Aug 1, 2023
2 parents cfce296 + 79809d2 commit de76629
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions floss/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,11 @@ def main(argv=None) -> int:
# can throw away result later if not desired in output
time0 = time()
interim = time0

static_strings = get_static_strings(sample, args.min_length)
if static_strings == []:
return 0

static_runtime = get_runtime_diff(interim)

lang_id = identify_language(sample, static_strings)
Expand Down
2 changes: 0 additions & 2 deletions floss/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def from_utf8(cls, buf, addr, min_length):
except UnicodeDecodeError:
raise ValueError("not utf-8")

if not decoded_string.isprintable():
raise ValueError("not printable")
if len(decoded_string) < min_length:
raise ValueError("too short")
return cls(string=decoded_string, offset=addr, encoding=StringEncoding.UTF8)
Expand Down
5 changes: 5 additions & 0 deletions floss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ def get_static_strings(sample: Path, min_length: int) -> list:
"""
Returns list of static strings from the file which are above the minimum length
"""

if sample.stat().st_size == 0:
logger.warning("File is empty")
return []

with sample.open("r") as f:
if hasattr(mmap, "MAP_PRIVATE"):
# unix
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
extras_require={
"dev": [
"pre-commit==2.21.0",
"pyyaml==6.0",
"pyyaml==6.0.1",
"pytest==7.4.0",
"pytest-sugar==0.9.4",
"pytest-instafail==0.5.0",
Expand All @@ -68,7 +68,7 @@
"mypy==1.4.1",
# type stubs for mypy
"types-PyYAML==6.0.10",
"types-tabulate==0.9.0.2",
"types-tabulate==0.9.0.3",
],
"build": [
"pyinstaller==5.13.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/data
Submodule data updated 31 files
+1 −0 .gitattributes
+ language/dotnet/dotnet-hello/bin/dotnet-hello.exe
+0 −0 language/dotnet/dotnet-hello/hello-world.cs
+21 −0 language/go/go-binaries-all-versions/Readme.md
+ language/go/go-binaries-all-versions/bin/versions_32.zip
+ language/go/go-binaries-all-versions/bin/versions_64.zip
+4 −0 language/go/go-binaries-all-versions/go.mod
+91 −0 language/go/go-binaries-all-versions/go_binary_generator.py
+20 −0 language/go/go-binaries-all-versions/main32.go
+20 −0 language/go/go-binaries-all-versions/main64.go
+ language/go/go-hello/bin/go-hello
+ language/go/go-hello/bin/go-hello.exe
+ language/go/go-hello/bin/go-hello64.exe
+0 −0 language/go/go-hello/go-hello.go
+0 −0 language/go/go-hello/go.mod
+16 −0 language/go/go-unknown-binaries/Readme.md
+ language/go/go-unknown-binaries/bin/386_go1.12
+ language/go/go-unknown-binaries/bin/386_go1.16
+ language/go/go-unknown-binaries/bin/386_go1.18
+ language/go/go-unknown-binaries/bin/386_go1.20
+ language/go/go-unknown-binaries/bin/amd64_go1.12
+ language/go/go-unknown-binaries/bin/amd64_go1.16
+ language/go/go-unknown-binaries/bin/amd64_go1.18
+ language/go/go-unknown-binaries/bin/amd64_go1.20
+0 −0 language/rust/rust-hello/Cargo.lock
+0 −0 language/rust/rust-hello/Cargo.toml
+0 −0 language/rust/rust-hello/Readme.md
+ language/rust/rust-hello/bin/hello-world-cargo
+ language/rust/rust-hello/bin/rust-hello.exe
+ language/rust/rust-hello/bin/rust-hello64.exe
+0 −0 language/rust/rust-hello/src/main.rs
19 changes: 17 additions & 2 deletions tests/test_language_extract_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
@pytest.fixture(scope="module")
def go_strings32():
n = 6
path = pathlib.Path(__file__).parent / "data" / "src" / "go-hello" / "bin" / "go-hello.exe"
path = pathlib.Path(__file__).parent / "data" / "language" / "go" / "go-hello" / "bin" / "go-hello.exe"
return extract_go_strings(path, n)


@pytest.fixture(scope="module")
def go_strings64():
n = 6
path = pathlib.Path(__file__).parent / "data" / "src" / "go-hello" / "bin" / "go-hello64.exe"
path = pathlib.Path(__file__).parent / "data" / "language" / "go" / "go-hello" / "bin" / "go-hello64.exe"
return extract_go_strings(path, n)


Expand Down Expand Up @@ -124,6 +124,21 @@ def test_mov_lea_mov(request, string, offset, encoding, go_strings):
assert StaticString(string=string, offset=offset, encoding=encoding) in request.getfixturevalue(go_strings)


@pytest.mark.parametrize(
"string,offset,encoding,go_strings",
[
# 00000000004AB080 20 6E 6F 74 20 66 6F 75 6E 64 20 6D 61 72 6B 72 not found markr
# 00000000004AB090 6F 6F 74 20 6A 6F 62 73 20 64 6F 6E 65 0A 20 74 oot jobs done. t
pytest.param(" markroot jobs done\n", 0xAA68A, StringEncoding.UTF8, "go_strings64"),
# 004A3DE0 66 6F 75 6E 64 20 6D 61 72 6B 72 6F 6F 74 20 6A found markroot j
# 004A3DF0 6F 62 73 20 64 6F 6E 65 0A 20 74 6F 20 75 6E 61 obs done. to una
pytest.param(" markroot jobs done\n", 0xA23E5, StringEncoding.UTF8, "go_strings32"),
],
)
def test_strings_with_newline_char_0A(request, string, offset, encoding, go_strings):
assert StaticString(string=string, offset=offset, encoding=encoding) in request.getfixturevalue(go_strings)


@pytest.mark.skip(reason="not extracted via go_strings")
@pytest.mark.parametrize(
"string,offset,encoding,go_strings",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_language_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
@pytest.mark.parametrize(
"binary_file, expected_result",
[
("data/src/go-hello/bin/go-hello.exe", Language.GO),
("data/src/rust-hello/bin/rust-hello.exe", Language.RUST),
("data/language/go/go-hello/bin/go-hello.exe", Language.GO),
("data/language/rust/rust-hello/bin/rust-hello.exe", Language.RUST),
("data/test-decode-to-stack.exe", Language.UNKNOWN),
("data/src/dotnet-hello/bin/dotnet-hello.exe", Language.DOTNET),
("data/language/dotnet/dotnet-hello/bin/dotnet-hello.exe", Language.DOTNET),
("data/src/shellcode-stackstrings/bin/shellcode-stackstrings.bin", Language.UNKNOWN),
],
)
Expand Down

0 comments on commit de76629

Please sign in to comment.