clang-format files.

This commit is contained in:
Markus F.X.J. Oberhumer
2017-04-05 17:13:29 +02:00
parent 18a8e1b6d6
commit 17a83d58da
3 changed files with 41 additions and 71 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ endif
# automatically format some C++ source code files # automatically format some C++ source code files
ifeq ($(shell uname),Linux) ifeq ($(shell uname),Linux)
CLANG_FORMAT_FILES += linker.cpp linker.h packhead.cpp CLANG_FORMAT_FILES += linker.cpp linker.h packhead.cpp packmast.cpp
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
CLANG_FORMAT_FILES += snprintf.cpp CLANG_FORMAT_FILES += snprintf.cpp
CLANG_FORMAT_FILES += stdcxx.cpp stdcxx.h CLANG_FORMAT_FILES += stdcxx.cpp stdcxx.h
+5 -6
View File
@@ -474,7 +474,8 @@ void ElfLinker::relocate() {
upx_byte *location = rel->section->output + rel->offset; upx_byte *location = rel->section->output + rel->offset;
// printf("%-28s %-28s %-10s %#16llx %#16llx\n", rel->section->name, rel->value->name, // printf("%-28s %-28s %-10s %#16llx %#16llx\n", rel->section->name, rel->value->name,
// rel->type, (long long) value, (long long) value - rel->section->offset - rel->offset); // rel->type, (long long) value, (long long) value - rel->section->offset - rel->offset);
// printf(" %llx %d %llx %d %llx : %d\n", (long long) value, (int)rel->value->section->offset, // printf(" %llx %d %llx %d %llx : %d\n", (long long) value,
// (int)rel->value->section->offset,
// rel->value->offset, rel->offset, (long long) rel->add, *location); // rel->value->offset, rel->offset, (long long) rel->add, *location);
relocate1(rel, location, value, rel->type); relocate1(rel, location, value, rel->type);
} }
@@ -611,14 +612,12 @@ void ElfLinkerARM64::relocate1(const Relocation *rel, upx_byte *location, upx_ui
set_le32(location, get_le32(location) + value); set_le32(location, get_le32(location) + value);
} else if (!strcmp(type, "ABS64")) { } else if (!strcmp(type, "ABS64")) {
set_le64(location, get_le64(location) + value); set_le64(location, get_le64(location) + value);
} } else if (!strcmp(type, "CONDBR19")) {
else if (!strcmp(type, "CONDBR19")) {
value -= rel->section->offset + rel->offset; value -= rel->section->offset + rel->offset;
upx_uint32_t const m19 = ~(~0u << 19); upx_uint32_t const m19 = ~(~0u << 19);
upx_uint32_t w = get_le32(location); upx_uint32_t w = get_le32(location);
set_le32(location, (w &~(m19<<5)) | ((((w>>5) + (value>>2)) & m19) << 5) ); set_le32(location, (w & ~(m19 << 5)) | ((((w >> 5) + (value >> 2)) & m19) << 5));
} } else
else
super::relocate1(rel, location, value, type); super::relocate1(rel, location, value, type);
} }
+35 -64
View File
@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
#include "file.h" #include "file.h"
#include "packmast.h" #include "packmast.h"
@@ -54,56 +53,48 @@
#include "p_mach.h" #include "p_mach.h"
#include "p_armpe.h" #include "p_armpe.h"
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
PackMaster::PackMaster(InputFile *f, options_t *o) : PackMaster::PackMaster(InputFile *f, options_t *o) : fi(f), p(NULL) {
fi(f), p(NULL)
{
// replace global options with local options // replace global options with local options
saved_opt = o; saved_opt = o;
if (o) if (o) {
{
memcpy(&this->local_options, o, sizeof(*o)); // struct copy memcpy(&this->local_options, o, sizeof(*o)); // struct copy
opt = &this->local_options; opt = &this->local_options;
} }
} }
PackMaster::~PackMaster() {
PackMaster::~PackMaster()
{
fi = NULL; fi = NULL;
delete p; p = NULL; delete p;
p = NULL;
// restore global options // restore global options
if (saved_opt) if (saved_opt)
opt = saved_opt; opt = saved_opt;
saved_opt = NULL; saved_opt = NULL;
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
static Packer* try_pack(Packer *p, void *user) static Packer *try_pack(Packer *p, void *user) {
{
if (p == NULL) if (p == NULL)
return NULL; return NULL;
InputFile *f = (InputFile *) user; InputFile *f = (InputFile *) user;
p->assertPacker(); p->assertPacker();
try { try {
p->initPackHeader(); p->initPackHeader();
f->seek(0,SEEK_SET); f->seek(0, SEEK_SET);
if (p->canPack()) if (p->canPack()) {
{
if (opt->cmd == CMD_COMPRESS) if (opt->cmd == CMD_COMPRESS)
p->updatePackHeader(); p->updatePackHeader();
f->seek(0,SEEK_SET); f->seek(0, SEEK_SET);
return p; return p;
} }
} catch (const IOException&) { } catch (const IOException &) {
} catch (...) { } catch (...) {
delete p; delete p;
throw; throw;
@@ -112,28 +103,24 @@ static Packer* try_pack(Packer *p, void *user)
return NULL; return NULL;
} }
static Packer *try_unpack(Packer *p, void *user) {
static Packer* try_unpack(Packer *p, void *user)
{
if (p == NULL) if (p == NULL)
return NULL; return NULL;
InputFile *f = (InputFile *) user; InputFile *f = (InputFile *) user;
p->assertPacker(); p->assertPacker();
try { try {
p->initPackHeader(); p->initPackHeader();
f->seek(0,SEEK_SET); f->seek(0, SEEK_SET);
int r = p->canUnpack(); int r = p->canUnpack();
if (r > 0) if (r > 0) {
{ f->seek(0, SEEK_SET);
f->seek(0,SEEK_SET);
return p; return p;
} }
if (r < 0) if (r < 0) {
{
// FIXME - could stop testing all other unpackers at this time // FIXME - could stop testing all other unpackers at this time
// see canUnpack() in packer.h // see canUnpack() in packer.h
} }
} catch (const IOException&) { } catch (const IOException &) {
} catch (...) { } catch (...) {
delete p; delete p;
throw; throw;
@@ -142,20 +129,20 @@ static Packer* try_unpack(Packer *p, void *user)
return NULL; return NULL;
} }
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
Packer *PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const options_t *o,
Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const options_t *o, void *user) void *user) {
{
Packer *p = NULL; Packer *p = NULL;
#define D(klass) \ #define D(klass) \
ACC_BLOCK_BEGIN \ ACC_BLOCK_BEGIN \
if (o->debug.debug_level) fprintf(stderr, "visitAllPackers: %s\n", #klass); \ if (o->debug.debug_level) \
if ((p = func(new klass(f), user)) != NULL) return p; \ fprintf(stderr, "visitAllPackers: %s\n", #klass); \
if ((p = func(new klass(f), user)) != NULL) \
return p; \
ACC_BLOCK_END ACC_BLOCK_END
// note: order of tries is important ! // note: order of tries is important !
@@ -163,8 +150,7 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
// //
// .exe // .exe
// //
if (!o->dos_exe.force_stub) if (!o->dos_exe.force_stub) {
{
D(PackDjgpp2); D(PackDjgpp2);
D(PackTmt); D(PackTmt);
D(PackWcle); D(PackWcle);
@@ -195,8 +181,7 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
// //
// linux // linux
// //
if (!o->o_unix.force_execve) if (!o->o_unix.force_execve) {
{
if (o->o_unix.use_ptinterp) { if (o->o_unix.use_ptinterp) {
D(PackLinuxElf32x86interp); D(PackLinuxElf32x86interp);
} }
@@ -215,7 +200,7 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
D(PackLinuxI386sh); D(PackLinuxI386sh);
} }
D(PackBSDI386); D(PackBSDI386);
D(PackMachFat); // cafebabe conflict D(PackMachFat); // cafebabe conflict
D(PackLinuxI386); // cafebabe conflict D(PackLinuxI386); // cafebabe conflict
// //
@@ -247,9 +232,7 @@ Packer* PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
#undef D #undef D
} }
Packer *PackMaster::getPacker(InputFile *f) {
Packer *PackMaster::getPacker(InputFile *f)
{
Packer *pp = visitAllPackers(try_pack, f, opt, f); Packer *pp = visitAllPackers(try_pack, f, opt, f);
if (!pp) if (!pp)
throwUnknownExecutableFormat(); throwUnknownExecutableFormat();
@@ -257,9 +240,7 @@ Packer *PackMaster::getPacker(InputFile *f)
return pp; return pp;
} }
Packer *PackMaster::getUnpacker(InputFile *f) {
Packer *PackMaster::getUnpacker(InputFile *f)
{
Packer *pp = visitAllPackers(try_unpack, f, opt, f); Packer *pp = visitAllPackers(try_unpack, f, opt, f);
if (!pp) if (!pp)
throwNotPacked(); throwNotPacked();
@@ -267,51 +248,41 @@ Packer *PackMaster::getUnpacker(InputFile *f)
return pp; return pp;
} }
/************************************************************************* /*************************************************************************
// delegation // delegation
**************************************************************************/ **************************************************************************/
void PackMaster::pack(OutputFile *fo) void PackMaster::pack(OutputFile *fo) {
{
p = getPacker(fi); p = getPacker(fi);
fi = NULL; fi = NULL;
p->doPack(fo); p->doPack(fo);
} }
void PackMaster::unpack(OutputFile *fo) {
void PackMaster::unpack(OutputFile *fo)
{
p = getUnpacker(fi); p = getUnpacker(fi);
p->assertPacker(); p->assertPacker();
fi = NULL; fi = NULL;
p->doUnpack(fo); p->doUnpack(fo);
} }
void PackMaster::test() {
void PackMaster::test()
{
p = getUnpacker(fi); p = getUnpacker(fi);
fi = NULL; fi = NULL;
p->doTest(); p->doTest();
} }
void PackMaster::list() {
void PackMaster::list()
{
p = getUnpacker(fi); p = getUnpacker(fi);
fi = NULL; fi = NULL;
p->doList(); p->doList();
} }
void PackMaster::fileInfo() {
void PackMaster::fileInfo()
{
p = visitAllPackers(try_unpack, fi, opt, fi); p = visitAllPackers(try_unpack, fi, opt, fi);
if (!p) if (!p)
p = visitAllPackers(try_pack, fi, opt, fi); p = visitAllPackers(try_pack, fi, opt, fi);
if (!p) if (!p)
throwUnknownExecutableFormat(NULL, 1); // make a warning here throwUnknownExecutableFormat(NULL, 1); // make a warning here
p->assertPacker(); p->assertPacker();
fi = NULL; fi = NULL;
p->doFileInfo(); p->doFileInfo();