clang-format

This commit is contained in:
Markus F.X.J. Oberhumer
2022-08-10 23:29:43 +02:00
parent 793d8c1d2e
commit 5f9c50cd3e
3 changed files with 69 additions and 100 deletions
+2 -4
View File
@@ -120,8 +120,7 @@ ElfLinker::~ElfLinker() {
free(relocations);
}
void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra)
{
void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
const upx_byte *pdata = (const upx_byte *) pdata_v;
if (plen >= 16 && memcmp(pdata, "UPX#", 4) == 0) {
// decompress pre-compressed stub-loader
@@ -318,8 +317,7 @@ ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const {
ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata, int slen,
unsigned p2align) {
// printf("addSection: %s len=%d align=%d\n", sname, slen, p2align);
if (!sdata
&& (!strcmp("ABS*", sname) || !strcmp("UND*", sname)))
if (!sdata && (!strcmp("ABS*", sname) || !strcmp("UND*", sname)))
return nullptr;
if (update_capacity(nsections, &nsections_capacity))
sections =
+24 -42
View File
@@ -37,8 +37,7 @@
**************************************************************************/
Packer::Packer(InputFile *f)
: bele(nullptr), fi(f), file_size(-1), ph_format(-1), ph_version(-1),
ibufgood(0), uip(nullptr),
: bele(nullptr), fi(f), file_size(-1), ph_format(-1), ph_version(-1), ibufgood(0), uip(nullptr),
linker(nullptr), last_patch(nullptr), last_patch_len(0), last_patch_off(0) {
file_size = 0;
if (fi != nullptr)
@@ -182,8 +181,7 @@ int forced_method(int method) // extract the forced method
**************************************************************************/
bool Packer::compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
const upx_compress_config_t *cconf_parm)
{
const upx_compress_config_t *cconf_parm) {
ph.u_len = i_len;
ph.c_len = 0;
assert(ph.level >= 1);
@@ -358,7 +356,8 @@ void ph_decompress(PackHeader &ph, const upx_bytep in, upx_bytep out, bool verif
throwCantUnpack("header corrupted");
}
unsigned new_len = ph.u_len;
int r = upx_decompress(in, ph.c_len, out, &new_len, forced_method(ph.method), &ph.compress_result);
int r =
upx_decompress(in, ph.c_len, out, &new_len, forced_method(ph.method), &ph.compress_result);
if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException();
if (r != UPX_E_OK || new_len != ph.u_len)
@@ -826,12 +825,8 @@ int Packer::patch_le32(void *b, int blen, const void *old, unsigned new_) {
// relocation util
**************************************************************************/
upx_byte *Packer::optimizeReloc(
upx_byte *in, unsigned relocnum,
upx_byte *out,
upx_byte *image, unsigned headway,
int bswap, int *big, int bits)
{
upx_byte *Packer::optimizeReloc(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image,
unsigned headway, int bswap, int *big, int bits) {
if (opt->exact)
throwCantPackExact();
@@ -866,8 +861,8 @@ upx_byte *Packer::optimizeReloc(
}
pc += oc;
if (headway <= pc) {
char msg[80]; snprintf(msg, sizeof(msg),
"bad reloc[%#x] = %#x", jc, oc);
char msg[80];
snprintf(msg, sizeof(msg), "bad reloc[%#x] = %#x", jc, oc);
throwCantPack(msg);
}
if (bswap) {
@@ -883,13 +878,13 @@ upx_byte *Packer::optimizeReloc(
return fix;
}
upx_byte *Packer::optimizeReloc32(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image, unsigned headway,
int bswap, int *big) {
upx_byte *Packer::optimizeReloc32(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image,
unsigned headway, int bswap, int *big) {
return optimizeReloc(in, relocnum, out, image, headway, bswap, big, 32);
}
upx_byte *Packer::optimizeReloc64(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image, unsigned headway,
int bswap, int *big) {
upx_byte *Packer::optimizeReloc64(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image,
unsigned headway, int bswap, int *big) {
return optimizeReloc(in, relocnum, out, image, headway, bswap, big, 64);
}
@@ -1233,18 +1228,17 @@ done:
return nfilters;
}
void Packer::compressWithFilters(
upx_bytep i_ptr, unsigned const i_len, // written and restored by filters
void Packer::compressWithFilters(upx_bytep i_ptr,
unsigned const i_len, // written and restored by filters
upx_bytep const o_ptr, // where to put compressed output
upx_bytep f_ptr, unsigned const f_len, // subset of [*i_ptr, +i_len)
upx_bytep f_ptr,
unsigned const f_len, // subset of [*i_ptr, +i_len)
upx_bytep const hdr_ptr, unsigned const hdr_len,
Filter *const parm_ft, // updated
unsigned const overlap_range,
upx_compress_config_t const *const cconf,
int filter_strategy, // in+out for prepareFilters
bool const inhibit_compression_check
)
{
bool const inhibit_compression_check) {
parm_ft->buf_len = f_len;
// struct copies
const PackHeader orig_ph = this->ph;
@@ -1437,26 +1431,18 @@ void Packer::compressWithFilters(
//
**************************************************************************/
void Packer::compressWithFilters(
Filter *ft, const unsigned overlap_range,
void Packer::compressWithFilters(Filter *ft, const unsigned overlap_range,
const upx_compress_config_t *cconf, int filter_strategy,
bool inhibit_compression_check)
{
bool inhibit_compression_check) {
compressWithFilters( // call the subroutine immediately below
ft, overlap_range,
cconf, filter_strategy,
0, 0, 0,
nullptr, 0,
inhibit_compression_check);
ft, overlap_range, cconf, filter_strategy, 0, 0, 0, nullptr, 0, inhibit_compression_check);
}
void Packer::compressWithFilters(
Filter *ft, const unsigned overlap_range,
void Packer::compressWithFilters(Filter *ft, const unsigned overlap_range,
upx_compress_config_t const *cconf, int filter_strategy,
unsigned filter_off, unsigned ibuf_off, unsigned obuf_off,
upx_bytep const hdr_ptr, unsigned hdr_len,
bool inhibit_compression_check)
{
bool inhibit_compression_check) {
ibuf.checkState();
obuf.checkState();
@@ -1469,12 +1455,8 @@ void Packer::compressWithFilters(
assert(f_ptr + f_len <= i_ptr + i_len);
compressWithFilters( // call the first one in this file
i_ptr, i_len,
o_ptr,
f_ptr, f_len,
hdr_ptr, hdr_len,
ft, overlap_range,
cconf, filter_strategy, inhibit_compression_check);
i_ptr, i_len, o_ptr, f_ptr, f_len, hdr_ptr, hdr_len, ft, overlap_range, cconf,
filter_strategy, inhibit_compression_check);
ibuf.checkState();
obuf.checkState();
+15 -26
View File
@@ -177,23 +177,17 @@ protected:
bool inhibit_compression_check = false);
void compressWithFilters(Filter *ft, const unsigned overlap_range,
const upx_compress_config_t *cconf, int filter_strategy,
unsigned filter_buf_off,
unsigned compress_ibuf_off,
unsigned compress_obuf_off,
upx_bytep const hdr_ptr, unsigned hdr_len,
unsigned filter_buf_off, unsigned compress_ibuf_off,
unsigned compress_obuf_off, upx_bytep const hdr_ptr, unsigned hdr_len,
bool inhibit_compression_check = false);
// real compression driver
void compressWithFilters(
upx_bytep i_ptr, unsigned i_len, // written and restored by filters
upx_bytep o_ptr,
upx_bytep f_ptr, unsigned f_len, // subset of [*i_ptr, +i_len)
void compressWithFilters(upx_bytep i_ptr, unsigned i_len, // written and restored by filters
upx_bytep o_ptr, upx_bytep f_ptr,
unsigned f_len, // subset of [*i_ptr, +i_len)
upx_bytep const hdr_ptr, unsigned hdr_len,
Filter *parm_ft, // updated
unsigned overlap_range,
upx_compress_config_t const *cconf,
int filter_strategy,
bool inhibit_compression_check = false
);
unsigned overlap_range, upx_compress_config_t const *cconf,
int filter_strategy, bool inhibit_compression_check = false);
// util for verifying overlapping decompresion
// non-destructive test
@@ -279,22 +273,17 @@ protected:
void checkPatch(void *b, int blen, int boff, int size);
// relocation util
static upx_byte *optimizeReloc(
upx_byte *in, unsigned relocnum,
upx_byte *out, upx_byte *image, unsigned headway,
int bs, int *big, int bits);
static unsigned unoptimizeReloc(upx_byte **in, upx_byte *image, MemBuffer *out, int bs, int bits);
static upx_byte *optimizeReloc(upx_byte *in, unsigned relocnum, upx_byte *out, upx_byte *image,
unsigned headway, int bs, int *big, int bits);
static unsigned unoptimizeReloc(upx_byte **in, upx_byte *image, MemBuffer *out, int bs,
int bits);
static upx_byte *optimizeReloc32(
upx_byte *in, unsigned relocnum,
upx_byte *out, upx_byte *image, unsigned headway,
int bs, int *big);
static upx_byte *optimizeReloc32(upx_byte *in, unsigned relocnum, upx_byte *out,
upx_byte *image, unsigned headway, int bs, int *big);
static unsigned unoptimizeReloc32(upx_byte **in, upx_byte *image, MemBuffer *out, int bs);
static upx_byte *optimizeReloc64(
upx_byte *in, unsigned relocnum,
upx_byte *out, upx_byte *image, unsigned headway,
int bs, int *big);
static upx_byte *optimizeReloc64(upx_byte *in, unsigned relocnum, upx_byte *out,
upx_byte *image, unsigned headway, int bs, int *big);
static unsigned unoptimizeReloc64(upx_byte **in, upx_byte *image, MemBuffer *out, int bs);
// target endianness abstraction