/* * Add a "make" option. */ void addmkoption(const char *name, const char *value) { (void)do_option(mkopttab, &nextmkopt, name, value, "mkoptions"); }
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 shortopts[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(shortopts, "123456789", longopts); acc_getopt_init(&mfx_getopt, 1, targc, targv); mfx_getopt.progname = progname; mfx_getopt.opterr = handle_opterr; while ((optc = acc_getopt(&mfx_getopt, shortopts, 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); }
static int get_options(int argc, char **argv) { 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 {"decompress", 0, 0, 'd'}, // decompress {"fast", 0x10, 0, '1'}, // compress faster {"fileinfo", 0x10, 0, 909}, // display info about file {"file-info", 0x10, 0, 909}, // display info about file {"help", 0, 0, 'h'+256}, // give help {"license", 0, 0, 'L'}, // display software license {"list", 0, 0, 'l'}, // list compressed exe {"test", 0, 0, 't'}, // test compressed file integrity {"uncompress", 0, 0, 'd'}, // decompress {"version", 0, 0, 'V'+256}, // display version number // options {"force", 0, 0, 'f'}, // force overwrite of output files {"force-compress", 0, 0, 'f'}, // and compression of suspicious files {"info", 0, 0, 'i'}, // info mode {"no-env", 0x10, 0, 519}, // no environment var {"no-mode", 0x10, 0, 526}, // do not preserve mode (permissions) {"no-owner", 0x10, 0, 527}, // do not preserve ownership {"no-progress", 0, 0, 516}, // no progress bar {"no-time", 0x10, 0, 528}, // do not preserve timestamp {"output", 0x21, 0, 'o'}, {"quiet", 0, 0, 'q'}, // quiet mode {"silent", 0, 0, 'q'}, // quiet mode #if 0 // FIXME: to_stdout doesn't work because of console code mess {"stdout", 0x10, 0, 517}, // write output on standard output {"to-stdout", 0x10, 0, 517}, // write output on standard output #endif {"verbose", 0, 0, 'v'}, // verbose mode // debug options {"debug", 0x10, 0, 'D'}, {"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging {"fake-stub-version",0x31, 0, 542}, // for internal debugging {"fake-stub-year" ,0x31, 0, 543}, // for internal debugging {"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 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 {"all-filters", 0x10, 0, 523}, {"all-methods", 0x10, 0, 524}, {"exact", 0x10, 0, 525}, // user requires byte-identical decompression {"filter", 0x31, 0, 521}, // --filter= {"no-filter", 0x10, 0, 522}, {"small", 0x10, 0, 520}, // compression runtime parameters {"crp-nrv-cf", 0x31, 0, 801}, {"crp-nrv-sl", 0x31, 0, 802}, {"crp-nrv-hl", 0x31, 0, 803}, {"crp-nrv-pl", 0x31, 0, 804}, {"crp-nrv-mo", 0x31, 0, 805}, {"crp-nrv-mm", 0x31, 0, 806}, {"crp-nrv-ms", 0x31, 0, 807}, {"crp-ucl-cf", 0x31, 0, 801}, {"crp-ucl-sl", 0x31, 0, 802}, {"crp-ucl-hl", 0x31, 0, 803}, {"crp-ucl-pl", 0x31, 0, 804}, {"crp-ucl-mo", 0x31, 0, 805}, {"crp-ucl-mm", 0x31, 0, 806}, {"crp-ucl-ms", 0x31, 0, 807}, {"crp-lzma-pb", 0x31, 0, 811}, {"crp-lzma-lp", 0x31, 0, 812}, {"crp-lzma-lc", 0x31, 0, 813}, {"crp-lzma-ds", 0x31, 0, 814}, {"crp-lzma-fb", 0x31, 0, 816}, {"crp-zlib-ml", 0x31, 0, 821}, {"crp-zlib-wb", 0x31, 0, 822}, {"crp-zlib-st", 0x31, 0, 823}, // [deprecated - only for compatibility with UPX 2.0x] {"crp-ms", 0x31, 0, 807}, // atari/tos {"split-segments", 0x10, 0, 650}, // djgpp2/coff {"coff", 0x10, 0, 610}, // produce COFF output // dos/com // dos/exe //{"force-stub", 0x10, 0, 600}, {"no-reloc", 0x10, 0, 601}, // no reloc. record into packer dos/exe // dos/sys // unix {"blocksize", 0x31, 0, 660}, // --blocksize= {"force-execve", 0x10, 0, 661}, // force linux/386 execve format #if 0 {"script", 0x31, 0, 662}, // --script= #endif {"is_ptinterp", 0x10, 0, 663}, // linux/elf386 PT_INTERP program {"use_ptinterp", 0x10, 0, 664}, // linux/elf386 PT_INTERP program {"make_ptinterp", 0x10, 0, 665}, // linux/elf386 PT_INTERP program {"Linux", 0x10, 0, 666}, {"linux", 0x10, 0, 666}, {"FreeBSD", 0x10, 0, 667}, {"freebsd", 0x10, 0, 667}, {"NetBSD", 0x10, 0, 668}, {"netbsd", 0x10, 0, 668}, {"OpenBSD", 0x10, 0, 669}, {"openbsd", 0x10, 0, 669}, {"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes // 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}, {"8mib-ram", 0x10, 0, 673}, {"8mb-ram", 0x10, 0, 673}, // mp (meta) options {"mp-compress-task", 0x31, 0, 501}, {"mp-query-format", 0x10, 0, 502}, {"mp-query-num-tasks", 0x10, 0, 503}, { NULL, 0, NULL, 0 } }; int optc, longind; char shortopts[256]; prepare_shortopts(shortopts, "123456789hH?V", longopts), acc_getopt_init(&mfx_getopt, 1, argc, argv); mfx_getopt.progname = progname; mfx_getopt.opterr = handle_opterr; opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX; while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0) { if (do_option(optc, argv[mfx_optind-1]) != 0) e_usage(); } return mfx_optind; }