1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

PackVmlinuxBase try template definitions in .cpp file

This commit is contained in:
John Reiser 2006-12-18 20:17:10 -08:00
parent dbed6a47bb
commit 277d862172
2 changed files with 40 additions and 35 deletions

View File

@ -58,6 +58,44 @@ PackVmlinuxBase<T>::~PackVmlinuxBase()
delete [] shdri;
}
template <class T>
int PackVmlinuxBase<T>::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));
};
template <class T>
class T::Shdr const *PackVmlinuxBase<T>::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;
};
/*************************************************************************
//
**************************************************************************/

View File

@ -65,41 +65,8 @@ protected:
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));
};
virtual Shdr const *getElfSections();
virtual int getStrategy(Filter &/*ft*/);
};