···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
27677+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
28202921#include "MachO.h"
3022#include "FatMachO.h"
+23-28
src/libmach-o/MachO.h
···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
27161717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
28202921#ifndef MACH_O_H_
3022#define MACH_O_H_
···1059710698 const std::vector<Symbol>& symbols() const { return m_symbols; }
10799108108- const char* base() const { return m_base; }
100100+ uintptr_t base() const { return m_base; }
109101110102 uint64_t entry() const { return m_entry; }
111103 uint64_t main() const { return m_main; }
···138130 std::vector<Bind*> m_binds;
139131 std::vector<Export*> m_exports;
140132 std::vector<Symbol> m_symbols;
141141- const char* m_base;
133133+ uintptr_t m_base;
142134 uint64_t m_entry, m_main;
143135 std::vector<uint64_t> m_init_funcs;
144136 std::vector<uint64_t> m_exit_funcs;
···162154private:
163155 std::vector<std::string> m_archs;
164156};
157157+158158+// we express stub binds as another type of ordinary bind
159159+#define BIND_TYPE_STUB 100
165160166161#endif // MACH_O_H_
+105-85
src/libmach-o/MachOImpl.cpp
···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
11+/*
22+This file is part of Darling.
27344+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
28202921#include "MachOImpl.h"
3022#include "log.h"
···4638template <class section>
4739void MachOImpl::readClassicBind(const section& sec, uint32_t* dysyms, uint32_t* symtab, const char* symstrtab)
4840{
4949- uint32_t indirect_offset = sec.reserved1;
5050- int count = sec.size / m_ptrsize;
4141+ const uint32_t indirect_offset = sec.reserved1;
4242+ const int count = sec.size / m_ptrsize;
51435244 for (int i = 0; i < count; i++)
5345 {
···6355 bind->ordinal = 1;
6456 bind->is_weak = ((sym->n_desc & N_WEAK_DEF) != 0);
6557 bind->is_classic = true;
6666- LOGF("add classic bind! %s type=%d sect=%d desc=%d value=%lld "
6767- "vmaddr=%p is_weak=%d\n",
6868- bind->name.c_str(), sym->n_type, sym->n_sect, sym->n_desc, (ll)sym->n_value,
6969- (void*)(bind->vmaddr), bind->is_weak);
5858+ LOG << "add classic bind: " << bind->name << " type=" << sym->n_type << " sect=" << sym->n_sect
5959+ << " desc=" << sym->n_desc << " value=" << sym->n_value << " vmaddr=" << (void*)(bind->vmaddr)
6060+ << " is_weak=" << bind->is_weak << std::endl;
7061 m_binds.push_back(bind);
7162 }
7263}
73646565+void MachOImpl::readStubBind(const section& sec, uint32_t* dysyms, uint32_t* symtab, const char* symstrtab)
6666+{
6767+ const uint32_t element_size = sec.reserved2;
6868+ const uint32_t indirect_offset = sec.reserved1;
6969+ const int count = sec.size / element_size;
7070+7171+ if (element_size != 5)
7272+ {
7373+ LOG << "MachOImpl::readStubBind(): cannot handle stubs of elem size != 5, size=" << element_size << std::endl;
7474+ return;
7575+ }
7676+7777+ for (int i = 0; i < count; i++)
7878+ {
7979+ uint32_t dysym = dysyms[indirect_offset + i];
8080+ uint32_t index = dysym & 0x3fffffff;
8181+ nlist* sym = (nlist*)(symtab + index * 3);
8282+8383+ MachO::Bind* bind = new MachO::Bind();
8484+ bind->name = symstrtab + sym->n_strx;
8585+ bind->vmaddr = sec.addr + i * element_size;
8686+ bind->value = sym->n_value;
8787+ bind->type = BIND_TYPE_STUB;
8888+ bind->ordinal = 1;
8989+ bind->is_weak = ((sym->n_desc & N_WEAK_DEF) != 0);
9090+ bind->is_classic = true;
9191+9292+ m_binds.push_back(bind);
9393+9494+ LOG << "add stub bind: " << bind->name.c_str() << " vmaddr=" << (void*) bind->vmaddr << std::endl;
9595+ }
9696+}
74977598template <class segment_command, class section>
7699void MachOImpl::readSegment(char* cmds_ptr, std::vector<segment_command*>* segments, std::vector<section*>* bind_sections)
···78101 segment_command* segment = reinterpret_cast<segment_command*>(cmds_ptr);
79102 segments->push_back(segment);
801038181- LOGF("segment %s: vmaddr=%p vmsize=%llu "
8282- "fileoff=%llu filesize=%llu "
8383- "maxprot=%d initprot=%d nsects=%u flags=%u\n",
8484- segment->segname,
8585- (void*)(intptr_t)segment->vmaddr, (ull)segment->vmsize,
8686- (ull)segment->fileoff, (ull)segment->filesize,
8787- segment->maxprot, segment->initprot,
8888- segment->nsects, segment->flags);
104104+ LOG << "segment " << segment->segname << ": vmaddr=" << (void*)segment->vmaddr
105105+ << " vmsize=" << std::hex << segment->vmsize << " file_offset=" << segment->fileoff
106106+ << " file_size=" << segment->filesize << " maxprot=" << segment->maxprot
107107+ << " init_prot=" << segment->initprot << " nsects=" << std::dec << segment->nsects
108108+ << " flags=" << std::hex << segment->flags << std::dec << std::endl;
8910990110 section* sections = reinterpret_cast<section*>(cmds_ptr + sizeof(segment_command));
91111···96116 {
97117 const section& sec = sections[j];
98118 Section savedSection{sec.segname, sec.sectname, uintptr_t(sec.addr), uintptr_t(sec.size)};
9999-100100- LOGF("section %s in %s: "
101101- "addr=%p size=%llu offset=%u align=%u "
102102- "reloff=%u nreloc=%u flags=%u "
103103- "reserved1=%u reserved2=%u\n",
104104- sec.sectname, sec.segname,
105105- (void*)(intptr_t)sec.addr, (ull)sec.size,
106106- sec.offset, sec.align,
107107- sec.reloff, sec.nreloc, sec.flags,
108108- sec.reserved1, sec.reserved2);
119119+120120+ LOG << "section " << sec.sectname << " in " << sec.segname << ": addr="
121121+ << ((void*)(uintptr_t)sec.addr) << " size=" << std::hex << sec.size << " offset="
122122+ << sec.offset << " align=" << sec.align << " reloff=" << sec.reloff
123123+ << " nreloc=" << std::dec << sec.nreloc << " flags=" << std::hex
124124+ << sec.flags << " reserved1=" << sec.reserved1 << " reserved2="
125125+ << sec.reserved2 << std::dec << std::endl;
109126110127 if (savedSection.section.size() > sizeof(sec.sectname))
111128 savedSection.section.resize(sizeof(sec.sectname));
···153170 bind_sections->push_back(sections + j);
154171 break;
155172173173+ case S_SYMBOL_STUBS: // 0x8, byte size of element in reserved2, indir offset in reserved1
174174+ //assert(!m_is64);
175175+ if (!m_is64)
176176+ bind_sections->push_back(sections + j);
177177+ break;
156178 case S_ZEROFILL:
157179 case S_CSTRING_LITERALS: // 0x2
158180 case S_4BYTE_LITERALS: // 0x3
159181 case S_8BYTE_LITERALS: // 0x4
160182 case S_LITERAL_POINTERS: // 0x5
161161- case S_SYMBOL_STUBS: // 0x8, byte size of stub in reserved2
162183 case S_COALESCED:
163184 case S_GB_ZEROFILL:
164185 case S_INTERPOSING: // 0xD
165186 case S_16BYTE_LITERALS:
166187 case S_DTRACE_DOF:
167188 case S_LAZY_DYLIB_SYMBOL_POINTERS:
168168- LOGF("FIXME: section type %d will not be handled for %s in %s (%p)\n",
169169- section_type, sec.sectname, sec.segname, sec.addr);
189189+ LOG << "Section " << sec.sectname << " in " << sec.segname << " not handled with type " << std::hex << section_type << std::dec << std::endl;
170190 break;
171191172192 default:
173173- fprintf(stderr, "Unknown section type: %d\n", section_type);
193193+ std::cerr << "ERROR: Section " << sec.sectname << " in " << sec.segname << " has unknown type " << std::hex << section_type << std::dec << std::endl;
174194 abort();
175195 break;
176196 }
···209229 exp->name = *name_buf;
210230 exp->flag = uleb128(p);
211231 exp->addr = uleb128(p);
212212- LOGF("export: %s %lu %p\n",
213213- name_buf->c_str(), (long)exp->flag, (void*)exp->addr);
232232+ LOG << "export: " << name_buf << " flags=" << std::hex << exp->flag << std::dec << " addr=" << (void*)exp->addr << std::endl;
214233215234 m_exports.push_back(exp);
216235···252271253272 ::lseek(fd, 0, SEEK_SET);
254273255255- char* bin = m_mapped = reinterpret_cast<char*>(
274274+ void* bin = m_mapped = reinterpret_cast<char*>(
256275 ::mmap(NULL, m_mapped_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, m_fd, offset)
257276 );
258277259278 if (bin == MAP_FAILED)
260279 throw std::runtime_error("Cannot mmap Mach-O file");
261280262262- m_base = bin;
281281+ m_base = uintptr_t(bin);
263282264264- mach_header* header = reinterpret_cast<mach_header*>(bin);
283283+ const mach_header* header = reinterpret_cast<mach_header*>(bin);
265284 memcpy(&m_header, header, sizeof(*header));
266285267286 m_is64 = false;
···286305 {
287306 throw std::runtime_error("Unsupported CPU type in Mach-O");
288307 }
289289-290290- // TODO: split into a method
291308309309+ processLoaderCommands(header);
310310+}
311311+312312+void MachOImpl::processLoaderCommands(const mach_header* header)
313313+{
292314 struct load_command* cmds_ptr = reinterpret_cast<struct load_command*>(
293293- bin + (m_is64 ? sizeof(mach_header_64) : sizeof(mach_header))
315315+ m_base + (m_is64 ? sizeof(mach_header_64) : sizeof(mach_header))
294316 );
295317296318 uint32_t* symtab = 0;
···302324303325 for (uint32_t ii = 0; ii < header->ncmds; ii++)
304326 {
305305- LOGF("cmd type:%x\n", cmds_ptr->cmd);
327327+ LOG << "loader command type=" << std::hex << cmds_ptr->cmd << std::dec << std::endl;
306328307329 switch (cmds_ptr->cmd)
308330 {
···332354333355 {
334356 const uint8_t* p = reinterpret_cast<uint8_t*>(
335335- bin + dyinfo->rebase_off);
357357+ m_base + dyinfo->rebase_off);
336358 const uint8_t* end = p + dyinfo->rebase_size;
337359 if (dyinfo->rebase_off && dyinfo->rebase_size)
338360 readRebase(p, end);
···340362341363 {
342364 const uint8_t* p = reinterpret_cast<uint8_t*>(
343343- bin + dyinfo->bind_off);
365365+ m_base + dyinfo->bind_off);
344366 const uint8_t* end = p + dyinfo->bind_size;
345367 readBind(p, end, false);
346368 }
347369348370 {
349371 const uint8_t* p = reinterpret_cast<uint8_t*>(
350350- bin + dyinfo->lazy_bind_off);
372372+ m_base + dyinfo->lazy_bind_off);
351373 const uint8_t* end = p + dyinfo->lazy_bind_size;
352374 readBind(p, end, false);
353375 }
354376355377 {
356378 const uint8_t* p = reinterpret_cast<uint8_t*>(
357357- bin + dyinfo->weak_bind_off);
379379+ m_base + dyinfo->weak_bind_off);
358380 const uint8_t* end = p + dyinfo->weak_bind_size;
359381 readBind(p, end, true);
360382 }
···362384 if (m_need_exports)
363385 {
364386 const uint8_t* p = reinterpret_cast<uint8_t*>(
365365- bin + dyinfo->export_off);
387387+ m_base + dyinfo->export_off);
366388 const uint8_t* end = p + dyinfo->export_size;
367389 if (dyinfo->export_off && dyinfo->export_size)
368390 {
···382404 symtab_cmd->symoff, symtab_cmd->nsyms,
383405 symtab_cmd->stroff, symtab_cmd->strsize);
384406385385- uint32_t* symtab_top = symtab = reinterpret_cast<uint32_t*>(bin + symtab_cmd->symoff);
386386- symstrtab = bin + symtab_cmd->stroff;
407407+ uint32_t* symtab_top = symtab = reinterpret_cast<uint32_t*>(m_base + symtab_cmd->symoff);
408408+ symstrtab = (const char*) m_base + symtab_cmd->stroff;
387409388410 if (FLAGS_READ_SYMTAB)
389411 {
···443465 if (dysymtab_cmd->nindirectsyms)
444466 {
445467 dysyms = reinterpret_cast<uint32_t*>(
446446- bin + dysymtab_cmd->indirectsymoff);
468468+ m_base + dysymtab_cmd->indirectsymoff);
447469 }
448470 if (FLAGS_READ_DYSYMTAB)
449471 {
···462484 LOGF("dysym %d %s(%u)%s%s\n", j, symstrtab + sym[0], index, local, abs);
463485 }
464486465465- uint32_t* dymods = reinterpret_cast<uint32_t*>( bin + dysymtab_cmd->modtaboff);
487487+ uint32_t* dymods = reinterpret_cast<uint32_t*>( m_base + dysymtab_cmd->modtaboff);
466488 for (uint32_t j = 0; j < dysymtab_cmd->nmodtab; j++)
467489 LOGF("dymods: %u\n", dymods[j]);
468490 }
···473495 case LC_LOAD_DYLINKER:
474496 {
475497 lc_str name = reinterpret_cast<struct dylinker_command*>(cmds_ptr)->name;
476476- LOGF("dylinker: %s\n", (char*)cmds_ptr + name.offset);
498498+ LOG << "dynamic linker: " << ((char*)cmds_ptr + name.offset) << std::endl;
477499 break;
478500 }
479501···483505 case LC_UNIXTHREAD:
484506 {
485507 uint32_t* p = reinterpret_cast<uint32_t*>(cmds_ptr);
486486- LOGF("UNIXTHREAD");
487487-488488- for (uint32_t i = 2; i < p[1]; i++)
489489- LOGF(" %d:%x", i, p[i]);
490490-491491- LOGF("\n");
492508493509 if (m_is64)
494510 m_entry = reinterpret_cast<uint64_t*>(cmds_ptr)[18];
495511 else
496512 m_entry = reinterpret_cast<uint32_t*>(cmds_ptr)[14];
497513498498- LOGF("entry=%llx\n", (ull)m_entry);
514514+ LOG << "UNIXTHREAD entry=" << (void*)m_entry << std::endl;
499515 break;
500516 }
501517502518 case LC_MAIN:
503519 {
504520 entry_point_command* cmd = reinterpret_cast<entry_point_command*>(cmds_ptr);
505505- LOGF("MAIN: entry offset: %x\n", cmd->entryoff);
521521+ LOG << "Main: entry offset: " << std::hex << cmd->entryoff << std::dec << std::endl;
506522 m_main = reinterpret_cast<uint64_t>(m_text_offset + cmd->entryoff);
507523 break;
508524 }
···510526 case LC_LOAD_DYLIB:
511527 {
512528 dylib* lib = &reinterpret_cast<dylib_command*>(cmds_ptr)->dylib;
513513- LOGF("dylib: '%s'\n", (char*)cmds_ptr + lib->name.offset);
514514- m_dylibs.push_back((char*)cmds_ptr + lib->name.offset);
529529+ const char* name = (char*)cmds_ptr + lib->name.offset;
530530+ LOG << "dylib: '" << name << "'\n";
531531+ m_dylibs.push_back(name);
515532 break;
516533 }
517534···521538 reinterpret_cast<char*>(cmds_ptr) + cmds_ptr->cmdsize);
522539 }
523540524524- LOGF("%p vs %p\n", cmds_ptr, bin + m_mapped_size);
541541+ //LOGF("%p vs %p\n", cmds_ptr, bin + m_mapped_size);
525542526543 LOG << "dyinfo: " << dyinfo << ", dysyms: " << dysyms << ", symtab: " << symtab << ", symstrtab: " << symstrtab << ", symbol count: " << m_symbols.size() << std::endl;
527544 // No LC_DYLD_INFO_ONLY, we will read classic binding info.
···534551 }
535552 for (size_t i = 0; i < bind_sections_32.size(); i++)
536553 {
537537- readClassicBind<section>(*bind_sections_32[i], dysyms, symtab, symstrtab);
554554+ if ((bind_sections_32[i]->flags & SECTION_TYPE) == S_SYMBOL_STUBS)
555555+ readStubBind(*bind_sections_32[i], dysyms, symtab, symstrtab);
556556+ else
557557+ readClassicBind<section>(*bind_sections_32[i], dysyms, symtab, symstrtab);
538558 }
539559 }
540560}
+21-26
src/libmach-o/MachOImpl.h
···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
27161717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
28202921#ifndef MACHOIMPL_H
3022#define MACHOIMPL_H
···5143 friend class RebaseState;
5244 friend class BindState;
53454646+ void processLoaderCommands(const mach_header* header);
4747+5448 template <class segment_command, class section>
5549 void readSegment(char* cmds_ptr, std::vector<segment_command*>* segments, std::vector<section*>* bind_sections);
5650···60546155 template <class section>
6256 void readClassicBind(const section& sec, uint32_t* dysyms, uint32_t* symtab, const char* symstrtab);
5757+ void readStubBind(const section& sec, uint32_t* dysyms, uint32_t* symtab, const char* symstrtab);
63586459 char* m_mapped;
6560 size_t m_mapped_size;