model_multipart* reader::load_from_stream(std::istream &stream, std::string name) { model_multipart *nm = new model_multipart; // Search for submodel names std::set<std::string> m_submodel_names; std::string line; while (!stream.eof()) { getline(stream, line); line = utils::trim_string(line); if (line.length() > 7 && line.substr(0, 6) == "0 FILE") { std::string filename = utils::translate_string(line.substr(7, line.length() - 7)); m_submodel_names.insert(filename); } } // Rewind the stream to the beginning stream.clear(); stream.seekg(0, std::ios::beg); bool tmp = parse_stream(nm->main_model(), stream, true); if (nm->main_model()->name().empty()) { std::string nfp; size_t o = name.find_last_of("/"); if (o == std::string::npos) nfp = name; else nfp = name.substr(o + 1, name.length() - o); nm->main_model()->set_name(nfp); } if (!tmp) return nm; bool loop = true; while (loop) { std::string fn; model *m = new model; m->set_parent(nm); m->set_modeltype(model::submodel); loop = parse_stream(m, stream, true, &fn); if (fn.length() == 0) fn = m->name(); nm->insert_submodel(m, fn); } nm->link_submodels(); if (utils::cyclic_reference_test(nm->main_model())) throw exception(__func__, exception::fatal, "Cyclic reference detected. This model file may be corrupted."); for (model_multipart::submodel_const_iterator it = nm->submodel_list().begin(); it != nm->submodel_list().end(); ++it) { if (utils::cyclic_reference_test((*it).second)) throw exception(__func__, exception::fatal, "Cyclic reference detected. This model file may be corrupted."); } return nm; }
stn_t parser_c::parse_stn() { auto stn = stn_t(); stn.num_video = m_bc->get_bits(8); stn.num_audio = m_bc->get_bits(8); stn.num_pg = m_bc->get_bits(8); stn.num_ig = m_bc->get_bits(8); stn.num_secondary_audio = m_bc->get_bits(8); stn.num_secondary_video = m_bc->get_bits(8); stn.num_pip_pg = m_bc->get_bits(8); m_bc->skip_bits(5 * 8); // reserved stn.video_streams.reserve(stn.num_video); stn.audio_streams.reserve(stn.num_audio); stn.pg_streams.reserve(stn.num_pg); for (auto idx = 0u; idx < stn.num_video; ++idx) stn.video_streams.push_back(parse_stream()); for (auto idx = 0u; idx < stn.num_audio; ++idx) stn.audio_streams.push_back(parse_stream()); for (auto idx = 0u; idx < stn.num_pg; ++idx) stn.pg_streams.push_back(parse_stream()); return stn; }
int main(int argc, char *argv[]) { FILE *fp; char res[16]; struct pollfd fds; fds.fd = 0; /* this is STDIN */ fds.events = POLLIN; int inputViaStdIn = poll(&fds, 1, 0); if(inputViaStdIn) { fp = stdin; } else { fp=fopen(argv[1],"rb"); if (fp==(FILE *)NULL) { fprintf (stderr,"failed: can't open %s\n", argv[1]); exit(-1); } } parse_stream(fp,res); fprintf(stdout, "ADLER32 %x\n",adlercount); if(!inputViaStdIn) fclose(fp); exit(0); }
const char* TaggerImpl::parse(const char*input, size_t len1, char *output, size_t len2) { std::istrstream is(input, len1); std::ostrstream os(output, len2); if (!parse_stream(&is, &os)) return false; return output; }
int main(int argc,char *argv[]) { msgqueue_param_t *msgqueue; int infd, outfd; Byte8_t jptlen, j2klen; struct stat sb; Byte_t *jptstream, *j2kstream; if( argc < 3){ fprintf( stderr, "Too few arguments:\n"); fprintf( stderr, " - input jpt file\n"); fprintf( stderr, " - output j2k file\n"); return -1; } if(( infd = open( argv[1], O_RDONLY)) == -1){ fprintf( stderr, "file %s not exist\n", argv[1]); return -1; } if( fstat( infd, &sb) == -1){ fprintf( stderr, "input file stream is broken\n"); return -1; } jptlen = (Byte8_t)sb.st_size; jptstream = (Byte_t *)malloc( jptlen); if( read( infd, jptstream, jptlen) != jptlen){ fprintf( stderr, "file reading error\n"); free( jptstream); return -1; } close(infd); msgqueue = gene_msgqueue( true, NULL); parse_stream( jptstream, jptlen, 0, msgqueue); //print_msgqueue( msgqueue); j2kstream = recons_j2k( msgqueue, jptstream, msgqueue->first->csn, 0, &j2klen); delete_msgqueue( &msgqueue); free( jptstream); if(( outfd = open( argv[2], O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){ fprintf( stderr, "file %s open error\n", argv[2]); return -1; } if( write( outfd, j2kstream, j2klen) != j2klen) fprintf( stderr, "j2k file write error\n"); free( j2kstream); close(outfd); return 0; }
void LLSecAPIBasicHandler::_readProtectedData() { // attempt to load the file into our map LLPointer<LLSDParser> parser = new LLSDXMLParser(); llifstream protected_data_stream(mProtectedDataFilename.c_str(), llifstream::binary); if (!protected_data_stream.fail()) { int offset; U8 salt[STORE_SALT_SIZE]; U8 buffer[BUFFER_READ_SIZE]; U8 decrypted_buffer[BUFFER_READ_SIZE]; int decrypted_length; unsigned char unique_id[MAC_ADDRESS_BYTES]; LLMachineID::getUniqueID(unique_id, sizeof(unique_id)); LLXORCipher cipher(unique_id, sizeof(unique_id)); // read in the salt and key protected_data_stream.read((char *)salt, STORE_SALT_SIZE); offset = 0; if (protected_data_stream.gcount() < STORE_SALT_SIZE) { throw LLProtectedDataException("Config file too short."); } cipher.decrypt(salt, STORE_SALT_SIZE); // totally lame. As we're not using the OS level protected data, we need to // at least obfuscate the data. We do this by using a salt stored at the head of the file // to encrypt the data, therefore obfuscating it from someone using simple existing tools. // We do include the MAC address as part of the obfuscation, which would require an // attacker to get the MAC address as well as the protected store, which improves things // somewhat. It would be better to use the password, but as this store // will be used to store the SL password when the user decides to have SL remember it, // so we can't use that. OS-dependent store implementations will use the OS password/storage // mechanisms and are considered to be more secure. // We've a strong intent to move to OS dependent protected data stores. // read in the rest of the file. EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX_init(&ctx); EVP_DecryptInit(&ctx, EVP_rc4(), salt, NULL); // allocate memory: std::string decrypted_data; while(protected_data_stream.good()) { // read data as a block: protected_data_stream.read((char *)buffer, BUFFER_READ_SIZE); EVP_DecryptUpdate(&ctx, decrypted_buffer, &decrypted_length, buffer, protected_data_stream.gcount()); decrypted_data.append((const char *)decrypted_buffer, protected_data_stream.gcount()); } // RC4 is a stream cipher, so we don't bother to EVP_DecryptFinal, as there is // no block padding. EVP_CIPHER_CTX_cleanup(&ctx); std::istringstream parse_stream(decrypted_data); if (parser->parse(parse_stream, mProtectedDataMap, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE) { throw LLProtectedDataException("Config file cannot be decrypted."); } } }
bool Driver::parse_string(const std::string &input, const std::string& sname) { std::istringstream iss(input); return parse_stream(iss, sname); }
bool Driver::parse_file(const std::string &filename) { std::ifstream in(filename.c_str()); if (!in.good()) return false; return parse_stream(in, filename); }