Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verbose output of file offsets and virtual addresses for language-specific strings #1019

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions floss/language/rust/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ def get_static_strings_from_rdata(sample, static_strings) -> List[StaticString]:
return list(filter(lambda s: start_rdata <= s.offset < end_rdata, static_strings))


def get_file_offset_in_rdata(sample: pathlib.Path) -> int:
pe = pefile.PE(data=pathlib.Path(sample).read_bytes(), fast_load=True)

try:
rdata_section = get_rdata_section(pe)
except ValueError:
return -1

image_base = pe.OPTIONAL_HEADER.ImageBase
virtual_address = rdata_section.VirtualAddress
pointer_to_raw_data = rdata_section.PointerToRawData

print("DD:", image_base + virtual_address - pointer_to_raw_data)
Arker123 marked this conversation as resolved.
Show resolved Hide resolved

return image_base + virtual_address - pointer_to_raw_data


def get_string_blob_strings(pe: pefile.PE, min_length: int) -> Iterable[StaticString]:
image_base = pe.OPTIONAL_HEADER.ImageBase

Expand Down
5 changes: 5 additions & 0 deletions floss/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,11 @@ def main(argv=None) -> int:
results.strings.language_strings_missed = floss.language.utils.get_missed_strings(
rdata_strings, results.strings.language_strings, args.min_length
)

# get the file offset diff file offset and va
if args.verbose:
results.metadata.file_offset_in_rdata = floss.language.rust.extract.get_file_offset_in_rdata(sample)

if (
results.analysis.enable_decoded_strings
or results.analysis.enable_stack_strings
Expand Down
7 changes: 5 additions & 2 deletions floss/render/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def strtime(seconds):
return f"{m:02.0f}:{s:02.0f}"


def render_language_strings(language, language_strings, language_strings_missed, console, verbose, disable_headers):
def render_language_strings(
language, language_strings, language_strings_missed, file_offset, console, verbose, disable_headers
):
strings = sorted(language_strings + language_strings_missed, key=lambda s: s.offset)
render_heading(f"FLOSS {language.upper()} STRINGS ({len(strings)})", console, verbose, disable_headers)
offset_len = len(f"{strings[-1].offset}")
Expand All @@ -167,7 +169,7 @@ def render_language_strings(language, language_strings, language_strings_missed,
console.print(sanitize(s.string, is_ascii_only=False), markup=False)
else:
colored_string = string_style(sanitize(s.string, is_ascii_only=False))
console.print(f"0x{s.offset:>0{offset_len}x} {colored_string}")
console.print(f"0x{s.offset:>0{offset_len}x} 0x{s.offset + file_offset:>0{offset_len}x} {colored_string}")


def render_static_substrings(strings, encoding, offset_len, console, verbose, disable_headers):
Expand Down Expand Up @@ -340,6 +342,7 @@ def render(results: floss.results.ResultDocument, verbose, disable_headers, colo
results.metadata.language,
results.strings.language_strings,
results.strings.language_strings_missed,
results.metadata.file_offset_in_rdata,
console,
verbose,
disable_headers,
Expand Down
3 changes: 2 additions & 1 deletion floss/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import datetime
from enum import Enum
from typing import Dict, List
from typing import Dict, List, Optional
from pathlib import Path
from dataclasses import field

Expand Down Expand Up @@ -194,6 +194,7 @@ class Metadata:
language: str = ""
language_version: str = ""
language_selected: str = "" # configured by user
file_offset_in_rdata: Optional[int] = None


@dataclass
Expand Down
Loading