GEF save sub-command. Saves the current configuration of GEF to disk (by default in file '~/.gef.rc').
| 9702 | |
| 9703 | |
| 9704 | class GefSaveCommand(gdb.Command): |
| 9705 | """GEF save sub-command. |
| 9706 | Saves the current configuration of GEF to disk (by default in file '~/.gef.rc').""" |
| 9707 | _cmdline_ = "gef save" |
| 9708 | _syntax_ = _cmdline_ |
| 9709 | |
| 9710 | def __init__(self) -> None: |
| 9711 | super().__init__(self._cmdline_, gdb.COMMAND_SUPPORT, gdb.COMPLETE_NONE, False) |
| 9712 | return |
| 9713 | |
| 9714 | def invoke(self, args: Any, from_tty: bool) -> None: |
| 9715 | self.dont_repeat() |
| 9716 | cfg = configparser.RawConfigParser() |
| 9717 | old_sect = None |
| 9718 | |
| 9719 | # save the configuration |
| 9720 | for key in sorted(gef.config): |
| 9721 | sect, optname = key.split(".", 1) |
| 9722 | value = gef.config[key] |
| 9723 | |
| 9724 | if old_sect != sect: |
| 9725 | cfg.add_section(sect) |
| 9726 | old_sect = sect |
| 9727 | |
| 9728 | cfg.set(sect, optname, value) |
| 9729 | |
| 9730 | # save the aliases |
| 9731 | cfg.add_section("aliases") |
| 9732 | for alias in gef.session.aliases: |
| 9733 | cfg.set("aliases", alias._alias, alias._command) |
| 9734 | |
| 9735 | with GEF_RC.open("w") as fd: |
| 9736 | cfg.write(fd) |
| 9737 | |
| 9738 | ok(f"Configuration saved to '{GEF_RC}'") |
| 9739 | return |
| 9740 | |
| 9741 | |
| 9742 | class GefRestoreCommand(gdb.Command): |