diff --git a/docs/commands.md b/docs/commands.md index 003f4fa20..24d865b0f 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -38,6 +38,7 @@ improve it. |`pattern` | This command will create or search a De Bruijn cyclic pattern to facilitate determining the offset in memory. The algorithm used is the same as the one used by pwntools, and can therefore be used in conjunction.| |`pcustom` | Dump user defined structure. This command attempts to reproduce WinDBG awesome `dt` command for GDB and allows to apply structures (from symbols or custom) directly to an address. Custom structures can be defined in pure Python using ctypes, and should be stored in a specific directory, whose path must be stored in the `pcustom.struct_path` configuration setting. (alias: `dt`)| |`pie` | Base command to support PIE breakpoints. PIE breakpoints is that you can set to a PIE binary, and use pie series commands to attach or create a new process, and it will automatically set the real breakpoint when the binary is running. +|`print-format` | Command to dump memory in a variety of formats, such as programming language array literals. (alias: `pf`)| |`process-search` | List and filter process. (alias: `ps`)| |`process-status` | Extends the info given by GDB `info proc`, by giving an exhaustive description of the process status.| |`registers` | Display full details on one, many or all registers value from current architecture.| diff --git a/docs/commands/print-format.md b/docs/commands/print-format.md index 15bd94fb5..e9a78a750 100644 --- a/docs/commands/print-format.md +++ b/docs/commands/print-format.md @@ -1,17 +1,18 @@ ## Command print-format ## -The command `print-format` (alias `pf`) will dump an arbitrary location as an array of bytes following the syntax of the programming language specified. Currently, the output language supported are +The command `print-format` (alias `pf`) will dump an arbitrary location as an array of bytes following the format specified. Currently, the output formats supported are - Python (`py` - default) - C (`c`) - Assembly (`asm`) - Javascript (`js`) + - Hex string (`hex`) ``` gef➤ print-format -h [+] print-format [--lang LANG] [--bitlen SIZE] [(--length,-l) LENGTH] [--clip] LOCATION - --lang LANG specifies the output format for programming language (available: ['py', 'c', 'js', 'asm'], default 'py'). + --lang LANG specifies the output format for programming language (available: ['py', 'c', 'js', 'asm', 'hex'], default 'py'). --bitlen SIZE specifies size of bit (possible values: [8, 16, 32, 64], default is 8). --length LENGTH specifies length of array (default is 256). --clip The output data will be copied to clipboard diff --git a/gef.py b/gef.py index 88e27fa3c..0bf4309b8 100644 --- a/gef.py +++ b/gef.py @@ -4762,7 +4762,7 @@ def do_invoke(self, argv): @register_command class PrintFormatCommand(GenericCommand): - """Print bytes format in high level languages.""" + """Print bytes format in commonly used formats, such as literals in high level languages.""" format_matrix = { 8: (endian_str() + "B", "char", "db"), @@ -4771,12 +4771,12 @@ class PrintFormatCommand(GenericCommand): 64: (endian_str() + "Q", "long long", "dq"), } - valid_formats = ["py", "c", "js", "asm"] + valid_formats = ["py", "c", "js", "asm", "hex"] _cmdline_ = "print-format" _aliases_ = ["pf",] _syntax_ = """{} [--lang LANG] [--bitlen SIZE] [(--length,-l) LENGTH] [--clip] LOCATION -\t--lang LANG specifies the output format for programming language (available: {}, default 'py'). +\t--lang LANG specifies the output format (available: {}, default 'py'). \t--bitlen SIZE specifies size of bit (possible values: {}, default is 8). \t--length LENGTH specifies length of array (default is 256). \t--clip The output data will be copied to clipboard @@ -4825,6 +4825,8 @@ def do_invoke(self, argv, *args, **kwargs): elif args.lang == "asm": asm_type = self.format_matrix[args.bitlen][2] out = "buf {0} {1}".format(asm_type, sdata) + elif args.lang == "hex": + out = binascii.hexlify(read_memory(start_addr, end_addr-start_addr)).decode() if args.clip: if copy_to_clipboard(gef_pybytes(out)): diff --git a/tests/runtests.py b/tests/runtests.py index c2db5f08d..d5d15325c 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -536,6 +536,9 @@ def test_cmd_print_format(self): res = gdb_start_silent_cmd("print-format --lang js $sp") self.assertNoException(res) self.assertTrue("var buf = [" in res) + res = gdb_start_silent_cmd("print-format --lang hex $sp") + self.assertNoException(res) + self.assertTrue("f7ff7f" in res) res = gdb_start_silent_cmd("print-format --lang iDontExist $sp") self.assertNoException(res) self.assertTrue("Language must be in:" in res)