src: use 'byte' instead of 'upx_byte'; NFCI
This commit is contained in:
+16
-16
@@ -143,27 +143,27 @@ inline void set_le64(void *p, upx_uint64_t v) { set_ne64(p, ne64_to_le64(v)); }
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
inline unsigned get_be24(const void *p) {
|
inline unsigned get_be24(const void *p) {
|
||||||
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
|
const byte *b = ACC_CCAST(const byte *, p);
|
||||||
return (b[0] << 16) | (b[1] << 8) | (b[2] << 0);
|
return (b[0] << 16) | (b[1] << 8) | (b[2] << 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned get_le24(const void *p) {
|
inline unsigned get_le24(const void *p) {
|
||||||
const unsigned char *b = ACC_CCAST(const unsigned char *, p);
|
const byte *b = ACC_CCAST(const byte *, p);
|
||||||
return (b[0] << 0) | (b[1] << 8) | (b[2] << 16);
|
return (b[0] << 0) | (b[1] << 8) | (b[2] << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_be24(void *p, unsigned v) {
|
inline void set_be24(void *p, unsigned v) {
|
||||||
unsigned char *b = ACC_PCAST(unsigned char *, p);
|
byte *b = ACC_PCAST(byte *, p);
|
||||||
b[0] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
|
b[0] = ACC_ICONV(byte, (v >> 16) & 0xff);
|
||||||
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
b[1] = ACC_ICONV(byte, (v >> 8) & 0xff);
|
||||||
b[2] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
|
b[2] = ACC_ICONV(byte, (v >> 0) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void set_le24(void *p, unsigned v) {
|
inline void set_le24(void *p, unsigned v) {
|
||||||
unsigned char *b = ACC_PCAST(unsigned char *, p);
|
byte *b = ACC_PCAST(byte *, p);
|
||||||
b[0] = ACC_ICONV(unsigned char, (v >> 0) & 0xff);
|
b[0] = ACC_ICONV(byte, (v >> 0) & 0xff);
|
||||||
b[1] = ACC_ICONV(unsigned char, (v >> 8) & 0xff);
|
b[1] = ACC_ICONV(byte, (v >> 8) & 0xff);
|
||||||
b[2] = ACC_ICONV(unsigned char, (v >> 16) & 0xff);
|
b[2] = ACC_ICONV(byte, (v >> 16) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned get_le26(const void *p) { return get_le32(p) & 0x03ffffff; }
|
inline unsigned get_le26(const void *p) { return get_le32(p) & 0x03ffffff; }
|
||||||
@@ -250,7 +250,7 @@ inline upx_int64_t get_le64_signed(const void *p) {
|
|||||||
|
|
||||||
struct alignas(1) BE16 {
|
struct alignas(1) BE16 {
|
||||||
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
unsigned char d[2];
|
byte d[2];
|
||||||
|
|
||||||
BE16 &operator=(unsigned v) {
|
BE16 &operator=(unsigned v) {
|
||||||
set_be16(d, v);
|
set_be16(d, v);
|
||||||
@@ -300,7 +300,7 @@ struct alignas(1) BE16 {
|
|||||||
|
|
||||||
struct alignas(1) BE32 {
|
struct alignas(1) BE32 {
|
||||||
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
unsigned char d[4];
|
byte d[4];
|
||||||
|
|
||||||
BE32 &operator=(unsigned v) {
|
BE32 &operator=(unsigned v) {
|
||||||
set_be32(d, v);
|
set_be32(d, v);
|
||||||
@@ -350,7 +350,7 @@ struct alignas(1) BE32 {
|
|||||||
|
|
||||||
struct alignas(1) BE64 {
|
struct alignas(1) BE64 {
|
||||||
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
|
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
|
||||||
unsigned char d[8];
|
byte d[8];
|
||||||
|
|
||||||
BE64 &operator=(upx_uint64_t v) {
|
BE64 &operator=(upx_uint64_t v) {
|
||||||
set_be64(d, v);
|
set_be64(d, v);
|
||||||
@@ -400,7 +400,7 @@ struct alignas(1) BE64 {
|
|||||||
|
|
||||||
struct alignas(1) LE16 {
|
struct alignas(1) LE16 {
|
||||||
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
unsigned char d[2];
|
byte d[2];
|
||||||
|
|
||||||
LE16 &operator=(unsigned v) {
|
LE16 &operator=(unsigned v) {
|
||||||
set_le16(d, v);
|
set_le16(d, v);
|
||||||
@@ -450,7 +450,7 @@ struct alignas(1) LE16 {
|
|||||||
|
|
||||||
struct alignas(1) LE32 {
|
struct alignas(1) LE32 {
|
||||||
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
typedef unsigned integral_conversion_type; // automatic conversion to unsigned
|
||||||
unsigned char d[4];
|
byte d[4];
|
||||||
|
|
||||||
LE32 &operator=(unsigned v) {
|
LE32 &operator=(unsigned v) {
|
||||||
set_le32(d, v);
|
set_le32(d, v);
|
||||||
@@ -500,7 +500,7 @@ struct alignas(1) LE32 {
|
|||||||
|
|
||||||
struct alignas(1) LE64 {
|
struct alignas(1) LE64 {
|
||||||
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
|
typedef upx_uint64_t integral_conversion_type; // automatic conversion to upx_uint64_t
|
||||||
unsigned char d[8];
|
byte d[8];
|
||||||
|
|
||||||
LE64 &operator=(upx_uint64_t v) {
|
LE64 &operator=(upx_uint64_t v) {
|
||||||
set_le64(d, v);
|
set_le64(d, v);
|
||||||
|
|||||||
@@ -301,10 +301,10 @@ void upx_compiler_sanity_check(void) {
|
|||||||
assert(TestBELE<BE32>::test());
|
assert(TestBELE<BE32>::test());
|
||||||
assert(TestBELE<BE64>::test());
|
assert(TestBELE<BE64>::test());
|
||||||
{
|
{
|
||||||
alignas(16) static const unsigned char dd[32] = {
|
alignas(16) static const byte dd[32] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0,
|
0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0,
|
||||||
0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0, 0, 0, 0, 0};
|
0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 0, 0, 0, 0, 0};
|
||||||
const unsigned char *d;
|
const byte *d;
|
||||||
const N_BELE_RTP::AbstractPolicy *bele;
|
const N_BELE_RTP::AbstractPolicy *bele;
|
||||||
d = dd + 7;
|
d = dd + 7;
|
||||||
assert(upx_adler32(d, 4) == 0x09f003f7);
|
assert(upx_adler32(d, 4) == 0x09f003f7);
|
||||||
|
|||||||
+4
-2
@@ -186,8 +186,9 @@ typedef acc_int64_t upx_int64_t;
|
|||||||
typedef acc_uint64_t upx_uint64_t;
|
typedef acc_uint64_t upx_uint64_t;
|
||||||
typedef acc_uintptr_t upx_uintptr_t;
|
typedef acc_uintptr_t upx_uintptr_t;
|
||||||
|
|
||||||
typedef unsigned char upx_byte;
|
typedef unsigned char byte;
|
||||||
#define upx_bytep upx_byte *
|
#define upx_byte byte
|
||||||
|
#define upx_bytep byte *
|
||||||
|
|
||||||
// protect against integer overflows and malicious header fields
|
// protect against integer overflows and malicious header fields
|
||||||
// see C 11 standard, Annex K
|
// see C 11 standard, Annex K
|
||||||
@@ -834,6 +835,7 @@ void *membuffer_get_void_ptr(MemBuffer &mb);
|
|||||||
unsigned membuffer_get_size(MemBuffer &mb);
|
unsigned membuffer_get_size(MemBuffer &mb);
|
||||||
|
|
||||||
// xspan
|
// xspan
|
||||||
|
#include "util/raw_bytes.h"
|
||||||
#include "util/xspan.h"
|
#include "util/xspan.h"
|
||||||
|
|
||||||
// util/dt_check.cpp
|
// util/dt_check.cpp
|
||||||
|
|||||||
+10
-10
@@ -33,7 +33,7 @@
|
|||||||
// util
|
// util
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static void initFilter(Filter *f, upx_byte *buf, unsigned buf_len) {
|
static void initFilter(Filter *f, byte *buf, unsigned buf_len) {
|
||||||
f->buf = buf;
|
f->buf = buf;
|
||||||
f->buf_len = buf_len;
|
f->buf_len = buf_len;
|
||||||
// clear output parameters
|
// clear output parameters
|
||||||
@@ -45,7 +45,7 @@ static void initFilter(Filter *f, upx_byte *buf, unsigned buf_len) {
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
|
const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
|
||||||
static unsigned char filter_map[256];
|
static upx_uint8_t filter_map[256];
|
||||||
static upx_std_once_flag init_done;
|
static upx_std_once_flag init_done;
|
||||||
|
|
||||||
upx_std_call_once(init_done, []() noexcept {
|
upx_std_call_once(init_done, []() noexcept {
|
||||||
@@ -56,7 +56,7 @@ const FilterImpl::FilterEntry *FilterImpl::getFilter(int id) {
|
|||||||
int filter_id = filters[i].id;
|
int filter_id = filters[i].id;
|
||||||
assert(filter_id >= 0 && filter_id <= 255);
|
assert(filter_id >= 0 && filter_id <= 255);
|
||||||
assert(filter_map[filter_id] == 0xff);
|
assert(filter_map[filter_id] == 0xff);
|
||||||
filter_map[filter_id] = (unsigned char) i;
|
filter_map[filter_id] = (upx_uint8_t) i;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,8 +102,8 @@ void Filter::init(int id_, unsigned addvalue_) {
|
|||||||
this->n_mru = 0;
|
this->n_mru = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Filter::filter(SPAN_0(upx_byte) xbuf, unsigned buf_len_) {
|
bool Filter::filter(SPAN_0(byte) xbuf, unsigned buf_len_) {
|
||||||
upx_byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
||||||
initFilter(this, buf_, buf_len_);
|
initFilter(this, buf_, buf_len_);
|
||||||
|
|
||||||
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
||||||
@@ -134,8 +134,8 @@ bool Filter::filter(SPAN_0(upx_byte) xbuf, unsigned buf_len_) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Filter::unfilter(SPAN_0(upx_byte) xbuf, unsigned buf_len_, bool verify_checksum) {
|
void Filter::unfilter(SPAN_0(byte) xbuf, unsigned buf_len_, bool verify_checksum) {
|
||||||
upx_byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
||||||
initFilter(this, buf_, buf_len_);
|
initFilter(this, buf_, buf_len_);
|
||||||
|
|
||||||
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
||||||
@@ -179,11 +179,11 @@ void Filter::verifyUnfilter() {
|
|||||||
unfilter(this->buf, this->buf_len, true);
|
unfilter(this->buf, this->buf_len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Filter::scan(SPAN_0(const upx_byte) xbuf, unsigned buf_len_) {
|
bool Filter::scan(SPAN_0(const byte) xbuf, unsigned buf_len_) {
|
||||||
const upx_byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
const byte *const buf_ = raw_bytes(xbuf, buf_len_);
|
||||||
// Note: must use const_cast here. This is fine as the scan
|
// Note: must use const_cast here. This is fine as the scan
|
||||||
// implementations (fe->do_scan) actually don't change the buffer.
|
// implementations (fe->do_scan) actually don't change the buffer.
|
||||||
upx_byte *const b = const_cast<upx_byte *>(buf_);
|
byte *const b = const_cast<byte *>(buf_);
|
||||||
initFilter(this, b, buf_len_);
|
initFilter(this, b, buf_len_);
|
||||||
|
|
||||||
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
const FilterImpl::FilterEntry *const fe = FilterImpl::getFilter(id);
|
||||||
|
|||||||
+5
-9
@@ -26,8 +26,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef UPX_FILTER_H__
|
|
||||||
#define UPX_FILTER_H__ 1
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// A filter is a reversible operation that modifies a given
|
// A filter is a reversible operation that modifies a given
|
||||||
@@ -54,10 +52,10 @@ public:
|
|||||||
}
|
}
|
||||||
void init(int id = 0, unsigned addvalue = 0);
|
void init(int id = 0, unsigned addvalue = 0);
|
||||||
|
|
||||||
bool filter(SPAN_0(upx_byte) buf, unsigned buf_len);
|
bool filter(SPAN_0(byte) buf, unsigned buf_len);
|
||||||
void unfilter(SPAN_0(upx_byte) buf, unsigned buf_len, bool verify_checksum = false);
|
void unfilter(SPAN_0(byte) buf, unsigned buf_len, bool verify_checksum = false);
|
||||||
void verifyUnfilter();
|
void verifyUnfilter();
|
||||||
bool scan(SPAN_0(const upx_byte) buf, unsigned buf_len);
|
bool scan(SPAN_0(const byte) buf, unsigned buf_len);
|
||||||
|
|
||||||
static bool isValidFilter(int filter_id);
|
static bool isValidFilter(int filter_id);
|
||||||
static bool isValidFilter(int filter_id, const int *allowed_filters);
|
static bool isValidFilter(int filter_id, const int *allowed_filters);
|
||||||
@@ -65,7 +63,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
// Will be set by each call to filter()/unfilter().
|
// Will be set by each call to filter()/unfilter().
|
||||||
// Read-only afterwards.
|
// Read-only afterwards.
|
||||||
upx_byte *buf = nullptr;
|
byte *buf = nullptr;
|
||||||
unsigned buf_len = 0;
|
unsigned buf_len = 0;
|
||||||
|
|
||||||
// Checksum of the buffer before applying the filter
|
// Checksum of the buffer before applying the filter
|
||||||
@@ -77,7 +75,7 @@ public:
|
|||||||
const int *preferred_ctos = nullptr;
|
const int *preferred_ctos = nullptr;
|
||||||
|
|
||||||
// Input/output parameters used by various filters
|
// Input/output parameters used by various filters
|
||||||
unsigned char cto; // call trick offset
|
byte cto; // call trick offset
|
||||||
|
|
||||||
// Output used by various filters. Read only.
|
// Output used by various filters. Read only.
|
||||||
unsigned calls;
|
unsigned calls;
|
||||||
@@ -123,6 +121,4 @@ private:
|
|||||||
static const int n_filters; // number of filters[]
|
static const int n_filters; // number of filters[]
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+10
-10
@@ -32,8 +32,8 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT16(f, cond, addvalue, get, set) \
|
#define CT16(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 3; \
|
byte *b_end = b + f->buf_len - 3; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
@@ -211,8 +211,8 @@ static int s_ct16_e8e9_bswap_be(Filter *f)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT32(f, cond, addvalue, get, set) \
|
#define CT32(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 5; \
|
byte *b_end = b + f->buf_len - 5; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
@@ -388,8 +388,8 @@ static int s_ct32_e8e9_bswap_be(Filter *f)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT24ARM_LE(f, cond, addvalue, get, set) \
|
#define CT24ARM_LE(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 4; \
|
byte *b_end = b + f->buf_len - 4; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
@@ -424,8 +424,8 @@ static int s_ct24arm_le(Filter *f)
|
|||||||
#undef CT24ARM_LE
|
#undef CT24ARM_LE
|
||||||
|
|
||||||
#define CT24ARM_BE(f, cond, addvalue, get, set) \
|
#define CT24ARM_BE(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 4; \
|
byte *b_end = b + f->buf_len - 4; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
@@ -464,8 +464,8 @@ static int s_ct24arm_be(Filter *f)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CT26ARM_LE(f, cond, addvalue, get, set) \
|
#define CT26ARM_LE(f, cond, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 4; \
|
byte *b_end = b + f->buf_len - 4; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
+3
-3
@@ -35,10 +35,10 @@ static int F(Filter *f)
|
|||||||
{
|
{
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
@@ -141,7 +141,7 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f)
|
||||||
{
|
{
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned)f->cto << 24;
|
const unsigned cto = (unsigned)f->cto << 24;
|
||||||
|
|||||||
+3
-3
@@ -39,10 +39,10 @@ static int F(Filter *f)
|
|||||||
{
|
{
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
@@ -140,7 +140,7 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f)
|
||||||
{
|
{
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned)f->cto << 24;
|
const unsigned cto = (unsigned)f->cto << 24;
|
||||||
|
|||||||
+3
-3
@@ -98,10 +98,10 @@ static int F(Filter *f)
|
|||||||
{
|
{
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *const b = f->buf;
|
byte *const b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ static int U(Filter *f)
|
|||||||
{
|
{
|
||||||
unsigned ic, jc;
|
unsigned ic, jc;
|
||||||
|
|
||||||
upx_byte *const b = f->buf;
|
byte *const b = f->buf;
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned cto = (unsigned)f->cto << 24;
|
const unsigned cto = (unsigned)f->cto << 24;
|
||||||
unsigned lastcall = 0;
|
unsigned lastcall = 0;
|
||||||
|
|||||||
+3
-3
@@ -39,10 +39,10 @@ static int F(Filter *f)
|
|||||||
{
|
{
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned size = f->buf_len;
|
const unsigned size = f->buf_len;
|
||||||
@@ -141,7 +141,7 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f)
|
||||||
{
|
{
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
const unsigned size5 = f->buf_len - 5;
|
const unsigned size5 = f->buf_len - 5;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
const unsigned cto = (unsigned)f->cto << 24;
|
const unsigned cto = (unsigned)f->cto << 24;
|
||||||
|
|||||||
+4
-4
@@ -32,8 +32,8 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
|
#define CTSW16(f, cond1, cond2, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 3; \
|
byte *b_end = b + f->buf_len - 3; \
|
||||||
do { \
|
do { \
|
||||||
if (cond1) \
|
if (cond1) \
|
||||||
{ \
|
{ \
|
||||||
@@ -102,8 +102,8 @@ static int s_ctsw16_e9_e8(Filter *f)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
|
#define CTSW32(f, cond1, cond2, addvalue, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 5; \
|
byte *b_end = b + f->buf_len - 5; \
|
||||||
do { \
|
do { \
|
||||||
if (cond1) \
|
if (cond1) \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
+2
-2
@@ -31,7 +31,7 @@
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static int getcto(Filter *f, const unsigned char *buf, const int n=256)
|
static int getcto(Filter *f, const byte *buf, const int n=256)
|
||||||
{
|
{
|
||||||
int ic = n;
|
int ic = n;
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ static int getcto(Filter *f, const unsigned char *buf, const int n=256)
|
|||||||
//throwCantPack("call trick problem");
|
//throwCantPack("call trick problem");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
f->cto = (unsigned char) ic;
|
f->cto = (byte) ic;
|
||||||
return ic;
|
return ic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -41,11 +41,11 @@ static int F(Filter *f)
|
|||||||
{
|
{
|
||||||
#ifdef U
|
#ifdef U
|
||||||
// filter
|
// filter
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
#else
|
#else
|
||||||
// scan
|
// scan
|
||||||
const upx_byte *b = f->buf;
|
const byte *b = f->buf;
|
||||||
#endif
|
#endif
|
||||||
const unsigned size = umin(f->buf_len, 0u - (~0u<<(32 - (6+ W_CTO))));
|
const unsigned size = umin(f->buf_len, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||||
const unsigned size4 = size -4;
|
const unsigned size4 = size -4;
|
||||||
@@ -125,7 +125,7 @@ static int F(Filter *f)
|
|||||||
#ifdef U
|
#ifdef U
|
||||||
static int U(Filter *f)
|
static int U(Filter *f)
|
||||||
{
|
{
|
||||||
upx_byte *b = f->buf;
|
byte *b = f->buf;
|
||||||
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u<<(32 - (6+ W_CTO))));
|
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||||
const unsigned addvalue = f->addvalue;
|
const unsigned addvalue = f->addvalue;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -32,7 +32,7 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define SUB(f, N, T, get, set) \
|
#define SUB(f, N, T, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
unsigned l = f->buf_len / sizeof(T); \
|
unsigned l = f->buf_len / sizeof(T); \
|
||||||
int i; \
|
int i; \
|
||||||
T d[N]; \
|
T d[N]; \
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define ADD(f, N, T, get, set) \
|
#define ADD(f, N, T, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
unsigned l = f->buf_len / sizeof(T); \
|
unsigned l = f->buf_len / sizeof(T); \
|
||||||
int i; \
|
int i; \
|
||||||
T d[N]; \
|
T d[N]; \
|
||||||
|
|||||||
+4
-4
@@ -32,8 +32,8 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define SW16(f, cond, get, set) \
|
#define SW16(f, cond, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 3; \
|
byte *b_end = b + f->buf_len - 3; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
@@ -110,8 +110,8 @@ static int s_sw16_e8e9(Filter *f)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#define SW32(f, cond, get, set) \
|
#define SW32(f, cond, get, set) \
|
||||||
upx_byte *b = f->buf; \
|
byte *b = f->buf; \
|
||||||
upx_byte *b_end = b + f->buf_len - 5; \
|
byte *b_end = b + f->buf_len - 5; \
|
||||||
do { \
|
do { \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
+6
-6
@@ -89,7 +89,7 @@ void LeFile::writePageMap() {
|
|||||||
|
|
||||||
void LeFile::readResidentNames() {
|
void LeFile::readResidentNames() {
|
||||||
sores_names = ih.entry_table_offset - ih.resident_names_offset;
|
sores_names = ih.entry_table_offset - ih.resident_names_offset;
|
||||||
ires_names = New(upx_byte, sores_names);
|
ires_names = New(byte, sores_names);
|
||||||
fif->seek(le_offset + ih.resident_names_offset, SEEK_SET);
|
fif->seek(le_offset + ih.resident_names_offset, SEEK_SET);
|
||||||
fif->readx(ires_names, sores_names);
|
fif->readx(ires_names, sores_names);
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ void LeFile::writeResidentNames() {
|
|||||||
void LeFile::readEntryTable() {
|
void LeFile::readEntryTable() {
|
||||||
soentries = ih.fixup_page_table_offset - ih.entry_table_offset;
|
soentries = ih.fixup_page_table_offset - ih.entry_table_offset;
|
||||||
fif->seek(le_offset + ih.entry_table_offset, SEEK_SET);
|
fif->seek(le_offset + ih.entry_table_offset, SEEK_SET);
|
||||||
ientries = New(upx_byte, soentries);
|
ientries = New(byte, soentries);
|
||||||
fif->readx(ientries, soentries);
|
fif->readx(ientries, soentries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ void LeFile::writeFixupPageTable() {
|
|||||||
|
|
||||||
void LeFile::readFixups() {
|
void LeFile::readFixups() {
|
||||||
sofixups = get_le32(ifpage_table + pages) - get_le32(ifpage_table);
|
sofixups = get_le32(ifpage_table + pages) - get_le32(ifpage_table);
|
||||||
ifixups = New(upx_byte, sofixups);
|
ifixups = New(byte, sofixups);
|
||||||
fif->seek(le_offset + ih.fixup_record_table_offset, SEEK_SET);
|
fif->seek(le_offset + ih.fixup_record_table_offset, SEEK_SET);
|
||||||
fif->readx(ifixups, sofixups);
|
fif->readx(ifixups, sofixups);
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ void LeFile::writeImage() {
|
|||||||
void LeFile::readNonResidentNames() {
|
void LeFile::readNonResidentNames() {
|
||||||
if (ih.non_resident_name_table_length) {
|
if (ih.non_resident_name_table_length) {
|
||||||
sononres_names = ih.non_resident_name_table_length;
|
sononres_names = ih.non_resident_name_table_length;
|
||||||
inonres_names = New(upx_byte, sononres_names);
|
inonres_names = New(byte, sononres_names);
|
||||||
fif->seek(exe_offset + ih.non_resident_name_table_offset, SEEK_SET);
|
fif->seek(exe_offset + ih.non_resident_name_table_offset, SEEK_SET);
|
||||||
fif->readx(inonres_names, sononres_names);
|
fif->readx(inonres_names, sononres_names);
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ void LeFile::writeNonResidentNames() {
|
|||||||
|
|
||||||
bool LeFile::readFileHeader() {
|
bool LeFile::readFileHeader() {
|
||||||
#define H(x) get_le16(header + 2 * (x))
|
#define H(x) get_le16(header + 2 * (x))
|
||||||
upx_byte header[0x40];
|
byte header[0x40];
|
||||||
le_offset = exe_offset = 0;
|
le_offset = exe_offset = 0;
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ void LeFile::countFixups(unsigned *counts) const {
|
|||||||
// counts[objects] - # of selector fixups
|
// counts[objects] - # of selector fixups
|
||||||
// counts[objects+1] - # of self-relative fixups
|
// counts[objects+1] - # of self-relative fixups
|
||||||
|
|
||||||
const upx_byte *fix = ifixups;
|
const byte *fix = ifixups;
|
||||||
const unsigned sfixups = get_le32(ifpage_table + pages);
|
const unsigned sfixups = get_le32(ifpage_table + pages);
|
||||||
unsigned ll;
|
unsigned ll;
|
||||||
|
|
||||||
|
|||||||
+14
-14
@@ -127,10 +127,10 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) le_pagemap_entry_t {
|
struct alignas(1) le_pagemap_entry_t {
|
||||||
unsigned char h;
|
byte h;
|
||||||
unsigned char m;
|
byte m;
|
||||||
unsigned char l;
|
byte l;
|
||||||
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
byte type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void readObjectTable();
|
virtual void readObjectTable();
|
||||||
@@ -199,18 +199,18 @@ protected:
|
|||||||
unsigned *ofpage_table = nullptr;
|
unsigned *ofpage_table = nullptr;
|
||||||
le_pagemap_entry_t *ipm_entries = nullptr;
|
le_pagemap_entry_t *ipm_entries = nullptr;
|
||||||
le_pagemap_entry_t *opm_entries = nullptr;
|
le_pagemap_entry_t *opm_entries = nullptr;
|
||||||
upx_byte *ires_names = nullptr;
|
byte *ires_names = nullptr;
|
||||||
upx_byte *ores_names = nullptr;
|
byte *ores_names = nullptr;
|
||||||
upx_byte *ifixups = nullptr;
|
byte *ifixups = nullptr;
|
||||||
upx_byte *ofixups = nullptr;
|
byte *ofixups = nullptr;
|
||||||
upx_byte *inonres_names = nullptr;
|
byte *inonres_names = nullptr;
|
||||||
upx_byte *ononres_names = nullptr;
|
byte *ononres_names = nullptr;
|
||||||
MemBuffer mb_iimage;
|
MemBuffer mb_iimage;
|
||||||
SPAN_0(upx_byte) iimage = nullptr;
|
SPAN_0(byte) iimage = nullptr;
|
||||||
MemBuffer mb_oimage;
|
MemBuffer mb_oimage;
|
||||||
SPAN_0(upx_byte) oimage = nullptr;
|
SPAN_0(byte) oimage = nullptr;
|
||||||
upx_byte *ientries = nullptr;
|
byte *ientries = nullptr;
|
||||||
upx_byte *oentries = nullptr;
|
byte *oentries = nullptr;
|
||||||
|
|
||||||
unsigned soobject_table;
|
unsigned soobject_table;
|
||||||
unsigned sofpage_table;
|
unsigned sofpage_table;
|
||||||
|
|||||||
+19
-19
@@ -122,7 +122,7 @@ ElfLinker::~ElfLinker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
|
void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
|
||||||
const upx_byte *pdata = (const upx_byte *) pdata_v;
|
const byte *pdata = (const byte *) pdata_v;
|
||||||
if (plen >= 16 && memcmp(pdata, "UPX#", 4) == 0) {
|
if (plen >= 16 && memcmp(pdata, "UPX#", 4) == 0) {
|
||||||
// decompress pre-compressed stub-loader
|
// decompress pre-compressed stub-loader
|
||||||
int method;
|
int method;
|
||||||
@@ -142,7 +142,7 @@ void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
|
|||||||
}
|
}
|
||||||
assert((unsigned) plen < u_len);
|
assert((unsigned) plen < u_len);
|
||||||
inputlen = u_len;
|
inputlen = u_len;
|
||||||
input = new upx_byte[inputlen + 1];
|
input = New(byte, inputlen + 1);
|
||||||
unsigned new_len = u_len;
|
unsigned new_len = u_len;
|
||||||
int r = upx_decompress(pdata, c_len, input, &new_len, method, nullptr);
|
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)
|
||||||
@@ -151,7 +151,7 @@ void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
|
|||||||
throwBadLoader();
|
throwBadLoader();
|
||||||
} else {
|
} else {
|
||||||
inputlen = plen;
|
inputlen = plen;
|
||||||
input = new upx_byte[inputlen + 1];
|
input = New(byte, inputlen + 1);
|
||||||
if (inputlen)
|
if (inputlen)
|
||||||
memcpy(input, pdata, inputlen);
|
memcpy(input, pdata, inputlen);
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ void ElfLinker::init(const void *pdata_v, int plen, unsigned pxtra) {
|
|||||||
|
|
||||||
output_capacity = (inputlen ? (inputlen + pxtra) : 0x4000);
|
output_capacity = (inputlen ? (inputlen + pxtra) : 0x4000);
|
||||||
assert(output_capacity <= (1 << 16)); // LE16 l_info.l_size
|
assert(output_capacity <= (1 << 16)); // LE16 l_info.l_size
|
||||||
output = new upx_byte[output_capacity];
|
output = New(byte, output_capacity);
|
||||||
outputlen = 0;
|
outputlen = 0;
|
||||||
NO_printf("\nElfLinker::init %d @%p\n", output_capacity, output);
|
NO_printf("\nElfLinker::init %d @%p\n", output_capacity, output);
|
||||||
|
|
||||||
@@ -456,7 +456,7 @@ int ElfLinker::getSectionSize(const char *sname) const {
|
|||||||
return section->size;
|
return section->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
upx_byte *ElfLinker::getLoader(int *llen) const {
|
byte *ElfLinker::getLoader(int *llen) const {
|
||||||
if (llen)
|
if (llen)
|
||||||
*llen = outputlen;
|
*llen = outputlen;
|
||||||
return output;
|
return output;
|
||||||
@@ -482,7 +482,7 @@ void ElfLinker::relocate() {
|
|||||||
else {
|
else {
|
||||||
value = rel->value->section->offset + rel->value->offset + rel->add;
|
value = rel->value->section->offset + rel->value->offset + rel->add;
|
||||||
}
|
}
|
||||||
upx_byte *location = rel->section->output + rel->offset;
|
byte *location = rel->section->output + rel->offset;
|
||||||
NO_printf("%-28s %-28s %-10s %#16llx %#16llx\n", rel->section->name, rel->value->name,
|
NO_printf("%-28s %-28s %-10s %#16llx %#16llx\n", rel->section->name, rel->value->name,
|
||||||
rel->type, (long long) value,
|
rel->type, (long long) value,
|
||||||
(long long) value - rel->section->offset - rel->offset);
|
(long long) value - rel->section->offset - rel->offset);
|
||||||
@@ -553,7 +553,7 @@ void ElfLinker::alignWithByte(unsigned len, unsigned char b) {
|
|||||||
outputlen += len;
|
outputlen += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinker::relocate1(const Relocation *rel, upx_byte *, upx_uint64_t, const char *) {
|
void ElfLinker::relocate1(const Relocation *rel, byte *, upx_uint64_t, const char *) {
|
||||||
internal_error("unknown relocation type '%s\n'", rel->type);
|
internal_error("unknown relocation type '%s\n'", rel->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,7 +564,7 @@ void ElfLinker::relocate1(const Relocation *rel, upx_byte *, upx_uint64_t, const
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#if 0 // FIXME
|
#if 0 // FIXME
|
||||||
static void check8(const Relocation *rel, const upx_byte *location, int v, int d)
|
static void check8(const Relocation *rel, const byte *location, int v, int d)
|
||||||
{
|
{
|
||||||
if (v < -128 || v > 127)
|
if (v < -128 || v > 127)
|
||||||
internal_error("value out of range (%d) in reloc %s:%x\n",
|
internal_error("value out of range (%d) in reloc %s:%x\n",
|
||||||
@@ -575,7 +575,7 @@ static void check8(const Relocation *rel, const upx_byte *location, int v, int d
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerAMD64::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (strncmp(type, "R_X86_64_", 9))
|
if (strncmp(type, "R_X86_64_", 9))
|
||||||
return super::relocate1(rel, location, value, type);
|
return super::relocate1(rel, location, value, type);
|
||||||
@@ -608,7 +608,7 @@ void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location, upx_ui
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerArmBE::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (!strcmp(type, "R_ARM_PC24") || !strcmp(type, "R_ARM_CALL") ||
|
if (!strcmp(type, "R_ARM_PC24") || !strcmp(type, "R_ARM_CALL") ||
|
||||||
!strcmp(type, "R_ARM_JUMP24")) {
|
!strcmp(type, "R_ARM_JUMP24")) {
|
||||||
@@ -633,7 +633,7 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location, upx_ui
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerArmLE::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (!strcmp(type, "R_ARM_PC24") || !strcmp(type, "R_ARM_CALL") ||
|
if (!strcmp(type, "R_ARM_PC24") || !strcmp(type, "R_ARM_CALL") ||
|
||||||
!strcmp(type, "R_ARM_JUMP24")) {
|
!strcmp(type, "R_ARM_JUMP24")) {
|
||||||
@@ -658,7 +658,7 @@ void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location, upx_ui
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerArm64LE::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerArm64LE::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (strncmp(type, "R_AARCH64_", 10))
|
if (strncmp(type, "R_AARCH64_", 10))
|
||||||
return super::relocate1(rel, location, value, type);
|
return super::relocate1(rel, location, value, type);
|
||||||
@@ -706,7 +706,7 @@ void ElfLinkerM68k::alignCode(unsigned len) {
|
|||||||
outputlen += len;
|
outputlen += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerM68k::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (strncmp(type, "R_68K_", 6))
|
if (strncmp(type, "R_68K_", 6))
|
||||||
return super::relocate1(rel, location, value, type);
|
return super::relocate1(rel, location, value, type);
|
||||||
@@ -726,7 +726,7 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location, upx_uin
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerMipsBE::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
#define MIPS_HI(a) (((a) >> 16) + (((a) &0x8000) >> 15))
|
#define MIPS_HI(a) (((a) >> 16) + (((a) &0x8000) >> 15))
|
||||||
#define MIPS_LO(a) ((a) &0xffff)
|
#define MIPS_LO(a) ((a) &0xffff)
|
||||||
@@ -753,7 +753,7 @@ void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location, upx_u
|
|||||||
#undef MIPS_PC26
|
#undef MIPS_PC26
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerMipsLE::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
#define MIPS_HI(a) (((a) >> 16) + (((a) &0x8000) >> 15))
|
#define MIPS_HI(a) (((a) >> 16) + (((a) &0x8000) >> 15))
|
||||||
#define MIPS_LO(a) ((a) &0xffff)
|
#define MIPS_LO(a) ((a) &0xffff)
|
||||||
@@ -780,7 +780,7 @@ void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location, upx_u
|
|||||||
#undef MIPS_PC26
|
#undef MIPS_PC26
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerPpc32::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (strncmp(type, "R_PPC_", 6))
|
if (strncmp(type, "R_PPC_", 6))
|
||||||
return super::relocate1(rel, location, value, type);
|
return super::relocate1(rel, location, value, type);
|
||||||
@@ -813,7 +813,7 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location, upx_ui
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerPpc64le::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerPpc64le::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (!strcmp(type, "R_PPC64_ADDR64")) {
|
if (!strcmp(type, "R_PPC64_ADDR64")) {
|
||||||
set_le64(location, get_le64(location) + value);
|
set_le64(location, get_le64(location) + value);
|
||||||
@@ -856,7 +856,7 @@ void ElfLinkerPpc64le::relocate1(const Relocation *rel, upx_byte *location, upx_
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerPpc64::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerPpc64::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (!strcmp(type, "R_PPC64_ADDR32")) {
|
if (!strcmp(type, "R_PPC64_ADDR32")) {
|
||||||
set_be32(location, get_be32(location) + value);
|
set_be32(location, get_be32(location) + value);
|
||||||
@@ -886,7 +886,7 @@ void ElfLinkerPpc64::relocate1(const Relocation *rel, upx_byte *location, upx_ui
|
|||||||
super::relocate1(rel, location, value, type);
|
super::relocate1(rel, location, value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location, upx_uint64_t value,
|
void ElfLinkerX86::relocate1(const Relocation *rel, byte *location, upx_uint64_t value,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
if (strncmp(type, "R_386_", 6))
|
if (strncmp(type, "R_386_", 6))
|
||||||
return super::relocate1(rel, location, value, type);
|
return super::relocate1(rel, location, value, type);
|
||||||
|
|||||||
+17
-17
@@ -42,9 +42,9 @@ protected:
|
|||||||
struct Symbol;
|
struct Symbol;
|
||||||
struct Relocation;
|
struct Relocation;
|
||||||
|
|
||||||
upx_byte *input = nullptr;
|
byte *input = nullptr;
|
||||||
int inputlen = 0;
|
int inputlen = 0;
|
||||||
upx_byte *output = nullptr;
|
byte *output = nullptr;
|
||||||
int outputlen = 0;
|
int outputlen = 0;
|
||||||
unsigned output_capacity = 0;
|
unsigned output_capacity = 0;
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public:
|
|||||||
Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
|
Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
|
||||||
int getSection(const char *sname, int *slen = nullptr) const;
|
int getSection(const char *sname, int *slen = nullptr) const;
|
||||||
int getSectionSize(const char *sname) const;
|
int getSectionSize(const char *sname) const;
|
||||||
upx_byte *getLoader(int *llen = nullptr) const;
|
byte *getLoader(int *llen = nullptr) const;
|
||||||
void defineSymbol(const char *name, upx_uint64_t value);
|
void defineSymbol(const char *name, upx_uint64_t value);
|
||||||
upx_uint64_t getSymbolOffset(const char *) const;
|
upx_uint64_t getSymbolOffset(const char *) const;
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void relocate();
|
void relocate();
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type);
|
const char *type);
|
||||||
|
|
||||||
// target endianness abstraction
|
// target endianness abstraction
|
||||||
@@ -126,7 +126,7 @@ protected:
|
|||||||
struct ElfLinker::Section : private noncopyable {
|
struct ElfLinker::Section : private noncopyable {
|
||||||
char *name = nullptr;
|
char *name = nullptr;
|
||||||
void *input = nullptr;
|
void *input = nullptr;
|
||||||
upx_byte *output = nullptr;
|
byte *output = nullptr;
|
||||||
unsigned size = 0;
|
unsigned size = 0;
|
||||||
upx_uint64_t offset = 0;
|
upx_uint64_t offset = 0;
|
||||||
unsigned p2align = 0; // log2
|
unsigned p2align = 0; // log2
|
||||||
@@ -164,7 +164,7 @@ class ElfLinkerAMD64 : public ElfLinker {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ class ElfLinkerARM64 final : public ElfLinker {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ public:
|
|||||||
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ class ElfLinkerArmLE final : public ElfLinker {
|
|||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ class ElfLinkerArm64LE final : public ElfLinker {
|
|||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override;
|
virtual void alignCode(unsigned len) override;
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ public:
|
|||||||
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ class ElfLinkerMipsLE final : public ElfLinker {
|
|||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ public:
|
|||||||
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ class ElfLinkerPpc64le final : public ElfLinker {
|
|||||||
typedef ElfLinker super;
|
typedef ElfLinker super;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -261,7 +261,7 @@ public:
|
|||||||
ElfLinkerPpc64() { bele = &N_BELE_RTP::be_policy; }
|
ElfLinkerPpc64() { bele = &N_BELE_RTP::be_policy; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ class ElfLinkerX86 final : public ElfLinker {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
virtual void alignCode(unsigned len) override { alignWithByte(len, 0x90); }
|
||||||
virtual void relocate1(const Relocation *, upx_byte *location, upx_uint64_t value,
|
virtual void relocate1(const Relocation *, byte *location, upx_uint64_t value,
|
||||||
const char *type) override;
|
const char *type) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -59,7 +59,7 @@ const int *PackCom::getFilters() const {
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackCom::canPack() {
|
bool PackCom::canPack() {
|
||||||
unsigned char buf[128];
|
byte buf[128];
|
||||||
|
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
if (memcmp(buf, "MZ", 2) == 0 || memcmp(buf, "ZM", 2) == 0) // .exe
|
if (memcmp(buf, "MZ", 2) == 0 || memcmp(buf, "ZM", 2) == 0) // .exe
|
||||||
@@ -123,7 +123,7 @@ void PackCom::buildLoader(const Filter *ft) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackCom::patchLoader(OutputFile *fo, upx_byte *loader, int lsize, unsigned calls) {
|
void PackCom::patchLoader(OutputFile *fo, byte *loader, int lsize, unsigned calls) {
|
||||||
const int e_len = getLoaderSectionStart("COMCUTPO");
|
const int e_len = getLoaderSectionStart("COMCUTPO");
|
||||||
const int d_len = lsize - e_len;
|
const int d_len = lsize - e_len;
|
||||||
assert(e_len > 0 && e_len < 128);
|
assert(e_len > 0 && e_len < 128);
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ protected:
|
|||||||
// dos/sys will override these:
|
// dos/sys will override these:
|
||||||
virtual unsigned getCallTrickOffset() const { return 0x100; }
|
virtual unsigned getCallTrickOffset() const { return 0x100; }
|
||||||
virtual void buildLoader(const Filter *ft) override;
|
virtual void buildLoader(const Filter *ft) override;
|
||||||
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
|
virtual void patchLoader(OutputFile *fo, byte *, int, unsigned);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|||||||
+8
-8
@@ -66,7 +66,7 @@ const int *PackDjgpp2::getFilters() const {
|
|||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf, unsigned range,
|
unsigned PackDjgpp2::findOverlapOverhead(const byte *buf, const byte *tbuf, unsigned range,
|
||||||
unsigned upper_limit) const {
|
unsigned upper_limit) const {
|
||||||
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
||||||
o = (o + 0x3ff) & ~0x1ff;
|
o = (o + 0x3ff) & ~0x1ff;
|
||||||
@@ -106,7 +106,7 @@ void PackDjgpp2::handleStub(OutputFile *fo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool is_dlm(InputFile *fi, unsigned coff_offset) {
|
static bool is_dlm(InputFile *fi, unsigned coff_offset) {
|
||||||
unsigned char buf[4];
|
byte buf[4];
|
||||||
unsigned off;
|
unsigned off;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -125,7 +125,7 @@ static bool is_dlm(InputFile *fi, unsigned coff_offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void handle_allegropak(InputFile *fi, OutputFile *fo) {
|
static void handle_allegropak(InputFile *fi, OutputFile *fo) {
|
||||||
unsigned char b[8];
|
byte b[8];
|
||||||
int pfsize = 0;
|
int pfsize = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -150,8 +150,8 @@ static void handle_allegropak(InputFile *fi, OutputFile *fo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PackDjgpp2::readFileHeader() {
|
int PackDjgpp2::readFileHeader() {
|
||||||
unsigned char hdr[0x1c];
|
byte hdr[0x1c];
|
||||||
unsigned char magic[8];
|
byte magic[8];
|
||||||
|
|
||||||
fi->seek(0, SEEK_SET);
|
fi->seek(0, SEEK_SET);
|
||||||
fi->readx(hdr, sizeof(hdr));
|
fi->readx(hdr, sizeof(hdr));
|
||||||
@@ -390,11 +390,11 @@ void PackDjgpp2::unpack(OutputFile *fo) {
|
|||||||
if (ph.filter) {
|
if (ph.filter) {
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.init(ph.filter, addvalue);
|
ft.init(ph.filter, addvalue);
|
||||||
ft.cto = (unsigned char) ph.filter_cto;
|
ft.cto = (byte) ph.filter_cto;
|
||||||
if (ph.version < 11) {
|
if (ph.version < 11) {
|
||||||
unsigned char ctobuf[4];
|
byte ctobuf[4];
|
||||||
fi->readx(ctobuf, 4);
|
fi->readx(ctobuf, 4);
|
||||||
ft.cto = (unsigned char) (get_le32(ctobuf) >> 24);
|
ft.cto = (byte) (get_le32(ctobuf) >> 24);
|
||||||
}
|
}
|
||||||
ft.unfilter(obuf, ph.u_len - data->size);
|
ft.unfilter(obuf, ph.u_len - data->size);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -57,8 +57,7 @@ protected:
|
|||||||
void handleStub(OutputFile *fo);
|
void handleStub(OutputFile *fo);
|
||||||
int readFileHeader();
|
int readFileHeader();
|
||||||
|
|
||||||
virtual unsigned findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf,
|
virtual unsigned findOverlapOverhead(const byte *buf, const byte *tbuf, unsigned range = 0,
|
||||||
unsigned range = 0,
|
|
||||||
unsigned upper_limit = ~0u) const override;
|
unsigned upper_limit = ~0u) const override;
|
||||||
virtual void buildLoader(const Filter *ft) override;
|
virtual void buildLoader(const Filter *ft) override;
|
||||||
virtual Linker *newLinker() const override;
|
virtual Linker *newLinker() const override;
|
||||||
|
|||||||
+14
-14
@@ -258,12 +258,12 @@ bool PackExe::canPack() {
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static unsigned optimize_relocs(upx_byte *b, const unsigned size, const upx_byte *relocs,
|
static unsigned optimize_relocs(byte *b, const unsigned size, const byte *relocs,
|
||||||
const unsigned nrelocs, upx_byte *crel, bool *has_9a) {
|
const unsigned nrelocs, byte *crel, bool *has_9a) {
|
||||||
if (opt->exact)
|
if (opt->exact)
|
||||||
throwCantPackExact();
|
throwCantPackExact();
|
||||||
|
|
||||||
upx_byte *const crel_save = crel;
|
byte *const crel_save = crel;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
unsigned seg_high = 0;
|
unsigned seg_high = 0;
|
||||||
#if 0
|
#if 0
|
||||||
@@ -351,7 +351,7 @@ static unsigned optimize_relocs(upx_byte *b, const unsigned size, const upx_byte
|
|||||||
t -= 254;
|
t -= 254;
|
||||||
ones++;
|
ones++;
|
||||||
}
|
}
|
||||||
*crel++ = (unsigned char) t;
|
*crel++ = (byte) t;
|
||||||
di = offs;
|
di = offs;
|
||||||
}
|
}
|
||||||
} while (i < nrelocs);
|
} while (i < nrelocs);
|
||||||
@@ -390,9 +390,9 @@ void PackExe::pack(OutputFile *fo) {
|
|||||||
|
|
||||||
// relocations
|
// relocations
|
||||||
has_9a = false;
|
has_9a = false;
|
||||||
upx_byte *w = ibuf + ih_imagesize;
|
byte *w = ibuf + ih_imagesize;
|
||||||
if (ih.relocs) {
|
if (ih.relocs) {
|
||||||
upx_byte *wr = w + RSFCRI;
|
byte *wr = w + RSFCRI;
|
||||||
|
|
||||||
fi->seek(ih.relocoffs, SEEK_SET);
|
fi->seek(ih.relocoffs, SEEK_SET);
|
||||||
fi->readx(wr, 4 * ih.relocs);
|
fi->readx(wr, 4 * ih.relocs);
|
||||||
@@ -408,7 +408,7 @@ void PackExe::pack(OutputFile *fo) {
|
|||||||
if (relocsize > MAXRELOCS)
|
if (relocsize > MAXRELOCS)
|
||||||
throwCantPack("too many relocations");
|
throwCantPack("too many relocations");
|
||||||
#if 0
|
#if 0
|
||||||
upx_byte out[9*relocsize/8+1024];
|
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, nullptr, 9, nullptr, nullptr);
|
ucl_nrv2b_99_compress(w, in_len, out, &out_len, nullptr, 9, nullptr, nullptr);
|
||||||
@@ -467,7 +467,7 @@ void PackExe::pack(OutputFile *fo) {
|
|||||||
oh.max = ic < 0xffff && ih.max != 0xffff ? ic : 0xffff;
|
oh.max = ic < 0xffff && ih.max != 0xffff ? ic : 0xffff;
|
||||||
|
|
||||||
// set extra info
|
// set extra info
|
||||||
unsigned char extra_info[9];
|
byte extra_info[9];
|
||||||
unsigned eisize = 0;
|
unsigned eisize = 0;
|
||||||
if (oh.ss != ih.ss) {
|
if (oh.ss != ih.ss) {
|
||||||
set_le16(extra_info + eisize, ih.ss);
|
set_le16(extra_info + eisize, ih.ss);
|
||||||
@@ -489,7 +489,7 @@ void PackExe::pack(OutputFile *fo) {
|
|||||||
eisize += 2;
|
eisize += 2;
|
||||||
flag |= MAXMEM;
|
flag |= MAXMEM;
|
||||||
}
|
}
|
||||||
extra_info[eisize++] = (unsigned char) flag;
|
extra_info[eisize++] = (byte) flag;
|
||||||
|
|
||||||
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
|
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
|
||||||
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
|
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
|
||||||
@@ -608,13 +608,13 @@ void PackExe::unpack(OutputFile *fo) {
|
|||||||
|
|
||||||
unsigned imagesize = ih_imagesize;
|
unsigned imagesize = ih_imagesize;
|
||||||
imagesize--;
|
imagesize--;
|
||||||
const unsigned char flag = ibuf[imagesize];
|
const byte flag = ibuf[imagesize];
|
||||||
|
|
||||||
unsigned relocn = 0;
|
unsigned relocn = 0;
|
||||||
SPAN_S_VAR(upx_byte, relocs, obuf + ph.u_len, obuf);
|
SPAN_S_VAR(byte, relocs, obuf + ph.u_len, obuf);
|
||||||
|
|
||||||
MemBuffer mb_wrkmem;
|
MemBuffer mb_wrkmem;
|
||||||
SPAN_0_VAR(upx_byte, wrkmem, nullptr);
|
SPAN_0_VAR(byte, wrkmem, nullptr);
|
||||||
if (!(flag & NORELOC)) {
|
if (!(flag & NORELOC)) {
|
||||||
relocs -= get_le16(obuf + (ph.u_len - 2));
|
relocs -= get_le16(obuf + (ph.u_len - 2));
|
||||||
ph.u_len -= 2;
|
ph.u_len -= 2;
|
||||||
@@ -623,7 +623,7 @@ void PackExe::unpack(OutputFile *fo) {
|
|||||||
wrkmem = mb_wrkmem; // => now a SPAN_S
|
wrkmem = mb_wrkmem; // => now a SPAN_S
|
||||||
unsigned es = 0, ones = get_le16(relocs);
|
unsigned es = 0, ones = get_le16(relocs);
|
||||||
const unsigned seghi = get_le16(relocs + 2);
|
const unsigned seghi = get_le16(relocs + 2);
|
||||||
SPAN_S_VAR(const upx_byte, p, relocs + 4);
|
SPAN_S_VAR(const byte, p, relocs + 4);
|
||||||
|
|
||||||
while (ones) {
|
while (ones) {
|
||||||
unsigned di = get_le16(p);
|
unsigned di = get_le16(p);
|
||||||
@@ -637,7 +637,7 @@ void PackExe::unpack(OutputFile *fo) {
|
|||||||
}
|
}
|
||||||
dorel = true;
|
dorel = true;
|
||||||
if (*p == 0) {
|
if (*p == 0) {
|
||||||
SPAN_S_VAR(const upx_byte, q, obuf);
|
SPAN_S_VAR(const byte, q, obuf);
|
||||||
for (q = obuf + (es * 16 + di); !(*q == 0x9a && get_le16(q + 3) <= seghi);
|
for (q = obuf + (es * 16 + di); !(*q == 0x9a && get_le16(q + 3) <= seghi);
|
||||||
q++) {
|
q++) {
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-19
@@ -126,10 +126,10 @@ bool PackPs1::readBkupHeader() {
|
|||||||
fi->readx(&bh, sizeof(bh));
|
fi->readx(&bh, sizeof(bh));
|
||||||
|
|
||||||
if (bh.ih_csum != upx_adler32(&bh, SZ_IH_BKUP)) {
|
if (bh.ih_csum != upx_adler32(&bh, SZ_IH_BKUP)) {
|
||||||
unsigned char buf[sizeof(bh)];
|
byte buf[sizeof(bh)];
|
||||||
fi->seek(sizeof(ps1_exe_t), SEEK_SET);
|
fi->seek(sizeof(ps1_exe_t), SEEK_SET);
|
||||||
fi->readx(buf, sizeof(bh));
|
fi->readx(buf, sizeof(bh));
|
||||||
if (!getBkupHeader(buf, (unsigned char *) &bh))
|
if (!getBkupHeader(buf, (byte *) &bh))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -144,11 +144,11 @@ bool PackPs1::readBkupHeader() {
|
|||||||
ACC_BLOCK_END
|
ACC_BLOCK_END
|
||||||
#define ADLER16(a) (((a) >> 16) ^ ((a) &0xffff))
|
#define ADLER16(a) (((a) >> 16) ^ ((a) &0xffff))
|
||||||
|
|
||||||
void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len) {
|
void PackPs1::putBkupHeader(const byte *src, byte *dst, unsigned *len) {
|
||||||
unsigned sz_cbh = MemBuffer::getSizeForCompression(SZ_IH_BKUP);
|
unsigned sz_cbh = MemBuffer::getSizeForCompression(SZ_IH_BKUP);
|
||||||
|
|
||||||
if (src && dst) {
|
if (src && dst) {
|
||||||
unsigned char *cpr_bh = New(unsigned char, sz_cbh);
|
ByteArray(cpr_bh, sz_cbh);
|
||||||
|
|
||||||
memset(cpr_bh, 0, sizeof(bh));
|
memset(cpr_bh, 0, sizeof(bh));
|
||||||
ps1_exe_chb_t *p = (ps1_exe_chb_t *) cpr_bh;
|
ps1_exe_chb_t *p = (ps1_exe_chb_t *) cpr_bh;
|
||||||
@@ -161,7 +161,6 @@ void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsign
|
|||||||
*len = ALIGN_UP(sz_cbh + (unsigned) sizeof(ps1_exe_chb_t) - 1, 4u);
|
*len = ALIGN_UP(sz_cbh + (unsigned) sizeof(ps1_exe_chb_t) - 1, 4u);
|
||||||
p->ih_csum = ADLER16(upx_adler32(&ih.epc, SZ_IH_BKUP));
|
p->ih_csum = ADLER16(upx_adler32(&ih.epc, SZ_IH_BKUP));
|
||||||
memcpy(dst, cpr_bh, SZ_IH_BKUP);
|
memcpy(dst, cpr_bh, SZ_IH_BKUP);
|
||||||
delete[] cpr_bh;
|
|
||||||
} else
|
} else
|
||||||
throwInternalError("header compression failed");
|
throwInternalError("header compression failed");
|
||||||
}
|
}
|
||||||
@@ -170,15 +169,15 @@ void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsign
|
|||||||
#define ADLER16_LO(a, b) (((a) >> 16) ^ (b))
|
#define ADLER16_LO(a, b) (((a) >> 16) ^ (b))
|
||||||
#define RE_ADLER16(a, b) (ADLER16_HI(a, b) | ADLER16_LO(a, b))
|
#define RE_ADLER16(a, b) (ADLER16_HI(a, b) | ADLER16_LO(a, b))
|
||||||
|
|
||||||
bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst) {
|
bool PackPs1::getBkupHeader(byte *p, byte *dst) {
|
||||||
ps1_exe_chb_t *src = (ps1_exe_chb_t *) p;
|
ps1_exe_chb_t *src = (ps1_exe_chb_t *) p;
|
||||||
|
|
||||||
if (src && (src->id == '1' && src->len < SZ_IH_BKUP) && dst) {
|
if (src && (src->id == '1' && src->len < SZ_IH_BKUP) && dst) {
|
||||||
unsigned char *unc_bh = New(unsigned char, MemBuffer::getSizeForDecompression(SZ_IH_BKUP));
|
ByteArray(unc_bh, MemBuffer::getSizeForDecompression(SZ_IH_BKUP));
|
||||||
|
|
||||||
unsigned sz_bh = SZ_IH_BKUP;
|
unsigned sz_bh = SZ_IH_BKUP;
|
||||||
int r = upx_decompress((const unsigned char *) &src->ih_bkup, src->len, unc_bh, &sz_bh,
|
int r = upx_decompress((const byte *) &src->ih_bkup, src->len, unc_bh, &sz_bh, M_NRV2E_8,
|
||||||
M_NRV2E_8, nullptr);
|
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)
|
||||||
@@ -188,7 +187,6 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst) {
|
|||||||
if (ad != RE_ADLER16(ad, ch))
|
if (ad != RE_ADLER16(ad, ch))
|
||||||
throwInternalError("backup header damaged");
|
throwInternalError("backup header damaged");
|
||||||
memcpy(dst, unc_bh, SZ_IH_BKUP);
|
memcpy(dst, unc_bh, SZ_IH_BKUP);
|
||||||
delete[] unc_bh;
|
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -223,7 +221,7 @@ bool PackPs1::checkFileHeader() {
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackPs1::canPack() {
|
bool PackPs1::canPack() {
|
||||||
unsigned char buf[PS_HDR_SIZE - sizeof(ps1_exe_t)];
|
byte buf[PS_HDR_SIZE - sizeof(ps1_exe_t)];
|
||||||
|
|
||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
@@ -295,7 +293,7 @@ void PackPs1::buildLoader(const Filter *) {
|
|||||||
} else {
|
} else {
|
||||||
if (M_IS_LZMA(ph.method) && buildPart2) {
|
if (M_IS_LZMA(ph.method) && buildPart2) {
|
||||||
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
|
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
|
||||||
unsigned char *cprLoader = New(unsigned char, sz_lcpr);
|
byte *cprLoader = New(byte, sz_lcpr); // FIXME: does this leak? => should put into class
|
||||||
int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr, nullptr, M_NRV2B_8, 10,
|
int r = upx_compress(getLoader(), sz_lunc, cprLoader, &sz_lcpr, nullptr, M_NRV2B_8, 10,
|
||||||
nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
|
if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
|
||||||
@@ -303,13 +301,12 @@ 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),
|
||||||
isCon || !M_IS_LZMA(ph.method) ? 0 : 1);
|
isCon || !M_IS_LZMA(ph.method) ? 0 : 1);
|
||||||
linker->addSection("lzma.exec", cprLoader, sz_lcpr, 0);
|
linker->addSection("lzma.exec", cprLoader, sz_lcpr, 0);
|
||||||
delete[] cprLoader;
|
|
||||||
} else
|
} else
|
||||||
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
|
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
|
||||||
|
|
||||||
pad_code = ALIGN_GAP((ph.c_len + (isCon ? sz_lcpr : 0)), 4u);
|
pad_code = ALIGN_GAP((ph.c_len + (isCon ? sz_lcpr : 0)), 4u);
|
||||||
assert(pad_code < 4);
|
assert(pad_code < 4);
|
||||||
static const unsigned char pad_buffer[4] = {0, 0, 0, 0};
|
static const byte pad_buffer[4] = {0, 0, 0, 0};
|
||||||
linker->addSection("pad.code", pad_buffer, pad_code, 0);
|
linker->addSection("pad.code", pad_buffer, pad_code, 0);
|
||||||
|
|
||||||
if (isCon) {
|
if (isCon) {
|
||||||
@@ -363,7 +360,7 @@ void PackPs1::buildLoader(const Filter *) {
|
|||||||
#define BSS_CHK_LIMIT (18)
|
#define BSS_CHK_LIMIT (18)
|
||||||
|
|
||||||
bool PackPs1::findBssSection() {
|
bool PackPs1::findBssSection() {
|
||||||
unsigned char reg;
|
byte reg;
|
||||||
const LE32 *const p1 = ACC_CCAST(const LE32 *, ibuf + (ih.epc - ih.tx_ptr));
|
const LE32 *const p1 = ACC_CCAST(const LE32 *, ibuf + (ih.epc - ih.tx_ptr));
|
||||||
|
|
||||||
if ((ih.epc - ih.tx_ptr + (BSS_CHK_LIMIT * 4)) > fdata_size)
|
if ((ih.epc - ih.tx_ptr + (BSS_CHK_LIMIT * 4)) > fdata_size)
|
||||||
@@ -413,7 +410,7 @@ bool PackPs1::findBssSection() {
|
|||||||
void PackPs1::pack(OutputFile *fo) {
|
void PackPs1::pack(OutputFile *fo) {
|
||||||
ibuf.alloc(fdata_size);
|
ibuf.alloc(fdata_size);
|
||||||
obuf.allocForCompression(fdata_size);
|
obuf.allocForCompression(fdata_size);
|
||||||
const upx_byte *p_scan = ibuf + fdata_size;
|
const byte *p_scan = ibuf + fdata_size;
|
||||||
|
|
||||||
// read file
|
// read file
|
||||||
fi->seek(PS_HDR_SIZE, SEEK_SET);
|
fi->seek(PS_HDR_SIZE, SEEK_SET);
|
||||||
@@ -472,7 +469,7 @@ void PackPs1::pack(OutputFile *fo) {
|
|||||||
memcpy(&oh, &ih, sizeof(ih));
|
memcpy(&oh, &ih, sizeof(ih));
|
||||||
|
|
||||||
unsigned sz_cbh;
|
unsigned sz_cbh;
|
||||||
putBkupHeader((const unsigned char *) &ih.epc, (unsigned char *) &bh, &sz_cbh);
|
putBkupHeader((const byte *) &ih.epc, (byte *) &bh, &sz_cbh);
|
||||||
|
|
||||||
if (ih.is_ptr < (EXE_BS | (PS_RAM_SIZE - PS_STACK_SIZE)))
|
if (ih.is_ptr < (EXE_BS | (PS_RAM_SIZE - PS_STACK_SIZE)))
|
||||||
oh.is_ptr = (EXE_BS | (PS_RAM_SIZE - 16));
|
oh.is_ptr = (EXE_BS | (PS_RAM_SIZE - 16));
|
||||||
@@ -529,7 +526,7 @@ void PackPs1::pack(OutputFile *fo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ibuf.clear(0, fdata_size);
|
ibuf.clear(0, fdata_size);
|
||||||
upx_bytep paddata = ibuf;
|
byte *paddata = ibuf;
|
||||||
|
|
||||||
if (M_IS_LZMA(ph.method)) {
|
if (M_IS_LZMA(ph.method)) {
|
||||||
linker->defineSymbol("lzma_init_off", lzma_init);
|
linker->defineSymbol("lzma_init_off", lzma_init);
|
||||||
@@ -593,7 +590,7 @@ void PackPs1::pack(OutputFile *fo) {
|
|||||||
printf("%-13s: bbs end : %08X bytes\n", getName(), (unsigned int) bss_end);
|
printf("%-13s: bbs end : %08X bytes\n", getName(), (unsigned int) bss_end);
|
||||||
printf("%-13s: eof in mem IF : %08X bytes\n", getName(), (unsigned int) ih.tx_ptr + ih.tx_len);
|
printf("%-13s: eof in mem IF : %08X bytes\n", getName(), (unsigned int) ih.tx_ptr + ih.tx_len);
|
||||||
printf("%-13s: eof in mem OF : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr + oh.tx_len);
|
printf("%-13s: eof in mem OF : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr + oh.tx_len);
|
||||||
unsigned char i = 0;
|
byte i = 0;
|
||||||
if (isCon) { if (foundBss) i = 1; }
|
if (isCon) { if (foundBss) i = 1; }
|
||||||
else { i = 2; if (M_IS_LZMA(ph.method)) { if (!foundBss) i = 3; else i = 4; } }
|
else { i = 2; if (M_IS_LZMA(ph.method)) { if (!foundBss) i = 3; else i = 4; } }
|
||||||
const char *loader_method[] = { "con/stack", "con/bss", "cdb", "cdb/stack", "cdb/bss" };
|
const char *loader_method[] = { "con/stack", "con/bss", "cdb", "cdb/stack", "cdb/bss" };
|
||||||
|
|||||||
+5
-5
@@ -56,8 +56,8 @@ public:
|
|||||||
virtual int canUnpack() override;
|
virtual int canUnpack() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len);
|
void putBkupHeader(const byte *src, byte *dst, unsigned *len);
|
||||||
bool getBkupHeader(unsigned char *src, unsigned char *dst);
|
bool getBkupHeader(byte *src, byte *dst);
|
||||||
bool readBkupHeader();
|
bool readBkupHeader();
|
||||||
virtual void buildLoader(const Filter *ft) override;
|
virtual void buildLoader(const Filter *ft) override;
|
||||||
bool findBssSection();
|
bool findBssSection();
|
||||||
@@ -99,10 +99,10 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) ps1_exe_chb_t {
|
struct alignas(1) ps1_exe_chb_t {
|
||||||
unsigned char id;
|
byte id;
|
||||||
unsigned char len;
|
byte len;
|
||||||
LE16 ih_csum;
|
LE16 ih_csum;
|
||||||
unsigned char ih_bkup;
|
byte ih_bkup;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct alignas(1) bss_nfo {
|
struct alignas(1) bss_nfo {
|
||||||
|
|||||||
+2
-2
@@ -41,7 +41,7 @@ static const CLANG_FORMAT_DUMMY_STATEMENT
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackSys::canPack() {
|
bool PackSys::canPack() {
|
||||||
unsigned char buf[128];
|
byte buf[128];
|
||||||
|
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
if (memcmp(buf, "\xff\xff\xff\xff", 4) != 0)
|
if (memcmp(buf, "\xff\xff\xff\xff", 4) != 0)
|
||||||
@@ -83,7 +83,7 @@ void PackSys::buildLoader(const Filter *ft) {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackSys::patchLoader(OutputFile *fo, upx_byte *loader, int lsize, unsigned calls) {
|
void PackSys::patchLoader(OutputFile *fo, byte *loader, int lsize, unsigned calls) {
|
||||||
const int e_len = getLoaderSectionStart("SYSCUTPO");
|
const int e_len = getLoaderSectionStart("SYSCUTPO");
|
||||||
const int d_len = lsize - e_len;
|
const int d_len = lsize - e_len;
|
||||||
assert(e_len > 0 && e_len < 128);
|
assert(e_len > 0 && e_len < 128);
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ public:
|
|||||||
protected: // dos/com overrides
|
protected: // dos/com overrides
|
||||||
virtual unsigned getCallTrickOffset() const override { return 0; }
|
virtual unsigned getCallTrickOffset() const override { return 0; }
|
||||||
virtual void buildLoader(const Filter *ft) override;
|
virtual void buildLoader(const Filter *ft) override;
|
||||||
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned) override;
|
virtual void patchLoader(OutputFile *fo, byte *, int, unsigned) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|||||||
+10
-12
@@ -56,7 +56,7 @@ const int *PackTmt::getFilters() const {
|
|||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned PackTmt::findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf, unsigned range,
|
unsigned PackTmt::findOverlapOverhead(const byte *buf, const byte *tbuf, unsigned range,
|
||||||
unsigned upper_limit) const {
|
unsigned upper_limit) const {
|
||||||
// make sure the decompressor will be paragraph aligned
|
// make sure the decompressor will be paragraph aligned
|
||||||
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
||||||
@@ -89,7 +89,7 @@ void PackTmt::buildLoader(const Filter *ft) {
|
|||||||
int PackTmt::readFileHeader() {
|
int PackTmt::readFileHeader() {
|
||||||
#define H(x) get_le16(h + 2 * (x))
|
#define H(x) get_le16(h + 2 * (x))
|
||||||
#define H4(x) get_le32(h + (x))
|
#define H4(x) get_le32(h + (x))
|
||||||
unsigned char h[0x40];
|
byte h[0x40];
|
||||||
int ic;
|
int ic;
|
||||||
unsigned exe_offset = 0;
|
unsigned exe_offset = 0;
|
||||||
adam_offset = 0;
|
adam_offset = 0;
|
||||||
@@ -181,7 +181,7 @@ void PackTmt::pack(OutputFile *fo) {
|
|||||||
throwCantPack("file is already compressed with another packer");
|
throwCantPack("file is already compressed with another packer");
|
||||||
|
|
||||||
MemBuffer mb_relocs(rsize);
|
MemBuffer mb_relocs(rsize);
|
||||||
SPAN_S_VAR(upx_byte, relocs, mb_relocs);
|
SPAN_S_VAR(byte, relocs, mb_relocs);
|
||||||
fi->readx(relocs, rsize);
|
fi->readx(relocs, rsize);
|
||||||
|
|
||||||
const unsigned overlay = file_size - fi->tell();
|
const unsigned overlay = file_size - fi->tell();
|
||||||
@@ -191,10 +191,9 @@ void PackTmt::pack(OutputFile *fo) {
|
|||||||
set_le32(relocs + ic * 4, get_le32(relocs + ic * 4) - 4);
|
set_le32(relocs + ic * 4, get_le32(relocs + ic * 4) - 4);
|
||||||
|
|
||||||
MemBuffer mb_orelocs(4 * relocnum + 8192); // relocations + extra_info
|
MemBuffer mb_orelocs(4 * relocnum + 8192); // relocations + extra_info
|
||||||
SPAN_S_VAR(upx_byte, orelocs, mb_orelocs);
|
SPAN_S_VAR(byte, orelocs, mb_orelocs);
|
||||||
unsigned orelocsize =
|
unsigned orelocsize =
|
||||||
optimizeReloc(relocnum, relocs, orelocs, ibuf, usize, 32, true, &big_relocs);
|
optimizeReloc(relocnum, relocs, orelocs, ibuf, usize, 32, true, &big_relocs);
|
||||||
relocs.destroy(); // done
|
|
||||||
mb_relocs.dealloc(); // done
|
mb_relocs.dealloc(); // done
|
||||||
// extra_info
|
// extra_info
|
||||||
orelocs[orelocsize++] = 0; // why is this needed - historical oversight ???
|
orelocs[orelocsize++] = 0; // why is this needed - historical oversight ???
|
||||||
@@ -203,7 +202,6 @@ void PackTmt::pack(OutputFile *fo) {
|
|||||||
set_le32(orelocs + orelocsize, orelocsize + 4); // save orelocsize
|
set_le32(orelocs + orelocsize, orelocsize + 4); // save orelocsize
|
||||||
orelocsize += 4;
|
orelocsize += 4;
|
||||||
memcpy(raw_index_bytes(ibuf, usize, orelocsize), orelocs, orelocsize);
|
memcpy(raw_index_bytes(ibuf, usize, orelocsize), orelocs, orelocsize);
|
||||||
orelocs.destroy(); // done
|
|
||||||
mb_orelocs.dealloc(); // done
|
mb_orelocs.dealloc(); // done
|
||||||
|
|
||||||
// prepare packheader
|
// prepare packheader
|
||||||
@@ -249,7 +247,7 @@ void PackTmt::pack(OutputFile *fo) {
|
|||||||
fo->write(loader, e_len);
|
fo->write(loader, e_len);
|
||||||
fo->write(obuf, ph.c_len);
|
fo->write(obuf, ph.c_len);
|
||||||
fo->write(loader + lsize - d_len, d_len); // decompressor
|
fo->write(loader + lsize - d_len, d_len); // decompressor
|
||||||
unsigned char rel_entry[4];
|
byte rel_entry[4];
|
||||||
set_le32(rel_entry, 5 + s_point);
|
set_le32(rel_entry, 5 + s_point);
|
||||||
fo->write(rel_entry, sizeof(rel_entry));
|
fo->write(rel_entry, sizeof(rel_entry));
|
||||||
|
|
||||||
@@ -292,18 +290,18 @@ void PackTmt::unpack(OutputFile *fo) {
|
|||||||
if (ph.filter) {
|
if (ph.filter) {
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.init(ph.filter, 0);
|
ft.init(ph.filter, 0);
|
||||||
ft.cto = (unsigned char) ph.filter_cto;
|
ft.cto = (byte) ph.filter_cto;
|
||||||
if (ph.version < 11)
|
if (ph.version < 11)
|
||||||
ft.cto = (unsigned char) (get_le32(obuf + ph.u_len - 12) >> 24);
|
ft.cto = (byte) (get_le32(obuf + ph.u_len - 12) >> 24);
|
||||||
ft.unfilter(obuf, osize);
|
ft.unfilter(obuf, osize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode relocations
|
// decode relocations
|
||||||
SPAN_S_VAR(const upx_byte, orelocs, raw_index_bytes(obuf, osize, orelocsize), orelocsize);
|
SPAN_S_VAR(const byte, orelocs, raw_index_bytes(obuf, osize, orelocsize), orelocsize);
|
||||||
SPAN_S_VAR(upx_byte, reloc_image, raw_index_bytes(obuf, 0, osize), osize);
|
SPAN_S_VAR(byte, reloc_image, raw_index_bytes(obuf, 0, osize), osize);
|
||||||
MemBuffer mb_relocs;
|
MemBuffer mb_relocs;
|
||||||
const unsigned relocnum = unoptimizeReloc(orelocs, mb_relocs, reloc_image, osize, 32, true);
|
const unsigned relocnum = unoptimizeReloc(orelocs, mb_relocs, reloc_image, osize, 32, true);
|
||||||
SPAN_S_VAR(upx_byte, relocs, mb_relocs);
|
SPAN_S_VAR(byte, relocs, mb_relocs);
|
||||||
for (unsigned ic = 0; ic < relocnum; ic++)
|
for (unsigned ic = 0; ic < relocnum; ic++)
|
||||||
set_le32(relocs + ic * 4, get_le32(relocs + ic * 4) + 4);
|
set_le32(relocs + ic * 4, get_le32(relocs + ic * 4) + 4);
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -56,8 +56,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
int readFileHeader();
|
int readFileHeader();
|
||||||
|
|
||||||
virtual unsigned findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf,
|
virtual unsigned findOverlapOverhead(const byte *buf, const byte *tbuf, unsigned range = 0,
|
||||||
unsigned range = 0,
|
|
||||||
unsigned upper_limit = ~0u) const override;
|
unsigned upper_limit = ~0u) const override;
|
||||||
virtual void buildLoader(const Filter *ft) override;
|
virtual void buildLoader(const Filter *ft) override;
|
||||||
virtual Linker *newLinker() const override;
|
virtual Linker *newLinker() const override;
|
||||||
|
|||||||
+2
-2
@@ -298,7 +298,7 @@ bool PackTos::checkFileHeader() {
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
// Check relocation for errors to make sure our loader can handle it.
|
// Check relocation for errors to make sure our loader can handle it.
|
||||||
static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize, unsigned *nrelocs,
|
static int check_relocs(const byte *relocs, unsigned rsize, unsigned isize, unsigned *nrelocs,
|
||||||
unsigned *relocsize, unsigned *overlay) {
|
unsigned *relocsize, unsigned *overlay) {
|
||||||
unsigned fixup = get_be32(relocs);
|
unsigned fixup = get_be32(relocs);
|
||||||
unsigned last_fixup = fixup;
|
unsigned last_fixup = fixup;
|
||||||
@@ -345,7 +345,7 @@ bool PackTos::canPack() {
|
|||||||
if (!readFileHeader())
|
if (!readFileHeader())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned char buf[768];
|
byte buf[768];
|
||||||
fi->readx(buf, sizeof(buf));
|
fi->readx(buf, sizeof(buf));
|
||||||
checkAlreadyPacked(buf, sizeof(buf));
|
checkAlreadyPacked(buf, sizeof(buf));
|
||||||
|
|
||||||
|
|||||||
+30
-30
@@ -127,7 +127,7 @@ bool PackWcle::canPack() {
|
|||||||
|
|
||||||
void PackWcle::encodeEntryTable() {
|
void PackWcle::encodeEntryTable() {
|
||||||
unsigned count, object, n;
|
unsigned count, object, n;
|
||||||
upx_byte *p = ientries;
|
byte *p = ientries;
|
||||||
n = 0;
|
n = 0;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
count = *p;
|
count = *p;
|
||||||
@@ -208,8 +208,8 @@ void PackWcle::encodeObjectTable() {
|
|||||||
void PackWcle::encodePageMap() {
|
void PackWcle::encodePageMap() {
|
||||||
opm_entries = New(le_pagemap_entry_t, sopm_entries = opages);
|
opm_entries = New(le_pagemap_entry_t, sopm_entries = opages);
|
||||||
for (unsigned ic = 0; ic < sopm_entries; ic++) {
|
for (unsigned ic = 0; ic < sopm_entries; ic++) {
|
||||||
opm_entries[ic].l = (unsigned char) (ic + 1);
|
opm_entries[ic].l = (byte) (ic + 1);
|
||||||
opm_entries[ic].m = (unsigned char) ((ic + 1) >> 8);
|
opm_entries[ic].m = (byte) ((ic + 1) >> 8);
|
||||||
opm_entries[ic].h = 0;
|
opm_entries[ic].h = 0;
|
||||||
opm_entries[ic].type = 0;
|
opm_entries[ic].type = 0;
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ void PackWcle::encodeFixupPageTable() {
|
|||||||
|
|
||||||
void PackWcle::encodeFixups() {
|
void PackWcle::encodeFixups() {
|
||||||
sofixups = 1 * 7 + FIXUP_EXTRA;
|
sofixups = 1 * 7 + FIXUP_EXTRA;
|
||||||
ofixups = New(upx_byte, sofixups);
|
ofixups = New(byte, sofixups);
|
||||||
memset(ofixups, 0, sofixups);
|
memset(ofixups, 0, sofixups);
|
||||||
ofixups[0] = 7;
|
ofixups[0] = 7;
|
||||||
set_le16(ofixups + 2, (LE_STUB_EDI + neweip) & (mps - 1));
|
set_le16(ofixups + 2, (LE_STUB_EDI + neweip) & (mps - 1));
|
||||||
@@ -251,12 +251,12 @@ void PackWcle::preprocessFixups() {
|
|||||||
ByteArray(srf, counts[objects + 0] + 1);
|
ByteArray(srf, counts[objects + 0] + 1);
|
||||||
ByteArray(slf, counts[objects + 1] + 1);
|
ByteArray(slf, counts[objects + 1] + 1);
|
||||||
|
|
||||||
SPAN_S_VAR(upx_byte, relocs, mb_relocs);
|
SPAN_S_VAR(byte, relocs, mb_relocs);
|
||||||
SPAN_S_VAR(upx_byte, selector_fixups, srf_membuf);
|
SPAN_S_VAR(byte, selector_fixups, srf_membuf);
|
||||||
SPAN_S_VAR(upx_byte, selfrel_fixups, slf_membuf);
|
SPAN_S_VAR(byte, selfrel_fixups, slf_membuf);
|
||||||
unsigned relocnum = 0;
|
unsigned relocnum = 0;
|
||||||
|
|
||||||
upx_byte *fix = ifixups;
|
byte *fix = ifixups;
|
||||||
for (ic = jc = 0; ic < pages; ic++) {
|
for (ic = jc = 0; ic < pages; ic++) {
|
||||||
while (ptr_udiff_bytes(fix, ifixups) < get_le32(ifpage_table + (ic + 1))) {
|
while (ptr_udiff_bytes(fix, ifixups) < get_le32(ifpage_table + (ic + 1))) {
|
||||||
const int fixp2 = get_le16_signed(fix + 2);
|
const int fixp2 = get_le16_signed(fix + 2);
|
||||||
@@ -351,9 +351,9 @@ void PackWcle::preprocessFixups() {
|
|||||||
if (sofixups < 4 * relocnum + 8192) {
|
if (sofixups < 4 * relocnum + 8192) {
|
||||||
delete[] ifixups;
|
delete[] ifixups;
|
||||||
sofixups = 4 * relocnum + 8192;
|
sofixups = 4 * relocnum + 8192;
|
||||||
ifixups = New(upx_byte, sofixups);
|
ifixups = New(byte, sofixups);
|
||||||
}
|
}
|
||||||
SPAN_S_VAR(upx_byte, orelocs, ifixups, sofixups);
|
SPAN_S_VAR(byte, orelocs, ifixups, sofixups);
|
||||||
fix =
|
fix =
|
||||||
ifixups + optimizeReloc(relocnum, relocs, orelocs, iimage, soimage, 32, true, &big_relocs);
|
ifixups + optimizeReloc(relocnum, relocs, orelocs, iimage, soimage, 32, true, &big_relocs);
|
||||||
has_extra_code = ptr_udiff_bytes(selector_fixups, srf) != 0;
|
has_extra_code = ptr_udiff_bytes(selector_fixups, srf) != 0;
|
||||||
@@ -431,7 +431,7 @@ void PackWcle::pack(OutputFile *fo) {
|
|||||||
const unsigned text_vaddr = IOT(ih.init_cs_object - 1, my_base_address);
|
const unsigned text_vaddr = IOT(ih.init_cs_object - 1, my_base_address);
|
||||||
|
|
||||||
// attach some useful data at the end of preprocessed fixups
|
// attach some useful data at the end of preprocessed fixups
|
||||||
ifixups[sofixups++] = (unsigned char) (ih.automatic_data_object & 0xff);
|
ifixups[sofixups++] = (byte) (ih.automatic_data_object & 0xff);
|
||||||
unsigned ic = objects * sizeof(*iobject_table);
|
unsigned ic = objects * sizeof(*iobject_table);
|
||||||
memcpy(ifixups + sofixups, iobject_desc, ic);
|
memcpy(ifixups + sofixups, iobject_desc, ic);
|
||||||
iobject_desc.dealloc();
|
iobject_desc.dealloc();
|
||||||
@@ -442,7 +442,7 @@ void PackWcle::pack(OutputFile *fo) {
|
|||||||
set_le32(ifixups + sofixups + 4, ih.init_eip_offset + text_vaddr); // real entry point
|
set_le32(ifixups + sofixups + 4, ih.init_eip_offset + text_vaddr); // real entry point
|
||||||
set_le32(ifixups + sofixups + 8,
|
set_le32(ifixups + sofixups + 8,
|
||||||
mem_size(mps, pages)); // virtual address of unpacked relocations
|
mem_size(mps, pages)); // virtual address of unpacked relocations
|
||||||
ifixups[sofixups + 12] = (unsigned char) (unsigned) objects;
|
ifixups[sofixups + 12] = (byte) (unsigned) objects;
|
||||||
sofixups += 13;
|
sofixups += 13;
|
||||||
|
|
||||||
// prepare filter
|
// prepare filter
|
||||||
@@ -525,7 +525,7 @@ void PackWcle::decodeFixups() {
|
|||||||
mb_iimage.dealloc();
|
mb_iimage.dealloc();
|
||||||
iimage = nullptr;
|
iimage = nullptr;
|
||||||
|
|
||||||
SPAN_S_VAR(const upx_byte, p, oimage + soimage);
|
SPAN_S_VAR(const byte, p, oimage + soimage);
|
||||||
MemBuffer mb_relocs;
|
MemBuffer mb_relocs;
|
||||||
unsigned const fixupn = unoptimizeReloc(p, mb_relocs, oimage, soimage, 32, true);
|
unsigned const fixupn = unoptimizeReloc(p, mb_relocs, oimage, soimage, 32, true);
|
||||||
|
|
||||||
@@ -544,10 +544,10 @@ void PackWcle::decodeFixups() {
|
|||||||
mb_relocs.dealloc(); // done
|
mb_relocs.dealloc(); // done
|
||||||
|
|
||||||
// selector fixups then self-relative fixups
|
// selector fixups then self-relative fixups
|
||||||
SPAN_S_VAR(const upx_byte, selector_fixups, p);
|
SPAN_S_VAR(const byte, selector_fixups, p);
|
||||||
|
|
||||||
// Find selfrel_fixups by skipping over selector_fixups.
|
// Find selfrel_fixups by skipping over selector_fixups.
|
||||||
SPAN_S_VAR(const upx_byte, q, selector_fixups);
|
SPAN_S_VAR(const byte, q, selector_fixups);
|
||||||
// The code is a subroutine that ends in RET (0xC3).
|
// The code is a subroutine that ends in RET (0xC3).
|
||||||
while (*q != 0xC3) {
|
while (*q != 0xC3) {
|
||||||
// Defend against tampered selector_fixups; see PackWcle::preprocessFixups().
|
// Defend against tampered selector_fixups; see PackWcle::preprocessFixups().
|
||||||
@@ -557,14 +557,14 @@ void PackWcle::decodeFixups() {
|
|||||||
// and where byte [+1] also can be '\xDA' or '\xDB'.
|
// and where byte [+1] also can be '\xDA' or '\xDB'.
|
||||||
if (0x8C != q[0] || 0x66 != q[2] || 0x89 != q[3]) { // Unexpected; tampering?
|
if (0x8C != q[0] || 0x66 != q[2] || 0x89 != q[3]) { // Unexpected; tampering?
|
||||||
// Try to recover by looking for the RET.
|
// Try to recover by looking for the RET.
|
||||||
upx_byte const *q2 = (upx_byte const *) memchr(q, 0xC3, 9);
|
const byte *q2 = (const byte *) memchr(q, 0xC3, 9);
|
||||||
if (q2) { // Assume recovery
|
if (q2) { // Assume recovery
|
||||||
q = q2;
|
q = q2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Guard against run-away.
|
// Guard against run-away.
|
||||||
static unsigned char const blank[9] = {0};
|
static byte const blank[9] = {0};
|
||||||
// catastrophic worst case or no-good early warning
|
// catastrophic worst case or no-good early warning
|
||||||
if (ptr_diff_bytes(oimage + ph.u_len - sizeof(blank), raw_bytes(q, 0)) < 0 ||
|
if (ptr_diff_bytes(oimage + ph.u_len - sizeof(blank), raw_bytes(q, 0)) < 0 ||
|
||||||
!memcmp(blank, q, sizeof(blank))) {
|
!memcmp(blank, q, sizeof(blank))) {
|
||||||
@@ -576,11 +576,11 @@ void PackWcle::decodeFixups() {
|
|||||||
q += 9;
|
q += 9;
|
||||||
}
|
}
|
||||||
unsigned selectlen = ptr_udiff_bytes(q, selector_fixups) / 9;
|
unsigned selectlen = ptr_udiff_bytes(q, selector_fixups) / 9;
|
||||||
SPAN_S_VAR(const upx_byte, selfrel_fixups, q + 1); // Skip the 0xC3
|
SPAN_S_VAR(const byte, selfrel_fixups, q + 1); // Skip the 0xC3
|
||||||
|
|
||||||
const unsigned fbytes = fixupn * 9 + 1000 + selectlen * 5;
|
const unsigned fbytes = fixupn * 9 + 1000 + selectlen * 5;
|
||||||
ofixups = New(upx_byte, fbytes);
|
ofixups = New(byte, fbytes);
|
||||||
SPAN_S_VAR(upx_byte, fp, ofixups, fbytes, ofixups);
|
SPAN_S_VAR(byte, fp, ofixups, fbytes, ofixups);
|
||||||
|
|
||||||
for (ic = 1, jc = 0; ic <= opages; ic++) {
|
for (ic = 1, jc = 0; ic <= opages; ic++) {
|
||||||
// self relative fixups
|
// self relative fixups
|
||||||
@@ -592,9 +592,9 @@ void PackWcle::decodeFixups() {
|
|||||||
r += o;
|
r += o;
|
||||||
o = soobject_table;
|
o = soobject_table;
|
||||||
virt2rela(oobject_table, &o, &r);
|
virt2rela(oobject_table, &o, &r);
|
||||||
fp[4] = (unsigned char) o;
|
fp[4] = (byte) o;
|
||||||
set_le32(fp + 5, r);
|
set_le32(fp + 5, r);
|
||||||
fp[1] = (unsigned char) (r > 0xFFFF ? 0x10 : 0);
|
fp[1] = (byte) (r > 0xFFFF ? 0x10 : 0);
|
||||||
fp += fp[1] ? 9 : 7;
|
fp += fp[1] ? 9 : 7;
|
||||||
selfrel_fixups += 4;
|
selfrel_fixups += 4;
|
||||||
dputc('r', stdout);
|
dputc('r', stdout);
|
||||||
@@ -605,7 +605,7 @@ void PackWcle::decodeFixups() {
|
|||||||
fp[1] = 0;
|
fp[1] = 0;
|
||||||
set_le16(fp + 2, r & (mps - 1));
|
set_le16(fp + 2, r & (mps - 1));
|
||||||
unsigned x = selector_fixups[1] > 0xD0 ? oh.init_ss_object : oh.init_cs_object;
|
unsigned x = selector_fixups[1] > 0xD0 ? oh.init_ss_object : oh.init_cs_object;
|
||||||
fp[4] = (unsigned char) x;
|
fp[4] = (byte) x;
|
||||||
fp += 5;
|
fp += 5;
|
||||||
selector_fixups += 9;
|
selector_fixups += 9;
|
||||||
selectlen--;
|
selectlen--;
|
||||||
@@ -618,13 +618,13 @@ void PackWcle::decodeFixups() {
|
|||||||
{
|
{
|
||||||
r = get_le32(oimage + get_le32(wrkmem + 4 * (jc - 2)));
|
r = get_le32(oimage + get_le32(wrkmem + 4 * (jc - 2)));
|
||||||
fp[0] = 7;
|
fp[0] = 7;
|
||||||
fp[1] = (unsigned char) (r > 0xFFFF ? 0x10 : 0);
|
fp[1] = (byte) (r > 0xFFFF ? 0x10 : 0);
|
||||||
set_le16(fp + 2, get_le32(wrkmem + 4 * (jc - 2)) | ~3);
|
set_le16(fp + 2, get_le32(wrkmem + 4 * (jc - 2)) | ~3);
|
||||||
set_le32(fp + 5, r);
|
set_le32(fp + 5, r);
|
||||||
o = soobject_table;
|
o = soobject_table;
|
||||||
r = get_le32(wrkmem + 4 * (jc - 1));
|
r = get_le32(wrkmem + 4 * (jc - 1));
|
||||||
virt2rela(oobject_table, &o, &r);
|
virt2rela(oobject_table, &o, &r);
|
||||||
fp[4] = (unsigned char) o;
|
fp[4] = (byte) o;
|
||||||
fp += fp[1] ? 9 : 7;
|
fp += fp[1] ? 9 : 7;
|
||||||
dputc('0', stdout);
|
dputc('0', stdout);
|
||||||
}
|
}
|
||||||
@@ -633,9 +633,9 @@ void PackWcle::decodeFixups() {
|
|||||||
virt2rela(oobject_table, &o, &r);
|
virt2rela(oobject_table, &o, &r);
|
||||||
r = get_le32(oimage + get_le32(wrkmem + 4 * jc));
|
r = get_le32(oimage + get_le32(wrkmem + 4 * jc));
|
||||||
fp[0] = 7;
|
fp[0] = 7;
|
||||||
fp[1] = (unsigned char) (r > 0xFFFF ? 0x10 : 0);
|
fp[1] = (byte) (r > 0xFFFF ? 0x10 : 0);
|
||||||
set_le16(fp + 2, get_le32(wrkmem + 4 * jc) & (mps - 1));
|
set_le16(fp + 2, get_le32(wrkmem + 4 * jc) & (mps - 1));
|
||||||
fp[4] = (unsigned char) o;
|
fp[4] = (byte) o;
|
||||||
set_le32(fp + 5, r);
|
set_le32(fp + 5, r);
|
||||||
fp += fp[1] ? 9 : 7;
|
fp += fp[1] ? 9 : 7;
|
||||||
jc += 2;
|
jc += 2;
|
||||||
@@ -697,7 +697,7 @@ void PackWcle::decodeImage() {
|
|||||||
|
|
||||||
void PackWcle::decodeEntryTable() {
|
void PackWcle::decodeEntryTable() {
|
||||||
unsigned count, object, n, r;
|
unsigned count, object, n, r;
|
||||||
SPAN_S_VAR(upx_byte, p, ientries, soentries);
|
SPAN_S_VAR(byte, p, ientries, soentries);
|
||||||
n = 0;
|
n = 0;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
count = *p;
|
count = *p;
|
||||||
@@ -776,9 +776,9 @@ void PackWcle::unpack(OutputFile *fo) {
|
|||||||
|
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.init(ph.filter, text_vaddr);
|
ft.init(ph.filter, text_vaddr);
|
||||||
ft.cto = (unsigned char) ph.filter_cto;
|
ft.cto = (byte) ph.filter_cto;
|
||||||
if (ph.version < 11)
|
if (ph.version < 11)
|
||||||
ft.cto = (unsigned char) (get_le32(oimage + ph.u_len - 9) >> 24);
|
ft.cto = (byte) (get_le32(oimage + ph.u_len - 9) >> 24);
|
||||||
ft.unfilter(raw_bytes(oimage + text_vaddr, text_size), text_size);
|
ft.unfilter(raw_bytes(oimage + text_vaddr, text_size), text_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -122,7 +122,7 @@ bool PackWinCeArm::canPack() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PackWinCeArm::buildLoader(const Filter *ft) {
|
void PackWinCeArm::buildLoader(const Filter *ft) {
|
||||||
const unsigned char *loader = use_thumb_stub ? stub_arm_v4t_wince_pe : stub_arm_v4a_wince_pe;
|
const byte *loader = use_thumb_stub ? stub_arm_v4t_wince_pe : stub_arm_v4a_wince_pe;
|
||||||
unsigned size = use_thumb_stub ? sizeof(stub_arm_v4t_wince_pe) : sizeof(stub_arm_v4a_wince_pe);
|
unsigned size = use_thumb_stub ? sizeof(stub_arm_v4t_wince_pe) : sizeof(stub_arm_v4a_wince_pe);
|
||||||
|
|
||||||
// prepare loader
|
// prepare loader
|
||||||
|
|||||||
+36
-37
@@ -180,7 +180,7 @@ int forced_method(int method) // extract the forced method
|
|||||||
// compress - wrap call to low-level upx_compress()
|
// compress - wrap call to low-level upx_compress()
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool Packer::compress(SPAN_P(upx_byte) i_ptr, unsigned i_len, SPAN_P(upx_byte) o_ptr,
|
bool Packer::compress(SPAN_P(byte) i_ptr, unsigned i_len, SPAN_P(byte) o_ptr,
|
||||||
const upx_compress_config_t *cconf_parm) {
|
const upx_compress_config_t *cconf_parm) {
|
||||||
ph.u_len = i_len;
|
ph.u_len = i_len;
|
||||||
ph.c_len = 0;
|
ph.c_len = 0;
|
||||||
@@ -331,8 +331,8 @@ bool Packer::checkFinalCompressionRatio(const OutputFile *fo) const {
|
|||||||
// decompress
|
// decompress
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void ph_decompress(PackHeader &ph, SPAN_P(const upx_byte) in, SPAN_P(upx_byte) out,
|
void ph_decompress(PackHeader &ph, SPAN_P(const byte) in, SPAN_P(byte) out, bool verify_checksum,
|
||||||
bool verify_checksum, Filter *ft) {
|
Filter *ft) {
|
||||||
unsigned adler;
|
unsigned adler;
|
||||||
|
|
||||||
// verify checksum of compressed data
|
// verify checksum of compressed data
|
||||||
@@ -364,8 +364,7 @@ void ph_decompress(PackHeader &ph, SPAN_P(const upx_byte) in, SPAN_P(upx_byte) o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packer::decompress(SPAN_P(const upx_byte) in, SPAN_P(upx_byte) out, bool verify_checksum,
|
void Packer::decompress(SPAN_P(const byte) in, SPAN_P(byte) out, bool verify_checksum, Filter *ft) {
|
||||||
Filter *ft) {
|
|
||||||
ph_decompress(ph, in, out, verify_checksum, ft);
|
ph_decompress(ph, in, out, verify_checksum, ft);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,8 +372,8 @@ void Packer::decompress(SPAN_P(const upx_byte) in, SPAN_P(upx_byte) out, bool ve
|
|||||||
// overlapping decompression
|
// overlapping decompression
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_bytep buf,
|
static bool ph_testOverlappingDecompression(const PackHeader &ph, const byte *buf, const byte *tbuf,
|
||||||
const upx_bytep tbuf, unsigned overlap_overhead) {
|
unsigned overlap_overhead) {
|
||||||
if (ph.c_len >= ph.u_len)
|
if (ph.c_len >= ph.u_len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -400,7 +399,7 @@ static bool ph_testOverlappingDecompression(const PackHeader &ph, const upx_byte
|
|||||||
return (r == UPX_E_OK && new_len == ph.u_len);
|
return (r == UPX_E_OK && new_len == ph.u_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Packer::testOverlappingDecompression(const upx_bytep buf, const upx_bytep tbuf,
|
bool Packer::testOverlappingDecompression(const byte *buf, const byte *tbuf,
|
||||||
unsigned overlap_overhead) const {
|
unsigned overlap_overhead) const {
|
||||||
return ph_testOverlappingDecompression(ph, buf, tbuf, overlap_overhead);
|
return ph_testOverlappingDecompression(ph, buf, tbuf, overlap_overhead);
|
||||||
}
|
}
|
||||||
@@ -433,7 +432,7 @@ void Packer::verifyOverlappingDecompression(Filter *ft) {
|
|||||||
obuf.checkState();
|
obuf.checkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packer::verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft) {
|
void Packer::verifyOverlappingDecompression(byte *o_ptr, unsigned o_size, Filter *ft) {
|
||||||
assert(ph.c_len < ph.u_len);
|
assert(ph.c_len < ph.u_len);
|
||||||
assert((int) ph.overlap_overhead > 0);
|
assert((int) ph.overlap_overhead > 0);
|
||||||
if (ph_skipVerify(ph))
|
if (ph_skipVerify(ph))
|
||||||
@@ -455,7 +454,7 @@ void Packer::verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Fi
|
|||||||
// - you can enforce an upper_limit (so that we can fail early)
|
// - you can enforce an upper_limit (so that we can fail early)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
unsigned Packer::findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf, unsigned range,
|
unsigned Packer::findOverlapOverhead(const byte *buf, const byte *tbuf, unsigned range,
|
||||||
unsigned upper_limit) const {
|
unsigned upper_limit) const {
|
||||||
assert((int) range >= 0);
|
assert((int) range >= 0);
|
||||||
|
|
||||||
@@ -635,15 +634,15 @@ int Packer::patchPackHeader(void *b, int blen) {
|
|||||||
int boff = find_le32(b, blen, UPX_MAGIC_LE32);
|
int boff = find_le32(b, blen, UPX_MAGIC_LE32);
|
||||||
checkPatch(b, blen, boff, size);
|
checkPatch(b, blen, boff, size);
|
||||||
|
|
||||||
auto bb = (upx_byte *) b;
|
auto bb = (byte *) b;
|
||||||
ph.putPackHeader(SPAN_S_MAKE(upx_byte, bb + boff, blen, bb));
|
ph.putPackHeader(SPAN_S_MAKE(byte, bb + boff, blen, bb));
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Packer::getPackHeader(const void *b, int blen, bool allow_incompressible) {
|
bool Packer::getPackHeader(const void *b, int blen, bool allow_incompressible) {
|
||||||
auto bb = (const upx_byte *) b;
|
auto bb = (const byte *) b;
|
||||||
if (!ph.decodePackHeaderFromBuf(SPAN_S_MAKE(const upx_byte, bb, blen), blen))
|
if (!ph.decodePackHeaderFromBuf(SPAN_S_MAKE(const byte, bb, blen), blen))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (ph.version > getVersion())
|
if (ph.version > getVersion())
|
||||||
@@ -695,7 +694,7 @@ void Packer::checkAlreadyPacked(const void *b, int blen) {
|
|||||||
// is a real PackHeader, e.g.
|
// is a real PackHeader, e.g.
|
||||||
//
|
//
|
||||||
// PackHeader tmp;
|
// PackHeader tmp;
|
||||||
// if (!tmp.decodePackHeaderFromBuf((unsigned char *)b + boff, blen - boff))
|
// if (!tmp.decodePackHeaderFromBuf((byte *)b + boff, blen - boff))
|
||||||
// return;
|
// return;
|
||||||
//
|
//
|
||||||
// This also would require that the buffer in 'b' holds
|
// This also would require that the buffer in 'b' holds
|
||||||
@@ -738,7 +737,7 @@ int Packer::patch_be16(void *b, int blen, unsigned old, unsigned new_) {
|
|||||||
int boff = find_be16(b, blen, old);
|
int boff = find_be16(b, blen, old);
|
||||||
checkPatch(b, blen, boff, 2);
|
checkPatch(b, blen, boff, 2);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_be16(p, new_);
|
set_be16(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -748,7 +747,7 @@ int Packer::patch_be16(void *b, int blen, const void *old, unsigned new_) {
|
|||||||
int boff = find(b, blen, old, 2);
|
int boff = find(b, blen, old, 2);
|
||||||
checkPatch(b, blen, boff, 2);
|
checkPatch(b, blen, boff, 2);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_be16(p, new_);
|
set_be16(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -758,7 +757,7 @@ int Packer::patch_be32(void *b, int blen, unsigned old, unsigned new_) {
|
|||||||
int boff = find_be32(b, blen, old);
|
int boff = find_be32(b, blen, old);
|
||||||
checkPatch(b, blen, boff, 4);
|
checkPatch(b, blen, boff, 4);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_be32(p, new_);
|
set_be32(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -768,7 +767,7 @@ int Packer::patch_be32(void *b, int blen, const void *old, unsigned new_) {
|
|||||||
int boff = find(b, blen, old, 4);
|
int boff = find(b, blen, old, 4);
|
||||||
checkPatch(b, blen, boff, 4);
|
checkPatch(b, blen, boff, 4);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_be32(p, new_);
|
set_be32(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -778,7 +777,7 @@ int Packer::patch_le16(void *b, int blen, unsigned old, unsigned new_) {
|
|||||||
int boff = find_le16(b, blen, old);
|
int boff = find_le16(b, blen, old);
|
||||||
checkPatch(b, blen, boff, 2);
|
checkPatch(b, blen, boff, 2);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_le16(p, new_);
|
set_le16(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -788,7 +787,7 @@ int Packer::patch_le16(void *b, int blen, const void *old, unsigned new_) {
|
|||||||
int boff = find(b, blen, old, 2);
|
int boff = find(b, blen, old, 2);
|
||||||
checkPatch(b, blen, boff, 2);
|
checkPatch(b, blen, boff, 2);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_le16(p, new_);
|
set_le16(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -798,7 +797,7 @@ int Packer::patch_le32(void *b, int blen, unsigned old, unsigned new_) {
|
|||||||
int boff = find_le32(b, blen, old);
|
int boff = find_le32(b, blen, old);
|
||||||
checkPatch(b, blen, boff, 4);
|
checkPatch(b, blen, boff, 4);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_le32(p, new_);
|
set_le32(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -808,7 +807,7 @@ int Packer::patch_le32(void *b, int blen, const void *old, unsigned new_) {
|
|||||||
int boff = find(b, blen, old, 4);
|
int boff = find(b, blen, old, 4);
|
||||||
checkPatch(b, blen, boff, 4);
|
checkPatch(b, blen, boff, 4);
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *) b + boff;
|
byte *p = (byte *) b + boff;
|
||||||
set_le32(p, new_);
|
set_le32(p, new_);
|
||||||
|
|
||||||
return boff;
|
return boff;
|
||||||
@@ -910,9 +909,9 @@ void Packer::addLoaderVA(const char *s, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
upx_byte *Packer::getLoader() const {
|
byte *Packer::getLoader() const {
|
||||||
int size = -1;
|
int size = -1;
|
||||||
upx_byte *oloader = linker->getLoader(&size);
|
byte *oloader = linker->getLoader(&size);
|
||||||
if (oloader == nullptr || size <= 0)
|
if (oloader == nullptr || size <= 0)
|
||||||
throwBadLoader();
|
throwBadLoader();
|
||||||
return oloader;
|
return oloader;
|
||||||
@@ -920,7 +919,7 @@ upx_byte *Packer::getLoader() const {
|
|||||||
|
|
||||||
int Packer::getLoaderSize() const {
|
int Packer::getLoaderSize() const {
|
||||||
int size = -1;
|
int size = -1;
|
||||||
upx_byte *oloader = linker->getLoader(&size);
|
byte *oloader = linker->getLoader(&size);
|
||||||
if (oloader == nullptr || size <= 0)
|
if (oloader == nullptr || size <= 0)
|
||||||
throwBadLoader();
|
throwBadLoader();
|
||||||
return size;
|
return size;
|
||||||
@@ -962,7 +961,7 @@ void Packer::relocateLoader() {
|
|||||||
int lsize = -1;
|
int lsize = -1;
|
||||||
int loff = getLoaderSectionStart("UPX1HEAD", &lsize);
|
int loff = getLoaderSectionStart("UPX1HEAD", &lsize);
|
||||||
assert(lsize == ph.getPackHeaderSize());
|
assert(lsize == ph.getPackHeaderSize());
|
||||||
unsigned char *p = getLoader() + loff;
|
byte *p = getLoader() + loff;
|
||||||
assert(get_le32(p) == UPX_MAGIC_LE32);
|
assert(get_le32(p) == UPX_MAGIC_LE32);
|
||||||
//patchPackHeader(p, lsize);
|
//patchPackHeader(p, lsize);
|
||||||
ph.putPackHeader(p);
|
ph.putPackHeader(p);
|
||||||
@@ -1093,12 +1092,12 @@ done:
|
|||||||
return nfilters;
|
return nfilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Packer::compressWithFilters(upx_bytep i_ptr,
|
void Packer::compressWithFilters(byte *i_ptr,
|
||||||
unsigned const i_len, // written and restored by filters
|
unsigned const i_len, // written and restored by filters
|
||||||
upx_bytep const o_ptr, // where to put compressed output
|
byte *const o_ptr, // where to put compressed output
|
||||||
upx_bytep f_ptr,
|
byte *f_ptr,
|
||||||
unsigned const f_len, // subset of [*i_ptr, +i_len)
|
unsigned const f_len, // subset of [*i_ptr, +i_len)
|
||||||
upx_bytep const hdr_ptr, unsigned const hdr_len,
|
byte *const hdr_ptr, unsigned const hdr_len,
|
||||||
Filter *const parm_ft, // updated
|
Filter *const parm_ft, // updated
|
||||||
unsigned const overlap_range,
|
unsigned const overlap_range,
|
||||||
upx_compress_config_t const *const cconf,
|
upx_compress_config_t const *const cconf,
|
||||||
@@ -1150,7 +1149,7 @@ void Packer::compressWithFilters(upx_bytep i_ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Working buffer for compressed data. Don't waste memory and allocate as needed.
|
// Working buffer for compressed data. Don't waste memory and allocate as needed.
|
||||||
upx_bytep o_tmp = o_ptr;
|
byte *o_tmp = o_ptr;
|
||||||
MemBuffer o_tmp_buf;
|
MemBuffer o_tmp_buf;
|
||||||
|
|
||||||
// compress using all methods/filters
|
// compress using all methods/filters
|
||||||
@@ -1305,15 +1304,15 @@ void Packer::compressWithFilters(Filter *ft, const unsigned overlap_range,
|
|||||||
void Packer::compressWithFilters(Filter *ft, const unsigned overlap_range,
|
void Packer::compressWithFilters(Filter *ft, const unsigned overlap_range,
|
||||||
upx_compress_config_t const *cconf, int filter_strategy,
|
upx_compress_config_t const *cconf, int filter_strategy,
|
||||||
unsigned filter_off, unsigned ibuf_off, unsigned obuf_off,
|
unsigned filter_off, unsigned ibuf_off, unsigned obuf_off,
|
||||||
upx_bytep const hdr_ptr, unsigned hdr_len,
|
byte *const hdr_ptr, unsigned hdr_len,
|
||||||
bool inhibit_compression_check) {
|
bool inhibit_compression_check) {
|
||||||
ibuf.checkState();
|
ibuf.checkState();
|
||||||
obuf.checkState();
|
obuf.checkState();
|
||||||
|
|
||||||
upx_bytep i_ptr = ibuf + ibuf_off;
|
byte *i_ptr = ibuf + ibuf_off;
|
||||||
unsigned i_len = ph.u_len;
|
unsigned i_len = ph.u_len;
|
||||||
upx_bytep o_ptr = obuf + obuf_off;
|
byte *o_ptr = obuf + obuf_off;
|
||||||
upx_bytep f_ptr = ibuf + filter_off;
|
byte *f_ptr = ibuf + filter_off;
|
||||||
unsigned f_len = ft->buf_len ? ft->buf_len : i_len;
|
unsigned f_len = ft->buf_len ? ft->buf_len : i_len;
|
||||||
|
|
||||||
assert(f_ptr + f_len <= i_ptr + i_len);
|
assert(f_ptr + f_len <= i_ptr + i_len);
|
||||||
|
|||||||
+21
-22
@@ -48,8 +48,8 @@ class PackHeader final {
|
|||||||
// these are strictly private to friend Packer
|
// these are strictly private to friend Packer
|
||||||
PackHeader();
|
PackHeader();
|
||||||
|
|
||||||
void putPackHeader(SPAN_S(upx_byte) p);
|
void putPackHeader(SPAN_S(byte) p);
|
||||||
bool decodePackHeaderFromBuf(SPAN_S(const upx_byte) b, int blen);
|
bool decodePackHeaderFromBuf(SPAN_S(const byte) b, int blen);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int getPackHeaderSize() const;
|
int getPackHeaderSize() const;
|
||||||
@@ -94,9 +94,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool ph_skipVerify(const PackHeader &ph);
|
bool ph_skipVerify(const PackHeader &ph);
|
||||||
void ph_decompress(PackHeader &ph, SPAN_P(const upx_byte) in, SPAN_P(upx_byte) out,
|
void ph_decompress(PackHeader &ph, SPAN_P(const byte) in, SPAN_P(byte) out, bool verify_checksum,
|
||||||
bool verify_checksum, Filter *ft);
|
Filter *ft);
|
||||||
bool ph_testOverlappingDecompression(const PackHeader &ph, SPAN_P(const upx_byte) buf,
|
bool ph_testOverlappingDecompression(const PackHeader &ph, SPAN_P(const byte) buf,
|
||||||
unsigned overlap_overhead);
|
unsigned overlap_overhead);
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -161,9 +161,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// main compression drivers
|
// main compression drivers
|
||||||
bool compress(SPAN_P(upx_byte) i_ptr, unsigned i_len, SPAN_P(upx_byte) o_ptr,
|
bool compress(SPAN_P(byte) i_ptr, unsigned i_len, SPAN_P(byte) o_ptr,
|
||||||
const upx_compress_config_t *cconf = nullptr);
|
const upx_compress_config_t *cconf = nullptr);
|
||||||
void decompress(SPAN_P(const upx_byte) in, SPAN_P(upx_byte) out, bool verify_checksum = true,
|
void decompress(SPAN_P(const byte) in, SPAN_P(byte) out, bool verify_checksum = true,
|
||||||
Filter *ft = nullptr);
|
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;
|
||||||
@@ -176,27 +176,27 @@ protected:
|
|||||||
void compressWithFilters(Filter *ft, const unsigned overlap_range,
|
void compressWithFilters(Filter *ft, const unsigned overlap_range,
|
||||||
const upx_compress_config_t *cconf, int filter_strategy,
|
const upx_compress_config_t *cconf, int filter_strategy,
|
||||||
unsigned filter_buf_off, unsigned compress_ibuf_off,
|
unsigned filter_buf_off, unsigned compress_ibuf_off,
|
||||||
unsigned compress_obuf_off, upx_bytep const hdr_ptr, unsigned hdr_len,
|
unsigned compress_obuf_off, byte *const hdr_ptr, unsigned hdr_len,
|
||||||
bool inhibit_compression_check = false);
|
bool inhibit_compression_check = false);
|
||||||
// real compression driver
|
// real compression driver
|
||||||
void compressWithFilters(upx_bytep i_ptr, unsigned i_len, // written and restored by filters
|
void compressWithFilters(byte *i_ptr, unsigned i_len, // written and restored by filters
|
||||||
upx_bytep o_ptr, upx_bytep f_ptr,
|
byte *o_ptr, byte *f_ptr,
|
||||||
unsigned f_len, // subset of [*i_ptr, +i_len)
|
unsigned f_len, // subset of [*i_ptr, +i_len)
|
||||||
upx_bytep const hdr_ptr, unsigned hdr_len,
|
byte *const hdr_ptr, unsigned hdr_len,
|
||||||
Filter *parm_ft, // updated
|
Filter *parm_ft, // updated
|
||||||
unsigned overlap_range, upx_compress_config_t const *cconf,
|
unsigned overlap_range, upx_compress_config_t const *cconf,
|
||||||
int filter_strategy, bool inhibit_compression_check = false);
|
int filter_strategy, bool inhibit_compression_check = false);
|
||||||
|
|
||||||
// util for verifying overlapping decompresion
|
// util for verifying overlapping decompresion
|
||||||
// non-destructive test
|
// non-destructive test
|
||||||
virtual bool testOverlappingDecompression(const upx_bytep buf, const upx_bytep tbuf,
|
virtual bool testOverlappingDecompression(const byte *buf, const byte *tbuf,
|
||||||
unsigned overlap_overhead) const;
|
unsigned overlap_overhead) const;
|
||||||
// non-destructive find
|
// non-destructive find
|
||||||
virtual unsigned findOverlapOverhead(const upx_bytep buf, const upx_bytep tbuf,
|
virtual unsigned findOverlapOverhead(const byte *buf, const byte *tbuf, 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 = nullptr);
|
void verifyOverlappingDecompression(Filter *ft = nullptr);
|
||||||
void verifyOverlappingDecompression(upx_bytep o_ptr, unsigned o_size, Filter *ft = nullptr);
|
void verifyOverlappingDecompression(byte *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);
|
||||||
@@ -209,7 +209,7 @@ protected:
|
|||||||
virtual Linker *newLinker() const = 0;
|
virtual Linker *newLinker() const = 0;
|
||||||
virtual void relocateLoader();
|
virtual void relocateLoader();
|
||||||
// loader util for linker
|
// loader util for linker
|
||||||
virtual upx_byte *getLoader() const;
|
virtual byte *getLoader() const;
|
||||||
virtual int getLoaderSize() const;
|
virtual int getLoaderSize() const;
|
||||||
virtual void initLoader(const void *pdata, int plen, int small = -1, int pextra = 0);
|
virtual void initLoader(const void *pdata, int plen, int small = -1, int pextra = 0);
|
||||||
#define C const char *
|
#define C const char *
|
||||||
@@ -247,7 +247,7 @@ protected:
|
|||||||
|
|
||||||
// filter handling [see packer_f.cpp]
|
// filter handling [see packer_f.cpp]
|
||||||
virtual bool isValidFilter(int filter_id) const;
|
virtual bool isValidFilter(int filter_id) const;
|
||||||
virtual void optimizeFilter(Filter *, const upx_byte *, unsigned) const {}
|
virtual void optimizeFilter(Filter *, const byte *, unsigned) const {}
|
||||||
virtual void addFilter32(int filter_id);
|
virtual void addFilter32(int filter_id);
|
||||||
virtual void defineFilterSymbols(const Filter *ft);
|
virtual void defineFilterSymbols(const Filter *ft);
|
||||||
|
|
||||||
@@ -271,12 +271,11 @@ protected:
|
|||||||
void checkPatch(void *b, int blen, int boff, int size);
|
void checkPatch(void *b, int blen, int boff, int size);
|
||||||
|
|
||||||
// relocation util
|
// relocation util
|
||||||
static unsigned optimizeReloc(unsigned relocnum, SPAN_P(upx_byte) relocs, SPAN_S(upx_byte) out,
|
static unsigned optimizeReloc(unsigned relocnum, SPAN_P(byte) relocs, SPAN_S(byte) out,
|
||||||
SPAN_P(upx_byte) image, unsigned image_size, int bits, bool bswap,
|
SPAN_P(byte) image, unsigned image_size, int bits, bool bswap,
|
||||||
int *big);
|
int *big);
|
||||||
static unsigned unoptimizeReloc(SPAN_S(const upx_byte) & in, MemBuffer &out,
|
static unsigned unoptimizeReloc(SPAN_S(const byte) & in, MemBuffer &out, SPAN_P(byte) image,
|
||||||
SPAN_P(upx_byte) image, unsigned image_size, int bits,
|
unsigned image_size, int bits, bool bswap);
|
||||||
bool bswap);
|
|
||||||
|
|
||||||
// Target Endianness abstraction
|
// Target Endianness abstraction
|
||||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||||
|
|||||||
+10
-11
@@ -33,12 +33,12 @@
|
|||||||
// returns number of bytes written to |out|
|
// returns number of bytes written to |out|
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
unsigned Packer::optimizeReloc(unsigned relocnum, SPAN_P(upx_byte) relocs, SPAN_S(upx_byte) out,
|
unsigned Packer::optimizeReloc(unsigned relocnum, SPAN_P(byte) relocs, SPAN_S(byte) out,
|
||||||
SPAN_P(upx_byte) image, unsigned image_size, int bits, bool bswap,
|
SPAN_P(byte) image, unsigned image_size, int bits, bool bswap,
|
||||||
int *big) {
|
int *big) {
|
||||||
assert(bits == 32 || bits == 64);
|
assert(bits == 32 || bits == 64);
|
||||||
mem_size_assert(1, image_size);
|
mem_size_assert(1, image_size);
|
||||||
SPAN_P_VAR(upx_byte, fix, out);
|
SPAN_P_VAR(byte, fix, out);
|
||||||
|
|
||||||
*big = 0;
|
*big = 0;
|
||||||
if (opt->exact)
|
if (opt->exact)
|
||||||
@@ -55,11 +55,11 @@ unsigned Packer::optimizeReloc(unsigned relocnum, SPAN_P(upx_byte) relocs, SPAN_
|
|||||||
else if ((int) delta < 4)
|
else if ((int) delta < 4)
|
||||||
throwCantPack("overlapping fixups");
|
throwCantPack("overlapping fixups");
|
||||||
else if (delta < 0xf0)
|
else if (delta < 0xf0)
|
||||||
*fix++ = (unsigned char) delta;
|
*fix++ = (byte) delta;
|
||||||
else if (delta < 0x100000) {
|
else if (delta < 0x100000) {
|
||||||
*fix++ = (unsigned char) (0xf0 + (delta >> 16));
|
*fix++ = (byte) (0xf0 + (delta >> 16));
|
||||||
*fix++ = (unsigned char) delta;
|
*fix++ = (byte) delta;
|
||||||
*fix++ = (unsigned char) (delta >> 8);
|
*fix++ = (byte) (delta >> 8);
|
||||||
} else {
|
} else {
|
||||||
*big = 1;
|
*big = 1;
|
||||||
*fix++ = 0xf0;
|
*fix++ = 0xf0;
|
||||||
@@ -88,12 +88,11 @@ unsigned Packer::optimizeReloc(unsigned relocnum, SPAN_P(upx_byte) relocs, SPAN_
|
|||||||
// allocates |out| and returns number of relocs written to |out|
|
// allocates |out| and returns number of relocs written to |out|
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
unsigned Packer::unoptimizeReloc(SPAN_S(const upx_byte) & in, MemBuffer &out,
|
unsigned Packer::unoptimizeReloc(SPAN_S(const byte) & in, MemBuffer &out, SPAN_P(byte) image,
|
||||||
SPAN_P(upx_byte) image, unsigned image_size, int bits,
|
unsigned image_size, int bits, bool bswap) {
|
||||||
bool bswap) {
|
|
||||||
assert(bits == 32 || bits == 64);
|
assert(bits == 32 || bits == 64);
|
||||||
mem_size_assert(1, image_size);
|
mem_size_assert(1, image_size);
|
||||||
SPAN_S_VAR(const upx_byte, fix, in);
|
SPAN_S_VAR(const byte, fix, in);
|
||||||
|
|
||||||
// count
|
// count
|
||||||
unsigned relocnum = 0;
|
unsigned relocnum = 0;
|
||||||
|
|||||||
+18
-20
@@ -41,7 +41,7 @@ PackHeader::PackHeader() : version(-1), format(-1) {}
|
|||||||
// simple checksum for the header itself (since version 10)
|
// simple checksum for the header itself (since version 10)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static unsigned char get_packheader_checksum(SPAN_S(const upx_byte) buf, int len) {
|
static byte get_packheader_checksum(SPAN_S(const byte) buf, int len) {
|
||||||
assert(len >= 4);
|
assert(len >= 4);
|
||||||
assert(get_le32(buf) == UPX_MAGIC_LE32);
|
assert(get_le32(buf) == UPX_MAGIC_LE32);
|
||||||
// printf("1 %d\n", len);
|
// printf("1 %d\n", len);
|
||||||
@@ -52,7 +52,7 @@ static unsigned char get_packheader_checksum(SPAN_S(const upx_byte) buf, int len
|
|||||||
c += *buf++;
|
c += *buf++;
|
||||||
c %= 251;
|
c %= 251;
|
||||||
// printf("2 %d\n", c);
|
// printf("2 %d\n", c);
|
||||||
return (unsigned char) c;
|
return (byte) c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -92,7 +92,7 @@ int PackHeader::getPackHeaderSize() const {
|
|||||||
// see stub/header.ash
|
// see stub/header.ash
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void PackHeader::putPackHeader(SPAN_S(upx_byte) p) {
|
void PackHeader::putPackHeader(SPAN_S(byte) p) {
|
||||||
// NOTE: It is the caller's responsbility to ensure the buffer p has
|
// NOTE: It is the caller's responsbility to ensure the buffer p has
|
||||||
// sufficient space for the header.
|
// sufficient space for the header.
|
||||||
assert(get_le32(p) == UPX_MAGIC_LE32);
|
assert(get_le32(p) == UPX_MAGIC_LE32);
|
||||||
@@ -111,14 +111,14 @@ void PackHeader::putPackHeader(SPAN_S(upx_byte) p) {
|
|||||||
old_chksum = get_packheader_checksum(p, size - 1);
|
old_chksum = get_packheader_checksum(p, size - 1);
|
||||||
set_le16(p + 16, u_len);
|
set_le16(p + 16, u_len);
|
||||||
set_le16(p + 18, c_len);
|
set_le16(p + 18, c_len);
|
||||||
p[20] = (unsigned char) filter;
|
p[20] = (byte) filter;
|
||||||
} else if (format == UPX_F_DOS_EXE) {
|
} else if (format == UPX_F_DOS_EXE) {
|
||||||
size = 27;
|
size = 27;
|
||||||
old_chksum = get_packheader_checksum(p, size - 1);
|
old_chksum = get_packheader_checksum(p, size - 1);
|
||||||
set_le24(p + 16, u_len);
|
set_le24(p + 16, u_len);
|
||||||
set_le24(p + 19, c_len);
|
set_le24(p + 19, c_len);
|
||||||
set_le24(p + 22, u_file_size);
|
set_le24(p + 22, u_file_size);
|
||||||
p[25] = (unsigned char) filter;
|
p[25] = (byte) filter;
|
||||||
} else if (format == UPX_F_DOS_EXEH) {
|
} else if (format == UPX_F_DOS_EXEH) {
|
||||||
throwInternalError("invalid format");
|
throwInternalError("invalid format");
|
||||||
} else {
|
} else {
|
||||||
@@ -127,10 +127,10 @@ void PackHeader::putPackHeader(SPAN_S(upx_byte) p) {
|
|||||||
set_le32(p + 16, u_len);
|
set_le32(p + 16, u_len);
|
||||||
set_le32(p + 20, c_len);
|
set_le32(p + 20, c_len);
|
||||||
set_le32(p + 24, u_file_size);
|
set_le32(p + 24, u_file_size);
|
||||||
p[28] = (unsigned char) filter;
|
p[28] = (byte) filter;
|
||||||
p[29] = (unsigned char) filter_cto;
|
p[29] = (byte) filter_cto;
|
||||||
assert(n_mru == 0 || (n_mru >= 2 && n_mru <= 256));
|
assert(n_mru == 0 || (n_mru >= 2 && n_mru <= 256));
|
||||||
p[30] = (unsigned char) (n_mru ? n_mru - 1 : 0);
|
p[30] = (byte) (n_mru ? n_mru - 1 : 0);
|
||||||
}
|
}
|
||||||
set_le32(p + 8, u_adler);
|
set_le32(p + 8, u_adler);
|
||||||
set_le32(p + 12, c_adler);
|
set_le32(p + 12, c_adler);
|
||||||
@@ -142,16 +142,16 @@ void PackHeader::putPackHeader(SPAN_S(upx_byte) p) {
|
|||||||
set_be32(p + 16, u_adler);
|
set_be32(p + 16, u_adler);
|
||||||
set_be32(p + 20, c_adler);
|
set_be32(p + 20, c_adler);
|
||||||
set_be32(p + 24, u_file_size);
|
set_be32(p + 24, u_file_size);
|
||||||
p[28] = (unsigned char) filter;
|
p[28] = (byte) filter;
|
||||||
p[29] = (unsigned char) filter_cto;
|
p[29] = (byte) filter_cto;
|
||||||
assert(n_mru == 0 || (n_mru >= 2 && n_mru <= 256));
|
assert(n_mru == 0 || (n_mru >= 2 && n_mru <= 256));
|
||||||
p[30] = (unsigned char) (n_mru ? n_mru - 1 : 0);
|
p[30] = (byte) (n_mru ? n_mru - 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
p[4] = (unsigned char) version;
|
p[4] = (byte) version;
|
||||||
p[5] = (unsigned char) format;
|
p[5] = (byte) format;
|
||||||
p[6] = (unsigned char) method;
|
p[6] = (byte) method;
|
||||||
p[7] = (unsigned char) level;
|
p[7] = (byte) level;
|
||||||
|
|
||||||
// header_checksum
|
// header_checksum
|
||||||
assert(size == getPackHeaderSize());
|
assert(size == getPackHeaderSize());
|
||||||
@@ -170,7 +170,7 @@ void PackHeader::putPackHeader(SPAN_S(upx_byte) p) {
|
|||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool PackHeader::decodePackHeaderFromBuf(SPAN_S(const upx_byte) buf, int blen) {
|
bool PackHeader::decodePackHeaderFromBuf(SPAN_S(const byte) buf, int blen) {
|
||||||
int boff = find_le32(raw_bytes(buf, blen), blen, UPX_MAGIC_LE32);
|
int boff = find_le32(raw_bytes(buf, blen), blen, UPX_MAGIC_LE32);
|
||||||
if (boff < 0)
|
if (boff < 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -178,7 +178,7 @@ bool PackHeader::decodePackHeaderFromBuf(SPAN_S(const upx_byte) buf, int blen) {
|
|||||||
if (blen < 20)
|
if (blen < 20)
|
||||||
throwCantUnpack("header corrupted 1");
|
throwCantUnpack("header corrupted 1");
|
||||||
|
|
||||||
SPAN_S_VAR(const upx_byte, const p, buf + boff);
|
SPAN_S_VAR(const byte, const p, buf + boff);
|
||||||
|
|
||||||
version = p[4];
|
version = p[4];
|
||||||
format = p[5];
|
format = p[5];
|
||||||
@@ -192,9 +192,7 @@ bool PackHeader::decodePackHeaderFromBuf(SPAN_S(const upx_byte) buf, int blen) {
|
|||||||
}
|
}
|
||||||
if (!((format >= 1 && format <= UPX_F_W64PE_ARM64EC) ||
|
if (!((format >= 1 && format <= UPX_F_W64PE_ARM64EC) ||
|
||||||
(format >= 129 && format <= UPX_F_DYLIB_PPC64))) {
|
(format >= 129 && format <= UPX_F_DYLIB_PPC64))) {
|
||||||
char msg[24];
|
throwCantUnpack("unknown format %d", format);
|
||||||
snprintf(msg, sizeof(msg), "unknown format %d", format);
|
|
||||||
throwCantUnpack(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -26,8 +26,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef UPX_PACKMASTER_H__
|
|
||||||
#define UPX_PACKMASTER_H__ 1
|
|
||||||
|
|
||||||
class Packer;
|
class Packer;
|
||||||
class InputFile;
|
class InputFile;
|
||||||
@@ -63,6 +61,4 @@ private:
|
|||||||
options_t *saved_opt = nullptr;
|
options_t *saved_opt = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
+76
-77
@@ -256,7 +256,7 @@ void PeFile::Reloc::newRelocPos(void *p) {
|
|||||||
rel1 = (LE16 *) ((char *) p + sizeof(reloc));
|
rel1 = (LE16 *) ((char *) p + sizeof(reloc));
|
||||||
}
|
}
|
||||||
|
|
||||||
PeFile::Reloc::Reloc(upx_byte *s, unsigned si) : start(s), size(si), rel(nullptr), rel1(nullptr) {
|
PeFile::Reloc::Reloc(byte *s, unsigned si) : 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)
|
||||||
memset(counts, 0, sizeof(counts));
|
memset(counts, 0, sizeof(counts));
|
||||||
@@ -266,7 +266,7 @@ PeFile::Reloc::Reloc(upx_byte *s, unsigned si) : start(s), size(si), rel(nullptr
|
|||||||
}
|
}
|
||||||
|
|
||||||
PeFile::Reloc::Reloc(unsigned relocnum) : start(nullptr), size(0), rel(nullptr), rel1(nullptr) {
|
PeFile::Reloc::Reloc(unsigned relocnum) : start(nullptr), size(0), rel(nullptr), rel1(nullptr) {
|
||||||
start = new upx_byte[mem_size(4, relocnum, 8192)]; // => oxrelocs
|
start = new byte[mem_size(4, relocnum, 8192)]; // => oxrelocs
|
||||||
counts[0] = 0;
|
counts[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ void PeFile::Reloc::add(unsigned pos, unsigned type) {
|
|||||||
set_le32(start + 1024 + 4 * counts[0]++, (pos << 4) + type);
|
set_le32(start + 1024 + 4 * counts[0]++, (pos << 4) + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeFile::Reloc::finish(upx_byte *&p, unsigned &siz) {
|
void PeFile::Reloc::finish(byte *&p, unsigned &siz) {
|
||||||
unsigned prev = 0xffffffff;
|
unsigned prev = 0xffffffff;
|
||||||
set_le32(start + 1024 + 4 * counts[0]++, 0xf0000000);
|
set_le32(start + 1024 + 4 * counts[0]++, 0xf0000000);
|
||||||
qsort(start + 1024, counts[0], 4, le32_compare);
|
qsort(start + 1024, counts[0], 4, le32_compare);
|
||||||
@@ -390,8 +390,8 @@ void PeFile32::processRelocs() // pass1
|
|||||||
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||||
mb_orelocs.alloc(mem_size(4, relocnum, 8192)); // 8192 - safety
|
mb_orelocs.alloc(mem_size(4, relocnum, 8192)); // 8192 - safety
|
||||||
orelocs = mb_orelocs; // => orelocs now is a SPAN_S
|
orelocs = mb_orelocs; // => orelocs now is a SPAN_S
|
||||||
sorelocs = optimizeReloc(xcounts[3], (upx_byte *) fix[3], orelocs, ibuf + rvamin,
|
sorelocs = optimizeReloc(xcounts[3], (byte *) fix[3], orelocs, ibuf + rvamin, ibufgood - rvamin,
|
||||||
ibufgood - rvamin, 32, true, &big_relocs);
|
32, true, &big_relocs);
|
||||||
delete[] fix[3];
|
delete[] fix[3];
|
||||||
|
|
||||||
// Malware that hides behind UPX often has PE header info that is
|
// Malware that hides behind UPX often has PE header info that is
|
||||||
@@ -489,7 +489,7 @@ void PeFile64::processRelocs() // pass1
|
|||||||
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL);
|
||||||
mb_orelocs.alloc(mem_size(4, relocnum, 8192)); // 8192 - safety
|
mb_orelocs.alloc(mem_size(4, relocnum, 8192)); // 8192 - safety
|
||||||
orelocs = mb_orelocs; // => orelocs now is a SPAN_S
|
orelocs = mb_orelocs; // => orelocs now is a SPAN_S
|
||||||
sorelocs = optimizeReloc(xcounts[10], (upx_byte *) fix[10], orelocs, ibuf + rvamin,
|
sorelocs = optimizeReloc(xcounts[10], (byte *) fix[10], orelocs, ibuf + rvamin,
|
||||||
ibufgood - rvamin, 64, true, &big_relocs);
|
ibufgood - rvamin, 64, true, &big_relocs);
|
||||||
|
|
||||||
for (ic = 15; ic; ic--)
|
for (ic = 15; ic; ic--)
|
||||||
@@ -682,7 +682,7 @@ public:
|
|||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
void add(const C *dll, unsigned ordinal) {
|
void add(const C *dll, unsigned ordinal) {
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "byte"
|
||||||
assert(ordinal < 0x10000);
|
assert(ordinal < 0x10000);
|
||||||
char ord[1 + 5 + 1];
|
char ord[1 + 5 + 1];
|
||||||
upx_safe_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
|
upx_safe_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
|
||||||
@@ -691,8 +691,8 @@ public:
|
|||||||
|
|
||||||
template <typename C1, typename C2>
|
template <typename C1, typename C2>
|
||||||
void add(const C1 *dll, const C2 *proc) {
|
void add(const C1 *dll, const C2 *proc) {
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "byte"
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "byte"
|
||||||
assert(proc);
|
assert(proc);
|
||||||
add((const char *) dll, (const char *) proc, 0);
|
add((const char *) dll, (const char *) proc, 0);
|
||||||
}
|
}
|
||||||
@@ -702,7 +702,7 @@ public:
|
|||||||
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;
|
||||||
output = New(upx_byte, output_capacity = osize);
|
output = New(byte, output_capacity = osize);
|
||||||
outputlen = 0;
|
outputlen = 0;
|
||||||
|
|
||||||
// sort the sections by name before adding them all
|
// sort the sections by name before adding them all
|
||||||
@@ -727,8 +727,8 @@ public:
|
|||||||
|
|
||||||
template <typename C1, typename C2>
|
template <typename C1, typename C2>
|
||||||
upx_uint64_t getAddress(const C1 *dll, const C2 *proc) const {
|
upx_uint64_t getAddress(const C1 *dll, const C2 *proc) const {
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C1) == 1) // "char" or "byte"
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C2) == 1) // "char" or "byte"
|
||||||
const Section *s = getThunk((const char *) dll, (const char *) proc, thunk_separator_first);
|
const Section *s = getThunk((const char *) dll, (const char *) proc, thunk_separator_first);
|
||||||
if (s == nullptr &&
|
if (s == nullptr &&
|
||||||
(s = getThunk((const char *) dll, (const char *) proc, thunk_separator)) == nullptr)
|
(s = getThunk((const char *) dll, (const char *) proc, thunk_separator)) == nullptr)
|
||||||
@@ -738,7 +738,7 @@ public:
|
|||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
upx_uint64_t getAddress(const C *dll, unsigned ordinal) const {
|
upx_uint64_t getAddress(const C *dll, unsigned ordinal) const {
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "byte"
|
||||||
assert(ordinal > 0 && ordinal < 0x10000);
|
assert(ordinal > 0 && ordinal < 0x10000);
|
||||||
char ord[1 + 5 + 1];
|
char ord[1 + 5 + 1];
|
||||||
upx_safe_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
|
upx_safe_snprintf(ord, sizeof(ord), "%c%05u", ordinal_id, ordinal);
|
||||||
@@ -751,14 +751,14 @@ public:
|
|||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
upx_uint64_t getAddress(const C *dll) const {
|
upx_uint64_t getAddress(const C *dll) const {
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "byte"
|
||||||
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, true)->offset;
|
return findSection(sdll, true)->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
upx_uint64_t hasDll(const C *dll) const {
|
upx_uint64_t hasDll(const C *dll) const {
|
||||||
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "unsigned char"
|
ACC_COMPILE_TIME_ASSERT(sizeof(C) == 1) // "char" or "byte"
|
||||||
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) != nullptr;
|
return findSection(sdll, false) != nullptr;
|
||||||
}
|
}
|
||||||
@@ -814,8 +814,8 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct udll {
|
struct udll {
|
||||||
const upx_byte *name;
|
const byte *name;
|
||||||
const upx_byte *shname;
|
const byte *shname;
|
||||||
unsigned ordinal;
|
unsigned ordinal;
|
||||||
unsigned iat;
|
unsigned iat;
|
||||||
LEXX *lookupt;
|
LEXX *lookupt;
|
||||||
@@ -878,7 +878,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
|
|||||||
dlls[ic].ordinal = *tarr & 0xffff;
|
dlls[ic].ordinal = *tarr & 0xffff;
|
||||||
} else // it's an import by name
|
} else // it's an import by name
|
||||||
{
|
{
|
||||||
IPTR_VAR(const upx_byte, const name, ibuf + *tarr + 2);
|
IPTR_VAR(const byte, const name, ibuf + *tarr + 2);
|
||||||
unsigned len = strlen(name);
|
unsigned len = strlen(name);
|
||||||
soimport += len + 1;
|
soimport += len + 1;
|
||||||
if (dlls[ic].shname == nullptr || len < strlen(dlls[ic].shname))
|
if (dlls[ic].shname == nullptr || len < strlen(dlls[ic].shname))
|
||||||
@@ -925,7 +925,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
|
|||||||
Interval names(ibuf), iats(ibuf), lookups(ibuf);
|
Interval names(ibuf), iats(ibuf), lookups(ibuf);
|
||||||
|
|
||||||
// create the preprocessed data
|
// create the preprocessed data
|
||||||
SPAN_S_VAR(upx_byte, ppi, oimport); // preprocessed imports
|
SPAN_S_VAR(byte, ppi, oimport); // preprocessed imports
|
||||||
for (ic = 0; ic < dllnum; ic++) {
|
for (ic = 0; ic < dllnum; ic++) {
|
||||||
LEXX *tarr = idlls[ic]->lookupt;
|
LEXX *tarr = idlls[ic]->lookupt;
|
||||||
set_le32(ppi, ilinker->getAddress(idlls[ic]->name));
|
set_le32(ppi, ilinker->getAddress(idlls[ic]->name));
|
||||||
@@ -1309,7 +1309,7 @@ void PeFile::processTls2(Reloc *rel, const Interval *iv, unsigned newaddr,
|
|||||||
SPAN_S_VAR(tls, const tlsp, mb_otls);
|
SPAN_S_VAR(tls, const tlsp, mb_otls);
|
||||||
// now the relocation entries in the tls data area
|
// now the relocation entries in the tls data area
|
||||||
for (ic = 0; ic < iv->ivnum; ic += 4) {
|
for (ic = 0; ic < iv->ivnum; ic += 4) {
|
||||||
SPAN_S_VAR(upx_byte, pp,
|
SPAN_S_VAR(byte, pp,
|
||||||
otls + (iv->ivarr[ic].start - (tlsp->datastart - imagebase) + sizeof(tls)));
|
otls + (iv->ivarr[ic].start - (tlsp->datastart - imagebase) + sizeof(tls)));
|
||||||
LEXX *const p = (LEXX *) raw_bytes(pp, sizeof(LEXX));
|
LEXX *const p = (LEXX *) raw_bytes(pp, sizeof(LEXX));
|
||||||
cb_value_t kc = *p;
|
cb_value_t kc = *p;
|
||||||
@@ -1331,7 +1331,7 @@ void PeFile::processTls2(Reloc *rel, const Interval *iv, unsigned newaddr,
|
|||||||
|
|
||||||
if (use_tls_callbacks) {
|
if (use_tls_callbacks) {
|
||||||
// set handler offset
|
// set handler offset
|
||||||
SPAN_S_VAR(upx_byte, pp, otls);
|
SPAN_S_VAR(byte, pp, otls);
|
||||||
pp = otls + (sotls - 2 * cb_size);
|
pp = otls + (sotls - 2 * cb_size);
|
||||||
*(LEXX *) raw_bytes(pp, sizeof(LEXX)) = tls_handler_offset + imagebase;
|
*(LEXX *) raw_bytes(pp, sizeof(LEXX)) = tls_handler_offset + imagebase;
|
||||||
pp = otls + (sotls - 1 * cb_size);
|
pp = otls + (sotls - 1 * cb_size);
|
||||||
@@ -1351,7 +1351,7 @@ void PeFile::processLoadConf(Interval *iv) // pass 1
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const unsigned lcaddr = IDADDR(PEDIR_LOADCONF);
|
const unsigned lcaddr = IDADDR(PEDIR_LOADCONF);
|
||||||
const upx_byte *const loadconf = ibuf.subref("bad loadconf %#x", lcaddr, 4);
|
const byte *const loadconf = ibuf.subref("bad loadconf %#x", lcaddr, 4);
|
||||||
soloadconf = get_le32(loadconf);
|
soloadconf = get_le32(loadconf);
|
||||||
if (soloadconf == 0)
|
if (soloadconf == 0)
|
||||||
return;
|
return;
|
||||||
@@ -1372,7 +1372,7 @@ void PeFile::processLoadConf(Interval *iv) // pass 1
|
|||||||
}
|
}
|
||||||
|
|
||||||
mb_oloadconf.alloc(soloadconf);
|
mb_oloadconf.alloc(soloadconf);
|
||||||
oloadconf = (upx_byte *) mb_oloadconf.getVoidPtr();
|
oloadconf = (byte *) mb_oloadconf.getVoidPtr();
|
||||||
memcpy(oloadconf, loadconf, soloadconf);
|
memcpy(oloadconf, loadconf, soloadconf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1416,7 +1416,7 @@ struct alignas(1) PeFile::Resource::res_data {
|
|||||||
|
|
||||||
struct PeFile::Resource::upx_rnode {
|
struct PeFile::Resource::upx_rnode {
|
||||||
unsigned id;
|
unsigned id;
|
||||||
upx_byte *name;
|
byte *name;
|
||||||
upx_rnode *parent;
|
upx_rnode *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1432,13 +1432,12 @@ struct PeFile::Resource::upx_rleaf : public PeFile::Resource::upx_rnode {
|
|||||||
res_data data;
|
res_data data;
|
||||||
};
|
};
|
||||||
|
|
||||||
PeFile::Resource::Resource(const upx_byte *ibufstart_, const upx_byte *ibufend_) : root(nullptr) {
|
PeFile::Resource::Resource(const byte *ibufstart_, const byte *ibufend_) : root(nullptr) {
|
||||||
ibufstart = ibufstart_;
|
ibufstart = ibufstart_;
|
||||||
ibufend = ibufend_;
|
ibufend = ibufend_;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeFile::Resource::Resource(const upx_byte *p, const upx_byte *ibufstart_,
|
PeFile::Resource::Resource(const byte *p, const byte *ibufstart_, const byte *ibufend_) {
|
||||||
const upx_byte *ibufend_) {
|
|
||||||
ibufstart = ibufstart_;
|
ibufstart = ibufstart_;
|
||||||
ibufend = ibufend_;
|
ibufend = ibufend_;
|
||||||
newstart = nullptr;
|
newstart = nullptr;
|
||||||
@@ -1462,7 +1461,7 @@ bool PeFile::Resource::next() {
|
|||||||
|
|
||||||
unsigned PeFile::Resource::itype() const { return current->parent->parent->id; }
|
unsigned PeFile::Resource::itype() const { return current->parent->parent->id; }
|
||||||
|
|
||||||
const upx_byte *PeFile::Resource::ntype() const { return current->parent->parent->name; }
|
const byte *PeFile::Resource::ntype() const { return current->parent->parent->name; }
|
||||||
|
|
||||||
unsigned PeFile::Resource::size() const { return ALIGN_UP(current->data.size, 4u); }
|
unsigned PeFile::Resource::size() const { return ALIGN_UP(current->data.size, 4u); }
|
||||||
|
|
||||||
@@ -1474,14 +1473,14 @@ void PeFile::Resource::dump() const { dump(root, 0); }
|
|||||||
|
|
||||||
unsigned PeFile::Resource::iname() const { return current->parent->id; }
|
unsigned PeFile::Resource::iname() const { return current->parent->id; }
|
||||||
|
|
||||||
const upx_byte *PeFile::Resource::nname() const { return current->parent->name; }
|
const byte *PeFile::Resource::nname() const { return current->parent->name; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
unsigned ilang() const {return current->id;}
|
unsigned ilang() const {return current->id;}
|
||||||
const upx_byte *nlang() const {return current->name;}
|
const byte *nlang() const {return current->name;}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void PeFile::Resource::init(const upx_byte *res) {
|
void PeFile::Resource::init(const byte *res) {
|
||||||
COMPILE_TIME_ASSERT(sizeof(res_dir_entry) == 8)
|
COMPILE_TIME_ASSERT(sizeof(res_dir_entry) == 8)
|
||||||
COMPILE_TIME_ASSERT(sizeof(res_dir) == 16 + 8)
|
COMPILE_TIME_ASSERT(sizeof(res_dir) == 16 + 8)
|
||||||
COMPILE_TIME_ASSERT(sizeof(res_data) == 16)
|
COMPILE_TIME_ASSERT(sizeof(res_data) == 16)
|
||||||
@@ -1553,11 +1552,11 @@ PeFile::Resource::upx_rnode *PeFile::Resource::convert(const void *rnode, upx_rn
|
|||||||
branch->children[ic] = child;
|
branch->children[ic] = child;
|
||||||
child->id = rde->tnl;
|
child->id = rde->tnl;
|
||||||
if (child->id & 0x80000000) {
|
if (child->id & 0x80000000) {
|
||||||
const upx_byte *p = start + (child->id & 0x7fffffff);
|
const byte *p = start + (child->id & 0x7fffffff);
|
||||||
ibufcheck(p, 2);
|
ibufcheck(p, 2);
|
||||||
const unsigned len = 2 + 2 * get_le16(p);
|
const unsigned len = 2 + 2 * get_le16(p);
|
||||||
ibufcheck(p, len);
|
ibufcheck(p, len);
|
||||||
child->name = New(upx_byte, len);
|
child->name = New(byte, len);
|
||||||
memcpy(child->name, p, len); // copy unicode string
|
memcpy(child->name, p, len); // copy unicode string
|
||||||
ssize += len; // size of unicode strings
|
ssize += len; // size of unicode strings
|
||||||
}
|
}
|
||||||
@@ -1593,7 +1592,7 @@ void PeFile::Resource::build(const upx_rnode *node, unsigned &bpos, unsigned &sp
|
|||||||
be->tnl = branch->children[ic]->id;
|
be->tnl = branch->children[ic]->id;
|
||||||
be->child = bpos + ((level < 2) ? 0x80000000 : 0);
|
be->child = bpos + ((level < 2) ? 0x80000000 : 0);
|
||||||
|
|
||||||
const upx_byte *p;
|
const byte *p;
|
||||||
if ((p = branch->children[ic]->name) != nullptr) {
|
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())
|
||||||
@@ -1606,12 +1605,12 @@ void PeFile::Resource::build(const upx_rnode *node, unsigned &bpos, unsigned &sp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
upx_byte *PeFile::Resource::build() {
|
byte *PeFile::Resource::build() {
|
||||||
mb_start.dealloc();
|
mb_start.dealloc();
|
||||||
newstart = nullptr;
|
newstart = nullptr;
|
||||||
if (dirsize()) {
|
if (dirsize()) {
|
||||||
mb_start.alloc(dirsize());
|
mb_start.alloc(dirsize());
|
||||||
newstart = static_cast<upx_byte *>(mb_start.getVoidPtr());
|
newstart = static_cast<byte *>(mb_start.getVoidPtr());
|
||||||
unsigned bpos = 0, spos = dsize;
|
unsigned bpos = 0, spos = dsize;
|
||||||
build(root, bpos, spos, 0);
|
build(root, bpos, spos, 0);
|
||||||
|
|
||||||
@@ -1643,7 +1642,7 @@ void PeFile::Resource::destroy(upx_rnode *node, unsigned level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lame_print_unicode(const upx_byte *p) {
|
static void lame_print_unicode(const byte *p) {
|
||||||
for (unsigned ic = 0; ic < get_le16(p); ic++)
|
for (unsigned ic = 0; ic < get_le16(p); ic++)
|
||||||
printf("%c", (char) p[ic * 2 + 2]);
|
printf("%c", (char) p[ic * 2 + 2]);
|
||||||
}
|
}
|
||||||
@@ -1665,7 +1664,7 @@ void PeFile::Resource::dump(const upx_rnode *node, unsigned level) const {
|
|||||||
dump(branch->children[ic], level + 1);
|
dump(branch->children[ic], level + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeFile::Resource::clear(upx_byte *node, unsigned level, Interval *iv) {
|
void PeFile::Resource::clear(byte *node, unsigned level, Interval *iv) {
|
||||||
if (level == 3)
|
if (level == 3)
|
||||||
iv->add(node, sizeof(res_data));
|
iv->add(node, sizeof(res_data));
|
||||||
else {
|
else {
|
||||||
@@ -1679,7 +1678,7 @@ void PeFile::Resource::clear(upx_byte *node, unsigned level, Interval *iv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PeFile::Resource::clear() {
|
bool PeFile::Resource::clear() {
|
||||||
newstart = const_cast<upx_byte *>(start);
|
newstart = const_cast<byte *>(start);
|
||||||
Interval iv(newstart);
|
Interval iv(newstart);
|
||||||
clear(newstart, 0, &iv);
|
clear(newstart, 0, &iv);
|
||||||
iv.flatten();
|
iv.flatten();
|
||||||
@@ -1699,25 +1698,25 @@ void PeFile::processResources(Resource *res, unsigned newaddr) {
|
|||||||
if (res->newoffs())
|
if (res->newoffs())
|
||||||
res->newoffs() += newaddr;
|
res->newoffs() += newaddr;
|
||||||
if (res->dirsize()) {
|
if (res->dirsize()) {
|
||||||
upx_byte *p = res->build();
|
byte *p = res->build();
|
||||||
memcpy(oresources, p, res->dirsize());
|
memcpy(oresources, p, res->dirsize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool match(unsigned itype, const unsigned char *ntype, unsigned iname,
|
static bool match(unsigned itype, const byte *ntype, unsigned iname, const byte *nname,
|
||||||
const unsigned char *nname, const char *keep) {
|
const char *keep) {
|
||||||
// format of string keep: type1[/name1],type2[/name2], ....
|
// format of string keep: type1[/name1],type2[/name2], ....
|
||||||
// typex and namex can be string or number
|
// typex and namex can be string or number
|
||||||
// hopefully resource names do not have '/' or ',' characters inside
|
// hopefully resource names do not have '/' or ',' characters inside
|
||||||
|
|
||||||
struct helper {
|
struct helper {
|
||||||
static bool match(unsigned num, const unsigned char *unistr, const char *mkeep) {
|
static bool match(unsigned num, const byte *unistr, const char *mkeep) {
|
||||||
if (!unistr)
|
if (!unistr)
|
||||||
return (unsigned) atoi(mkeep) == num;
|
return (unsigned) atoi(mkeep) == num;
|
||||||
|
|
||||||
unsigned ic;
|
unsigned ic;
|
||||||
for (ic = 0; ic < get_le16(unistr); ic++)
|
for (ic = 0; ic < get_le16(unistr); ic++)
|
||||||
if (unistr[2 + ic * 2] != (unsigned char) mkeep[ic])
|
if (unistr[2 + ic * 2] != (byte) mkeep[ic])
|
||||||
return false;
|
return false;
|
||||||
return mkeep[ic] == 0 || mkeep[ic] == ',' || mkeep[ic] == '/';
|
return mkeep[ic] == 0 || mkeep[ic] == ',' || mkeep[ic] == '/';
|
||||||
}
|
}
|
||||||
@@ -1770,7 +1769,7 @@ void PeFile::processResources(Resource *res) {
|
|||||||
mb_oresources.alloc(soresources);
|
mb_oresources.alloc(soresources);
|
||||||
mb_oresources.clear();
|
mb_oresources.clear();
|
||||||
oresources = mb_oresources; // => SPAN_S
|
oresources = mb_oresources; // => SPAN_S
|
||||||
SPAN_S_VAR(upx_byte, ores, oresources + res->dirsize());
|
SPAN_S_VAR(byte, ores, oresources + res->dirsize());
|
||||||
|
|
||||||
char *keep_icons = nullptr; // icon ids in the first icon group
|
char *keep_icons = nullptr; // icon ids in the first icon group
|
||||||
unsigned iconsin1stdir = 0;
|
unsigned iconsin1stdir = 0;
|
||||||
@@ -2130,7 +2129,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, unsigned subsystem_mask,
|
|||||||
|
|
||||||
// EFI build tools already clear DOS stub
|
// EFI build tools already clear DOS stub
|
||||||
// and small file alignment benefits from extra space
|
// and small file alignment benefits from extra space
|
||||||
unsigned char stub[0x40];
|
byte stub[0x40];
|
||||||
memset(stub, 0, sizeof(stub));
|
memset(stub, 0, sizeof(stub));
|
||||||
set_le16(stub, 'M' + 'Z' * 256);
|
set_le16(stub, 'M' + 'Z' * 256);
|
||||||
set_le32(stub + sizeof(stub) - sizeof(LE32), sizeof(stub));
|
set_le32(stub + sizeof(stub) - sizeof(LE32), sizeof(stub));
|
||||||
@@ -2162,7 +2161,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, unsigned subsystem_mask,
|
|||||||
Resource res(ibuf, ibuf + ibuf.getSize());
|
Resource res(ibuf, ibuf + ibuf.getSize());
|
||||||
Interval tlsiv(ibuf);
|
Interval tlsiv(ibuf);
|
||||||
Interval loadconfiv(ibuf);
|
Interval loadconfiv(ibuf);
|
||||||
Export xport((char *) (unsigned char *) ibuf);
|
Export xport((char *) (byte *) ibuf);
|
||||||
|
|
||||||
const unsigned dllstrings = processImports();
|
const unsigned dllstrings = processImports();
|
||||||
processTls(&tlsiv); // call before processRelocs!!
|
processTls(&tlsiv); // call before processRelocs!!
|
||||||
@@ -2205,7 +2204,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, unsigned subsystem_mask,
|
|||||||
|
|
||||||
// some extra_info data for uncompression support
|
// some extra_info data for uncompression support
|
||||||
unsigned s = 0;
|
unsigned s = 0;
|
||||||
upx_byte *const p1 = ibuf.subref("bad ph.u_len %#x", ph.u_len, sizeof(ih));
|
byte *const p1 = ibuf.subref("bad ph.u_len %#x", ph.u_len, sizeof(ih));
|
||||||
memcpy(p1 + s, &ih, sizeof(ih));
|
memcpy(p1 + s, &ih, sizeof(ih));
|
||||||
s += sizeof(ih);
|
s += sizeof(ih);
|
||||||
memcpy(p1 + s, isection, ih.objects * sizeof(*isection));
|
memcpy(p1 + s, isection, ih.objects * sizeof(*isection));
|
||||||
@@ -2217,7 +2216,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, unsigned subsystem_mask,
|
|||||||
}
|
}
|
||||||
if (sorelocs) {
|
if (sorelocs) {
|
||||||
set_le32(p1 + s, crelocs);
|
set_le32(p1 + s, crelocs);
|
||||||
p1[s + 4] = (unsigned char) (big_relocs & 6);
|
p1[s + 4] = (byte) (big_relocs & 6);
|
||||||
s += 5;
|
s += 5;
|
||||||
}
|
}
|
||||||
if (soresources) {
|
if (soresources) {
|
||||||
@@ -2536,7 +2535,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh, unsigned subsystem_mask,
|
|||||||
// unpack
|
// unpack
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void PeFile::rebuildRelocs(SPAN_S(upx_byte) & extra_info, unsigned bits, unsigned flags,
|
void PeFile::rebuildRelocs(SPAN_S(byte) & extra_info, unsigned bits, unsigned flags,
|
||||||
upx_uint64_t imagebase) {
|
upx_uint64_t imagebase) {
|
||||||
assert(bits == 32 || bits == 64);
|
assert(bits == 32 || bits == 64);
|
||||||
if (!ODADDR(PEDIR_RELOC) || !ODSIZE(PEDIR_RELOC) || (flags & RELOCS_STRIPPED))
|
if (!ODADDR(PEDIR_RELOC) || !ODSIZE(PEDIR_RELOC) || (flags & RELOCS_STRIPPED))
|
||||||
@@ -2549,10 +2548,10 @@ void PeFile::rebuildRelocs(SPAN_S(upx_byte) & extra_info, unsigned bits, unsigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
const unsigned orig_crelocs = mem_size(1, get_le32(extra_info));
|
const unsigned orig_crelocs = mem_size(1, get_le32(extra_info));
|
||||||
const upx_byte big = extra_info[4];
|
const byte big = extra_info[4];
|
||||||
extra_info += 5;
|
extra_info += 5;
|
||||||
|
|
||||||
SPAN_S_VAR(const upx_byte, rdata, obuf + orig_crelocs, obuf);
|
SPAN_S_VAR(const byte, rdata, obuf + orig_crelocs, obuf);
|
||||||
MemBuffer mb_wrkmem;
|
MemBuffer mb_wrkmem;
|
||||||
unsigned relocnum = unoptimizeReloc(rdata, mb_wrkmem, obuf, orig_crelocs, bits, true);
|
unsigned relocnum = unoptimizeReloc(rdata, mb_wrkmem, obuf, orig_crelocs, bits, true);
|
||||||
unsigned r16 = 0;
|
unsigned r16 = 0;
|
||||||
@@ -2573,12 +2572,12 @@ void PeFile::rebuildRelocs(SPAN_S(upx_byte) & extra_info, unsigned bits, unsigne
|
|||||||
if ((big & 6) == 6)
|
if ((big & 6) == 6)
|
||||||
while (*++q)
|
while (*++q)
|
||||||
rel.add(*q + rvamin, 1);
|
rel.add(*q + rvamin, 1);
|
||||||
// rdata = (upx_byte *) raw_bytes(q, 0); // ???
|
// rdata = (byte *) raw_bytes(q, 0); // ???
|
||||||
}
|
}
|
||||||
|
|
||||||
SPAN_S_VAR(upx_byte, const wrkmem, mb_wrkmem);
|
SPAN_S_VAR(byte, const wrkmem, mb_wrkmem);
|
||||||
for (unsigned ic = 0; ic < relocnum; ic++) {
|
for (unsigned ic = 0; ic < relocnum; ic++) {
|
||||||
OPTR_VAR(upx_byte, const p, obuf + get_le32(wrkmem + 4 * ic));
|
OPTR_VAR(byte, const p, obuf + get_le32(wrkmem + 4 * ic));
|
||||||
if (bits == 32)
|
if (bits == 32)
|
||||||
set_le32(p, get_le32(p) + imagebase + rvamin);
|
set_le32(p, get_le32(p) + imagebase + rvamin);
|
||||||
else
|
else
|
||||||
@@ -2600,7 +2599,7 @@ void PeFile::rebuildExports() {
|
|||||||
return; // nothing to do
|
return; // nothing to do
|
||||||
|
|
||||||
opt->win32_pe.compress_exports = 0;
|
opt->win32_pe.compress_exports = 0;
|
||||||
Export xport((char *) (unsigned char *) ibuf - isection[2].vaddr);
|
Export xport((char *) (byte *) ibuf - isection[2].vaddr);
|
||||||
processExports(&xport);
|
processExports(&xport);
|
||||||
processExports(&xport, ODADDR(PEDIR_EXPORT));
|
processExports(&xport, ODADDR(PEDIR_EXPORT));
|
||||||
omemcpy(obuf + (ODADDR(PEDIR_EXPORT) - rvamin), oexport, soexport);
|
omemcpy(obuf + (ODADDR(PEDIR_EXPORT) - rvamin), oexport, soexport);
|
||||||
@@ -2610,7 +2609,7 @@ void PeFile::rebuildTls() {
|
|||||||
// this is an easy one : just do nothing ;-)
|
// this is an easy one : just do nothing ;-)
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeFile::rebuildResources(SPAN_S(upx_byte) & extra_info, unsigned lastvaddr) {
|
void PeFile::rebuildResources(SPAN_S(byte) & extra_info, unsigned lastvaddr) {
|
||||||
if (ODSIZE(PEDIR_RESOURCE) == 0 || IDSIZE(PEDIR_RESOURCE) == 0)
|
if (ODSIZE(PEDIR_RESOURCE) == 0 || IDSIZE(PEDIR_RESOURCE) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -2623,7 +2622,7 @@ void PeFile::rebuildResources(SPAN_S(upx_byte) & extra_info, unsigned lastvaddr)
|
|||||||
throwCantUnpack("corrupted PE header");
|
throwCantUnpack("corrupted PE header");
|
||||||
|
|
||||||
// TODO: introduce WildPtr for "virtual pointer" pointing before a buffer
|
// TODO: introduce WildPtr for "virtual pointer" pointing before a buffer
|
||||||
const upx_byte *r = ibuf.raw_bytes(0) - lastvaddr;
|
const byte *r = ibuf.raw_bytes(0) - lastvaddr;
|
||||||
Resource res(r + vaddr, ibuf, ibuf + ibuf.getSize());
|
Resource res(r + vaddr, ibuf, ibuf + ibuf.getSize());
|
||||||
while (res.next())
|
while (res.next())
|
||||||
if (res.offs() > vaddr) {
|
if (res.offs() > vaddr) {
|
||||||
@@ -2637,7 +2636,7 @@ void PeFile::rebuildResources(SPAN_S(upx_byte) & extra_info, unsigned lastvaddr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res.dirsize()) {
|
if (res.dirsize()) {
|
||||||
upx_byte *p = res.build();
|
byte *p = res.build();
|
||||||
OCHECK(obuf + (ODADDR(PEDIR_RESOURCE) - rvamin), 16);
|
OCHECK(obuf + (ODADDR(PEDIR_RESOURCE) - rvamin), 16);
|
||||||
// write back when the original is zeroed
|
// write back when the original is zeroed
|
||||||
if (get_le32(obuf + (ODADDR(PEDIR_RESOURCE) - rvamin + 12)) == 0)
|
if (get_le32(obuf + (ODADDR(PEDIR_RESOURCE) - rvamin + 12)) == 0)
|
||||||
@@ -2646,21 +2645,21 @@ void PeFile::rebuildResources(SPAN_S(upx_byte) & extra_info, unsigned lastvaddr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename LEXX, typename ord_mask_t>
|
template <typename LEXX, typename ord_mask_t>
|
||||||
void PeFile::rebuildImports(SPAN_S(upx_byte) & extra_info, ord_mask_t ord_mask, bool set_oft) {
|
void PeFile::rebuildImports(SPAN_S(byte) & extra_info, ord_mask_t ord_mask, bool set_oft) {
|
||||||
if (ODADDR(PEDIR_IMPORT) == 0 || ODSIZE(PEDIR_IMPORT) <= sizeof(import_desc))
|
if (ODADDR(PEDIR_IMPORT) == 0 || ODSIZE(PEDIR_IMPORT) <= sizeof(import_desc))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OPTR_VAR(const upx_byte, const imdata, obuf + mem_size(1, get_le32(extra_info)));
|
OPTR_VAR(const byte, const imdata, obuf + mem_size(1, get_le32(extra_info)));
|
||||||
const unsigned inamespos = mem_size(1, get_le32(extra_info + 4));
|
const unsigned inamespos = mem_size(1, get_le32(extra_info + 4));
|
||||||
extra_info += 8;
|
extra_info += 8;
|
||||||
|
|
||||||
unsigned sdllnames = 0;
|
unsigned sdllnames = 0;
|
||||||
|
|
||||||
IPTR_VAR_OFFSET(const upx_byte, const import, IDADDR(PEDIR_IMPORT) - isection[2].vaddr);
|
IPTR_VAR_OFFSET(const byte, const import, IDADDR(PEDIR_IMPORT) - isection[2].vaddr);
|
||||||
OPTR_VAR(const upx_byte, p, raw_bytes(imdata, 4));
|
OPTR_VAR(const byte, p, raw_bytes(imdata, 4));
|
||||||
|
|
||||||
for (; get_le32(p) != 0; ++p) {
|
for (; get_le32(p) != 0; ++p) {
|
||||||
const upx_byte *dname = raw_bytes(import + mem_size(1, get_le32(p)), 1);
|
const byte *dname = raw_bytes(import + mem_size(1, get_le32(p)), 1);
|
||||||
const unsigned dlen = strlen(dname);
|
const unsigned dlen = strlen(dname);
|
||||||
ICHECK(dname, dlen + 1);
|
ICHECK(dname, dlen + 1);
|
||||||
|
|
||||||
@@ -2676,24 +2675,24 @@ void PeFile::rebuildImports(SPAN_S(upx_byte) & extra_info, ord_mask_t ord_mask,
|
|||||||
sdllnames = ALIGN_UP(sdllnames, 2u);
|
sdllnames = ALIGN_UP(sdllnames, 2u);
|
||||||
|
|
||||||
// TODO: introduce WildPtr for "virtual pointer" pointing before a buffer
|
// TODO: introduce WildPtr for "virtual pointer" pointing before a buffer
|
||||||
upx_byte *const Obuf = obuf.raw_bytes(0) - rvamin;
|
byte *const Obuf = obuf.raw_bytes(0) - rvamin;
|
||||||
#if 0
|
#if 0
|
||||||
import_desc * const im0 = (import_desc*) (Obuf + ODADDR(PEDIR_IMPORT));
|
import_desc * const im0 = (import_desc*) (Obuf + ODADDR(PEDIR_IMPORT));
|
||||||
import_desc *im = im0;
|
import_desc *im = im0;
|
||||||
upx_byte *dllnames = Obuf + inamespos;
|
byte *dllnames = Obuf + inamespos;
|
||||||
upx_byte *importednames = dllnames + sdllnames;
|
byte *importednames = dllnames + sdllnames;
|
||||||
upx_byte * const importednames_start = importednames;
|
byte * const importednames_start = importednames;
|
||||||
#else
|
#else
|
||||||
SPAN_S_VAR(import_desc, const im0, (import_desc *) (Obuf + ODADDR(PEDIR_IMPORT)), obuf);
|
SPAN_S_VAR(import_desc, const im0, (import_desc *) (Obuf + ODADDR(PEDIR_IMPORT)), obuf);
|
||||||
SPAN_S_VAR(import_desc, im, im0);
|
SPAN_S_VAR(import_desc, im, im0);
|
||||||
SPAN_0_VAR(upx_byte, dllnames, inamespos ? Obuf + inamespos : nullptr, obuf);
|
SPAN_0_VAR(byte, dllnames, inamespos ? Obuf + inamespos : nullptr, obuf);
|
||||||
SPAN_0_VAR(upx_byte, importednames, inamespos ? dllnames + sdllnames : nullptr);
|
SPAN_0_VAR(byte, importednames, inamespos ? dllnames + sdllnames : nullptr);
|
||||||
SPAN_0_VAR(upx_byte, const importednames_start, importednames);
|
SPAN_0_VAR(byte, const importednames_start, importednames);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (p = imdata; get_le32(p) != 0; ++p) {
|
for (p = imdata; get_le32(p) != 0; ++p) {
|
||||||
// restore the name of the dll
|
// restore the name of the dll
|
||||||
const upx_byte *dname = raw_bytes(import + get_le32(p), 1);
|
const byte *dname = raw_bytes(import + get_le32(p), 1);
|
||||||
const unsigned dlen = strlen(dname);
|
const unsigned dlen = strlen(dname);
|
||||||
ICHECK(dname, dlen + 1);
|
ICHECK(dname, dlen + 1);
|
||||||
|
|
||||||
@@ -2768,9 +2767,9 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh, ord_mask_t ord_mask,
|
|||||||
decompress(ibuf, obuf);
|
decompress(ibuf, obuf);
|
||||||
unsigned skip = get_le32(obuf + (ph.u_len - 4));
|
unsigned skip = get_le32(obuf + (ph.u_len - 4));
|
||||||
unsigned take = sizeof(oh);
|
unsigned take = sizeof(oh);
|
||||||
SPAN_S_VAR(upx_byte, extra_info, obuf);
|
SPAN_S_VAR(byte, extra_info, obuf);
|
||||||
extra_info = obuf.subref("bad extra_info offset %#x", skip, take);
|
extra_info = obuf.subref("bad extra_info offset %#x", skip, take);
|
||||||
// upx_byte * const eistart = raw_bytes(extra_info, 0);
|
// byte * const eistart = raw_bytes(extra_info, 0);
|
||||||
|
|
||||||
memcpy(&oh, extra_info, take);
|
memcpy(&oh, extra_info, take);
|
||||||
extra_info += take;
|
extra_info += take;
|
||||||
@@ -2799,7 +2798,7 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh, ord_mask_t ord_mask,
|
|||||||
if (ph.filter) {
|
if (ph.filter) {
|
||||||
Filter ft(ph.level);
|
Filter ft(ph.level);
|
||||||
ft.init(ph.filter, oh.codebase - rvamin);
|
ft.init(ph.filter, oh.codebase - rvamin);
|
||||||
ft.cto = (unsigned char) ph.filter_cto;
|
ft.cto = (byte) ph.filter_cto;
|
||||||
OCHECK(obuf + (oh.codebase - rvamin), oh.codesize);
|
OCHECK(obuf + (oh.codebase - rvamin), oh.codesize);
|
||||||
ft.unfilter(obuf + (oh.codebase - rvamin), oh.codesize);
|
ft.unfilter(obuf + (oh.codebase - rvamin), oh.codesize);
|
||||||
}
|
}
|
||||||
@@ -2890,7 +2889,7 @@ int PeFile::canUnpack0(unsigned max_sections, unsigned objs, unsigned ih_entry,
|
|||||||
if (!is_packed && !found_ph)
|
if (!is_packed && !found_ph)
|
||||||
return -1;
|
return -1;
|
||||||
if (is_packed && ih_entry < isection[2].vaddr) {
|
if (is_packed && ih_entry < isection[2].vaddr) {
|
||||||
unsigned char buf[256];
|
byte buf[256];
|
||||||
bool x = false;
|
bool x = false;
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
@@ -2899,7 +2898,7 @@ int PeFile::canUnpack0(unsigned max_sections, unsigned objs, unsigned ih_entry,
|
|||||||
fi->read(buf, sizeof(buf));
|
fi->read(buf, sizeof(buf));
|
||||||
|
|
||||||
// FIXME this is for x86
|
// FIXME this is for x86
|
||||||
static const unsigned char magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb";
|
static const byte magic[] = "\x8b\x1e\x83\xee\xfc\x11\xdb";
|
||||||
// mov ebx, [esi]; sub esi, -4; adc ebx,ebx
|
// mov ebx, [esi]; sub esi, -4; adc ebx,ebx
|
||||||
|
|
||||||
int offset = find(buf, sizeof(buf), magic, 7);
|
int offset = find(buf, sizeof(buf), magic, 7);
|
||||||
|
|||||||
+26
-26
@@ -92,13 +92,13 @@ protected:
|
|||||||
unsigned processImports0(ord_mask_t ord_mask);
|
unsigned processImports0(ord_mask_t ord_mask);
|
||||||
|
|
||||||
template <typename LEXX, typename ord_mask_t>
|
template <typename LEXX, typename ord_mask_t>
|
||||||
void rebuildImports(SPAN_S(upx_byte) & extra_info, ord_mask_t ord_mask, bool set_oft);
|
void rebuildImports(SPAN_S(byte) & extra_info, ord_mask_t ord_mask, bool set_oft);
|
||||||
virtual unsigned processImports() = 0;
|
virtual unsigned processImports() = 0;
|
||||||
virtual void processImports2(unsigned, unsigned);
|
virtual void processImports2(unsigned, unsigned);
|
||||||
MemBuffer mb_oimport;
|
MemBuffer mb_oimport;
|
||||||
SPAN_0(upx_byte) oimport = nullptr;
|
SPAN_0(byte) oimport = nullptr;
|
||||||
unsigned soimport;
|
unsigned soimport;
|
||||||
upx_byte *oimpdlls;
|
byte *oimpdlls;
|
||||||
unsigned soimpdlls;
|
unsigned soimpdlls;
|
||||||
ImportLinker *ilinker;
|
ImportLinker *ilinker;
|
||||||
virtual const char *kernelDll() const { return "KERNEL32.DLL"; }
|
virtual const char *kernelDll() const { return "KERNEL32.DLL"; }
|
||||||
@@ -108,25 +108,25 @@ protected:
|
|||||||
|
|
||||||
virtual void processRelocs() = 0;
|
virtual void processRelocs() = 0;
|
||||||
void processRelocs(Reloc *);
|
void processRelocs(Reloc *);
|
||||||
void rebuildRelocs(SPAN_S(upx_byte) &, unsigned bits, unsigned flags, upx_uint64_t imagebase);
|
void rebuildRelocs(SPAN_S(byte) &, unsigned bits, unsigned flags, upx_uint64_t imagebase);
|
||||||
MemBuffer mb_orelocs;
|
MemBuffer mb_orelocs;
|
||||||
SPAN_0(upx_byte) orelocs = nullptr;
|
SPAN_0(byte) orelocs = nullptr;
|
||||||
unsigned sorelocs;
|
unsigned sorelocs;
|
||||||
upx_byte *oxrelocs = nullptr;
|
byte *oxrelocs = nullptr;
|
||||||
unsigned soxrelocs;
|
unsigned soxrelocs;
|
||||||
|
|
||||||
void processExports(Export *);
|
void processExports(Export *);
|
||||||
void processExports(Export *, unsigned);
|
void processExports(Export *, unsigned);
|
||||||
void rebuildExports();
|
void rebuildExports();
|
||||||
MemBuffer mb_oexport;
|
MemBuffer mb_oexport;
|
||||||
SPAN_0(upx_byte) oexport = nullptr;
|
SPAN_0(byte) oexport = nullptr;
|
||||||
unsigned soexport;
|
unsigned soexport;
|
||||||
|
|
||||||
void processResources(Resource *);
|
void processResources(Resource *);
|
||||||
void processResources(Resource *, unsigned);
|
void processResources(Resource *, unsigned);
|
||||||
void rebuildResources(SPAN_S(upx_byte) &, unsigned);
|
void rebuildResources(SPAN_S(byte) &, unsigned);
|
||||||
MemBuffer mb_oresources;
|
MemBuffer mb_oresources;
|
||||||
SPAN_0(upx_byte) oresources = nullptr;
|
SPAN_0(byte) oresources = nullptr;
|
||||||
unsigned soresources;
|
unsigned soresources;
|
||||||
|
|
||||||
template <typename>
|
template <typename>
|
||||||
@@ -142,7 +142,7 @@ protected:
|
|||||||
|
|
||||||
void rebuildTls();
|
void rebuildTls();
|
||||||
MemBuffer mb_otls;
|
MemBuffer mb_otls;
|
||||||
SPAN_0(upx_byte) otls = nullptr;
|
SPAN_0(byte) otls = nullptr;
|
||||||
unsigned sotls;
|
unsigned sotls;
|
||||||
unsigned tlsindex;
|
unsigned tlsindex;
|
||||||
unsigned tlscb_ptr;
|
unsigned tlscb_ptr;
|
||||||
@@ -152,7 +152,7 @@ protected:
|
|||||||
void processLoadConf(Reloc *, const Interval *, unsigned);
|
void processLoadConf(Reloc *, const Interval *, unsigned);
|
||||||
void processLoadConf(Interval *);
|
void processLoadConf(Interval *);
|
||||||
MemBuffer mb_oloadconf;
|
MemBuffer mb_oloadconf;
|
||||||
upx_byte *oloadconf = nullptr;
|
byte *oloadconf = nullptr;
|
||||||
unsigned soloadconf;
|
unsigned soloadconf;
|
||||||
|
|
||||||
unsigned stripDebug(unsigned);
|
unsigned stripDebug(unsigned);
|
||||||
@@ -353,7 +353,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Reloc : private noncopyable {
|
class Reloc : private noncopyable {
|
||||||
upx_byte *start;
|
byte *start;
|
||||||
unsigned size;
|
unsigned size;
|
||||||
|
|
||||||
void newRelocPos(void *p);
|
void newRelocPos(void *p);
|
||||||
@@ -364,14 +364,14 @@ protected:
|
|||||||
unsigned counts[16];
|
unsigned counts[16];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Reloc(upx_byte *, unsigned);
|
Reloc(byte *, unsigned);
|
||||||
Reloc(unsigned relocnum);
|
Reloc(unsigned relocnum);
|
||||||
//
|
//
|
||||||
bool next(unsigned &pos, unsigned &type);
|
bool next(unsigned &pos, unsigned &type);
|
||||||
const unsigned *getcounts() const { return counts; }
|
const unsigned *getcounts() const { return counts; }
|
||||||
//
|
//
|
||||||
void add(unsigned pos, unsigned type);
|
void add(unsigned pos, unsigned type);
|
||||||
void finish(upx_byte *&p, unsigned &size);
|
void finish(byte *&p, unsigned &size);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Resource : private noncopyable {
|
class Resource : private noncopyable {
|
||||||
@@ -383,50 +383,50 @@ protected:
|
|||||||
struct upx_rleaf;
|
struct upx_rleaf;
|
||||||
|
|
||||||
MemBuffer mb_start;
|
MemBuffer mb_start;
|
||||||
const upx_byte *start;
|
const byte *start;
|
||||||
upx_byte *newstart;
|
byte *newstart;
|
||||||
upx_rnode *root;
|
upx_rnode *root;
|
||||||
upx_rleaf *head;
|
upx_rleaf *head;
|
||||||
upx_rleaf *current;
|
upx_rleaf *current;
|
||||||
unsigned dsize;
|
unsigned dsize;
|
||||||
unsigned ssize;
|
unsigned ssize;
|
||||||
|
|
||||||
const upx_byte *ibufstart;
|
const byte *ibufstart;
|
||||||
const upx_byte *ibufend;
|
const byte *ibufend;
|
||||||
|
|
||||||
void check(const res_dir *, unsigned);
|
void check(const res_dir *, unsigned);
|
||||||
upx_rnode *convert(const void *, upx_rnode *, unsigned);
|
upx_rnode *convert(const void *, upx_rnode *, unsigned);
|
||||||
void build(const upx_rnode *, unsigned &, unsigned &, unsigned);
|
void build(const upx_rnode *, unsigned &, unsigned &, unsigned);
|
||||||
void clear(upx_byte *, unsigned, Interval *);
|
void clear(byte *, unsigned, Interval *);
|
||||||
void dump(const upx_rnode *, unsigned) const;
|
void dump(const upx_rnode *, unsigned) const;
|
||||||
void destroy(upx_rnode *urd, unsigned level);
|
void destroy(upx_rnode *urd, unsigned level);
|
||||||
|
|
||||||
void ibufcheck(const void *m, unsigned size);
|
void ibufcheck(const void *m, unsigned size);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Resource(const upx_byte *ibufstart, const upx_byte *ibufen);
|
Resource(const byte *ibufstart, const byte *ibufen);
|
||||||
Resource(const upx_byte *p, const upx_byte *ibufstart, const upx_byte *ibufend);
|
Resource(const byte *p, const byte *ibufstart, const byte *ibufend);
|
||||||
~Resource();
|
~Resource();
|
||||||
void init(const upx_byte *);
|
void init(const byte *);
|
||||||
|
|
||||||
unsigned dirsize() const;
|
unsigned dirsize() const;
|
||||||
bool next();
|
bool next();
|
||||||
|
|
||||||
unsigned itype() const;
|
unsigned itype() const;
|
||||||
const upx_byte *ntype() const;
|
const byte *ntype() const;
|
||||||
unsigned size() const;
|
unsigned size() const;
|
||||||
unsigned offs() const;
|
unsigned offs() const;
|
||||||
unsigned &newoffs();
|
unsigned &newoffs();
|
||||||
|
|
||||||
upx_byte *build();
|
byte *build();
|
||||||
bool clear();
|
bool clear();
|
||||||
|
|
||||||
void dump() const;
|
void dump() const;
|
||||||
unsigned iname() const;
|
unsigned iname() const;
|
||||||
const upx_byte *nname() const;
|
const byte *nname() const;
|
||||||
/*
|
/*
|
||||||
unsigned ilang() const {return current->id;}
|
unsigned ilang() const {return current->id;}
|
||||||
const upx_byte *nlang() const {return current->name;}
|
const byte *nlang() const {return current->name;}
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -428,10 +428,10 @@ section LXUNF000 // enter at +0 for decompression; +2 for unfiltering
|
|||||||
jmps decompr0
|
jmps decompr0
|
||||||
section LXUNF002
|
section LXUNF002
|
||||||
// 2+ address of decompress subroutine
|
// 2+ address of decompress subroutine
|
||||||
// unfilter(upx_byte *, length, cto8)
|
// unfilter(byte *, length, cto8)
|
||||||
lxunfilter:
|
lxunfilter:
|
||||||
pop edx // return address
|
pop edx // return address
|
||||||
pop eax // upx_byte *, same as addvalue
|
pop eax // byte *, same as addvalue
|
||||||
pop ecx // length
|
pop ecx // length
|
||||||
xchg eax, edi // edi= pointer; eax= saved_edi
|
xchg eax, edi // edi= pointer; eax= saved_edi
|
||||||
pusha // save C-convention ebx, ebp, esi, edi; also eax, edx
|
pusha // save C-convention ebx, ebp, esi, edi; also eax, edx
|
||||||
|
|||||||
@@ -26,8 +26,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef UPX_UI_H__
|
|
||||||
#define UPX_UI_H__ 1
|
|
||||||
|
|
||||||
class OutputFile;
|
class OutputFile;
|
||||||
class Packer;
|
class Packer;
|
||||||
@@ -108,6 +106,4 @@ protected:
|
|||||||
static unsigned update_fu_len;
|
static unsigned update_fu_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* already included */
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ void MemBuffer::checkState() const {
|
|||||||
throwInternalError("block not allocated");
|
throwInternalError("block not allocated");
|
||||||
assert(size_in_bytes > 0);
|
assert(size_in_bytes > 0);
|
||||||
if (use_simple_mcheck()) {
|
if (use_simple_mcheck()) {
|
||||||
const unsigned char *p = (const unsigned char *) ptr;
|
const byte *p = (const byte *) ptr;
|
||||||
if (get_ne32(p - 4) != MAGIC1(p))
|
if (get_ne32(p - 4) != MAGIC1(p))
|
||||||
throwInternalError("memory clobbered before allocated block 1");
|
throwInternalError("memory clobbered before allocated block 1");
|
||||||
if (get_ne32(p - 8) != size_in_bytes)
|
if (get_ne32(p - 8) != size_in_bytes)
|
||||||
@@ -201,7 +201,7 @@ void MemBuffer::alloc(upx_uint64_t bytes) {
|
|||||||
size_t malloc_bytes = mem_size(1, bytes);
|
size_t malloc_bytes = mem_size(1, bytes);
|
||||||
if (use_simple_mcheck())
|
if (use_simple_mcheck())
|
||||||
malloc_bytes += 32;
|
malloc_bytes += 32;
|
||||||
unsigned char *p = (unsigned char *) ::malloc(malloc_bytes);
|
byte *p = (byte *) ::malloc(malloc_bytes);
|
||||||
NO_printf("MemBuffer::alloc %llu: %p\n", bytes, p);
|
NO_printf("MemBuffer::alloc %llu: %p\n", bytes, p);
|
||||||
if (!p)
|
if (!p)
|
||||||
throwOutOfMemoryException();
|
throwOutOfMemoryException();
|
||||||
@@ -234,7 +234,7 @@ void MemBuffer::dealloc() {
|
|||||||
stats.global_dealloc_counter += 1;
|
stats.global_dealloc_counter += 1;
|
||||||
stats.global_total_active_bytes -= size_in_bytes;
|
stats.global_total_active_bytes -= size_in_bytes;
|
||||||
if (use_simple_mcheck()) {
|
if (use_simple_mcheck()) {
|
||||||
unsigned char *p = (unsigned char *) ptr;
|
byte *p = (byte *) ptr;
|
||||||
// clear magic constants
|
// clear magic constants
|
||||||
set_ne32(p - 8, 0);
|
set_ne32(p - 8, 0);
|
||||||
set_ne32(p - 4, 0);
|
set_ne32(p - 4, 0);
|
||||||
@@ -278,7 +278,7 @@ TEST_CASE("MemBuffer") {
|
|||||||
CHECK_THROWS(mb.subref("", 1, 64));
|
CHECK_THROWS(mb.subref("", 1, 64));
|
||||||
CHECK_THROWS(mb.subref("", 64, 1));
|
CHECK_THROWS(mb.subref("", 64, 1));
|
||||||
if (use_simple_mcheck()) {
|
if (use_simple_mcheck()) {
|
||||||
unsigned char *p = raw_bytes(mb, 0);
|
byte *p = raw_bytes(mb, 0);
|
||||||
unsigned magic1 = get_ne32(p - 4);
|
unsigned magic1 = get_ne32(p - 4);
|
||||||
set_ne32(p - 4, magic1 ^ 1);
|
set_ne32(p - 4, magic1 ^ 1);
|
||||||
CHECK_THROWS(mb.checkState());
|
CHECK_THROWS(mb.checkState());
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ public: // raw access
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MemBuffer final : public MemBufferBase<unsigned char> {
|
class MemBuffer final : public MemBufferBase<byte> {
|
||||||
public:
|
public:
|
||||||
MemBuffer() : MemBufferBase<unsigned char>() {}
|
MemBuffer() : MemBufferBase<byte>() {}
|
||||||
explicit MemBuffer(upx_uint64_t bytes);
|
explicit MemBuffer(upx_uint64_t bytes);
|
||||||
~MemBuffer();
|
~MemBuffer();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/* xspan -- a minimally invasive checked memory smart pointer
|
||||||
|
|
||||||
|
This file is part of the UPX executable compressor.
|
||||||
|
|
||||||
|
Copyright (C) 1996-2023 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
UPX and the UCL library are free software; you can redistribute them
|
||||||
|
and/or modify them under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
// raw_bytes() - get underlying memory from checked buffers/pointers.
|
||||||
|
// This is overloaded by various utility classes like MemBuffer and XSpan.
|
||||||
|
//
|
||||||
|
// Note that the pointer type is retained, the "_bytes" hints size_in_bytes
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
// default: for any regular pointer, raw_bytes() is just the pointer itself
|
||||||
|
template <class T>
|
||||||
|
inline
|
||||||
|
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
||||||
|
raw_bytes(T ptr, size_t size_in_bytes) {
|
||||||
|
if (size_in_bytes > 0) {
|
||||||
|
if very_unlikely (ptr == nullptr)
|
||||||
|
throwCantPack("raw_bytes unexpected NULL ptr");
|
||||||
|
if very_unlikely (__acc_cte(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, size_in_bytes) != 0))
|
||||||
|
throwCantPack("raw_bytes valgrind-check-mem");
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// default: for any regular pointer, raw_index_bytes() is just "pointer + index"
|
||||||
|
// NOTE: index == number of elements, *NOT* size in bytes!
|
||||||
|
template <class T>
|
||||||
|
inline
|
||||||
|
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
||||||
|
raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) {
|
||||||
|
typedef typename std::remove_pointer<T>::type element_type;
|
||||||
|
if very_unlikely (ptr == nullptr)
|
||||||
|
throwCantPack("raw_index_bytes unexpected NULL ptr");
|
||||||
|
size_in_bytes = mem_size(sizeof(element_type), index, size_in_bytes); // assert size
|
||||||
|
if very_unlikely (__acc_cte(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, size_in_bytes) != 0))
|
||||||
|
throwCantPack("raw_index_bytes valgrind-check-mem");
|
||||||
|
UNUSED(size_in_bytes);
|
||||||
|
return ptr + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
// same for bounded arrays
|
||||||
|
template <class T, size_t N>
|
||||||
|
inline T *raw_bytes(T (&a)[N], size_t size_in_bytes) {
|
||||||
|
typedef T element_type;
|
||||||
|
if very_unlikely (size_in_bytes > mem_size(sizeof(element_type), N))
|
||||||
|
throwCantPack("raw_bytes out of range");
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T, size_t N>
|
||||||
|
inline T *raw_index_bytes(T (&a)[N], size_t index, size_t size_in_bytes) {
|
||||||
|
typedef T element_type;
|
||||||
|
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
+10
-10
@@ -261,8 +261,8 @@ int find(const void *buf, int blen, const void *what, int wlen) {
|
|||||||
if (buf == nullptr || blen <= 0 || what == nullptr || wlen <= 0)
|
if (buf == nullptr || blen <= 0 || what == nullptr || wlen <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
const unsigned char *b = (const unsigned char *) buf;
|
const byte *b = (const byte *) buf;
|
||||||
unsigned char first_byte = *(const unsigned char *) what;
|
byte first_byte = *(const byte *) what;
|
||||||
|
|
||||||
blen -= wlen;
|
blen -= wlen;
|
||||||
for (int i = 0; i <= blen; i++, b++)
|
for (int i = 0; i <= blen; i++, b++)
|
||||||
@@ -273,44 +273,44 @@ int find(const void *buf, int blen, const void *what, int wlen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int find_be16(const void *b, int blen, unsigned what) {
|
int find_be16(const void *b, int blen, unsigned what) {
|
||||||
unsigned char w[2];
|
byte w[2];
|
||||||
set_be16(w, what);
|
set_be16(w, what);
|
||||||
return find(b, blen, w, 2);
|
return find(b, blen, w, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_be32(const void *b, int blen, unsigned what) {
|
int find_be32(const void *b, int blen, unsigned what) {
|
||||||
unsigned char w[4];
|
byte w[4];
|
||||||
set_be32(w, what);
|
set_be32(w, what);
|
||||||
return find(b, blen, w, 4);
|
return find(b, blen, w, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_be64(const void *b, int blen, upx_uint64_t what) {
|
int find_be64(const void *b, int blen, upx_uint64_t what) {
|
||||||
unsigned char w[8];
|
byte w[8];
|
||||||
set_be64(w, what);
|
set_be64(w, what);
|
||||||
return find(b, blen, w, 8);
|
return find(b, blen, w, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_le16(const void *b, int blen, unsigned what) {
|
int find_le16(const void *b, int blen, unsigned what) {
|
||||||
unsigned char w[2];
|
byte w[2];
|
||||||
set_le16(w, what);
|
set_le16(w, what);
|
||||||
return find(b, blen, w, 2);
|
return find(b, blen, w, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_le32(const void *b, int blen, unsigned what) {
|
int find_le32(const void *b, int blen, unsigned what) {
|
||||||
unsigned char w[4];
|
byte w[4];
|
||||||
set_le32(w, what);
|
set_le32(w, what);
|
||||||
return find(b, blen, w, 4);
|
return find(b, blen, w, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_le64(const void *b, int blen, upx_uint64_t what) {
|
int find_le64(const void *b, int blen, upx_uint64_t what) {
|
||||||
unsigned char w[8];
|
byte w[8];
|
||||||
set_le64(w, what);
|
set_le64(w, what);
|
||||||
return find(b, blen, w, 8);
|
return find(b, blen, w, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("find") {
|
TEST_CASE("find") {
|
||||||
CHECK(find(nullptr, -1, nullptr, -1) == -1);
|
CHECK(find(nullptr, -1, nullptr, -1) == -1);
|
||||||
static const unsigned char b[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
static const byte b[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||||
CHECK(find(b, 16, b, 0) == -1);
|
CHECK(find(b, 16, b, 0) == -1);
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
CHECK(find(b, 16, b + i, 1) == i);
|
CHECK(find(b, 16, b + i, 1) == i);
|
||||||
@@ -330,7 +330,7 @@ TEST_CASE("find") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mem_replace(void *buf, int blen, const void *what, int wlen, const void *replacement) {
|
int mem_replace(void *buf, int blen, const void *what, int wlen, const void *replacement) {
|
||||||
unsigned char *b = (unsigned char *) buf;
|
byte *b = (byte *) buf;
|
||||||
int boff = 0;
|
int boff = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -46,28 +46,28 @@ static XSpanStats xspan_stats;
|
|||||||
// HINT: set env-var "UPX_DEBUG_DOCTEST_DISABLE=1" for improved debugging experience
|
// HINT: set env-var "UPX_DEBUG_DOCTEST_DISABLE=1" for improved debugging experience
|
||||||
noinline void xspan_fail_nullptr() {
|
noinline void xspan_fail_nullptr() {
|
||||||
xspan_stats.fail_nullptr += 1;
|
xspan_stats.fail_nullptr += 1;
|
||||||
throwCantUnpack("xspan unexpected NULL pointer; take care!");
|
throwCantPack("xspan unexpected NULL pointer; take care!");
|
||||||
}
|
}
|
||||||
noinline void xspan_fail_nullbase() {
|
noinline void xspan_fail_nullbase() {
|
||||||
xspan_stats.fail_nullbase += 1;
|
xspan_stats.fail_nullbase += 1;
|
||||||
throwCantUnpack("xspan unexpected NULL base; take care!");
|
throwCantPack("xspan unexpected NULL base; take care!");
|
||||||
}
|
}
|
||||||
noinline void xspan_fail_not_same_base() {
|
noinline void xspan_fail_not_same_base() {
|
||||||
xspan_stats.fail_not_same_base += 1;
|
xspan_stats.fail_not_same_base += 1;
|
||||||
throwInternalError("xspan unexpected base pointer; take care!");
|
throwCantPack("xspan unexpected base pointer; take care!");
|
||||||
}
|
}
|
||||||
|
|
||||||
noinline void xspan_fail_range_nullptr() {
|
noinline void xspan_fail_range_nullptr() {
|
||||||
xspan_stats.fail_range_nullptr += 1;
|
xspan_stats.fail_range_nullptr += 1;
|
||||||
throwCantUnpack("xspan_check_range: unexpected NULL pointer; take care!");
|
throwCantPack("xspan_check_range: unexpected NULL pointer; take care!");
|
||||||
}
|
}
|
||||||
noinline void xspan_fail_range_nullbase() {
|
noinline void xspan_fail_range_nullbase() {
|
||||||
xspan_stats.fail_range_nullbase += 1;
|
xspan_stats.fail_range_nullbase += 1;
|
||||||
throwCantUnpack("xspan_check_range: unexpected NULL base; take care!");
|
throwCantPack("xspan_check_range: unexpected NULL base; take care!");
|
||||||
}
|
}
|
||||||
noinline void xspan_fail_range_range() {
|
noinline void xspan_fail_range_range() {
|
||||||
xspan_stats.fail_range_range += 1;
|
xspan_stats.fail_range_range += 1;
|
||||||
throwCantUnpack("xspan_check_range: pointer out of range; take care!");
|
throwCantPack("xspan_check_range: pointer out of range; take care!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void xspan_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes) {
|
void xspan_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes) {
|
||||||
|
|||||||
@@ -159,56 +159,4 @@ inline R *xspan_make_helper__(R * /*dummy*/, MemBuffer &first) {
|
|||||||
#define SPAN_S_VAR XSPAN_S_VAR
|
#define SPAN_S_VAR XSPAN_S_VAR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
// raw_bytes() - get underlying memory from checked buffers/pointers.
|
|
||||||
// This is overloaded by various utility classes like MemBuffer and XSpan.
|
|
||||||
//
|
|
||||||
// Note that the pointer type is retained, the "_bytes" hints size_in_bytes
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
// default: for any regular pointer, raw_bytes() is just the pointer itself
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
|
||||||
raw_bytes(T ptr, size_t size_in_bytes) {
|
|
||||||
if (size_in_bytes > 0) {
|
|
||||||
if very_unlikely (ptr == nullptr)
|
|
||||||
throwInternalError("raw_bytes unexpected NULL ptr");
|
|
||||||
if very_unlikely (__acc_cte(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, size_in_bytes) != 0))
|
|
||||||
throwInternalError("raw_bytes valgrind-check-mem");
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// default: for any regular pointer, raw_index_bytes() is just "pointer + index"
|
|
||||||
// NOTE: index == number of elements, *NOT* size in bytes!
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
typename std::enable_if<std::is_pointer<T>::value && !std_is_bounded_array<T>::value, T>::type
|
|
||||||
raw_index_bytes(T ptr, size_t index, size_t size_in_bytes) {
|
|
||||||
typedef typename std::remove_pointer<T>::type element_type;
|
|
||||||
if very_unlikely (ptr == nullptr)
|
|
||||||
throwInternalError("raw_index_bytes unexpected NULL ptr");
|
|
||||||
size_in_bytes = mem_size(sizeof(element_type), index, size_in_bytes); // assert size
|
|
||||||
if very_unlikely (__acc_cte(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, size_in_bytes) != 0))
|
|
||||||
throwInternalError("raw_index_bytes valgrind-check-mem");
|
|
||||||
UNUSED(size_in_bytes);
|
|
||||||
return ptr + index;
|
|
||||||
}
|
|
||||||
|
|
||||||
// same for bounded arrays
|
|
||||||
template <class T, size_t N>
|
|
||||||
inline T *raw_bytes(T (&a)[N], size_t size_in_bytes) {
|
|
||||||
typedef T element_type;
|
|
||||||
if very_unlikely (size_in_bytes > mem_size(sizeof(element_type), N))
|
|
||||||
throwInternalError("raw_bytes out of range");
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T, size_t N>
|
|
||||||
inline T *raw_index_bytes(T (&a)[N], size_t index, size_t size_in_bytes) {
|
|
||||||
typedef T element_type;
|
|
||||||
return raw_bytes(a, mem_size(sizeof(element_type), index, size_in_bytes)) + index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vim:set ts=4 sw=4 et: */
|
/* vim:set ts=4 sw=4 et: */
|
||||||
|
|||||||
@@ -94,9 +94,15 @@ forceinline pointer ensureBase() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline ~CSelf() {}
|
inline ~CSelf() {
|
||||||
void destroy() {
|
#if DEBUG
|
||||||
|
invalidate();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
noinline void invalidate() {
|
||||||
assertInvariants();
|
assertInvariants();
|
||||||
|
ptr = (pointer) (acc_uintptr_t) 16; // point to non-null invalid address
|
||||||
|
// ptr = (pointer) (void *) &ptr; // point to self
|
||||||
base = ptr;
|
base = ptr;
|
||||||
size_in_bytes = 0;
|
size_in_bytes = 0;
|
||||||
assertInvariants();
|
assertInvariants();
|
||||||
|
|||||||
@@ -62,7 +62,17 @@ public:
|
|||||||
operator pointer() const { return ptr; }
|
operator pointer() const { return ptr; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline ~CSelf() {}
|
inline ~CSelf() {
|
||||||
|
#if DEBUG
|
||||||
|
invalidate();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
noinline void invalidate() {
|
||||||
|
assertInvariants();
|
||||||
|
ptr = (pointer) (acc_uintptr_t) 16; // point to non-null invalid address
|
||||||
|
// ptr = (pointer) (void *) &ptr; // point to self
|
||||||
|
assertInvariants();
|
||||||
|
}
|
||||||
inline CSelf() { assertInvariants(); }
|
inline CSelf() { assertInvariants(); }
|
||||||
|
|
||||||
// constructors from pointers
|
// constructors from pointers
|
||||||
|
|||||||
Reference in New Issue
Block a user