Skip to content

Stabilize commons infrastructure for attack_surface_approximation compatibility - #8

Draft
krpandrei05 wants to merge 6 commits into
mainfrom
krpandrei/fix/attack-surface-approximation-support
Draft

Stabilize commons infrastructure for attack_surface_approximation compatibility#8
krpandrei05 wants to merge 6 commits into
mainfrom
krpandrei/fix/attack-surface-approximation-support

Conversation

@krpandrei05

@krpandrei05 krpandrei05 commented May 9, 2026

Copy link
Copy Markdown

Converted filenames to absolute paths before passing them to Docker. This ensures correct bind-mounting and avoids 400 Bad Request errors on Linux hosts.

Fixes: #7, Fixes: #9

Converted filenames to absolute paths before passing them to Docker. This ensures correct bind-mounting and avoids 400 Bad Request errors on Linux hosts.

Fixes: #7
Signed-off-by: Andrei Carp <andrei.krp@gmail.com>
@krpandrei05
krpandrei05 requested a review from razvand May 9, 2026 20:54
@krpandrei05 krpandrei05 self-assigned this May 9, 2026
Added replacements for Ghidra-specific types like undefined8, bool, and uint in the decompiled code. This prevents ParseError when pycparser processes the main function.

Signed-off-by: Andrei Carp <andrei.krp@gmail.com>
…acts

Implemented fallback to Entry Point in decompile_function.py when 'main' is missing. Updated ghidra.py with a robust regex to strip all C-style comments and a cleaner for Ghidra-specific artifacts (processEntry, PTR_FUN_, stack references) to ensure compatibility with pycparser.

Fixes: #9
Signed-off-by: Andrei Carp <andrei.krp@gmail.com>
@krpandrei05
krpandrei05 force-pushed the krpandrei/fix/attack-surface-approximation-support branch from 111731a to 20b423d Compare May 10, 2026 00:46
Updated pyproject.toml to use a fixed Python version (3.12.7) and ensured all core dependencies are pinned to exact versions for consistency across the CRS environment.

Signed-off-by: Andrei Carp <andrei.krp@gmail.com>

@razvand razvand left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a blank line between Fixes and the Signed-off-by message.

Limit commit messages to 72 characters.

Start commit title with capital, i.e. instead of support stripped binaries ..., use Support stripped binaries ...

Use Python instead of python.

@razvand
razvand requested a review from AmaliaI12 June 5, 2026 15:12
krpandrei05 and others added 2 commits August 7, 2026 13:15
Added substitutions for stdint.h exact-width types (uint8_t..uint64_t,
int8_t..int64_t), POSIX public types (ssize_t, pid_t, off_t, uid_t,
gid_t, mode_t, time_t, socklen_t) and their __ variants, preserving
correct replacement order to avoid partial-match corruption (e.g.
ssize_t before size_t, uint32_t before uint). Also broadened PTR_
pattern from PTR_FUN_* to PTR_* to cover global pointer artifacts
such as PTR_stdin_ generated by Ghidra for standard streams.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d glibc macro aliases

Removed duplicate entries from STDIN list. Added missing indicators:
getc/getchar/getline/scanf (STDIN), fopen/open/openat (FILES),
connect/send/sendto/sendmsg (NETWORKING), secure_getenv (ENV).
Added GLIBC_MACRO_EXPANSIONS dict and _with_glibc_aliases() to
automatically include _IO_getc/_IO_getchar alongside their public
macro names, covering glibc binaries where getc expands at compile
time to _IO_getc in the PLT.

Signed-off-by: Andrei Carp <andrei.krp@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve compatibility/stability when commons is used by attack_surface_approximation, primarily by ensuring Docker bind mounts use absolute host paths and by making Ghidra-based decompilation more resilient for stripped binaries / irregular decompiler output.

Changes:

  • Convert analyzed binary filenames to absolute paths before passing them into Docker volume mounts.
  • Expand/adjust static input-stream indicators (including glibc macro expansion aliases and additional sources like env/network/file open calls).
  • Improve Ghidra headless decompilation behavior (fallback function selection + additional decompiled-code cleanup) and pin runtime dependencies.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
pyproject.toml Pins Python and key dependencies to specific versions.
commons/input_streams.py Adds glibc macro alias expansion and broadens input source indicator lists.
commons/ghidra/scripts/decompile_function.py Adds fallback logic to select a function even when the requested symbol isn’t found.
commons/ghidra/ghidra.py Uses absolute paths for Docker mounts and expands decompiled-code normalization/sanitization.
Suppressed comments (2)

commons/ghidra/ghidra.py:131

  • __replace_longs is annotated as returning None, but it returns a transformed string and is used as such by __process_decompiled_code. The return type should be str.
    def __replace_longs(self, code: str) -> None:

commons/ghidra/ghidra.py:175

  • __replace_double_lines is annotated as returning None, but it returns a transformed string and is used as such by __process_decompiled_code. The return type should be str.
    def __replace_double_lines(self, code: str) -> None:

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pyproject.toml
Comment on lines +10 to +12
python = "==3.12.7"
pwntools = "==4.15.0"
docker = "==7.1.0"
Comment on lines +39 to +43
if not function:
entry_points = program.getSymbolTable().getExternalSymbols("entry")
# If still nothing, pick the absolute first function in the manager
if not function:
function = program.getFunctionManager().getFunctions(True).next()
Comment thread commons/ghidra/ghidra.py

return code

def __replace_undefs(self, code: str) -> None:
Comment thread commons/ghidra/ghidra.py
Comment on lines +167 to +173
def __replace_ghidra_artifacts(self, code: str) -> str:
# Remove Ghidra specific keywords and formatting that break pycparser
code = code.replace("processEntry", "")
code = re.sub(r'PTR_\w+', '0', code)
code = re.sub(r'FUN_[0-9a-f]+', '0', code)
code = re.sub(r'&stack0x[0-9a-f]+', '0', code)
return code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants