MCPcopy
hub / github.com/DerekSelander/LLDB / generateLazyPointerScriptWithOptions

Function generateLazyPointerScriptWithOptions

lldb_commands/ds.py:707–792  ·  view source on GitHub ↗
(section)

Source from the content-addressed store, hash-verified

705 '''
706
707def generateLazyPointerScriptWithOptions(section):
708 ptrsize = getType("void*").GetByteSize()
709 size = section.GetByteSize() / ptrsize
710 baseAddress = section.addr.module.FindSection("__TEXT").addr.GetLoadAddress(getTarget())
711 linkeditAddress = section.addr.module.FindSection("__LINKEDIT").addr.GetLoadAddress(getTarget())
712 la_symbol_addr = section.addr.module.FindSection("__DATA").FindSubSection("__la_symbol_ptr").addr.GetLoadAddress(getTarget())
713 script = 'char *retstring[' + str(size) + '];\n'
714 script += 'uint64_t baseAddress = (uintptr_t)' + str(baseAddress) + ';\n'
715 script += 'uint64_t linkeditAddress = (uintptr_t)' + str(linkeditAddress) + ';\n'
716 script += generateMachOHeaders()
717 script += '''
718 memset(&retstring, 0, sizeof(retstring));
719
720 ds_symtab_command *symtab_cmd = NULL;
721 ds_dysymtab_command *dysymtab_cmd = NULL;
722 char *strtab = NULL;
723
724 ds_header *dsheader = (ds_header *)baseAddress;
725 ds_section *la_section = NULL;
726
727 ds_segment *cur_seg = NULL;
728 ds_segment *linkeditSegment = NULL;
729 struct nlist_64 *symtab = NULL;
730 uintptr_t pagezero = 0;
731
732 uintptr_t cur = baseAddress + sizeof(ds_header);
733 for (int i = 0; i < dsheader->ncmds; i++, cur += cur_seg->cmdsize) {
734 cur_seg = (ds_segment *)cur;
735 if (cur_seg->cmd == 0x2) { // LC_SYMTAB
736 symtab_cmd = (ds_symtab_command *)cur_seg;
737
738 } else if (cur_seg->cmd == 0xb) { // LC_DYSYMTAB
739 dysymtab_cmd = (ds_dysymtab_command *)cur_seg;
740 }
741 else if (cur_seg->cmd == 0x19 && strcmp(cur_seg->segname, "__LINKEDIT") == 0) {
742 linkeditSegment = cur_seg;
743 }
744 else if (cur_seg->cmd == 0x19 && strcmp(cur_seg->segname, "__PAGEZERO") == 0) {
745 pagezero = cur_seg->vmsize;
746 }
747 else if (cur_seg->cmd == 0x19 && strcmp(cur_seg->segname, "__DATA") == 0) {
748 uintptr_t curs = cur + sizeof(ds_segment);
749 for (int j = 0; j < cur_seg->nsects; j++, curs += sizeof(ds_section)) {
750 ds_section *cur_sect = (ds_section*)curs;
751 if (strcmp(cur_sect->sectname, "__la_symbol_ptr") == 0) {
752 la_section = (ds_section *)curs;
753 break;
754 }
755 }
756 }
757 }
758
759 uintptr_t linkedit_base = baseAddress + linkeditSegment->vmaddr - linkeditSegment->fileoff - pagezero;
760 strtab = (char *)(symtab_cmd->stroff + linkedit_base);
761 symtab = (struct nlist_64 *)(symtab_cmd->symoff + linkedit_base);
762
763 if (!symtab_cmd || !dysymtab_cmd || !strtab || !la_section) {
764 //strcat(retstring, "0|||An error has occurred in parsing");

Callers 1

getLazyPointersFromDataFunction · 0.85

Calls 3

getTypeFunction · 0.85
getTargetFunction · 0.85
generateMachOHeadersFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…