Skip to content
This repository was archived by the owner on Apr 21, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions dyld_decache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ class ExtraStringRepository {

boost::unordered_map<const char*, int> _indices;
std::vector<Entry> _entries;
size_t _total_size;

section _template;

Expand Down Expand Up @@ -458,7 +457,7 @@ class ExtraStringRepository {
}

void increase_size_by(size_t delta) { _template.size += delta; }
size_t total_size() const { return _template.size; }
uint32_t total_size() const { return _template.size; }
bool has_content() const { return _template.size != 0; }

// Get the 'section' structure for the extra section this repository
Expand Down Expand Up @@ -497,7 +496,7 @@ class ExtraBindRepository {
}
}

long optimize_and_write(FILE* f) {
uint32_t optimize_and_write(FILE* f) {
typedef boost::unordered_map<uint32_t, Entry>::value_type V;
typedef boost::unordered_map<int, std::vector<const Entry*> > M;
typedef std::pair<int, uint32_t> P;
Expand All @@ -512,7 +511,7 @@ class ExtraBindRepository {

fputc(BIND_OPCODE_SET_TYPE_IMM | 1, f);

long size = 1;
uint32_t size = 1;
BOOST_FOREACH(const M::value_type& pair, entries_by_libord) {
int libord = pair.first;
if (libord < 0x10) {
Expand Down Expand Up @@ -671,15 +670,15 @@ class DecachingFile : public MachOFile {
};

struct {
long rebase_off, bind_off, weak_bind_off,
uint32_t rebase_off, bind_off, weak_bind_off,
lazy_bind_off, export_off, // dyld_info
symoff, stroff, // symtab
tocoff, modtaboff, extrefsymoff,
indirectsymoff, extreloff, locreloff, // dysymtab
dataoff, // linkedit_data_command (dummy)
dataoff_cs, dataoff_ssi, dataoff_fs;
long bind_size;
int32_t strsize;
uint32_t bind_size;
uint32_t strsize;
} _new_linkedit_offsets;

private:
Expand Down Expand Up @@ -1197,7 +1196,7 @@ class ProgramContext {
_macho_files.clear();
for (uint32_t i = 0; i < _header->imagesCount; ++ i) {
const mach_header* mh = _f->peek_data_at<mach_header>(this->from_vmaddr(_images[i].address));
_macho_files.push_back(MachOFile(mh, this, _images[i].address));
_macho_files.push_back(MachOFile(mh, this, static_cast<uint32_t>(_images[i].address)));
}

for (uint32_t i = 0; i < _header->imagesCount; ++ i) {
Expand Down Expand Up @@ -1278,7 +1277,7 @@ void DecachingFile::write_segment_content(const segment_command* segcmd) {
ExtraStringRepository* repo = this->repo_for_segname(segcmd->segname);

const char* data_ptr = _context->peek_char_at_vmaddr(segcmd->vmaddr);
long new_fileoff = ftell(_f);
uint32_t new_fileoff = static_cast<uint32_t>(ftell(_f));

fwrite(data_ptr, 1, segcmd->filesize, _f);
uint32_t filesize = segcmd->filesize;
Expand Down Expand Up @@ -1309,8 +1308,8 @@ void DecachingFile::write_real_linkedit(const load_command* cmd) {
// and pad to make sure the beginning is aligned with 'objsize' boundary.
#define TRY_WRITE(offmem, countmem, objsize) \
if (cmdvar->offmem && cmdvar->countmem) { \
long curloc = ftell(_f); \
long extra = curloc % objsize; \
uint32_t curloc = static_cast<uint32_t>(ftell(_f)); \
uint32_t extra = curloc % objsize; \
if (extra != 0) { \
char padding[objsize] = {0}; \
fwrite(padding, 1, objsize-extra, _f); \
Expand All @@ -1328,8 +1327,8 @@ void DecachingFile::write_real_linkedit(const load_command* cmd) {
case LC_DYLD_INFO_ONLY: {
const dyld_info_command* cmdvar = static_cast<const dyld_info_command*>(cmd);
TRY_WRITE(rebase_off, rebase_size, 1);
long curloc = ftell(_f);
long extra_size = _extra_bind.optimize_and_write(_f);
uint32_t curloc = static_cast<uint32_t>(ftell(_f));
uint32_t extra_size = _extra_bind.optimize_and_write(_f);
TRY_WRITE(bind_off, bind_size, 1);
_new_linkedit_offsets.bind_off = curloc;
_new_linkedit_offsets.bind_size += extra_size;
Expand All @@ -1346,7 +1345,7 @@ void DecachingFile::write_real_linkedit(const load_command* cmd) {
// take those strings which are used by the symbol.
const symtab_command* cmdvar = static_cast<const symtab_command*>(cmd);
if (cmdvar->symoff && cmdvar->nsyms) {
_new_linkedit_offsets.stroff = ftell(_f);
_new_linkedit_offsets.stroff = static_cast<uint32_t>(ftell(_f));

nlist* syms = new nlist[cmdvar->nsyms];
memcpy(syms, _context->_f->peek_data_at<nlist>(cmdvar->symoff), sizeof(*syms) * cmdvar->nsyms);
Expand All @@ -1361,8 +1360,8 @@ void DecachingFile::write_real_linkedit(const load_command* cmd) {
}
_new_linkedit_offsets.strsize = cur_strx;

long curloc = ftell(_f);
long extra = curloc % sizeof(nlist);
uint32_t curloc = static_cast<uint32_t>(ftell(_f));
uint32_t extra = curloc % sizeof(nlist);
if (extra != 0) {
char padding[sizeof(nlist)] = {0};
fwrite(padding, 1, sizeof(nlist)-extra, _f);
Expand Down