Some cleanups.

committer: mfx <mfx> 962208107 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2000-06-28 16:01:47 +00:00
parent 51c6566092
commit 3980081a5a
5 changed files with 39 additions and 22 deletions

1
BUGS
View File

@ -44,6 +44,7 @@ win32/pe
--------
* writeable shared sections (`--force' *may* work)
* certificates in the image
* compressing files containing big BSS requires lots of memory
djgpp2/coff
-----------

View File

@ -499,7 +499,7 @@ int PackTos::canUnpack()
// check header as set by packer
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
throwCantUnpack("file damaged");
throwCantUnpack("program header damaged");
if (!checkFileHeader())
throwCantUnpack("unsupported header flags");
return true;

View File

@ -508,11 +508,13 @@ unsigned PackW32Pe::processImports() // pass 1
if (!u2->shname) return -1;
return strlen(u1->shname) - strlen(u2->shname);
}
} *dlls, **idlls;
};
// +1 for dllnum=0
autoheap_array(struct udll, dlls, dllnum+1);
autoheap_array(struct udll *, idlls, dllnum+1);
soimport = 1024; // safety
dlls = new udll[dllnum+1]; // +1 for dllnum=0
idlls = new udll*[dllnum+1];
unsigned ic,k32o;
for (ic = k32o = 0; dllnum && im->dllname; ic++, im++)
@ -722,9 +724,6 @@ unsigned PackW32Pe::processImports() // pass 1
for (ic = 0; ic < iats.ivnum; ic++)
ilen += iats.ivarr[ic].len;
delete [] dlls;
delete [] idlls;
info("Imports: original size: %u bytes, preprocessed size: %u bytes",ilen,soimport);
return names.ivnum == 1 ? names.ivarr[0].start : 0;
}
@ -1899,16 +1898,20 @@ int PackW32Pe::canUnpack()
fi->readx(isection,sizeof(pe_section_t)*objs);
if (ih.objects < 3)
return -1;
if (memcmp(isection[0].name,"UPX",3))
bool is_packed = (ih.objects == 3 &&
(IDSIZE(15) || ih.entry > isection[1].vaddr));
bool found_ph = false;
if (memcmp(isection[0].name,"UPX",3) == 0)
{
if (ih.objects == 3 && (IDSIZE(15) || ih.entry > isection[1].vaddr))
throwCantUnpack("file is possibly modified/hacked/protected; take care!");
return -1;
found_ph = readPackHeader(1024, isection[1].rawdataptr - 64) // current version
|| readPackHeader(1024, isection[2].rawdataptr); // old versions
}
ph_format = getFormat();
bool b = readPackHeader(1024, isection[1].rawdataptr - 64) // current version
|| readPackHeader(1024, isection[2].rawdataptr); // old versions
return b ? 1 : -1;
if (is_packed && found_ph)
return true;
if (!is_packed && !found_ph)
return -1;
throwCantUnpack("file is possibly modified/hacked/protected; take care!");
return false; // not reached
}
@ -2136,7 +2139,7 @@ void PackW32Pe::unpack(OutputFile *fo)
extrainfo += sizeof (oh);
unsigned objs = oh.objects;
pe_section_t *osection = new pe_section_t[objs]; // FIXME: this might leak
autoheap_array(pe_section_t, osection, objs);
memcpy(osection,extrainfo,sizeof(pe_section_t) * objs);
rvamin = osection[0].vaddr;
extrainfo += sizeof(pe_section_t) * objs;
@ -2177,7 +2180,7 @@ void PackW32Pe::unpack(OutputFile *fo)
oh.headersize = ALIGN_UP(pe_offset + sizeof(oh) + sizeof(pe_section_t) * objs, oh.filealign);
oh.chksum = 0;
// FIXME: ih.flags is checked here because of a bug in 0.92
// FIXME: ih.flags is checked here because of a bug in UPX 0.92
if ((opt->w32pe.strip_relocs && !isdll) || (ih.flags & RELOCS_STRIPPED))
{
oh.flags |= RELOCS_STRIPPED;
@ -2202,7 +2205,7 @@ void PackW32Pe::unpack(OutputFile *fo)
fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign));
copyOverlay(fo, overlay, &obuf);
}
delete [] osection;
ibuf.free();
}
/*

View File

@ -572,15 +572,21 @@ void Packer::putPackHeader(upx_bytep buf, unsigned len)
bool Packer::readPackHeader(unsigned len, off_t seek_offset, upx_byte *buf)
{
unsigned char hbuf[1024];
assert((int)len > 0);
MemBuffer hbuf;
if (buf == NULL)
{
assert(len <= sizeof(hbuf));
hbuf.alloc(len);
buf = hbuf;
}
memset(buf, 0, len);
if (seek_offset >= 0)
fi->seek(seek_offset, SEEK_SET);
if (seek_offset != -1)
{
if (seek_offset >= 0)
fi->seek(seek_offset, SEEK_SET);
}
len = fi->read(buf,len);
if (!ph.fillPackHeader(buf, len))

View File

@ -166,6 +166,9 @@ bool PackHeader::fillPackHeader(upx_bytep buf, unsigned len)
if (l == 0)
return false;
buf_offset = l - buf;
const int hlen = len - buf_offset;
if (hlen < 8)
return false;
version = l[4];
format = l[5];
@ -173,6 +176,10 @@ bool PackHeader::fillPackHeader(upx_bytep buf, unsigned len)
level = l[7];
filter_cto = 0;
const int hs = getPackHeaderSize();
if (hs > hlen)
throwCantUnpack("header corrupted");
// the new variable length header
int off_filter = 0;
if (format < 128)