self.vmaddr = None
self.pipe = None
- def get_binary_vmaddr(self):
- """Get the slide value to be added to the address.
-
- We're looking for the following piece in otool -l output:
- Load command 0
- cmd LC_SEGMENT
- cmdsize 736
- segname __TEXT
- vmaddr 0x00000000
- """
- if self.vmaddr:
- return self.vmaddr
- cmdline = ['otool', '-l', self.binary]
- pipe = subprocess.Popen(cmdline,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
- is_text = False
- vmaddr = 0
- for line in pipe.stdout:
- line = line.strip()
- if line.startswith('segname'):
- is_text = (line == 'segname __TEXT')
- continue
- if line.startswith('vmaddr') and is_text:
- sv = line.split(' ')
- vmaddr = int(sv[-1], 16)
- break
- self.vmaddr = vmaddr
- return self.vmaddr
-
def write_addr_to_pipe(self, offset):
- slide = self.get_binary_vmaddr()
- print >> self.pipe.stdin, '0x%x' % (int(offset, 16) + slide)
+ print >> self.pipe.stdin, '0x%x' % int(offset, 16)
def open_atos(self):
if DEBUG:
current_load_cmd_count_ = -1;
current_load_cmd_addr_ = 0;
current_magic_ = 0;
+ current_filetype_ = 0;
}
// Next and NextSegmentLoad were inspired by base/sysinfo.cc in
const SegmentCommand* sc = (const SegmentCommand *)lc;
if (start) *start = sc->vmaddr + dlloff;
if (end) *end = sc->vmaddr + sc->vmsize + dlloff;
- if (offset) *offset = sc->fileoff;
+ if (offset) {
+ if (current_filetype_ == /*MH_EXECUTE*/ 0x2) {
+ *offset = sc->vmaddr;
+ } else {
+ *offset = sc->fileoff;
+ }
+ }
if (filename) {
internal_strncpy(filename, _dyld_get_image_name(current_image_),
filename_size);
// Set up for this image;
current_load_cmd_count_ = hdr->ncmds;
current_magic_ = hdr->magic;
+ current_filetype_ = hdr->filetype;
switch (current_magic_) {
#ifdef MH_MAGIC_64
case MH_MAGIC_64: {