LightingView() { SkString diffusePath = GetResourcePath("brickwork-texture.jpg"); decode_file(diffusePath.c_str(), &fDiffuseBitmap); SkString normalPath = GetResourcePath("brickwork_normal-map.jpg"); decode_file(normalPath.c_str(), &fNormalBitmap); fLightAngle = 0.0f; fColorFactor = 0.0f; }
static void run_check_for_file (const gchar * filename) { gboolean ret; /* first, pull-based */ ret = decode_file (filename, FALSE); fail_unless (ret == TRUE, "Failed to decode '%s' (pull mode)", filename); /* second, push-based */ ret = decode_file (filename, TRUE); fail_unless (ret == TRUE, "Failed to decode '%s' (push mode)", filename); }
CameraView() { fRX = fRY = fRZ = 0; fShaderIndex = 0; fFrontFace = false; for (int i = 0;; i++) { SkString str; str.printf("/skimages/elephant%d.jpeg", i); SkBitmap bm; if (decode_file(str.c_str(), &bm)) { SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; SkRect dst = { -150, -150, 150, 150 }; SkMatrix matrix; matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); fShaders.push_back(SkShader::MakeBitmapShader(bm, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix)); } else { break; } } this->setBGColor(0xFFDDDDDD); }
int main(int argc, char *argv[]) { char *NameFunc = argv[1]; char *InFile = argv[2]; char *OutFile = argv[3]; int ptr1, ptr2; ptr1 = strncmp("encode", NameFunc, 10); ptr2 = strncmp("decode", NameFunc, 10); if ((argc != 4) || (((ptr1 == -1) || (ptr1 == 1)) & ((ptr2 == -1) || (ptr2 == 1)))) { printf("Usage:\n"); printf("main encode <in-file-name> <out-file-name>\n"); printf("main decode <in-file-name> <out-file-name>\n"); return 0; } else if (ptr1 == 0) { printf("encode\n"); encode_file(InFile, OutFile); } else if (ptr2 == 0) { printf("decode\n"); decode_file(InFile, OutFile); } return 0; }
int main(int argc, char **argv) { int i; if(argc == 1) { fprintf(stderr, VERSIONSTRING); usage(); return 1; } parse_options(argc,argv); if(!quiet) fprintf(stderr, VERSIONSTRING); if(optind >= argc) { fprintf(stderr, "ERROR: No input files specified. Use -h for help\n"); return 1; } if(argc - optind > 1 && outfilename) { fprintf(stderr, "ERROR: Can only specify one input file if output filename is specified\n"); return 1; } for(i=optind; i < argc; i++) { char *in, *out; if(!strcmp(argv[i], "-")) in = NULL; else in = argv[i]; if(outfilename) { if(!strcmp(outfilename, "-")) out = NULL; else out = outfilename; } else { char *end = strrchr(argv[i], '.'); end = end?end:(argv[i] + strlen(argv[i]) + 1); out = malloc(strlen(argv[i]) + 10); strncpy(out, argv[i], end-argv[i]); out[end-argv[i]] = 0; if(raw) strcat(out, ".raw"); else strcat(out, ".wav"); } if(decode_file(in,out)) return 1; } if(outfilename) free(outfilename); return 0; }
void parseOpt(int argc , char * const * argv) { int result; std::string in_file, out_file,action; opterr = 0; //使getopt不行stderr输出错误信息 while( (result = getopt(argc, argv, "edi:o:")) != -1 ) { switch(result) { case 'e': action = (char *)"encode"; break; case 'd': action = (char *)"decode"; break; case 'i': in_file = optarg; break; case 'o': out_file = optarg; break; default: printf("Usage:\n ./wbxml -d -i input -o output\n"); break; } } if (action == "encode"){ encode_file(in_file,out_file); }else if (action == "decode") { decode_file(in_file,out_file); } }
void FORTRAN(decode_file_jacket) ( char* fname, char *recptr, char *delims, int *skip, int* maxrec, int* reclen, int* nfields, int field_type[], int* nrec, int mrlist[], DFTYPE *memptr, int mr_blk1[], int* mblk_size, DFTYPE mr_bad_flags[], char ***mr_c_ptr, int* status) { DFTYPE **numeric_fields = (DFTYPE **) malloc(sizeof(DFTYPE*) * (*nfields)); DFTYPE *bad_flags = (DFTYPE *) malloc(sizeof(DFTYPE) * (*nfields)); char ***text_fields = (char ***) malloc(sizeof(char**) * (*nfields)); int i, mr; int pinc = 8/sizeof(char*); /* pointers spaced 8 bytes apart */ for (i=0; i<(*nfields); i++) { mr = mrlist[i] - 1; /* -1 for C indexing */ /* compute separate pointer arrays for numeric and text fields */ numeric_fields[i] = (DFTYPE *) NULL; text_fields[i] = (char**) NULL; if (field_type[i] == FTYP_CHARACTER ) { /* *kob* make sure were using size of real*4 float */ text_fields[i] = (char**) (memptr + ((mr_blk1[mr]-1)*(*mblk_size)*4)/sizeof(float)); mr_c_ptr[mr*pinc] = text_fields[i]; } else if (field_type[i] != FTYP_MISSING ) { numeric_fields[i] = memptr + (mr_blk1[mr]-1)*(*mblk_size); mr_c_ptr[mr*pinc] = (char**) NULL; } /* isolate the bad data flags that correspond to the numeric fields */ if ( (field_type[i]==FTYP_MISSING) || (field_type[i]==FTYP_CHARACTER) ) bad_flags[i] = 0.0; else bad_flags[i] = mr_bad_flags[mr]; } /* at last we actually read the file */ decode_file (fname, recptr, delims, skip, maxrec, reclen, nfields, field_type, nrec, numeric_fields, text_fields, bad_flags, status); free(numeric_fields); free(text_fields); free(bad_flags); return; }
int decode_steg(char *file_input, char *file_output, unsigned char *key) { FILE *fpi, *fpo; unsigned char digest[16]; //clock_t c1, c2; // Open files if((fpi = fopen(file_input, "rb")) == NULL) { fprintf(stderr, "Cannot open input file!\n"); return(-1); } if((fpo = fopen(file_output, "wb")) == NULL) { fprintf(stderr, "Cannot open output file!\n"); return(-1); } // Get MD5 Checksum of key MD5String(key, digest); // Seed the PRNG with the md5 checksum of the key prng_seed(digest); // Decode //c1 = clock(); decode_file(fpi, fpo); //c2 = clock(); //printf("%f\n", get_speed(c1,c2)); //system("PAUSE"); // Close files fclose(fpi); fclose(fpo); return(0); }
void decodeCurrFile() { if (fCurrFile.size() == 0) { fDecodeSucceeded = false; return; } fDecodeSucceeded = decode_file(fCurrFile.c_str(), &fBitmap, kN32_SkColorType, !fPremul); this->inval(nullptr); }
static sk_sp<SkShader> make_shader0(SkIPoint* size) { SkBitmap bm; decode_file("/skimages/logo.gif", &bm); size->set(bm.width(), bm.height()); return SkShader::MakeBitmapShader(bm, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); }
SubpixelTranslateView(const char imageFilename[], float horizontalVelocity, float verticalVelocity) : fHorizontalVelocity(horizontalVelocity), fVerticalVelocity(verticalVelocity) { SkString resourcePath = GetResourcePath(imageFilename); if (!decode_file(resourcePath.c_str(), &fBM)) { fBM.allocN32Pixels(1, 1); *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad } fCurPos = SkPoint::Make(0,0); fSize = 200; }
void processExtractedFile(char *filename, char *folderExtractTo, const char *PAKname) { char extractedFile[255] = ""; int extracted = 0; if (is_lz4(filename)) { constructPath(extractedFile, folderExtractTo, PAKname, ".unlz4"); printf("UnLZ4 %s to %s\n", filename, extractedFile); extracted = !decode_file(filename, extractedFile); } else { if (check_lzo_header(filename)) { constructPath(extractedFile, folderExtractTo, PAKname, ".unpacked"); printf("LZOunpack %s to %s\n", filename, extractedFile); extracted = !lzo_unpack((const char*) filename, (const char*) extractedFile); } else { if (is_cramfs_image(filename)) { constructPath(extractedFile, folderExtractTo, PAKname, NULL); printf("Uncramfs %s to folder %s\n", filename, extractedFile); rmrf(extractedFile); uncramfs(extractedFile, filename); return; } else { if (is_kernel(filename)) { constructPath(extractedFile, folderExtractTo, PAKname, ".unpaked"); printf("Extracting kernel %s to %s\n", filename, extractedFile); extract_kernel(filename, extractedFile); extracted = 1; } else { if (is_nfsb(filename)) { constructPath(extractedFile, folderExtractTo, PAKname, ".unnfsb"); printf("Unnfsb %s to %s\n", filename, extractedFile); unnfsb(filename, extractedFile); extracted = 1; } } } } } if (strcmp(PAKname, "patc") != 0 && strcmp(PAKname, "extr") != 0) { if (is_squashfs(filename)) { constructPath(extractedFile, folderExtractTo, PAKname, NULL); printf("Unsquashfs %s to folder %s\n", filename, extractedFile); rmrf(extractedFile); unsquashfs(filename, extractedFile); return; } } else { printf("!!!Skipping unsquashfs (%s) as it doesn't know how to handle it...\n", PAKname); return; } if (extracted) processExtractedFile(extractedFile, folderExtractTo, PAKname); }
/** * @brief Loads and decodes the sound into memory. */ void Sound::load() { std::string file_name = (std::string) "sounds/" + id; if (id.find(".") == std::string::npos) { file_name += ".ogg"; } // create an OpenAL buffer with the sound decoded by the library buffer = decode_file(file_name); if (buffer == AL_NONE) { std::cerr << "Sound '" << file_name << "' will not be played" << std::endl; } }
int main(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "c:fhr")) != -1) { switch (opt) { case 'c': config = optarg; break; case 'f': use_dsp = false; break; case 'r': use_dsp = false; write_raw = true; break; case 'h': /* fallthrough */ default: print_help(argv[0]); exit(1); } } if (argc == optind + 2) { write_init(argv[optind + 1]); } else if (argc == optind + 1) { if (!use_dsp) { fprintf(stderr, "error: -r can't be used for playback\n"); print_help(argv[0]); exit(1); } core_allocator_init(); playback_init(); } else { if (argc > 1) fprintf(stderr, "error: wrong number of arguments\n"); print_help(argv[0]); exit(1); } decode_file(argv[optind]); if (mode == MODE_WRITE) write_quit(); else if (mode == MODE_PLAY) playback_quit(); return 0; }
static int set_value(const char* path, const char* var, const char* val) { epai_file_t* efp; epai_error_t err = decode_file(path, &efp); if (err) { fprintf(stderr, "Failed to decode file. Error %d.\n", err); return 2; } err = encode_file(path, efp); if (err) { fprintf(stderr, "Failed to encode file. Error %d.\n", err); return 4; } return 0; }
int main(int argc, char *argv[]) { int opt; const char *decode_test_file; decode_test_file = NULL; while ((opt = getopt(argc, argv, "d:")) != -1) { switch (opt) { case 'd': decode_test_file = optarg; break; default: //usage(); exit(2); break; } } if (decode_test_file) { decode_file(decode_test_file); return 0; } if (encode_decode_tests()) { printf("Tests failed\n"); return 2; } if (mitel_cm7291_side_2_and_bellcore_tests()) { printf("Tests failed\n"); return 2; } if (end_to_end_tests()) { printf("Tests failed\n"); return 2; } printf("Tests passed\n"); return 0; }
void file_mode(char *filename,file_mode_t type) { Enigma enigma; init_enigma(&enigma); if(type == ENCODE) { printf("Encoding\n"); encode_file(&enigma,filename); } else if(type == DECODE) { printf("Decoding\n"); decode_file(&enigma,filename); } }
ShaderView() { decode_file("/skimages/logo.gif", &fBitmap); SkPoint pts[2]; SkColor colors[2]; pts[0].set(0, 0); pts[1].set(SkIntToScalar(100), 0); colors[0] = SK_ColorRED; colors[1] = SK_ColorBLUE; auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp); pts[0].set(0, 0); pts[1].set(0, SkIntToScalar(100)); colors[0] = SK_ColorBLACK; colors[1] = SkColorSetARGB(0x80, 0, 0, 0); auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp); fShader = SkShaders::Blend(SkBlendMode::kDstIn, std::move(shaderA), std::move(shaderB)); }
int main(int argc, char *argv[]) #endif { int wave_out = 0, ref_size; char *ref_file_name = (argc > 2) ? argv[2] : NULL; char *output_file_name = (argc > 3) ? argv[3] : NULL; FILE *file_out = NULL; if (output_file_name) { file_out = fopen(output_file_name, "wb"); #ifndef MINIMP3_NO_WAV char *ext = strrchr(output_file_name, '.'); if (ext && !strcasecmp(ext + 1, "wav")) wave_out = 1; #endif } FILE *file_ref = ref_file_name ? fopen(ref_file_name, "rb") : NULL; unsigned char *buf_ref = preload(file_ref, &ref_size); if (file_ref) fclose(file_ref); #ifdef __AFL_HAVE_MANUAL_CONTROL __AFL_INIT(); while (__AFL_LOOP(1000)) { #endif char *input_file_name = (argc > 1) ? argv[1] : NULL; if (!input_file_name) { printf("error: no file names given\n"); return 1; } decode_file(input_file_name, buf_ref, ref_size, file_out, wave_out); #ifdef __AFL_HAVE_MANUAL_CONTROL } #endif if (buf_ref) free(buf_ref); if (file_out) fclose(file_out); return 0; }
static int get_value(const char* path, const char* var) { epai_file_t* efp; epai_error_t err = decode_file(path, &efp); if (err) { fprintf(stderr, "Failed to decode file. Error %d. " "libepai error:\n%s\n", err, epai_get_error()); return 2; } if (!strcmp(var, "all")) { get_endian(efp); get_version(efp); } else if (!strcmp(var, "endian")) { get_endian(efp); } else if (!strcmp(var, "fver")) { get_version(efp); } else { fprintf(stderr, "Invalid variable name.\n"); return 8; } return 0; }
int main(int argc, char *argv[]) { int c, i; char *fn, *fn2 = NULL; int cmd_decode = 0; int cmd_chg_channels = 0; int cmd_info = 0, cmd_play = 0; int cf_set_chans = 0; while ((c = getopt(argc, argv, "pdiMSqhrmsnvo:")) != -1) { switch (c) { case 'h': usage(0); break; case 'd': cmd_decode = 1; break; case 'i': cmd_info = 1; break; case 'p': cmd_play = 1; break; case 'M': cmd_chg_channels = 1; cf_set_chans = 1; break; case 'S': cmd_chg_channels = 1; cf_set_chans = 2; break; case 'q': cf_quiet = 1; break; case 'm': cf_force_chans = 1; break; case 's': cf_force_chans = 2; break; case 'r': cf_raw = 1; break; case 'n': cf_no_output = 1; break; case 'o': fn2 = optarg; break; case 'v': printf("%s\n", version); exit(0); default: fprintf(stderr, "bad arg: -%c\n", c); usage(1); } } i = cmd_chg_channels + cmd_info + cmd_decode + cmd_play; if (i < 1 || i > 1) { fprintf(stderr, "only one command at a time please\n"); usage(1); } /* play file */ if (cmd_play) { #ifdef HAVE_AO ao_initialize(); for (i = optind; i < argc; i++) play_file(argv[i]); close_audio(); ao_shutdown(); return 0; #else fprintf(stderr, "For audio output, please compile with libao.\n"); return 1; #endif } /* show info */ if (cmd_info) { for (i = optind; i < argc; i++) show_info(argv[i]); return 0; } /* channel changing */ if (cmd_chg_channels) { for (i = optind; i < argc; i++) set_channels(argv[i], cf_set_chans); return 0; } /* regular converting */ if (optind == argc) usage(1); if (fn2) { if (optind + 1 != argc) usage(1); fn = argv[optind]; decode_file(fn, fn2); } else { while (optind < argc) { fn = argv[optind++]; fn2 = makefn(fn, cf_raw ? ".raw" : ".wav"); decode_file(fn, fn2); free(fn2); } } return 0; }
int main(int argc, char **argv) { int i; if(argc == 1) { usage(); return 1; } parse_options(argc,argv); if(!quiet) version(); if(optind >= argc) { fprintf(stderr, _("ERROR: No input files specified. Use -h for help\n")); return 1; } if(argc - optind > 1 && outfilename && !raw) { fprintf(stderr, _("ERROR: Can only specify one input file if output filename is specified\n")); return 1; } if(outfilename && raw) { FILE *infile, *outfile; char *infilename; if(!strcmp(outfilename, "-")) { free(outfilename); outfilename = NULL; } outfile = open_output(outfilename); if(!outfile) return 1; for(i=optind; i < argc; i++) { if(!strcmp(argv[i], "-")) { infilename = NULL; infile = open_input(NULL); } else { infilename = argv[i]; infile = open_input(argv[i]); } if(!infile) { fclose(outfile); free(outfilename); return 1; } if(decode_file(infile, outfile, infilename, outfilename)) { fclose(outfile); return 1; } } fclose(outfile); } else { for(i=optind; i < argc; i++) { char *in, *out; FILE *infile, *outfile; if(!strcmp(argv[i], "-")) in = NULL; else in = argv[i]; if(outfilename) { if(!strcmp(outfilename, "-")) out = NULL; else out = outfilename; } else { char *end = strrchr(argv[i], '.'); end = end?end:(argv[i] + strlen(argv[i]) + 1); out = malloc(strlen(argv[i]) + 10); strncpy(out, argv[i], end-argv[i]); out[end-argv[i]] = 0; if(raw) strcat(out, ".raw"); else strcat(out, ".wav"); } infile = open_input(in); if(!infile) { if(outfilename) free(outfilename); return 1; } outfile = open_output(out); if(!outfile) { fclose(infile); return 1; } if(decode_file(infile, outfile, in, out)) { fclose(outfile); return 1; } if(!outfilename) free(out); fclose(outfile); } } if(outfilename) free(outfilename); return 0; }
int main(int argc, char *argv[]) { int nativeBlockNum = 4; int parityBlockNum = 2; char *inFile = NULL; char *confFile = NULL; char *outFile = NULL; enum func { encode, decode }; enum func op; nativeBlockNum = atoi(argv[1]); parityBlockNum = atoi(argv[2]); if( strcmp(argv[3], "-e") == 0 ) { op = encode; } else if( strcmp(argv[3], "-d") == 0 ) { op = decode; } else { printf("Invalid option!\n"); exit(-1); } /* if(op == encode) { file = argv[4]; encode_file(file, nativeBlockNum, parityBlockNum); } if(op == decode) { file = argv[4]; decode_file(file, nativeBlockNum, parityBlockNum); } */ switch(op) { case encode: inFile = argv[4]; encode_file(inFile, nativeBlockNum, parityBlockNum); break; case decode: /* if(argc > 4) { file = argv[4]; decode_file(file, nativeBlockNum, parityBlockNum); } else { decode_file(NULL, nativeBlockNum, parityBlockNum); } */ if(argc == 5) { confFile = argv[4]; } else if(argc == 7 && strcmp(argv[5], "-o") == 0) { confFile = argv[4]; outFile = argv[6]; } else { printf("Invalid command!\n"); exit(-1); } decode_file(confFile, outFile, nativeBlockNum, parityBlockNum); break; } return 0; }
int handle_file(const char *file, struct config_opts_t *config_opts) { const char *dest_dir = config_opts->dest_dir; const char *file_name = basename(strdup(file)); char dest_file[1024] = ""; char lz4pack[1024] = ""; if (check_lzo_header(file)) { constructPath(dest_file, dest_dir, file_name, ".lzounpack"); printf("Extracting LZO file to: %s\n", dest_file); if (lzo_unpack(file, dest_file) == 0) { handle_file(dest_file, config_opts); return EXIT_SUCCESS; } } else if (is_nfsb(file)) { constructPath(dest_file, dest_dir, file_name, ".unnfsb"); printf("Extracting nfsb image to: %s.\n\n", dest_file); unnfsb(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if (is_lz4(file)) { constructPath(dest_file, dest_dir, file_name, ".unlz4"); printf("UnLZ4 file to: %s\n", dest_file); decode_file(file, dest_file); return EXIT_SUCCESS; } else if (is_squashfs(file)) { constructPath(dest_file, dest_dir, file_name, ".unsquashfs"); printf("Unsquashfs file to: %s\n", dest_file); rmrf(dest_file); unsquashfs(file, dest_file); return EXIT_SUCCESS; } else if (is_gzip(file)) { constructPath(dest_file, dest_dir, "", ""); printf("Extracting gzip file %s\n", file_name); strcpy(dest_file, file_uncompress_origname((char *)file, dest_file)); return EXIT_SUCCESS; } else if(is_cramfs_image(file, "be")) { constructPath(dest_file, dest_dir, file_name, ".cramswap"); printf("Swapping cramfs endian for file %s\n",file); cramswap(file, dest_file); return EXIT_SUCCESS; } else if(is_cramfs_image(file, "le")) { constructPath(dest_file, dest_dir, file_name, ".uncramfs"); printf("Uncramfs %s to folder %s\n", file, dest_file); rmrf(dest_file); uncramfs(dest_file, file); return EXIT_SUCCESS; } else if (isFileEPK2(file)) { extractEPK2file(file, config_opts); return EXIT_SUCCESS; } else if (isFileEPK1(file)) { extract_epk1_file(file, config_opts); return EXIT_SUCCESS; } else if (is_kernel(file)) { constructPath(dest_file, dest_dir, file_name, ".unpaked"); printf("Extracting boot image to: %s.\n\n", dest_file); extract_kernel(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if(isPartPakfile(file)) { constructPath(dest_file, dest_dir, remove_ext(file_name), ".txt"); printf("Saving Partition info to: %s\n", dest_file); dump_partinfo(file, dest_file); return EXIT_SUCCESS; } else if(is_jffs2(file)) { constructPath(dest_file, dest_dir, file_name, ".unjffs2"); printf("jffs2extract %s to folder %s\n", file, dest_file); rmrf(dest_file); jffs2extract(file, dest_file, "1234"); return EXIT_SUCCESS; } else if(isSTRfile(file)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nConverting %s file to TS: %s\n", file, dest_file); convertSTR2TS(file, dest_file, 0); return EXIT_SUCCESS; } else if(!memcmp(&file[strlen(file)-3], "PIF", 3)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nProcessing PIF file: %s\n", file); processPIF(file, dest_file); return EXIT_SUCCESS; } else if(symfile_load(file) == 0) { constructPath(dest_file, dest_dir, file_name, ".idc"); printf("Converting SYM file to IDC script: %s\n", dest_file); symfile_write_idc(dest_file); return EXIT_SUCCESS; } return EXIT_FAILURE; }
int main(int argc, char** argv) { int i, compression=1, // default action if no argument decode=0; char *input_filename=0, *output_filename=0; // Welcome message fprintf(stderr, WELCOME_MESSAGE); if (argc<2) { badusage(); return 1; } for(i=1; i<argc; i++) { char* argument = argv[i]; char command = 0; if(!argument) continue; // Protection if argument empty if (argument[0]=='-') command++; // valid command trigger // Select command if (command) { argument += command; // display help on usage if( argument[0] =='h' ) { usage(); return 0; } // Forced Compression (default) if( argument[0] =='c' ) { compression=1; continue; } // Forced Decoding if( argument[0] =='d' ) { decode=1; continue; } } // first provided filename is input if (!input_filename) { input_filename=argument; continue; } // second provided filename is output if (!output_filename) { output_filename=argument; continue; } } // No input filename ==> Error if(!input_filename) { badusage(); return 1; } // No output filename if (!output_filename) { badusage(); return 1; } if (decode) return decode_file(input_filename, output_filename); if (compression) return compress_file(input_filename, output_filename); badusage(); return 0; }
int main (int ac, char **av) { char *cmd = *av; char *cname; unsigned long delimiters[MAX_DELIMITER]; char *localmappers[MAX_LOCALMAPPER]; char *nameprep_version = NULL; int ndelimiters = 0; int nlocalmappers = 0; char *in_code = NULL; char *out_code = NULL; char *resconf_file = NULL; int no_resconf = 0; char *encoding_alias = NULL; int flags = DEFAULT_FLAGS; FILE *fp; idn_result_t r; idn_resconf_t resconf1, resconf2; idn_converter_t conv; int exit_value; #ifdef HAVE_SETLOCALE (void) setlocale (LC_ALL, ""); #endif /* * If the command name begins with 'r', reverse mode is assumed. */ if ((cname = strrchr (cmd, '/')) != NULL) cname++; else cname = cmd; if (cname[0] == 'r') flags |= FLAG_REVERSE; ac--; av++; while (ac > 0 && **av == '-') { #define OPT_MATCH(opt) (strcmp(*av, opt) == 0) #define MUST_HAVE_ARG if (ac < 2) print_usage(cmd) #define APPEND_LIST(array, size, item, what) \ if (size >= (sizeof(array) / sizeof(array[0]))) { \ errormsg("too many " what "\n"); \ exit(1); \ } \ array[size++] = item; \ ac--; av++ if (OPT_MATCH ("-in") || OPT_MATCH ("-i")) { MUST_HAVE_ARG; in_code = av[1]; ac--; av++; } else if (OPT_MATCH ("-out") || OPT_MATCH ("-o")) { MUST_HAVE_ARG; out_code = av[1]; ac--; av++; } else if (OPT_MATCH ("-conf") || OPT_MATCH ("-c")) { MUST_HAVE_ARG; resconf_file = av[1]; ac--; av++; } else if (OPT_MATCH ("-nameprep") || OPT_MATCH ("-n")) { MUST_HAVE_ARG; nameprep_version = av[1]; ac--; av++; } else if (OPT_MATCH ("-noconf") || OPT_MATCH ("-C")) { no_resconf = 1; } else if (OPT_MATCH ("-reverse") || OPT_MATCH ("-r")) { flags |= FLAG_REVERSE; } else if (OPT_MATCH ("-nolocalmap") || OPT_MATCH ("-L")) { flags &= ~FLAG_LOCALMAP; } else if (OPT_MATCH ("-nonameprep") || OPT_MATCH ("-N")) { flags &= ~FLAG_NAMEPREP; } else if (OPT_MATCH ("-unassigncheck") || OPT_MATCH ("-u")) { flags |= FLAG_UNASSIGNCHECK; } else if (OPT_MATCH ("-nounassigncheck") || OPT_MATCH ("-U")) { flags &= ~FLAG_UNASSIGNCHECK; } else if (OPT_MATCH ("-nobidicheck") || OPT_MATCH ("-B")) { flags &= ~FLAG_BIDICHECK; } else if (OPT_MATCH ("-noasciicheck") || OPT_MATCH ("-A")) { flags &= ~FLAG_ASCIICHECK; } else if (OPT_MATCH ("-nolengthcheck")) { flags &= ~FLAG_LENGTHCHECK; } else if (OPT_MATCH ("-noroundtripcheck")) { flags &= ~FLAG_ROUNDTRIPCHECK; } else if (OPT_MATCH ("-whole") || OPT_MATCH ("-w")) { flags &= ~FLAG_SELECTIVE; } else if (OPT_MATCH ("-localmap")) { MUST_HAVE_ARG; APPEND_LIST (localmappers, nlocalmappers, av[1], "local maps"); } else if (OPT_MATCH ("-delimiter")) { unsigned long v; MUST_HAVE_ARG; v = get_ucs (av[1]); APPEND_LIST (delimiters, ndelimiters, v, "delimiter maps"); } else if (OPT_MATCH ("-alias") || OPT_MATCH ("-a")) { MUST_HAVE_ARG; encoding_alias = av[1]; ac--; av++; } else if (OPT_MATCH ("-flush")) { flush_every_line = 1; } else if (OPT_MATCH ("-version") || OPT_MATCH ("-v")) { print_version (); } else { print_usage (cmd); } #undef OPT_MATCH #undef MUST_HAVE_ARG #undef APPEND_LIST ac--; av++; } if (ac > 1) print_usage (cmd); /* Initialize. */ if ((r = idn_resconf_initialize ()) != idn_success) { errormsg ("error initializing library\n"); return (1); } /* * Create resource contexts. * `resconf1' and `resconf2' are almost the same but local and * IDN encodings are reversed. */ resconf1 = NULL; resconf2 = NULL; if (idn_resconf_create (&resconf1) != idn_success || idn_resconf_create (&resconf2) != idn_success) { errormsg ("error initializing configuration contexts\n"); return (1); } /* Load configuration file. */ if (no_resconf) { set_defaults (resconf1); set_defaults (resconf2); } else { load_conf_file (resconf1, resconf_file); load_conf_file (resconf2, resconf_file); } /* Set encoding alias file. */ if (encoding_alias != NULL) set_encoding_alias (encoding_alias); /* Set input codeset. */ if (flags & FLAG_REVERSE) { if (in_code == NULL) { conv = idn_resconf_getidnconverter (resconf1); if (conv == NULL) { errormsg ("cannot get the IDN encoding.\n" "please specify an appropriate one " "with `-in' option.\n"); exit (1); } idn_resconf_setlocalconverter (resconf2, conv); idn_converter_destroy (conv); } else { set_idncode (resconf1, in_code); set_localcode (resconf2, in_code); } } else { if (in_code == NULL) { conv = idn_resconf_getlocalconverter (resconf1); if (conv == NULL) { errormsg ("cannot get the local encoding.\n" "please specify an appropriate one " "with `-in' option.\n"); exit (1); } idn_resconf_setidnconverter (resconf2, conv); idn_converter_destroy (conv); } else { set_localcode (resconf1, in_code); set_idncode (resconf2, in_code); } } /* Set output codeset. */ if (flags & FLAG_REVERSE) { if (out_code == NULL) { conv = idn_resconf_getlocalconverter (resconf1); if (conv == NULL) { errormsg ("cannot get the local encoding.\n" "please specify an appropriate one " "with `-out' option.\n"); exit (1); } idn_resconf_setidnconverter (resconf2, conv); idn_converter_destroy (conv); } else { set_localcode (resconf1, out_code); set_idncode (resconf2, out_code); } } else { if (out_code == NULL) { conv = idn_resconf_getidnconverter (resconf1); if (conv == NULL) { errormsg ("cannot get the IDN encoding.\n" "please specify an appropriate one " "with `-out' option.\n"); exit (1); } idn_resconf_setlocalconverter (resconf2, conv); idn_converter_destroy (conv); } else { set_idncode (resconf1, out_code); set_localcode (resconf2, out_code); } } /* Set delimiter map(s). */ if (ndelimiters > 0) { set_delimitermapper (resconf1, delimiters, ndelimiters); set_delimitermapper (resconf2, delimiters, ndelimiters); } /* Set local map(s). */ if (nlocalmappers > 0) { set_localmapper (resconf1, localmappers, nlocalmappers); set_localmapper (resconf2, localmappers, nlocalmappers); } /* Set NAMEPREP version. */ if (nameprep_version != NULL) { set_nameprep (resconf1, nameprep_version); set_nameprep (resconf2, nameprep_version); } idn_res_enable (1); /* Open input file. */ if (ac > 0) { if ((fp = fopen (av[0], "r")) == NULL) { errormsg ("cannot open file %s: %s\n", av[0], strerror (errno)); return (1); } } else { fp = stdin; } /* Do the conversion. */ if (flags & FLAG_REVERSE) exit_value = decode_file (resconf1, resconf2, fp, flags); else exit_value = encode_file (resconf1, resconf2, fp, flags); idn_resconf_destroy (resconf1); idn_resconf_destroy (resconf2); return exit_value; }
int main (int argc, char *argv[]) { unsigned char key[65]; FILE *kf; char *config_file=NULL, *key_file=NULL, *output_file=NULL, *extension_string=NULL, *custom_mibs=NULL; unsigned int keylen = 0; unsigned int encode_docsis = FALSE, decode_bin = FALSE, hash = 0; int i; int resolve_oids = 1; while (argc > 0) { argc--; argv++; if (!argc) { usage(); } /* the initial command-line parameters are flags / modifiers */ if (!strcmp (argv[0], "-nohash")) { nohash = 1; continue; } if (!strcmp (argv[0], "-o")) { resolve_oids = 0; continue; } if (!strcmp (argv[0], "-M")) { if (argc < 2 ) { usage(); } custom_mibs=argv[1]; argc--; argv++; continue; } if (!strcmp (argv[0], "-na")) { if (hash) { usage(); } hash = 1; continue; } if (!strcmp (argv[0], "-eu")) { if (hash) { usage(); } hash = 2; continue; } if (!strcmp (argv[0], "-dialplan")) { dialplan = 1; continue; } /* the following command-line parameters are actions */ if (!strcmp (argv[0], "-d")) { if (argc < 2 ) { usage(); } decode_bin = TRUE; config_file = argv[1]; break; } if (!strcmp (argv[0], "-e")) { if (argc < 4 ) { usage(); } encode_docsis = TRUE; config_file = argv[1]; key_file = argv[2]; output_file = argv[3]; break; } if (!strcmp (argv[0], "-m")) { extension_string = argv[argc-1]; key_file = argv[argc-2]; encode_docsis = TRUE; continue; } if (!strcmp (argv[0], "-p")) { /* encode_docsis may already have been set via the "-m" option */ encode_docsis = 0; argc--; argv++; if (argc < 2 ) { usage(); } /* -p might be followed by -dialplan. This is allowed for backwards * compatibility */ if (!strcmp (argv[0], "-dialplan")) { dialplan = 1; argc--; argv++; } if (argc < 2 ) { usage(); } /* if -m has not already been specified, then we expect "<mta_cfg_file> <output_file>" */ if (extension_string == NULL) { config_file = argv[0]; output_file = argv[1]; } break; } /* no more recognisable options means that we've either finished parsing * all arguments or else that the remaining arguments refer to a list of * config files */ if (argc) { break; } } if (encode_docsis) { if ((kf = fopen (key_file, "r")) == NULL) { fprintf (stderr, "docsis: error: can't open keyfile %s\n", key_file); exit (-5); } keylen = fread (key, sizeof (unsigned char), 64, kf); while (keylen > 0 && (key[keylen - 1] == 10 || key[keylen - 1] == 13)) { keylen--; /* eliminate trailing \n or \r */ } fclose(kf); } init_global_symtable (); setup_mib_flags(resolve_oids,custom_mibs); if (decode_bin) { decode_file (config_file); exit(0); // TODO: clean shutdown } if (extension_string) { /* encoding multiple files */ if (encode_docsis) { /* encode argv[argc-3] to argv[0] */ for (i=0; i<argc-2; i++) { if ( (output_file = get_output_name (argv[i], extension_string)) == NULL ) { fprintf(stderr, "Cannot process input file %s, extension too short ?\n",argv[i] ); continue; } fprintf(stderr, "Processing input file %s: output to %s\n",argv[i], output_file); if (encode_one_file (argv[i], output_file, key, keylen, encode_docsis, hash)) { exit(2); } free (output_file); output_file = NULL; } } else { /* encode argv[argc-2] to argv[0] */ for (i=0; i<argc-1; i++) { if ( (output_file = get_output_name (argv[i], extension_string)) == NULL ) { fprintf(stderr, "Cannot process input file %s, extension too short ?\n",argv[i] ); continue; } fprintf (stderr, "Processing input file %s: output to %s\n",argv[i], output_file); if (encode_one_file (argv[i], output_file, key, keylen, encode_docsis, hash)) { exit(2); } free (output_file); output_file = NULL; } } } else { if (encode_one_file (config_file, output_file, key, keylen, encode_docsis, hash)) { exit(2); } /* encode argv[1] */ } free(global_symtable); shutdown_mib(); return 0; }
int handle_file(const char *file, struct config_opts_t *config_opts) { const char *dest_dir = config_opts->dest_dir; const char *file_name = basename(strdup(file)); char dest_file[1024] = ""; char lz4pack[1024] = ""; if (check_lzo_header(file)) { constructPath(dest_file, dest_dir, file_name, ".lzounpack"); printf("Extracting LZO file to: %s\n", dest_file); if (lzo_unpack(file, dest_file) == 0) { handle_file(dest_file, config_opts); return EXIT_SUCCESS; } } else if (is_nfsb(file)) { constructPath(dest_file, dest_dir, file_name, ".unnfsb"); printf("Extracting nfsb image to: %s.\n\n", dest_file); unnfsb(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if (is_lz4(file)) { constructPath(dest_file, dest_dir, file_name, ".unlz4"); printf("UnLZ4 file to: %s\n", dest_file); decode_file(file, dest_file); return EXIT_SUCCESS; } else if (is_squashfs(file)) { constructPath(dest_file, dest_dir, file_name, ".unsquashfs"); printf("Unsquashfs file to: %s\n", dest_file); rmrf(dest_file); unsquashfs(file, dest_file); return EXIT_SUCCESS; } else if (is_cramfs_image(file)) { constructPath(dest_file, dest_dir, file_name, ".uncramfs"); printf("Uncramfs file to: %s\n", dest_file); rmrf(dest_file); uncramfs(dest_file, file); return EXIT_SUCCESS; } else if (isFileEPK2(file)) { extractEPK2file(file, config_opts); return EXIT_SUCCESS; } else if (isFileEPK1(file)) { extract_epk1_file(file, config_opts); return EXIT_SUCCESS; } else if (is_kernel(file)) { constructPath(dest_file, dest_dir, file_name, ".unpaked"); printf("Extracting boot image to: %s.\n\n", dest_file); extract_kernel(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if(isSTRfile(file)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nConverting %s file to TS: %s\n", file, dest_file); convertSTR2TS(file, dest_file, 0); return EXIT_SUCCESS; } else if(!memcmp(&file[strlen(file)-3], "PIF", 3)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nProcessing PIF file: %s\n", file); processPIF(file, dest_file); return EXIT_SUCCESS; } else if(symfile_load(file) == 0) { constructPath(dest_file, dest_dir, file_name, ".idc"); printf("Converting SYM file to IDC script: %s\n", dest_file); symfile_write_idc(dest_file); return EXIT_SUCCESS; } return EXIT_FAILURE; }
int main(int argc, const char * argv[]) { std::ios_base::sync_with_stdio(false); try { sp::program_options po(argc, argv); if( po.contains("help") ) { po.print(argv[0], std::cout); return EXIT_SUCCESS; } if( !po.validate_or_print_error(std::cerr) ) { return EXIT_FAILURE; } std::string output_file_name = po.get<std::string>("output-file"); if( sp::file_exists(output_file_name) ) { std::cerr << "Error: output-file " << output_file_name << " already exists; refusing to overwrite.\n"; return EXIT_FAILURE; } std::ofstream output_file( output_file_name, std::ios::binary ); if( !output_file.good() ) { std::cerr << "Error: failed creating output-file " << output_file_name << "\n"; return EXIT_FAILURE; } // // DECODE FILE // if( po.contains("decode-file") ) { std::ifstream decode_file( po.get<std::string>("decode-file"), std::ios::binary ); if( !decode_file.good() ) { std::cerr << "Error: failed opening decode-file " << po.get<std::string>("decode-file") << "\n"; return EXIT_FAILURE; } auto dec_iter = std::istreambuf_iterator<char>(decode_file); auto dec_iter_end = std::istreambuf_iterator<char>(); hm::meta md_decoded = hm::decode_meta_data(dec_iter, dec_iter_end); hm::decode( md_decoded, dec_iter, dec_iter_end, std::ostreambuf_iterator<char>(output_file) ); decode_file.close(); } // // ENCODE FILE // else if( po.contains("encode-file") ) { std::ifstream encode_file( po.get<std::string>("encode-file"), std::ios::binary ); if( !encode_file.good() ) { std::cerr << "Error: failed opening encode-file " << po.get<std::string>("encode-file") << "\n"; return EXIT_FAILURE; } unsigned int entity_size = po.get_entity_size(); auto enc_iter = std::istreambuf_iterator<char>(encode_file); auto enc_iter_end = std::istreambuf_iterator<char>(); auto out_iter = std::ostreambuf_iterator<char>(output_file); // write dummy data hm::meta md; hm::encode_meta_data(md, out_iter); // Because we cannot select a type based on runtime input, we either have // to use a macro or duplicate code. switch( entity_size ) { default: case 1: { auto tree = hm::build_huffman_tree<uint8_t>( enc_iter, enc_iter_end ); encode_file.seekg(0); md = hm::encode(enc_iter, enc_iter_end, tree.get(), out_iter); break; } case 2: { auto tree = hm::build_huffman_tree<uint16_t>( enc_iter, enc_iter_end ); encode_file.seekg(0); md = hm::encode(enc_iter, enc_iter_end, tree.get(), out_iter); break; } case 4: { auto tree = hm::build_huffman_tree<uint32_t>( enc_iter, enc_iter_end ); encode_file.seekg(0); md = hm::encode(enc_iter, enc_iter_end, tree.get(), out_iter); break; } case 8: { auto tree = hm::build_huffman_tree<uint64_t>( enc_iter, enc_iter_end ); encode_file.seekg(0); md = hm::encode(enc_iter, enc_iter_end, tree.get(), out_iter); break; } } // overwrite dummy with actual meta data output_file.seekp(0); hm::encode_meta_data(md, out_iter); encode_file.close(); } else { // program option validation failed // "should never happen" assert(false); } output_file.close(); return EXIT_SUCCESS; } catch(const boost::program_options::validation_error& e) { std::cerr << "Error " << e.what() << "\n"; return EXIT_FAILURE; } // "should never happen" assert(false); return EXIT_FAILURE; }
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { decode_file(Data, Size, 0, 0, 0, 0); return 0; }