Skip to content

Commit

Permalink
More i386 xrefs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arker123 committed Nov 9, 2023
1 parent 9405cb8 commit afe9a48
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 9 additions & 2 deletions floss/language/rust/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
import binary2strings as b2s

from floss.results import StaticString, StringEncoding
from floss.language.utils import find_lea_xrefs, find_mov_xrefs, find_push_xrefs, get_struct_string_candidates
from floss.language.utils import (
find_lea_xrefs,
find_mov_xrefs,
find_push_xrefs,
get_raw_xrefs_rdata_i386,
get_struct_string_candidates,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -151,7 +157,8 @@ def get_string_blob_strings(pe: pefile.PE, min_length: int) -> Iterable[StaticSt
xrefs_lea = find_lea_xrefs(pe)
xrefs_push = find_push_xrefs(pe)
xrefs_mov = find_mov_xrefs(pe)
xrefs = itertools.chain(struct_string_addrs, xrefs_lea, xrefs_push, xrefs_mov)
xrefs_raw_rdata = get_raw_xrefs_rdata_i386(pe, rdata_section.get_data())
xrefs = itertools.chain(struct_string_addrs, xrefs_lea, xrefs_push, xrefs_mov, xrefs_raw_rdata)

elif pe.FILE_HEADER.Machine == pefile.MACHINE_TYPE["IMAGE_FILE_MACHINE_AMD64"]:
xrefs_lea = find_lea_xrefs(pe)
Expand Down
28 changes: 28 additions & 0 deletions floss/language/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,34 @@ def get_struct_string_candidates(pe: pefile.PE) -> Iterable[StructString]:
# dozens of seconds or more (suspect many minutes).


def get_raw_xrefs_rdata_i386(pe: pefile.PE, buf: bytes) -> Iterable[VA]:
"""
scan for raw xrefs in .rdata section
"""
format = "I"

if not buf:
return

low, high = get_image_range(pe)

# using array module as a high-performance way to access the data as fixed-sized words.
words = iter(array.array(format, buf))

last = next(words)
for current in words:
address = last
last = current

if address == 0x0:
continue

if not (low <= address < high):
continue

yield address


def get_extract_stats(
pe: pefile, all_ss_strings: List[StaticString], lang_strings: List[StaticString], min_len: int, min_blob_len=0
) -> float:
Expand Down

0 comments on commit afe9a48

Please sign in to comment.