Added a framework for the elks/8086 format. Completely non-functional at the moment.
committer: mfx <mfx> 978092698 +0000
This commit is contained in:
+1
-1
@@ -61,7 +61,7 @@ OBJECTS1 = \
|
|||||||
compress$o except$o file$o lefile$o \
|
compress$o except$o file$o lefile$o \
|
||||||
filter$o mem$o msg$o stdcxx$o work$o ui$o \
|
filter$o mem$o msg$o stdcxx$o work$o ui$o \
|
||||||
packer$o packhead$o packmast$o \
|
packer$o packhead$o packmast$o \
|
||||||
p_com$o p_djgpp2$o p_exe$o \
|
p_com$o p_djgpp2$o p_elks$o p_exe$o \
|
||||||
p_lx_elf$o p_lx_exc$o p_lx_sep$o p_lx_sh$o \
|
p_lx_elf$o p_lx_exc$o p_lx_sep$o p_lx_sh$o \
|
||||||
p_sys$o p_tmt$o p_tos$o \
|
p_sys$o p_tmt$o p_tos$o \
|
||||||
p_unix$o p_vmlinz$o p_w32pe$o p_wcle$o
|
p_unix$o p_vmlinz$o p_w32pe$o p_wcle$o
|
||||||
|
|||||||
+193
@@ -0,0 +1,193 @@
|
|||||||
|
/* p_elks.cpp --
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1996-2000 Laszlo Molnar
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||||
|
markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
#include "file.h"
|
||||||
|
#include "filter.h"
|
||||||
|
#include "packer.h"
|
||||||
|
#include "p_vmlinz.h"
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
static const
|
||||||
|
#include "stub/l_vmlinz.h"
|
||||||
|
|
||||||
|
// from elks-0.0.83/Documentation/boot.txt
|
||||||
|
static const unsigned kernel_entry = 0x100000;
|
||||||
|
static const unsigned stack_during_uncompression = 0x90000;
|
||||||
|
static const unsigned zimage_offset = 0x1000;
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int PackElks8086::getCompressionMethod() const
|
||||||
|
{
|
||||||
|
if (M_IS_NRV2B(opt->method))
|
||||||
|
return M_NRV2B_8;
|
||||||
|
if (M_IS_NRV2D(opt->method))
|
||||||
|
return M_NRV2D_8;
|
||||||
|
return opt->level > 1 ? M_NRV2D_8 : M_NRV2B_8;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const int *PackElks8086::getFilters() const
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// common util routines
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int PackElks8086::uncompressKernel()
|
||||||
|
{
|
||||||
|
// not used
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PackElks8086::readKernel()
|
||||||
|
{
|
||||||
|
int klen = file_size - setup_size;
|
||||||
|
fi->seek(0, SEEK_SET);
|
||||||
|
|
||||||
|
setup_buf.alloc(setup_size);
|
||||||
|
fi->readx(setup_buf, setup_size);
|
||||||
|
|
||||||
|
ibuf.alloc(klen);
|
||||||
|
fi->readx(ibuf, klen);
|
||||||
|
|
||||||
|
obuf.allocForCompression(klen);
|
||||||
|
|
||||||
|
ph.u_len = klen;
|
||||||
|
ph.filter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int PackElks8086::buildLoader(const Filter *ft)
|
||||||
|
{
|
||||||
|
// prepare loader
|
||||||
|
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||||
|
// FIXME
|
||||||
|
UNUSED(ft);
|
||||||
|
return getLoaderSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PackElks8086::pack(OutputFile *fo)
|
||||||
|
{
|
||||||
|
readKernel();
|
||||||
|
|
||||||
|
// prepare filter
|
||||||
|
Filter ft(opt->level);
|
||||||
|
ft.buf_len = ph.u_len;
|
||||||
|
ft.addvalue = kernel_entry;
|
||||||
|
// prepare other settings
|
||||||
|
const unsigned overlap_range = 1 << 20;
|
||||||
|
unsigned overlapoh;
|
||||||
|
|
||||||
|
int strategy = -1; // try the first working filter
|
||||||
|
if (opt->filter >= 0 && isValidFilter(opt->filter))
|
||||||
|
// try opt->filter or 0 if that fails
|
||||||
|
strategy = -2;
|
||||||
|
else if (opt->all_filters)
|
||||||
|
// choose best from all available filters
|
||||||
|
strategy = 0;
|
||||||
|
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
|
||||||
|
|
||||||
|
const unsigned lsize = getLoaderSize();
|
||||||
|
MemBuffer loader(lsize);
|
||||||
|
memcpy(loader, getLoader(), lsize);
|
||||||
|
|
||||||
|
patchPackHeader(loader, lsize);
|
||||||
|
#if 0
|
||||||
|
// FIXME
|
||||||
|
patchFilter32(loader, lsize, &ft);
|
||||||
|
patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
|
||||||
|
patch_le32(loader, lsize, "KEIP", kernel_entry);
|
||||||
|
patch_le32(loader, lsize, "STAK", stack_during_uncompression);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||||
|
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16) / 16;
|
||||||
|
|
||||||
|
fo->write(setup_buf, setup_buf.getSize());
|
||||||
|
fo->write(loader, lsize);
|
||||||
|
fo->write(obuf, ph.c_len);
|
||||||
|
#if 0
|
||||||
|
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
|
||||||
|
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
|
||||||
|
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// finally check the compression ratio
|
||||||
|
if (!checkFinalCompressionRatio(fo))
|
||||||
|
throwNotCompressible();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// unpack
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
int PackElks8086::canUnpack()
|
||||||
|
{
|
||||||
|
if (readFileHeader() != getFormat())
|
||||||
|
return false;
|
||||||
|
fi->seek(setup_size, SEEK_SET);
|
||||||
|
return readPackHeader(1024) ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PackElks8086::unpack(OutputFile *)
|
||||||
|
{
|
||||||
|
// no uncompression support for this format yet
|
||||||
|
|
||||||
|
// FIXME: but we could write the uncompressed "Image" image
|
||||||
|
|
||||||
|
throwCantUnpack("build a new kernel instead :-)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* if 0 */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
vi:ts=4:et
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -105,6 +105,33 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// elks/8086 (linux-8086 uncompressed kernel image)
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
class PackElks8086 : public PackVmlinuzI386
|
||||||
|
{
|
||||||
|
typedef PackVmlinuzI386 super;
|
||||||
|
public:
|
||||||
|
PackElks8086(InputFile *f) : super(f) { }
|
||||||
|
virtual int getFormat() const { return UPX_F_ELKS_8086; }
|
||||||
|
virtual const char *getName() const { return "elks/8086"; }
|
||||||
|
virtual int getCompressionMethod() const;
|
||||||
|
virtual const int *getFilters() const;
|
||||||
|
|
||||||
|
virtual void pack(OutputFile *fo);
|
||||||
|
virtual void unpack(OutputFile *fo);
|
||||||
|
|
||||||
|
virtual int canUnpack();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual int uncompressKernel();
|
||||||
|
virtual void readKernel();
|
||||||
|
|
||||||
|
virtual int buildLoader(const Filter *ft);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -177,10 +177,14 @@ static Packer* try_packers(InputFile *f, try_function func)
|
|||||||
//
|
//
|
||||||
// linux kernel
|
// linux kernel
|
||||||
//
|
//
|
||||||
if ((p = func(new PackBvmlinuzI386(f),f)) != NULL)
|
|
||||||
return p;
|
|
||||||
if ((p = func(new PackVmlinuzI386(f),f)) != NULL)
|
if ((p = func(new PackVmlinuzI386(f),f)) != NULL)
|
||||||
return p;
|
return p;
|
||||||
|
if ((p = func(new PackBvmlinuzI386(f),f)) != NULL)
|
||||||
|
return p;
|
||||||
|
#if 0
|
||||||
|
if ((p = func(new PackElks8086(f),f)) != NULL)
|
||||||
|
return p;
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// linux
|
// linux
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ typedef unsigned upx_uint32;
|
|||||||
#define UPX_F_LINUX_SH_i386 14
|
#define UPX_F_LINUX_SH_i386 14
|
||||||
#define UPX_F_VMLINUZ_i386 15
|
#define UPX_F_VMLINUZ_i386 15
|
||||||
#define UPX_F_BVMLINUZ_i386 16
|
#define UPX_F_BVMLINUZ_i386 16
|
||||||
|
#define UPX_F_ELKS_8086 17
|
||||||
#define UPX_F_ATARI_TOS 129
|
#define UPX_F_ATARI_TOS 129
|
||||||
#define UPX_F_SOLARIS_SPARC 130
|
#define UPX_F_SOLARIS_SPARC 130
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user