⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conf.h

📁 UPX 源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
#define EXIT_INIT       1#define EXIT_INTERNAL   1// magic constants for patching#define UPX_MAGIC_LE32          0x21585055      /* "UPX!" */#define UPX_MAGIC2_LE32         0xD5D0D8A1// upx_compress() error codes#define UPX_E_OK                    (0)#define UPX_E_ERROR                 (-1)#define UPX_E_OUT_OF_MEMORY         (-2)#define UPX_E_NOT_COMPRESSIBLE      (-3)#define UPX_E_INPUT_OVERRUN         (-4)#define UPX_E_OUTPUT_OVERRUN        (-5)#define UPX_E_LOOKBEHIND_OVERRUN    (-6)#define UPX_E_EOF_NOT_FOUND         (-7)#define UPX_E_INPUT_NOT_CONSUMED    (-8)#define UPX_E_NOT_YET_IMPLEMENTED   (-9)#define UPX_E_INVALID_ARGUMENT      (-10)// Executable formats. Note: big endian types are >= 128.#define UPX_F_DOS_COM           1#define UPX_F_DOS_SYS           2#define UPX_F_DOS_EXE           3#define UPX_F_DJGPP2_COFF       4#define UPX_F_WATCOM_LE         5#define UPX_F_VXD_LE            6#define UPX_F_DOS_EXEH          7               /* OBSOLETE */#define UPX_F_TMT_ADAM          8#define UPX_F_WIN32_PE          9#define UPX_F_LINUX_i386        10#define UPX_F_WIN16_NE          11#define UPX_F_LINUX_ELF_i386    12#define UPX_F_LINUX_SEP_i386    13#define UPX_F_LINUX_SH_i386     14#define UPX_F_VMLINUZ_i386      15#define UPX_F_BVMLINUZ_i386     16#define UPX_F_ELKS_8086         17#define UPX_F_PS1_EXE           18#define UPX_F_VMLINUX_i386      19#define UPX_F_LINUX_ELFI_i386   20#define UPX_F_WINCE_ARM_PE      21#define UPX_F_LINUX_ELF64_AMD   22#define UPX_F_LINUX_ELF32_ARMEL 23#define UPX_F_BSD_i386          24#define UPX_F_BSD_ELF_i386      25#define UPX_F_BSD_SH_i386       26#define UPX_F_VMLINUX_AMD64     27#define UPX_F_VMLINUX_ARMEL     28#define UPX_F_MACH_i386         29#define UPX_F_LINUX_ELF32_MIPSEL 30#define UPX_F_PLAIN_TEXT        127#define UPX_F_ATARI_TOS         129#define UPX_F_SOLARIS_SPARC     130#define UPX_F_MACH_PPC32        131#define UPX_F_LINUX_ELFPPC32    132#define UPX_F_LINUX_ELF32_ARMEB 133#define UPX_F_MACH_FAT          134#define UPX_F_VMLINUX_ARMEB     135#define UPX_F_VMLINUX_PPC32     136#define UPX_F_LINUX_ELF32_MIPSEB 137// compression methods#define M_ALL           (-1)#define M_END           (-2)#define M_NONE          (-3)#define M_SKIP          (-4)#define M_ULTRA_BRUTE   (-5)// compression methods - DO NOT CHANGE#define M_NRV2B_LE32    2#define M_NRV2B_8       3#define M_NRV2B_LE16    4#define M_NRV2D_LE32    5#define M_NRV2D_8       6#define M_NRV2D_LE16    7#define M_NRV2E_LE32    8#define M_NRV2E_8       9#define M_NRV2E_LE16    10//#define M_CL1B_LE32     11//#define M_CL1B_8        12//#define M_CL1B_LE16     13#define M_LZMA          14#define M_DEFLATE       15      /* zlib */#define M_IS_NRV2B(x)   ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)#define M_IS_NRV2D(x)   ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)#define M_IS_NRV2E(x)   ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)//#define M_IS_CL1B(x)    ((x) >= M_CL1B_LE32  && (x) <= M_CL1B_LE16)#define M_IS_LZMA(x)    (((x) & 255) == M_LZMA)#define M_IS_DEFLATE(x) ((x) == M_DEFLATE)// filters#define FT_END          (-1)#define FT_NONE         (-2)#define FT_SKIP         (-3)#define FT_ULTRA_BRUTE  (-4)/*************************************************************************// compression - callback_t**************************************************************************/struct upx_callback_t;#define upx_callback_p upx_callback_t *#if 0typedef void* (__acc_cdecl *upx_alloc_func_t)    (upx_callback_p self, unsigned items, unsigned size);typedef void      (__acc_cdecl *upx_free_func_t)    (upx_callback_p self, void* ptr);#endiftypedef void (__acc_cdecl *upx_progress_func_t)    (upx_callback_p, unsigned, unsigned);struct upx_callback_t{    upx_progress_func_t nprogress;    void *user;    void reset() { memset(this, 0, sizeof(*this)); }};/*************************************************************************// compression - config_t**************************************************************************/template <class T, T default_value, T min_value, T max_value>struct OptVar{    typedef T Type;    static const T default_value_c = default_value;    static const T min_value_c = min_value;    static const T max_value_c = max_value;    void assertValue() {        // FIXME: this generates annoying warnings "unsigned >= 0 is always true"        //assert((v >= min_value) && (v <= max_value));    }    OptVar() : v(default_value), is_set(0) { }    OptVar& operator= (const T other) {        v = other; is_set += 1;        assertValue();        return *this;    }#if 0#error    // there is too much implicit magic in this copy operator;    // better introduce an explicit "oassign" function.    OptVar& operator= (const OptVar& other) {        if (other.is_set) { v = other.v; is_set += 1; }        assertValue(); return *this;    }#endif    void reset() { v = default_value; is_set = 0; }    operator T () const { return v; }    T v;    unsigned is_set;};// optional assignmentstemplate <class T> inline void oassign(T& self, const T& other) {    if (other.is_set) { self.v = other.v; self.is_set += 1; }}#if 0template <class V, class T> inline void oassign(V& v, const T& other) {    if (other.is_set) { v = other.v; }}#elsetemplate <class T> inline void oassign(unsigned& v, const T& other) {    if (other.is_set) { v = other.v; }}#endifstruct lzma_compress_config_t{    typedef OptVar<unsigned,  2u, 0u,   4u> pos_bits_t;             // pb    typedef OptVar<unsigned,  0u, 0u,   4u> lit_pos_bits_t;         // lb    typedef OptVar<unsigned,  3u, 0u,   8u> lit_context_bits_t;     // lc    typedef OptVar<unsigned, (1u<<22), 1u, (1u<<30) > dict_size_t;    typedef OptVar<unsigned, 64u, 5u, 273u> num_fast_bytes_t;    pos_bits_t          pos_bits;           // pb    lit_pos_bits_t      lit_pos_bits;       // lp    lit_context_bits_t  lit_context_bits;   // lc    dict_size_t         dict_size;    unsigned            fast_mode;    num_fast_bytes_t    num_fast_bytes;    unsigned            match_finder_cycles;    unsigned            max_num_probs;    void reset();};struct ucl_compress_config_t : public REAL_ucl_compress_config_t{    void reset() { memset(this, 0xff, sizeof(*this)); }};struct zlib_compress_config_t{    typedef OptVar<unsigned,  8u, 1u,   9u> mem_level_t;            // ml    typedef OptVar<unsigned, 15u, 9u,  15u> window_bits_t;          // wb    typedef OptVar<unsigned,  0u, 0u,   4u> strategy_t;             // st    mem_level_t         mem_level;          // ml    window_bits_t       window_bits;        // wb    strategy_t          strategy;           // st    void reset();};struct upx_compress_config_t{    lzma_compress_config_t  conf_lzma;    ucl_compress_config_t   conf_ucl;    zlib_compress_config_t  conf_zlib;    void reset() { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); }};#define NULL_cconf  ((upx_compress_config_t *) NULL)/*************************************************************************// compression - result_t**************************************************************************/struct lzma_compress_result_t{    unsigned pos_bits;              // pb    unsigned lit_pos_bits;          // lp    unsigned lit_context_bits;      // lc    unsigned dict_size;    unsigned fast_mode;    unsigned num_fast_bytes;    unsigned match_finder_cycles;    unsigned num_probs;             // (computed result)    void reset() { memset(this, 0, sizeof(*this)); }};struct ucl_compress_result_t{    ucl_uint result[16];    void reset() { memset(this, 0, sizeof(*this)); }};struct zlib_compress_result_t{    unsigned dummy;    void reset() { memset(this, 0, sizeof(*this)); }};struct upx_compress_result_t{    // debug    int method, level;    unsigned u_len, c_len;    lzma_compress_result_t  result_lzma;    ucl_compress_result_t   result_ucl;    zlib_compress_result_t  result_zlib;    void reset() {        memset(this, 0, sizeof(*this));        result_lzma.reset(); result_ucl.reset(); result_zlib.reset();    }};/*************************************************************************// globals**************************************************************************/#include "snprintf.h"#if defined(__cplusplus)#include "stdcxx.h"#include "options.h"#include "except.h"#include "bele.h"#include "util.h"#include "console.h"// classesclass ElfLinker;typedef ElfLinker Linker;// main.cppextern const char *progname;bool set_ec(int ec);#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)void e_exit(int ec) __attribute__((__noreturn__));#elsevoid e_exit(int ec);#endif// msg.cppvoid printSetNl(int need_nl);void printClearLine(FILE *f = NULL);void printErr(const char *iname, const Throwable *e);void printUnhandledException(const char *iname, const std::exception *e);#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)void __acc_cdecl_va printErr(const char *iname, const char *format, ...)        __attribute__((__format__(__printf__,2,3)));void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)        __attribute__((__format__(__printf__,2,3)));#elsevoid __acc_cdecl_va printErr(const char *iname, const char *format, ...);void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);#endif#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)void __acc_cdecl_va infoWarning(const char *format, ...)        __attribute__((__format__(__printf__,1,2)));void __acc_cdecl_va infoHeader(const char *format, ...)        __attribute__((__format__(__printf__,1,2)));void __acc_cdecl_va info(const char *format, ...)        __attribute__((__format__(__printf__,1,2)));#elsevoid __acc_cdecl_va infoWarning(const char *format, ...);void __acc_cdecl_va infoHeader(const char *format, ...);void __acc_cdecl_va info(const char *format, ...);#endifvoid infoHeader();void infoWriting(const char *what, long size);// work.cppvoid do_one_file(const char *iname, char *oname);void do_files(int i, int argc, char *argv[]);// help.cppvoid show_head(void);void show_help(int verbose=0);void show_license(void);void show_usage(void);void show_version(int);// compress.cppunsigned upx_adler32(const void *buf, unsigned len, unsigned adler=1);unsigned upx_crc32(const void *buf, unsigned len, unsigned crc=0);int upx_compress           ( const upx_bytep src, unsigned  src_len,                                   upx_bytep dst, unsigned* dst_len,                                   upx_callback_p cb,                                   int method, int level,                             const upx_compress_config_t *cconf,                                   upx_compress_result_t *cresult );int upx_decompress         ( const upx_bytep src, unsigned  src_len,                                   upx_bytep dst, unsigned* dst_len,                                   int method,                             const upx_compress_result_t *cresult );int upx_test_overlap       ( const upx_bytep buf,                             const upx_bytep tbuf,                                   unsigned  src_off, unsigned src_len,                                   unsigned* dst_len,                                   int method,                             const upx_compress_result_t *cresult );#endif /* __cplusplus */#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)#  if defined(INVALID_HANDLE_VALUE) || defined(MAKEWORD) || defined(RT_CURSOR)#    error "something pulled in <windows.h>"#  endif#endif#endif /* already included *//*vi:ts=4:et*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -