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

Better way to determine the glibc version #22516

Closed
wants to merge 1 commit into from

Conversation

MewtR
Copy link
Contributor

@MewtR MewtR commented Dec 28, 2023

  • Mark this if you consider it ready to merge
  • I've added tests (optional)
  • I wrote some lines in the book (optional)

Description
So I wrote a new function that determines the glibc version based on the strings inside the .so.
This is similar to what pwndbg/GEF do. Previously, the version was parsed out of the filename, but this is not
relevant for newer versions of libc as they will all be named libc.so.6

@koyaan
Copy link
Contributor

koyaan commented Dec 28, 2023

Funny that after years of stale code two people are working on the same thing, I also did some new libc version detection in koyaan@ffcb7c2

  1. looking for a __libc_version version symbol and 2) doing string searching in .rodata section similiar to your solution

@MewtR
Copy link
Contributor Author

MewtR commented Dec 28, 2023

Yeah... you're version seems solid. I also made a change to regcomp.c which could potentially be dangerous. Are you going to have a PR up soon?


// We only care about the first match
char *first_match = r_list_first (matches);
version = r_num_get_float (core->num, first_match);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this api should be renamed to get_double instead 🤔

unum.c:R_API double r_num_get_float(RNum *num, const char *str) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make this change, but I'd rather do it in a separate PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes please

libr/core/cmd_debug.inc.c Outdated Show resolved Hide resolved
r_io_bind (io, &bin->iob);
RBinFileOptions opt = { 0 };

if (r_bin_open (bin, libc_path, &opt)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe worth adding some extra checks about the filetype. but guess its fine for an intiaial approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checks such as what? Like making sure it's an .so?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if its worth ensuring its an elf too. But i doubt this function will take a wrong path as arg

Copy link
Collaborator

@trufae trufae left a comment

Choose a reason for hiding this comment

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

lgtm

* New function get_glibc_version that gets strings from
the glibc .so and parses out the version.
* Unit test at `test_glibc_version.c`
@trufae
Copy link
Collaborator

trufae commented Jan 19, 2024

Should i close this pr?

@koyaan
Copy link
Contributor

koyaan commented Jan 19, 2024

Please leave it open till mine is resolved i will take some code from this

@trufae
Copy link
Collaborator

trufae commented Feb 14, 2024

Closing this pr in favour of the other one

@trufae trufae closed this Feb 14, 2024
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.

3 participants