diff --git a/.gitignore b/.gitignore index eb6eed49d..f18a5baa8 100644 --- a/.gitignore +++ b/.gitignore @@ -64,7 +64,7 @@ site/ target/ npm-debug.log -.gdb_history +**/.gdb_history # PyCharm project files .idea/ diff --git a/docs/commands/misc/break-if-not-taken.md b/docs/commands/breakpoint/break-if-not-taken.md similarity index 100% rename from docs/commands/misc/break-if-not-taken.md rename to docs/commands/breakpoint/break-if-not-taken.md diff --git a/docs/commands/misc/break-if-taken.md b/docs/commands/breakpoint/break-if-taken.md similarity index 100% rename from docs/commands/misc/break-if-taken.md rename to docs/commands/breakpoint/break-if-taken.md diff --git a/docs/commands/index.md b/docs/commands/index.md index c51433d23..0e9395f11 100644 --- a/docs/commands/index.md +++ b/docs/commands/index.md @@ -7,6 +7,8 @@ ## Breakpoint +- [break-if-not-taken](breakpoint/break-if-not-taken.md) - Breaks on a branch if it is not taken. +- [break-if-taken](breakpoint/break-if-taken.md) - Breaks on a branch if it is taken. - [breakrva](breakpoint/breakrva.md) - Break at RVA from PIE base. - [ignore](breakpoint/ignore.md) - Set ignore-count of breakpoint number N to COUNT. @@ -100,7 +102,7 @@ - [gotplt](linux_libc_elf/gotplt.md) - Prints any symbols found in the .got.plt section if it exists. - [libcinfo](linux_libc_elf/libcinfo.md) - Show libc version and link to its sources - [linkmap](linux_libc_elf/linkmap.md) - Show the state of the Link Map -- [onegadget](linux_libc_elf/onegadget.md) - Show onegadget +- [onegadget](linux_libc_elf/onegadget.md) - Find gadgets which single-handedly give code execution. - [piebase](linux_libc_elf/piebase.md) - Calculate VA of RVA from PIE base. - [plt](linux_libc_elf/plt.md) - Prints any symbols found in the .plt section if it exists. - [strings](linux_libc_elf/strings.md) - Extracts and displays ASCII strings from readable memory pages of the debugged process. @@ -135,8 +137,6 @@ ## Misc - [asm](misc/asm.md) - Assemble shellcode into bytes -- [break-if-not-taken](misc/break-if-not-taken.md) - Breaks on a branch if it is not taken. -- [break-if-taken](misc/break-if-taken.md) - Breaks on a branch if it is taken. - [checksec](misc/checksec.md) - Prints out the binary security settings using `checksec`. - [comm](misc/comm.md) - Put comments in assembly code. - [cyclic](misc/cyclic.md) - Cyclic pattern creator/finder. diff --git a/docs/commands/linux_libc_elf/onegadget.md b/docs/commands/linux_libc_elf/onegadget.md index 98f790352..2fe40372d 100644 --- a/docs/commands/linux_libc_elf/onegadget.md +++ b/docs/commands/linux_libc_elf/onegadget.md @@ -8,11 +8,10 @@ ## Description -Show onegadget -Examples: - onegadget - onegadget --show-unsat +Find gadgets which single-handedly give code execution. + +Uses the onegadget tool by david942j. ## Usage: diff --git a/pwndbg/commands/branch.py b/pwndbg/commands/branch.py index 4c81b76fd..0335a83ae 100644 --- a/pwndbg/commands/branch.py +++ b/pwndbg/commands/branch.py @@ -43,7 +43,7 @@ parser.add_argument( @pwndbg.commands.ArgparsedCommand( - parser, command_name="break-if-taken", category=CommandCategory.MISC + parser, command_name="break-if-taken", category=CommandCategory.BREAKPOINT ) @pwndbg.commands.OnlyWhenRunning def break_if_taken(branch) -> None: @@ -59,7 +59,7 @@ parser.add_argument( @pwndbg.commands.ArgparsedCommand( - parser, command_name="break-if-not-taken", category=CommandCategory.MISC + parser, command_name="break-if-not-taken", category=CommandCategory.BREAKPOINT ) @pwndbg.commands.OnlyWhenRunning def break_if_not_taken(branch) -> None: diff --git a/pwndbg/commands/onegadget.py b/pwndbg/commands/onegadget.py index 6fadbf8dd..50d885a71 100644 --- a/pwndbg/commands/onegadget.py +++ b/pwndbg/commands/onegadget.py @@ -12,13 +12,13 @@ from pwndbg.commands import CommandCategory parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, - description="""Show onegadget + description=""" +Find gadgets which single-handedly give code execution. -Examples: - onegadget - onegadget --show-unsat +Uses the onegadget tool by david942j. """, ) + parser.add_argument("--show-unsat", help="Show unsatisfiable gadgets.", action="store_true") parser.add_argument("--no-unknown", help="Do not show unknown gadgets.", action="store_true") parser.add_argument("-v", "--verbose", help="Show verbose output.", action="store_true") diff --git a/scripts/_gen_command_docs.py b/scripts/_gen_command_docs.py index 115bc3d94..bb0de9da9 100644 --- a/scripts/_gen_command_docs.py +++ b/scripts/_gen_command_docs.py @@ -42,6 +42,15 @@ def category_to_folder_name(category) -> str: assert(all(c.isalnum() or c == '_' for c in folder)) return folder +def get_files_in_dir(directory) -> list[str]: + file_paths = [] + for root, dirs, files in os.walk(directory): + for file in files: + full_path = os.path.join(root, file) + relative_path = os.path.relpath(full_path, directory) + file_paths.append(relative_path) + return file_paths + def extract_sources() -> (Dict[str, argparse.ArgumentParser], Dict[str, list[str]]): """ Extract the sources. @@ -210,6 +219,26 @@ def generate_index(filename_to_parser: Dict[str, argparse.ArgumentParser], categ index_autogen_warning = "\n" return index_autogen_warning + mdFile.get_md_text() +def verify_existence(filenames: list[str]) -> (list[str], list[str]): + current = get_files_in_dir(base_path) + current = [base_path + x for x in current] + + missing = [x for x in filenames if x not in current] + extra = [x for x in current if x not in filenames] + + if missing: + print("Missing files:") + for f in missing: + print(f) + print() + + if extra: + print("These files shouldn't exist:") + for f in extra: + print(f) + print() + + return missing, extra def verify_files(filename_to_markdown: Dict[str, str]) -> str | None: """ @@ -306,7 +335,14 @@ markdowned = convert_all_to_markdown(extracted) markdowned[base_path + "index.md"] = generate_index(extracted, cat_to_names) if just_verify: - print("Verifying...") + print("Checking if all files are in place..") + missing, extra = verify_existence(markdowned.keys()) + if missing or extra: + print("To fix this please run ./scripts/generate_docs.sh.") + exit(555) + print("Every file is where it should be!") + + print("Verifying contents...") err = verify_files(markdowned) if err: print("VERIFICATION FAILED. The files differ from what would be auto-generated.") @@ -314,8 +350,17 @@ if just_verify: print("Please run ./scripts/generate_docs.sh from project root and commit the changes.") exit(777) - print("Verification Successful.") + print("Verification successful!") else: print("Updating files...") update_files(markdowned) print("Update successful.") + + missing, extra = verify_existence(markdowned.keys()) + assert(not missing and "Some files are missing, which should be impossible.") + if extra: + print(f"Take care! Deleting these extra files ({len(extra)}):") + for e in extra: + print(e) + os.remove(e) + print("Deleted successfully.")