DerekSelander / dsdump

An improved nm + Objective-C & Swift class-dump
1.12k stars 111 forks source link

Failing to load mach-o correctly may lead to segment fault #26

Open 4B5F5F4B opened 3 years ago

4B5F5F4B commented 3 years ago

Hi all,

While trying your tool I came across some segment fault like the issue posted here.

https://github.com/DerekSelander/dsdump/issues/25

I spent some time to debug the root cause of mentioned bug, I find dsdump doesn't load mach-o into memory correctly. The author naively mapped mach-o file into memory through mmap(. You can find the following code in XRMachOLibrary.mm

void buff = ::mmap((void)0x0000000400000000UL, fsize, PROT_READ, MAP_PRIVATE, self.fd, 0); payload::data = (uint8_t *)buff; // self.data; payload::size = fsize;

In fact you'd better parse all segments carefully.