From 1268be93f433f09bf21a51d5a7a97ab561166cb7 Mon Sep 17 00:00:00 2001 From: kunalsz Date: Thu, 2 Apr 2026 15:02:44 +0530 Subject: [PATCH] Add loop BB range extraction Signed-off-by: kunalsz --- floss/features/extract.py | 12 ++++++++++-- floss/features/features.py | 3 ++- floss/main.py | 12 ++++++++---- tests/test_load.py | 6 ++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/floss/features/extract.py b/floss/features/extract.py index f79bbf880..fca7e4dec 100644 --- a/floss/features/extract.py +++ b/floss/features/extract.py @@ -291,6 +291,7 @@ def extract_function_loop(f): parse if a function has a loop """ edges = [] + bb_by_va = {bb.va: bb for bb in f.basic_blocks} for bb in f.basic_blocks: if len(bb.instructions) > 0: @@ -313,8 +314,15 @@ def extract_function_loop(f): comps = strongly_connected_components(g) for comp in comps: if len(comp) >= 2: - # TODO get list of bb start/end eas - yield Loop(comp) + loop_bb_ranges = [] + for bb_va in sorted(comp): + bb = bb_by_va.get(bb_va) + if bb is None: + continue + + loop_bb_ranges.append((bb.va, bb.va + bb.size)) + + yield Loop(comp, bb_ranges=loop_bb_ranges) FUNCTION_HANDLERS = ( diff --git a/floss/features/features.py b/floss/features/features.py index 1ea341d87..c8e1778ff 100644 --- a/floss/features/features.py +++ b/floss/features/features.py @@ -172,10 +172,11 @@ def score(self): class Loop(Feature): weight = MEDIUM - def __init__(self, comp): + def __init__(self, comp, bb_ranges=None): super(Loop, self).__init__(len(comp)) self.comp = comp + self.bb_ranges = bb_ranges or [] def score(self): return 1.0 diff --git a/floss/main.py b/floss/main.py index 6a56f28b2..9892552e0 100644 --- a/floss/main.py +++ b/floss/main.py @@ -126,7 +126,8 @@ def make_parser(argv): " 1. Go: strings from binaries written in Go\n" " 2. Rust: strings from binaries written in Rust\n" ) - epilog = textwrap.dedent(""" + epilog = textwrap.dedent( + """ only displaying core arguments, run `floss -H` to see all supported options examples: @@ -138,8 +139,10 @@ def make_parser(argv): only extract stack and tight strings floss --only stack tight -- suspicious.exe - """) - epilog_advanced = textwrap.dedent(""" + """ + ) + epilog_advanced = textwrap.dedent( + """ examples: extract all strings from 32-bit shellcode floss -f sc32 shellcode.bin @@ -149,7 +152,8 @@ def make_parser(argv): extract strings from a binary written in Go (if automatic language identification fails) floss --language go program.exe - """) + """ + ) show_all_options = "-H" in argv diff --git a/tests/test_load.py b/tests/test_load.py index 0ccca6f92..5cf505660 100644 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -3,7 +3,8 @@ import floss.main # floss --no static -j tests/data/src/decode-in-place/bin/test-decode-in-place.exe -RESULTS = textwrap.dedent(""" +RESULTS = textwrap.dedent( + """ { "analysis": { "enable_decoded_strings": true, @@ -83,7 +84,8 @@ "tight_strings": [] } } -""") +""" +) def test_load(tmp_path):