diff --git a/README.md b/README.md index a574590..3d9e330 100644 --- a/README.md +++ b/README.md @@ -310,8 +310,6 @@ polymorphic nature of the dynamic entries needed_. The below uses a file built with [NixOS](https://nixos.org) as they all have RUNPATH set. -A recursive query can further be used to split the row into multiple rows. - ```console ❯ sqlelf /nix/store/gjr9ylm023rl9di484g1wxcd1jp84xxv-nix-2.8.1/bin/nix \ --sql "SELECT elf_strings.path, elf_strings.value @@ -328,6 +326,33 @@ WHERE elf_dynamic_entries.tag = 'RUNPATH';" └─────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ ``` +A recursive query can further be used to split the row into multiple rows. + +```console +❯ sqlelf /nix/store/gjr9ylm023rl9di484g1wxcd1jp84xxv-nix-2.8.1/bin/nix \ +--sql "WITH split(rpath, str) AS ( + SELECT '', elf_strings.value||':' as rpath + FROM elf_dynamic_entries + INNER JOIN elf_strings ON elf_dynamic_entries.value = elf_strings.offset + WHERE elf_dynamic_entries.tag = 'RUNPATH' + UNION ALL SELECT + substr(str, 0, instr(str, ':')), + substr(str, instr(str, ':')+1) + FROM split WHERE str!='' +) SELECT rpath FROM split WHERE rpath!='';" +WARNING:root:SQLITE_LOG: automatic index on elf_strings(offset) (284) SQLITE_WARNING SQLITE_WARNING_AUTOINDEX +┌────────────────────────────────────────────────────────────────────┐ +│ rpath │ +│ /nix/store/gjr9ylm023rl9di484g1wxcd1jp84xxv-nix-2.8.1/lib │ +│ /nix/store/pkxyfwarcq081rybpbnprjmnkiy1cz6g-libsodium-1.0.18/lib │ +│ /nix/store/r6mrf9pz4dpax6rcszcmbyrpsk8j6saz-editline-1.17.1/lib │ +│ /nix/store/ppm63lvkyfa58sgcnr2ddzh14dy1k9fn-boehm-gc-8.0.6/lib │ +│ /nix/store/sgw2i15l01rwxzj62745h30bsjmh7wc1-lowdown-0.11.1-lib/lib │ +│ /nix/store/bvy2z17rzlvkx2sj7fy99ajm853yv898-glibc-2.34-210/lib │ +│ /nix/store/gka59hya7l7qp26s0rydcgq8hj0d7v7k-gcc-11.3.0-lib/lib │ +└────────────────────────────────────────────────────────────────────┘ +``` + diff --git a/sqlelf/cli.py b/sqlelf/cli.py index 984cebb..89250d4 100644 --- a/sqlelf/cli.py +++ b/sqlelf/cli.py @@ -6,6 +6,7 @@ from functools import reduce from typing import TextIO +from sqlelf import elf from sqlelf import sql as api_sql @@ -65,7 +66,9 @@ def start(args: list[str] = sys.argv[1:], stdin: TextIO = sys.stdin) -> None: if len(filenames) == 0: sys.exit("No valid ELF files were provided") - sql_engine = api_sql.make_sql_engine(filenames, recursive=program_args.recursive) + sql_engine = api_sql.make_sql_engine( + filenames, recursive=program_args.recursive, cache_flags=elf.CacheFlag.ALL() + ) shell = sql_engine.shell(stdin=stdin) if program_args.sql and len(program_args.filenames) > 0: diff --git a/sqlelf/elf.py b/sqlelf/elf.py index a387f8c..54cc539 100644 --- a/sqlelf/elf.py +++ b/sqlelf/elf.py @@ -289,6 +289,11 @@ def strings_generator() -> Iterator[dict[str, Any]]: cache_flags, ) + if CacheFlag.STRINGS in cache_flags: + connection.execute( + """CREATE INDEX elf_strings_offset_idx ON elf_strings (offset);""" + ) + def split_with_index(str: str, delimiter: str) -> list[tuple[int, str]]: """Split a string with the delimiter and return the index