Start using some C++ 14 features.

This commit is contained in:
Markus F.X.J. Oberhumer
2020-12-08 05:40:17 +01:00
parent 361a3056cb
commit f7e2266c3f
62 changed files with 971 additions and 960 deletions
+4 -4
View File
@@ -44,10 +44,10 @@ public:
~BoundedPtr() { } ~BoundedPtr() { }
explicit BoundedPtr(void* base, size_t size_in_bytes, T* ptr=0) BoundedPtr(void* base, size_t size_in_bytes, T* ptr=nullptr)
: ptr_(ptr), base_(base), size_in_bytes_(0) : ptr_(ptr), base_(base), size_in_bytes_(0)
{ {
assert(base_ != NULL); assert(base_ != nullptr);
size_in_bytes_ = mem_size(1, size_in_bytes); size_in_bytes_ = mem_size(1, size_in_bytes);
check(); check();
} }
@@ -86,7 +86,7 @@ private:
throwCantUnpack("pointer out of range; take care!"); throwCantUnpack("pointer out of range; take care!");
} }
void check() const { // check ptr_ invariant: either NULL or valid checkRange() void check() const { // check ptr_ invariant: either NULL or valid checkRange()
if (ptr_ != NULL) if (ptr_ != nullptr)
checkRange(); checkRange();
} }
@@ -95,7 +95,7 @@ private:
size_t size_in_bytes_; size_t size_in_bytes_;
// disable copy // disable copy
BoundedPtr(const BoundedPtr&); // {} BoundedPtr(const BoundedPtr&) = delete;
// disable dynamic allocation // disable dynamic allocation
DISABLE_NEW_DELETE DISABLE_NEW_DELETE
}; };
+3 -3
View File
@@ -28,7 +28,7 @@
#include "conf.h" #include "conf.h"
FILE *con_term = NULL; FILE *con_term = nullptr;
#if (USE_CONSOLE) #if (USE_CONSOLE)
@@ -60,7 +60,7 @@ static void try_init(console_t *c, FILE *f)
{ {
con_mode = k; con_mode = k;
con = c; con = c;
con->init = 0; con->init = nullptr;
if (!con->set_fg) if (!con->set_fg)
con->set_fg = console_none.set_fg; con->set_fg = console_none.set_fg;
if (!con->print0) if (!con->print0)
@@ -137,7 +137,7 @@ console_t console_init =
{ {
init, init,
set_fg, set_fg,
0, nullptr,
intro intro
}; };
+5 -5
View File
@@ -72,11 +72,11 @@ static int do_init(screen_t *s, int fd)
static screen_t *do_construct(screen_t *s, int fd) static screen_t *do_construct(screen_t *s, int fd)
{ {
if (!s) if (!s)
return NULL; return nullptr;
if (do_init(s,fd) != 0) if (do_init(s,fd) != 0)
{ {
s->destroy(s); s->destroy(s);
return NULL; return nullptr;
} }
return s; return s;
} }
@@ -86,7 +86,7 @@ static screen_t *do_construct(screen_t *s, int fd)
// //
**************************************************************************/ **************************************************************************/
static screen_t *screen = NULL; static screen_t *screen = nullptr;
static void __acc_cdecl_atexit do_destroy(void) static void __acc_cdecl_atexit do_destroy(void)
{ {
@@ -95,7 +95,7 @@ static void __acc_cdecl_atexit do_destroy(void)
if (screen->atExit) if (screen->atExit)
screen->atExit(); screen->atExit();
screen->destroy(screen); screen->destroy(screen);
screen = NULL; screen = nullptr;
} }
} }
@@ -113,7 +113,7 @@ static int init(FILE *f, int o, int now)
int n; int n;
UNUSED(now); UNUSED(now);
assert(screen == NULL); assert(screen == nullptr);
if (o == CON_SCREEN) if (o == CON_SCREEN)
n = CON_SCREEN; n = CON_SCREEN;
+4 -4
View File
@@ -39,7 +39,7 @@ unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
{ {
if (len == 0) if (len == 0)
return adler; return adler;
assert(buf != NULL); assert(buf != nullptr);
#if 1 #if 1
return upx_ucl_adler32(buf, len, adler); return upx_ucl_adler32(buf, len, adler);
#else #else
@@ -53,7 +53,7 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
{ {
if (len == 0) if (len == 0)
return crc; return crc;
assert(buf != NULL); assert(buf != nullptr);
#if 1 #if 1
return upx_ucl_crc32(buf, len, crc); return upx_ucl_crc32(buf, len, crc);
#else #else
@@ -145,7 +145,7 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
assert(src_len < *dst_len); // must be compressed assert(src_len < *dst_len); // must be compressed
if (cresult && cresult->method == 0) if (cresult && cresult->method == 0)
cresult = NULL; cresult = nullptr;
if __acc_cte(0) { if __acc_cte(0) {
} }
@@ -187,7 +187,7 @@ int upx_test_overlap ( const upx_bytep buf,
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
if (cresult && cresult->method == 0) if (cresult && cresult->method == 0)
cresult = NULL; cresult = nullptr;
assert(*dst_len > 0); assert(*dst_len > 0);
assert(src_len < *dst_len); // must be compressed assert(src_len < *dst_len); // must be compressed
+9 -7
View File
@@ -230,6 +230,8 @@ error:
#undef _WIN32_WCE #undef _WIN32_WCE
#undef COMPRESS_MF_MT #undef COMPRESS_MF_MT
#undef _NO_EXCEPTIONS #undef _NO_EXCEPTIONS
#undef NULL
#define NULL nullptr
#include "C/Common/MyInitGuid.h" #include "C/Common/MyInitGuid.h"
//#include "C/7zip/Compress/LZMA/LZMADecoder.h" //#include "C/7zip/Compress/LZMA/LZMADecoder.h"
#include "C/7zip/Compress/LZMA/LZMAEncoder.h" #include "C/7zip/Compress/LZMA/LZMAEncoder.h"
@@ -253,7 +255,7 @@ STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
if (size > remain) size = (UInt32) remain; if (size > remain) size = (UInt32) remain;
memmove(data, b_buf + b_pos, size); memmove(data, b_buf + b_pos, size);
b_pos += size; b_pos += size;
if (processedSize != NULL) *processedSize = size; if (processedSize != nullptr) *processedSize = size;
return S_OK; return S_OK;
} }
@@ -279,7 +281,7 @@ STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSi
if (size > remain) size = (UInt32) remain, overflow = true; if (size > remain) size = (UInt32) remain, overflow = true;
memmove(b_buf + b_pos, data, size); memmove(b_buf + b_pos, data, size);
b_pos += size; b_pos += size;
if (processedSize != NULL) *processedSize = size; if (processedSize != nullptr) *processedSize = size;
return overflow ? E_FAIL : S_OK; return overflow ? E_FAIL : S_OK;
} }
@@ -321,11 +323,11 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
upx_compress_result_t *cresult ) upx_compress_result_t *cresult )
{ {
assert(M_IS_LZMA(method)); assert(M_IS_LZMA(method));
assert(level > 0); assert(cresult != NULL); assert(level > 0); assert(cresult != nullptr);
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
HRESULT rh; HRESULT rh;
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL; const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : nullptr;
lzma_compress_result_t *res = &cresult->result_lzma; lzma_compress_result_t *res = &cresult->result_lzma;
MyLzma::InStream is; is.AddRef(); MyLzma::InStream is; is.AddRef();
@@ -382,7 +384,7 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
os.WriteByte(Byte((t << 3) | res->pos_bits)); os.WriteByte(Byte((t << 3) | res->pos_bits));
os.WriteByte(Byte((res->lit_pos_bits << 4) | (res->lit_context_bits))); os.WriteByte(Byte((res->lit_pos_bits << 4) | (res->lit_context_bits)));
rh = enc.Code(&is, &os, NULL, NULL, &progress); rh = enc.Code(&is, &os, nullptr, nullptr, &progress);
} catch (...) { } catch (...) {
rh = E_OUTOFMEMORY; rh = E_OUTOFMEMORY;
@@ -509,7 +511,7 @@ int upx_lzma_test_overlap ( const upx_bytep buf,
// NOTE: there is a very tiny possibility that decompression has // NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of // succeeded but the data is not restored correctly because of
// in-place buffer overlapping, so we use an extra memcmp(). // in-place buffer overlapping, so we use an extra memcmp().
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0) if (tbuf != nullptr && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR; return UPX_E_ERROR;
return UPX_E_OK; return UPX_E_OK;
} }
@@ -530,7 +532,7 @@ const char *upx_lzma_version_string(void)
return "4.43"; return "4.43";
#else #else
# error "unknown WITH_LZMA version" # error "unknown WITH_LZMA version"
return NULL; return nullptr;
#endif #endif
} }
+21 -21
View File
@@ -106,13 +106,13 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
upx_compress_result_t *cresult ) upx_compress_result_t *cresult )
{ {
int r; int r;
assert(level > 0); assert(cresult != NULL); assert(level > 0); assert(cresult != nullptr);
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t)) COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
ucl_progress_callback_t cb; ucl_progress_callback_t cb;
cb.callback = 0; cb.callback = nullptr;
cb.user = NULL; cb.user = nullptr;
if (cb_parm && cb_parm->nprogress) { if (cb_parm && cb_parm->nprogress) {
cb.callback = wrap_nprogress_ucl; cb.callback = wrap_nprogress_ucl;
cb.user = cb_parm; cb.user = cb_parm;
@@ -188,31 +188,31 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
switch (method) switch (method)
{ {
case M_NRV2B_8: case M_NRV2B_8:
r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,NULL); r = ucl_nrv2b_decompress_safe_8(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2B_LE16: case M_NRV2B_LE16:
r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,NULL); r = ucl_nrv2b_decompress_safe_le16(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2B_LE32: case M_NRV2B_LE32:
r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,NULL); r = ucl_nrv2b_decompress_safe_le32(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2D_8: case M_NRV2D_8:
r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,NULL); r = ucl_nrv2d_decompress_safe_8(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2D_LE16: case M_NRV2D_LE16:
r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,NULL); r = ucl_nrv2d_decompress_safe_le16(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2D_LE32: case M_NRV2D_LE32:
r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,NULL); r = ucl_nrv2d_decompress_safe_le32(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2E_8: case M_NRV2E_8:
r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,NULL); r = ucl_nrv2e_decompress_safe_8(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2E_LE16: case M_NRV2E_LE16:
r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,NULL); r = ucl_nrv2e_decompress_safe_le16(src,src_len,dst,dst_len,nullptr);
break; break;
case M_NRV2E_LE32: case M_NRV2E_LE32:
r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,NULL); r = ucl_nrv2e_decompress_safe_le32(src,src_len,dst,dst_len,nullptr);
break; break;
default: default:
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
@@ -241,31 +241,31 @@ int upx_ucl_test_overlap ( const upx_bytep buf,
switch (method) switch (method)
{ {
case M_NRV2B_8: case M_NRV2B_8:
r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2b_test_overlap_8(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2B_LE16: case M_NRV2B_LE16:
r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2b_test_overlap_le16(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2B_LE32: case M_NRV2B_LE32:
r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2b_test_overlap_le32(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2D_8: case M_NRV2D_8:
r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2d_test_overlap_8(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2D_LE16: case M_NRV2D_LE16:
r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2d_test_overlap_le16(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2D_LE32: case M_NRV2D_LE32:
r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2d_test_overlap_le32(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2E_8: case M_NRV2E_8:
r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2e_test_overlap_8(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2E_LE16: case M_NRV2E_LE16:
r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2e_test_overlap_le16(buf,src_off,src_len,dst_len,nullptr);
break; break;
case M_NRV2E_LE32: case M_NRV2E_LE32:
r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,NULL); r = ucl_nrv2e_test_overlap_le32(buf,src_off,src_len,dst_len,nullptr);
break; break;
default: default:
throwInternalError("unknown decompression method"); throwInternalError("unknown decompression method");
+7 -7
View File
@@ -73,11 +73,11 @@ int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
upx_compress_result_t *cresult ) upx_compress_result_t *cresult )
{ {
assert(method == M_DEFLATE); assert(method == M_DEFLATE);
assert(level > 0); assert(cresult != NULL); assert(level > 0); assert(cresult != nullptr);
UNUSED(cb_parm); UNUSED(cb_parm);
int r = UPX_E_ERROR; int r = UPX_E_ERROR;
int zr; int zr;
const zlib_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_zlib : NULL; const zlib_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_zlib : nullptr;
zlib_compress_result_t *res = &cresult->result_zlib; zlib_compress_result_t *res = &cresult->result_zlib;
if (level == 10) if (level == 10)
@@ -97,8 +97,8 @@ int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
res->dummy = 0; res->dummy = 0;
z_stream s; z_stream s;
s.zalloc = (alloc_func) 0; s.zalloc = (alloc_func) nullptr;
s.zfree = (free_func) 0; s.zfree = (free_func) nullptr;
s.next_in = ACC_UNCONST_CAST(upx_bytep, src); s.next_in = ACC_UNCONST_CAST(upx_bytep, src);
s.avail_in = src_len; s.avail_in = src_len;
s.next_out = dst; s.next_out = dst;
@@ -151,8 +151,8 @@ int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
int zr; int zr;
z_stream s; z_stream s;
s.zalloc = (alloc_func) 0; s.zalloc = (alloc_func) nullptr;
s.zfree = (free_func) 0; s.zfree = (free_func) nullptr;
s.next_in = ACC_UNCONST_CAST(upx_bytep, src); s.next_in = ACC_UNCONST_CAST(upx_bytep, src);
s.avail_in = src_len; s.avail_in = src_len;
s.next_out = dst; s.next_out = dst;
@@ -212,7 +212,7 @@ int upx_zlib_test_overlap ( const upx_bytep buf,
// NOTE: there is a very tiny possibility that decompression has // NOTE: there is a very tiny possibility that decompression has
// succeeded but the data is not restored correctly because of // succeeded but the data is not restored correctly because of
// in-place buffer overlapping, so we use an extra memcmp(). // in-place buffer overlapping, so we use an extra memcmp().
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0) if (tbuf != nullptr && memcmp(tbuf, b, *dst_len) != 0)
return UPX_E_ERROR; return UPX_E_ERROR;
return UPX_E_OK; return UPX_E_OK;
} }
+7 -2
View File
@@ -65,11 +65,16 @@
# error "UINT_MAX" # error "UINT_MAX"
#endif #endif
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4)
ACC_COMPILE_TIME_ASSERT_HEADER(-1 == ~0) // two's complement - see http://wg21.link/P0907R4
ACC_COMPILE_TIME_ASSERT_HEADER(0u-1 == ~0u) // two's complement - see http://wg21.link/P0907R4
ACC_COMPILE_TIME_ASSERT_HEADER((1u << 31) << 1 == 0) ACC_COMPILE_TIME_ASSERT_HEADER((1u << 31) << 1 == 0)
ACC_COMPILE_TIME_ASSERT_HEADER(((int)(1u << 31)) >> 31 == -1) // arithmetic right shift ACC_COMPILE_TIME_ASSERT_HEADER(((int)(1u << 31)) >> 31 == -1) // arithmetic right shift
ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255) // -funsigned-char ACC_COMPILE_TIME_ASSERT_HEADER(CHAR_MAX == 255) // -funsigned-char
ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) > 0) // -funsigned-char ACC_COMPILE_TIME_ASSERT_HEADER((char)(-1) > 0) // -funsigned-char
#if (ACC_CC_GNUC >= 0x040700)
# pragma GCC diagnostic error "-Wzero-as-null-pointer-constant"
#endif
#if (ACC_CC_MSC) #if (ACC_CC_MSC)
# pragma warning(error: 4127) # pragma warning(error: 4127)
# pragma warning(error: 4146) # pragma warning(error: 4146)
@@ -585,7 +590,7 @@ struct upx_compress_config_t
void reset() { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); } void reset() { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); }
}; };
#define NULL_cconf ((upx_compress_config_t *) NULL) #define NULL_cconf ((upx_compress_config_t *) nullptr)
/************************************************************************* /*************************************************************************
@@ -670,7 +675,7 @@ void e_exit(int ec);
// msg.cpp // msg.cpp
void printSetNl(int need_nl); void printSetNl(int need_nl);
void printClearLine(FILE *f = NULL); void printClearLine(FILE *f = nullptr);
void printErr(const char *iname, const Throwable *e); void printErr(const char *iname, const Throwable *e);
void printUnhandledException(const char *iname, const std::exception *e); void printUnhandledException(const char *iname, const std::exception *e);
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE) #if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
+7 -7
View File
@@ -36,7 +36,7 @@
unsigned long Throwable::counter = 0; unsigned long Throwable::counter = 0;
Throwable::Throwable(const char *m, int e, bool w) noexcept Throwable::Throwable(const char *m, int e, bool w) noexcept
: super(), msg(NULL), err(e), is_warning(w) : super(), msg(nullptr), err(e), is_warning(w)
{ {
if (m) if (m)
msg = strdup(m); msg = strdup(m);
@@ -48,7 +48,7 @@ Throwable::Throwable(const char *m, int e, bool w) noexcept
Throwable::Throwable(const Throwable &other) noexcept Throwable::Throwable(const Throwable &other) noexcept
: super(other), msg(NULL), err(other.err), is_warning(other.is_warning) : super(other), msg(nullptr), err(other.err), is_warning(other.is_warning)
{ {
if (other.msg) if (other.msg)
msg = strdup(other.msg); msg = strdup(other.msg);
@@ -112,7 +112,7 @@ void throwAlreadyPacked(const char *msg)
void throwAlreadyPackedByUPX(const char *msg) void throwAlreadyPackedByUPX(const char *msg)
{ {
if (msg == NULL) if (msg == nullptr)
msg = "already packed by UPX"; msg = "already packed by UPX";
throwAlreadyPacked(msg); throwAlreadyPacked(msg);
} }
@@ -130,7 +130,7 @@ void throwCantUnpack(const char *msg)
void throwNotPacked(const char *msg) void throwNotPacked(const char *msg)
{ {
if (msg == NULL) if (msg == nullptr)
msg = "not packed by UPX"; msg = "not packed by UPX";
throw NotPackedException(msg); throw NotPackedException(msg);
} }
@@ -163,7 +163,7 @@ void throwBadLoader()
void throwOutOfMemoryException(const char *msg) void throwOutOfMemoryException(const char *msg)
{ {
if (msg == NULL) if (msg == nullptr)
msg = "out of memory"; msg = "out of memory";
throw OutOfMemoryException(msg); throw OutOfMemoryException(msg);
} }
@@ -177,7 +177,7 @@ void throwIOException(const char *msg, int e)
void throwEOFException(const char *msg, int e) void throwEOFException(const char *msg, int e)
{ {
if (msg == NULL && e == 0) if (msg == nullptr && e == 0)
msg = "premature end of file"; msg = "premature end of file";
throw EOFException(msg, e); throw EOFException(msg, e);
} }
@@ -189,7 +189,7 @@ void throwEOFException(const char *msg, int e)
const char *prettyName(const char *n) noexcept const char *prettyName(const char *n) noexcept
{ {
if (n == NULL) if (n == nullptr)
return "(null)"; return "(null)";
while (*n) while (*n)
{ {
+24 -24
View File
@@ -42,7 +42,7 @@ class Throwable : public std::exception
{ {
typedef std::exception super; typedef std::exception super;
protected: protected:
Throwable(const char *m = 0, int e = 0, bool w = false) noexcept; Throwable(const char *m = nullptr, int e = 0, bool w = false) noexcept;
public: public:
Throwable(const Throwable &) noexcept; Throwable(const Throwable &) noexcept;
virtual ~Throwable() noexcept; virtual ~Throwable() noexcept;
@@ -71,7 +71,7 @@ class Exception : public Throwable
{ {
typedef Throwable super; typedef Throwable super;
public: public:
Exception(const char *m = 0, int e = 0, bool w = false) noexcept : super(m,e,w) { } Exception(const char *m = nullptr, int e = 0, bool w = false) noexcept : super(m,e,w) { }
}; };
@@ -80,7 +80,7 @@ class Error : public Throwable
{ {
typedef Throwable super; typedef Throwable super;
public: public:
Error(const char *m = 0, int e = 0) noexcept : super(m,e) { } Error(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
}; };
@@ -92,7 +92,7 @@ class OutOfMemoryException : public Exception
{ {
typedef Exception super; typedef Exception super;
public: public:
OutOfMemoryException(const char *m = 0, int e = 0) noexcept : super(m,e) { } OutOfMemoryException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
}; };
@@ -100,7 +100,7 @@ class IOException : public Exception
{ {
typedef Exception super; typedef Exception super;
public: public:
IOException(const char *m = 0, int e = 0) noexcept : super(m,e) { } IOException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
}; };
@@ -108,7 +108,7 @@ class EOFException : public IOException
{ {
typedef IOException super; typedef IOException super;
public: public:
EOFException(const char *m = 0, int e = 0) noexcept : super(m,e) { } EOFException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
}; };
@@ -116,7 +116,7 @@ class FileNotFoundException : public IOException
{ {
typedef IOException super; typedef IOException super;
public: public:
FileNotFoundException(const char *m = 0, int e = 0) noexcept : super(m,e) { } FileNotFoundException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
}; };
@@ -124,7 +124,7 @@ class FileAlreadyExistsException : public IOException
{ {
typedef IOException super; typedef IOException super;
public: public:
FileAlreadyExistsException(const char *m = 0, int e = 0) noexcept : super(m,e) { } FileAlreadyExistsException(const char *m = nullptr, int e = 0) noexcept : super(m,e) { }
}; };
@@ -136,35 +136,35 @@ class OverlayException : public Exception
{ {
typedef Exception super; typedef Exception super;
public: public:
OverlayException(const char *m = 0, bool w = false) noexcept : super(m,0,w) { } OverlayException(const char *m = nullptr, bool w = false) noexcept : super(m,0,w) { }
}; };
class CantPackException : public Exception class CantPackException : public Exception
{ {
typedef Exception super; typedef Exception super;
public: public:
CantPackException(const char *m = 0, bool w = false) noexcept : super(m,0,w) { } CantPackException(const char *m = nullptr, bool w = false) noexcept : super(m,0,w) { }
}; };
class UnknownExecutableFormatException : public CantPackException class UnknownExecutableFormatException : public CantPackException
{ {
typedef CantPackException super; typedef CantPackException super;
public: public:
UnknownExecutableFormatException(const char *m = 0, bool w = false) noexcept : super(m,w) { } UnknownExecutableFormatException(const char *m = nullptr, bool w = false) noexcept : super(m,w) { }
}; };
class AlreadyPackedException : public CantPackException class AlreadyPackedException : public CantPackException
{ {
typedef CantPackException super; typedef CantPackException super;
public: public:
AlreadyPackedException(const char *m = 0) noexcept : super(m) { is_warning = true; } AlreadyPackedException(const char *m = nullptr) noexcept : super(m) { is_warning = true; }
}; };
class NotCompressibleException : public CantPackException class NotCompressibleException : public CantPackException
{ {
typedef CantPackException super; typedef CantPackException super;
public: public:
NotCompressibleException(const char *m = 0) noexcept : super(m) { } NotCompressibleException(const char *m = nullptr) noexcept : super(m) { }
}; };
@@ -172,14 +172,14 @@ class CantUnpackException : public Exception
{ {
typedef Exception super; typedef Exception super;
public: public:
CantUnpackException(const char *m = 0, bool w = false) noexcept : super(m,0,w) { } CantUnpackException(const char *m = nullptr, bool w = false) noexcept : super(m,0,w) { }
}; };
class NotPackedException : public CantUnpackException class NotPackedException : public CantUnpackException
{ {
typedef CantUnpackException super; typedef CantUnpackException super;
public: public:
NotPackedException(const char *m = 0) noexcept : super(m,true) { } NotPackedException(const char *m = nullptr) noexcept : super(m,true) { }
}; };
@@ -191,7 +191,7 @@ class InternalError : public Error
{ {
typedef Error super; typedef Error super;
public: public:
InternalError(const char *m = 0) noexcept : super(m,0) { } InternalError(const char *m = nullptr) noexcept : super(m,0) { }
}; };
@@ -208,20 +208,20 @@ public:
void throwCantPack(const char *msg) NORET; void throwCantPack(const char *msg) NORET;
void throwCantPackExact() NORET; void throwCantPackExact() NORET;
void throwUnknownExecutableFormat(const char *msg = NULL, bool warn = false) NORET; void throwUnknownExecutableFormat(const char *msg = nullptr, bool warn = false) NORET;
void throwNotCompressible(const char *msg = NULL) NORET; void throwNotCompressible(const char *msg = nullptr) NORET;
void throwAlreadyPacked(const char *msg = NULL) NORET; void throwAlreadyPacked(const char *msg = nullptr) NORET;
void throwAlreadyPackedByUPX(const char *msg = NULL) NORET; void throwAlreadyPackedByUPX(const char *msg = nullptr) NORET;
void throwCantUnpack(const char *msg) NORET; void throwCantUnpack(const char *msg) NORET;
void throwNotPacked(const char *msg = NULL) NORET; void throwNotPacked(const char *msg = nullptr) NORET;
void throwFilterException() NORET; void throwFilterException() NORET;
void throwBadLoader() NORET; void throwBadLoader() NORET;
void throwChecksumError() NORET; void throwChecksumError() NORET;
void throwCompressedDataViolation() NORET; void throwCompressedDataViolation() NORET;
void throwInternalError(const char *msg) NORET; void throwInternalError(const char *msg) NORET;
void throwOutOfMemoryException(const char *msg = NULL) NORET; void throwOutOfMemoryException(const char *msg = nullptr) NORET;
void throwIOException(const char *msg = NULL, int e = 0) NORET; void throwIOException(const char *msg = nullptr, int e = 0) NORET;
void throwEOFException(const char *msg = NULL, int e = 0) NORET; void throwEOFException(const char *msg = nullptr, int e = 0) NORET;
#undef NORET #undef NORET
+3 -3
View File
@@ -69,7 +69,7 @@ void File::unlink(const char *name)
**************************************************************************/ **************************************************************************/
FileBase::FileBase() : FileBase::FileBase() :
_fd(-1), _flags(0), _shflags(0), _mode(0), _name(NULL), _offset(0), _length(0) _fd(-1), _flags(0), _shflags(0), _mode(0), _name(nullptr), _offset(0), _length(0)
{ {
memset(&st,0,sizeof(st)); memset(&st,0,sizeof(st));
} }
@@ -122,7 +122,7 @@ bool FileBase::close()
_fd = -1; _fd = -1;
_flags = 0; _flags = 0;
_mode = 0; _mode = 0;
_name = NULL; _name = nullptr;
_offset = 0; _offset = 0;
_length = 0; _length = 0;
return ok; return ok;
@@ -477,7 +477,7 @@ void OutputFile::dump(const char *name, const void *buf, int len, int flags)
#if 0 #if 0
MemoryOutputFile::MemoryOutputFile() : MemoryOutputFile::MemoryOutputFile() :
b(NULL), b_size(0), b_pos(0), bytes_written(0) b(nullptr), b_size(0), b_pos(0), bytes_written(0)
{ {
} }
+3 -3
View File
@@ -163,10 +163,10 @@ class MemoryOutputFile : public FileBase
typedef FileBase super; typedef FileBase super;
public: public:
MemoryOutputFile(); MemoryOutputFile();
virtual ~MemoryOutputFile() { b = NULL; } virtual ~MemoryOutputFile() { b = nullptr; }
virtual bool close() { b = NULL; return true; } virtual bool close() { b = nullptr; return true; }
virtual bool isOpen() const { return b != NULL; } virtual bool isOpen() const { return b != nullptr; }
virtual void open(void *buf, unsigned size) virtual void open(void *buf, unsigned size)
{ b = (upx_bytep) buf; b_size = size; } { b = (upx_bytep) buf; b_size = size; }
+9 -9
View File
@@ -70,10 +70,10 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
} }
if (id < 0 || id > 255) if (id < 0 || id > 255)
return NULL; return nullptr;
unsigned index = filter_map[id]; unsigned index = filter_map[id];
if (index == 0xff) // empty slot if (index == 0xff) // empty slot
return NULL; return nullptr;
assert(filters[index].id == id); assert(filters[index].id == id);
return &filters[index]; return &filters[index];
} }
@@ -82,7 +82,7 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
bool Filter::isValidFilter(int filter_id) bool Filter::isValidFilter(int filter_id)
{ {
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(filter_id); const FilterImp::FilterEntry * const fe = FilterImp::getFilter(filter_id);
return fe != NULL; return fe != nullptr;
} }
bool Filter::isValidFilter(int filter_id, const int *allowed_filters) bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
@@ -91,7 +91,7 @@ bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
return false; return false;
if (filter_id == 0) if (filter_id == 0)
return true; return true;
if (allowed_filters == NULL) if (allowed_filters == nullptr)
return false; return false;
while (*allowed_filters != FT_END) while (*allowed_filters != FT_END)
if (*allowed_filters++ == filter_id) if (*allowed_filters++ == filter_id)
@@ -107,10 +107,10 @@ bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
void Filter::init(int id_, unsigned addvalue_) void Filter::init(int id_, unsigned addvalue_)
{ {
this->id = id_; this->id = id_;
initFilter(this, NULL, 0); initFilter(this, nullptr, 0);
// clear input parameters // clear input parameters
this->addvalue = addvalue_; this->addvalue = addvalue_;
this->preferred_ctos = NULL; this->preferred_ctos = nullptr;
// clear input/output parameters // clear input/output parameters
this->cto = 0; this->cto = 0;
this->n_mru = 0; this->n_mru = 0;
@@ -122,7 +122,7 @@ bool Filter::filter(upx_byte *buf_, unsigned buf_len_)
initFilter(this, buf_, buf_len_); initFilter(this, buf_, buf_len_);
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id); const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id);
if (fe == NULL) if (fe == nullptr)
throwInternalError("filter-1"); throwInternalError("filter-1");
if (fe->id == 0) if (fe->id == 0)
return true; return true;
@@ -155,7 +155,7 @@ void Filter::unfilter(upx_byte *buf_, unsigned buf_len_, bool verify_checksum)
initFilter(this, buf_, buf_len_); initFilter(this, buf_, buf_len_);
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id); const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id);
if (fe == NULL) if (fe == nullptr)
throwInternalError("unfilter-1"); throwInternalError("unfilter-1");
if (fe->id == 0) if (fe->id == 0)
return; return;
@@ -207,7 +207,7 @@ bool Filter::scan(const upx_byte *buf_, unsigned buf_len_)
initFilter(this, b, buf_len_); initFilter(this, b, buf_len_);
const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id); const FilterImp::FilterEntry * const fe = FilterImp::getFilter(id);
if (fe == NULL) if (fe == nullptr)
throwInternalError("scan-1"); throwInternalError("scan-1");
if (fe->id == 0) if (fe->id == 0)
return true; return true;
+1 -1
View File
@@ -170,7 +170,7 @@ umin(unsigned const a, unsigned const b)
const FilterImp::FilterEntry FilterImp::filters[] = { const FilterImp::FilterEntry FilterImp::filters[] = {
// no filter // no filter
{ 0x00, 0, 0, NULL, NULL, NULL }, { 0x00, 0, 0, nullptr, nullptr, nullptr },
// 16-bit calltrick // 16-bit calltrick
{ 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8 }, { 0x01, 4, 0, f_ct16_e8, u_ct16_e8, s_ct16_e8 },
+8 -8
View File
@@ -107,7 +107,7 @@ struct PackerNames
Entry names[64]; Entry names[64];
size_t names_count; size_t names_count;
const options_t *o; const options_t *o;
PackerNames() : names_count(0), o(NULL) { } PackerNames() : names_count(0), o(nullptr) { }
void add(const Packer *p) void add(const Packer *p)
{ {
p->assertPacker(); p->assertPacker();
@@ -120,8 +120,8 @@ struct PackerNames
{ {
PackerNames *self = (PackerNames *) user; PackerNames *self = (PackerNames *) user;
self->add(p); self->add(p);
delete p; p = NULL; delete p; p = nullptr;
return NULL; return nullptr;
} }
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) { static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {
return strcmp(((const Entry *) a)->fname, ((const Entry *) b)->fname); return strcmp(((const Entry *) a)->fname, ((const Entry *) b)->fname);
@@ -135,7 +135,7 @@ static void show_all_packers(FILE *f, int verbose)
{ {
options_t o; o.reset(); options_t o; o.reset();
PackerNames pn; pn.o = &o; PackerNames pn; pn.o = &o;
PackMaster::visitAllPackers(PackerNames::visit, NULL, &o, &pn); PackMaster::visitAllPackers(PackerNames::visit, nullptr, &o, &pn);
qsort(pn.names, pn.names_count, sizeof(PackerNames::Entry), PackerNames::cmp_fname); qsort(pn.names, pn.names_count, sizeof(PackerNames::Entry), PackerNames::cmp_fname);
size_t pos = 0; size_t pos = 0;
for (size_t i = 0; i < pn.names_count; ++i) for (size_t i = 0; i < pn.names_count; ++i)
@@ -389,22 +389,22 @@ void show_version(int x)
); );
#if (WITH_NRV) #if (WITH_NRV)
v = upx_nrv_version_string(); v = upx_nrv_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "NRV data compression library %s\n", v); fprintf(fp, "NRV data compression library %s\n", v);
#endif #endif
#if (WITH_UCL) #if (WITH_UCL)
v = upx_ucl_version_string(); v = upx_ucl_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "UCL data compression library %s\n", v); fprintf(fp, "UCL data compression library %s\n", v);
#endif #endif
#if (WITH_ZLIB) #if (WITH_ZLIB)
v = upx_zlib_version_string(); v = upx_zlib_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "zlib data compression library %s\n", v); fprintf(fp, "zlib data compression library %s\n", v);
#endif #endif
#if (WITH_LZMA) #if (WITH_LZMA)
v = upx_lzma_version_string(); v = upx_lzma_version_string();
if (v != NULL && v[0]) if (v != nullptr && v[0])
fprintf(fp, "LZMA SDK version %s\n", v); fprintf(fp, "LZMA SDK version %s\n", v);
#endif #endif
fprintf(fp, "Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer\n"); fprintf(fp, "Copyright (C) 1996-2020 Markus Franz Xaver Johannes Oberhumer\n");
+9 -9
View File
@@ -33,7 +33,7 @@
LeFile::LeFile(InputFile *f) : LeFile::LeFile(InputFile *f) :
fif(f), fof(NULL), fif(f), fof(nullptr),
le_offset(0), exe_offset(0) le_offset(0), exe_offset(0)
{ {
COMPILE_TIME_ASSERT(sizeof(le_header_t) == 196); COMPILE_TIME_ASSERT(sizeof(le_header_t) == 196);
@@ -41,13 +41,13 @@ LeFile::LeFile(InputFile *f) :
COMPILE_TIME_ASSERT(sizeof(le_pagemap_entry_t) == 4); COMPILE_TIME_ASSERT(sizeof(le_pagemap_entry_t) == 4);
memset(&ih,0,sizeof ih); memset(&ih,0,sizeof ih);
memset(&oh,0,sizeof oh); memset(&oh,0,sizeof oh);
iobject_table = oobject_table = NULL; iobject_table = oobject_table = nullptr;
ifpage_table = ofpage_table = NULL; ifpage_table = ofpage_table = nullptr;
ipm_entries = opm_entries = NULL; ipm_entries = opm_entries = nullptr;
ires_names = ores_names = NULL; ires_names = ores_names = nullptr;
ifixups = ofixups = NULL; ifixups = ofixups = nullptr;
inonres_names = ononres_names = NULL; inonres_names = ononres_names = nullptr;
ientries = oentries = NULL; ientries = oentries = nullptr;
} }
@@ -206,7 +206,7 @@ void LeFile::readImage()
void LeFile::writeImage() void LeFile::writeImage()
{ {
if (fof && oimage != NULL) if (fof && oimage != nullptr)
fof->write(oimage, soimage); fof->write(oimage, soimage);
} }
+10 -10
View File
@@ -137,42 +137,42 @@ protected:
virtual void readObjectTable(); virtual void readObjectTable();
virtual void writeObjectTable(); virtual void writeObjectTable();
//virtual void encodeObjectTable(){oobject_table = iobject_table; iobject_table = NULL;} //virtual void encodeObjectTable(){oobject_table = iobject_table; iobject_table = nullptr;}
//virtual void decodeObjectTable(){encodeObjectTable();} //virtual void decodeObjectTable(){encodeObjectTable();}
virtual void readFixupPageTable(); virtual void readFixupPageTable();
virtual void writeFixupPageTable(); virtual void writeFixupPageTable();
//virtual void encodeFixupPageTable(){ofpage_table = ifpage_table; ifpage_table = NULL;} //virtual void encodeFixupPageTable(){ofpage_table = ifpage_table; ifpage_table = nullptr;}
//virtual void decodeFixupPageTable(){encodeFixupPageTable();} //virtual void decodeFixupPageTable(){encodeFixupPageTable();}
virtual void readPageMap(); virtual void readPageMap();
virtual void writePageMap(); virtual void writePageMap();
virtual void encodePageMap(){opm_entries = ipm_entries; ipm_entries = NULL;} virtual void encodePageMap(){opm_entries = ipm_entries; ipm_entries = nullptr;}
virtual void decodePageMap(){encodePageMap();} virtual void decodePageMap(){encodePageMap();}
virtual void readResidentNames(); virtual void readResidentNames();
virtual void writeResidentNames(); virtual void writeResidentNames();
virtual void encodeResidentNames(){ores_names = ires_names; ires_names = NULL;} virtual void encodeResidentNames(){ores_names = ires_names; ires_names = nullptr;}
virtual void decodeResidentNames(){encodeResidentNames();} virtual void decodeResidentNames(){encodeResidentNames();}
virtual void readNonResidentNames(); virtual void readNonResidentNames();
virtual void writeNonResidentNames(); virtual void writeNonResidentNames();
virtual void encodeNonResidentNames(){ononres_names = inonres_names; inonres_names = NULL;} virtual void encodeNonResidentNames(){ononres_names = inonres_names; inonres_names = nullptr;}
virtual void decodeNonResidentNames(){encodeNonResidentNames();} virtual void decodeNonResidentNames(){encodeNonResidentNames();}
virtual void readEntryTable(); virtual void readEntryTable();
virtual void writeEntryTable(); virtual void writeEntryTable();
//virtual void encodeEntryTable(){oentries = ientries; ientries = NULL;} //virtual void encodeEntryTable(){oentries = ientries; ientries = nullptr;}
//virtual void decodeEntryTable(){encodeEntryTable();} //virtual void decodeEntryTable(){encodeEntryTable();}
virtual void readFixups(); virtual void readFixups();
virtual void writeFixups(); virtual void writeFixups();
//virtual void encodeFixups(){ofixups = ifixups; ifixups = NULL;} //virtual void encodeFixups(){ofixups = ifixups; ifixups = nullptr;}
//virtual void decodeFixups(){encodeFixups();} //virtual void decodeFixups(){encodeFixups();}
virtual void readImage(); virtual void readImage();
virtual void writeImage(); virtual void writeImage();
//virtual void encodeImage(){oimage = iimage; iimage = NULL;} //virtual void encodeImage(){oimage = iimage; iimage = nullptr;}
//virtual void decodeImage(){encodeImage();} //virtual void decodeImage(){encodeImage();}
void countFixups(unsigned *) const; void countFixups(unsigned *) const;
@@ -214,8 +214,8 @@ protected:
private: private:
// disable copy and assignment // disable copy and assignment
LeFile(const LeFile &); // {} LeFile(const LeFile &) = delete;
LeFile& operator= (const LeFile &); // { return *this; } LeFile& operator= (const LeFile &) = delete;
}; };
+35 -35
View File
@@ -56,11 +56,11 @@ static void __acc_cdecl_va internal_error(const char *format, ...) {
**************************************************************************/ **************************************************************************/
ElfLinker::Section::Section(const char *n, const void *i, unsigned s, unsigned a) ElfLinker::Section::Section(const char *n, const void *i, unsigned s, unsigned a)
: name(NULL), output(NULL), size(s), offset(0), p2align(a), next(NULL) { : name(nullptr), output(nullptr), size(s), offset(0), p2align(a), next(nullptr) {
name = strdup(n); name = strdup(n);
assert(name != NULL); assert(name != nullptr);
input = malloc(s + 1); input = malloc(s + 1);
assert(input != NULL); assert(input != nullptr);
if (s != 0) if (s != 0)
memcpy(input, i, s); memcpy(input, i, s);
((char *) input)[s] = 0; ((char *) input)[s] = 0;
@@ -76,10 +76,10 @@ ElfLinker::Section::~Section() {
**************************************************************************/ **************************************************************************/
ElfLinker::Symbol::Symbol(const char *n, Section *s, upx_uint64_t o) ElfLinker::Symbol::Symbol(const char *n, Section *s, upx_uint64_t o)
: name(NULL), section(s), offset(o) { : name(nullptr), section(s), offset(o) {
name = strdup(n); name = strdup(n);
assert(name != NULL); assert(name != nullptr);
assert(section != NULL); assert(section != nullptr);
} }
ElfLinker::Symbol::~Symbol() { free(name); } ElfLinker::Symbol::~Symbol() { free(name); }
@@ -91,7 +91,7 @@ ElfLinker::Symbol::~Symbol() { free(name); }
ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t, const Symbol *v, ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t, const Symbol *v,
upx_uint64_t a) upx_uint64_t a)
: section(s), offset(o), type(t), value(v), add(a) { : section(s), offset(o), type(t), value(v), add(a) {
assert(section != NULL); assert(section != nullptr);
} }
/************************************************************************* /*************************************************************************
@@ -99,10 +99,10 @@ ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t, c
**************************************************************************/ **************************************************************************/
ElfLinker::ElfLinker() ElfLinker::ElfLinker()
: bele(&N_BELE_RTP::le_policy), input(NULL), output(NULL), head(NULL), tail(NULL), : bele(&N_BELE_RTP::le_policy), input(nullptr), output(nullptr), head(nullptr), tail(nullptr),
sections(NULL), symbols(NULL), relocations(NULL), nsections(0), nsections_capacity(0), sections(nullptr), symbols(nullptr), relocations(nullptr), nsections(0),
nsymbols(0), nsymbols_capacity(0), nrelocations(0), nrelocations_capacity(0), nsections_capacity(0), nsymbols(0), nsymbols_capacity(0), nrelocations(0),
reloc_done(false) {} nrelocations_capacity(0), reloc_done(false) {}
ElfLinker::~ElfLinker() { ElfLinker::~ElfLinker() {
delete[] input; delete[] input;
@@ -143,7 +143,7 @@ void ElfLinker::init(const void *pdata_v, int plen) {
inputlen = u_len; inputlen = u_len;
input = new upx_byte[inputlen + 1]; input = new upx_byte[inputlen + 1];
unsigned new_len = u_len; unsigned new_len = u_len;
int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL); int r = upx_decompress(pdata, c_len, input, &new_len, method, nullptr);
if (r == UPX_E_OUT_OF_MEMORY) if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException(); throwOutOfMemoryException();
if (r != UPX_E_OK || new_len != u_len) if (r != UPX_E_OK || new_len != u_len)
@@ -167,10 +167,10 @@ void ElfLinker::init(const void *pdata_v, int plen) {
char *psections = (char *) input + pos; char *psections = (char *) input + pos;
char *psymbols = strstr(psections, "SYMBOL TABLE:\n"); char *psymbols = strstr(psections, "SYMBOL TABLE:\n");
assert(psymbols != NULL); assert(psymbols != nullptr);
char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR "); char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR ");
assert(prelocs != NULL); assert(prelocs != nullptr);
preprocessSections(psections, psymbols); preprocessSections(psections, psymbols);
preprocessSymbols(psymbols, prelocs); preprocessSymbols(psymbols, prelocs);
@@ -183,7 +183,7 @@ void ElfLinker::preprocessSections(char *start, char *end) {
char *nextl; char *nextl;
for (nsections = 0; start < end; start = 1 + nextl) { for (nsections = 0; start < end; start = 1 + nextl) {
nextl = strchr(start, '\n'); nextl = strchr(start, '\n');
assert(nextl != NULL); assert(nextl != nullptr);
*nextl = '\0'; // a record is a line *nextl = '\0'; // a record is a line
unsigned offset, size, align; unsigned offset, size, align;
@@ -197,15 +197,15 @@ void ElfLinker::preprocessSections(char *start, char *end) {
// printf("section %s preprocessed\n", n); // printf("section %s preprocessed\n", n);
} }
} }
addSection("*ABS*", NULL, 0, 0); addSection("*ABS*", nullptr, 0, 0);
addSection("*UND*", NULL, 0, 0); addSection("*UND*", nullptr, 0, 0);
} }
void ElfLinker::preprocessSymbols(char *start, char *end) { void ElfLinker::preprocessSymbols(char *start, char *end) {
char *nextl; char *nextl;
for (nsymbols = 0; start < end; start = 1 + nextl) { for (nsymbols = 0; start < end; start = 1 + nextl) {
nextl = strchr(start, '\n'); nextl = strchr(start, '\n');
assert(nextl != NULL); assert(nextl != nullptr);
*nextl = '\0'; // a record is a line *nextl = '\0'; // a record is a line
unsigned value, offset; unsigned value, offset;
@@ -238,11 +238,11 @@ void ElfLinker::preprocessSymbols(char *start, char *end) {
} }
void ElfLinker::preprocessRelocations(char *start, char *end) { void ElfLinker::preprocessRelocations(char *start, char *end) {
Section *section = NULL; Section *section = nullptr;
char *nextl; char *nextl;
for (nrelocations = 0; start < end; start = 1 + nextl) { for (nrelocations = 0; start < end; start = 1 + nextl) {
nextl = strchr(start, '\n'); nextl = strchr(start, '\n');
assert(nextl != NULL); assert(nextl != nullptr);
*nextl = '\0'; // a record is a line *nextl = '\0'; // a record is a line
{ {
@@ -261,7 +261,7 @@ void ElfLinker::preprocessRelocations(char *start, char *end) {
upx_uint64_t add = 0; upx_uint64_t add = 0;
char *p = strstr(symbol, "+0x"); char *p = strstr(symbol, "+0x");
if (p == NULL) if (p == nullptr)
p = strstr(symbol, "-0x"); p = strstr(symbol, "-0x");
if (p) { if (p) {
char sign = *p; char sign = *p;
@@ -275,7 +275,7 @@ void ElfLinker::preprocessRelocations(char *start, char *end) {
else else
add = a; add = a;
#else #else
char *endptr = NULL; char *endptr = nullptr;
add = strtoull(p, &endptr, 16); add = strtoull(p, &endptr, 16);
assert(endptr && *endptr == '\0'); assert(endptr && *endptr == '\0');
#endif #endif
@@ -298,7 +298,7 @@ ElfLinker::Section *ElfLinker::findSection(const char *name, bool fatal) const {
return sections[ic]; return sections[ic];
if (fatal) if (fatal)
internal_error("unknown section %s\n", name); internal_error("unknown section %s\n", name);
return NULL; return nullptr;
} }
ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const { ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const {
@@ -307,7 +307,7 @@ ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const {
return symbols[ic]; return symbols[ic];
if (fatal) if (fatal)
internal_error("unknown symbol %s\n", name); internal_error("unknown symbol %s\n", name);
return NULL; return nullptr;
} }
ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata, int slen, ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata, int slen,
@@ -320,7 +320,7 @@ ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata,
assert(sname); assert(sname);
assert(sname[0]); assert(sname[0]);
assert(sname[strlen(sname) - 1] != ':'); assert(sname[strlen(sname) - 1] != ':');
assert(findSection(sname, false) == NULL); assert(findSection(sname, false) == nullptr);
Section *sec = new Section(sname, sdata, slen, p2align); Section *sec = new Section(sname, sdata, slen, p2align);
sections[nsections++] = sec; sections[nsections++] = sec;
return sec; return sec;
@@ -331,11 +331,11 @@ ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
// printf("addSymbol: %s %s 0x%x\n", name, section, offset); // printf("addSymbol: %s %s 0x%x\n", name, section, offset);
if (update_capacity(nsymbols, &nsymbols_capacity)) if (update_capacity(nsymbols, &nsymbols_capacity))
symbols = static_cast<Symbol **>(realloc(symbols, nsymbols_capacity * sizeof(Symbol *))); symbols = static_cast<Symbol **>(realloc(symbols, nsymbols_capacity * sizeof(Symbol *)));
assert(symbols != NULL); assert(symbols != nullptr);
assert(name); assert(name);
assert(name[0]); assert(name[0]);
assert(name[strlen(name) - 1] != ':'); assert(name[strlen(name) - 1] != ':');
assert(findSymbol(name, false) == NULL); assert(findSymbol(name, false) == nullptr);
Symbol *sym = new Symbol(name, findSection(section), offset); Symbol *sym = new Symbol(name, findSection(section), offset);
symbols[nsymbols++] = sym; symbols[nsymbols++] = sym;
return sym; return sym;
@@ -346,7 +346,7 @@ ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned of
if (update_capacity(nrelocations, &nrelocations_capacity)) if (update_capacity(nrelocations, &nrelocations_capacity))
relocations = static_cast<Relocation **>( relocations = static_cast<Relocation **>(
realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *))); realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *)));
assert(relocations != NULL); assert(relocations != nullptr);
Relocation *rel = new Relocation(findSection(section), off, type, findSymbol(symbol), add); Relocation *rel = new Relocation(findSection(section), off, type, findSymbol(symbol), add);
relocations[nrelocations++] = rel; relocations[nrelocations++] = rel;
return rel; return rel;
@@ -361,7 +361,7 @@ void ElfLinker::setLoaderAlignOffset(int phase)
#endif #endif
int ElfLinker::addLoader(const char *sname) { int ElfLinker::addLoader(const char *sname) {
assert(sname != NULL); assert(sname != nullptr);
if (!sname[0]) if (!sname[0])
return outputlen; return outputlen;
@@ -420,7 +420,7 @@ int ElfLinker::addLoader(const char *sname) {
} }
void ElfLinker::addLoader(const char *s, va_list ap) { void ElfLinker::addLoader(const char *s, va_list ap) {
while (s != NULL) { while (s != nullptr) {
addLoader(s); addLoader(s);
s = va_arg(ap, const char *); s = va_arg(ap, const char *);
} }
@@ -458,14 +458,14 @@ void ElfLinker::relocate() {
const Relocation *rel = relocations[ic]; const Relocation *rel = relocations[ic];
upx_uint64_t value = 0; upx_uint64_t value = 0;
if (rel->section->output == NULL) if (rel->section->output == nullptr)
continue; continue;
if (strcmp(rel->value->section->name, "*ABS*") == 0) { if (strcmp(rel->value->section->name, "*ABS*") == 0) {
value = rel->value->offset; value = rel->value->offset;
} else if (strcmp(rel->value->section->name, "*UND*") == 0 && } else if (strcmp(rel->value->section->name, "*UND*") == 0 &&
rel->value->offset == 0xdeaddead) rel->value->offset == 0xdeaddead)
internal_error("undefined symbol '%s' referenced\n", rel->value->name); internal_error("undefined symbol '%s' referenced\n", rel->value->name);
else if (rel->value->section->output == NULL) else if (rel->value->section->output == nullptr)
internal_error("can not apply reloc '%s:%x' without section '%s'\n", rel->section->name, internal_error("can not apply reloc '%s:%x' without section '%s'\n", rel->section->name,
rel->offset, rel->value->section->name); rel->offset, rel->value->section->name);
else { else {
@@ -500,7 +500,7 @@ void ElfLinker::defineSymbol(const char *name, upx_uint64_t value) {
// debugging support // debugging support
void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const { void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const {
if ((flags & 1) && symbol->section->output == NULL) if ((flags & 1) && symbol->section->output == nullptr)
return; return;
char d0[16 + 1], d1[16 + 1]; char d0[16 + 1], d1[16 + 1];
upx_snprintf(d0, sizeof(d0), "%016llx", (upx_uint64_t) symbol->offset); upx_snprintf(d0, sizeof(d0), "%016llx", (upx_uint64_t) symbol->offset);
@@ -508,7 +508,7 @@ void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const
fprintf(fp, "%-28s 0x%-16s | %-28s 0x%-16s\n", symbol->name, d0, symbol->section->name, d1); fprintf(fp, "%-28s 0x%-16s | %-28s 0x%-16s\n", symbol->name, d0, symbol->section->name, d1);
} }
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const { void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const {
if (fp == NULL) if (fp == nullptr)
fp = stdout; fp = stdout;
if ((flags & 2) == 0) { if ((flags & 2) == 0) {
// default: dump symbols in used section order // default: dump symbols in used section order
@@ -531,7 +531,7 @@ void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const {
upx_uint64_t ElfLinker::getSymbolOffset(const char *name) const { upx_uint64_t ElfLinker::getSymbolOffset(const char *name) const {
const Symbol *symbol = findSymbol(name); const Symbol *symbol = findSymbol(name);
if (symbol->section->output == NULL) if (symbol->section->output == nullptr)
return 0xdeaddead; return 0xdeaddead;
return symbol->section->offset + symbol->offset; return symbol->section->offset + symbol->offset;
} }
+3 -3
View File
@@ -88,14 +88,14 @@ public:
void __acc_cdecl_va addLoaderVA(const char *s, ...); void __acc_cdecl_va addLoaderVA(const char *s, ...);
#endif #endif
virtual Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align); virtual Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
virtual int getSection(const char *sname, int *slen = NULL) const; virtual int getSection(const char *sname, int *slen = nullptr) const;
virtual int getSectionSize(const char *sname) const; virtual int getSectionSize(const char *sname) const;
virtual upx_byte *getLoader(int *llen = NULL) const; virtual upx_byte *getLoader(int *llen = nullptr) const;
virtual void defineSymbol(const char *name, upx_uint64_t value); virtual void defineSymbol(const char *name, upx_uint64_t value);
virtual upx_uint64_t getSymbolOffset(const char *) const; virtual upx_uint64_t getSymbolOffset(const char *) const;
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const; virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
virtual void dumpSymbols(unsigned flags = 0, FILE *fp = NULL) const; virtual void dumpSymbols(unsigned flags = 0, FILE *fp = nullptr) const;
void alignWithByte(unsigned len, unsigned char b); void alignWithByte(unsigned len, unsigned char b);
virtual void alignCode(unsigned len) { alignWithByte(len, 0); } virtual void alignCode(unsigned len) { alignWithByte(len, 0); }
+173 -171
View File
@@ -280,7 +280,7 @@ static void check_options(int i, int argc)
if (!(opt->cmd == CMD_COMPRESS || opt->cmd == CMD_DECOMPRESS)) if (!(opt->cmd == CMD_COMPRESS || opt->cmd == CMD_DECOMPRESS))
opt->backup = 1; opt->backup = 1;
check_not_both(opt->to_stdout, opt->output_name != NULL, "--stdout", "-o"); check_not_both(opt->to_stdout, opt->output_name != nullptr, "--stdout", "-o");
if (opt->to_stdout && opt->cmd == CMD_COMPRESS) if (opt->to_stdout && opt->cmd == CMD_COMPRESS)
{ {
fprintf(stderr,"%s: cannot use '--stdout' when compressing\n", argv0); fprintf(stderr,"%s: cannot use '--stdout' when compressing\n", argv0);
@@ -393,12 +393,12 @@ char* prepare_shortopts(char *buf, const char *n,
static char vopts[1024]; static char vopts[1024];
if (v > 0 && v < 1024) if (v > 0 && v < 1024)
{ {
if (vopts[v] && strchr(buf,v) == NULL) if (vopts[v] && strchr(buf,v) == nullptr)
printf("warning: duplicate option %d ('%c')!\n", v, v & 127); printf("warning: duplicate option %d ('%c')!\n", v, v & 127);
vopts[v] = 1; vopts[v] = 1;
} }
#endif #endif
if (v > 0 && v < 256 && strchr(buf,v) == NULL) if (v > 0 && v < 256 && strchr(buf,v) == nullptr)
{ {
*o++ = (char) v; *o++ = (char) v;
if ((longopts->has_arg & 0xf) >= 1) if ((longopts->has_arg & 0xf) >= 1)
@@ -439,7 +439,7 @@ static int getoptvar(T *var, const T min_value, const T max_value, const char *a
*var = v; *var = v;
goto done; goto done;
error: error:
if (arg_fatal != NULL) if (arg_fatal != nullptr)
e_optval(arg_fatal); e_optval(arg_fatal);
done: done:
return r; return r;
@@ -889,163 +889,164 @@ static int do_option(int optc, const char *arg)
static int get_options(int argc, char **argv) static int get_options(int argc, char **argv)
{ {
constexpr int *N = nullptr;
static const struct mfx_option longopts[] = static const struct mfx_option longopts[] =
{ {
// commands // commands
{"best", 0x10, 0, 900}, // compress best {"best", 0x10, N, 900}, // compress best
{"brute", 0x10, 0, 901}, // compress best, brute force {"brute", 0x10, N, 901}, // compress best, brute force
{"ultra-brute", 0x10, 0, 902}, // compress best, brute force {"ultra-brute", 0x10, N, 902}, // compress best, brute force
{"decompress", 0, 0, 'd'}, // decompress {"decompress", 0, N, 'd'}, // decompress
{"fast", 0x10, 0, '1'}, // compress faster {"fast", 0x10, N, '1'}, // compress faster
{"fileinfo", 0x10, 0, 909}, // display info about file {"fileinfo", 0x10, N, 909}, // display info about file
{"file-info", 0x10, 0, 909}, // display info about file {"file-info", 0x10, N, 909}, // display info about file
{"help", 0, 0, 'h'+256}, // give help {"help", 0, N, 'h'+256}, // give help
{"license", 0, 0, 'L'}, // display software license {"license", 0, N, 'L'}, // display software license
{"list", 0, 0, 'l'}, // list compressed exe {"list", 0, N, 'l'}, // list compressed exe
{"test", 0, 0, 't'}, // test compressed file integrity {"test", 0, N, 't'}, // test compressed file integrity
{"uncompress", 0, 0, 'd'}, // decompress {"uncompress", 0, N, 'd'}, // decompress
{"version", 0, 0, 'V'+256}, // display version number {"version", 0, N, 'V'+256}, // display version number
// options // options
{"force", 0, 0, 'f'}, // force overwrite of output files {"force", 0, N, 'f'}, // force overwrite of output files
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files {"force-compress", 0, N, 'f'}, // and compression of suspicious files
{"info", 0, 0, 'i'}, // info mode {"info", 0, N, 'i'}, // info mode
{"no-env", 0x10, 0, 519}, // no environment var {"no-env", 0x10, N, 519}, // no environment var
{"no-mode", 0x10, 0, 526}, // do not preserve mode (permissions) {"no-mode", 0x10, N, 526}, // do not preserve mode (permissions)
{"no-owner", 0x10, 0, 527}, // do not preserve ownership {"no-owner", 0x10, N, 527}, // do not preserve ownership
{"no-progress", 0, 0, 516}, // no progress bar {"no-progress", 0, N, 516}, // no progress bar
{"no-time", 0x10, 0, 528}, // do not preserve timestamp {"no-time", 0x10, N, 528}, // do not preserve timestamp
{"output", 0x21, 0, 'o'}, {"output", 0x21, N, 'o'},
{"quiet", 0, 0, 'q'}, // quiet mode {"quiet", 0, N, 'q'}, // quiet mode
{"silent", 0, 0, 'q'}, // quiet mode {"silent", 0, N, 'q'}, // quiet mode
#if 0 #if 0
// FIXME: to_stdout doesn't work because of console code mess // FIXME: to_stdout doesn't work because of console code mess
{"stdout", 0x10, 0, 517}, // write output on standard output {"stdout", 0x10, N, 517}, // write output on standard output
{"to-stdout", 0x10, 0, 517}, // write output on standard output {"to-stdout", 0x10, N, 517}, // write output on standard output
#endif #endif
{"verbose", 0, 0, 'v'}, // verbose mode {"verbose", 0, N, 'v'}, // verbose mode
// debug options // debug options
{"debug", 0x10, 0, 'D'}, {"debug", 0x10, N, 'D'},
{"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging {"dump-stub-loader" ,0x31, N, 544}, // for internal debugging
{"fake-stub-version",0x31, 0, 542}, // for internal debugging {"fake-stub-version",0x31, N, 542}, // for internal debugging
{"fake-stub-year" ,0x31, 0, 543}, // for internal debugging {"fake-stub-year" ,0x31, N, 543}, // for internal debugging
{"disable-random-id",0x10, 0, 545}, // for internal debugging {"disable-random-id",0x10, N, 545}, // for internal debugging
// backup options // backup options
{"backup", 0x10, 0, 'k'}, {"backup", 0x10, N, 'k'},
{"keep", 0x10, 0, 'k'}, {"keep", 0x10, N, 'k'},
{"no-backup", 0x10, 0, 541}, {"no-backup", 0x10, N, 541},
// overlay options // overlay options
{"overlay", 0x31, 0, 551}, // --overlay= {"overlay", 0x31, N, 551}, // --overlay=
{"skip-overlay", 0x10, 0, 552}, {"skip-overlay", 0x10, N, 552},
{"no-overlay", 0x10, 0, 552}, // old name {"no-overlay", 0x10, N, 552}, // old name
{"copy-overlay", 0x10, 0, 553}, {"copy-overlay", 0x10, N, 553},
{"strip-overlay", 0x10, 0, 554}, {"strip-overlay", 0x10, N, 554},
// CPU options // CPU options
{"cpu", 0x31, 0, 560}, // --cpu= {"cpu", 0x31, N, 560}, // --cpu=
{"8086", 0x10, 0, 561}, {"8086", 0x10, N, 561},
{"386", 0x10, 0, 563}, {"386", 0x10, N, 563},
{"486", 0x10, 0, 564}, {"486", 0x10, N, 564},
// color options // color options
{"no-color", 0x10, 0, 512}, {"no-color", 0x10, N, 512},
{"mono", 0x10, 0, 513}, {"mono", 0x10, N, 513},
{"color", 0x10, 0, 514}, {"color", 0x10, N, 514},
// compression method // compression method
{"nrv2b", 0x10, 0, 702}, // --nrv2b {"nrv2b", 0x10, N, 702}, // --nrv2b
{"nrv2d", 0x10, 0, 704}, // --nrv2d {"nrv2d", 0x10, N, 704}, // --nrv2d
{"nrv2e", 0x10, 0, 705}, // --nrv2e {"nrv2e", 0x10, N, 705}, // --nrv2e
{"lzma", 0x10, 0, 721}, // --lzma {"lzma", 0x10, N, 721}, // --lzma
{"no-lzma", 0x10, 0, 722}, // disable all_methods_use_lzma {"no-lzma", 0x10, N, 722}, // disable all_methods_use_lzma
{"prefer-nrv", 0x10, 0, 723}, {"prefer-nrv", 0x10, N, 723},
{"prefer-ucl", 0x10, 0, 724}, {"prefer-ucl", 0x10, N, 724},
// compression settings // compression settings
{"all-filters", 0x10, 0, 523}, {"all-filters", 0x10, N, 523},
{"all-methods", 0x10, 0, 524}, {"all-methods", 0x10, N, 524},
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression {"exact", 0x10, N, 525}, // user requires byte-identical decompression
{"filter", 0x31, 0, 521}, // --filter= {"filter", 0x31, N, 521}, // --filter=
{"no-filter", 0x10, 0, 522}, {"no-filter", 0x10, N, 522},
{"small", 0x10, 0, 520}, {"small", 0x10, N, 520},
// compression runtime parameters // compression runtime parameters
{"crp-nrv-cf", 0x31, 0, 801}, {"crp-nrv-cf", 0x31, N, 801},
{"crp-nrv-sl", 0x31, 0, 802}, {"crp-nrv-sl", 0x31, N, 802},
{"crp-nrv-hl", 0x31, 0, 803}, {"crp-nrv-hl", 0x31, N, 803},
{"crp-nrv-pl", 0x31, 0, 804}, {"crp-nrv-pl", 0x31, N, 804},
{"crp-nrv-mo", 0x31, 0, 805}, {"crp-nrv-mo", 0x31, N, 805},
{"crp-nrv-mm", 0x31, 0, 806}, {"crp-nrv-mm", 0x31, N, 806},
{"crp-nrv-ms", 0x31, 0, 807}, {"crp-nrv-ms", 0x31, N, 807},
{"crp-ucl-cf", 0x31, 0, 801}, {"crp-ucl-cf", 0x31, N, 801},
{"crp-ucl-sl", 0x31, 0, 802}, {"crp-ucl-sl", 0x31, N, 802},
{"crp-ucl-hl", 0x31, 0, 803}, {"crp-ucl-hl", 0x31, N, 803},
{"crp-ucl-pl", 0x31, 0, 804}, {"crp-ucl-pl", 0x31, N, 804},
{"crp-ucl-mo", 0x31, 0, 805}, {"crp-ucl-mo", 0x31, N, 805},
{"crp-ucl-mm", 0x31, 0, 806}, {"crp-ucl-mm", 0x31, N, 806},
{"crp-ucl-ms", 0x31, 0, 807}, {"crp-ucl-ms", 0x31, N, 807},
{"crp-lzma-pb", 0x31, 0, 811}, {"crp-lzma-pb", 0x31, N, 811},
{"crp-lzma-lp", 0x31, 0, 812}, {"crp-lzma-lp", 0x31, N, 812},
{"crp-lzma-lc", 0x31, 0, 813}, {"crp-lzma-lc", 0x31, N, 813},
{"crp-lzma-ds", 0x31, 0, 814}, {"crp-lzma-ds", 0x31, N, 814},
{"crp-lzma-fb", 0x31, 0, 816}, {"crp-lzma-fb", 0x31, N, 816},
{"crp-zlib-ml", 0x31, 0, 821}, {"crp-zlib-ml", 0x31, N, 821},
{"crp-zlib-wb", 0x31, 0, 822}, {"crp-zlib-wb", 0x31, N, 822},
{"crp-zlib-st", 0x31, 0, 823}, {"crp-zlib-st", 0x31, N, 823},
// [deprecated - only for compatibility with UPX 2.0x] // [deprecated - only for compatibility with UPX 2.0x]
{"crp-ms", 0x31, 0, 807}, {"crp-ms", 0x31, N, 807},
// atari/tos // atari/tos
{"split-segments", 0x10, 0, 650}, {"split-segments", 0x10, N, 650},
// djgpp2/coff // djgpp2/coff
{"coff", 0x10, 0, 610}, // produce COFF output {"coff", 0x10, N, 610}, // produce COFF output
// dos/com // dos/com
// dos/exe // dos/exe
//{"force-stub", 0x10, 0, 600}, //{"force-stub", 0x10, 0, 600},
{"no-reloc", 0x10, 0, 601}, // no reloc. record into packer dos/exe {"no-reloc", 0x10, N, 601}, // no reloc. record into packer dos/exe
// dos/sys // dos/sys
// unix // unix
{"blocksize", 0x31, 0, 660}, // --blocksize= {"blocksize", 0x31, N, 660}, // --blocksize=
{"force-execve", 0x10, 0, 661}, // force linux/386 execve format {"force-execve", 0x10, N, 661}, // force linux/386 execve format
{"is_ptinterp", 0x10, 0, 663}, // linux/elf386 PT_INTERP program {"is_ptinterp", 0x10, N, 663}, // linux/elf386 PT_INTERP program
{"use_ptinterp", 0x10, 0, 664}, // linux/elf386 PT_INTERP program {"use_ptinterp", 0x10, N, 664}, // linux/elf386 PT_INTERP program
{"make_ptinterp", 0x10, 0, 665}, // linux/elf386 PT_INTERP program {"make_ptinterp", 0x10, N, 665}, // linux/elf386 PT_INTERP program
{"Linux", 0x10, 0, 666}, {"Linux", 0x10, N, 666},
{"linux", 0x10, 0, 666}, {"linux", 0x10, N, 666},
{"FreeBSD", 0x10, 0, 667}, {"FreeBSD", 0x10, N, 667},
{"freebsd", 0x10, 0, 667}, {"freebsd", 0x10, N, 667},
{"NetBSD", 0x10, 0, 668}, {"NetBSD", 0x10, N, 668},
{"netbsd", 0x10, 0, 668}, {"netbsd", 0x10, N, 668},
{"OpenBSD", 0x10, 0, 669}, {"OpenBSD", 0x10, N, 669},
{"openbsd", 0x10, 0, 669}, {"openbsd", 0x10, N, 669},
{"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes {"unmap-all-pages", 0x10, N, 674}, // linux /proc/self/exe vanishes
{"preserve-build-id", 0, 0, 675}, {"preserve-build-id", 0, N, 675},
{"android-shlib", 0, 0, 676}, {"android-shlib", 0, N, 676},
{"force-pie", 0, 0, 677}, {"force-pie", 0, N, 677},
// watcom/le // watcom/le
{"le", 0x10, 0, 620}, // produce LE output {"le", 0x10, N, 620}, // produce LE output
// win32/pe // win32/pe
{"compress-exports", 2, 0, 630}, {"compress-exports", 2, N, 630},
{"compress-icons", 2, 0, 631}, {"compress-icons", 2, N, 631},
{"compress-resources", 2, 0, 632}, {"compress-resources", 2, N, 632},
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED {"strip-loadconf", 0x12, N, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634}, {"strip-relocs", 0x12, N, 634},
{"keep-resource", 0x31, 0, 635}, {"keep-resource", 0x31, N, 635},
// ps1/exe // ps1/exe
{"boot-only", 0x10, 0, 670}, {"boot-only", 0x10, N, 670},
{"no-align", 0x10, 0, 671}, {"no-align", 0x10, N, 671},
{"8-bit", 0x10, 0, 672}, {"8-bit", 0x10, N, 672},
{"8mib-ram", 0x10, 0, 673}, {"8mib-ram", 0x10, N, 673},
{"8mb-ram", 0x10, 0, 673}, {"8mb-ram", 0x10, N, 673},
// mp (meta) options // mp (meta) options
{"mp-compress-task", 0x31, 0, 501}, {"mp-compress-task", 0x31, N, 501},
{"mp-query-format", 0x10, 0, 502}, {"mp-query-format", 0x10, N, 502},
{"mp-query-num-tasks", 0x10, 0, 503}, {"mp-query-num-tasks", 0x10, N, 503},
{ NULL, 0, NULL, 0 } { nullptr, 0, nullptr, 0 }
}; };
int optc, longind; int optc, longind;
@@ -1069,88 +1070,89 @@ static const struct mfx_option longopts[] =
#if defined(OPTIONS_VAR) #if defined(OPTIONS_VAR)
static void get_envoptions(int argc, char **argv) static void get_envoptions(int argc, char **argv)
{ {
constexpr int *N = nullptr;
/* only some options are allowed in the environment variable */ /* only some options are allowed in the environment variable */
static const struct mfx_option longopts[] = static const struct mfx_option longopts[] =
{ {
// commands // commands
{"best", 0x10, 0, 900}, // compress best {"best", 0x10, N, 900}, // compress best
{"brute", 0x10, 0, 901}, // compress best, brute force {"brute", 0x10, N, 901}, // compress best, brute force
{"ultra-brute", 0x10, 0, 902}, // compress best, brute force {"ultra-brute", 0x10, N, 902}, // compress best, brute force
{"fast", 0x10, 0, '1'}, // compress faster {"fast", 0x10, N, '1'}, // compress faster
// options // options
{"info", 0, 0, 'i'}, // info mode {"info", 0, N, 'i'}, // info mode
{"no-progress", 0, 0, 516}, // no progress bar {"no-progress", 0, N, 516}, // no progress bar
{"quiet", 0, 0, 'q'}, // quiet mode {"quiet", 0, N, 'q'}, // quiet mode
{"silent", 0, 0, 'q'}, // quiet mode {"silent", 0, N, 'q'}, // quiet mode
{"verbose", 0, 0, 'v'}, // verbose mode {"verbose", 0, N, 'v'}, // verbose mode
// debug options // debug options
{"disable-random-id",0x10, 0, 545}, // for internal debugging {"disable-random-id",0x10, N, 545}, // for internal debugging
// backup options // backup options
{"backup", 0x10, 0, 'k'}, {"backup", 0x10, N, 'k'},
{"keep", 0x10, 0, 'k'}, {"keep", 0x10, N, 'k'},
{"no-backup", 0x10, 0, 541}, {"no-backup", 0x10, N, 541},
// overlay options // overlay options
{"overlay", 0x31, 0, 551}, // --overlay= {"overlay", 0x31, N, 551}, // --overlay=
{"skip-overlay", 0x10, 0, 552}, {"skip-overlay", 0x10, N, 552},
{"no-overlay", 0x10, 0, 552}, // old name {"no-overlay", 0x10, N, 552}, // old name
{"copy-overlay", 0x10, 0, 553}, {"copy-overlay", 0x10, N, 553},
{"strip-overlay", 0x10, 0, 554}, {"strip-overlay", 0x10, N, 554},
// CPU options // CPU options
{"cpu", 0x31, 0, 560}, // --cpu= {"cpu", 0x31, N, 560}, // --cpu=
{"8086", 0x10, 0, 561}, {"8086", 0x10, N, 561},
{"386", 0x10, 0, 563}, {"386", 0x10, N, 563},
{"486", 0x10, 0, 564}, {"486", 0x10, N, 564},
// color options // color options
{"no-color", 0x10, 0, 512}, {"no-color", 0x10, N, 512},
{"mono", 0x10, 0, 513}, {"mono", 0x10, N, 513},
{"color", 0x10, 0, 514}, {"color", 0x10, N, 514},
// compression settings // compression settings
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression {"exact", 0x10, N, 525}, // user requires byte-identical decompression
// compression method // compression method
{"nrv2b", 0x10, 0, 702}, // --nrv2b {"nrv2b", 0x10, N, 702}, // --nrv2b
{"nrv2d", 0x10, 0, 704}, // --nrv2d {"nrv2d", 0x10, N, 704}, // --nrv2d
{"nrv2e", 0x10, 0, 705}, // --nrv2e {"nrv2e", 0x10, N, 705}, // --nrv2e
{"lzma", 0x10, 0, 721}, // --lzma {"lzma", 0x10, N, 721}, // --lzma
{"no-lzma", 0x10, 0, 722}, // disable all_methods_use_lzma {"no-lzma", 0x10, N, 722}, // disable all_methods_use_lzma
{"prefer-nrv", 0x10, 0, 723}, {"prefer-nrv", 0x10, N, 723},
{"prefer-ucl", 0x10, 0, 724}, {"prefer-ucl", 0x10, N, 724},
// compression settings // compression settings
// compression runtime parameters // compression runtime parameters
// win32/pe // win32/pe
{"compress-exports", 2, 0, 630}, {"compress-exports", 2, N, 630},
{"compress-icons", 2, 0, 631}, {"compress-icons", 2, N, 631},
{"compress-resources", 2, 0, 632}, {"compress-resources", 2, N, 632},
{"strip-loadconf", 0x12, 0, 633}, // OBSOLETE - IGNORED {"strip-loadconf", 0x12, N, 633}, // OBSOLETE - IGNORED
{"strip-relocs", 0x12, 0, 634}, {"strip-relocs", 0x12, N, 634},
{"keep-resource", 0x31, 0, 635}, {"keep-resource", 0x31, N, 635},
{ NULL, 0, NULL, 0 } { nullptr, 0, nullptr, 0 }
}; };
char *env, *p; char *env, *p;
const char *var; const char *var;
int i, optc, longind; int i, optc, longind;
int targc; int targc;
char **targv = NULL; char **targv = nullptr;
static const char sep[] = " \t"; static const char sep[] = " \t";
char shortopts[256]; char shortopts[256];
var = getenv(OPTIONS_VAR); var = getenv(OPTIONS_VAR);
if (var == NULL || !var[0]) if (var == nullptr || !var[0])
return; return;
env = strdup(var); env = strdup(var);
if (env == NULL) if (env == nullptr)
return; return;
/* count arguments */ /* count arguments */
@@ -1171,7 +1173,7 @@ static const struct mfx_option longopts[] =
/* alloc temp argv */ /* alloc temp argv */
if (targc > 1) if (targc > 1)
targv = (char **) calloc(targc+1,sizeof(char *)); targv = (char **) calloc(targc+1,sizeof(char *));
if (targv == NULL) if (targv == nullptr)
{ {
free(env); free(env);
return; return;
@@ -1192,7 +1194,7 @@ static const struct mfx_option longopts[] =
break; break;
*p++ = '\0'; *p++ = '\0';
} }
targv[targc] = NULL; targv[targc] = nullptr;
/* check that only options are in temp argv */ /* check that only options are in temp argv */
for (i = 1; i < targc; i++) for (i = 1; i < targc; i++)
@@ -1207,7 +1209,7 @@ static const struct mfx_option longopts[] =
while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0) while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
{ {
if (do_option(optc, targv[mfx_optind-1]) != 0) if (do_option(optc, targv[mfx_optind-1]) != 0)
e_envopt(NULL); e_envopt(nullptr);
} }
if (mfx_optind < targc) if (mfx_optind < targc)
@@ -1472,7 +1474,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
assert(upx_nrv_init() == 0); assert(upx_nrv_init() == 0);
#endif #endif
//srand((int) time(NULL)); //srand((int) time(nullptr));
srand((int) clock()); srand((int) clock());
/* get options */ /* get options */
@@ -1484,7 +1486,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
i = get_options(argc,argv); i = get_options(argc,argv);
assert(i <= argc); assert(i <= argc);
set_term(NULL); set_term(nullptr);
// cmdline_cmd = opt->cmd; // cmdline_cmd = opt->cmd;
switch (opt->cmd) switch (opt->cmd)
{ {
+4 -4
View File
@@ -62,7 +62,7 @@ __acc_static_forceinline bool use_simple_mcheck() { return true; }
**************************************************************************/ **************************************************************************/
MemBuffer::MemBuffer(upx_uint64_t size) : MemBuffer::MemBuffer(upx_uint64_t size) :
b(NULL), b_size(0) b(nullptr), b_size(0)
{ {
alloc(size); alloc(size);
} }
@@ -87,7 +87,7 @@ unsigned char *MemBuffer::subref(char const *errfmt, unsigned skip, unsigned tak
void MemBuffer::dealloc() void MemBuffer::dealloc()
{ {
if (b != NULL) if (b != nullptr)
{ {
checkState(); checkState();
if (use_simple_mcheck()) if (use_simple_mcheck())
@@ -102,7 +102,7 @@ void MemBuffer::dealloc()
} }
else else
::free(b); ::free(b);
b = NULL; b = nullptr;
b_size = 0; b_size = 0;
} }
else else
@@ -186,7 +186,7 @@ void MemBuffer::checkState() const
void MemBuffer::alloc(upx_uint64_t size) void MemBuffer::alloc(upx_uint64_t size)
{ {
// NOTE: we don't automatically free a used buffer // NOTE: we don't automatically free a used buffer
assert(b == NULL); assert(b == nullptr);
assert(b_size == 0); assert(b_size == 0);
// //
assert(size > 0); assert(size > 0);
+3 -3
View File
@@ -37,7 +37,7 @@
class MemBuffer class MemBuffer
{ {
public: public:
MemBuffer() : b(NULL), b_size(0) { } MemBuffer() : b(nullptr), b_size(0) { }
explicit MemBuffer(upx_uint64_t size); explicit MemBuffer(upx_uint64_t size);
~MemBuffer(); ~MemBuffer();
@@ -76,8 +76,8 @@ private:
static unsigned global_alloc_counter; static unsigned global_alloc_counter;
// disable copy and assignment // disable copy and assignment
MemBuffer(const MemBuffer &); // {} MemBuffer(const MemBuffer &) = delete;
MemBuffer& operator= (const MemBuffer &); // { return *this; } MemBuffer& operator= (const MemBuffer &) = delete;
// disable dynamic allocation // disable dynamic allocation
DISABLE_NEW_DELETE DISABLE_NEW_DELETE
+12 -12
View File
@@ -4812,13 +4812,13 @@ typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED 1 #define _WCHAR_T_DEFINED 1
#endif #endif
#endif #endif
#ifndef NULL #ifndef nullptr
#if defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ >= 4) #if defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ >= 4)
#define NULL __null #define nullptr __null
#elif defined(__cplusplus) #elif defined(__cplusplus)
#define NULL 0 #define nullptr 0
#else #else
#define NULL ((void*)0) #define nullptr ((void*)0)
#endif #endif
#endif #endif
#ifndef offsetof #ifndef offsetof
@@ -6756,7 +6756,7 @@ static int __ACCLIB_FUNCNAME(acc_getopt_perror) (acc_getopt_p g, int ret, const
g->opterr(g, f, &s); g->opterr(g, f, &s);
va_end(s.ap); va_end(s.ap);
#else #else
g->opterr(g, f, NULL); g->opterr(g, f, nullptr);
#endif #endif
} }
++g->errcount; ++g->errcount;
@@ -6777,7 +6777,7 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g,
if (*shortopts == ':') if (*shortopts == ':')
missing_arg_ret = *shortopts++; missing_arg_ret = *shortopts++;
} }
g->optarg = NULL; g->optarg = nullptr;
if (g->optopt == -1) if (g->optopt == -1)
g->optopt = g->bad_option; g->optopt = g->bad_option;
if (longind) if (longind)
@@ -6801,8 +6801,8 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g,
if (a[0] == '-' && a[1] == '-') { if (a[0] == '-' && a[1] == '-') {
size_t l = 0; size_t l = 0;
const acc_getopt_longopt_p o; const acc_getopt_longopt_p o;
const acc_getopt_longopt_p o1 = NULL; const acc_getopt_longopt_p o1 = nullptr;
const acc_getopt_longopt_p o2 = NULL; const acc_getopt_longopt_p o2 = nullptr;
int need_exact = 0; int need_exact = 0;
++g->optind; ++g->optind;
if (!a[2]) if (!a[2])
@@ -6864,7 +6864,7 @@ ACCLIB_PUBLIC(int, acc_getopt) (acc_getopt_p g,
const char *s; const char *s;
acc_label_next_shortopt: acc_label_next_shortopt:
a = g->argv[g->optind] + ++g->shortpos; a = g->argv[g->optind] + ++g->shortpos;
c = (unsigned char) *a++; s = NULL; c = (unsigned char) *a++; s = nullptr;
if (c != ':' && shortopts) if (c != ':' && shortopts)
s = strchr(shortopts, c); s = strchr(shortopts, c);
if (!s || s[1] != ':') { if (!s || s[1] != ':') {
@@ -7235,7 +7235,7 @@ static int acc_pclock_read_clock_gettime_r_syscall(acc_pclock_handle_p h, acc_pc
static int acc_pclock_read_gettimeofday(acc_pclock_handle_p h, acc_pclock_p c) static int acc_pclock_read_gettimeofday(acc_pclock_handle_p h, acc_pclock_p c)
{ {
struct timeval tv; struct timeval tv;
if (gettimeofday(&tv, NULL) != 0) if (gettimeofday(&tv, nullptr) != 0)
return -1; return -1;
#if defined(acc_int64l_t) #if defined(acc_int64l_t)
c->tv_sec = tv.tv_sec; c->tv_sec = tv.tv_sec;
@@ -7428,7 +7428,7 @@ ACCLIB_PUBLIC(int, acc_pclock_open) (acc_pclock_handle_p h, int mode)
h->h = ACC_STATIC_CAST(acclib_handle_t, 0); h->h = ACC_STATIC_CAST(acclib_handle_t, 0);
h->mode = -1; h->mode = -1;
h->read_error = 2; h->read_error = 2;
h->name = NULL; h->name = nullptr;
h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, 0); h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, 0);
#if defined(acc_int64l_t) #if defined(acc_int64l_t)
h->ticks_base = 0; h->ticks_base = 0;
@@ -7556,7 +7556,7 @@ ACCLIB_PUBLIC(int, acc_pclock_close) (acc_pclock_handle_p h)
{ {
h->h = ACC_STATIC_CAST(acclib_handle_t, 0); h->h = ACC_STATIC_CAST(acclib_handle_t, 0);
h->mode = -1; h->mode = -1;
h->name = NULL; h->name = nullptr;
h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, 0); h->gettime = ACC_STATIC_CAST(acc_pclock_gettime_t, 0);
return 0; return 0;
} }
+1 -1
View File
@@ -55,7 +55,7 @@ void printClearLine(FILE *f)
} }
fflush(stdout); fflush(stderr); fflush(stdout); fflush(stderr);
if (f == NULL) if (f == nullptr)
f = stdout; f = stdout;
con_fprintf(f, "%s", clear_line_msg); con_fprintf(f, "%s", clear_line_msg);
fflush(f); fflush(f);
+16 -16
View File
@@ -145,38 +145,38 @@ void PackArmPe::buildLoader(const Filter *ft)
initLoader(loader, size); initLoader(loader, size);
if (isdll) if (isdll)
addLoader("DllStart", NULL); addLoader("DllStart", nullptr);
addLoader("ExeStart", NULL); addLoader("ExeStart", nullptr);
if (ph.method == M_NRV2E_8) if (ph.method == M_NRV2E_8)
addLoader("Call2E", NULL); addLoader("Call2E", nullptr);
else if (ph.method == M_NRV2B_8) else if (ph.method == M_NRV2B_8)
addLoader("Call2B", NULL); addLoader("Call2B", nullptr);
else if (ph.method == M_NRV2D_8) else if (ph.method == M_NRV2D_8)
addLoader("Call2D", NULL); addLoader("Call2D", nullptr);
else if (M_IS_LZMA(ph.method)) else if (M_IS_LZMA(ph.method))
addLoader("+40C,CallLZMA", NULL); addLoader("+40C,CallLZMA", nullptr);
if (ft->id == 0x50) if (ft->id == 0x50)
addLoader("+40C,Unfilter_0x50", NULL); addLoader("+40C,Unfilter_0x50", nullptr);
if (sorelocs) if (sorelocs)
addLoader("+40C,Relocs", NULL); addLoader("+40C,Relocs", nullptr);
addLoader("+40C,Imports", NULL); addLoader("+40C,Imports", nullptr);
addLoader("ProcessEnd", NULL); addLoader("ProcessEnd", nullptr);
if (ph.method == M_NRV2E_8) if (ph.method == M_NRV2E_8)
addLoader(".ucl_nrv2e_decompress_8", NULL); addLoader(".ucl_nrv2e_decompress_8", nullptr);
else if (ph.method == M_NRV2B_8) else if (ph.method == M_NRV2B_8)
addLoader(".ucl_nrv2b_decompress_8", NULL); addLoader(".ucl_nrv2b_decompress_8", nullptr);
else if (ph.method == M_NRV2D_8) else if (ph.method == M_NRV2D_8)
addLoader(".ucl_nrv2d_decompress_8", NULL); addLoader(".ucl_nrv2d_decompress_8", nullptr);
else if (M_IS_LZMA(ph.method)) else if (M_IS_LZMA(ph.method))
addLoader("+40C,LZMA_DECODE,LZMA_DEC10", NULL); addLoader("+40C,LZMA_DECODE,LZMA_DEC10", nullptr);
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
bool PackArmPe::handleForceOption() bool PackArmPe::handleForceOption()
@@ -197,7 +197,7 @@ void PackArmPe::callCompressWithFilters(Filter &ft, int filter_strategy, unsigne
upx_compress_config_t cconf; cconf.reset(); upx_compress_config_t cconf; cconf.reset();
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
compressWithFilters(&ft, 2048, &cconf, filter_strategy, compressWithFilters(&ft, 2048, &cconf, filter_strategy,
ih_codebase, rvamin, 0, NULL, 0); ih_codebase, rvamin, 0, nullptr, 0);
} }
void PackArmPe::addNewRelocations(Reloc &rel, unsigned upxsection) void PackArmPe::addNewRelocations(Reloc &rel, unsigned upxsection)
+3 -3
View File
@@ -143,7 +143,7 @@ void PackCom::buildLoader(const Filter *ft)
"NRVDECO1", "NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00", ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2", "NRVDECO2",
NULL nullptr
); );
if (ft->id) if (ft->id)
{ {
@@ -164,7 +164,7 @@ void PackCom::addFilter16(int filter_id)
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286,CT16SUB0"), filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I086" : "CT16I286,CT16SUB0"),
"CALLTRI2", "CALLTRI2",
getFormat() == UPX_F_DOS_COM ? "CORETURN" : "", getFormat() == UPX_F_DOS_COM ? "CORETURN" : "",
NULL nullptr
); );
else else
addLoader(filter_id%3 == 1 ? "CT16E800" : "CT16E900", addLoader(filter_id%3 == 1 ? "CT16E800" : "CT16E900",
@@ -173,7 +173,7 @@ void PackCom::addFilter16(int filter_id)
filter_id < 4 ? "CT16SUB1" : "", filter_id < 4 ? "CT16SUB1" : "",
filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287,CT16SUB1"), filter_id < 4 ? "" : (opt->cpu == opt->CPU_8086 ? "CT16I087" : "CT16I287,CT16SUB1"),
"CALLTRI6", "CALLTRI6",
NULL nullptr
); );
} }
+3 -3
View File
@@ -103,15 +103,15 @@ void PackDjgpp2::buildLoader(const Filter *ft)
getDecompressorSections(), getDecompressorSections(),
M_IS_LZMA(ph.method) ? "LZMA_DONE_STACK" : "", M_IS_LZMA(ph.method) ? "LZMA_DONE_STACK" : "",
"DJ2BSS00", "DJ2BSS00",
NULL nullptr
); );
if (ft->id) if (ft->id)
{ {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("DJCALLT2", NULL); addLoader("DJCALLT2", nullptr);
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("DJRETURN,+40C,UPX1HEAD", NULL); addLoader("DJRETURN,+40C,UPX1HEAD", nullptr);
} }
+15 -15
View File
@@ -72,7 +72,7 @@ const int *PackExe::getCompressionMethods(int method, int level) const
const int *PackExe::getFilters() const const int *PackExe::getFilters() const
{ {
return NULL; return nullptr;
} }
@@ -119,7 +119,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
void PackExe::addLoaderEpilogue(int flag) void PackExe::addLoaderEpilogue(int flag)
{ {
addLoader("EXEMAIN5", NULL); addLoader("EXEMAIN5", nullptr);
if (relocsize) if (relocsize)
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS", addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
"EXERELO1", "EXERELO1",
@@ -127,19 +127,19 @@ void PackExe::addLoaderEpilogue(int flag)
"EXERELO2", "EXERELO2",
ih_exesize > 0xFE00 ? "EXEREBIG" : "", ih_exesize > 0xFE00 ? "EXEREBIG" : "",
"EXERELO3", "EXERELO3",
NULL nullptr
); );
addLoader("EXEMAIN8", addLoader("EXEMAIN8",
device_driver ? "DEVICEEND" : "", device_driver ? "DEVICEEND" : "",
(flag & SS) ? "EXESTACK" : "", (flag & SS) ? "EXESTACK" : "",
(flag & SP) ? "EXESTASP" : "", (flag & SP) ? "EXESTASP" : "",
(flag & USEJUMP) ? "EXEJUMPF" : "", (flag & USEJUMP) ? "EXEJUMPF" : "",
NULL nullptr
); );
if (!(flag & USEJUMP)) if (!(flag & USEJUMP))
addLoader(ih.cs ? "EXERCSPO" : "", addLoader(ih.cs ? "EXERCSPO" : "",
"EXERETIP", "EXERETIP",
NULL nullptr
); );
linker->defineSymbol("original_cs", ih.cs); linker->defineSymbol("original_cs", ih.cs);
@@ -167,7 +167,7 @@ void PackExe::buildLoader(const Filter *)
use_clear_dirty_stack ? "LZMA_DEC31" : "", use_clear_dirty_stack ? "LZMA_DEC31" : "",
"LZMA_DEC32", "LZMA_DEC32",
ph.u_len > 0xffff ? "LZMA_DEC33" : "", ph.u_len > 0xffff ? "LZMA_DEC33" : "",
NULL nullptr
); );
addLoaderEpilogue(flag); addLoaderEpilogue(flag);
@@ -196,7 +196,7 @@ void PackExe::buildLoader(const Filter *)
compressed_lzma.allocForCompression(lsize); compressed_lzma.allocForCompression(lsize);
unsigned c_len_lzma = MemBuffer::getSizeForCompression(lsize); unsigned c_len_lzma = MemBuffer::getSizeForCompression(lsize);
int r = upx_compress(loader, lsize, compressed_lzma, &c_len_lzma, int r = upx_compress(loader, lsize, compressed_lzma, &c_len_lzma,
NULL, M_NRV2B_LE16, 9, NULL, NULL); nullptr, M_NRV2B_LE16, 9, nullptr, nullptr);
assert(r == UPX_E_OK); assert(c_len_lzma < lsize); assert(r == UPX_E_OK); assert(c_len_lzma < lsize);
info("lzma+relocator code compressed: %u -> %u", lsize, c_len_lzma); info("lzma+relocator code compressed: %u -> %u", lsize, c_len_lzma);
@@ -204,15 +204,15 @@ void PackExe::buildLoader(const Filter *)
initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe)); initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe));
// prepare loader // prepare loader
if (device_driver) if (device_driver)
addLoader("DEVICEENTRY,LZMADEVICE,DEVICEENTRY2", NULL); addLoader("DEVICEENTRY,LZMADEVICE,DEVICEENTRY2", nullptr);
linker->addSection("COMPRESSED_LZMA", compressed_lzma, c_len_lzma, 0); linker->addSection("COMPRESSED_LZMA", compressed_lzma, c_len_lzma, 0);
addLoader("LZMAENTRY,NRV2B160,NRVDDONE,NRVDECO1,NRVGTD00,NRVDECO2", addLoader("LZMAENTRY,NRV2B160,NRVDDONE,NRVDECO1,NRVGTD00,NRVDECO2",
NULL); nullptr);
} }
else if (device_driver) else if (device_driver)
addLoader("DEVICEENTRY,DEVICEENTRY2", NULL); addLoader("DEVICEENTRY,DEVICEENTRY2", nullptr);
addLoader("EXEENTRY", addLoader("EXEENTRY",
M_IS_LZMA(ph.method) && device_driver ? "LONGSUB" : "SHORTSUB", M_IS_LZMA(ph.method) && device_driver ? "LONGSUB" : "SHORTSUB",
@@ -223,7 +223,7 @@ void PackExe::buildLoader(const Filter *)
"EXEMAIN4C", "EXEMAIN4C",
M_IS_LZMA(ph.method) ? "COMPRESSED_LZMA_START,COMPRESSED_LZMA" : "", M_IS_LZMA(ph.method) ? "COMPRESSED_LZMA_START,COMPRESSED_LZMA" : "",
"+G5DXXXX,UPX1HEAD,EXECUTPO", "+G5DXXXX,UPX1HEAD,EXECUTPO",
NULL nullptr
); );
if (ph.method == M_NRV2B_8) if (ph.method == M_NRV2B_8)
addLoader("NRV2B16S", // decompressor addLoader("NRV2B16S", // decompressor
@@ -235,7 +235,7 @@ void PackExe::buildLoader(const Filter *)
"NRV2BEX3", "NRV2BEX3",
ph.c_len > 0xffff ? "N2B64K02" : "", ph.c_len > 0xffff ? "N2B64K02" : "",
"NRV2BEX9", "NRV2BEX9",
NULL nullptr
); );
else if (ph.method == M_NRV2D_8) else if (ph.method == M_NRV2D_8)
addLoader("NRV2D16S", addLoader("NRV2D16S",
@@ -247,7 +247,7 @@ void PackExe::buildLoader(const Filter *)
"NRV2DEX3", "NRV2DEX3",
ph.c_len > 0xffff ? "N2D64K02" : "", ph.c_len > 0xffff ? "N2D64K02" : "",
"NRV2DEX9", "NRV2DEX9",
NULL nullptr
); );
else if (ph.method == M_NRV2E_8) else if (ph.method == M_NRV2E_8)
addLoader("NRV2E16S", addLoader("NRV2E16S",
@@ -259,7 +259,7 @@ void PackExe::buildLoader(const Filter *)
"NRV2EEX3", "NRV2EEX3",
ph.c_len > 0xffff ? "N2E64K02" : "", ph.c_len > 0xffff ? "N2E64K02" : "",
"NRV2EEX9", "NRV2EEX9",
NULL nullptr
); );
else if M_IS_LZMA(ph.method) else if M_IS_LZMA(ph.method)
return; return;
@@ -495,7 +495,7 @@ void PackExe::pack(OutputFile *fo)
upx_byte out[9*relocsize/8+1024]; upx_byte out[9*relocsize/8+1024];
unsigned in_len = relocsize; unsigned in_len = relocsize;
unsigned out_len = 0; unsigned out_len = 0;
ucl_nrv2b_99_compress(w, in_len, out, &out_len, NULL, 9, NULL, NULL); ucl_nrv2b_99_compress(w, in_len, out, &out_len, nullptr, 9, nullptr, nullptr);
printf("reloc compress: %d -> %d\n", in_len, out_len); printf("reloc compress: %d -> %d\n", in_len, out_len);
#endif #endif
} }
+97 -97
View File
@@ -120,7 +120,7 @@ funpad4(InputFile *fi)
static void alloc_file_image(MemBuffer &mb, off_t size) static void alloc_file_image(MemBuffer &mb, off_t size)
{ {
assert(mem_size_valid_bytes(size)); assert(mem_size_valid_bytes(size));
if (mb.getVoidPtr() == NULL) { if (mb.getVoidPtr() == nullptr) {
mb.alloc(size); mb.alloc(size);
} else { } else {
assert((u32_t)size <= mb.getSize()); assert((u32_t)size <= mb.getSize());
@@ -225,13 +225,13 @@ PackLinuxElf64::checkEhdr(Elf64_Ehdr const *ehdr) const
} }
PackLinuxElf::PackLinuxElf(InputFile *f) PackLinuxElf::PackLinuxElf(InputFile *f)
: super(f), e_phnum(0), dynstr(NULL), : super(f), e_phnum(0), dynstr(nullptr),
sz_phdrs(0), sz_elf_hdrs(0), sz_pack2(0), sz_pack2a(0), sz_phdrs(0), sz_elf_hdrs(0), sz_pack2(0), sz_pack2a(0),
lg2_page(12), page_size(1u<<lg2_page), is_pie(0), lg2_page(12), page_size(1u<<lg2_page), is_pie(0),
xct_off(0), xct_va(0), jni_onload_va(0), xct_off(0), xct_va(0), jni_onload_va(0),
user_init_va(0), user_init_off(0), user_init_va(0), user_init_off(0),
e_machine(0), ei_class(0), ei_data(0), ei_osabi(0), osabi_note(NULL), e_machine(0), ei_class(0), ei_data(0), ei_osabi(0), osabi_note(nullptr),
shstrtab(NULL), shstrtab(nullptr),
o_elf_shnum(0) o_elf_shnum(0)
{ {
memset(dt_table, 0, sizeof(dt_table)); memset(dt_table, 0, sizeof(dt_table));
@@ -293,7 +293,7 @@ PackLinuxElf32::PackLinuxElf32help1(InputFile *f)
phdri= (Elf32_Phdr *)(e_phoff + file_image); // do not free() !! phdri= (Elf32_Phdr *)(e_phoff + file_image); // do not free() !!
shdri= (Elf32_Shdr *)(e_shoff + file_image); // do not free() !! shdri= (Elf32_Shdr *)(e_shoff + file_image); // do not free() !!
if (opt->cmd != CMD_COMPRESS) { if (opt->cmd != CMD_COMPRESS) {
shdri = NULL; shdri = nullptr;
} }
sec_dynsym = elf_find_section_type(Elf32_Shdr::SHT_DYNSYM); sec_dynsym = elf_find_section_type(Elf32_Shdr::SHT_DYNSYM);
if (sec_dynsym) { if (sec_dynsym) {
@@ -409,7 +409,7 @@ off_t PackLinuxElf32::pack3(OutputFile *fo, Filter &ft)
if (x.size) { if (x.size) {
x.offset = get_te32(&phdri[k].p_offset) + x.offset = get_te32(&phdri[k].p_offset) +
get_te32(&phdri[k].p_filesz); get_te32(&phdri[k].p_filesz);
packExtent(x, total_in, total_out, 0, fo); packExtent(x, total_in, total_out, nullptr, fo);
} }
} }
// write block end marker (uncompressed size 0) // write block end marker (uncompressed size 0)
@@ -533,7 +533,7 @@ off_t PackLinuxElf64::pack3(OutputFile *fo, Filter &ft)
if (x.size) { if (x.size) {
x.offset = get_te64(&phdri[k].p_offset) + x.offset = get_te64(&phdri[k].p_offset) +
get_te64(&phdri[k].p_filesz); get_te64(&phdri[k].p_filesz);
packExtent(x, total_in, total_out, 0, fo); packExtent(x, total_in, total_out, nullptr, fo);
} }
} }
// write block end marker (uncompressed size 0) // write block end marker (uncompressed size 0)
@@ -651,38 +651,38 @@ off_t PackLinuxElf64::pack3(OutputFile *fo, Filter &ft)
void void
PackLinuxElf::addStubEntrySections(Filter const *) PackLinuxElf::addStubEntrySections(Filter const *)
{ {
addLoader("ELFMAINX", NULL); addLoader("ELFMAINX", nullptr);
if (hasLoaderSection("ELFMAINXu")) { if (hasLoaderSection("ELFMAINXu")) {
// brk() trouble if static // brk() trouble if static
addLoader("ELFMAINXu", NULL); addLoader("ELFMAINXu", nullptr);
} }
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("ELFMAINY,IDENTSTR", NULL); addLoader("ELFMAINY,IDENTSTR", nullptr);
if (hasLoaderSection("ELFMAINZe")) { // ppc64 big-endian only if (hasLoaderSection("ELFMAINZe")) { // ppc64 big-endian only
addLoader("ELFMAINZe", NULL); addLoader("ELFMAINZe", nullptr);
} }
addLoader("+40,ELFMAINZ", NULL); addLoader("+40,ELFMAINZ", nullptr);
if (hasLoaderSection("ANDMAJNZ")) { // Android trouble with args to DT_INIT if (hasLoaderSection("ANDMAJNZ")) { // Android trouble with args to DT_INIT
if (opt->o_unix.android_shlib) { if (opt->o_unix.android_shlib) {
addLoader("ANDMAJNZ", NULL); // constant PAGE_SIZE addLoader("ANDMAJNZ", nullptr); // constant PAGE_SIZE
} }
else { else {
addLoader("ELFMAJNZ", NULL); // PAGE_SIZE from AT_PAGESZ addLoader("ELFMAJNZ", nullptr); // PAGE_SIZE from AT_PAGESZ
} }
addLoader("ELFMAKNZ", NULL); addLoader("ELFMAKNZ", nullptr);
} }
if (hasLoaderSection("ELFMAINZu")) { if (hasLoaderSection("ELFMAINZu")) {
addLoader("ELFMAINZu", NULL); addLoader("ELFMAINZu", nullptr);
} }
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", nullptr);
} }
@@ -702,12 +702,12 @@ void PackLinuxElf64::defineSymbols(Filter const *ft)
} }
PackLinuxElf32::PackLinuxElf32(InputFile *f) PackLinuxElf32::PackLinuxElf32(InputFile *f)
: super(f), phdri(NULL), shdri(NULL), : super(f), phdri(nullptr), shdri(nullptr),
gnu_stack(NULL), gnu_stack(nullptr),
page_mask(~0u<<lg2_page), page_mask(~0u<<lg2_page),
dynseg(NULL), hashtab(NULL), gashtab(NULL), dynsym(NULL), dynseg(nullptr), hashtab(nullptr), gashtab(nullptr), dynsym(nullptr),
jni_onload_sym(NULL), jni_onload_sym(nullptr),
sec_strndx(NULL), sec_dynsym(NULL), sec_dynstr(NULL) sec_strndx(nullptr), sec_dynsym(nullptr), sec_dynstr(nullptr)
, symnum_end(0) , symnum_end(0)
{ {
memset(&ehdri, 0, sizeof(ehdri)); memset(&ehdri, 0, sizeof(ehdri));
@@ -722,12 +722,12 @@ PackLinuxElf32::~PackLinuxElf32()
} }
PackLinuxElf64::PackLinuxElf64(InputFile *f) PackLinuxElf64::PackLinuxElf64(InputFile *f)
: super(f), phdri(NULL), shdri(NULL), : super(f), phdri(nullptr), shdri(nullptr),
gnu_stack(NULL), gnu_stack(nullptr),
page_mask(~0ull<<lg2_page), page_mask(~0ull<<lg2_page),
dynseg(NULL), hashtab(NULL), gashtab(NULL), dynsym(NULL), dynseg(nullptr), hashtab(nullptr), gashtab(nullptr), dynsym(nullptr),
jni_onload_sym(NULL), jni_onload_sym(nullptr),
sec_strndx(NULL), sec_dynsym(NULL), sec_dynstr(NULL) sec_strndx(nullptr), sec_dynsym(nullptr), sec_dynstr(nullptr)
, symnum_end(0) , symnum_end(0)
{ {
memset(&ehdri, 0, sizeof(ehdri)); memset(&ehdri, 0, sizeof(ehdri));
@@ -794,7 +794,7 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f)
phdri= (Elf64_Phdr *)(e_phoff + file_image); // do not free() !! phdri= (Elf64_Phdr *)(e_phoff + file_image); // do not free() !!
shdri= (Elf64_Shdr *)(e_shoff + file_image); // do not free() !! shdri= (Elf64_Shdr *)(e_shoff + file_image); // do not free() !!
if (opt->cmd != CMD_COMPRESS) { if (opt->cmd != CMD_COMPRESS) {
shdri = NULL; shdri = nullptr;
} }
sec_dynsym = elf_find_section_type(Elf64_Shdr::SHT_DYNSYM); sec_dynsym = elf_find_section_type(Elf64_Shdr::SHT_DYNSYM);
if (sec_dynsym) { if (sec_dynsym) {
@@ -1084,61 +1084,61 @@ void PackLinuxElf32x86::addStubEntrySections(Filter const *ft)
// b_len + ph.c_len ); // b_len + ph.c_len );
// entry to stub // entry to stub
addLoader("LEXEC000", NULL); addLoader("LEXEC000", nullptr);
if (ft->id) { if (ft->id) {
{ // decompr, unfilter are separate { // decompr, unfilter are separate
addLoader("LXUNF000", NULL); addLoader("LXUNF000", nullptr);
addLoader("LXUNF002", NULL); addLoader("LXUNF002", nullptr);
if (0x80==(ft->id & 0xF0)) { if (0x80==(ft->id & 0xF0)) {
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE0", NULL); addLoader("MRUBYTE0", nullptr);
} }
else if (n_mru) { else if (n_mru) {
addLoader("LXMRU005", NULL); addLoader("LXMRU005", nullptr);
} }
if (n_mru) { if (n_mru) {
addLoader("LXMRU006", NULL); addLoader("LXMRU006", nullptr);
} }
else { else {
addLoader("LXMRU007", NULL); addLoader("LXMRU007", nullptr);
} }
} }
else if (0x40==(ft->id & 0xF0)) { else if (0x40==(ft->id & 0xF0)) {
addLoader("LXUNF008", NULL); addLoader("LXUNF008", nullptr);
} }
addLoader("LXUNF010", NULL); addLoader("LXUNF010", nullptr);
} }
if (n_mru) { if (n_mru) {
addLoader("LEXEC009", NULL); addLoader("LEXEC009", nullptr);
} }
} }
addLoader("LEXEC010", NULL); addLoader("LEXEC010", nullptr);
addLoader(getDecompressorSections(), NULL); addLoader(getDecompressorSections(), nullptr);
addLoader("LEXEC015", NULL); addLoader("LEXEC015", nullptr);
if (ft->id) { if (ft->id) {
{ // decompr, unfilter are separate { // decompr, unfilter are separate
if (0x80!=(ft->id & 0xF0)) { if (0x80!=(ft->id & 0xF0)) {
addLoader("LXUNF042", NULL); addLoader("LXUNF042", nullptr);
} }
} }
addFilter32(ft->id); addFilter32(ft->id);
{ // decompr, unfilter are separate { // decompr, unfilter are separate
if (0x80==(ft->id & 0xF0)) { if (0x80==(ft->id & 0xF0)) {
if (0==n_mru) { if (0==n_mru) {
addLoader("LXMRU058", NULL); addLoader("LXMRU058", nullptr);
} }
} }
addLoader("LXUNF035", NULL); addLoader("LXUNF035", nullptr);
} }
} }
else { else {
addLoader("LEXEC017", NULL); addLoader("LEXEC017", nullptr);
} }
addLoader("IDENTSTR", NULL); addLoader("IDENTSTR", nullptr);
addLoader("LEXEC020", NULL); addLoader("LEXEC020", nullptr);
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", nullptr);
} }
void PackLinuxElf32x86::defineSymbols(Filter const *const ft) void PackLinuxElf32x86::defineSymbols(Filter const *const ft)
@@ -1185,7 +1185,7 @@ PackLinuxElf32::buildLinuxLoader(
{ {
unsigned h_sz_cpr = h.sz_cpr; unsigned h_sz_cpr = h.sz_cpr;
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h_sz_cpr, int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h_sz_cpr,
NULL, ph.method, 10, NULL, NULL ); nullptr, ph.method, 10, nullptr, nullptr );
h.sz_cpr = h_sz_cpr; h.sz_cpr = h_sz_cpr;
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc) if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
throwInternalError("loader compression failed"); throwInternalError("loader compression failed");
@@ -1196,7 +1196,7 @@ PackLinuxElf32::buildLinuxLoader(
MemBuffer mb_tmp(tmp_len); MemBuffer mb_tmp(tmp_len);
unsigned char *tmp = (unsigned char *)mb_tmp; unsigned char *tmp = (unsigned char *)mb_tmp;
memset(tmp, 0, tmp_len); memset(tmp, 0, tmp_len);
int r = upx_decompress(sizeof(h) + cprLoader, h.sz_cpr, tmp, &tmp_len, h.b_method, NULL); int r = upx_decompress(sizeof(h) + cprLoader, h.sz_cpr, tmp, &tmp_len, h.b_method, nullptr);
if (r == UPX_E_OUT_OF_MEMORY) if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException(); throwOutOfMemoryException();
printf("\n%d %d: %d %d %d\n", h.b_method, r, h.sz_cpr, h.sz_unc, tmp_len); printf("\n%d %d: %d %d %d\n", h.b_method, r, h.sz_cpr, h.sz_unc, tmp_len);
@@ -1255,7 +1255,7 @@ PackLinuxElf64::buildLinuxLoader(
{ {
unsigned h_sz_cpr = h.sz_cpr; unsigned h_sz_cpr = h.sz_cpr;
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h_sz_cpr, int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &h_sz_cpr,
NULL, ph.method, 10, NULL, NULL ); nullptr, ph.method, 10, nullptr, nullptr );
h.sz_cpr = h_sz_cpr; h.sz_cpr = h_sz_cpr;
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc) if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
throwInternalError("loader compression failed"); throwInternalError("loader compression failed");
@@ -1266,7 +1266,7 @@ PackLinuxElf64::buildLinuxLoader(
MemBuffer mb_tmp(tmp_len); MemBuffer mb_tmp(tmp_len);
unsigned char *tmp = (unsigned char *)mb_tmp; unsigned char *tmp = (unsigned char *)mb_tmp;
memset(tmp, 0, tmp_len); memset(tmp, 0, tmp_len);
int r = upx_decompress(sizeof(h) + cprLoader, h.sz_cpr, tmp, &tmp_len, h.b_method, NULL); int r = upx_decompress(sizeof(h) + cprLoader, h.sz_cpr, tmp, &tmp_len, h.b_method, nullptr);
if (r == UPX_E_OUT_OF_MEMORY) if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException(); throwOutOfMemoryException();
printf("\n%d %d: %d %d %d\n", h.b_method, r, h.sz_cpr, h.sz_unc, tmp_len); printf("\n%d %d: %d %d %d\n", h.b_method, r, h.sz_cpr, h.sz_unc, tmp_len);
@@ -1313,12 +1313,12 @@ PackLinuxElf32x86::buildLoader(const Filter *ft)
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
buildLinuxLoader( buildLinuxLoader(
stub_i386_linux_shlib_init, sizeof(stub_i386_linux_shlib_init), stub_i386_linux_shlib_init, sizeof(stub_i386_linux_shlib_init),
NULL, 0, ft ); nullptr, 0, ft );
return; return;
} }
unsigned char tmp[sizeof(stub_i386_linux_elf_fold)]; unsigned char tmp[sizeof(stub_i386_linux_elf_fold)];
memcpy(tmp, stub_i386_linux_elf_fold, sizeof(stub_i386_linux_elf_fold)); memcpy(tmp, stub_i386_linux_elf_fold, sizeof(stub_i386_linux_elf_fold));
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
if (opt->o_unix.is_ptinterp) { if (opt->o_unix.is_ptinterp) {
unsigned j; unsigned j;
for (j = 0; j < sizeof(stub_i386_linux_elf_fold)-1; ++j) { for (j = 0; j < sizeof(stub_i386_linux_elf_fold)-1; ++j) {
@@ -1346,7 +1346,7 @@ PackBSDElf32x86::buildLoader(const Filter *ft)
{ {
unsigned char tmp[sizeof(stub_i386_bsd_elf_fold)]; unsigned char tmp[sizeof(stub_i386_bsd_elf_fold)];
memcpy(tmp, stub_i386_bsd_elf_fold, sizeof(stub_i386_bsd_elf_fold)); memcpy(tmp, stub_i386_bsd_elf_fold, sizeof(stub_i386_bsd_elf_fold));
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
if (opt->o_unix.is_ptinterp) { if (opt->o_unix.is_ptinterp) {
unsigned j; unsigned j;
for (j = 0; j < sizeof(stub_i386_bsd_elf_fold)-1; ++j) { for (j = 0; j < sizeof(stub_i386_bsd_elf_fold)-1; ++j) {
@@ -1378,7 +1378,7 @@ PackNetBSDElf32x86::buildLoader(const Filter *ft)
{ {
unsigned char tmp[sizeof(stub_i386_netbsd_elf_fold)]; unsigned char tmp[sizeof(stub_i386_netbsd_elf_fold)];
memcpy(tmp, stub_i386_netbsd_elf_fold, sizeof(stub_i386_netbsd_elf_fold)); memcpy(tmp, stub_i386_netbsd_elf_fold, sizeof(stub_i386_netbsd_elf_fold));
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
if (opt->o_unix.is_ptinterp) { if (opt->o_unix.is_ptinterp) {
unsigned j; unsigned j;
for (j = 0; j < sizeof(stub_i386_netbsd_elf_fold)-1; ++j) { for (j = 0; j < sizeof(stub_i386_netbsd_elf_fold)-1; ++j) {
@@ -1404,7 +1404,7 @@ PackOpenBSDElf32x86::buildLoader(const Filter *ft)
{ {
unsigned char tmp[sizeof(stub_i386_openbsd_elf_fold)]; unsigned char tmp[sizeof(stub_i386_openbsd_elf_fold)];
memcpy(tmp, stub_i386_openbsd_elf_fold, sizeof(stub_i386_openbsd_elf_fold)); memcpy(tmp, stub_i386_openbsd_elf_fold, sizeof(stub_i386_openbsd_elf_fold));
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
if (opt->o_unix.is_ptinterp) { if (opt->o_unix.is_ptinterp) {
unsigned j; unsigned j;
for (j = 0; j < sizeof(stub_i386_openbsd_elf_fold)-1; ++j) { for (j = 0; j < sizeof(stub_i386_openbsd_elf_fold)-1; ++j) {
@@ -1461,7 +1461,7 @@ PackLinuxElf32armLe::buildLoader(Filter const *ft)
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
buildLinuxLoader( buildLinuxLoader(
stub_arm_v5t_linux_shlib_init, sizeof(stub_arm_v5t_linux_shlib_init), stub_arm_v5t_linux_shlib_init, sizeof(stub_arm_v5t_linux_shlib_init),
NULL, 0, ft ); nullptr, 0, ft );
return; return;
} }
buildLinuxLoader( buildLinuxLoader(
@@ -1488,7 +1488,7 @@ PackLinuxElf32mipsel::buildLoader(Filter const *ft)
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
buildLinuxLoader( buildLinuxLoader(
stub_mipsel_r3000_linux_shlib_init, sizeof(stub_mipsel_r3000_linux_shlib_init), stub_mipsel_r3000_linux_shlib_init, sizeof(stub_mipsel_r3000_linux_shlib_init),
NULL, 0, ft ); nullptr, 0, ft );
return; return;
} }
buildLinuxLoader( buildLinuxLoader(
@@ -1509,7 +1509,7 @@ PackLinuxElf32mipseb::buildLoader(Filter const *ft)
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
buildLinuxLoader( buildLinuxLoader(
stub_mips_r3000_linux_shlib_init, sizeof(stub_mips_r3000_linux_shlib_init), stub_mips_r3000_linux_shlib_init, sizeof(stub_mips_r3000_linux_shlib_init),
NULL, 0, ft ); nullptr, 0, ft );
return; return;
} }
buildLinuxLoader( buildLinuxLoader(
@@ -1569,7 +1569,7 @@ PackLinuxElf64amd::buildLoader(const Filter *ft)
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
buildLinuxLoader( buildLinuxLoader(
stub_amd64_linux_shlib_init, sizeof(stub_amd64_linux_shlib_init), stub_amd64_linux_shlib_init, sizeof(stub_amd64_linux_shlib_init),
NULL, 0, ft ); nullptr, 0, ft );
return; return;
} }
buildLinuxLoader( buildLinuxLoader(
@@ -1590,7 +1590,7 @@ PackLinuxElf64arm::buildLoader(const Filter *ft)
if (0!=xct_off) { // shared library if (0!=xct_off) { // shared library
buildLinuxLoader( buildLinuxLoader(
stub_arm64_linux_shlib_init, sizeof(stub_arm64_linux_shlib_init), stub_arm64_linux_shlib_init, sizeof(stub_arm64_linux_shlib_init),
NULL, 0, ft ); nullptr, 0, ft );
return; return;
} }
buildLinuxLoader( buildLinuxLoader(
@@ -1787,7 +1787,7 @@ PackLinuxElf32::elf_find_ptype(unsigned type, Elf32_Phdr const *phdr, unsigned p
return phdr; return phdr;
} }
} }
return 0; return nullptr;
} }
Elf64_Phdr const * Elf64_Phdr const *
@@ -1798,7 +1798,7 @@ PackLinuxElf64::elf_find_ptype(unsigned type, Elf64_Phdr const *phdr, unsigned p
return phdr; return phdr;
} }
} }
return 0; return nullptr;
} }
Elf32_Shdr const *PackLinuxElf32::elf_find_section_name( Elf32_Shdr const *PackLinuxElf32::elf_find_section_name(
@@ -1807,7 +1807,7 @@ Elf32_Shdr const *PackLinuxElf32::elf_find_section_name(
{ {
Elf32_Shdr const *shdr = shdri; Elf32_Shdr const *shdr = shdri;
if (!shdr) { if (!shdr) {
return 0; return nullptr;
} }
int j = e_shnum; int j = e_shnum;
for (; 0 <=--j; ++shdr) { for (; 0 <=--j; ++shdr) {
@@ -1822,7 +1822,7 @@ Elf32_Shdr const *PackLinuxElf32::elf_find_section_name(
return shdr; return shdr;
} }
} }
return 0; return nullptr;
} }
Elf64_Shdr const *PackLinuxElf64::elf_find_section_name( Elf64_Shdr const *PackLinuxElf64::elf_find_section_name(
@@ -1831,7 +1831,7 @@ Elf64_Shdr const *PackLinuxElf64::elf_find_section_name(
{ {
Elf64_Shdr const *shdr = shdri; Elf64_Shdr const *shdr = shdri;
if (!shdr) { if (!shdr) {
return 0; return nullptr;
} }
int j = e_shnum; int j = e_shnum;
for (; 0 <=--j; ++shdr) { for (; 0 <=--j; ++shdr) {
@@ -1846,7 +1846,7 @@ Elf64_Shdr const *PackLinuxElf64::elf_find_section_name(
return shdr; return shdr;
} }
} }
return 0; return nullptr;
} }
Elf32_Shdr const *PackLinuxElf32::elf_find_section_type( Elf32_Shdr const *PackLinuxElf32::elf_find_section_type(
@@ -1855,7 +1855,7 @@ Elf32_Shdr const *PackLinuxElf32::elf_find_section_type(
{ {
Elf32_Shdr const *shdr = shdri; Elf32_Shdr const *shdr = shdri;
if (!shdr) { if (!shdr) {
return 0; return nullptr;
} }
int j = e_shnum; int j = e_shnum;
for (; 0 <=--j; ++shdr) { for (; 0 <=--j; ++shdr) {
@@ -1863,7 +1863,7 @@ Elf32_Shdr const *PackLinuxElf32::elf_find_section_type(
return shdr; return shdr;
} }
} }
return 0; return nullptr;
} }
Elf64_Shdr const *PackLinuxElf64::elf_find_section_type( Elf64_Shdr const *PackLinuxElf64::elf_find_section_type(
@@ -1872,7 +1872,7 @@ Elf64_Shdr const *PackLinuxElf64::elf_find_section_type(
{ {
Elf64_Shdr const *shdr = shdri; Elf64_Shdr const *shdr = shdri;
if (!shdr) { if (!shdr) {
return 0; return nullptr;
} }
int j = e_shnum; int j = e_shnum;
for (; 0 <=--j; ++shdr) { for (; 0 <=--j; ++shdr) {
@@ -1880,7 +1880,7 @@ Elf64_Shdr const *PackLinuxElf64::elf_find_section_type(
return shdr; return shdr;
} }
} }
return 0; return nullptr;
} }
char const *PackLinuxElf64::get_str_name(unsigned st_name, unsigned symnum) const char const *PackLinuxElf64::get_str_name(unsigned st_name, unsigned symnum) const
@@ -2087,8 +2087,8 @@ bool PackLinuxElf32::canPack()
phdri= (Elf32_Phdr *)((size_t)e_phoff + file_image); // do not free() !! phdri= (Elf32_Phdr *)((size_t)e_phoff + file_image); // do not free() !!
shdri= (Elf32_Shdr *)((size_t)e_shoff + file_image); // do not free() !! shdri= (Elf32_Shdr *)((size_t)e_shoff + file_image); // do not free() !!
sec_strndx = NULL; sec_strndx = nullptr;
shstrtab = NULL; shstrtab = nullptr;
if (e_shnum) { if (e_shnum) {
unsigned const e_shstrndx = get_te16(&ehdr->e_shstrndx); unsigned const e_shstrndx = get_te16(&ehdr->e_shstrndx);
if (e_shstrndx) { if (e_shstrndx) {
@@ -2129,7 +2129,7 @@ bool PackLinuxElf32::canPack()
} }
} }
Elf32_Phdr const *pload_x0(0); // first eXecutable PT_LOAD Elf32_Phdr const *pload_x0(nullptr); // first eXecutable PT_LOAD
phdr= phdri; phdr= phdri;
for (int j= e_phnum; --j>=0; ++phdr) for (int j= e_phnum; --j>=0; ++phdr)
if (Elf32_Phdr::PT_DYNAMIC==get_te32(&phdr->p_type)) { if (Elf32_Phdr::PT_DYNAMIC==get_te32(&phdr->p_type)) {
@@ -2437,8 +2437,8 @@ PackLinuxElf64::canPack()
phdri= (Elf64_Phdr *)((size_t)e_phoff + file_image); // do not free() !! phdri= (Elf64_Phdr *)((size_t)e_phoff + file_image); // do not free() !!
shdri= (Elf64_Shdr *)((size_t)e_shoff + file_image); // do not free() !! shdri= (Elf64_Shdr *)((size_t)e_shoff + file_image); // do not free() !!
sec_strndx = NULL; sec_strndx = nullptr;
shstrtab = NULL; shstrtab = nullptr;
if (e_shnum) { if (e_shnum) {
unsigned const e_shstrndx = get_te16(&ehdr->e_shstrndx); unsigned const e_shstrndx = get_te16(&ehdr->e_shstrndx);
if (e_shstrndx) { if (e_shstrndx) {
@@ -2479,7 +2479,7 @@ PackLinuxElf64::canPack()
} }
} }
Elf64_Phdr const *pload_x0(0); // first eXecutable PT_LOAD Elf64_Phdr const *pload_x0(nullptr); // first eXecutable PT_LOAD
phdr= phdri; phdr= phdri;
for (int j= e_phnum; --j>=0; ++phdr) for (int j= e_phnum; --j>=0; ++phdr)
if (Elf64_Phdr::PT_DYNAMIC==get_te32(&phdr->p_type)) { if (Elf64_Phdr::PT_DYNAMIC==get_te32(&phdr->p_type)) {
@@ -2864,8 +2864,8 @@ PackNetBSDElf32x86::generateElfHdr(
unsigned note_offset = sz_elf_hdrs; unsigned note_offset = sz_elf_hdrs;
// Find the NetBSD PT_NOTE and the PaX PT_NOTE. // Find the NetBSD PT_NOTE and the PaX PT_NOTE.
Elf32_Nhdr const *np_NetBSD = 0; unsigned sz_NetBSD = 0; Elf32_Nhdr const *np_NetBSD = nullptr; unsigned sz_NetBSD = 0;
Elf32_Nhdr const *np_PaX = 0; unsigned sz_PaX = 0; Elf32_Nhdr const *np_PaX = nullptr; unsigned sz_PaX = 0;
unsigned char *cp = (unsigned char *)note_body; unsigned char *cp = (unsigned char *)note_body;
unsigned j; unsigned j;
for (j=0; j < note_size; ) { for (j=0; j < note_size; ) {
@@ -2942,7 +2942,7 @@ PackNetBSDElf32x86::generateElfHdr(
// The 'if' guards on these two calls to memcpy are required // The 'if' guards on these two calls to memcpy are required
// because the C Standard Committee did not debug the Standard // because the C Standard Committee did not debug the Standard
// before publishing. An empty region (0==size) must nevertheless // before publishing. An empty region (0==size) must nevertheless
// have a valid (non-NULL) pointer. // have a valid (non-nullptr) pointer.
if (sz_NetBSD) memcpy(&((char *)phdr)[0], np_NetBSD, sz_NetBSD); if (sz_NetBSD) memcpy(&((char *)phdr)[0], np_NetBSD, sz_NetBSD);
if (sz_PaX) memcpy(&((char *)phdr)[sz_NetBSD], np_PaX, sz_PaX); if (sz_PaX) memcpy(&((char *)phdr)[sz_NetBSD], np_PaX, sz_PaX);
@@ -4031,7 +4031,7 @@ int PackLinuxElf32::pack2(OutputFile *fo, Filter &ft)
// sometimes marks as PF_X anyway. So filter only first segment. // sometimes marks as PF_X anyway. So filter only first segment.
if (k == nk_f || !is_shlib) { if (k == nk_f || !is_shlib) {
packExtent(x, total_in, total_out, packExtent(x, total_in, total_out,
(k==nk_f ? &ft : 0 ), fo, hdr_u_len); (k==nk_f ? &ft : nullptr ), fo, hdr_u_len);
} }
else { else {
total_in += x.size; total_in += x.size;
@@ -4162,7 +4162,7 @@ int PackLinuxElf64::pack2(OutputFile *fo, Filter &ft)
// sometimes marks as PF_X anyway. So filter only first segment. // sometimes marks as PF_X anyway. So filter only first segment.
if (k == nk_f || !is_shlib) { if (k == nk_f || !is_shlib) {
packExtent(x, total_in, total_out, packExtent(x, total_in, total_out,
(k==nk_f ? &ft : 0 ), fo, hdr_u_len); (k==nk_f ? &ft : nullptr ), fo, hdr_u_len);
} }
else { else {
total_in += x.size; total_in += x.size;
@@ -4553,7 +4553,7 @@ void PackLinuxElf64::unpack(OutputFile *fo)
MemBuffer u(ph.u_len); MemBuffer u(ph.u_len);
Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)&u[0]; Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)&u[0];
Elf64_Phdr const *phdr = 0; Elf64_Phdr const *phdr = nullptr;
// Uncompress Ehdr and Phdrs. // Uncompress Ehdr and Phdrs.
if (ibuf.getSize() < ph.c_len) if (ibuf.getSize() < ph.c_len)
@@ -4576,8 +4576,8 @@ void PackLinuxElf64::unpack(OutputFile *fo)
unsigned const u_phnum = get_te16(&ehdr->e_phnum); unsigned const u_phnum = get_te16(&ehdr->e_phnum);
unsigned total_in = 0; unsigned total_in = 0;
unsigned total_out = 0; unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0); unsigned c_adler = upx_adler32(nullptr, 0);
unsigned u_adler = upx_adler32(NULL, 0); unsigned u_adler = upx_adler32(nullptr, 0);
#define MAX_ELF_HDR 1024 #define MAX_ELF_HDR 1024
if ((umin64(MAX_ELF_HDR, ph.u_len) - sizeof(Elf64_Ehdr))/sizeof(Elf64_Phdr) < u_phnum) { if ((umin64(MAX_ELF_HDR, ph.u_len) - sizeof(Elf64_Ehdr))/sizeof(Elf64_Phdr) < u_phnum) {
throwCantUnpack("bad compressed e_phnum"); throwCantUnpack("bad compressed e_phnum");
@@ -5071,7 +5071,7 @@ PackLinuxElf32::elf_has_dynamic(unsigned int key) const
for (; Elf32_Dyn::DT_NULL!=dynp->d_tag; ++dynp) if (get_te32(&dynp->d_tag)==key) { for (; Elf32_Dyn::DT_NULL!=dynp->d_tag; ++dynp) if (get_te32(&dynp->d_tag)==key) {
return dynp; return dynp;
} }
return 0; return nullptr;
} }
unsigned // checked .p_offset; sz_dynseg set unsigned // checked .p_offset; sz_dynseg set
@@ -5109,7 +5109,7 @@ PackLinuxElf32::elf_find_dynamic(unsigned int key) const
} }
break; break;
} }
return 0; return nullptr;
} }
upx_uint64_t upx_uint64_t
@@ -5173,7 +5173,7 @@ PackLinuxElf64::elf_has_dynamic(unsigned int key) const
for (; Elf64_Dyn::DT_NULL!=dynp->d_tag; ++dynp) if (get_te64(&dynp->d_tag)==key) { for (; Elf64_Dyn::DT_NULL!=dynp->d_tag; ++dynp) if (get_te64(&dynp->d_tag)==key) {
return dynp; return dynp;
} }
return 0; return nullptr;
} }
upx_uint64_t // checked .p_offset; sz_dynseg set upx_uint64_t // checked .p_offset; sz_dynseg set
@@ -5399,7 +5399,7 @@ PackLinuxElf64::elf_find_dynamic(unsigned int key) const
} }
break; break;
} }
return 0; return nullptr;
} }
upx_uint64_t upx_uint64_t
@@ -5512,7 +5512,7 @@ Elf32_Sym const *PackLinuxElf32::elf_lookup(char const *name) const
} }
} }
} }
return 0; return nullptr;
} }
@@ -5589,7 +5589,7 @@ Elf64_Sym const *PackLinuxElf64::elf_lookup(char const *name) const
} }
} }
} }
return 0; return nullptr;
} }
@@ -5640,7 +5640,7 @@ void PackLinuxElf32::unpack(OutputFile *fo)
MemBuffer u(ph.u_len); MemBuffer u(ph.u_len);
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)&u[0]; Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)&u[0];
Elf32_Phdr const *phdr = 0; Elf32_Phdr const *phdr = nullptr;
// Uncompress Ehdr and Phdrs. // Uncompress Ehdr and Phdrs.
if (ibuf.getSize() < ph.c_len) { if (ibuf.getSize() < ph.c_len) {
@@ -5662,8 +5662,8 @@ void PackLinuxElf32::unpack(OutputFile *fo)
unsigned const u_phnum = get_te16(&ehdr->e_phnum); unsigned const u_phnum = get_te16(&ehdr->e_phnum);
unsigned total_in = 0; unsigned total_in = 0;
unsigned total_out = 0; unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0); unsigned c_adler = upx_adler32(nullptr, 0);
unsigned u_adler = upx_adler32(NULL, 0); unsigned u_adler = upx_adler32(nullptr, 0);
#define MAX_ELF_HDR 512 #define MAX_ELF_HDR 512
if ((umin(MAX_ELF_HDR, ph.u_len) - sizeof(Elf32_Ehdr))/sizeof(Elf32_Phdr) < u_phnum) { if ((umin(MAX_ELF_HDR, ph.u_len) - sizeof(Elf32_Ehdr))/sizeof(Elf32_Phdr) < u_phnum) {
throwCantUnpack("bad compressed e_phnum"); throwCantUnpack("bad compressed e_phnum");
+16 -16
View File
@@ -55,7 +55,7 @@
**************************************************************************/ **************************************************************************/
PackLinuxI386::PackLinuxI386(InputFile *f) : super(f), PackLinuxI386::PackLinuxI386(InputFile *f) : super(f),
ei_osabi(Elf32_Ehdr::ELFOSABI_LINUX), osabi_note(NULL) ei_osabi(Elf32_Ehdr::ELFOSABI_LINUX), osabi_note(nullptr)
{ {
bele = &N_BELE_RTP::le_policy; bele = &N_BELE_RTP::le_policy;
} }
@@ -336,43 +336,43 @@ PackLinuxI386::buildLinuxLoader(
// // compressed data // // compressed data
// b_len + ph.c_len ); // b_len + ph.c_len );
// // entry to stub // // entry to stub
addLoader("LEXEC000", NULL); addLoader("LEXEC000", nullptr);
if (ft->id) { if (ft->id) {
if (n_mru) { if (n_mru) {
addLoader("LEXEC009", NULL); addLoader("LEXEC009", nullptr);
} }
} }
addLoader("LEXEC010", NULL); addLoader("LEXEC010", nullptr);
linker->defineSymbol("filter_cto", ft->cto); linker->defineSymbol("filter_cto", ft->cto);
linker->defineSymbol("filter_length", linker->defineSymbol("filter_length",
(ft->id & 0xf) % 3 == 0 ? ft->calls : (ft->id & 0xf) % 3 == 0 ? ft->calls :
ft->lastcall - ft->calls * 4); ft->lastcall - ft->calls * 4);
addLoader(getDecompressorSections(), NULL); addLoader(getDecompressorSections(), nullptr);
addLoader("LEXEC015", NULL); addLoader("LEXEC015", nullptr);
if (ft->id) { if (ft->id) {
{ // decompr, unfilter not separate { // decompr, unfilter not separate
if (0x80==(ft->id & 0xF0)) { if (0x80==(ft->id & 0xF0)) {
addLoader("LEXEC110", NULL); addLoader("LEXEC110", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LEXEC100", NULL); addLoader("LEXEC100", nullptr);
} }
// bug in APP: jmp and label must be in same .asx/.asy // bug in APP: jmp and label must be in same .asx/.asy
addLoader("LEXEC016", NULL); addLoader("LEXEC016", nullptr);
} }
} }
addFilter32(ft->id); addFilter32(ft->id);
{ // decompr always unfilters { // decompr always unfilters
addLoader("LEXEC017", NULL); addLoader("LEXEC017", nullptr);
} }
} }
else { else {
addLoader("LEXEC017", NULL); addLoader("LEXEC017", nullptr);
} }
addLoader("IDENTSTR", NULL); addLoader("IDENTSTR", nullptr);
addLoader("LEXEC020", NULL); addLoader("LEXEC020", nullptr);
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", nullptr);
if (M_IS_LZMA(ph.method)) { if (M_IS_LZMA(ph.method)) {
const lzma_compress_result_t *res = &ph.compress_result.result_lzma; const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
upx_uint32_t properties = // lc, lp, pb, dummy upx_uint32_t properties = // lc, lp, pb, dummy
@@ -408,7 +408,7 @@ PackLinuxI386::buildLoader(Filter const *ft)
// patch loader // patch loader
// note: we only can use /proc/<pid>/fd when exetype > 0. // note: we only can use /proc/<pid>/fd when exetype > 0.
// also, we sleep much longer when compressing a script. // also, we sleep much longer when compressing a script.
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
patch_le32(buf,sz_fold,"UPX4",exetype > 0 ? 3 : 15); // sleep time patch_le32(buf,sz_fold,"UPX4",exetype > 0 ? 3 : 15); // sleep time
patch_le32(buf,sz_fold,"UPX3",progid); patch_le32(buf,sz_fold,"UPX3",progid);
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff); patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
@@ -428,7 +428,7 @@ PackBSDI386::buildLoader(Filter const *ft)
// patch loader // patch loader
// note: we only can use /proc/<pid>/fd when exetype > 0. // note: we only can use /proc/<pid>/fd when exetype > 0.
// also, we sleep much longer when compressing a script. // also, we sleep much longer when compressing a script.
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
patch_le32(buf,sz_fold,"UPX4",exetype > 0 ? 3 : 15); // sleep time patch_le32(buf,sz_fold,"UPX4",exetype > 0 ? 3 : 15); // sleep time
patch_le32(buf,sz_fold,"UPX3",progid); patch_le32(buf,sz_fold,"UPX3",progid);
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff); patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
+23 -23
View File
@@ -150,38 +150,38 @@ off_t PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
initLoader(stub_i386_linux_elf_interp_entry, sizeof(stub_i386_linux_elf_interp_entry)); initLoader(stub_i386_linux_elf_interp_entry, sizeof(stub_i386_linux_elf_interp_entry));
linker->addSection("FOLDEXEC", stub_i386_linux_elf_interp_fold, sizeof(stub_i386_linux_elf_interp_fold), 0); linker->addSection("FOLDEXEC", stub_i386_linux_elf_interp_fold, sizeof(stub_i386_linux_elf_interp_fold), 0);
addLoader("LXPTI000", NULL); addLoader("LXPTI000", nullptr);
addLoader("LXPTI040", NULL); addLoader("LXPTI040", nullptr);
ph.method = M_NRV2B_LE32; addLoader(getDecompressorSections(), NULL); ph.method = M_NRV2B_LE32; addLoader(getDecompressorSections(), nullptr);
addLoader("LXPTI090", NULL); addLoader("LXPTI090", nullptr);
addLoader("LXPTI041", NULL); addLoader("LXPTI041", nullptr);
ph.method = M_NRV2D_LE32; addLoader(getDecompressorSections(), NULL); ph.method = M_NRV2D_LE32; addLoader(getDecompressorSections(), nullptr);
addLoader("LXPTI090", NULL); addLoader("LXPTI090", nullptr);
addLoader("LXPTI042", NULL); addLoader("LXPTI042", nullptr);
ph.method = M_NRV2E_LE32; addLoader(getDecompressorSections(), NULL); ph.method = M_NRV2E_LE32; addLoader(getDecompressorSections(), nullptr);
addLoader("LXPTI090", NULL); addLoader("LXPTI090", nullptr);
//addLoader("LXPTI043", NULL); //addLoader("LXPTI043", nullptr);
//ph.method = M_CL1B_LE32; addLoader(getDecompressorSections(), NULL); //ph.method = M_CL1B_LE32; addLoader(getDecompressorSections(), nullptr);
//addLoader("LXPTI090", NULL); //addLoader("LXPTI090", nullptr);
addLoader("LXPTI091", NULL); addLoader("LXPTI091", nullptr);
addLoader("LXPTI140", NULL); addLoader("LXPTI140", nullptr);
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL); addLoader("LXUNF002,LXUNF008,LXUNF010", nullptr);
addFilter32(0x46); addFilter32(0x46);
addLoader("LXUNF042,LXUNF035", NULL); addLoader("LXUNF042,LXUNF035", nullptr);
addLoader("LXUNF002,LXUNF008,LXUNF010", NULL); addLoader("LXUNF002,LXUNF008,LXUNF010", nullptr);
addFilter32(0x49); addFilter32(0x49);
addLoader("LXUNF042,LXUNF035", NULL); addLoader("LXUNF042,LXUNF035", nullptr);
addLoader("LXPTI200", NULL); addLoader("LXPTI200", nullptr);
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", nullptr);
upx_byte const *p = getLoader(); upx_byte const *p = getLoader();
lsize = getLoaderSize(); lsize = getLoaderSize();
updateLoader(fo); updateLoader(fo);
@@ -236,8 +236,8 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
unsigned total_in = 0; unsigned total_in = 0;
unsigned total_out = 0; unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0); unsigned c_adler = upx_adler32(nullptr, 0);
unsigned u_adler = upx_adler32(NULL, 0); unsigned u_adler = upx_adler32(nullptr, 0);
off_t ptload0hi=0, ptload1lo=0, ptload1sz=0; off_t ptload0hi=0, ptload1lo=0, ptload1sz=0;
// decompress PT_LOAD // decompress PT_LOAD
+4 -4
View File
@@ -78,7 +78,7 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
MemBuffer buf(sz_fold); MemBuffer buf(sz_fold);
memcpy(buf, stub_i386_linux_elf_shell_fold, sz_fold); memcpy(buf, stub_i386_linux_elf_shell_fold, sz_fold);
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
patch_le32(buf,sz_fold,"UPX3",l_shname); patch_le32(buf,sz_fold,"UPX3",l_shname);
patch_le32(buf,sz_fold,"UPX2",o_shname); patch_le32(buf,sz_fold,"UPX2",o_shname);
@@ -115,12 +115,12 @@ bool PackLinuxI386sh::getShellName(char *buf)
static char const *const shname[] = { // known shells that accept "-c" arg static char const *const shname[] = { // known shells that accept "-c" arg
"ash", "bash", "bsh", "csh", "ksh", "pdksh", "sh", "tcsh", "zsh", "ash", "bash", "bsh", "csh", "ksh", "pdksh", "sh", "tcsh", "zsh",
"python", "python2", "python3", "python", "python2", "python3",
NULL nullptr
}; };
const char *bname = strrchr(buf, '/'); const char *bname = strrchr(buf, '/');
if (bname == NULL) if (bname == nullptr)
return false; return false;
for (int j = 0; NULL != shname[j]; ++j) { for (int j = 0; nullptr != shname[j]; ++j) {
if (0 == strcmp(shname[j], bname + 1)) { if (0 == strcmp(shname[j], bname + 1)) {
bool const s = super::canPack(); bool const s = super::canPack();
if (s) { if (s) {
+1 -1
View File
@@ -48,7 +48,7 @@ public:
virtual int getFormat() const { return UPX_F_LINUX_SH_i386; } virtual int getFormat() const { return UPX_F_LINUX_SH_i386; }
virtual const char *getName() const { return "linux.sh/i386"; } virtual const char *getName() const { return "linux.sh/i386"; }
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.shell"; } virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.shell"; }
virtual const int *getFilters() const { return NULL; } virtual const int *getFilters() const { return nullptr; }
virtual void buildLoader(const Filter *); virtual void buildLoader(const Filter *);
virtual void pack1(OutputFile *fo, Filter &ft); virtual void pack1(OutputFile *fo, Filter &ft);
+48 -48
View File
@@ -106,11 +106,11 @@ PackMachBase<T>::PackMachBase(InputFile *f, unsigned cputype, unsigned filetype,
unsigned flavor, unsigned count, unsigned size) : unsigned flavor, unsigned count, unsigned size) :
super(f), my_cputype(cputype), my_filetype(filetype), my_thread_flavor(flavor), super(f), my_cputype(cputype), my_filetype(filetype), my_thread_flavor(flavor),
my_thread_state_word_count(count), my_thread_command_size(size), my_thread_state_word_count(count), my_thread_command_size(size),
n_segment(0), rawmseg(NULL), msegcmd(NULL), o__mod_init_func(0), n_segment(0), rawmseg(nullptr), msegcmd(nullptr), o__mod_init_func(0),
prev_mod_init_func(0), pagezero_vmsize(0) prev_mod_init_func(0), pagezero_vmsize(0)
{ {
MachClass::compileTimeAssertions(); MachClass::compileTimeAssertions();
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL); bele = N_BELE_CTP::getRTP((const BeLePolicy*) nullptr);
memset(&cmdUUID, 0, sizeof(cmdUUID)); memset(&cmdUUID, 0, sizeof(cmdUUID));
memset(&cmdSRCVER, 0, sizeof(cmdSRCVER)); memset(&cmdSRCVER, 0, sizeof(cmdSRCVER));
memset(&cmdVERMIN, 0, sizeof(cmdVERMIN)); memset(&cmdVERMIN, 0, sizeof(cmdVERMIN));
@@ -254,107 +254,107 @@ template <class T>
void void
PackMachBase<T>::addStubEntrySections(Filter const *) PackMachBase<T>::addStubEntrySections(Filter const *)
{ {
addLoader("MACOS000", NULL); addLoader("MACOS000", nullptr);
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("ELFMAINY,IDENTSTR,+40,ELFMAINZ,FOLDEXEC", NULL); addLoader("ELFMAINY,IDENTSTR,+40,ELFMAINZ,FOLDEXEC", nullptr);
} }
void PackMachI386::addStubEntrySections(Filter const * /*ft*/) void PackMachI386::addStubEntrySections(Filter const * /*ft*/)
{ {
addLoader("MACHMAINX", NULL); // different for MY_DYLIB vs MH_EXECUTE addLoader("MACHMAINX", nullptr); // different for MY_DYLIB vs MH_EXECUTE
if (my_filetype==Mach_header::MH_EXECUTE) { if (my_filetype==Mach_header::MH_EXECUTE) {
addLoader("MACH_UNC", NULL); addLoader("MACH_UNC", nullptr);
} }
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL); addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", nullptr);
} }
void PackMachAMD64::addStubEntrySections(Filter const * /*ft*/) void PackMachAMD64::addStubEntrySections(Filter const * /*ft*/)
{ {
addLoader("MACHMAINX", NULL); // different for MY_DYLIB vs MH_EXECUTE addLoader("MACHMAINX", nullptr); // different for MY_DYLIB vs MH_EXECUTE
if (my_filetype==Mach_header::MH_EXECUTE) { if (my_filetype==Mach_header::MH_EXECUTE) {
addLoader("MACH_UNC", NULL); addLoader("MACH_UNC", nullptr);
} }
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL); addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", nullptr);
} }
void PackMachPPC32::addStubEntrySections(Filter const * /*ft*/) void PackMachPPC32::addStubEntrySections(Filter const * /*ft*/)
{ {
if (my_filetype!=Mach_header::MH_EXECUTE) { if (my_filetype!=Mach_header::MH_EXECUTE) {
addLoader("MACHMAINX", NULL); addLoader("MACHMAINX", nullptr);
} }
else { else {
addLoader("PPC32BXX", NULL); addLoader("PPC32BXX", nullptr);
} }
addLoader("MACH_UNC", NULL); addLoader("MACH_UNC", nullptr);
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ", NULL); addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ", nullptr);
if (my_filetype!=Mach_header::MH_EXECUTE) { if (my_filetype!=Mach_header::MH_EXECUTE) {
addLoader("FOLDEXEC", NULL); addLoader("FOLDEXEC", nullptr);
} }
} }
void PackMachARMEL::addStubEntrySections(Filter const * /*ft*/) void PackMachARMEL::addStubEntrySections(Filter const * /*ft*/)
{ {
addLoader("MACHMAINX", NULL); addLoader("MACHMAINX", nullptr);
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL); addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", nullptr);
} }
void PackMachARM64EL::addStubEntrySections(Filter const * /*ft*/) void PackMachARM64EL::addStubEntrySections(Filter const * /*ft*/)
{ {
addLoader("MACHMAINX", NULL); addLoader("MACHMAINX", nullptr);
//addLoader(getDecompressorSections(), NULL); //addLoader(getDecompressorSections(), nullptr);
addLoader( addLoader(
( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL" ( M_IS_NRV2E(ph.method) ? "NRV_HEAD,NRV2E,NRV_TAIL"
: M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL" : M_IS_NRV2D(ph.method) ? "NRV_HEAD,NRV2D,NRV_TAIL"
: M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL" : M_IS_NRV2B(ph.method) ? "NRV_HEAD,NRV2B,NRV_TAIL"
: M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30" : M_IS_LZMA(ph.method) ? "LZMA_ELF00,LZMA_DEC20,LZMA_DEC30"
: NULL), NULL); : nullptr), nullptr);
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", NULL); addLoader("MACHMAINY,IDENTSTR,+40,MACHMAINZ,FOLDEXEC", nullptr);
} }
template <class T> template <class T>
@@ -391,7 +391,7 @@ PackMachBase<T>::buildMachLoader(
if (0 < szfold) { if (0 < szfold) {
unsigned sz_cpr = 0; unsigned sz_cpr = 0;
int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr, int r = upx_compress(uncLoader, h.sz_unc, sizeof(h) + cprLoader, &sz_cpr,
NULL, ph.method, 10, NULL, NULL ); nullptr, ph.method, 10, nullptr, nullptr );
h.sz_cpr = sz_cpr; h.sz_cpr = sz_cpr;
if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc) if (r != UPX_E_OK || h.sz_cpr >= h.sz_unc)
throwInternalError("loader compression failed"); throwInternalError("loader compression failed");
@@ -1099,7 +1099,7 @@ int PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
ptr = (Mach_segment_command const *)(ptr->cmdsize + (char const *)ptr); ptr = (Mach_segment_command const *)(ptr->cmdsize + (char const *)ptr);
} }
packExtent(x, total_in, total_out, packExtent(x, total_in, total_out,
(do_filter ? &ft : 0 ), fo, hdr_u_len, b_extra ); (do_filter ? &ft : nullptr), fo, hdr_u_len, b_extra );
if (do_filter) { if (do_filter) {
exe_filesize_max = 0; exe_filesize_max = 0;
} }
@@ -1114,7 +1114,7 @@ int PackMachBase<T>::pack2(OutputFile *fo, Filter &ft) // append compressed bo
x.size = find_SEGMENT_gap(k, fi->st_size()); x.size = find_SEGMENT_gap(k, fi->st_size());
if (x.size) { if (x.size) {
x.offset = msegcmd[k].fileoff +msegcmd[k].filesize; x.offset = msegcmd[k].fileoff +msegcmd[k].filesize;
packExtent(x, total_in, total_out, 0, fo); packExtent(x, total_in, total_out, nullptr, fo);
} }
} }
@@ -1452,8 +1452,8 @@ void PackMachBase<T>::unpack(OutputFile *fo)
unsigned total_in = 0; unsigned total_in = 0;
unsigned total_out = 0; unsigned total_out = 0;
unsigned c_adler = upx_adler32(NULL, 0); unsigned c_adler = upx_adler32(nullptr, 0);
unsigned u_adler = upx_adler32(NULL, 0); unsigned u_adler = upx_adler32(nullptr, 0);
fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR); fi->seek(- (off_t)(sizeof(bhdr) + ph.c_len), SEEK_CUR);
for (unsigned k = 0; k < ncmds; ++k) { for (unsigned k = 0; k < ncmds; ++k) {
@@ -1546,7 +1546,7 @@ int PackMachBase<T>::canUnpack()
rawmseg = (Mach_segment_command *)rawmseg_buf.getVoidPtr(); rawmseg = (Mach_segment_command *)rawmseg_buf.getVoidPtr();
fi->readx(rawmseg, mhdri.sizeofcmds); fi->readx(rawmseg, mhdri.sizeofcmds);
Mach_segment_command const *ptrTEXT = 0; Mach_segment_command const *ptrTEXT = nullptr;
upx_uint64_t rip = 0; upx_uint64_t rip = 0;
unsigned style = 0; unsigned style = 0;
off_t offLINK = 0; off_t offLINK = 0;
@@ -1903,7 +1903,7 @@ bool PackMachBase<T>::canPack()
if (!n_segment) { if (!n_segment) {
return false; return false;
} }
struct { static struct {
unsigned cputype; unsigned cputype;
unsigned short filetype; unsigned short filetype;
unsigned short sz_stub_entry; unsigned short sz_stub_entry;
@@ -1923,7 +1923,7 @@ bool PackMachBase<T>::canPack()
}, },
{CPU_TYPE_I386, MH_DYLIB, {CPU_TYPE_I386, MH_DYLIB,
sizeof(stub_i386_darwin_dylib_entry), 0, 0, sizeof(stub_i386_darwin_dylib_entry), 0, 0,
stub_i386_darwin_dylib_entry, 0, 0 stub_i386_darwin_dylib_entry, nullptr, nullptr
}, },
{CPU_TYPE_X86_64, MH_EXECUTE, {CPU_TYPE_X86_64, MH_EXECUTE,
sizeof(stub_amd64_darwin_macho_entry), sizeof(stub_amd64_darwin_macho_entry),
@@ -1931,11 +1931,11 @@ bool PackMachBase<T>::canPack()
0, //sizeof(stub_amd64_darwin_macho_upxmain_exe), 0, //sizeof(stub_amd64_darwin_macho_upxmain_exe),
stub_amd64_darwin_macho_entry, stub_amd64_darwin_macho_entry,
stub_amd64_darwin_macho_fold, stub_amd64_darwin_macho_fold,
0 // stub_amd64_darwin_macho_upxmain_exe nullptr // stub_amd64_darwin_macho_upxmain_exe
}, },
{CPU_TYPE_X86_64, MH_DYLIB, {CPU_TYPE_X86_64, MH_DYLIB,
sizeof(stub_amd64_darwin_dylib_entry), 0, 0, sizeof(stub_amd64_darwin_dylib_entry), 0, 0,
stub_amd64_darwin_dylib_entry, 0, 0 stub_amd64_darwin_dylib_entry, nullptr, nullptr
}, },
{CPU_TYPE_ARM, MH_EXECUTE, {CPU_TYPE_ARM, MH_EXECUTE,
sizeof(stub_arm_v5a_darwin_macho_entry), sizeof(stub_arm_v5a_darwin_macho_entry),
@@ -1943,7 +1943,7 @@ bool PackMachBase<T>::canPack()
0, 0,
stub_arm_v5a_darwin_macho_entry, stub_arm_v5a_darwin_macho_entry,
stub_arm_v5a_darwin_macho_fold, stub_arm_v5a_darwin_macho_fold,
0 nullptr
}, },
{CPU_TYPE_ARM64, MH_EXECUTE, {CPU_TYPE_ARM64, MH_EXECUTE,
sizeof(stub_arm64_darwin_macho_entry), sizeof(stub_arm64_darwin_macho_entry),
@@ -1951,7 +1951,7 @@ bool PackMachBase<T>::canPack()
0, 0,
stub_arm64_darwin_macho_entry, stub_arm64_darwin_macho_entry,
stub_arm64_darwin_macho_fold, stub_arm64_darwin_macho_fold,
0 nullptr
}, },
{CPU_TYPE_POWERPC, MH_EXECUTE, {CPU_TYPE_POWERPC, MH_EXECUTE,
sizeof(stub_powerpc_darwin_macho_entry), sizeof(stub_powerpc_darwin_macho_entry),
@@ -1963,7 +1963,7 @@ bool PackMachBase<T>::canPack()
}, },
{CPU_TYPE_POWERPC, MH_DYLIB, {CPU_TYPE_POWERPC, MH_DYLIB,
sizeof(stub_powerpc_darwin_dylib_entry), 0, 0, sizeof(stub_powerpc_darwin_dylib_entry), 0, 0,
stub_powerpc_darwin_dylib_entry, 0, 0 stub_powerpc_darwin_dylib_entry, nullptr, nullptr
}, },
{CPU_TYPE_POWERPC64LE, MH_EXECUTE, {CPU_TYPE_POWERPC64LE, MH_EXECUTE,
sizeof(stub_powerpc64le_darwin_macho_entry), sizeof(stub_powerpc64le_darwin_macho_entry),
@@ -1971,13 +1971,13 @@ bool PackMachBase<T>::canPack()
0, 0,
stub_powerpc64le_darwin_macho_entry, stub_powerpc64le_darwin_macho_entry,
stub_powerpc64le_darwin_macho_fold, stub_powerpc64le_darwin_macho_fold,
0 nullptr
}, },
{CPU_TYPE_POWERPC64LE, MH_DYLIB, {CPU_TYPE_POWERPC64LE, MH_DYLIB,
sizeof(stub_powerpc64le_darwin_dylib_entry), 0, 0, sizeof(stub_powerpc64le_darwin_dylib_entry), 0, 0,
stub_powerpc64le_darwin_dylib_entry, 0, 0 stub_powerpc64le_darwin_dylib_entry, nullptr, nullptr
}, },
{0,0, 0,0,0, 0,0,0} {0,0, 0,0,0, nullptr,nullptr,nullptr}
}; };
for (unsigned j = 0; stub_list[j].cputype; ++j) { for (unsigned j = 0; stub_list[j].cputype; ++j) {
if (stub_list[j].cputype == my_cputype if (stub_list[j].cputype == my_cputype
@@ -2236,7 +2236,7 @@ void PackMachFat::pack(OutputFile *fo)
void PackMachFat::unpack(OutputFile *fo) void PackMachFat::unpack(OutputFile *fo)
{ {
if (fo) { // test mode ("-t") sets fo = NULL if (fo) { // test mode ("-t") sets fo = nullptr
fo->seek(0, SEEK_SET); fo->seek(0, SEEK_SET);
fo->write(&fat_head, sizeof(fat_head.fat) + fo->write(&fat_head, sizeof(fat_head.fat) +
fat_head.fat.nfat_arch * sizeof(fat_head.arch[0])); fat_head.fat.nfat_arch * sizeof(fat_head.arch[0]));
+12 -12
View File
@@ -108,7 +108,7 @@ const int *PackPs1::getCompressionMethods(int method, int level) const
const int *PackPs1::getFilters() const const int *PackPs1::getFilters() const
{ {
return NULL; return nullptr;
} }
Linker* PackPs1::newLinker() const Linker* PackPs1::newLinker() const
@@ -166,7 +166,7 @@ void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsign
ps1_exe_chb_t * p = (ps1_exe_chb_t * )cpr_bh; ps1_exe_chb_t * p = (ps1_exe_chb_t * )cpr_bh;
int r = upx_compress(src, SZ_IH_BKUP, int r = upx_compress(src, SZ_IH_BKUP,
&p->ih_bkup, &sz_cbh, NULL, M_NRV2E_8, 10, NULL, NULL ); &p->ih_bkup, &sz_cbh, nullptr, M_NRV2E_8, 10, nullptr, nullptr );
if (r != UPX_E_OK || sz_cbh >= SZ_IH_BKUP) if (r != UPX_E_OK || sz_cbh >= SZ_IH_BKUP)
throwInternalError("header compression failed"); throwInternalError("header compression failed");
INIT_BH_BKUP(p, sz_cbh); INIT_BH_BKUP(p, sz_cbh);
@@ -193,7 +193,7 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
unsigned sz_bh = SZ_IH_BKUP; unsigned sz_bh = SZ_IH_BKUP;
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len, int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
unc_bh, &sz_bh, M_NRV2E_8, NULL ); unc_bh, &sz_bh, M_NRV2E_8, nullptr );
if (r == UPX_E_OUT_OF_MEMORY) if (r == UPX_E_OUT_OF_MEMORY)
throwOutOfMemoryException(); throwOutOfMemoryException();
if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP) if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP)
@@ -285,7 +285,7 @@ bool PackPs1::canPack()
void PackPs1::buildLoader(const Filter *) void PackPs1::buildLoader(const Filter *)
{ {
const char *method = NULL; const char *method = nullptr;
if (ph.method == M_NRV2B_8) if (ph.method == M_NRV2B_8)
method = isCon ? "nrv2b.small,8bit.sub,nrv.done" : method = isCon ? "nrv2b.small,8bit.sub,nrv.done" :
@@ -329,9 +329,9 @@ void PackPs1::buildLoader(const Filter *)
{ {
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1)); initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
addLoader("decompressor.start", addLoader("decompressor.start",
isCon ? "LZMA_DEC20" : "LZMA_DEC10", "lzma.init", NULL); isCon ? "LZMA_DEC20" : "LZMA_DEC10", "lzma.init", nullptr);
addLoader(sa_tmp > (0x10000 << 2) ? "memset.long" : "memset.short", addLoader(sa_tmp > (0x10000 << 2) ? "memset.long" : "memset.short",
!foundBss ? "con.exit" : "bss.exit", NULL); !foundBss ? "con.exit" : "bss.exit", nullptr);
} }
else else
{ {
@@ -340,7 +340,7 @@ void PackPs1::buildLoader(const Filter *)
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc); sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
unsigned char *cprLoader = New(unsigned char, sz_lcpr); unsigned char *cprLoader = New(unsigned char, sz_lcpr);
int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr, int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr,
NULL, M_NRV2B_8, 10, NULL, NULL ); nullptr, M_NRV2B_8, 10, nullptr, nullptr );
if (r != UPX_E_OK || sz_lcpr >= sz_lunc) if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
throwInternalError("loader compression failed"); throwInternalError("loader compression failed");
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1), initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1),
@@ -362,7 +362,7 @@ void PackPs1::buildLoader(const Filter *)
addLoader(!foundBss ? "con.start" : "bss.con.start", addLoader(!foundBss ? "con.start" : "bss.con.start",
method, method,
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi", ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
"con.entry", "pad.code", "lzma.exec", NULL); "con.entry", "pad.code", "lzma.exec", nullptr);
else else
addLoader(!foundBss ? "con.start" : "bss.con.start", "con.mcpy", addLoader(!foundBss ? "con.start" : "bss.con.start", "con.mcpy",
ph.c_len & 3 ? "con.padcd" : "", ph.c_len & 3 ? "con.padcd" : "",
@@ -370,7 +370,7 @@ void PackPs1::buildLoader(const Filter *)
"con.entry", method, "con.entry", method,
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "", sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
!foundBss ? "con.exit" : "bss.exit", !foundBss ? "con.exit" : "bss.exit",
"pad.code", NULL); "pad.code", nullptr);
} }
else else
{ {
@@ -379,7 +379,7 @@ void PackPs1::buildLoader(const Filter *)
!foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma", !foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma",
method, "cdb.lzma.cpr", method, "cdb.lzma.cpr",
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi", ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
"lzma.exec", NULL); "lzma.exec", nullptr);
else else
{ {
assert(foundBss != true); assert(foundBss != true);
@@ -387,10 +387,10 @@ void PackPs1::buildLoader(const Filter *)
ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi", ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi",
method, method,
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "", sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
"cdb.exit", NULL); "cdb.exit", nullptr);
} }
} }
addLoader("UPX1HEAD", "IDENTSTR", NULL); addLoader("UPX1HEAD", "IDENTSTR", nullptr);
} }
} }
+2 -2
View File
@@ -70,9 +70,9 @@ protected:
__packed_struct(ps1_exe_t) __packed_struct(ps1_exe_t)
// ident string // ident string
char id[8]; char id[8];
// is NULL // is nullptr
LE32 text; LE32 text;
// is NULL // is nullptr
LE32 data; LE32 data;
// initial program counter // initial program counter
LE32 epc; LE32 epc;
+2 -2
View File
@@ -111,7 +111,7 @@ void PackSys::buildLoader(const Filter *ft)
"SYSMAIN3,UPX1HEAD,SYSCUTPO,NRV2B160,NRVDDONE,NRVDECO1", "SYSMAIN3,UPX1HEAD,SYSCUTPO,NRV2B160,NRVDDONE,NRVDECO1",
ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00", ph.max_offset_found <= 0xd00 ? "NRVLED00" : "NRVGTD00",
"NRVDECO2", "NRVDECO2",
NULL nullptr
); );
if (ft->id) if (ft->id)
{ {
@@ -121,7 +121,7 @@ void PackSys::buildLoader(const Filter *ft)
addLoader("SYSMAIN5", addLoader("SYSMAIN5",
opt->cpu == opt->CPU_8086 ? "SYSI0862" : "SYSI2862", opt->cpu == opt->CPU_8086 ? "SYSI0862" : "SYSI2862",
"SYSJUMP1", "SYSJUMP1",
NULL nullptr
); );
} }
+4 -4
View File
@@ -93,22 +93,22 @@ void PackTmt::buildLoader(const Filter *ft)
"TMTMAIN1B", "TMTMAIN1B",
ft->id ? "TMTCALT1" : "", ft->id ? "TMTCALT1" : "",
"TMTMAIN2,UPX1HEAD,TMTCUTPO", "TMTMAIN2,UPX1HEAD,TMTCUTPO",
NULL); nullptr);
// fake alignment for the start of the decompressor // fake alignment for the start of the decompressor
linker->defineSymbol("TMTCUTPO", 0x1000); linker->defineSymbol("TMTCUTPO", 0x1000);
addLoader(getDecompressorSections(), "TMTMAIN5", NULL); addLoader(getDecompressorSections(), "TMTMAIN5", nullptr);
if (ft->id) if (ft->id)
{ {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("TMTCALT2",NULL); addLoader("TMTCALT2",nullptr);
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("TMTRELOC,RELOC320", addLoader("TMTRELOC,RELOC320",
big_relocs ? "REL32BIG" : "", big_relocs ? "REL32BIG" : "",
"RELOC32J,TMTJUMP1", "RELOC32J,TMTJUMP1",
NULL nullptr
); );
} }
+1 -1
View File
@@ -63,7 +63,7 @@ const int *PackTos::getCompressionMethods(int method, int level) const
const int *PackTos::getFilters() const const int *PackTos::getFilters() const
{ {
return NULL; return nullptr;
} }
+10 -10
View File
@@ -93,9 +93,9 @@ void PackUnix::writePackHeader(OutputFile *fo)
set_le32(buf+0, UPX_MAGIC_LE32); set_le32(buf+0, UPX_MAGIC_LE32);
set_le32(buf+4, UPX_MAGIC2_LE32); set_le32(buf+4, UPX_MAGIC2_LE32);
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
patchPackHeader(buf, hsize); patchPackHeader(buf, hsize);
checkPatch(NULL, 0, 0, 0); // reset checkPatch(nullptr, 0, 0, 0); // reset
fo->write(buf, hsize); fo->write(buf, hsize);
} }
@@ -179,7 +179,7 @@ int PackUnix::pack2(OutputFile *fo, Filter &ft)
!!n_block++); // check compression ratio only on first block !!n_block++); // check compression ratio only on first block
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
const upx_bytep tbuf = NULL; const upx_bytep tbuf = nullptr;
if (ft.id == 0) tbuf = ibuf; if (ft.id == 0) tbuf = ibuf;
ph.overlap_overhead = OVERHEAD; ph.overlap_overhead = OVERHEAD;
if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) { if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
@@ -248,7 +248,7 @@ PackUnix::patchLoaderChecksum()
off_t PackUnix::pack3(OutputFile *fo, Filter &ft) off_t PackUnix::pack3(OutputFile *fo, Filter &ft)
{ {
if (0==linker) { if (nullptr==linker) {
// If no filter, then linker is not constructed by side effect // If no filter, then linker is not constructed by side effect
// of packExtent calling compressWithFilters. // of packExtent calling compressWithFilters.
// This is typical after "/usr/bin/patchelf --set-rpath". // This is typical after "/usr/bin/patchelf --set-rpath".
@@ -372,8 +372,8 @@ void PackUnix::packExtent(
} }
if (ph.c_len < ph.u_len) { if (ph.c_len < ph.u_len) {
const upx_bytep tbuf = NULL; const upx_bytep tbuf = nullptr;
if (ft == NULL || ft->id == 0) tbuf = ibuf; if (ft == nullptr || ft->id == 0) tbuf = ibuf;
ph.overlap_overhead = OVERHEAD; ph.overlap_overhead = OVERHEAD;
if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) { if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
// not in-place compressible // not in-place compressible
@@ -394,8 +394,8 @@ void PackUnix::packExtent(
unsigned hdr_c_len = 0; unsigned hdr_c_len = 0;
MemBuffer hdr_obuf; MemBuffer hdr_obuf;
hdr_obuf.allocForCompression(hdr_u_len); hdr_obuf.allocForCompression(hdr_u_len);
int r = upx_compress(hdr_ibuf, hdr_u_len, hdr_obuf, &hdr_c_len, 0, int r = upx_compress(hdr_ibuf, hdr_u_len, hdr_obuf, &hdr_c_len, nullptr,
ph.method, 10, NULL, NULL); ph.method, 10, nullptr, nullptr);
if (r != UPX_E_OK) if (r != UPX_E_OK)
throwInternalError("header compression failed"); throwInternalError("header compression failed");
if (hdr_c_len >= hdr_u_len) if (hdr_c_len >= hdr_u_len)
@@ -566,8 +566,8 @@ void PackUnix::unpack(OutputFile *fo)
? sizeof(bhdr.sz_unc) + sizeof(bhdr.sz_cpr) // old style ? sizeof(bhdr.sz_unc) + sizeof(bhdr.sz_cpr) // old style
: sizeof(bhdr); : sizeof(bhdr);
unsigned c_adler = upx_adler32(NULL, 0); unsigned c_adler = upx_adler32(nullptr, 0);
unsigned u_adler = upx_adler32(NULL, 0); unsigned u_adler = upx_adler32(nullptr, 0);
// defaults for ph.version == 8 // defaults for ph.version == 8
unsigned orig_file_size = 0; unsigned orig_file_size = 0;
+1 -1
View File
@@ -42,7 +42,7 @@ protected:
PackUnix(InputFile *f); PackUnix(InputFile *f);
public: public:
virtual int getVersion() const { return 13; } virtual int getVersion() const { return 13; }
virtual const int *getFilters() const { return NULL; } virtual const int *getFilters() const { return nullptr; }
virtual int getStrategy(Filter &); virtual int getStrategy(Filter &);
virtual void pack(OutputFile *fo); virtual void pack(OutputFile *fo);
+56 -56
View File
@@ -61,10 +61,10 @@ PackVmlinuxBase<T>::PackVmlinuxBase(InputFile *f,
super(f), super(f),
my_e_machine(e_machine), my_elfclass(elfclass), my_elfdata(elfdata), my_e_machine(e_machine), my_elfclass(elfclass), my_elfdata(elfdata),
my_boot_label(boot_label), my_boot_label(boot_label),
n_ptload(0), phdri(NULL), shdri(NULL), shstrtab(NULL) n_ptload(0), phdri(nullptr), shdri(nullptr), shstrtab(nullptr)
{ {
ElfClass::compileTimeAssertions(); ElfClass::compileTimeAssertions();
bele = N_BELE_CTP::getRTP((const BeLePolicy*) NULL); bele = N_BELE_CTP::getRTP((const BeLePolicy*) nullptr);
} }
template <class T> template <class T>
@@ -140,7 +140,7 @@ typename T::Shdr const *PackVmlinuxBase<T>::getElfSections()
return p; return p;
} }
} }
return 0; return nullptr;
} }
template <class T> template <class T>
@@ -173,7 +173,7 @@ bool PackVmlinuxBase<T>::canPack()
// A Linux kernel must have a __ksymtab section. [??] // A Linux kernel must have a __ksymtab section. [??]
Shdr const *p, *const shstrsec = getElfSections(); Shdr const *p, *const shstrsec = getElfSections();
if (0==shstrsec) { if (nullptr==shstrsec) {
return false; return false;
} }
{ {
@@ -230,7 +230,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
Ehdr ehdro; Ehdr ehdro;
TE32 tmp_u32; TE32 tmp_u32;
// NULL // nullptr
// .text(PT_LOADs) .note(1st page) .note(rest) // .text(PT_LOADs) .note(1st page) .note(rest)
// .shstrtab .symtab .strtab // .shstrtab .symtab .strtab
Shdr shdro[1+3+3]; Shdr shdro[1+3+3];
@@ -313,7 +313,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
memcpy(&unc_hdr[sizeof(ehdri)], phdri, sizeof(Phdr) * ehdri.e_phnum); memcpy(&unc_hdr[sizeof(ehdri)], phdri, sizeof(Phdr) * ehdri.e_phnum);
unsigned len_cpr = 0; unsigned len_cpr = 0;
int const r = upx_compress(unc_hdr, len_unc, cpr_hdr, &len_cpr, int const r = upx_compress(unc_hdr, len_unc, cpr_hdr, &len_cpr,
NULL, ph.method, 10, NULL, NULL ); nullptr, ph.method, 10, nullptr, nullptr );
if (UPX_E_OK!=r || len_unc<=len_cpr) // FIXME: allow no compression if (UPX_E_OK!=r || len_unc<=len_cpr) // FIXME: allow no compression
throwInternalError("Ehdr compression failed"); throwInternalError("Ehdr compression failed");
@@ -371,7 +371,7 @@ void PackVmlinuxBase<T>::pack(OutputFile *fo)
} }
compressWithFilters(ibuf, ph.u_len, obuf, compressWithFilters(ibuf, ph.u_len, obuf,
f_ptr, f_len, // filter range f_ptr, f_len, // filter range
NULL, 0, // hdr_ptr, hdr_len nullptr, 0, // hdr_ptr, hdr_len
&ft, 512, &cconf, getStrategy(ft)); &ft, 512, &cconf, getStrategy(ft));
set_be32(&hdr_info.sz_unc, ph.u_len); set_be32(&hdr_info.sz_unc, ph.u_len);
@@ -581,12 +581,12 @@ int PackVmlinuxBase<T>::canUnpack()
// find the .shstrtab section // find the .shstrtab section
Shdr const *const shstrsec = getElfSections(); Shdr const *const shstrsec = getElfSections();
if (0==shstrsec) { if (nullptr==shstrsec) {
return false; return false;
} }
// check for .text .note .note and sane (.sh_size + .sh_offset) // check for .text .note .note and sane (.sh_size + .sh_offset)
p_note0 = p_note1 = p_text = 0; p_note0 = p_note1 = p_text = nullptr;
int j; int j;
Shdr *p; Shdr *p;
for (p= shdri, j= ehdri.e_shnum; --j>=0; ++p) { for (p= shdri, j= ehdri.e_shnum; --j>=0; ++p) {
@@ -599,15 +599,15 @@ int PackVmlinuxBase<T>::canUnpack()
p_text = p; p_text = p;
} }
if (0==strcmp(".note", shstrtab + p->sh_name)) { if (0==strcmp(".note", shstrtab + p->sh_name)) {
if (0==p_note0) { if (nullptr==p_note0) {
p_note0 = p; p_note0 = p;
} else } else
if (0==p_note1) { if (nullptr==p_note1) {
p_note1 = p; p_note1 = p;
} }
} }
} }
if (0==p_text || 0==p_note0 || 0==p_note1) { if (nullptr==p_text || nullptr==p_note0 || nullptr==p_note1) {
return false; return false;
} }
@@ -781,21 +781,21 @@ void PackVmlinuxI386::buildLoader(const Filter *ft)
(0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""), (0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""),
"LXMOVEUP", "LXMOVEUP",
getDecompressorSections(), getDecompressorSections(),
NULL nullptr
); );
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
if (0x40==(0xf0 & ft->id)) { if (0x40==(0xf0 & ft->id)) {
addLoader("LXCKLLT9", NULL); addLoader("LXCKLLT9", nullptr);
} }
else { else {
addLoader("LXCALLT9", NULL); addLoader("LXCALLT9", nullptr);
} }
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX990", addLoader("LINUX990",
((ph.first_offset_found == 1) ? "LINUX991" : ""), ((ph.first_offset_found == 1) ? "LINUX991" : ""),
"LINUX992,IDENTSTR,UPX1HEAD", NULL); "LINUX992,IDENTSTR,UPX1HEAD", nullptr);
} }
void PackVmlinuxAMD64::buildLoader(const Filter *ft) void PackVmlinuxAMD64::buildLoader(const Filter *ft)
@@ -806,21 +806,21 @@ void PackVmlinuxAMD64::buildLoader(const Filter *ft)
(0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""), (0x40==(0xf0 & ft->id)) ? "LXCKLLT1" : (ft->id ? "LXCALLT1" : ""),
"LXMOVEUP", "LXMOVEUP",
getDecompressorSections(), getDecompressorSections(),
NULL nullptr
); );
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
if (0x40==(0xf0 & ft->id)) { if (0x40==(0xf0 & ft->id)) {
addLoader("LXCKLLT9", NULL); addLoader("LXCKLLT9", nullptr);
} }
else { else {
addLoader("LXCALLT9", NULL); addLoader("LXCALLT9", nullptr);
} }
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX990", addLoader("LINUX990",
((ph.first_offset_found == 1) ? "LINUX991" : ""), ((ph.first_offset_found == 1) ? "LINUX991" : ""),
"LINUX992,IDENTSTR,UPX1HEAD", NULL); "LINUX992,IDENTSTR,UPX1HEAD", nullptr);
} }
bool PackVmlinuxARMEL::is_valid_e_entry(Addr e_entry) bool PackVmlinuxARMEL::is_valid_e_entry(Addr e_entry)
@@ -868,69 +868,69 @@ void PackVmlinuxARMEL::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(stub_arm_v5a_linux_kernel_vmlinux, sizeof(stub_arm_v5a_linux_kernel_vmlinux)); initLoader(stub_arm_v5a_linux_kernel_vmlinux, sizeof(stub_arm_v5a_linux_kernel_vmlinux));
addLoader("LINUX000", NULL); addLoader("LINUX000", nullptr);
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("LINUX010", NULL); addLoader("LINUX010", nullptr);
} }
addLoader("LINUX020", NULL); addLoader("LINUX020", nullptr);
if (ft->id) { if (ft->id) {
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX030", NULL); addLoader("LINUX030", nullptr);
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL); if (ph.method == M_NRV2E_8) addLoader("NRV2E", nullptr);
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2B_8) addLoader("NRV2B", nullptr);
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL); else if (ph.method == M_NRV2D_8) addLoader("NRV2D", nullptr);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", nullptr);
else throwBadLoader(); else throwBadLoader();
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
void PackVmlinuxARMEB::buildLoader(const Filter *ft) void PackVmlinuxARMEB::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(stub_armeb_v5a_linux_kernel_vmlinux, sizeof(stub_armeb_v5a_linux_kernel_vmlinux)); initLoader(stub_armeb_v5a_linux_kernel_vmlinux, sizeof(stub_armeb_v5a_linux_kernel_vmlinux));
addLoader("LINUX000", NULL); addLoader("LINUX000", nullptr);
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("LINUX010", NULL); addLoader("LINUX010", nullptr);
} }
addLoader("LINUX020", NULL); addLoader("LINUX020", nullptr);
if (ft->id) { if (ft->id) {
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX030", NULL); addLoader("LINUX030", nullptr);
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL); if (ph.method == M_NRV2E_8) addLoader("NRV2E", nullptr);
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2B_8) addLoader("NRV2B", nullptr);
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL); else if (ph.method == M_NRV2D_8) addLoader("NRV2D", nullptr);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", nullptr);
else throwBadLoader(); else throwBadLoader();
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
void PackVmlinuxPPC32::buildLoader(const Filter *ft) void PackVmlinuxPPC32::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(stub_powerpc_linux_kernel_vmlinux, sizeof(stub_powerpc_linux_kernel_vmlinux)); initLoader(stub_powerpc_linux_kernel_vmlinux, sizeof(stub_powerpc_linux_kernel_vmlinux));
addLoader("LINUX000", NULL); addLoader("LINUX000", nullptr);
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("LINUX010", NULL); addLoader("LINUX010", nullptr);
} }
addLoader("LINUX020", NULL); addLoader("LINUX020", nullptr);
if (ft->id) { if (ft->id) {
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX030", NULL); addLoader("LINUX030", nullptr);
if (ph.method == M_NRV2E_LE32) addLoader("NRV2E,NRV_TAIL", NULL); if (ph.method == M_NRV2E_LE32) addLoader("NRV2E,NRV_TAIL", nullptr);
else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B,NRV_TAIL", NULL); else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B,NRV_TAIL", nullptr);
else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D,NRV_TAIL", NULL); else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D,NRV_TAIL", nullptr);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", nullptr);
else throwBadLoader(); else throwBadLoader();
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
static const static const
@@ -939,25 +939,25 @@ void PackVmlinuxPPC64LE::buildLoader(const Filter *ft)
{ {
// prepare loader // prepare loader
initLoader(stub_powerpc64le_linux_kernel_vmlinux, sizeof(stub_powerpc64le_linux_kernel_vmlinux)); initLoader(stub_powerpc64le_linux_kernel_vmlinux, sizeof(stub_powerpc64le_linux_kernel_vmlinux));
addLoader("LINUX000", NULL); addLoader("LINUX000", nullptr);
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("LINUX010", NULL); addLoader("LINUX010", nullptr);
} }
addLoader("LINUX020", NULL); addLoader("LINUX020", nullptr);
if (ft->id) { if (ft->id) {
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX030", NULL); addLoader("LINUX030", nullptr);
if (ph.method == M_NRV2E_LE32) addLoader("NRV2E,NRV_TAIL", NULL); if (ph.method == M_NRV2E_LE32) addLoader("NRV2E,NRV_TAIL", nullptr);
else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B,NRV_TAIL", NULL); else if (ph.method == M_NRV2B_LE32) addLoader("NRV2B,NRV_TAIL", nullptr);
else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D,NRV_TAIL", NULL); else if (ph.method == M_NRV2D_LE32) addLoader("NRV2D,NRV_TAIL", nullptr);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", NULL); else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00,LZMA_DEC10,LZMA_DEC30", nullptr);
else throwBadLoader(); else throwBadLoader();
if (hasLoaderSection("CFLUSH")) if (hasLoaderSection("CFLUSH"))
addLoader("CFLUSH"); addLoader("CFLUSH");
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
+22 -22
View File
@@ -159,7 +159,7 @@ int PackVmlinuzI386::decompressKernel()
fi->readx(obuf, file_size); fi->readx(obuf, file_size);
{ {
const upx_byte *base = NULL; const upx_byte *base = nullptr;
unsigned relocated = 0; unsigned relocated = 0;
// See startup_32: in linux/arch/i386/boot/compressed/head.S // See startup_32: in linux/arch/i386/boot/compressed/head.S
@@ -270,7 +270,7 @@ int PackVmlinuzI386::decompressKernel()
if (fd < 0) if (fd < 0)
break; break;
gzFile zf = gzdopen(fd, "rb"); gzFile zf = gzdopen(fd, "rb");
if (zf == NULL) if (zf == nullptr)
break; break;
// estimate gzip-decompressed kernel size & alloc buffer // estimate gzip-decompressed kernel size & alloc buffer
if (ibuf.getSize() == 0) if (ibuf.getSize() == 0)
@@ -434,15 +434,15 @@ void PackVmlinuzI386::buildLoader(const Filter *ft)
ft->id ? "LZCALLT1" : "", ft->id ? "LZCALLT1" : "",
"LZIMAGE0", "LZIMAGE0",
getDecompressorSections(), getDecompressorSections(),
NULL nullptr
); );
if (ft->id) if (ft->id)
{ {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("LZCALLT9", NULL); addLoader("LZCALLT9", nullptr);
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUZ990,IDENTSTR,UPX1HEAD", NULL); addLoader("LINUZ990,IDENTSTR,UPX1HEAD", nullptr);
} }
@@ -511,7 +511,7 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
"LINUZ140,LZCUTPOI,LINUZ141", "LINUZ140,LZCUTPOI,LINUZ141",
(ft->id ? "LINUZ145" : ""), (ft->id ? "LINUZ145" : ""),
(ph.first_offset_found == 1 ? "LINUZ010" : ""), (ph.first_offset_found == 1 ? "LINUZ010" : ""),
NULL); nullptr);
} }
else { else {
addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ005", addLoader("LINUZ000,LINUZ001,LINUZVGA,LINUZ005",
@@ -521,26 +521,26 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
"+40", // align the stuff to 4 byte boundary "+40", // align the stuff to 4 byte boundary
"UPX1HEAD", // 32 byte "UPX1HEAD", // 32 byte
"LZCUTPOI", "LZCUTPOI",
NULL); nullptr);
// fake alignment for the start of the decompressor // fake alignment for the start of the decompressor
//linker->defineSymbol("LZCUTPOI", 0x1000); //linker->defineSymbol("LZCUTPOI", 0x1000);
} }
addLoader(getDecompressorSections(), NULL); addLoader(getDecompressorSections(), nullptr);
if (ft->id) if (ft->id)
{ {
assert(ft->calls > 0); assert(ft->calls > 0);
if (0x40==(0xf0 & ft->id)) { if (0x40==(0xf0 & ft->id)) {
addLoader("LZCKLLT9", NULL); addLoader("LZCKLLT9", nullptr);
} }
else { else {
addLoader("LZCALLT9", NULL); addLoader("LZCALLT9", nullptr);
} }
addFilter32(ft->id); addFilter32(ft->id);
} }
if (0!=page_offset) { if (0!=page_offset) {
addLoader("LINUZ150,IDENTSTR,+40,UPX1HEAD", NULL); addLoader("LINUZ150,IDENTSTR,+40,UPX1HEAD", nullptr);
unsigned const l_len = getLoaderSize(); unsigned const l_len = getLoaderSize();
unsigned const c_len = ALIGN_UP(ph.c_len, 4u); unsigned const c_len = ALIGN_UP(ph.c_len, 4u);
unsigned const e_len = getLoaderSectionStart("LINUZ141") - unsigned const e_len = getLoaderSectionStart("LINUZ141") -
@@ -558,7 +558,7 @@ void PackBvmlinuzI386::buildLoader(const Filter *ft)
linker->defineSymbol("unc_offset", ph.overlap_overhead + ph.u_len - c_len); linker->defineSymbol("unc_offset", ph.overlap_overhead + ph.u_len - c_len);
} }
else { else {
addLoader("LINUZ990", NULL); addLoader("LINUZ990", nullptr);
} }
} }
@@ -852,7 +852,7 @@ int PackVmlinuzARMEL::decompressKernel()
if (fd < 0) if (fd < 0)
break; break;
gzFile zf = gzdopen(fd, "rb"); gzFile zf = gzdopen(fd, "rb");
if (zf == NULL) if (zf == nullptr)
break; break;
// estimate gzip-decompressed kernel size & alloc buffer // estimate gzip-decompressed kernel size & alloc buffer
if (ibuf.getSize() == 0) if (ibuf.getSize() == 0)
@@ -929,23 +929,23 @@ void PackVmlinuzARMEL::buildLoader(const Filter *ft)
{ {
// prepare loader; same as vmlinux (with 'x') // prepare loader; same as vmlinux (with 'x')
initLoader(stub_arm_v5a_linux_kernel_vmlinux, sizeof(stub_arm_v5a_linux_kernel_vmlinux)); initLoader(stub_arm_v5a_linux_kernel_vmlinux, sizeof(stub_arm_v5a_linux_kernel_vmlinux));
addLoader("LINUX000", NULL); addLoader("LINUX000", nullptr);
if (ft->id) { if (ft->id) {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader("LINUX010", NULL); addLoader("LINUX010", nullptr);
} }
addLoader("LINUX020", NULL); addLoader("LINUX020", nullptr);
if (ft->id) { if (ft->id) {
addFilter32(ft->id); addFilter32(ft->id);
} }
addLoader("LINUX030", NULL); addLoader("LINUX030", nullptr);
if (ph.method == M_NRV2E_8) addLoader("NRV2E", NULL); if (ph.method == M_NRV2E_8) addLoader("NRV2E", nullptr);
else if (ph.method == M_NRV2B_8) addLoader("NRV2B", NULL); else if (ph.method == M_NRV2B_8) addLoader("NRV2B", nullptr);
else if (ph.method == M_NRV2D_8) addLoader("NRV2D", NULL); else if (ph.method == M_NRV2D_8) addLoader("NRV2D", nullptr);
else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00", else if (M_IS_LZMA(ph.method)) addLoader("LZMA_ELF00",
(opt->small ? "LZMA_DEC10" : "LZMA_DEC20"), "LZMA_DEC30", NULL); (opt->small ? "LZMA_DEC10" : "LZMA_DEC20"), "LZMA_DEC30", nullptr);
else throwBadLoader(); else throwBadLoader();
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
// To debug (2008-09-14): // To debug (2008-09-14):
// Build gdb-6.8-21.fc9.src.rpm; ./configure --target=arm-none-elf; make // Build gdb-6.8-21.fc9.src.rpm; ./configure --target=arm-none-elf; make
+13 -13
View File
@@ -117,13 +117,13 @@ void PackW32Pe::buildLoader(const Filter *ft)
getDecompressorSections(), getDecompressorSections(),
/*multipass ? "PEMULTIP" : */ "", /*multipass ? "PEMULTIP" : */ "",
"PEMAIN10", "PEMAIN10",
NULL nullptr
); );
if (ft->id) if (ft->id)
{ {
const unsigned texv = ih.codebase - rvamin; const unsigned texv = ih.codebase - rvamin;
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader(texv ? "PECTTPOS" : "PECTTNUL",NULL); addLoader(texv ? "PECTTPOS" : "PECTTNUL",nullptr);
addFilter32(ft->id); addFilter32(ft->id);
} }
if (soimport) if (soimport)
@@ -134,7 +134,7 @@ void PackW32Pe::buildLoader(const Filter *ft)
"PEIMPOR2", "PEIMPOR2",
isdll ? "PEIERDLL" : "PEIEREXE", isdll ? "PEIERDLL" : "PEIEREXE",
"PEIMDONE", "PEIMDONE",
NULL nullptr
); );
if (sorelocs) if (sorelocs)
{ {
@@ -142,34 +142,34 @@ void PackW32Pe::buildLoader(const Filter *ft)
"PERELOC3,RELOC320", "PERELOC3,RELOC320",
big_relocs ? "REL32BIG" : "", big_relocs ? "REL32BIG" : "",
"RELOC32J", "RELOC32J",
NULL nullptr
); );
//FIXME: the following should be moved out of the above if //FIXME: the following should be moved out of the above if
addLoader(big_relocs&6 ? "PERLOHI0" : "", addLoader(big_relocs&6 ? "PERLOHI0" : "",
big_relocs&4 ? "PERELLO0" : "", big_relocs&4 ? "PERELLO0" : "",
big_relocs&2 ? "PERELHI0" : "", big_relocs&2 ? "PERELHI0" : "",
NULL nullptr
); );
} }
if (use_dep_hack) if (use_dep_hack)
addLoader("PEDEPHAK", NULL); addLoader("PEDEPHAK", nullptr);
//NEW: TLS callback support PART 1, the callback handler installation - Stefan Widmann //NEW: TLS callback support PART 1, the callback handler installation - Stefan Widmann
if(use_tls_callbacks) if(use_tls_callbacks)
addLoader("PETLSC", NULL); addLoader("PETLSC", nullptr);
addLoader("PEMAIN20", NULL); addLoader("PEMAIN20", nullptr);
if (use_clear_dirty_stack) if (use_clear_dirty_stack)
addLoader("CLEARSTACK", NULL); addLoader("CLEARSTACK", nullptr);
addLoader("PEMAIN21", NULL); addLoader("PEMAIN21", nullptr);
//NEW: last loader sections split up to insert TLS callback handler - Stefan Widmann //NEW: last loader sections split up to insert TLS callback handler - Stefan Widmann
addLoader(ih.entry ? "PEDOJUMP" : "PERETURN", NULL); addLoader(ih.entry ? "PEDOJUMP" : "PERETURN", nullptr);
//NEW: TLS callback support PART 2, the callback handler - Stefan Widmann //NEW: TLS callback support PART 2, the callback handler - Stefan Widmann
if(use_tls_callbacks) if(use_tls_callbacks)
addLoader("PETLSC2", NULL); addLoader("PETLSC2", nullptr);
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
+13 -13
View File
@@ -114,14 +114,14 @@ void PackW64Pep::buildLoader(const Filter *ft)
//getDecompressorSections(), //getDecompressorSections(),
/*multipass ? "PEMULTIP" : */ "", /*multipass ? "PEMULTIP" : */ "",
"PEMAIN10", "PEMAIN10",
NULL nullptr
); );
addLoader(tmp_tlsindex ? "PETLSHAK2" : ""); addLoader(tmp_tlsindex ? "PETLSHAK2" : "");
if (ft->id) if (ft->id)
{ {
const unsigned texv = ih.codebase - rvamin; const unsigned texv = ih.codebase - rvamin;
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader(texv ? "PECTTPOS" : "PECTTNUL",NULL); addLoader(texv ? "PECTTPOS" : "PECTTNUL",nullptr);
addLoader("PEFILTER49"); addLoader("PEFILTER49");
} }
if (soimport) if (soimport)
@@ -132,7 +132,7 @@ void PackW64Pep::buildLoader(const Filter *ft)
"PEIMPOR2", "PEIMPOR2",
isdll ? "PEIERDLL" : "PEIEREXE", isdll ? "PEIERDLL" : "PEIEREXE",
"PEIMDONE", "PEIMDONE",
NULL nullptr
); );
if (sorelocs) if (sorelocs)
{ {
@@ -140,38 +140,38 @@ void PackW64Pep::buildLoader(const Filter *ft)
"PERELOC3", "PERELOC3",
big_relocs ? "REL64BIG" : "", big_relocs ? "REL64BIG" : "",
"RELOC64J", "RELOC64J",
NULL nullptr
); );
if __acc_cte(0) if __acc_cte(0)
{ {
addLoader(big_relocs&6 ? "PERLOHI0" : "", addLoader(big_relocs&6 ? "PERLOHI0" : "",
big_relocs&4 ? "PERELLO0" : "", big_relocs&4 ? "PERELLO0" : "",
big_relocs&2 ? "PERELHI0" : "", big_relocs&2 ? "PERELHI0" : "",
NULL nullptr
); );
} }
} }
if (use_dep_hack) if (use_dep_hack)
addLoader("PEDEPHAK", NULL); addLoader("PEDEPHAK", nullptr);
//NEW: TLS callback support PART 1, the callback handler installation - Stefan Widmann //NEW: TLS callback support PART 1, the callback handler installation - Stefan Widmann
if(use_tls_callbacks) if(use_tls_callbacks)
addLoader("PETLSC", NULL); addLoader("PETLSC", nullptr);
addLoader("PEMAIN20", NULL); addLoader("PEMAIN20", nullptr);
if (use_clear_dirty_stack) if (use_clear_dirty_stack)
addLoader("CLEARSTACK", NULL); addLoader("CLEARSTACK", nullptr);
addLoader("PEMAIN21", NULL); addLoader("PEMAIN21", nullptr);
if (ih.entry && isdll) if (ih.entry && isdll)
addLoader("PEISDLL9"); addLoader("PEISDLL9");
addLoader(ih.entry ? "PEDOJUMP" : "PERETURN", NULL); addLoader(ih.entry ? "PEDOJUMP" : "PERETURN", nullptr);
//NEW: TLS callback support PART 2, the callback handler - Stefan Widmann //NEW: TLS callback support PART 2, the callback handler - Stefan Widmann
if(use_tls_callbacks) if(use_tls_callbacks)
addLoader("PETLSC2", NULL); addLoader("PETLSC2", nullptr);
addLoader("IDENTSTR,UPX1HEAD", NULL); addLoader("IDENTSTR,UPX1HEAD", nullptr);
} }
bool PackW64Pep::handleForceOption() bool PackW64Pep::handleForceOption()
+9 -9
View File
@@ -95,16 +95,16 @@ void PackWcle::buildLoader(const Filter *ft)
initLoader(stub_i386_dos32_watcom_le, sizeof(stub_i386_dos32_watcom_le)); initLoader(stub_i386_dos32_watcom_le, sizeof(stub_i386_dos32_watcom_le));
addLoader("IDENTSTR,WCLEMAIN", addLoader("IDENTSTR,WCLEMAIN",
ph.first_offset_found == 1 ? "WCLEMAIN02" : "", ph.first_offset_found == 1 ? "WCLEMAIN02" : "",
"WCLEMAIN03,UPX1HEAD,WCLECUTP", NULL); "WCLEMAIN03,UPX1HEAD,WCLECUTP", nullptr);
// fake alignment for the start of the decompressor // fake alignment for the start of the decompressor
linker->defineSymbol("WCLECUTP", 0x1000); linker->defineSymbol("WCLECUTP", 0x1000);
addLoader(getDecompressorSections(), "WCLEMAI2", NULL); addLoader(getDecompressorSections(), "WCLEMAI2", nullptr);
if (ft->id) if (ft->id)
{ {
assert(ft->calls > 0); assert(ft->calls > 0);
addLoader(ft->addvalue ? "WCCTTPOS" : "WCCTTNUL", NULL); addLoader(ft->addvalue ? "WCCTTPOS" : "WCCTTNUL", nullptr);
addFilter32(ft->id); addFilter32(ft->id);
} }
#if 1 #if 1
@@ -113,13 +113,13 @@ void PackWcle::buildLoader(const Filter *ft)
addLoader("WCRELOC1,RELOC320", addLoader("WCRELOC1,RELOC320",
big_relocs ? "REL32BIG" : "", big_relocs ? "REL32BIG" : "",
"RELOC32J", "RELOC32J",
NULL nullptr
); );
} }
#endif #endif
addLoader(has_extra_code ? "WCRELSEL" : "", addLoader(has_extra_code ? "WCRELSEL" : "",
"WCLEMAI4", "WCLEMAI4",
NULL nullptr
); );
} }
@@ -178,7 +178,7 @@ void PackWcle::encodeEntryTable()
soentries = ptr_diff(p, ientries) + 1; soentries = ptr_diff(p, ientries) + 1;
oentries = ientries; oentries = ientries;
ientries = NULL; ientries = nullptr;
} }
@@ -425,7 +425,7 @@ void PackWcle::encodeImage(Filter *ft)
memcpy(ibuf,iimage,soimage); memcpy(ibuf,iimage,soimage);
memcpy(ibuf+soimage,ifixups,sofixups); memcpy(ibuf+soimage,ifixups,sofixups);
delete[] ifixups; ifixups = NULL; delete[] ifixups; ifixups = nullptr;
oimage.allocForCompression(isize, RESERVED+512); oimage.allocForCompression(isize, RESERVED+512);
// prepare packheader // prepare packheader
@@ -437,7 +437,7 @@ void PackWcle::encodeImage(Filter *ft)
compressWithFilters(ibuf, isize, compressWithFilters(ibuf, isize,
oimage + RESERVED, oimage + RESERVED,
ibuf + ft->addvalue, ft->buf_len, ibuf + ft->addvalue, ft->buf_len,
NULL, 0, nullptr, 0,
ft, 512, &cconf, 0); ft, 512, &cconf, 0);
ibuf.dealloc(); ibuf.dealloc();
@@ -766,7 +766,7 @@ void PackWcle::decodeEntryTable()
soentries = ptr_diff(p, ientries) + 1; soentries = ptr_diff(p, ientries) + 1;
oentries = ientries; oentries = ientries;
ientries = NULL; ientries = nullptr;
} }
+25 -25
View File
@@ -39,12 +39,12 @@
**************************************************************************/ **************************************************************************/
Packer::Packer(InputFile *f) : Packer::Packer(InputFile *f) :
bele(NULL), bele(nullptr),
fi(f), file_size(-1), ph_format(-1), ph_version(-1), fi(f), file_size(-1), ph_format(-1), ph_version(-1),
uip(NULL), linker(NULL), uip(nullptr), linker(nullptr),
last_patch(NULL), last_patch_len(0), last_patch_off(0) last_patch(nullptr), last_patch_len(0), last_patch_off(0)
{ {
if (fi != NULL) if (fi != nullptr)
file_size = fi->st_size(); file_size = fi->st_size();
uip = new UiPacker(this); uip = new UiPacker(this);
mem_clear(&ph, sizeof(ph)); mem_clear(&ph, sizeof(ph));
@@ -53,8 +53,8 @@ Packer::Packer(InputFile *f) :
Packer::~Packer() Packer::~Packer()
{ {
delete uip; uip = NULL; delete uip; uip = nullptr;
delete linker; linker = NULL; delete linker; linker = nullptr;
} }
@@ -68,9 +68,9 @@ void Packer::assertPacker() const
assert(strlen(getName()) <= 15); assert(strlen(getName()) <= 15);
// info: 36 is the limit for show_all_packers() in help.cpp // info: 36 is the limit for show_all_packers() in help.cpp
assert(strlen(getFullName(opt)) <= 32); assert(strlen(getFullName(opt)) <= 32);
assert(strlen(getFullName(NULL)) <= 32); assert(strlen(getFullName(nullptr)) <= 32);
if (bele == NULL) fprintf(stderr, "%s\n", getName()); if (bele == nullptr) fprintf(stderr, "%s\n", getName());
assert(bele != NULL); assert(bele != nullptr);
if (getFormat() != UPX_F_MACH_FAT) // macho/fat is multiarch if (getFormat() != UPX_F_MACH_FAT) // macho/fat is multiarch
{ {
const N_BELE_RTP::AbstractPolicy *format_bele; const N_BELE_RTP::AbstractPolicy *format_bele;
@@ -136,7 +136,7 @@ void Packer::doFileInfo()
void Packer::test() void Packer::test()
{ {
unpack(NULL); unpack(nullptr);
} }
@@ -639,11 +639,11 @@ unsigned Packer::getRandomId() const
while (id == 0) while (id == 0)
{ {
#if !(HAVE_GETTIMEOFDAY) || ((ACC_OS_DOS32) && defined(__DJGPP__)) #if !(HAVE_GETTIMEOFDAY) || ((ACC_OS_DOS32) && defined(__DJGPP__))
id ^= (unsigned) time(NULL); id ^= (unsigned) time(nullptr);
id ^= ((unsigned) clock()) << 12; id ^= ((unsigned) clock()) << 12;
#else #else
struct timeval tv; struct timeval tv;
gettimeofday(&tv, 0); gettimeofday(&tv, nullptr);
id ^= (unsigned) tv.tv_sec; id ^= (unsigned) tv.tv_sec;
id ^= ((unsigned) tv.tv_usec) << 12; // shift into high-bits id ^= ((unsigned) tv.tv_usec) << 12; // shift into high-bits
#endif #endif
@@ -670,7 +670,7 @@ void Packer::initPackHeader()
ph.format = getFormat(); ph.format = getFormat();
ph.method = M_NONE; ph.method = M_NONE;
ph.level = -1; ph.level = -1;
ph.u_adler = ph.c_adler = ph.saved_u_adler = ph.saved_c_adler = upx_adler32(NULL,0); ph.u_adler = ph.c_adler = ph.saved_u_adler = ph.saved_c_adler = upx_adler32(nullptr,0);
ph.buf_offset = 0; ph.buf_offset = 0;
ph.u_file_size = file_size; ph.u_file_size = file_size;
} }
@@ -788,15 +788,15 @@ void Packer::checkAlreadyPacked(const void *b, int blen)
void Packer::checkPatch(void *b, int blen, int boff, int size) void Packer::checkPatch(void *b, int blen, int boff, int size)
{ {
if (b == NULL && blen == 0 && boff == 0 && size == 0) if (b == nullptr && blen == 0 && boff == 0 && size == 0)
{ {
// reset // reset
last_patch = NULL; last_patch = nullptr;
last_patch_len = 0; last_patch_len = 0;
last_patch_off = 0; last_patch_off = 0;
return; return;
} }
if (b == NULL || blen <= 0 || boff < 0 || size <= 0) if (b == nullptr || blen <= 0 || boff < 0 || size <= 0)
throwBadLoader(); throwBadLoader();
if (boff + size <= 0 || boff + size > blen) if (boff + size <= 0 || boff + size > blen)
throwBadLoader(); throwBadLoader();
@@ -1091,7 +1091,7 @@ static const char *getIdentstr(unsigned *size, int small)
{ identbig, (int)sizeof(identbig) }, { identbig, (int)sizeof(identbig) },
{ identsmall, (int)sizeof(identsmall) }, { identsmall, (int)sizeof(identsmall) },
{ identtiny, (int)sizeof(identtiny) }, { identtiny, (int)sizeof(identtiny) },
{ NULL, 0 } }; { nullptr, 0 } };
const strinfo_t* iter; const strinfo_t* iter;
for (iter = strlist; iter->s; ++iter) for (iter = strlist; iter->s; ++iter)
@@ -1139,7 +1139,7 @@ void Packer::initLoader(const void *pdata, int plen, int small)
#define C const char * #define C const char *
#define N ACC_STATIC_CAST(void *, 0) #define N ACC_STATIC_CAST(void *, nullptr)
void Packer::addLoader(C a) void Packer::addLoader(C a)
{ addLoaderVA(a, N); } { addLoaderVA(a, N); }
void Packer::addLoader(C a, C b) void Packer::addLoader(C a, C b)
@@ -1175,7 +1175,7 @@ upx_byte *Packer::getLoader() const
{ {
int size = -1; int size = -1;
upx_byte *oloader = linker->getLoader(&size); upx_byte *oloader = linker->getLoader(&size);
if (oloader == NULL || size <= 0) if (oloader == nullptr || size <= 0)
throwBadLoader(); throwBadLoader();
return oloader; return oloader;
} }
@@ -1184,7 +1184,7 @@ int Packer::getLoaderSize() const
{ {
int size = -1; int size = -1;
upx_byte *oloader = linker->getLoader(&size); upx_byte *oloader = linker->getLoader(&size);
if (oloader == NULL || size <= 0) if (oloader == nullptr || size <= 0)
throwBadLoader(); throwBadLoader();
return size; return size;
} }
@@ -1192,7 +1192,7 @@ int Packer::getLoaderSize() const
bool Packer::hasLoaderSection(const char *name) const bool Packer::hasLoaderSection(const char *name) const
{ {
void *section = linker->findSection(name, false); void *section = linker->findSection(name, false);
return section != NULL; return section != nullptr;
} }
int Packer::getLoaderSection(const char *name, int *slen) const int Packer::getLoaderSection(const char *name, int *slen) const
@@ -1289,7 +1289,7 @@ void Packer::relocateLoader()
static int prepareMethods(int *methods, int ph_method, const int *all_methods) static int prepareMethods(int *methods, int ph_method, const int *all_methods)
{ {
int nmethods = 0; int nmethods = 0;
if (!opt->all_methods || all_methods == NULL) if (!opt->all_methods || all_methods == nullptr)
{ {
methods[nmethods++] = ph_method; methods[nmethods++] = ph_method;
return nmethods; return nmethods;
@@ -1431,7 +1431,7 @@ void Packer::compressWithFilters(upx_bytep i_ptr, unsigned i_len,
{ {
assert(isValidCompressionMethod(methods[mm])); assert(isValidCompressionMethod(methods[mm]));
unsigned hdr_c_len = 0; unsigned hdr_c_len = 0;
if (hdr_ptr != NULL && hdr_len) if (hdr_ptr != nullptr && hdr_len)
{ {
if (nfilters_success_total != 0 && o_tmp == o_ptr) if (nfilters_success_total != 0 && o_tmp == o_ptr)
{ {
@@ -1440,7 +1440,7 @@ void Packer::compressWithFilters(upx_bytep i_ptr, unsigned i_len,
o_tmp = o_tmp_buf; o_tmp = o_tmp_buf;
} }
int r = upx_compress(hdr_ptr, hdr_len, o_tmp, &hdr_c_len, int r = upx_compress(hdr_ptr, hdr_len, o_tmp, &hdr_c_len,
NULL, methods[mm], 10, NULL, NULL); nullptr, methods[mm], 10, nullptr, nullptr);
if (r != UPX_E_OK) if (r != UPX_E_OK)
throwInternalError("header compression failed"); throwInternalError("header compression failed");
if (hdr_c_len >= hdr_len) if (hdr_c_len >= hdr_len)
@@ -1584,7 +1584,7 @@ void Packer::compressWithFilters(Filter *ft,
bool inhibit_compression_check) bool inhibit_compression_check)
{ {
compressWithFilters(ft, overlap_range, cconf, filter_strategy, compressWithFilters(ft, overlap_range, cconf, filter_strategy,
0, 0, 0, NULL, 0, inhibit_compression_check); 0, 0, 0, nullptr, 0, inhibit_compression_check);
} }
+8 -8
View File
@@ -170,9 +170,9 @@ public:
protected: protected:
// main compression drivers // main compression drivers
virtual bool compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr, virtual bool compress(upx_bytep i_ptr, unsigned i_len, upx_bytep o_ptr,
const upx_compress_config_t *cconf = NULL); const upx_compress_config_t *cconf = nullptr);
virtual void decompress(const upx_bytep in, upx_bytep out, virtual void decompress(const upx_bytep in, upx_bytep out,
bool verify_checksum = true, Filter *ft = NULL); bool verify_checksum = true, Filter *ft = nullptr);
virtual bool checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const; virtual bool checkDefaultCompressionRatio(unsigned u_len, unsigned c_len) const;
virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const; virtual bool checkCompressionRatio(unsigned u_len, unsigned c_len) const;
virtual bool checkFinalCompressionRatio(const OutputFile *fo) const; virtual bool checkFinalCompressionRatio(const OutputFile *fo) const;
@@ -214,8 +214,8 @@ protected:
unsigned range = 0, unsigned range = 0,
unsigned upper_limit = ~0u) const; unsigned upper_limit = ~0u) const;
// destructive decompress + verify // destructive decompress + verify
void verifyOverlappingDecompression(Filter *ft = NULL); void verifyOverlappingDecompression(Filter *ft = nullptr);
void verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft = NULL); void verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft = nullptr);
// packheader handling // packheader handling
virtual int patchPackHeader(void *b, int blen); virtual int patchPackHeader(void *b, int blen);
@@ -244,8 +244,8 @@ protected:
void __acc_cdecl_va addLoaderVA(const char *s, ...); void __acc_cdecl_va addLoaderVA(const char *s, ...);
#endif #endif
virtual bool hasLoaderSection(const char *name) const; virtual bool hasLoaderSection(const char *name) const;
virtual int getLoaderSection(const char *name, int *slen=NULL) const; virtual int getLoaderSection(const char *name, int *slen=nullptr) const;
virtual int getLoaderSectionStart(const char *name, int *slen=NULL) const; virtual int getLoaderSectionStart(const char *name, int *slen=nullptr) const;
// compression handling [see packer_c.cpp] // compression handling [see packer_c.cpp]
public: public:
@@ -325,8 +325,8 @@ private:
private: private:
// disable copy and assignment // disable copy and assignment
Packer(const Packer &); // {} Packer(const Packer &) = delete;
Packer& operator= (const Packer &); // { return *this; } Packer& operator= (const Packer &) = delete;
}; };
+1 -1
View File
@@ -228,7 +228,7 @@ const char *Packer::getDecompressorSections() const
return opt->small ? lzma_small : lzma_fast; return opt->small ? lzma_small : lzma_fast;
} }
throwInternalError("bad decompressor"); throwInternalError("bad decompressor");
return NULL; return nullptr;
} }
+75 -75
View File
@@ -76,7 +76,7 @@ void Packer::addFilter32(int filter_id)
addLoader("ctok32.00", addLoader("ctok32.00",
((0x50==filter_id) ? "ctok32.50" : ((0x50==filter_id) ? "ctok32.50" :
(0x51==filter_id) ? "ctok32.51" : ""), (0x51==filter_id) ? "ctok32.51" : ""),
"ctok32.10", NULL); "ctok32.10", nullptr);
} }
else if ((filter_id & 0xf) % 3 == 0) { else if ((filter_id & 0xf) % 3 == 0) {
if (filter_id < 0x40) { if (filter_id < 0x40) {
@@ -85,19 +85,19 @@ void Packer::addFilter32(int filter_id)
"CALLTR01", "CALLTR01",
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01,CTBSWA01" : "CTBROR01,CTBSWA01") : "", (filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR01,CTBSWA01" : "CTBROR01,CTBSWA01") : "",
"CALLTR02", "CALLTR02",
NULL nullptr
); );
} }
else if (0x40==(0xF0 & filter_id)) { else if (0x40==(0xF0 & filter_id)) {
addLoader("ctok32.00", NULL); addLoader("ctok32.00", nullptr);
if (9<=(0xf & filter_id)) { if (9<=(0xf & filter_id)) {
addLoader("ctok32.10", NULL); addLoader("ctok32.10", nullptr);
} }
addLoader("ctok32.20", NULL); addLoader("ctok32.20", nullptr);
if (9<=(0xf & filter_id)) { if (9<=(0xf & filter_id)) {
addLoader("ctok32.30", NULL); addLoader("ctok32.30", nullptr);
} }
addLoader("ctok32.40", NULL); addLoader("ctok32.40", nullptr);
} }
} }
else else
@@ -108,7 +108,7 @@ void Packer::addFilter32(int filter_id)
"CALLTR12", "CALLTR12",
(filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11,CTBSWA11" : "CTBROR11,CTBSWA11") : "", (filter_id & 0xf) > 3 ? (filter_id > 0x20 ? "CTBSHR11,CTBSWA11" : "CTBROR11,CTBSWA11") : "",
"CALLTR13", "CALLTR13",
NULL nullptr
); );
} }
if (0x80==(filter_id & 0xF0)) { if (0x80==(filter_id & 0xF0)) {
@@ -120,187 +120,187 @@ void Packer::addFilter32(int filter_id)
unsigned const f_jcc2 = f80_jcc2(filter_id); unsigned const f_jcc2 = f80_jcc2(filter_id);
if (NOFILT!=f_jcc2) { if (NOFILT!=f_jcc2) {
addLoader("LXJCC010", NULL); addLoader("LXJCC010", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LXMRU045", NULL); addLoader("LXMRU045", nullptr);
} }
else { else {
addLoader("LXMRU046", NULL); addLoader("LXMRU046", nullptr);
} }
if (0==n_mru || MRUFLT!=f_jcc2) { if (0==n_mru || MRUFLT!=f_jcc2) {
addLoader("LXJCC020", NULL); addLoader("LXJCC020", nullptr);
} }
else { // 0!=n_mru else { // 0!=n_mru
addLoader("LXJCC021", NULL); addLoader("LXJCC021", nullptr);
} }
if (NOFILT!=f_jcc2) { if (NOFILT!=f_jcc2) {
addLoader("LXJCC023", NULL); addLoader("LXJCC023", nullptr);
} }
} }
addLoader("LXUNF037", NULL); addLoader("LXUNF037", nullptr);
if (x386) { if (x386) {
if (n_mru) { if (n_mru) {
addLoader("LXUNF386", NULL); addLoader("LXUNF386", nullptr);
} }
addLoader("LXUNF387", NULL); addLoader("LXUNF387", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LXUNF388", NULL); addLoader("LXUNF388", nullptr);
} }
} }
else { else {
addLoader("LXUNF486", NULL); addLoader("LXUNF486", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LXUNF487", NULL); addLoader("LXUNF487", nullptr);
} }
} }
if (n_mru) { if (n_mru) {
addLoader("LXMRU065", NULL); addLoader("LXMRU065", nullptr);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE3", NULL); addLoader("MRUBYTE3", nullptr);
} }
else { else {
addLoader("MRUARB30", NULL); addLoader("MRUARB30", nullptr);
if (mrupwr2) { if (mrupwr2) {
addLoader("MRUBITS3", NULL); addLoader("MRUBITS3", nullptr);
} }
else { else {
addLoader("MRUARB40", NULL); addLoader("MRUARB40", nullptr);
} }
} }
addLoader("LXMRU070", NULL); addLoader("LXMRU070", nullptr);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE4", NULL); addLoader("MRUBYTE4", nullptr);
} }
else if (mrupwr2) { else if (mrupwr2) {
addLoader("MRUBITS4", NULL); addLoader("MRUBITS4", nullptr);
} }
else { else {
addLoader("MRUARB50", NULL); addLoader("MRUARB50", nullptr);
} }
addLoader("LXMRU080", NULL); addLoader("LXMRU080", nullptr);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE5", NULL); addLoader("MRUBYTE5", nullptr);
} }
else { else {
addLoader("MRUARB60", NULL); addLoader("MRUARB60", nullptr);
if (mrupwr2) { if (mrupwr2) {
addLoader("MRUBITS5", NULL); addLoader("MRUBITS5", nullptr);
} }
else { else {
addLoader("MRUARB70", NULL); addLoader("MRUARB70", nullptr);
} }
} }
addLoader("LXMRU090", NULL); addLoader("LXMRU090", nullptr);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE6", NULL); addLoader("MRUBYTE6", nullptr);
} }
else { else {
addLoader("MRUARB80", NULL); addLoader("MRUARB80", nullptr);
if (mrupwr2) { if (mrupwr2) {
addLoader("MRUBITS6", NULL); addLoader("MRUBITS6", nullptr);
} }
else { else {
addLoader("MRUARB90", NULL); addLoader("MRUARB90", nullptr);
} }
} }
addLoader("LXMRU100", NULL); addLoader("LXMRU100", nullptr);
} }
addLoader("LXUNF040", NULL); addLoader("LXUNF040", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LXMRU110", NULL); addLoader("LXMRU110", nullptr);
} }
else { else {
addLoader("LXMRU111", NULL); addLoader("LXMRU111", nullptr);
} }
addLoader("LXUNF041", NULL); addLoader("LXUNF041", nullptr);
addLoader("LXUNF042", NULL); addLoader("LXUNF042", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LXMRU010", NULL); addLoader("LXMRU010", nullptr);
if (NOFILT!=f_jmp1 && NOFILT==f_call) { if (NOFILT!=f_jmp1 && NOFILT==f_call) {
addLoader("LXJMPA00", NULL); addLoader("LXJMPA00", nullptr);
} }
else { else {
addLoader("LXCALLB0", NULL); addLoader("LXCALLB0", nullptr);
} }
addLoader("LXUNF021", NULL); addLoader("LXUNF021", nullptr);
} }
else { else {
addLoader("LXMRU022", NULL); addLoader("LXMRU022", nullptr);
if (NOFILT!=f_jmp1 && NOFILT==f_call) { if (NOFILT!=f_jmp1 && NOFILT==f_call) {
addLoader("LXJMPA01", NULL); addLoader("LXJMPA01", nullptr);
} }
else { else {
addLoader("LXCALLB1", NULL); addLoader("LXCALLB1", nullptr);
} }
} }
if (n_mru) { if (n_mru) {
if (256!=n_mru && mrupwr2) { if (256!=n_mru && mrupwr2) {
addLoader("MRUBITS1", NULL); addLoader("MRUBITS1", nullptr);
} }
addLoader("LXMRU030", NULL); addLoader("LXMRU030", nullptr);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE1", NULL); addLoader("MRUBYTE1", nullptr);
} }
else { else {
addLoader("MRUARB10", NULL); addLoader("MRUARB10", nullptr);
} }
addLoader("LXMRU040", NULL); addLoader("LXMRU040", nullptr);
} }
addLoader("LXUNF030", NULL); addLoader("LXUNF030", nullptr);
if (NOFILT!=f_jcc2) { if (NOFILT!=f_jcc2) {
addLoader("LXJCC000", NULL); addLoader("LXJCC000", nullptr);
} }
if (NOFILT!=f_call || NOFILT!=f_jmp1) { // at least one is filtered if (NOFILT!=f_call || NOFILT!=f_jmp1) { // at least one is filtered
// shift opcode origin to zero // shift opcode origin to zero
if (0==n_mru) { if (0==n_mru) {
addLoader("LXCJ0MRU", NULL); addLoader("LXCJ0MRU", nullptr);
} }
else { else {
addLoader("LXCJ1MRU", NULL); addLoader("LXCJ1MRU", nullptr);
} }
// determine if in range // determine if in range
if ((NOFILT!=f_call) && (NOFILT!=f_jmp1)) { // unfilter both if ((NOFILT!=f_call) && (NOFILT!=f_jmp1)) { // unfilter both
addLoader("LXCALJMP", NULL); addLoader("LXCALJMP", nullptr);
} }
if ((NOFILT==f_call) ^ (NOFILT==f_jmp1)) { // unfilter just one if ((NOFILT==f_call) ^ (NOFILT==f_jmp1)) { // unfilter just one
if (0==n_mru) { if (0==n_mru) {
addLoader("LXCALL00", NULL); addLoader("LXCALL00", nullptr);
} }
else { else {
addLoader("LXCALL01", NULL); addLoader("LXCALL01", nullptr);
} }
} }
// determine if mru applies // determine if mru applies
if (0==n_mru || ! ((FNOMRU==f_call) || (FNOMRU==f_jmp1)) ) { if (0==n_mru || ! ((FNOMRU==f_call) || (FNOMRU==f_jmp1)) ) {
addLoader("LXCJ2MRU", NULL); // no mru, or no exceptions addLoader("LXCJ2MRU", nullptr); // no mru, or no exceptions
} }
else { // mru on one, but not the other else { // mru on one, but not the other
addLoader("LXCJ4MRU", NULL); addLoader("LXCJ4MRU", nullptr);
if (MRUFLT==f_jmp1) { // JMP only if (MRUFLT==f_jmp1) { // JMP only
addLoader("LXCJ6MRU", NULL); addLoader("LXCJ6MRU", nullptr);
} else } else
if (MRUFLT==f_call) { // CALL only if (MRUFLT==f_call) { // CALL only
addLoader("LXCJ7MRU", NULL); addLoader("LXCJ7MRU", nullptr);
} }
addLoader("LXCJ8MRU", NULL); addLoader("LXCJ8MRU", nullptr);
} }
} }
addLoader("LXUNF034", NULL); addLoader("LXUNF034", nullptr);
if (n_mru) { if (n_mru) {
addLoader("LXMRU055", NULL); addLoader("LXMRU055", nullptr);
if (256==n_mru) { if (256==n_mru) {
addLoader("MRUBYTE2", NULL); addLoader("MRUBYTE2", nullptr);
} }
else if (mrupwr2) { else if (mrupwr2) {
addLoader("MRUBITS2", NULL); addLoader("MRUBITS2", nullptr);
} }
else if (n_mru) { else if (n_mru) {
addLoader("MRUARB20", NULL); addLoader("MRUARB20", nullptr);
} }
addLoader("LXMRU057", NULL); addLoader("LXMRU057", nullptr);
} }
} }
} }
+19 -19
View File
@@ -57,7 +57,7 @@
// //
**************************************************************************/ **************************************************************************/
PackMaster::PackMaster(InputFile *f, options_t *o) : fi(f), p(NULL) { PackMaster::PackMaster(InputFile *f, options_t *o) : fi(f), p(nullptr) {
// replace global options with local options // replace global options with local options
saved_opt = o; saved_opt = o;
if (o) { if (o) {
@@ -67,13 +67,13 @@ PackMaster::PackMaster(InputFile *f, options_t *o) : fi(f), p(NULL) {
} }
PackMaster::~PackMaster() { PackMaster::~PackMaster() {
fi = NULL; fi = nullptr;
delete p; delete p;
p = NULL; p = nullptr;
// restore global options // restore global options
if (saved_opt) if (saved_opt)
opt = saved_opt; opt = saved_opt;
saved_opt = NULL; saved_opt = nullptr;
} }
/************************************************************************* /*************************************************************************
@@ -81,8 +81,8 @@ PackMaster::~PackMaster() {
**************************************************************************/ **************************************************************************/
static Packer *try_pack(Packer *p, void *user) { static Packer *try_pack(Packer *p, void *user) {
if (p == NULL) if (p == nullptr)
return NULL; return nullptr;
InputFile *f = (InputFile *) user; InputFile *f = (InputFile *) user;
p->assertPacker(); p->assertPacker();
try { try {
@@ -100,12 +100,12 @@ static Packer *try_pack(Packer *p, void *user) {
throw; throw;
} }
delete p; delete p;
return NULL; return nullptr;
} }
static Packer *try_unpack(Packer *p, void *user) { static Packer *try_unpack(Packer *p, void *user) {
if (p == NULL) if (p == nullptr)
return NULL; return nullptr;
InputFile *f = (InputFile *) user; InputFile *f = (InputFile *) user;
p->assertPacker(); p->assertPacker();
try { try {
@@ -126,7 +126,7 @@ static Packer *try_unpack(Packer *p, void *user) {
throw; throw;
} }
delete p; delete p;
return NULL; return nullptr;
} }
/************************************************************************* /*************************************************************************
@@ -135,7 +135,7 @@ static Packer *try_unpack(Packer *p, void *user) {
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 = nullptr;
#define D(Klass) \ #define D(Klass) \
ACC_BLOCK_BEGIN \ ACC_BLOCK_BEGIN \
@@ -143,7 +143,7 @@ Packer *PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
if (o->debug.debug_level) \ if (o->debug.debug_level) \
fprintf(stderr, "visitAllPackers: (ver=%d, fmt=%3d) %s\n", kp->getVersion(), \ fprintf(stderr, "visitAllPackers: (ver=%d, fmt=%3d) %s\n", kp->getVersion(), \
kp->getFormat(), #Klass); \ kp->getFormat(), #Klass); \
if ((p = func(kp, user)) != NULL) \ if ((p = func(kp, user)) != nullptr) \
return p; \ return p; \
ACC_BLOCK_END ACC_BLOCK_END
@@ -232,7 +232,7 @@ Packer *PackMaster::visitAllPackers(visit_func_t func, InputFile *f, const optio
// D(PackDylibI386); // D(PackDylibI386);
// D(PackDylibPPC32); // D(PackDylibPPC32);
return NULL; return nullptr;
#undef D #undef D
} }
@@ -258,26 +258,26 @@ Packer *PackMaster::getUnpacker(InputFile *f) {
void PackMaster::pack(OutputFile *fo) { void PackMaster::pack(OutputFile *fo) {
p = getPacker(fi); p = getPacker(fi);
fi = NULL; fi = nullptr;
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 = nullptr;
p->doUnpack(fo); p->doUnpack(fo);
} }
void PackMaster::test() { void PackMaster::test() {
p = getUnpacker(fi); p = getUnpacker(fi);
fi = NULL; fi = nullptr;
p->doTest(); p->doTest();
} }
void PackMaster::list() { void PackMaster::list() {
p = getUnpacker(fi); p = getUnpacker(fi);
fi = NULL; fi = nullptr;
p->doList(); p->doList();
} }
@@ -286,9 +286,9 @@ void PackMaster::fileInfo() {
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(nullptr, 1); // make a warning here
p->assertPacker(); p->assertPacker();
fi = NULL; fi = nullptr;
p->doFileInfo(); p->doFileInfo();
} }
+1 -1
View File
@@ -38,7 +38,7 @@ class OutputFile;
class PackMaster { class PackMaster {
public: public:
PackMaster(InputFile *f, options_t *o = NULL); PackMaster(InputFile *f, options_t *o = nullptr);
virtual ~PackMaster(); virtual ~PackMaster();
void pack(OutputFile *fo); void pack(OutputFile *fo);
+51 -49
View File
@@ -52,7 +52,7 @@
static void xcheck(const void *p) static void xcheck(const void *p)
{ {
if (!p) if (!p)
throwCantUnpack("unexpected NULL pointer; take care!"); throwCantUnpack("unexpected nullptr pointer; take care!");
} }
static void xcheck(const void *p, size_t plen, const void *b, size_t blen) static void xcheck(const void *p, size_t plen, const void *b, size_t blen)
{ {
@@ -92,14 +92,14 @@ PeFile::PeFile(InputFile *f) : super(f)
COMPILE_TIME_ASSERT_ALIGNED1(pe_section_t) COMPILE_TIME_ASSERT_ALIGNED1(pe_section_t)
COMPILE_TIME_ASSERT(RT_LAST == TABLESIZE(opt->win32_pe.compress_rt)) COMPILE_TIME_ASSERT(RT_LAST == TABLESIZE(opt->win32_pe.compress_rt))
isection = NULL; isection = nullptr;
oimport = NULL; oimport = nullptr;
oimpdlls = NULL; oimpdlls = nullptr;
orelocs = NULL; orelocs = nullptr;
oexport = NULL; oexport = nullptr;
otls = NULL; otls = nullptr;
oresources = NULL; oresources = nullptr;
oxrelocs = NULL; oxrelocs = nullptr;
icondir_offset = 0; icondir_offset = 0;
icondir_count = 0; icondir_count = 0;
importbyordinal = false; importbyordinal = false;
@@ -110,9 +110,9 @@ PeFile::PeFile(InputFile *f) : super(f)
soxrelocs = 0; soxrelocs = 0;
sotls = 0; sotls = 0;
isdll = false; isdll = false;
ilinker = NULL; ilinker = nullptr;
use_tls_callbacks = false; use_tls_callbacks = false;
oloadconf = NULL; oloadconf = nullptr;
soloadconf = 0; soloadconf = 0;
use_dep_hack = true; use_dep_hack = true;
@@ -194,7 +194,7 @@ int PeFile::readFileHeader()
// interval handling // interval handling
**************************************************************************/ **************************************************************************/
PeFile::Interval::Interval(void *b) : capacity(0),base(b),ivarr(NULL),ivnum(0) PeFile::Interval::Interval(void *b) : capacity(0),base(b),ivarr(nullptr),ivnum(0)
{} {}
PeFile::Interval::~Interval() PeFile::Interval::~Interval()
@@ -286,7 +286,7 @@ void PeFile::Reloc::newRelocPos(void *p)
} }
PeFile::Reloc::Reloc(upx_byte *s,unsigned si) : PeFile::Reloc::Reloc(upx_byte *s,unsigned si) :
start(s), size(si), rel(NULL), rel1(NULL) start(s), size(si), rel(nullptr), rel1(nullptr)
{ {
COMPILE_TIME_ASSERT(sizeof(reloc) == 8) COMPILE_TIME_ASSERT(sizeof(reloc) == 8)
COMPILE_TIME_ASSERT_ALIGNED1(reloc) COMPILE_TIME_ASSERT_ALIGNED1(reloc)
@@ -297,7 +297,7 @@ PeFile::Reloc::Reloc(upx_byte *s,unsigned si) :
} }
PeFile::Reloc::Reloc(unsigned rnum) : PeFile::Reloc::Reloc(unsigned rnum) :
start(NULL), size(0), rel(NULL), rel1(NULL) start(nullptr), size(0), rel(nullptr), rel1(nullptr)
{ {
start = new upx_byte[mem_size(4, rnum, 8192)]; start = new upx_byte[mem_size(4, rnum, 8192)];
counts[0] = 0; counts[0] = 0;
@@ -307,8 +307,10 @@ bool PeFile::Reloc::next(unsigned &pos,unsigned &type)
{ {
if (!rel) if (!rel)
newRelocPos(start); newRelocPos(start);
if (ptr_diff(rel, start) >= (int) size || rel->pagestart == 0) if (ptr_diff(rel, start) >= (int) size || rel->pagestart == 0) {
return rel = 0,false; // rewind rel = nullptr; // rewind
return false;
}
pos = rel->pagestart + (*rel1 & 0xfff); pos = rel->pagestart + (*rel1 & 0xfff);
type = *rel1++ >> 12; type = *rel1++ >> 12;
@@ -348,7 +350,7 @@ void PeFile::Reloc::finish(upx_byte *&p,unsigned &siz)
siz = ptr_diff(rel1,start) &~ 3; siz = ptr_diff(rel1,start) &~ 3;
siz -= 8; siz -= 8;
// siz can be 0 in 64-bit mode // assert(siz > 0); // siz can be 0 in 64-bit mode // assert(siz > 0);
start = 0; // safety start = nullptr; // safety
} }
void PeFile::processRelocs(Reloc *rel) // pass2 void PeFile::processRelocs(Reloc *rel) // pass2
@@ -659,7 +661,7 @@ class PeFile::ImportLinker : public ElfLinkerAMD64
tstr desc_name(name_for_dll(dll, descriptor_id)); tstr desc_name(name_for_dll(dll, descriptor_id));
char tsep = thunk_separator; char tsep = thunk_separator;
if (findSection(sdll, false) == NULL) if (findSection(sdll, false) == nullptr)
{ {
tsep = thunk_separator_first; tsep = thunk_separator_first;
addSection(sdll, dll, strlen(dll) + 1, 0); // name of the dll addSection(sdll, dll, strlen(dll) + 1, 0); // name of the dll
@@ -670,7 +672,7 @@ class PeFile::ImportLinker : public ElfLinkerAMD64
"R_X86_64_32", sdll, 0); "R_X86_64_32", sdll, 0);
} }
tstr thunk(name_for_proc(dll, proc, thunk_id, tsep)); tstr thunk(name_for_proc(dll, proc, thunk_id, tsep));
if (findSection(thunk, false) != NULL) if (findSection(thunk, false) != nullptr)
return; // we already have this dll/proc return; // we already have this dll/proc
addSection(thunk, zeros, thunk_size, 0); addSection(thunk, zeros, thunk_size, 0);
addSymbol(thunk, thunk, 0); addSymbol(thunk, thunk, 0);
@@ -722,9 +724,9 @@ public:
explicit ImportLinker(unsigned thunk_size_) : thunk_size(thunk_size_) explicit ImportLinker(unsigned thunk_size_) : thunk_size(thunk_size_)
{ {
assert(thunk_size == 4 || thunk_size == 8); assert(thunk_size == 4 || thunk_size == 8);
addSection("*UND*", NULL, 0, 0); addSection("*UND*", nullptr, 0, 0);
addSymbol("*UND*", "*UND*", 0); addSymbol("*UND*", "*UND*", 0);
addSection("*ZSTART", NULL, 0, 0); addSection("*ZSTART", nullptr, 0, 0);
addSymbol("*ZSTART", "*ZSTART", 0); addSymbol("*ZSTART", "*ZSTART", 0);
Section *s = addSection("Dzero", zeros, sizeof(import_desc), 0); Section *s = addSection("Dzero", zeros, sizeof(import_desc), 0);
assert(s->name[0] == descriptor_id); assert(s->name[0] == descriptor_id);
@@ -754,7 +756,7 @@ public:
unsigned build() unsigned build()
{ {
assert(output == NULL); assert(output == nullptr);
int osize = 4 + 2 * nsections; // upper limit for alignments int osize = 4 + 2 * nsections; // upper limit for alignments
for (unsigned ic = 0; ic < nsections; ic++) for (unsigned ic = 0; ic < nsections; ic++)
osize += sections[ic]->size; osize += sections[ic]->size;
@@ -789,8 +791,8 @@ public:
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char" ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char"
const Section *s = getThunk((const char*) dll, (const char*) proc, const Section *s = getThunk((const char*) dll, (const char*) proc,
thunk_separator_first); thunk_separator_first);
if (s == NULL && (s = getThunk((const char*) dll,(const char*) proc, if (s == nullptr && (s = getThunk((const char*) dll,(const char*) proc,
thunk_separator)) == NULL) thunk_separator)) == nullptr)
throwInternalError("entry not found"); throwInternalError("entry not found");
return s->offset; return s->offset;
} }
@@ -804,8 +806,8 @@ public:
upx_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal); upx_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
const Section *s = getThunk((const char*) dll, ord, thunk_separator_first); const Section *s = getThunk((const char*) dll, ord, thunk_separator_first);
if (s == NULL if (s == nullptr
&& (s = getThunk((const char*) dll, ord, thunk_separator)) == NULL) && (s = getThunk((const char*) dll, ord, thunk_separator)) == nullptr)
throwInternalError("entry not found"); throwInternalError("entry not found");
return s->offset; return s->offset;
} }
@@ -823,7 +825,7 @@ public:
{ {
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char" ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
tstr sdll(name_for_dll((const char*) dll, dll_name_id)); tstr sdll(name_for_dll((const char*) dll, dll_name_id));
return findSection(sdll, false) != NULL; return findSection(sdll, false) != nullptr;
} }
}; };
const char PeFile::ImportLinker::zeros[sizeof(import_desc)] = { 0 }; const char PeFile::ImportLinker::zeros[sizeof(import_desc)] = { 0 };
@@ -913,7 +915,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
{ {
idlls[ic] = dlls + ic; idlls[ic] = dlls + ic;
dlls[ic].name = ibuf.subref("bad dllname %#x", im->dllname, 1); dlls[ic].name = ibuf.subref("bad dllname %#x", im->dllname, 1);
dlls[ic].shname = NULL; dlls[ic].shname = nullptr;
dlls[ic].ordinal = 0; dlls[ic].ordinal = 0;
dlls[ic].iat = im->iat; dlls[ic].iat = im->iat;
unsigned const skip2 = (im->oft ? im->oft : im->iat); unsigned const skip2 = (im->oft ? im->oft : im->iat);
@@ -936,7 +938,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
IPTR_I(const upx_byte, n, ibuf + *tarr + 2); IPTR_I(const upx_byte, n, ibuf + *tarr + 2);
unsigned len = strlen(n); unsigned len = strlen(n);
soimport += len + 1; soimport += len + 1;
if (dlls[ic].shname == NULL || len < strlen (dlls[ic].shname)) if (dlls[ic].shname == nullptr || len < strlen (dlls[ic].shname))
dlls[ic].shname = ibuf + *tarr + 2; dlls[ic].shname = ibuf + *tarr + 2;
} }
soimport++; // separator soimport++; // separator
@@ -1092,8 +1094,8 @@ PeFile::Export::Export(char *_base) : base(_base), iv(_base)
{ {
COMPILE_TIME_ASSERT(sizeof(export_dir_t) == 40) COMPILE_TIME_ASSERT(sizeof(export_dir_t) == 40)
COMPILE_TIME_ASSERT_ALIGNED1(export_dir_t) COMPILE_TIME_ASSERT_ALIGNED1(export_dir_t)
ename = functionptrs = ordinals = NULL; ename = functionptrs = ordinals = nullptr;
names = NULL; names = nullptr;
memset(&edir,0,sizeof(edir)); memset(&edir,0,sizeof(edir));
size = 0; size = 0;
} }
@@ -1158,7 +1160,7 @@ void PeFile::Export::convert(unsigned eoffs,unsigned esize)
names[ic + edir.names] = strdup(forw); names[ic + edir.names] = strdup(forw);
} }
else else
names[ic + edir.names] = NULL; names[ic + edir.names] = nullptr;
len = 2 * edir.names; len = 2 * edir.names;
ordinals = New(char, len + 1); ordinals = New(char, len + 1);
@@ -1523,7 +1525,7 @@ struct PeFile::Resource::upx_rleaf : public PeFile::Resource::upx_rnode
}; };
PeFile::Resource::Resource(const upx_byte *ibufstart_, PeFile::Resource::Resource(const upx_byte *ibufstart_,
const upx_byte *ibufend_) : root(NULL) const upx_byte *ibufend_) : root(nullptr)
{ {
ibufstart = ibufstart_; ibufstart = ibufstart_;
ibufend = ibufend_; ibufend = ibufend_;
@@ -1540,7 +1542,7 @@ PeFile::Resource::Resource(const upx_byte *p,
PeFile::Resource::~Resource() PeFile::Resource::~Resource()
{ {
if (root) { destroy(root, 0); root = NULL; } if (root) { destroy(root, 0); root = nullptr; }
} }
unsigned PeFile::Resource::dirsize() const unsigned PeFile::Resource::dirsize() const
@@ -1551,7 +1553,7 @@ unsigned PeFile::Resource::dirsize() const
bool PeFile::Resource::next() bool PeFile::Resource::next()
{ {
// wow, builtin autorewind... :-) // wow, builtin autorewind... :-)
return (current = current ? current->next : head) != NULL; return (current = current ? current->next : head) != nullptr;
} }
unsigned PeFile::Resource::itype() const unsigned PeFile::Resource::itype() const
@@ -1609,10 +1611,10 @@ void PeFile::Resource::init(const upx_byte *res)
COMPILE_TIME_ASSERT_ALIGNED1(res_data) COMPILE_TIME_ASSERT_ALIGNED1(res_data)
start = res; start = res;
root = head = current = NULL; root = head = current = nullptr;
dsize = ssize = 0; dsize = ssize = 0;
check((const res_dir*) start,0); check((const res_dir*) start,0);
root = convert(start,NULL,0); root = convert(start,nullptr,0);
} }
void PeFile::Resource::check(const res_dir *node,unsigned level) void PeFile::Resource::check(const res_dir *node,unsigned level)
@@ -1647,7 +1649,7 @@ PeFile::Resource::upx_rnode *PeFile::Resource::convert(const void *rnode,
ibufcheck(node, sizeof(*node)); ibufcheck(node, sizeof(*node));
upx_rleaf *leaf = new upx_rleaf; upx_rleaf *leaf = new upx_rleaf;
leaf->id = 0; leaf->id = 0;
leaf->name = NULL; leaf->name = nullptr;
leaf->parent = parent; leaf->parent = parent;
leaf->next = head; leaf->next = head;
leaf->newoffset = 0; leaf->newoffset = 0;
@@ -1662,11 +1664,11 @@ PeFile::Resource::upx_rnode *PeFile::Resource::convert(const void *rnode,
ibufcheck(node, sizeof(*node)); ibufcheck(node, sizeof(*node));
int ic = node->identr + node->namedentr; int ic = node->identr + node->namedentr;
if (ic == 0) if (ic == 0)
return NULL; return nullptr;
upx_rbranch *branch = new upx_rbranch; upx_rbranch *branch = new upx_rbranch;
branch->id = 0; branch->id = 0;
branch->name = NULL; branch->name = nullptr;
branch->parent = parent; branch->parent = parent;
branch->nc = ic; branch->nc = ic;
branch->children = New(upx_rnode *, ic); branch->children = New(upx_rnode *, ic);
@@ -1724,7 +1726,7 @@ void PeFile::Resource::build(const upx_rnode *node, unsigned &bpos,
be->child = bpos + ((level < 2) ? 0x80000000 : 0); be->child = bpos + ((level < 2) ? 0x80000000 : 0);
const upx_byte *p; const upx_byte *p;
if ((p = branch->children[ic]->name) != 0) if ((p = branch->children[ic]->name) != nullptr)
{ {
be->tnl = spos + 0x80000000; be->tnl = spos + 0x80000000;
if (spos + get_le16(p) * 2 + 2 > dirsize()) if (spos + get_le16(p) * 2 + 2 > dirsize())
@@ -1762,16 +1764,16 @@ void PeFile::Resource::destroy(upx_rnode *node,unsigned level)
if (level == 3) if (level == 3)
{ {
upx_rleaf *leaf = ACC_STATIC_CAST(upx_rleaf *, node); upx_rleaf *leaf = ACC_STATIC_CAST(upx_rleaf *, node);
delete [] leaf->name; leaf->name = NULL; delete [] leaf->name; leaf->name = nullptr;
delete leaf; delete leaf;
} }
else else
{ {
upx_rbranch *branch = ACC_STATIC_CAST(upx_rbranch *, node); upx_rbranch *branch = ACC_STATIC_CAST(upx_rbranch *, node);
delete [] branch->name; branch->name = NULL; delete [] branch->name; branch->name = nullptr;
for (int ic = branch->nc; --ic >= 0; ) for (int ic = branch->nc; --ic >= 0; )
destroy(branch->children[ic], level + 1); destroy(branch->children[ic], level + 1);
delete [] branch->children; branch->children = NULL; delete [] branch->children; branch->children = nullptr;
delete branch; delete branch;
} }
} }
@@ -1883,7 +1885,7 @@ static bool match(unsigned itype, const unsigned char *ntype,
return true; return true;
} }
if (delim2 == NULL) if (delim2 == nullptr)
break; break;
keep = delim2 + 1; keep = delim2 + 1;
} }
@@ -1921,7 +1923,7 @@ void PeFile::processResources(Resource *res)
oresources = (upx_byte *)mb_oresources.getVoidPtr(); oresources = (upx_byte *)mb_oresources.getVoidPtr();
upx_byte *ores = oresources + res->dirsize(); upx_byte *ores = oresources + res->dirsize();
char *keep_icons = NULL; // icon ids in the first icon group char *keep_icons = nullptr; // icon ids in the first icon group
unsigned iconsin1stdir = 0; unsigned iconsin1stdir = 0;
if (opt->win32_pe.compress_icons == 2) if (opt->win32_pe.compress_icons == 2)
while (res->next()) // there is no rewind() in Resource while (res->next()) // there is no rewind() in Resource
@@ -2223,7 +2225,7 @@ unsigned PeFile::readSections(unsigned objs, unsigned usize,
void PeFile::callCompressWithFilters(Filter &ft, int filter_strategy, unsigned ih_codebase) void PeFile::callCompressWithFilters(Filter &ft, int filter_strategy, unsigned ih_codebase)
{ {
compressWithFilters(&ft, 2048, NULL_cconf, filter_strategy, compressWithFilters(&ft, 2048, NULL_cconf, filter_strategy,
ih_codebase, rvamin, 0, NULL, 0); ih_codebase, rvamin, 0, nullptr, 0);
} }
void PeFile::callProcessRelocs(Reloc &rel, unsigned &ic) void PeFile::callProcessRelocs(Reloc &rel, unsigned &ic)
@@ -2722,7 +2724,7 @@ void PeFile::rebuildRelocs(upx_byte *& extrainfo, unsigned bits,
rel.finish (oxrelocs,soxrelocs); rel.finish (oxrelocs,soxrelocs);
omemcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs); omemcpy(obuf + ODADDR(PEDIR_RELOC) - rvamin,oxrelocs,soxrelocs);
delete [] oxrelocs; oxrelocs = NULL; delete [] oxrelocs; oxrelocs = nullptr;
wrkmem.dealloc(); wrkmem.dealloc();
ODSIZE(PEDIR_RELOC) = soxrelocs; ODSIZE(PEDIR_RELOC) = soxrelocs;
@@ -3088,7 +3090,7 @@ upx_uint64_t PeFile::ilinkerGetAddress(const char *d, const char *n) const
PeFile::~PeFile() PeFile::~PeFile()
{ {
oimpdlls = NULL; oimpdlls = nullptr;
delete [] oxrelocs; delete [] oxrelocs;
delete ilinker; delete ilinker;
//delete res; //delete res;
+6 -6
View File
@@ -97,7 +97,7 @@ static void sb_push(screen_t *this, const Cell *line, int len) {
static const Cell *sb_pop(screen_t *this) { static const Cell *sb_pop(screen_t *this) {
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
return NULL; return nullptr;
sb_add(this, &this->data->sb_sp, -1); sb_add(this, &this->data->sb_sp, -1);
return this->data->sb_buf[this->data->sb_sp]; return this->data->sb_buf[this->data->sb_sp];
} }
@@ -274,7 +274,7 @@ static int init(screen_t *this, int fd) {
return -1; return -1;
} }
ScreenGetCursor(&this->data->cursor_y, &this->data->cursor_x); ScreenGetCursor(&this->data->cursor_y, &this->data->cursor_x);
getChar(this, NULL, &attr, this->data->cursor_x, this->data->cursor_y); getChar(this, nullptr, &attr, this->data->cursor_x, this->data->cursor_y);
this->data->init_attr = attr; this->data->init_attr = attr;
if (mode != 7) { if (mode != 7) {
/* Does it normally blink when bg has its 3rd bit set? */ /* Does it normally blink when bg has its 3rd bit set? */
@@ -369,7 +369,7 @@ static int scrollDown(screen_t *this, int lines) {
for (y = lines; --y >= 0;) { for (y = lines; --y >= 0;) {
#if USE_SCROLLBACK #if USE_SCROLLBACK
const Cell *buf = sb_pop(this); const Cell *buf = sb_pop(this);
if (buf == NULL) if (buf == nullptr)
clearLine(this, y); clearLine(this, y);
else else
updateLineN(this, buf, y, sc * 2); updateLineN(this, buf, y, sc * 2);
@@ -417,10 +417,10 @@ static void atExit(void) {
return; return;
done = 1; done = 1;
if (ae.cursor_shape >= 0) if (ae.cursor_shape >= 0)
setCursorShape(NULL, ae.cursor_shape); setCursorShape(nullptr, ae.cursor_shape);
} }
static const screen_t driver = {sobject_destroy, 0, /* finalize, */ static const screen_t driver = {sobject_destroy, nullptr, /* finalize */
atExit, init, refresh, atExit, init, refresh,
getMode, getPage, getRows, getMode, getPage, getRows,
getCols, isMono, getFg, getCols, isMono, getFg,
@@ -430,7 +430,7 @@ static const screen_t driver = {sobject_destroy, 0, /* finalize, */
putCharAttr, putString, putStringAttr, putCharAttr, putString, putStringAttr,
clear, clearLine, updateLineN, clear, clearLine, updateLineN,
scrollUp, scrollDown, getScrollCounter, scrollUp, scrollDown, getScrollCounter,
s_kbhit, intro, (struct screen_data_t *) 0}; s_kbhit, intro, (struct screen_data_t *) nullptr};
/* public constructor */ /* public constructor */
screen_t *screen_djgpp2_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); } screen_t *screen_djgpp2_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
+6 -6
View File
@@ -38,19 +38,19 @@
**************************************************************************/ **************************************************************************/
// ugly hacks // ugly hacks
static screen_t *last_screen = NULL; static screen_t *last_screen = nullptr;
screen_t *sobject_get_screen(void) { return last_screen; } screen_t *sobject_get_screen(void) { return last_screen; }
void sobject_destroy(screen_t *this) { void sobject_destroy(screen_t *this) {
last_screen = NULL; last_screen = nullptr;
if (!this) if (!this)
return; return;
if (this->data) { if (this->data) {
if (this->finalize) if (this->finalize)
this->finalize(this); this->finalize(this);
free(this->data); free(this->data);
this->data = NULL; this->data = nullptr;
} }
free(this); free(this);
} }
@@ -58,12 +58,12 @@ void sobject_destroy(screen_t *this) {
screen_t *sobject_construct(const screen_t *c, size_t data_size) { screen_t *sobject_construct(const screen_t *c, size_t data_size) {
screen_t *this; screen_t *this;
last_screen = NULL; last_screen = nullptr;
/* allocate object */ /* allocate object */
this = (screen_t *) malloc(sizeof(*this)); this = (screen_t *) malloc(sizeof(*this));
if (!this) if (!this)
return NULL; return nullptr;
/* copy function table */ /* copy function table */
*this = *c; *this = *c;
@@ -72,7 +72,7 @@ screen_t *sobject_construct(const screen_t *c, size_t data_size) {
this->data = (struct screen_data_t *) malloc(data_size); this->data = (struct screen_data_t *) malloc(data_size);
if (!this->data) { if (!this->data) {
free(this); free(this);
return NULL; return nullptr;
} }
memset(this->data, 0, data_size); memset(this->data, 0, data_size);
+7 -7
View File
@@ -89,7 +89,7 @@ static void sb_push(screen_t *this, const Cell *line, int len) {
static const Cell *sb_pop(screen_t *this) { static const Cell *sb_pop(screen_t *this) {
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
return NULL; return nullptr;
sb_add(this, &this->data->sb_sp, -1); sb_add(this, &this->data->sb_sp, -1);
return this->data->sb_buf[this->data->sb_sp]; return this->data->sb_buf[this->data->sb_sp];
} }
@@ -276,7 +276,7 @@ static int init(screen_t *this, int fd) {
this->data->map[i] = i; this->data->map[i] = i;
i = init_scrnmap(this, this->data->fd) || init_scrnmap(this, STDIN_FILENO); i = init_scrnmap(this, this->data->fd) || init_scrnmap(this, STDIN_FILENO);
getChar(this, NULL, &attr, this->data->cursor_x, this->data->cursor_y); getChar(this, nullptr, &attr, this->data->cursor_x, this->data->cursor_y);
this->data->init_attr = attr; this->data->init_attr = attr;
this->data->attr = attr; this->data->attr = attr;
a = make_cell(this, ' ', attr); a = make_cell(this, ' ', attr);
@@ -384,7 +384,7 @@ static int scrollDown(screen_t *this, int lines) {
for (y = lines; --y >= 0;) { for (y = lines; --y >= 0;) {
#if USE_SCROLLBACK #if USE_SCROLLBACK
const Cell *buf = sb_pop(this); const Cell *buf = sb_pop(this);
if (buf == NULL) if (buf == nullptr)
clearLine(this, y); clearLine(this, y);
else else
updateLineN(this, buf, y, sc * 2); updateLineN(this, buf, y, sc * 2);
@@ -420,7 +420,7 @@ static int kbhit(screen_t *this) {
FD_SET(fd, &fds); FD_SET(fd, &fds);
tv.tv_sec = usec / 1000000; tv.tv_sec = usec / 1000000;
tv.tv_usec = usec % 1000000; tv.tv_usec = usec % 1000000;
return (select(fd + 1, &fds, NULL, NULL, &tv) > 0); return (select(fd + 1, &fds, nullptr, nullptr, &tv) > 0);
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) { static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
@@ -455,7 +455,7 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static const screen_t driver = {sobject_destroy, static const screen_t driver = {sobject_destroy,
finalize, finalize,
0, /* atExit */ nullptr, /* atExit */
init, init,
refresh, refresh,
getMode, getMode,
@@ -471,7 +471,7 @@ static const screen_t driver = {sobject_destroy,
setBg, setBg,
setCursor, setCursor,
setCursorShape, setCursorShape,
0, /* hideCursor */ nullptr, /* hideCursor */
putChar, putChar,
putCharAttr, putCharAttr,
putString, putString,
@@ -484,7 +484,7 @@ static const screen_t driver = {sobject_destroy,
getScrollCounter, getScrollCounter,
kbhit, kbhit,
intro, intro,
(struct screen_data_t *) 0}; (struct screen_data_t *) nullptr};
/* public constructor */ /* public constructor */
screen_t *screen_vcsa_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); } screen_t *screen_vcsa_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
+3 -3
View File
@@ -346,7 +346,7 @@ static int do_scroll(screen_t *this, int lines, int way) {
break; break;
} }
// ScrollConsoleScreenBuffer(this->data->ho, &rect, &clip, dest, &this->data->empty_cell); // ScrollConsoleScreenBuffer(this->data->ho, &rect, &clip, dest, &this->data->empty_cell);
ScrollConsoleScreenBuffer(this->data->ho, &rect, NULL, dest, &this->data->empty_cell); ScrollConsoleScreenBuffer(this->data->ho, &rect, nullptr, dest, &this->data->empty_cell);
return lines; return lines;
} }
@@ -395,7 +395,7 @@ static void atExit(void) {
} }
} }
static const screen_t driver = {sobject_destroy, 0, /* finalize, */ static const screen_t driver = {sobject_destroy, nullptr, /* finalize */
atExit, init, refresh, atExit, init, refresh,
getMode, getPage, getRows, getMode, getPage, getRows,
getCols, isMono, getFg, getCols, isMono, getFg,
@@ -405,7 +405,7 @@ static const screen_t driver = {sobject_destroy, 0, /* finalize, */
putCharAttr, putString, putStringAttr, putCharAttr, putString, putStringAttr,
clear, clearLine, updateLineN, clear, clearLine, updateLineN,
scrollUp, scrollDown, getScrollCounter, scrollUp, scrollDown, getScrollCounter,
s_kbhit, intro, (struct screen_data_t *) 0}; s_kbhit, intro, (struct screen_data_t *) nullptr};
/* public constructor */ /* public constructor */
screen_t *screen_win32_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); } screen_t *screen_win32_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
+20 -20
View File
@@ -140,7 +140,7 @@ static void fmtstr(char *buffer, size_t *currsize, size_t maxsize, const char *s
#ifdef DEBUG_SNPRINTF #ifdef DEBUG_SNPRINTF
printf("fmtstr min=%d max=%d s=[%s]\n", min, max, strvalue); printf("fmtstr min=%d max=%d s=[%s]\n", min, max, strvalue);
#endif #endif
assert(strvalue != NULL); assert(strvalue != nullptr);
padlen = min - strln; padlen = min - strln;
if (padlen < 0) if (padlen < 0)
padlen = 0; padlen = 0;
@@ -677,27 +677,27 @@ static size_t dopr(char *buffer, size_t maxsize, const char *format, va_list arg
if (cflags == DP_C_CHAR) { if (cflags == DP_C_CHAR) {
signed char *num; signed char *num;
num = va_arg(args, signed char *); num = va_arg(args, signed char *);
assert(num != NULL); assert(num != nullptr);
*num = (signed char) currsize; *num = (signed char) currsize;
} else if (cflags == DP_C_SHORT) { } else if (cflags == DP_C_SHORT) {
short *num; short *num;
num = va_arg(args, short *); num = va_arg(args, short *);
assert(num != NULL); assert(num != nullptr);
*num = (short) currsize; *num = (short) currsize;
} else if (cflags == DP_C_LONG) { } else if (cflags == DP_C_LONG) {
long *num; long *num;
num = va_arg(args, long *); num = va_arg(args, long *);
assert(num != NULL); assert(num != nullptr);
*num = (long) currsize; *num = (long) currsize;
} else if (cflags == DP_C_LLONG) { } else if (cflags == DP_C_LLONG) {
LLONG *num; LLONG *num;
num = va_arg(args, LLONG *); num = va_arg(args, LLONG *);
assert(num != NULL); assert(num != nullptr);
*num = (LLONG) currsize; *num = (LLONG) currsize;
} else { } else {
int *num; int *num;
num = va_arg(args, int *); num = va_arg(args, int *);
assert(num != NULL); assert(num != nullptr);
*num = (int) currsize; *num = (int) currsize;
} }
break; break;
@@ -776,7 +776,7 @@ int upx_vsnprintf(char *str, upx_rsize_t max_size, const char *format, va_list a
// preconditions // preconditions
assert(max_size <= UPX_RSIZE_MAX_STR); assert(max_size <= UPX_RSIZE_MAX_STR);
if (str != NULL) if (str != nullptr)
assert(max_size > 0); assert(max_size > 0);
else else
assert(max_size == 0); assert(max_size == 0);
@@ -786,7 +786,7 @@ int upx_vsnprintf(char *str, upx_rsize_t max_size, const char *format, va_list a
// postconditions // postconditions
assert(size > 0); assert(size > 0);
assert(size <= UPX_RSIZE_MAX_STR); assert(size <= UPX_RSIZE_MAX_STR);
if (str != NULL) { if (str != nullptr) {
assert(size <= max_size); assert(size <= max_size);
assert(str[size - 1] == '\0'); assert(str[size - 1] == '\0');
} }
@@ -807,20 +807,20 @@ int __acc_cdecl_va upx_snprintf(char *str, upx_rsize_t max_size, const char *for
int upx_vasprintf(char **ptr, const char *format, va_list ap) { int upx_vasprintf(char **ptr, const char *format, va_list ap) {
int len; int len;
assert(ptr != NULL); assert(ptr != nullptr);
*ptr = NULL; *ptr = nullptr;
#if defined(va_copy) #if defined(va_copy)
va_list ap_copy; va_list ap_copy;
va_copy(ap_copy, ap); va_copy(ap_copy, ap);
len = upx_vsnprintf(NULL, 0, format, ap_copy); len = upx_vsnprintf(nullptr, 0, format, ap_copy);
va_end(ap_copy); va_end(ap_copy);
#else #else
len = upx_vsnprintf(NULL, 0, format, ap); len = upx_vsnprintf(nullptr, 0, format, ap);
#endif #endif
if (len >= 0) { if (len >= 0) {
*ptr = (char *) malloc(len + 1); *ptr = (char *) malloc(len + 1);
assert(*ptr != NULL); assert(*ptr != nullptr);
if (*ptr == NULL) if (*ptr == nullptr)
return -1; return -1;
int len2 = upx_vsnprintf(*ptr, len + 1, format, ap); int len2 = upx_vsnprintf(*ptr, len + 1, format, ap);
assert(len2 == len); assert(len2 == len);
@@ -840,7 +840,7 @@ int __acc_cdecl_va upx_asprintf(char **ptr, const char *format, ...) {
#undef strlen #undef strlen
upx_rsize_t upx_strlen(const char *s) { upx_rsize_t upx_strlen(const char *s) {
assert(s != NULL); assert(s != nullptr);
size_t len = strlen(s); size_t len = strlen(s);
assert(len < UPX_RSIZE_MAX_STR); assert(len < UPX_RSIZE_MAX_STR);
return len; return len;
@@ -881,7 +881,7 @@ int main(void)
"%.0f", "%.0f",
"%f", "%f",
"-16.16f", "-16.16f",
NULL nullptr
}; };
const double fp_nums[] = { const double fp_nums[] = {
6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
@@ -898,7 +898,7 @@ int main(void)
"%01.3d", "%01.3d",
"%4d", "%4d",
"%d", "%d",
NULL nullptr
}; };
const long int_nums[] = { -1, 134, 91340, 341, 0203, 0 }; const long int_nums[] = { -1, 134, 91340, 341, 0203, 0 };
const char *str_fmt[] = { const char *str_fmt[] = {
@@ -914,7 +914,7 @@ int main(void)
"%10s", "%10s",
0 0
}; };
const char *str_vals[] = {"hello", "a", "", "a longer string", NULL}; const char *str_vals[] = {"hello", "a", "", "a longer string", nullptr};
int x, y; int x, y;
int fail = 0; int fail = 0;
int num = 0; int num = 0;
@@ -923,7 +923,7 @@ int main(void)
for (x = 0; fp_fmt[x] ; x++) { for (x = 0; fp_fmt[x] ; x++) {
for (y = 0; fp_nums[y] != 0 ; y++) { for (y = 0; fp_nums[y] != 0 ; y++) {
int l1 = snprintf(NULL, 0, fp_fmt[x], fp_nums[y]); int l1 = snprintf(nullptr, 0, fp_fmt[x], fp_nums[y]);
int l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]); int l2 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]);
sprintf (buf2, fp_fmt[x], fp_nums[y]); sprintf (buf2, fp_fmt[x], fp_nums[y]);
if (strcmp (buf1, buf2)) { if (strcmp (buf1, buf2)) {
@@ -959,7 +959,7 @@ int main(void)
for (x = 0; str_fmt[x] ; x++) { for (x = 0; str_fmt[x] ; x++) {
for (y = 0; str_vals[y] != 0 ; y++) { for (y = 0; str_vals[y] != 0 ; y++) {
int l1 = snprintf(NULL, 0, str_fmt[x], str_vals[y]); int l1 = snprintf(nullptr, 0, str_fmt[x], str_vals[y]);
int l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]); int l2 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]);
sprintf (buf2, str_fmt[x], str_vals[y]); sprintf (buf2, str_fmt[x], str_vals[y]);
if (strcmp (buf1, buf2)) { if (strcmp (buf1, buf2)) {
+1 -1
View File
@@ -38,7 +38,7 @@ char *__cxa_demangle(const char *mangled_name, char *buf, size_t *n, int *status
UNUSED(n); UNUSED(n);
if (status) if (status)
*status = -1; /* memory_allocation_failure */ *status = -1; /* memory_allocation_failure */
return NULL; return nullptr;
} }
} /* extern "C" */ } /* extern "C" */
#endif #endif
+3 -3
View File
@@ -157,7 +157,7 @@ static const char *mkline(upx_uint64_t fu_len, upx_uint64_t fc_len, upx_uint64_t
// //
**************************************************************************/ **************************************************************************/
UiPacker::UiPacker(const Packer *p_) : ui_pass(0), ui_total_passes(0), p(p_), s(NULL) { UiPacker::UiPacker(const Packer *p_) : ui_pass(0), ui_total_passes(0), p(p_), s(nullptr) {
init_global_constants(); init_global_constants();
cb.reset(); cb.reset();
@@ -177,7 +177,7 @@ UiPacker::UiPacker(const Packer *p_) : ui_pass(0), ui_total_passes(0), p(p_), s(
s->mode = M_INFO; s->mode = M_INFO;
else if (opt->verbose == 1 || opt->no_progress) else if (opt->verbose == 1 || opt->no_progress)
s->mode = M_MSG; s->mode = M_MSG;
else if (s->screen == NULL) else if (s->screen == nullptr)
s->mode = M_CB_TERM; s->mode = M_CB_TERM;
else else
s->mode = M_CB_SCREEN; s->mode = M_CB_SCREEN;
@@ -186,7 +186,7 @@ UiPacker::UiPacker(const Packer *p_) : ui_pass(0), ui_total_passes(0), p(p_), s(
UiPacker::~UiPacker() { UiPacker::~UiPacker() {
cb.reset(); cb.reset();
delete s; delete s;
s = NULL; s = nullptr;
} }
/************************************************************************* /*************************************************************************
+8 -8
View File
@@ -99,8 +99,8 @@ bool mem_size_valid_bytes(upx_uint64_t bytes) {
} }
int ptr_diff(const void *p1, const void *p2) { int ptr_diff(const void *p1, const void *p2) {
assert(p1 != NULL); assert(p1 != nullptr);
assert(p2 != NULL); assert(p2 != nullptr);
ptrdiff_t d = (const char *) p1 - (const char *) p2; ptrdiff_t d = (const char *) p1 - (const char *) p2;
if (p1 >= p2) if (p1 >= p2)
assert(mem_size_valid_bytes(d)); assert(mem_size_valid_bytes(d));
@@ -239,7 +239,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *e1, const void *e2) {
**************************************************************************/ **************************************************************************/
int find(const void *b, int blen, const void *what, int wlen) { int find(const void *b, int blen, const void *what, int wlen) {
if (b == NULL || blen <= 0 || what == NULL || wlen <= 0) if (b == nullptr || blen <= 0 || what == nullptr || wlen <= 0)
return -1; return -1;
// Fast exit if the wanted string is longer than the buffer. // Fast exit if the wanted string is longer than the buffer.
if (wlen > blen) if (wlen > blen)
@@ -319,7 +319,7 @@ int mem_replace(void *bb, int blen, const void *what, int wlen, const void *r) {
static const char dir_sep[] = "/\\"; static const char dir_sep[] = "/\\";
#define fn_is_drive(s) (s[0] && s[1] == ':') #define fn_is_drive(s) (s[0] && s[1] == ':')
#define fn_is_sep(c) (strchr(dir_sep, c) != NULL) #define fn_is_sep(c) (strchr(dir_sep, c) != nullptr)
#define fn_skip_drive(s) (fn_is_drive(s) ? (s) + 2 : (s)) #define fn_skip_drive(s) (fn_is_drive(s) ? (s) + 2 : (s))
#define fn_tolower(c) (tolower(((unsigned char) (c)))) #define fn_tolower(c) (tolower(((unsigned char) (c))))
@@ -443,7 +443,7 @@ bool file_exists(const char *name) {
bool maketempname(char *ofilename, size_t size, const char *ifilename, const char *ext, bool maketempname(char *ofilename, size_t size, const char *ifilename, const char *ext,
bool force) { bool force) {
char *ofext = NULL, *ofname; char *ofext = nullptr, *ofname;
int ofile; int ofile;
if (size <= 0) if (size <= 0)
@@ -454,7 +454,7 @@ bool maketempname(char *ofilename, size_t size, const char *ifilename, const cha
if (*ofname == '.') if (*ofname == '.')
ofext = ofname; ofext = ofname;
} }
if (ofext == NULL) if (ofext == nullptr)
ofext = ofilename + strlen(ofilename); ofext = ofilename + strlen(ofilename);
strcpy(ofext, ext); strcpy(ofext, ext);
@@ -472,7 +472,7 @@ bool maketempname(char *ofilename, size_t size, const char *ifilename, const cha
} }
bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force) { bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force) {
char *ofext = NULL, *ofname; char *ofext = nullptr, *ofname;
int ofile; int ofile;
if (size <= 0) if (size <= 0)
@@ -483,7 +483,7 @@ bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force
if (*ofname == '.') if (*ofname == '.')
ofext = ofname; ofext = ofname;
} }
if (ofext == NULL) { if (ofext == nullptr) {
ofext = ofilename + strlen(ofilename); ofext = ofilename + strlen(ofilename);
strcpy(ofext, ".~"); strcpy(ofext, ".~");
} else if (strlen(ofext) < 1 + 3) } else if (strlen(ofext) < 1 + 3)
+1 -1
View File
@@ -299,7 +299,7 @@ void do_files(int i, int argc, char *argv[]) {
e_exit(EXIT_ERROR); e_exit(EXIT_ERROR);
} catch (...) { } catch (...) {
unlink_ofile(oname); unlink_ofile(oname);
printUnhandledException(iname, NULL); printUnhandledException(iname, nullptr);
e_exit(EXIT_ERROR); e_exit(EXIT_ERROR);
} }
} }