OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import re |
| 6 import subprocess |
| 7 |
| 8 |
| 9 def ReadMachOTextLoadAddress(file_name): |
| 10 """ |
| 11 This function returns the load address of the TEXT segment of a Mach-O file. |
| 12 """ |
| 13 regex = re.compile(r".* vmaddr 0x([\dabcdef]*)") |
| 14 cmd = ["otool", "-l", file_name] |
| 15 output = subprocess.check_output(cmd).split('\n') |
| 16 for i in range(len(output) - 3): |
| 17 # It's possible to use a regex here instead, but these conditionals are much |
| 18 # clearer. |
| 19 if ("cmd LC_SEGMENT_64" in output[i] and |
| 20 "cmdsize" in output[i + 1] and |
| 21 "segname __TEXT" in output[i + 2] and |
| 22 "vmaddr" in output[i + 3]): |
| 23 result = regex.match(output[i + 3]) |
| 24 assert result |
| 25 return int(result.group(1), 16) |
| 26 return None |
OLD | NEW |