さて、私は長い間、実行時にプロセスを実行する際にロードされたOSX Dylibのベースアドレスを取得しようとしています。
task_info を使用した後、dyld_all_image_infos を使用して実行時にすべての接続された Dylib をダンプし、そこに名前と ImageLoadADDRESS、mach_header、および segment_command を取得しました。
しかし、実行時にベースアドレスに到達できません..
実行時に要求されたイメージの実際のベースアドレスを取得する方法について混乱していることを除いて、すべてがうまく機能します! また、imageLoadAddress を使用して mach_header を取得した後に取得したマジック ナンバーは "feedfacf" です。「feedface」ではないでしょうか?
検索した後、「segment_command」の「fileoff」がデータセクションにつながるはずであることがわかりました。これも機能していません。
私の出力は見栄えがしますが、たとえばチートエンジンでこのメモリ領域を表示しようとすると、空です!
私のデバッグ出力:
mach object header
magic number feedfacf
cputype 01000007 - x86_64
subcputype 00000003
filetype 00000006
ncmds 00000015
sizeofcmds 00000988
flags 00118085
Segment
File Off 45545f5f
DYLIB: client.dylib
私のコードは次のとおりです。
// mach_header
mach_msg_type_number_t size4 = sizeof(mach_header);
uint8_t* info_addr2 =
readProcessMemory(this->task, (mach_vm_address_t) info[i].imageLoadAddress, &size4);
mach_header *info2 = (mach_header*) info_addr2;
// segment
mach_msg_type_number_t size5 = sizeof(segment_command);
uint8_t* info_addr3 =
readProcessMemory(this->task, (mach_vm_address_t) info[i].imageLoadAddress + sizeof(info2), &size5);
segment_command *info3 = (segment_command*) info_addr3;
tmp_str = tmp_str.substr(tmp_str.find_last_of("/") + 1, tmp_str.length());
//printf("%i Debug: %s\n", i, tmp_str.c_str());
this->dylibs[cc].Name = tmp_str;
this->dylibs[cc].imgHead = info2;
// this->dylibs[i].tSize = this->size_of_image((mach_header*)info[i].imageLoadAddress);
if(strcmp(tmp_str.c_str(), "client.dylib") == 0){
this->client = cc;
printf("mach object header\n");
printf("magic number\t%08x\n", info2->magic);
printf("cputype\t\t%08x - %s\n", info2->cputype,cpu_type_name(info2->cputype));//cputype_to_string(info2->filetype)
printf("subcputype\t%08x\n", info2->cpusubtype);
printf("filetype\t%08x\n", info2->filetype);// filetype_to_string(info2->filetype)
printf("ncmds\t\t%08x\n", info2->ncmds);
printf("sizeofcmds\t%08x\n", info2->sizeofcmds);
printf("flags\t\t%08x\n", info2->flags);
printf("Segment\n");
printf("File Off\t%x\n", info3->fileoff );
誰でも私を助けることができますか?感謝します!( ps: コードは少しわかりにくいですが、私は何日も前から作業を行っていて、動作させることができないので、今はより良いスタイルで書きたくありませんでした!)