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

persistent libc.txt.gz for glibc_function_args #106

Closed
aliencaocao opened this issue Mar 16, 2024 · 14 comments · Fixed by #109
Closed

persistent libc.txt.gz for glibc_function_args #106

aliencaocao opened this issue Mar 16, 2024 · 14 comments · Fixed by #109
Assignees
Milestone

Comments

@aliencaocao
Copy link

aliencaocao commented Mar 16, 2024

Is your feature request related to a problem? Please describe.
Im always frustrated when I have to download https://www.gnu.org/software/libc/manual/text/libc.txt.gz everytime I work on a new project/switch to a different dir. I hope there can be a way to read the extracted json from a fixed path in env var.

Describe the solution you'd like
Use the path defined in context.libc_args_path in gef config.

file libc.txt.gz cannot be found. download it from https://www.gnu.org/software/libc/manual/text/libc.txt.gz
Traceback (most recent call last):
  File "/root/.config/gef-extras/scripts/libc_function_args/tables/generate_glibc_args_json.py", line 56, in <module>
    fh = gzip.open(file_name, "r")
  File "/usr/lib/python3.10/gzip.py", line 58, in open
    binary_file = GzipFile(filename, gz_mode, compresslevel)
  File "/usr/lib/python3.10/gzip.py", line 174, in __init__
    fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'libc.txt.gz'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.config/gef-extras/scripts/libc_function_args/tables/generate_glibc_args_json.py", line 63, in <module>
    sys.exit(-1)
  File "/root/.gef-2024.01.py", line 446, in FakeExit
    raise RuntimeWarning
RuntimeWarning
@therealdreg
Copy link
Collaborator

therealdreg commented Apr 22, 2024

the same bug: #107

@hugsy Is aware of the (bug) cause and is working on it

@aliencaocao
Copy link
Author

Oh so this is supposed to be persistent but it is a bug that it is not?

@therealdreg
Copy link
Collaborator

therealdreg commented Apr 22, 2024

The current code is not behaving as it should, so it is a bug.

image

As you can see, the libc and JSON files are already included, but it fails to find the path....

@therealdreg
Copy link
Collaborator

therealdreg commented Apr 22, 2024

@aliencaocao can you test a simple crappy fix?

1

cd ~/.config/gef-extras/scripts/libc_function_args/tables
wget https://www.gnu.org/software/libc/manual/text/libc.txt.gz

2

Edit:

~/.config/gef-extras/scripts/libc_function_args/tables/generate_glibc_args_json.py

Replace:

file_name = "libc.txt.gz"

with this:

file_name = pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve() / "libc.txt.gz"

Replace:

with open(outfile_name, "w") as outfile:

with this:

with open(pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve() / outfile_name, "w") as outfile:

3

Edit:

~/.config/gef-extras/scripts/libc_function_args/__init__.py

Replace:

GLIBC_FUNCTION_ARGS_CURRENT_FILE = ...
GLIBC_FUNCTION_ARGS_CURRENT_DIRECTORY = ....

with this:

GLIBC_FUNCTION_ARGS_CURRENT_FILE = pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve()
GLIBC_FUNCTION_ARGS_CURRENT_DIRECTORY = pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve()

This works now as expected?

@aliencaocao
Copy link
Author

aliencaocao commented Apr 22, 2024

I did the mods, launched gef once and saw the json written messages, then deleted the txt.gz, still same error come out. I should be expecting it to just read the existing json instead of trying to extract a new one right? The patches given does not seem to fix this for me as it still point to the txt.gz and does not check for any existing json.

@aliencaocao
Copy link
Author

aliencaocao commented Apr 22, 2024

If I switch to the different dir without deleting the txt.gz, it works fine but it seem to be extracting it every time i run gef which is not very necessary.
Also, when I run gef in tables, I get file x86_64.json exists, overwrite? [y/N] for both json.

@therealdreg
Copy link
Collaborator

therealdreg commented Apr 22, 2024

Let's tackle this step by step.

First, I want to address the path issue, and then we'll move on to the other matters.

If we keep the files in the tables/ directory (json + tgz), everything works as you would expect, right?

(After fixing this, I'll look into ensuring that the JSON files aren't generated every time, etc.)

@DimSumCodes
Copy link

DimSumCodes commented Apr 22, 2024

I was having a similar issue with the libc.txt.gz not being read from tables. I had no idea the cause, but using step 1 and 2 it fixed the issue and now properly recognizes the lic.txt.gz file in the tables directory. Also to note it does generate the x86_32 and x86_64 files in my directory every time I run gdb but it's not a big deal to me I just overwrite them every time and everything runs smooth. I did the other steps to see if it would resolve the overwrite json issue but unfortunately the json is another issue anyway.

@aliencaocao
Copy link
Author

Yes it does work if i keep the txt.gz, but that was not the reason I opened the issue as I thought the json itself should be cached and reused. Seems like this is a feature request instead of a bug then

@therealdreg
Copy link
Collaborator

therealdreg commented Apr 23, 2024

I have to download https://www.gnu.org/software/libc/manual/text/libc.txt.gz everytime I work on a new project/switch to a different dir

This should not happen, and this is my fix :D. So yes, this part is a bug!

therealdreg added a commit to therealdreg/gef-extras that referenced this issue Apr 23, 2024
@hugsy hugsy linked a pull request Apr 23, 2024 that will close this issue
12 tasks
therealdreg added a commit that referenced this issue Apr 23, 2024
fix path issues scripts glibc syscalls #106 #107
@therealdreg therealdreg reopened this Apr 27, 2024
@therealdreg
Copy link
Collaborator

therealdreg commented Apr 27, 2024

I want to make sure everything works well.

Can you test the latest dev versions of gef-extras and gef and let me know if everything now works as you expect, please? @aliencaocao @DimSumCodes

Related to: #109 #111 hugsy/gef#1093

Can I close this issue?

@DimSumCodes
Copy link

Just checked it, works perfectly doesn't generate a new file in my active directory and doesn't have any issues referencing the files.

Repository owner deleted a comment from DimSumCodes Apr 27, 2024
@aliencaocao
Copy link
Author

Same for me.

@hugsy
Copy link
Owner

hugsy commented Apr 27, 2024

Great work on fixing this @therealdreg 🎉

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

Successfully merging a pull request may close this issue.

4 participants