Skip to content

More elf os detection cases#3099

Open
williballenthin wants to merge 2 commits into
masterfrom
more-elf-os-detection-cases
Open

More elf os detection cases#3099
williballenthin wants to merge 2 commits into
masterfrom
more-elf-os-detection-cases

Conversation

@williballenthin

Copy link
Copy Markdown
Collaborator

review after #3098
uses new ELF test files from mandiant/capa-testfiles#313

  ┌─────────────────┬────────┬──────────────────────┬───────────────────────────────────────────────────────────────┐
  │      File       │  Size  │       Purpose        │                     Strategies Exercised                      │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ 9486f2c5...elf_ │ 9.4KB  │ osabi=freebsd        │ osabi (only)                                                  │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ a72ac9f1...elf_ │ 7.4KB  │ osabi=openbsd        │ osabi (only)                                                  │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ 5e426357...elf_ │ 1.9KB  │ osabi=hpux           │ osabi (only)                                                  │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ ccb5eefc...elf_ │ 263KB  │ vdso aarch64         │ ident_directive, vdso_strings                                 │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ c2b2d7ce...elf_ │ 65KB   │ linker lean          │ ph_notes, linker (only 2 signals; section headers unreadable) │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ fb5cf3df...elf_ │ 5.8MB  │ go_source FreeBSD    │ osabi=freebsd, go_source=freebsd                              │
  ├─────────────────┼────────┼──────────────────────┼───────────────────────────────────────────────────────────────┤
  │ ef0ef969...elf_ │ 13.2MB │ go_buildinfo OpenBSD │ osabi, ph_notes, sh_notes, go_buildinfo=openbsd               │
  └─────────────────┴────────┴──────────────────────┴───────────────────────────────────────────────────────────────┘

Used Claude and VT to collect these files and construct the test cases.

Checklist

  • No CHANGELOG update needed
  • No documentation update needed
  • This submission includes AI-generated code and I have provided details in the description.

@williballenthin williballenthin requested a review from mr-tz June 9, 2026 08:56
@williballenthin

Copy link
Copy Markdown
Collaborator Author
image

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new test suite in tests/test_elf_os_detection.py to validate ELF OS detection algorithms against multiple test fixtures, and updates the CHANGELOG.md to reflect these additions. The review feedback recommends defining the FIXTURES dataset directly as a native Python list of dictionaries rather than parsing a raw JSON string at runtime, which would also allow for the removal of the unused json import.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +38 to +159
FIXTURES = json.loads(
"""
[
{
"path": "2f7f5fb5de175e770d7eae87666f9831.elf_",
"os": "linux",
"algorithms": {
"sh_notes": "linux",
"ident_directive": "linux",
"vdso_strings": "linux"
}
},
{
"path": "7351f8a40c5450557b24622417fc478d.elf_",
"os": "linux",
"algorithms": {
"ph_notes": "linux",
"sh_notes": "linux",
"ident_directive": "linux",
"linker": "linux",
"abi_versions_needed": "linux"
}
},
{
"path": "b5f0524e69b3a3cf636c7ac366ca57bf5e3a8fdc8a9f01caf196c611a7918a87.elf_",
"os": "hurd",
"algorithms": {
"sh_notes": "hurd",
"abi_versions_needed": "hurd",
"needed_dependencies": "hurd"
}
},
{
"path": "bf7a9c8bdfa6d47e01ad2b056264acc3fd90cf43fe0ed8deec93ab46b47d76cb.elf_",
"os": "hurd",
"algorithms": {
"sh_notes": "hurd",
"abi_versions_needed": "hurd"
}
},
{
"path": "2bf18d0403677378adad9001b1243211.elf_",
"os": "linux",
"algorithms": {
"symtab": "linux"
}
},
{
"path": "1038a23daad86042c66bfe6c9d052d27048de9653bde5750dc0f240c792d9ac8.elf_",
"os": "android",
"algorithms": {
"ph_notes": "android",
"needed_dependencies": "android"
}
},
{
"path": "3da7c2c70a2d93ac4643f20339d5c7d61388bddd77a4a5fd732311efad78e535.elf_",
"os": "linux",
"algorithms": {
"go_buildinfo": "linux",
"go_source": "linux",
"vdso_strings": "linux"
}
},
{
"path": "9486f2c5d514c1f39833b852ab03f4c0297e9e82b456b0dccad1a2d7d15c3385.elf_",
"os": "freebsd",
"algorithms": {
"osabi": "freebsd"
}
},
{
"path": "a72ac9f1cf6cc01103765f866aae2dd85ea48208fb180c01076ca982684a4032.elf_",
"os": "openbsd",
"algorithms": {
"osabi": "openbsd"
}
},
{
"path": "5e4263575796c6ea2445505a843e616111e0e540ec49441e3bb3fc99be7d3afb.elf_",
"os": "hpux",
"algorithms": {
"osabi": "hpux"
}
},
{
"path": "ccb5eefc47d09672c6d62368a55f48a80259b1408b4f3d260b131d40b487f262.elf_",
"os": "linux",
"algorithms": {
"ident_directive": "linux",
"vdso_strings": "linux"
}
},
{
"path": "c2b2d7cea94179e6c2b6913205e37c45b67ccc0156d8f266548f7f1f95144285.elf_",
"os": "linux",
"algorithms": {
"ph_notes": "linux",
"linker": "linux"
}
},
{
"path": "fb5cf3df103336ca6b84a5d0f314bdd394ce7465adac3cf1914d390d62884582.elf_",
"os": "freebsd",
"algorithms": {
"osabi": "freebsd",
"go_source": "freebsd"
}
},
{
"path": "ef0ef9693ac433b768dc4cd260132788c3d95afa12addab711c15de61f3631bf.elf_",
"os": "openbsd",
"algorithms": {
"osabi": "openbsd",
"ph_notes": "openbsd",
"sh_notes": "openbsd",
"go_buildinfo": "openbsd"
}
}
]
"""
)

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.

medium

Defining FIXTURES as a raw JSON string and parsing it at runtime with json.loads is unnecessary and introduces import-time overhead. Additionally, it prevents static analysis tools (like linters, formatters, and type checkers) from validating and formatting the fixture data.

It is highly recommended to define FIXTURES directly as a native Python list of dictionaries.

FIXTURES = [
    {
        "path": "2f7f5fb5de175e770d7eae87666f9831.elf_",
        "os": "linux",
        "algorithms": {
            "sh_notes": "linux",
            "ident_directive": "linux",
            "vdso_strings": "linux",
        },
    },
    {
        "path": "7351f8a40c5450557b24622417fc478d.elf_",
        "os": "linux",
        "algorithms": {
            "ph_notes": "linux",
            "sh_notes": "linux",
            "ident_directive": "linux",
            "linker": "linux",
            "abi_versions_needed": "linux",
        },
    },
    {
        "path": "b5f0524e69b3a3cf636c7ac366ca57bf5e3a8fdc8a9f01caf196c611a7918a87.elf_",
        "os": "hurd",
        "algorithms": {
            "sh_notes": "hurd",
            "abi_versions_needed": "hurd",
            "needed_dependencies": "hurd",
        },
    },
    {
        "path": "bf7a9c8bdfa6d47e01ad2b056264acc3fd90cf43fe0ed8deec93ab46b47d76cb.elf_",
        "os": "hurd",
        "algorithms": {
            "sh_notes": "hurd",
            "abi_versions_needed": "hurd",
        },
    },
    {
        "path": "2bf18d0403677378adad9001b1243211.elf_",
        "os": "linux",
        "algorithms": {
            "symtab": "linux",
        },
    },
    {
        "path": "1038a23daad86042c66bfe6c9d052d27048de9653bde5750dc0f240c792d9ac8.elf_",
        "os": "android",
        "algorithms": {
            "ph_notes": "android",
            "needed_dependencies": "android",
        },
    },
    {
        "path": "3da7c2c70a2d93ac4643f20339d5c7d61388bddd77a4a5fd732311efad78e535.elf_",
        "os": "linux",
        "algorithms": {
            "go_buildinfo": "linux",
            "go_source": "linux",
            "vdso_strings": "linux",
        },
    },
    {
        "path": "9486f2c5d514c1f39833b852ab03f4c0297e9e82b456b0dccad1a2d7d15c3385.elf_",
        "os": "freebsd",
        "algorithms": {
            "osabi": "freebsd",
        },
    },
    {
        "path": "a72ac9f1cf6cc01103765f866aae2dd85ea48208fb180c01076ca982684a4032.elf_",
        "os": "openbsd",
        "algorithms": {
            "osabi": "openbsd",
        },
    },
    {
        "path": "5e4263575796c6ea2445505a843e616111e0e540ec49441e3bb3fc99be7d3afb.elf_",
        "os": "hpux",
        "algorithms": {
            "osabi": "hpux",
        },
    },
    {
        "path": "ccb5eefc47d09672c6d62368a55f48a80259b1408b4f3d260b131d40b487f262.elf_",
        "os": "linux",
        "algorithms": {
            "ident_directive": "linux",
            "vdso_strings": "linux",
        },
    },
    {
        "path": "c2b2d7cea94179e6c2b6913205e37c45b67ccc0156d8f266548f7f1f95144285.elf_",
        "os": "linux",
        "algorithms": {
            "ph_notes": "linux",
            "linker": "linux",
        },
    },
    {
        "path": "fb5cf3df103336ca6b84a5d0f314bdd394ce7465adac3cf1914d390d62884582.elf_",
        "os": "freebsd",
        "algorithms": {
            "osabi": "freebsd",
            "go_source": "freebsd",
        },
    },
    {
        "path": "ef0ef9693ac433b768dc4cd260132788c3d95afa12addab711c15de61f3631bf.elf_",
        "os": "openbsd",
        "algorithms": {
            "osabi": "openbsd",
            "ph_notes": "openbsd",
            "sh_notes": "openbsd",
            "go_buildinfo": "openbsd",
        },
    },
]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is inline JSON so that it can be subsequently extracted into its own standalone JSON file later.

Comment on lines +15 to +16
import json
from pathlib import Path

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants