Cleanup.
committer: mfx <mfx> 1042576530 +0000
This commit is contained in:
+14
-10
@@ -136,6 +136,8 @@ int PackTos::getLoaderSize() const
|
|||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
|
// readFileHeader() reads ih and checks for illegal values
|
||||||
|
// checkFileHeader() checks ih for legal but unsupported values
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
int PackTos::readFileHeader()
|
int PackTos::readFileHeader()
|
||||||
@@ -365,14 +367,15 @@ bool PackTos::canPack()
|
|||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned char buf[512];
|
unsigned char buf[768];
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
checkAlreadyPacked(buf, sizeof(buf));
|
checkAlreadyPacked(buf, sizeof(buf));
|
||||||
|
|
||||||
if (!checkFileHeader())
|
if (!checkFileHeader())
|
||||||
throwCantPack("unsupported header flags");
|
throwCantPack("unsupported header flags");
|
||||||
if (file_size < 256)
|
if (file_size < 1024)
|
||||||
throwCantPack("program too small");
|
throwCantPack("program is too small");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,8 +477,8 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
// After compression this will become the first part of the
|
// After compression this will become the first part of the
|
||||||
// data segement. The second part will be the decompressor.
|
// data segement. The second part will be the decompressor.
|
||||||
|
|
||||||
// alloc buffer
|
// alloc buffer (512 is for the various alignments)
|
||||||
obuf.allocForCompression(t + d_len + 512);
|
obuf.allocForCompression(t, d_len + 512);
|
||||||
|
|
||||||
// prepare packheader
|
// prepare packheader
|
||||||
ph.u_len = t;
|
ph.u_len = t;
|
||||||
@@ -536,12 +539,12 @@ void PackTos::pack(OutputFile *fo)
|
|||||||
|
|
||||||
// prepare loader
|
// prepare loader
|
||||||
MemBuffer loader(o_text);
|
MemBuffer loader(o_text);
|
||||||
memcpy(loader,getLoader(),o_text);
|
memcpy(loader, getLoader(), o_text);
|
||||||
|
|
||||||
// patch loader
|
// patch loader
|
||||||
patchPackHeader(loader,o_text);
|
patchPackHeader(loader, o_text);
|
||||||
if (!opt->small)
|
if (!opt->small)
|
||||||
patchVersion(loader,o_text);
|
patchVersion(loader, o_text);
|
||||||
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
||||||
const unsigned dirty_bss_d6 =
|
const unsigned dirty_bss_d6 =
|
||||||
patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4");
|
patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4");
|
||||||
@@ -635,6 +638,7 @@ int PackTos::canUnpack()
|
|||||||
if ((ih.fh_text & 3) != 0 || (ih.fh_data & 3) != 0 || (ih.fh_bss & 3) != 0
|
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)
|
|| ih.fh_sym != 0 || ih.fh_reserved != 0 || ih.fh_reloc > 1)
|
||||||
throwCantUnpack("program header damaged");
|
throwCantUnpack("program header damaged");
|
||||||
|
// generic check
|
||||||
if (!checkFileHeader())
|
if (!checkFileHeader())
|
||||||
throwCantUnpack("unsupported header flags");
|
throwCantUnpack("unsupported header flags");
|
||||||
return true;
|
return true;
|
||||||
@@ -650,8 +654,8 @@ void PackTos::unpack(OutputFile *fo)
|
|||||||
ibuf.alloc(ph.c_len);
|
ibuf.alloc(ph.c_len);
|
||||||
obuf.allocForUncompression(ph.u_len);
|
obuf.allocForUncompression(ph.u_len);
|
||||||
|
|
||||||
fi->seek(ph.buf_offset + ph.getPackHeaderSize(),SEEK_SET);
|
fi->seek(ph.buf_offset + ph.getPackHeaderSize(), SEEK_SET);
|
||||||
fi->readx(ibuf,ph.c_len);
|
fi->readx(ibuf, ph.c_len);
|
||||||
|
|
||||||
// decompress
|
// decompress
|
||||||
decompress(ibuf,obuf);
|
decompress(ibuf,obuf);
|
||||||
|
|||||||
Reference in New Issue
Block a user