Skip to content

Commit

Permalink
fix path issues scripts glibc syscalls hugsy#106 hugsy#107
Browse files Browse the repository at this point in the history
  • Loading branch information
therealdreg committed Apr 23, 2024
1 parent 4a96333 commit b71e214
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 4 additions & 5 deletions scripts/libc_function_args/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
__VERSION__ = 0.1
__LICENSE__ = "MIT"

import inspect
import json
import pathlib
import re
Expand All @@ -16,8 +17,8 @@
from .. import *


GLIBC_FUNCTION_ARGS_CURRENT_FILE = pathlib.Path(__file__)
GLIBC_FUNCTION_ARGS_CURRENT_DIRECTORY = GLIBC_FUNCTION_ARGS_CURRENT_FILE.parent
GLIBC_FUNCTION_ARGS_CURRENT_FILE = pathlib.Path(inspect.getfile(inspect.currentframe())).resolve()
GLIBC_FUNCTION_ARGS_CURRENT_DIRECTORY = pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve()
GLIBC_FUNCTION_ARGS_CONTEXT_PANE_INDEX = "libc_function_args"
GLIBC_FUNCTION_ARGS_CONTEXT_PANE_DESCRIPTION = "Glibc Function Arguments"

Expand All @@ -33,9 +34,7 @@ def load_libc_args() -> bool:
"""Load the LIBC function arguments. Returns `True` on success, `False` or an Exception otherwise."""

# load libc function arguments' definitions
path = (
pathlib.Path(GLIBC_FUNCTION_ARGS_CURRENT_DIRECTORY).expanduser().absolute()
)
path = GLIBC_FUNCTION_ARGS_CURRENT_DIRECTORY
if not path.exists():
raise RuntimeError(
"Config `context.libc_args_path` set but it's not a directory"
Expand Down
6 changes: 4 additions & 2 deletions scripts/libc_function_args/tables/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__AUTHOR__ = "theguly"
__VERSION__ = 0.2

import inspect
import gzip
import json
import logging
Expand Down Expand Up @@ -36,15 +37,16 @@ def generate_json_file(
for i in range(0, len(_value)):
_dict[_key][_params[i]] = _value[i]

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

logging.info(f"{outfile_name} written")
return True


def generate_all_json_files() -> bool:
curdir = pathlib.Path(__file__).parent
curdir = pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve()
libc_file_path = curdir / "libc.txt.gz"
libc_x86_funcdef_fpath = curdir / "x86_32.json"
libc_x64_funcdef_fpath = curdir / "x86_64.json"
Expand Down
7 changes: 4 additions & 3 deletions scripts/syscall_args/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
__VERSION__ = 0.1
__LICENSE__ = "MIT"

import inspect
import pathlib
import re
from importlib.machinery import SourceFileLoader
Expand All @@ -14,8 +15,8 @@
if TYPE_CHECKING:
from .. import *

CURRENT_FILE = pathlib.Path(__file__)
CURRENT_DIRECTORY = CURRENT_FILE.parent
CURRENT_FILE = pathlib.Path(inspect.getfile(inspect.currentframe())).resolve()
CURRENT_DIRECTORY = pathlib.Path(inspect.getfile(inspect.currentframe())).parent.resolve()
CONTEXT_PANE_INDEX = "syscall_args"
CONTEXT_PANE_DESCRIPTION = "Syscall Arguments"

Expand Down Expand Up @@ -44,7 +45,7 @@ def __init__(self) -> None:
super().__init__(prefix=False, complete=gdb.COMPLETE_NONE)
self.__path: Optional[pathlib.Path] = None
path = CURRENT_DIRECTORY / "syscall-tables"
self["path"] = (str(path.absolute()),
self["path"] = (str(path),
"Path to store/load the syscall tables files")
return

Expand Down

0 comments on commit b71e214

Please sign in to comment.