| 102 | } |
| 103 | |
| 104 | static size_t get_lib_size(void *base_address) |
| 105 | { |
| 106 | #if OS_WIN |
| 107 | auto dos_header = (IMAGE_DOS_HEADER *)base_address; |
| 108 | auto nt_headers = (IMAGE_NT_HEADERS *)((uint8_t *)(base_address) + dos_header->e_lfanew); |
| 109 | return nt_headers->OptionalHeader.SizeOfImage; |
| 110 | #elif OS_MAC |
| 111 | struct mach_header_64 *header = (struct mach_header_64 *)base_address; |
| 112 | |
| 113 | size_t size = sizeof(*header); // Size of the header |
| 114 | size += header->sizeofcmds; // Size of the load commands |
| 115 | |
| 116 | struct load_command *lc = (struct load_command *)(header + 1); |
| 117 | for (uint32_t i = 0; i < header->ncmds; i++) |
| 118 | { |
| 119 | if (lc->cmd == LC_SEGMENT_64) |
| 120 | { |
| 121 | size += ((struct segment_command_64 *)lc)->vmsize; // Size of segments |
| 122 | } |
| 123 | lc = (struct load_command *)((char *)lc + lc->cmdsize); |
| 124 | } |
| 125 | return size; |
| 126 | #endif |
| 127 | } |
| 128 | |
| 129 | void *dylib::find_memory(const void *rladdr, const char *pattern) |
| 130 | { |