8000 lldbinit/lldbinit.py at master · sug0/lldbinit · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
6703 lines (5915 loc) · 218 KB

lldbinit.py

File metadata and controls

6703 lines (5915 loc) · 218 KB
"""
_ _ _ _ _ _ _
| | |_| | |_|_|___|_| |_
| | | . | . | | | | _|
|_|_|___|___|_|_|_|_|_|
lldbinit v3.1
A gdbinit clone for LLDB aka how to make LLDB a bit more useful and less crappy
Available at https://github.com/gdbinit/lldbinit
Original lldbinit code by Deroko @ https://github.com/deroko/lldbinit
gdbinit available @ https://github.com/gdbinit/Gdbinit
(c) Deroko 2014, 2015, 2016
(c) fG! 2017-2023 - reverser@put.as - https://reverse.put.as
No original license by Deroko.
All my modifications are under MIT license:
Copyright 2017-2023 Pedro Vilaca
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Huge thanks to Deroko for his original effort!
To list all implemented commands use 'lldbinitcmds' command.
How to install it:
------------------
$ cp lldbinit.py ~
$ echo "command script import ~/lldbinit.py" >>$HOME/.lldbinit
or
just copy it somewhere and use "command script import path_to_script" when you want to load it.
Notes:
------
Version 3.0+ drops support for ARM32 and assumes ARM64 instead
KNOWN BUGS:
-----------
"""
if __name__ == "__main__":
print("Run only as script from LLDB... Not as standalone program!")
import lldb
import sys
import re
import os
import time
import struct
import argparse
import subprocess
import tempfile
import termios
import fcntl
import json
import hashlib
try:
import keystone
CONFIG_KEYSTONE_AVAILABLE = 1
except ImportError:
CONFIG_KEYSTONE_AVAILABLE = 0
pass
VERSION = "3.1"
BUILD = "383"
#
# User configurable options
#
CONFIG_ENABLE_COLOR = 1
# light or dark mode
CONFIG_APPEARANCE = "light"
# display the instruction bytes in disassembler output
CONFIG_DISPLAY_DISASSEMBLY_BYTES = 1
# the maximum number of lines to display in disassembler output
CONFIG_DISASSEMBLY_LINE_COUNT = 8
# x/i and disas output customization - doesn't affect context disassembler output
CONFIG_USE_CUSTOM_DISASSEMBLY_FORMAT = 1
# enable all the register command shortcuts
CONFIG_ENABLE_REGISTER_SHORTCUTS = 1
# display stack contents on context stop
CONFIG_DISPLAY_STACK_WINDOW = 0
CONFIG_DISPLAY_FLOW_WINDOW = 0
# display data contents on context stop - an address for the data must be set with "datawin" command
CONFIG_DISPLAY_DATA_WINDOW = 0
# disassembly flavor 'intel' or 'att' - default is Intel unless AT&T syntax is your cup of tea
CONFIG_FLAVOR = "intel"
# setup the logging level, which is a bitmask of any of the following possible values (don't use spaces, doesn't seem to work)
#
# LOG_VERBOSE LOG_PROCESS LOG_THREAD LOG_EXCEPTIONS LOG_SHLIB LOG_MEMORY LOG_MEMORY_DATA_SHORT LOG_MEMORY_DATA_LONG LOG_MEMORY_PROTECTIONS LOG_BREAKPOINTS LOG_EVENTS LOG_WATCHPOINTS
# LOG_STEP LOG_TASK LOG_ALL LOG_DEFAULT LOG_NONE LOG_RNB_MINIMAL LOG_RNB_MEDIUM LOG_RNB_MAX LOG_RNB_COMM LOG_RNB_REMOTE LOG_RNB_EVENTS LOG_RNB_PROC LOG_RNB_PACKETS LOG_RNB_ALL LOG_RNB_DEFAULT
# LOG_DARWIN_LOG LOG_RNB_NONE
#
# to see log (at least in macOS)
# $ log stream --process debugserver --style compact
# (or whatever style you like)
CONFIG_LOG_LEVEL = "LOG_NONE"
# removes the offsets and modifies the module name position
# reference: https://lldb.llvm.org/formats.html
CUSTOM_DISASSEMBLY_FORMAT = '"{${function.initial-function}{${function.name-without-args}} @ {${module.file.basename}}:\n}{${function.changed}\n{${function.name-without-args}} @ {${module.file.basename}}:\n}{${current-pc-arrow} }${addr-file-or-load}: "'
# the colors definitions - don't mess with this
if CONFIG_ENABLE_COLOR:
RESET = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
REVERSE = "\033[7m"
BLACK = "\033[30m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
WHITE = "\033[37m"
else:
RESET = ""
BOLD = ""
UNDERLINE = ""
REVERSE = ""
BLACK = ""
RED = ""
GREEN = ""
YELLOW = ""
BLUE = ""
MAGENTA = ""
CYAN = ""
WHITE = ""
# default colors - modify as you wish
# since these are just strings modes can be combined
if CONFIG_APPEARANCE == "light":
COLOR_REGVAL = BLACK
COLOR_REGNAME = GREEN
COLOR_CPUFLAGS = BOLD + UNDERLINE + MAGENTA
COLOR_SEPARATOR = BOLD + BLUE
COLOR_HIGHLIGHT_LINE = RED
COLOR_REGVAL_MODIFIED = RED
COLOR_SYMBOL_NAME = BLUE
COLOR_CURRENT_PC = RED
COLOR_CONDITIONAL_YES = REVERSE + GREEN
COLOR_CONDITIONAL_NO = REVERSE + RED
COLOR_HEXDUMP_HEADER = BLUE
COLOR_HEXDUMP_ADDR = BLACK
COLOR_HEXDUMP_DATA = BLACK
COLOR_HEXDUMP_ASCII = BLACK
COLOR_COMMENT = GREEN
elif CONFIG_APPEARANCE == "dark":
COLOR_REGVAL = WHITE
COLOR_REGNAME = GREEN
COLOR_CPUFLAGS = BOLD + UNDERLINE + MAGENTA
COLOR_SEPARATOR = CYAN
COLOR_HIGHLIGHT_LINE = RED
COLOR_REGVAL_MODIFIED = RED
COLOR_SYMBOL_NAME = BLUE
COLOR_CURRENT_PC = RED
COLOR_CONDITIONAL_YES = REVERSE + GREEN
COLOR_CONDITIONAL_NO = REVERSE + RED
COLOR_HEXDUMP_HEADER = BLUE
COLOR_HEXDUMP_ADDR = WHITE
COLOR_HEXDUMP_DATA = WHITE
COLOR_HEXDUMP_ASCII = WHITE
COLOR_COMMENT = GREEN # XXX: test and change
else:
print("[-] Invalid CONFIG_APPEARANCE value.")
# configure the separator character between the "windows" and their size
SEPARATOR = "-"
# minimum terminal width 120 chars
I386_TOP_SIZE = 81
I386_STACK_SIZE = I386_TOP_SIZE - 1
I386_BOTTOM_SIZE = 87
# minimum terminal width 125 chars
X64_TOP_SIZE = 119
X64_STACK_SIZE = X64_TOP_SIZE - 1
X64_BOTTOM_SIZE = 125
# minimum terminal width 108 chars
ARM_TOP_SIZE = 102
ARM_STACK_SIZE = ARM_TOP_SIZE - 1
ARM_BOTTOM_SIZE = 108
# turn on debugging output - you most probably don't need this
DEBUG = 0
#
# Don't mess after here unless you know what you are doing!
#
DATA_WINDOW_ADDRESS = 0
POINTER_SIZE = 8
old_x86 = {
"eax": 0,
"ecx": 0,
"edx": 0,
"ebx": 0,
"esp": 0,
"ebp": 0,
"esi": 0,
"edi": 0,
"eip": 0,
"eflags": 0,
"cs": 0,
"ds": 0,
"fs": 0,
"gs": 0,
"ss": 0,
"es": 0,
}
old_x64 = {
"rax": 0,
"rcx": 0,
"rdx": 0,
"rbx": 0,
"rsp": 0,
"rbp": 0,
"rsi": 0,
"rdi": 0,
"rip": 0,
"r8": 0,
"r9": 0,
"r10": 0,
"r11": 0,
"r12": 0,
"r13": 0,
"r14": 0,
"r15": 0,
"rflags": 0,
"cs": 0,
"fs": 0,
"gs": 0,
}
old_arm64 = {
"x0": 0,
"x1": 0,
"x2": 0,
"x3": 0,
"x4": 0,
"x5": 0,
"x6": 0,
"x7": 0,
"x8": 0,
"x9": 0,
"x10": 0,
"x11": 0,
"x12": 0,
"x13": 0,
"x14": 0,
"x15": 0,
"x16": 0,
"x17": 0,
"x18": 0,
"x19": 0,
"x20": 0,
"x21": 0,
"x22": 0,
"x23": 0,
"x24": 0,
"x25": 0,
"x26": 0,
"x27": 0,
"x28": 0,
"fp": 0,
"lr": 0,
"sp": 0,
"pc": 0,
"cpsr": 0,
}
GlobalListOutput = []
int3patches = {}
crack_cmds = []
crack_cmds_noret = []
modules_list = []
g_current_target = ""
g_target_hash = ""
g_home = ""
g_db = ""
g_dbdata = {}
# dyld modes
dyld_mode_dict = {
0: "dyld_image_adding",
1: "dyld_image_removing",
2: "dyld_image_info_change",
3: "dyld_image_dyld_moved",
}
MIN_COLUMNS = 125
MIN_ROWS = 25
# test terminal - idea from https://github.com/ant4g0nist/lisa.py/
try:
tty_rows, tty_columns = struct.unpack(
"hh", fcntl.ioctl(1, termios.TIOCGWINSZ, "1234")
)
# i386 is fine with 87x21
# x64 is fine with 125x23
# aarch64 is fine with 108x26
if tty_columns < MIN_COLUMNS or tty_rows < MIN_ROWS:
print(
"\033[1m\033[31m[!] current terminal size is {:d}x{:d}".format(
tty_columns, tty_rows
)
)
print(
"[!] lldbinit is best experienced with a terminal size at least {}x{}\033[0m".format(
MIN_COLUMNS, MIN_ROWS
)
)
except Exception as e:
print("\033[1m\033[31m[-] failed to find out terminal size.")
print(
"[!] lldbinit is best experienced with a terminal size at least {}x{}\033[0m".format(
MIN_COLUMNS, MIN_ROWS
)
)
def __lldb_init_module(debugger, internal_dict):
"""we can execute lldb commands using debugger.HandleCommand() which makes all output to default
lldb console. With SBDebugger.GetCommandinterpreter().HandleCommand() we can consume all output
with SBCommandReturnObject and parse data before we send it to output (eg. modify it);
in practice there is nothing here in initialization or anywhere else that we want to modify
"""
# don't load if we are in Xcode since it is not compatible and will block Xcode
if os.getenv("PATH").startswith("/Applications/Xcode"):
return
global g_home
if g_home == "":
g_home = os.getenv("HOME")
res = lldb.SBCommandReturnObject()
ci = debugger.GetCommandInterpreter()
# settings
ci.HandleCommand("settings set target.x86-disassembly-flavor " + CONFIG_FLAVOR, res)
ci.HandleCommand('settings set prompt "(lldbinit) "', res)
ci.HandleCommand("settings set stop-disassembly-count 0", res)
# set the log level - must be done on startup?
ci.HandleCommand(
"settings set target.process.extra-startup-command QSetLogging:bitmask="
+ CONFIG_LOG_LEVEL
+ ";",
res,
)
if CONFIG_USE_CUSTOM_DISASSEMBLY_FORMAT == 1:
ci.HandleCommand(
"settings set disassembly-format " + CUSTOM_DISASSEMBLY_FORMAT, res
)
# the hook that makes everything possible :-)
ci.HandleCommand(
"command script add -h '(lldbinit)' -f lldbinit.HandleProcessLaunchHook HandleProcessLaunchHook",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) The main lldbinit hook.' -f lldbinit.HandleHookStopOnTarget HandleHookStopOnTarget",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Display the current disassembly/CPU context.' -f lldbinit.HandleHookStopOnTarget context",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Alias to context command.' -- ctx HandleHookStopOnTarget",
res,
)
# commands
ci.HandleCommand(
"command script add -h '(lldbinit) Print list of available commands.' -f lldbinit.cmd_lldbinitcmds lldbinitcmds",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Connect to debugserver running on iPhone.' -f lldbinit.cmd_IphoneConnect iphone",
res,
)
#
# comments commands
#
ci.HandleCommand(
"command script add -h '(lldbinit) Add disassembly comment.' -f lldbinit.cmd_addcomment acm",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Remove disassembly comment.' -f lldbinit.cmd_delcomment dcm",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) List disassembly comments.' -f lldbinit.cmd_listcomments lcm",
res,
)
# fuck the nazis :-)
# save session, restore session, list session commands
ci.HandleCommand(
"command script add -h '(lldbinit) Save breakpoint session.' -f lldbinit.cmd_save_session ss",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Restore breakpoint session.' -f lldbinit.cmd_restore_session rs",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) List breakpoint sessions.' -f lldbinit.cmd_list_sessions ls",
res,
)
#
# dump memory commands
#
ci.HandleCommand(
"command script add -h '(lldbinit) Memory hex dump in byte format.' -f lldbinit.cmd_db db",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Memory hex dump in word format.' -f lldbinit.cmd_dw dw",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Memory hex dump in double word format.' -f lldbinit.cmd_dd dd",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Memory hex dump in quad word format.' -f lldbinit.cmd_dq dq",
res,
)
# XXX: fix help
ci.HandleCommand(
"command script add -h '(lldbinit) Disassemble instructions at address.' -f lldbinit.cmd_DumpInstructions u",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Memory search.' -f lldbinit.cmd_findmem findmem",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Display process memory regions.' -f lldbinit.cmd_showregions showregions",
res,
)
#
# Settings related commands
#
ci.HandleCommand(
"command script add -h '(lldbinit) Configure lldb and lldbinit options.' -f lldbinit.cmd_enable enable",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Configure lldb and lldbinit options.' -f lldbinit.cmd_disable disable",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Set number of instruction lines in code window.' -f lldbinit.cmd_contextcodesize contextcodesize",
res,
)
# a few settings aliases
ci.HandleCommand(
"command alias -h '(lldbinit) Enable the stop on library load events.' -- enablesolib enable solib",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Disable the stop on library load events.' -- disablesolib disable solib",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Enable target ASLR.' -- enableaslr enable aslr",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Disable target ASLR.' -- disableaslr disable aslr",
res,
)
#
# Breakpoint related commands
#
# replace the default alias with our own version
ci.HandleCommand("command unalias b", res)
# software breakpoints
ci.HandleCommand(
"command script add -h '(lldbinit) Set a software breakpoint.' -f lldbinit.cmd_bp b",
res,
)
# alias "bp" command that exists in gdbinit
ci.HandleCommand("command alias -h '(lldbinit) Alias to b.' -- bp b", res)
ci.HandleCommand(
"command script add -h '(lldbinit) Set a temporary software breakpoint.' -f lldbinit.cmd_bpt bpt",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Set a temporary breakpoint on next instruction.' -f lldbinit.cmd_bpn bpn",
res,
)
# hardware breakpoints
ci.HandleCommand(
"command script add -h '(lldbinit) Set an hardware breakpoint.' -f lldbinit.cmd_bh bh",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Set a temporary hardware breakpoint.' -f lldbinit.cmd_bht bht",
res,
)
# module breakpoints
ci.HandleCommand(
"command script add -h '(lldbinit) Breakpoint on module load.' -f lldbinit.cmd_bm bm",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Clear all module load breakpoints.' -f lldbinit.cmd_bmc bmc",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) List all on module load breakpoints.' -f lldbinit.cmd_bml bml",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Enable anti-anti-debugging measures.' -f lldbinit.cmd_antidebug antidebug",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Print all images available at gdb_image_notifier() breakpoint.' -f lldbinit.cmd_print_notifier_images print_images",
res,
)
# disable a breakpoint or all
ci.HandleCommand(
"command script add -h '(lldbinit) Disable a breakpoint.' -f lldbinit.cmd_bpd bpd",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Disable all breakpoints.' -f lldbinit.cmd_bpda bpda",
res,
)
# clear a breakpoint or all
ci.HandleCommand(
"command script add -h '(lldbinit) Clear a breakpoint.' -f lldbinit.cmd_bpc bpc",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Clear all breakpoints' -- bpca breakpoint delete",
res,
)
# enable a breakpoint or all
ci.HandleCommand(
"command script add -h '(lldbinit) Enable a breakpoint.' -f lldbinit.cmd_bpe bpe",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Enable all breakpoints.' -f lldbinit.cmd_bpea bpea",
res,
)
# commands to set temporary int3 patches and restore original bytes
ci.HandleCommand(
"command script add -h '(lldbinit) Patch memory address with INT3.' -f lldbinit.cmd_int3 int3",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Restore original byte at address patched with INT3.' -f lldbinit.cmd_rint3 rint3",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) List all INT3 patched addresses.' -f lldbinit.cmd_listint3 listint3",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Patch memory address with NOP.' -f lldbinit.cmd_nop nop",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Patch memory address with NULL.' -f lldbinit.cmd_null null",
res,
)
# change eflags commands
ci.HandleCommand(
"command script add -h '(lldbinit) Change adjust CPU flag.' -f lldbinit.cmd_cfa cfa",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change carry CPU flag.' -f lldbinit.cmd_cfc cfc",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change direction CPU flag.' -f lldbinit.cmd_cfd cfd",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change interrupt CPU flag.' -f lldbinit.cmd_cfi cfi",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change overflow CPU flag.' -f lldbinit.cmd_cfo cfo",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change parity CPU flag.' -f lldbinit.cmd_cfp cfp",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change sign CPU flag.' -f lldbinit.cmd_cfs cfs",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change trap CPU flag.' -f lldbinit.cmd_cft cft",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change zero CPU flag.' -f lldbinit.cmd_cfz cfz",
res,
)
# change NZCV flags - exclusive commands to AArch64 (Z, C are common)
ci.HandleCommand(
"command script add -h '(lldbinit) Change negative CPU flag.' -f lldbinit.cmd_cfn cfn",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Change overflow CPU flag.' -f lldbinit.cmd_cfv cfv",
res,
)
# skip/step current instruction commands
ci.HandleCommand(
"command script add -h '(lldbinit) Skip current instruction.' -f lldbinit.cmd_skip skip",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Step over calls and loop instructions.' -f lldbinit.cmd_stepo stepo",
res,
)
# load breakpoints from file
ci.HandleCommand(
"command script add -h '(lldbinit) Load breakpoints from file.' -f lldbinit.cmd_LoadBreakPoints lb",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Load breakpoints from file.' -f lldbinit.cmd_LoadBreakPointsRva lbrva",
res,
)
# cracking friends
ci.HandleCommand(
"command script add -h '(lldbinit) Return from current function.' -f lldbinit.cmd_crack crack",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Set a breakpoint and return from that function.' -f lldbinit.cmd_crackcmd crackcmd",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Set a breakpoint and set a register value. doesn't return from function.' -f lldbinit.cmd_crackcmd_noret crackcmd_noret",
res,
)
# alias for existing breakpoint commands
# list all breakpoints
ci.HandleCommand(
"command script add -h '(lldbinit) List breakpoints.' -f lldbinit.cmd_bpl bpl",
res,
)
# to set breakpoint commands - I hate typing too much
ci.HandleCommand(
"command alias -h '(lldbinit) breakpoint command add alias.' -- bcmd breakpoint command add",
res,
)
# launch process and stop at entrypoint (not exactly as gdb command that just inserts breakpoint)
# replace the default run alias with our version
ci.HandleCommand("command unalias r", res)
ci.HandleCommand("command unalias run", res)
ci.HandleCommand(
"command script add -h '(lldbinit) Start the target and stop at entrypoint.' -f lldbinit.cmd_run r",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Start the target and stop at entrypoint.' -- run r",
res,
)
# usually it will be inside dyld and not the target main()
ci.HandleCommand(
"command alias -h '(lldbinit) Start target and stop at entrypoint.' -- break_entrypoint process launch --stop-at-entry",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Show otool output of Mach-O load commands.' -f lldbinit.cmd_show_loadcmds show_loadcmds",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Show otool output of Mach-O header.' -f lldbinit.cmd_show_header show_header",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Test function - do not use :-).' -f lldbinit.cmd_tester tester",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) Set start address to display on data window.' -f lldbinit.cmd_datawin datawin",
res,
)
# used mostly for aliases below but can be called as other commands
ci.HandleCommand(
"command script add -h '(lldbinit) Update register function to be used by all the register alias.' -f lldbinit.cmd_update_register update_register",
res,
)
# shortcut command to modify registers content
if CONFIG_ENABLE_REGISTER_SHORTCUTS == 1:
# x64
ci.HandleCommand(
"command alias -h '(lldbinit) Update RIP register.' -- rip update_register rip",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RAX register.' -- rax update_register rax",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RBX register.' -- rbx update_register rbx",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RBP register.' -- rbp update_register rbp",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RSP register.' -- rsp update_register rsp",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RDI register.' -- rdi update_register rdi",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RSI register.' -- rsi update_register rsi",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RDX register.' -- rdx update_register rdx",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update RCX register.' -- rcx update_register rcx",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R8 register.' -- r8 update_register r8",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R9 register.' -- r9 update_register r9",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R10 register.' -- r10 update_register r10",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R11 register.' -- r11 update_register r11",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R12 register.' -- r12 update_register r12",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R13 register.' -- r13 update_register r13",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R14 register.' -- r14 update_register r14",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update R15 register.' -- r15 update_register r15",
res,
)
# x86
ci.HandleCommand(
"command alias -h '(lldbinit) Update EIP register.' -- eip update_register eip",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update EAX register.' -- eax update_register eax",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update EBX register.' -- ebx update_register ebx",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update EBP register.' -- ebp update_register ebp",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update ESP register.' -- esp update_register esp",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update EDI register.' -- edi update_register edi",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update ESI register.' -- esi update_register esi",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update EDX register.' -- edx update_register edx",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update ECX register.' -- ecx update_register ecx",
res,
)
# ARM64
ci.HandleCommand(
"command alias -h '(lldbinit) Update X0 register.' -- x0 update_register x0",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X1 register.' -- x1 update_register x1",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X2 register.' -- x2 update_register x2",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X3 register.' -- x3 update_register x3",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X4 register.' -- x4 update_register x4",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X5 register.' -- x5 update_register x5",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X6 register.' -- x6 update_register x6",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X7 register.' -- x7 update_register x7",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X8 register.' -- x8 update_register x8",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X9 register.' -- x9 update_register x9",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X10 register.' -- x10 update_register x10",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X11 register.' -- x11 update_register x11",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X12 register.' -- x12 update_register x12",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X13 register.' -- x13 update_register x13",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X14 register.' -- x14 update_register x14",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X15 register.' -- x15 update_register x15",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X16 register.' -- x16 update_register x16",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X17 register.' -- x17 update_register x17",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X18 register.' -- x18 update_register x18",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X19 register.' -- x19 update_register x19",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X20 register.' -- x20 update_register x20",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X21 register.' -- x21 update_register x21",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X22 register.' -- x22 update_register x22",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X23 register.' -- x23 update_register x23",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X24 register.' -- x24 update_register x24",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X25 register.' -- x25 update_register x25",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X26 register.' -- x26 update_register x26",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X27 register.' -- x27 update_register x27",
res,
)
ci.HandleCommand(
"command alias -h '(lldbinit) Update X28 register.' -- x28 update_register x28",
res,
)
if CONFIG_KEYSTONE_AVAILABLE == 1:
ci.HandleCommand(
"command script add -h '(lldbinit) 32 bit x86 interactive Keystone based assembler.' -f lldbinit.cmd_asm32 asm32",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) 64 bit x86 interactive Keystone based assembler.' -f lldbinit.cmd_asm64 asm64",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) 32 bit ARM interactive Keystone based assembler.' -f lldbinit.cmd_arm32 arm32",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) 64 bit ARM interactive Keystone based assembler.' -f lldbinit.cmd_arm64 arm64",
res,
)
ci.HandleCommand(
"command script add -h '(lldbinit) 32 bit ARM Thumb interactive Keystone based assembler.' -f lldbinit.cmd_armthumb armthumb",
res,
)
# add the hook - we don't need to wait for a target to be loaded
# Note: since I removed the original stop-disassembly-count trick to allegedly avoid
# double loading it had a side effect to keep adding multiple copies of the hook
# when doing multiple imports of the script (for testing mostly)
# a check is now implemented where the hook is only added if no previous hook exist
ci.HandleCommand("target stop-hook list", res)
if res.Succeeded():
# XXX: older lldb crashes if we set the -s option...
# if "HandleProcessLaunchHook" not in res.GetOutput():
# ci.HandleCommand("target stop-hook add -n _dyld_start -s /usr/lib/dyld -o 'HandleProcessLaunchHook'", res)
if "HandleHookStopOnTarget" not in res.GetOutput():
ci.HandleCommand("target stop-hook add -o 'HandleHookStopOnTarget'", res)
else:
print("[-] error: failed to list stop hooks and our hook isn't loaded")
ci.HandleCommand(
"command script add -h '(lldbinit) Display lldbinit banner.' --function lldbinit.cmd_banner banner",
res,
)
# custom commands
ci.HandleCommand(
"command script add -h '(lldbinit) Fix return breakpoint.' -f lldbinit.cmd_fixret fixret",
res,
)
# displays the version banner when lldb is loaded
debugger.HandleCommand("banner")
return
0