Cleanups.

committer: mfx <mfx> 981586521 +0000
This commit is contained in:
Markus F.X.J. Oberhumer
2001-02-07 22:55:21 +00:00
parent 7db6c25c6a
commit 238a369948
3 changed files with 14 additions and 12 deletions
-1
View File
@@ -111,7 +111,6 @@ void show_help(int x)
con_fprintf(f, con_fprintf(f,
" -q be quiet -v be verbose\n" " -q be quiet -v be verbose\n"
//" -oFILE write output to `FILE' -c write output to stdout\n"
" -oFILE write output to `FILE'\n" " -oFILE write output to `FILE'\n"
//" -f force overwrite of output files and compression of suspicious files\n" //" -f force overwrite of output files and compression of suspicious files\n"
" -f force compression of suspicious files\n" " -f force compression of suspicious files\n"
+14 -10
View File
@@ -573,14 +573,12 @@ void PackExe::unpack(OutputFile *fo)
obuf.allocForUncompression(ph.u_len); obuf.allocForUncompression(ph.u_len);
// read the file // read the file
unsigned imagesize = ih_imagesize;
fi->seek(ih.headsize16*16,SEEK_SET); fi->seek(ih.headsize16*16,SEEK_SET);
fi->readx(ibuf,imagesize); fi->readx(ibuf,ih_imagesize);
// get compressed data offset // get compressed data offset
unsigned e_len = ph.buf_offset + ph.getPackHeaderSize(); unsigned e_len = ph.buf_offset + ph.getPackHeaderSize();
if (imagesize <= e_len + ph.c_len) if (ih_imagesize <= e_len + ph.c_len)
throwCantUnpack("file damaged"); throwCantUnpack("file damaged");
checkOverlay(ih_overlay); checkOverlay(ih_overlay);
@@ -588,7 +586,9 @@ void PackExe::unpack(OutputFile *fo)
// decompress // decompress
decompress(ibuf+e_len,obuf); decompress(ibuf+e_len,obuf);
const unsigned char flag = ibuf[imagesize-1]; unsigned imagesize = ih_imagesize;
imagesize--;
const unsigned char flag = ibuf[imagesize];
unsigned relocn = 0; unsigned relocn = 0;
upx_byte *relocs = obuf + ph.u_len; upx_byte *relocs = obuf + ph.u_len;
@@ -638,20 +638,23 @@ void PackExe::unpack(OutputFile *fo)
} }
} }
} }
// fill new exe header // fill new exe header
memset(&oh,0,sizeof(oh)); memset(&oh,0,sizeof(oh));
oh.ident = 'M' + 'Z'*256; oh.ident = 'M' + 'Z'*256;
oh.relocs = relocn; if (relocn)
while (relocn&3) {
set_le32(wrkmem+4*relocn++,0); oh.relocs = relocn;
while (relocn & 3)
set_le32(wrkmem+4*relocn++,0);
}
unsigned outputlen = sizeof(oh)+relocn*4+relocs-obuf; unsigned outputlen = sizeof(oh)+relocn*4+relocs-obuf;
oh.m512 = outputlen & 511; oh.m512 = outputlen & 511;
oh.p512 = (outputlen + 511) >> 9; oh.p512 = (outputlen + 511) >> 9;
oh.headsize16 = 2+relocn/4; oh.headsize16 = 2+relocn/4;
imagesize--;
oh.max = ih.max; oh.max = ih.max;
oh.min = ih.min; oh.min = ih.min;
oh.sp = ih.sp; oh.sp = ih.sp;
@@ -677,7 +680,8 @@ void PackExe::unpack(OutputFile *fo)
// write header + relocations + uncompressed file // write header + relocations + uncompressed file
fo->write(&oh,sizeof(oh)); fo->write(&oh,sizeof(oh));
fo->write(wrkmem,relocn*4); if (relocn)
fo->write(wrkmem,relocn*4);
fo->write(obuf,relocs-obuf); fo->write(obuf,relocs-obuf);
// copy the overlay // copy the overlay
-1
View File
@@ -151,7 +151,6 @@ void PackHeader::putPackHeader(upx_bytep p)
p[28] = (unsigned char) filter; p[28] = (unsigned char) filter;
p[29] = (unsigned char) filter_cto; p[29] = (unsigned char) filter_cto;
p[30] = (unsigned char) (n_mru ? 0 : n_mru -1); p[30] = (unsigned char) (n_mru ? 0 : n_mru -1);
size = 32;
} }
set_le32(p+8,u_adler); set_le32(p+8,u_adler);
set_le32(p+12,c_adler); set_le32(p+12,c_adler);