Documentation for how to use jtool goes here
(debugger, command, exe_ctx, result, internal_dict)
| 57 | 'command script add -f jtool.handle_command jtool -h "wrapper for @Morpheus______\'s jtool"') |
| 58 | |
| 59 | def handle_command(debugger, command, exe_ctx, result, internal_dict): |
| 60 | ''' |
| 61 | Documentation for how to use jtool goes here |
| 62 | ''' |
| 63 | if makeSureEverythingIsOK(result): |
| 64 | return |
| 65 | |
| 66 | target = exe_ctx.GetTarget() |
| 67 | command_args = shlex.split(command, posix=False) |
| 68 | parser = generate_option_parser() |
| 69 | try: |
| 70 | (options, args) = parser.parse_args(command_args) |
| 71 | except: |
| 72 | result.SetError(parser.usage) |
| 73 | return |
| 74 | |
| 75 | executablePath = None |
| 76 | module = None |
| 77 | addr = None |
| 78 | # No args default to main executable |
| 79 | if len(args) == 0: |
| 80 | executablePath = target.GetExecutable().fullpath |
| 81 | module = target.module[target.GetExecutable().fullpath] |
| 82 | result.AppendMessage("Inspecting main executable, {}{}{}".format("" if isXcode() else "\033[36m", module.GetFileSpec().basename, "" if isXcode() else "\033[0m")) |
| 83 | |
| 84 | if len(args) >= 1: |
| 85 | module = target.module[args[0]] |
| 86 | if module is None: |
| 87 | # Did they pass in a hex/int value? |
| 88 | try: |
| 89 | address = int(args[0]) |
| 90 | except: |
| 91 | |
| 92 | # Hex didn't work, just try an int |
| 93 | try: |
| 94 | address = int(args[0], 16) |
| 95 | except: |
| 96 | result.SetError("Unable to find module \"{}\", use \"image list -f ModuleName\"".format(args[0])) |
| 97 | return |
| 98 | |
| 99 | |
| 100 | addr = target.ResolveLoadAddress(address) |
| 101 | if module is None: |
| 102 | module = addr.GetModule() |
| 103 | result.AppendMessage("\"{}\" found in {}{}{}".format(args[0], "" if isXcode() else "\033[36m", module.GetFileSpec().basename, "" if isXcode() else "\033[0m")) |
| 104 | |
| 105 | |
| 106 | if addr.module.IsValid() == False: |
| 107 | result.SetError("Unable to find module for address {}".format(hex(address))) |
| 108 | return |
| 109 | |
| 110 | |
| 111 | if module is not None: |
| 112 | executablePath = module.GetFileSpec().fullpath |
| 113 | |
| 114 | if addr is None: |
| 115 | addr = module.GetObjectFileHeaderAddress() |
| 116 |
nothing calls this directly
no test coverage detected
searching dependent graphs…