Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dyldex] Add --lookup to quickly find the image an address lives in #43

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bin/dyldex
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def _getArguments():
parser.add_argument(
"-b", "--basenames", action="store_true",
help="Print only the basenames of each framework. Only applies when --list-frameworks is specified."
)
parser.add_argument(
"--lookup",
help="Find the library that an address lives in. E.g. dyldex --lookup 0x18008e9f8 dyld_shared_cache_arm64e."
)
parser.add_argument(
"-v", "--verbosity", type=int, choices=[0, 1, 2, 3], default=1,
Expand Down Expand Up @@ -204,6 +208,31 @@ def main():

imageMap[path] = imageData

# Find the image that an address lives in
if args.lookup:
lookupAddr = int(args.lookup, 0)

imagePaths = imageMap.keys()

# sort the paths so they're in VM address order
sortedPaths = sorted(imagePaths, key=lambda path: imageMap[path].address)

previousImagePath = None
for path in sortedPaths:
imageAddr = imageMap[path].address
if lookupAddr < imageAddr:
if previousImagePath is None:
print("Error: address before first image!", file=sys.stderr)
sys.exit(1)
print(os.path.basename(previousImagePath) if args.basenames else previousImagePath)
return
else:
previousImagePath = path
# We got to the end of the list, must be the last image
path = sortedPaths[-1]
print(os.path.basename(path) if args.basenames else path)
return

# list images option
if args.list_frameworks:
imagePaths = imageMap.keys()
Expand Down