1
0
mirror of https://github.com/upx/upx.git synced 2025-08-11 22:52:30 +08:00

PackVmlinuxBase use simple templates

This commit is contained in:
John Reiser
2006-12-18 20:08:24 -08:00
parent 94f3749784
commit dbed6a47bb
2 changed files with 37 additions and 127 deletions

View File

@ -58,7 +58,6 @@ PackVmlinuxBase<T>::~PackVmlinuxBase()
delete [] shdri;
}
/*************************************************************************
//
**************************************************************************/
@ -77,45 +76,6 @@ const int *PackVmlinuxI386::getFilters() const
return filters;
}
// copied from PackUnix 2006-10-13.
int PackVmlinuxI386::getStrategy(Filter &/*ft*/)
{
// Called just before reading and compressing each block.
// Might want to adjust blocksize, etc.
// If user specified the filter, then use it (-2==filter_strategy).
// Else try the first two filters, and pick the better (2==filter_strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}
Elf_LE32_Shdr const *
PackVmlinuxI386::getElfSections()
{
Elf_LE32_Shdr const *p, *shstrsec=0;
shdri = new Elf_LE32_Shdr[(unsigned) ehdri.e_shnum];
fi->seek(ehdri.e_shoff, SEEK_SET);
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Elf32_Shdr::SHT_STRTAB==p->sh_type
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
) {
delete [] shstrtab;
shstrtab = new char[1+ p->sh_size];
fi->seek(p->sh_offset, SEEK_SET);
fi->readx(shstrtab, p->sh_size);
shstrtab[p->sh_size] = '\0';
if (0==strcmp(".shstrtab", shstrtab + p->sh_name)) {
shstrsec = p;
break;
}
}
}
return shstrsec;
}
const int *PackVmlinuxARM::getCompressionMethods(int method, int level) const
{
return Packer::getDefaultCompressionMethods_8(method, level);
@ -128,45 +88,6 @@ const int *PackVmlinuxARM::getFilters() const
return f50;
}
// copied from PackUnix 2006-10-13.
int PackVmlinuxARM::getStrategy(Filter &/*ft*/)
{
// Called just before reading and compressing each block.
// Might want to adjust blocksize, etc.
// If user specified the filter, then use it (-2==filter_strategy).
// Else try the first two filters, and pick the better (2==filter_strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}
Elf_LE32_Shdr const *
PackVmlinuxARM::getElfSections()
{
Elf_LE32_Shdr const *p, *shstrsec=0;
shdri = new Elf_LE32_Shdr[(unsigned) ehdri.e_shnum];
fi->seek(ehdri.e_shoff, SEEK_SET);
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Elf32_Shdr::SHT_STRTAB==p->sh_type
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
) {
delete [] shstrtab;
shstrtab = new char[1+ p->sh_size];
fi->seek(p->sh_offset, SEEK_SET);
fi->readx(shstrtab, p->sh_size);
shstrtab[p->sh_size] = '\0';
if (0==strcmp(".shstrtab", shstrtab + p->sh_name)) {
shstrsec = p;
break;
}
}
}
return shstrsec;
}
static int __acc_cdecl_qsort
compare_Phdr(void const *aa, void const *bb)
{
@ -1256,45 +1177,6 @@ const int *PackVmlinuxAMD64::getFilters() const
return filters;
}
// copied from PackUnix 2006-10-13.
int PackVmlinuxAMD64::getStrategy(Filter &/*ft*/)
{
// Called just before reading and compressing each block.
// Might want to adjust blocksize, etc.
// If user specified the filter, then use it (-2==strategy).
// Else try the first two filters, and pick the better (2==strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
}
Elf_LE64_Shdr const *
PackVmlinuxAMD64::getElfSections()
{
Elf_LE64_Shdr const *p, *shstrsec=0;
shdri = new Elf_LE64_Shdr[(unsigned) ehdri.e_shnum];
fi->seek(ehdri.e_shoff, SEEK_SET);
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Elf64_Shdr::SHT_STRTAB==p->sh_type
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
) {
delete [] shstrtab;
shstrtab = new char[1+ p->sh_size];
fi->seek(p->sh_offset, SEEK_SET);
fi->readx(shstrtab, p->sh_size);
shstrtab[p->sh_size] = '\0';
if (0==strcmp(".shstrtab", shstrtab + p->sh_name)) {
shstrsec = p;
break;
}
}
}
return shstrsec;
}
static int __acc_cdecl_qsort
compare_Phdr64(void const *aa, void const *bb)
{

View File

@ -52,6 +52,7 @@ public:
bele = N_BELE_CTP::getRTP<typename TElfClass::BeLePolicy>();
}
virtual ~PackVmlinuxBase();
virtual int getVersion() const { return 13; }
protected:
int n_ptload;
@ -63,6 +64,42 @@ protected:
Shdr *p_note0;
Shdr *p_note1;
Ehdr ehdri; // from input file
virtual Shdr const *getElfSections() {
Shdr const *p, *shstrsec=0;
shdri = new Shdr[(unsigned) ehdri.e_shnum];
fi->seek(ehdri.e_shoff, SEEK_SET);
fi->readx(shdri, ehdri.e_shnum * sizeof(*shdri));
int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Shdr::SHT_STRTAB==p->sh_type
&& (p->sh_size + p->sh_offset) <= (unsigned) file_size
&& (10+ p->sh_name) <= p->sh_size // 1+ strlen(".shstrtab")
) {
delete [] shstrtab;
shstrtab = new char[1+ p->sh_size];
fi->seek(p->sh_offset, SEEK_SET);
fi->readx(shstrtab, p->sh_size);
shstrtab[p->sh_size] = '\0';
if (0==strcmp(".shstrtab", shstrtab + p->sh_name)) {
shstrsec = p;
break;
}
}
}
return shstrsec;
};
// copied from PackUnix 2006-10-13.
virtual int getStrategy(Filter &/*ft*/) {
// Called just before reading and compressing each block.
// Might want to adjust blocksize, etc.
// If user specified the filter, then use it (-2==strategy).
// Else try the first two filters, and pick the better (2==strategy).
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
};
};
@ -71,13 +108,11 @@ class PackVmlinuxI386 : public PackVmlinuxBase<ElfClass_LE32>
typedef PackVmlinuxBase<ElfClass_LE32> super;
public:
PackVmlinuxI386(InputFile *f) : super(f) { }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUX_i386; }
virtual const char *getName() const { return "vmlinux/386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
@ -86,7 +121,6 @@ public:
virtual int canUnpack();
protected:
virtual Elf_LE32_Shdr const *getElfSections();
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
};
@ -97,13 +131,11 @@ class PackVmlinuxARM : public PackVmlinuxBase<ElfClass_LE32>
typedef PackVmlinuxBase<ElfClass_LE32> super;
public:
PackVmlinuxARM(InputFile *f) : super(f) { }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUX_ARM; }
virtual const char *getName() const { return "vmlinux/ARM"; }
virtual const char *getFullName(const options_t *) const { return "ARM-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
@ -112,7 +144,6 @@ public:
virtual int canUnpack();
protected:
virtual Elf_LE32_Shdr const *getElfSections();
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
};
@ -123,13 +154,11 @@ class PackVmlinuxAMD64 : public PackVmlinuxBase<ElfClass_LE64>
typedef PackVmlinuxBase<ElfClass_LE64> super;
public:
PackVmlinuxAMD64(InputFile *f) : super(f) { }
virtual int getVersion() const { return 13; }
virtual int getFormat() const { return UPX_F_VMLINUX_AMD64; }
virtual const char *getName() const { return "vmlinux/AMD64"; }
virtual const char *getFullName(const options_t *) const { return "amd64-linux.kernel.vmlinux"; }
virtual const int *getCompressionMethods(int method, int level) const;
virtual const int *getFilters() const;
virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo);
virtual void unpack(OutputFile *fo);
@ -138,7 +167,6 @@ public:
virtual int canUnpack();
protected:
virtual Elf_LE64_Shdr const *getElfSections();
virtual void buildLoader(const Filter *ft);
virtual Linker* newLinker() const;
};