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

📄 main.cpp

📁 UPX 源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    {"openbsd",          0x10, 0, 669},    // watcom/le    {"le",               0x10, 0, 620},     // produce LE output    // win32/pe    {"compress-exports",    2, 0, 630},    {"compress-icons",      2, 0, 631},    {"compress-resources",  2, 0, 632},    {"strip-loadconf",   0x12, 0, 633},     // OBSOLETE - IGNORED    {"strip-relocs",     0x12, 0, 634},    {"keep-resource",    0x31, 0, 635},    // ps1/exe    {"boot-only",        0x10, 0, 670},    {"no-align",         0x10, 0, 671},    {"8-bit",            0x10, 0, 672},    {"8mb-ram",          0x10, 0, 673},    { NULL, 0, NULL, 0 }};    int optc, longind;    char buf[256];    prepare_shortopts(buf,"123456789hH?V",longopts),    mfx_optind = 0;    mfx_opterr = 1;    opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;    while ((optc = mfx_getopt_long(argc, argv, buf, longopts, &longind)) >= 0)    {        if (do_option(optc, argv[mfx_optind-1]) != 0)            e_usage();    }    return mfx_optind;}#if defined(OPTIONS_VAR)static void get_envoptions(int argc, char **argv){/* only some options are allowed in the environment variable */static const struct mfx_option longopts[] ={    // commands    {"best",             0x10, 0, 900},     // compress best    {"brute",            0x10, 0, 901},     // compress best, brute force    {"ultra-brute",      0x10, 0, 902},     // compress best, brute force    {"fast",             0x10, 0, '1'},     // compress faster    // options    {"info",                0, 0, 'i'},     // info mode    {"no-progress",         0, 0, 516},     // no progress bar    {"quiet",               0, 0, 'q'},     // quiet mode    {"silent",              0, 0, 'q'},     // quiet mode    {"verbose",             0, 0, 'v'},     // verbose mode    // debug options    {"disable-random-id",0x10, 0, 545},     // for internal debugging    // backup options    {"backup",           0x10, 0, 'k'},    {"keep",             0x10, 0, 'k'},    {"no-backup",        0x10, 0, 541},    // overlay options    {"overlay",          0x31, 0, 551},     // --overlay=    {"skip-overlay",     0x10, 0, 552},    {"no-overlay",       0x10, 0, 552},     // old name    {"copy-overlay",     0x10, 0, 553},    {"strip-overlay",    0x10, 0, 554},    // CPU options    {"cpu",              0x31, 0, 560},     // --cpu=    {"8086",             0x10, 0, 561},    {"386",              0x10, 0, 563},    {"486",              0x10, 0, 564},    // color options    {"no-color",         0x10, 0, 512},    {"mono",             0x10, 0, 513},    {"color",            0x10, 0, 514},    // compression settings    {"exact",            0x10, 0, 525},     // user requires byte-identical decompression    // compression method    {"nrv2b",            0x10, 0, 702},     // --nrv2b    {"nrv2d",            0x10, 0, 704},     // --nrv2d    {"nrv2e",            0x10, 0, 705},     // --nrv2e    {"lzma",             0x10, 0, 721},     // --lzma    {"no-lzma",          0x10, 0, 722},     // (disable all_methods_use_lzma)    // compression settings    // compression runtime parameters    // win32/pe    {"compress-exports",    2, 0, 630},    {"compress-icons",      2, 0, 631},    {"compress-resources",  2, 0, 632},    {"strip-loadconf",   0x12, 0, 633},     // OBSOLETE - IGNORED    {"strip-relocs",     0x12, 0, 634},    {"keep-resource",    0x31, 0, 635},    { NULL, 0, NULL, 0 }};    char *env, *p;    const char *var;    int i, optc, longind;    int targc;    char **targv = NULL;    static const char sep[] = " \t";    char buf[256];    var = getenv(OPTIONS_VAR);    if (var == NULL || !var[0])        return;    env = strdup(var);    if (env == NULL)        return;    /* count arguments */    for (p = env, targc = 1; ; )    {        while (*p && strchr(sep,*p))            p++;        if (*p == '\0')            break;        targc++;        while (*p && !strchr(sep,*p))            p++;        if (*p == '\0')            break;        p++;    }    /* alloc temp argv */    if (targc > 1)        targv = (char **) calloc(targc+1,sizeof(char *));    if (targv == NULL)    {        free(env);        return;    }    /* fill temp argv */    targv[0] = argv[0];    for (p = env, targc = 1; ; )    {        while (*p && strchr(sep,*p))            p++;        if (*p == '\0')            break;        targv[targc++] = p;        while (*p && !strchr(sep,*p))            p++;        if (*p == '\0')            break;        *p++ = '\0';    }    targv[targc] = NULL;    /* check that only options are in temp argv */    for (i = 1; i < targc; i++)        if (targv[i][0] != '-' || !targv[i][1] || strcmp(targv[i],"--") == 0)            e_envopt(targv[i]);    /* handle options */    prepare_shortopts(buf,"123456789",longopts);    mfx_optind = 0;    mfx_opterr = 1;    while ((optc = mfx_getopt_long(targc, targv, buf, longopts, &longind)) >= 0)    {        if (do_option(optc, targv[mfx_optind-1]) != 0)            e_envopt(NULL);    }    if (mfx_optind < targc)        e_envopt(targv[mfx_optind]);    /* clean up */    free(targv);    free(env);    UNUSED(argc);}#endif /* defined(OPTIONS_VAR) */static void first_options(int argc, char **argv){    int i;    int n = argc;    for (i = 1; i < n; i++)    {        if (strcmp(argv[i],"--") == 0)        {            n = i;            break;        }        if (strcmp(argv[i],"--version") == 0)            do_option('V'+256, argv[i]);    }    for (i = 1; i < n; i++)        if (strcmp(argv[i],"--help") == 0)            do_option('h'+256, argv[i]);    for (i = 1; i < n; i++)        if (strcmp(argv[i],"--no-env") == 0)            do_option(519, argv[i]);}/*************************************************************************// assert a sane architecture and compiler**************************************************************************/template <class T> struct TestBELE {static bool test(void){    COMPILE_TIME_ASSERT_ALIGNED1(T)    struct test1_t { char a; T b; } __attribute_packed;    struct test2_t { char a; T b[3]; } __attribute_packed;    test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2);    COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))    COMPILE_TIME_ASSERT_ALIGNED1(test1_t)    COMPILE_TIME_ASSERT(sizeof(t1) == 7 + 7*sizeof(T))    COMPILE_TIME_ASSERT(sizeof(test2_t) == 1 + 3*sizeof(T))    COMPILE_TIME_ASSERT_ALIGNED1(test2_t)    COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21*sizeof(T))#if defined(__acc_alignof)    COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)    COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)#endif#if 1 && !defined(xUPX_OFFICIAL_BUILD)    T allbits; allbits = 0; allbits -= 1;    //++allbits; allbits++; --allbits; allbits--;    T v1; v1 = 1; v1 *= 2; v1 -= 1;    T v2; v2 = 1;    assert( (v1 == v2)); assert(!(v1 != v2));    assert( (v1 <= v2)); assert( (v1 >= v2));    assert(!(v1 <  v2)); assert(!(v1 >  v2));    v2 ^= allbits;    assert(!(v1 == v2)); assert( (v1 != v2));    assert( (v1 <= v2)); assert(!(v1 >= v2));    assert( (v1 <  v2)); assert(!(v1 >  v2));    v2 += 2;    assert(v1 == 1); assert(v2 == 0);    v1 <<= 1; v1 |= v2; v1 >>= 1; v2 &= v1; v2 /= v1; v2 *= v1;    assert(v1 == 1); assert(v2 == 0);    if ((v1 ^ v2) != 1) return false;#endif    return true;}};#define ACC_WANT_ACC_CHK_CH 1#undef ACCCHK_ASSERT#include "miniacc.h"void upx_sanity_check(void){#define ACC_WANT_ACC_CHK_CH 1#undef ACCCHK_ASSERT#define ACCCHK_ASSERT(expr)   ACC_COMPILE_TIME_ASSERT(expr)#include "miniacc.h"#undef ACCCHK_ASSERT    COMPILE_TIME_ASSERT(sizeof(char) == 1)    COMPILE_TIME_ASSERT(sizeof(short) == 2)    COMPILE_TIME_ASSERT(sizeof(int) == 4)    COMPILE_TIME_ASSERT(sizeof(long) >= 4)    COMPILE_TIME_ASSERT(sizeof(void *) >= 4)    COMPILE_TIME_ASSERT(sizeof(off_t) >= sizeof(long))    COMPILE_TIME_ASSERT(((off_t) -1) < 0)    COMPILE_TIME_ASSERT(sizeof(BE16) == 2)    COMPILE_TIME_ASSERT(sizeof(BE32) == 4)    COMPILE_TIME_ASSERT(sizeof(BE64) == 8)    COMPILE_TIME_ASSERT(sizeof(LE16) == 2)    COMPILE_TIME_ASSERT(sizeof(LE32) == 4)    COMPILE_TIME_ASSERT(sizeof(LE64) == 8)    COMPILE_TIME_ASSERT_ALIGNED1(BE16)    COMPILE_TIME_ASSERT_ALIGNED1(BE32)    COMPILE_TIME_ASSERT_ALIGNED1(BE64)    COMPILE_TIME_ASSERT_ALIGNED1(LE16)    COMPILE_TIME_ASSERT_ALIGNED1(LE32)    COMPILE_TIME_ASSERT_ALIGNED1(LE64)    COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)    assert(strlen(UPX_VERSION_STRING4) == 4);    assert(memcmp(UPX_VERSION_STRING4, UPX_VERSION_STRING, 4) == 0);    COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_YEAR) == 4 + 1)    assert(strlen(UPX_VERSION_YEAR) == 4);    assert(memcmp(UPX_VERSION_DATE_ISO, UPX_VERSION_YEAR, 4) == 0);    assert(memcmp(UPX_VERSION_DATE + strlen(UPX_VERSION_DATE) - 4, UPX_VERSION_YEAR, 4) == 0);#if 1    assert(TestBELE<LE16>::test());    assert(TestBELE<LE32>::test());    assert(TestBELE<LE64>::test());    assert(TestBELE<BE16>::test());    assert(TestBELE<BE32>::test());    assert(TestBELE<BE64>::test());    {    static const unsigned char dd[32] = { 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 };    const unsigned char *d;    d = dd + 7;    assert(upx_adler32(d, 4) == 0x09f003f7);    assert(upx_adler32(d, 4, 0) == 0x09ec03f6);    assert(upx_adler32(d, 4, 1) == 0x09f003f7);    assert(get_be16(d) == 0xfffe);    assert(get_be16_signed(d) == -2);    assert(get_be24(d) == 0xfffefd);    assert(get_be24_signed(d) == -259);    assert(get_be32(d) == 0xfffefdfc);    assert(get_be32_signed(d) == -66052);    assert(get_le16(d) == 0xfeff);    assert(get_le16_signed(d) == -257);    assert(get_le24(d) == 0xfdfeff);    assert(get_le24_signed(d) == -131329);    assert(get_le32(d) == 0xfcfdfeff);    assert(get_le32_signed(d) == -50462977);    assert(get_le64_signed(d) == ACC_INT64_C(-506097522914230529));    assert(find_be16(d, 2, 0xfffe) == 0);    assert(find_le16(d, 2, 0xfeff) == 0);    assert(find_be32(d, 4, 0xfffefdfc) == 0);    assert(find_le32(d, 4, 0xfcfdfeff) == 0);    d += 12;    assert(get_be16_signed(d) == 32638);    assert(get_be24_signed(d) == 8355453);    assert(get_be32_signed(d) == 2138996092);    assert(get_be64_signed(d) == ACC_INT64_C(9186918263483431288));    }#endif}/*************************************************************************// main entry point**************************************************************************/#if !defined(WITH_GUI)#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)extern "C" { extern long _stksize; long _stksize = 256 * 1024L; }#endifint __acc_cdecl_main main(int argc, char *argv[]){    int i;    static char default_argv0[] = "upx";//    int cmdline_cmd = CMD_NONE;#if 0 && defined(__DJGPP__)    // LFN=n may cause problems with 2.03's _rename and mkdir under WinME    putenv("LFN=y");#endif    acc_wildargv(&argc, &argv);    upx_sanity_check();    opt->reset();    if (!argv[0] || !argv[0][0])        argv[0] = default_argv0;    argv0 = argv[0];#if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_TOS || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)    {        char *prog = fn_basename(argv0);        char *p;        bool allupper = true;        for (p = prog; *p; p++)            if (islower((unsigned char)*p))                allupper = false;        if (allupper)            fn_strlwr(prog);        if (p - prog > 4)        {            p -= 4;            if (fn_strcmp(p, ".exe") == 0 || fn_strcmp(p, ".ttp") == 0)                *p = 0;        }        progname = prog;    }#else    progname = fn_basename(argv0);#endif    while (progname[0] == '.' && progname[1] == '/'  && progname[2])        progname += 2;    set_term(stderr);#if defined(WITH_UCL)    if (ucl_init() != UCL_E_OK)    {        show_head();        fprintf(stderr,"ucl_init() failed - check your UCL installation !\n");        if (UCL_VERSION != ucl_version())            fprintf(stderr,"library version conflict (%lx, %lx) - check your UCL installation !\n",                    (long) UCL_VERSION, (long) ucl_version());        e_exit(EXIT_INIT);    }#endif#if defined(WITH_NRV)    if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version())    {        show_head();        fprintf(stderr,"nrv_init() failed - check your NRV installation !\n");        if (NRV_VERSION != nrv_version())            fprintf(stderr,"library version conflict (%lx, %lx) - check your NRV installation !\n",                    (long) NRV_VERSION, (long) nrv_version());        e_exit(EXIT_INIT);    }#endif    //srand((int) time(NULL));    srand((int) clock());    /* get options */    first_options(argc,argv);#if defined(OPTIONS_VAR)    if (!opt->no_env)        get_envoptions(argc,argv);#endif    i = get_options(argc,argv);    assert(i <= argc);    set_term(NULL);//    cmdline_cmd = opt->cmd;    switch (opt->cmd)    {    case CMD_NONE:        /* default - compress */        set_cmd(CMD_COMPRESS);        break;    case CMD_COMPRESS:        break;    case CMD_DECOMPRESS:        break;    case CMD_TEST:        break;    case CMD_LIST:        break;    case CMD_FILEINFO:        break;    case CMD_LICENSE:        show_license();        e_exit(EXIT_OK);        break;    case CMD_HELP:        show_help(1);        e_exit(EXIT_OK);        break;    case CMD_VERSION:        show_version(1);        e_exit(EXIT_OK);        break;    default:        /* ??? */        break;    }    /* check options */    if (argc == 1)        e_help();    set_term(stderr);    check_options(i,argc);    num_files = argc - i;    if (num_files < 1)    {        if (opt->verbose >= 2)            e_help();        else            e_usage();    }    /* start work */    set_term(stdout);    do_files(i,argc,argv);#if 0 && (UPX_VERSION_HEX < 0x030000)    {        FILE *f = stdout;        int fg = con_fg(f,FG_RED);        con_fprintf(f,"\nWARNING: this is an unstable beta version - use for testing only! Really.\n");        fg = con_fg(f,fg);        UNUSED(fg);    }#endif#if 0 && defined(__GLIBC__)    //malloc_stats();#endif    return exit_code;}#endif /* !defined(WITH_GUI) *//*vi:ts=4:et:nowrap*/

⌨️ 快捷键说明

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