mirror of
https://github.com/upx/upx
synced 2025-10-05 19:20:23 +08:00
Use MemBuffer.clear().
committer: mfx <mfx> 1043693892 +0000
This commit is contained in:
parent
51c28020de
commit
ac4b8f8617
|
@ -387,16 +387,18 @@ void PackDjgpp2::unpack(OutputFile *fo)
|
||||||
// decompress
|
// decompress
|
||||||
decompress(ibuf, obuf);
|
decompress(ibuf, obuf);
|
||||||
|
|
||||||
coff_header_t *chdr = (coff_header_t*) (unsigned char *) obuf;
|
coff_header_t *chdr = (coff_header_t*) obuf.getVoidPtr();
|
||||||
text = chdr->sh;
|
text = chdr->sh;
|
||||||
data = text + 1;
|
data = text + 1;
|
||||||
|
|
||||||
const unsigned hdrsize = 20 + 28
|
const unsigned hdrsize = 20 + 28
|
||||||
+ sizeof(external_scnhdr_t) * chdr->f_nscns;
|
+ sizeof(external_scnhdr_t) * chdr->f_nscns;
|
||||||
|
|
||||||
unsigned addvalue = text->vaddr &~ 0x1ff; // for old versions
|
unsigned addvalue;
|
||||||
if (ph.version >= 14)
|
if (ph.version >= 14)
|
||||||
addvalue = text->vaddr - hdrsize;
|
addvalue = text->vaddr - hdrsize;
|
||||||
|
else
|
||||||
|
addvalue = text->vaddr &~ 0x1ff; // for old versions
|
||||||
|
|
||||||
// unfilter
|
// unfilter
|
||||||
if (ph.filter)
|
if (ph.filter)
|
||||||
|
@ -422,18 +424,21 @@ void PackDjgpp2::unpack(OutputFile *fo)
|
||||||
if (fo)
|
if (fo)
|
||||||
fo->write(obuf, ph.u_len);
|
fo->write(obuf, ph.u_len);
|
||||||
}
|
}
|
||||||
else if (fo)
|
else
|
||||||
{
|
{
|
||||||
// write the header
|
// write the header
|
||||||
// some padding might be required between the end
|
// some padding might be required between the end
|
||||||
// of the header and the start of the .text section
|
// of the header and the start of the .text section
|
||||||
|
|
||||||
const unsigned padding = text->scnptr - hdrsize;
|
const unsigned padding = text->scnptr - hdrsize;
|
||||||
memset(ibuf, 0, padding);
|
ibuf.clear(0, padding);
|
||||||
|
|
||||||
fo->write(obuf, hdrsize);
|
if (fo)
|
||||||
fo->write(ibuf, padding);
|
{
|
||||||
fo->write(obuf + hdrsize, ph.u_len - hdrsize);
|
fo->write(obuf, hdrsize);
|
||||||
|
fo->write(ibuf, padding);
|
||||||
|
fo->write(obuf + hdrsize, ph.u_len - hdrsize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fo)
|
if (fo)
|
||||||
|
|
|
@ -301,7 +301,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||||
|
|
||||||
// prepare paddata
|
// prepare paddata
|
||||||
MemBuffer paddata(PS_HDR_SIZE);
|
MemBuffer paddata(PS_HDR_SIZE);
|
||||||
memset(paddata, 0, paddata.getSize());
|
paddata.clear();
|
||||||
|
|
||||||
// write loader + compressed file
|
// write loader + compressed file
|
||||||
fo->write(&oh, sizeof(oh));
|
fo->write(&oh, sizeof(oh));
|
||||||
|
@ -392,10 +392,10 @@ void PackPs1::unpack(OutputFile *fo)
|
||||||
// write header
|
// write header
|
||||||
fo->write(&oh, sizeof(oh));
|
fo->write(&oh, sizeof(oh));
|
||||||
// align the ps exe header (mode 2 sector data size)
|
// align the ps exe header (mode 2 sector data size)
|
||||||
memset(ibuf, 0, PS_HDR_SIZE - sizeof(oh));
|
ibuf.clear(0, PS_HDR_SIZE - sizeof(oh));
|
||||||
fo->write(ibuf, PS_HDR_SIZE - sizeof(oh));
|
fo->write(ibuf, PS_HDR_SIZE - sizeof(oh));
|
||||||
// write uncompressed data + pad
|
// write uncompressed data + pad
|
||||||
memset(obuf + ph.u_len, 0, pad);
|
obuf.clear(ph.u_len, pad);
|
||||||
fo->write(obuf, ph.u_len + pad);
|
fo->write(obuf, ph.u_len + pad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@ void PackW32Pe::processRelocs() // pass1
|
||||||
if ((opt->w32pe.strip_relocs && !isdll) || rnum == 0)
|
if ((opt->w32pe.strip_relocs && !isdll) || rnum == 0)
|
||||||
{
|
{
|
||||||
if (IDSIZE(PEDIR_RELOC))
|
if (IDSIZE(PEDIR_RELOC))
|
||||||
memset(ibuf + IDADDR(PEDIR_RELOC),FILLVAL,IDSIZE(PEDIR_RELOC));
|
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||||
orelocs = new upx_byte [1];
|
orelocs = new upx_byte [1];
|
||||||
sorelocs = 0;
|
sorelocs = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -432,7 +432,7 @@ void PackW32Pe::processRelocs() // pass1
|
||||||
}
|
}
|
||||||
fix[3] -= counts[3];
|
fix[3] -= counts[3];
|
||||||
|
|
||||||
memset(ibuf + IDADDR(PEDIR_RELOC),FILLVAL,IDSIZE(PEDIR_RELOC));
|
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||||
orelocs = new upx_byte [rnum * 4 + 1024]; // 1024 - safety
|
orelocs = new upx_byte [rnum * 4 + 1024]; // 1024 - safety
|
||||||
sorelocs = ptr_diff(optimizeReloc32((upx_byte*) fix[3],counts[3],orelocs,ibuf + rvamin,1,&big_relocs),orelocs);
|
sorelocs = ptr_diff(optimizeReloc32((upx_byte*) fix[3],counts[3],orelocs,ibuf + rvamin,1,&big_relocs),orelocs);
|
||||||
|
|
||||||
|
@ -1390,8 +1390,8 @@ void PackW32Pe::processResources(Resource *res)
|
||||||
|
|
||||||
set_le32(ores,res->offs()); // save original offset
|
set_le32(ores,res->offs()); // save original offset
|
||||||
ores += 4;
|
ores += 4;
|
||||||
memcpy(ores,ibuf + res->offs(),res->size());
|
memcpy(ores, ibuf + res->offs(), res->size());
|
||||||
memset(ibuf + res->offs(),FILLVAL,res->size());
|
ibuf.fill(res->offs(), res->size(), FILLVAL);
|
||||||
res->newoffs() = ptr_diff(ores,oresources);
|
res->newoffs() = ptr_diff(ores,oresources);
|
||||||
if (rtype == RT_ICON)
|
if (rtype == RT_ICON)
|
||||||
compress_icon = (++iconcnt >= iconsin1stdir || opt->w32pe.compress_icons == 1);
|
compress_icon = (++iconcnt >= iconsin1stdir || opt->w32pe.compress_icons == 1);
|
||||||
|
@ -1465,7 +1465,7 @@ unsigned PackW32Pe::stripDebug(unsigned overlaystart)
|
||||||
for (unsigned ic = 0; ic < IDSIZE(PEDIR_DEBUG) / sizeof(debug_dir_t); ic++, dd++)
|
for (unsigned ic = 0; ic < IDSIZE(PEDIR_DEBUG) / sizeof(debug_dir_t); ic++, dd++)
|
||||||
if (overlaystart == dd->fpos)
|
if (overlaystart == dd->fpos)
|
||||||
overlaystart += dd->size;
|
overlaystart += dd->size;
|
||||||
memset(ibuf + IDADDR(PEDIR_DEBUG),FILLVAL,IDSIZE(PEDIR_DEBUG));
|
ibuf.fill(IDADDR(PEDIR_DEBUG), IDSIZE(PEDIR_DEBUG), FILLVAL);
|
||||||
return overlaystart;
|
return overlaystart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1601,7 +1601,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||||
Interval holes(ibuf);
|
Interval holes(ibuf);
|
||||||
|
|
||||||
unsigned ic,jc,overlaystart = 0;
|
unsigned ic,jc,overlaystart = 0;
|
||||||
memset(ibuf,0,usize);
|
ibuf.clear(0, usize);
|
||||||
for (ic = jc = 0; ic < objs; ic++)
|
for (ic = jc = 0; ic < objs; ic++)
|
||||||
{
|
{
|
||||||
if (isection[ic].rawdataptr && overlaystart < isection[ic].rawdataptr + isection[ic].size)
|
if (isection[ic].rawdataptr && overlaystart < isection[ic].rawdataptr + isection[ic].size)
|
||||||
|
@ -1762,7 +1762,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||||
ic = identsize - identsplit;
|
ic = identsize - identsplit;
|
||||||
|
|
||||||
const unsigned clen = ((ph.c_len + ic) & 15) == 0 ? ph.c_len : ph.c_len + 16 - ((ph.c_len + ic) & 15);
|
const unsigned clen = ((ph.c_len + ic) & 15) == 0 ? ph.c_len : ph.c_len + 16 - ((ph.c_len + ic) & 15);
|
||||||
memset(obuf + ph.c_len, 0, clen - ph.c_len);
|
obuf.clear(ph.c_len, clen - ph.c_len);
|
||||||
|
|
||||||
const unsigned s1size = ALIGN_UP(ic + clen + codesize,4) + sotls;
|
const unsigned s1size = ALIGN_UP(ic + clen + codesize,4) + sotls;
|
||||||
const unsigned s1addr = (newvsize - (ic + clen) + oam1) &~ oam1;
|
const unsigned s1addr = (newvsize - (ic + clen) + oam1) &~ oam1;
|
||||||
|
@ -1932,8 +1932,7 @@ void PackW32Pe::pack(OutputFile *fo)
|
||||||
|
|
||||||
//for (ic = 0; ic < oh.filealign; ic += 4)
|
//for (ic = 0; ic < oh.filealign; ic += 4)
|
||||||
// set_le32(ibuf + ic,get_le32("UPX "));
|
// set_le32(ibuf + ic,get_le32("UPX "));
|
||||||
assert(oh.filealign <= ibuf.getSize());
|
ibuf.clear(0, oh.filealign);
|
||||||
memset(ibuf,0,oh.filealign);
|
|
||||||
|
|
||||||
infoHeader("[Writing compressed file]");
|
infoHeader("[Writing compressed file]");
|
||||||
|
|
||||||
|
@ -2197,7 +2196,7 @@ void PackW32Pe::rebuildRelocs(upx_byte *& extrainfo)
|
||||||
|
|
||||||
if (opt->w32pe.strip_relocs && !isdll)
|
if (opt->w32pe.strip_relocs && !isdll)
|
||||||
{
|
{
|
||||||
memset(obuf + ODADDR(PEDIR_RELOC) - rvamin,0,ODSIZE(PEDIR_RELOC));
|
obuf.clear(ODADDR(PEDIR_RELOC) - rvamin, ODSIZE(PEDIR_RELOC));
|
||||||
ODADDR(PEDIR_RELOC) = 0;
|
ODADDR(PEDIR_RELOC) = 0;
|
||||||
soxrelocs = 0;
|
soxrelocs = 0;
|
||||||
// FIXME: try to remove the original relocation section somehow
|
// FIXME: try to remove the original relocation section somehow
|
||||||
|
@ -2336,7 +2335,7 @@ void PackW32Pe::unpack(OutputFile *fo)
|
||||||
{
|
{
|
||||||
ibuf.dealloc();
|
ibuf.dealloc();
|
||||||
ibuf.alloc(osection[0].rawdataptr);
|
ibuf.alloc(osection[0].rawdataptr);
|
||||||
memset(ibuf,0,osection[0].rawdataptr);
|
ibuf.clear();
|
||||||
infoHeader("[Writing uncompressed file]");
|
infoHeader("[Writing uncompressed file]");
|
||||||
|
|
||||||
// write loader + compressed file
|
// write loader + compressed file
|
||||||
|
|
Loading…
Reference in New Issue
Block a user