Skip to content

Commit

Permalink
more ELF OS detection techniques (#1947)
Browse files Browse the repository at this point in the history
* elf: os: deprioritize .ident strategy due to potential for FPs

* elf: os: same as parent, fix .ident FP

* elf: os: detect Android via clang compiler .ident note

* elf: os: detect Android via dependency on liblog.so

* changelog
  • Loading branch information
williballenthin authored Jan 25, 2024
1 parent 85e1495 commit d2e1a47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Also a big thanks to the other contributors: @aaronatp, @Aayush-Goel-04, @bkojus
- binja: use `binaryninja.load` to open files @xusheng6
- binja: bump binja version to 3.5 #1789 @xusheng6
- elf: better detect ELF OS via GCC .ident directives #1928 @williballenthin
- elf: better detect ELF OS via Android dependencies #1947 @williballenthin
- fix setuptools package discovery #1886 @gmacon @mr-tz

### capa explorer IDA Pro plugin
Expand Down
13 changes: 9 additions & 4 deletions capa/features/extractors/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ def guess_os_from_ident_directive(elf: ELF) -> Optional[OS]:
return OS.LINUX
elif "Red Hat" in comment:
return OS.LINUX
elif "Android" in comment:
return OS.ANDROID

return None

Expand Down Expand Up @@ -921,6 +923,8 @@ def guess_os_from_needed_dependencies(elf: ELF) -> Optional[OS]:
return OS.HURD
if needed.startswith("libandroid.so"):
return OS.ANDROID
if needed.startswith("liblog.so"):
return OS.ANDROID

return None

Expand Down Expand Up @@ -1023,10 +1027,6 @@ def detect_elf_os(f) -> str:
if osabi_guess:
ret = osabi_guess

elif ident_guess:
# we don't trust this too much due to non-cross-compilation assumptions
ret = ident_guess

elif ph_notes_guess:
ret = ph_notes_guess

Expand All @@ -1045,6 +1045,11 @@ def detect_elf_os(f) -> str:
elif symtab_guess:
ret = symtab_guess

elif ident_guess:
# at the bottom because we don't trust this too much
# due to potential for bugs with cross-compilation.
ret = ident_guess

return ret.value if ret is not None else "unknown"


Expand Down

0 comments on commit d2e1a47

Please sign in to comment.