예제 #1
0
void
Package::extractItems(const char *filesPath, const char *pattern, char outType) {
    int32_t index;

    findItems(pattern);
    while((index=findNextItem())>=0) {
        extractItem(filesPath, index, outType);
    }
}
예제 #2
0
void z3ResEx::parseMsf( TMemoryStream &msf )
{
	switch( m_fileindexVer )
	{
		case 0 :
		{
			unsigned char method( 0 );
			FILEINDEX_ENTRY info;
			unsigned char *strMRFN( nullptr );
			unsigned char *strName( nullptr );

			unsigned int items( 0 ), errors( 0 );

			while( ( msf.Position() < msf.Size() ) && ( errors < MAX_ERRORS ) )
			{
				method = msf.ReadByte();
				msf.Read( &info, sizeof( FILEINDEX_ENTRY ) );

				unpackStringEx( msf, strMRFN, info.lenMRFN );
				unpackStringEx( msf, strName, info.lenName );

				if( m_listContents )
				{
					printf( "%s (%u bytes)\n", strName, info.size );
				}
				else
				{
					if( !( extractItem( info, method, (char *)strMRFN, (char *)strName ) ) )
						++errors;
				}

				++items;

				delete strMRFN;
				delete strName;
			}

			printf( "Processed %u items (%u issues)\n\n", items, errors );

			break;
		}
		case 1 :
		{
			parseMsfMethod2( msf );

			break;
		}		
	}
}
예제 #3
0
void z3ResEx::parseMsf( TMemoryStream &msf )
{
	switch( m_fileindexVer )
	{
		case 0 :
		{
			unsigned char method( 0 );
			FILEINDEX_ENTRY info;

      vector<unsigned char> strMRFN(MAX_STRING_SIZE);
      vector<unsigned char> strName(MAX_STRING_SIZE);

			unsigned int items( 0 ), errors( 0 );

			while( ( msf.Position() < msf.Size() ) && ( errors < MAX_ERRORS ) )
			{
				method = msf.ReadByte();
				msf.Read( &info, sizeof( FILEINDEX_ENTRY ) );

        unpackStringEx(msf, strMRFN, info.lenMRFN);
        unpackStringEx(msf, strName, info.lenName);

				if( m_listContents )
				{
					printf( "%s (%u bytes)\n", &strName[0], info.size );
				}
				else
				{
					if( !( extractItem( info, method, reinterpret_cast<const char*>(&strMRFN[0]), reinterpret_cast<const char*>(&strName[0]) ) ) )
						++errors;
				}

				++items;
			}

			printf( "Processed %u items (%u issues)\n\n", items, errors );

			break;
		}
		case 1 :
		{
			parseMsfMethod2( msf );

			break;
		}		
	}
}
예제 #4
0
파일: Tool.cpp 프로젝트: kdt3rd/constructor
std::shared_ptr<Tool>
Tool::parse( const Lua::Value &v )
{
	const Lua::Table &t = v.asTable();

	std::string tag, name, desc;
	std::vector<std::string> inpExt;
	std::vector<std::string> altExt;
	std::vector<std::string> inpTools;
	std::vector<std::string> outpExt;
	ItemPtr exePtr;
	std::string exe, outputPrefix;
	std::string pool;
	OptionGroup opts;
	OptionDefaultSet optDefaults;
	OptionDefaultSet flagPrefixes;
	std::string impFile, impStyle;
	std::vector<std::string> impCmd;
	std::vector<std::string> cmd;
	bool outRestat = false;

	for ( auto &i: t )
	{
		if ( i.first.type == Lua::KeyType::INDEX )
			continue;

		const std::string &k = i.first.tag;
		if ( k == "tag" )
			tag = i.second.asString();
		else if ( k == "name" )
			name = i.second.asString();
		else if ( k == "description" )
			desc = i.second.asString();
		else if ( k == "exe" )
		{
			if ( i.second.type() == LUA_TUSERDATA )
				exePtr = extractItem( i.second );
			else if ( i.second.type() == LUA_TSTRING )
				exe = i.second.asString();
			else if ( i.second.type() != LUA_TNIL )
				throw std::runtime_error( "Unknown type provided for executable" );
		}
		else if ( k == "input_extensions" )
		{
			inpExt = i.second.toStringList();
		}
		else if ( k == "alt_extensions" )
		{
			altExt = i.second.toStringList();
		}
		else if ( k == "output_extensions" )
		{
			outpExt = i.second.toStringList();
		}
		else if ( k == "output_prefix" )
		{
			outputPrefix = i.second.asString();
		}
		else if ( k == "input_tools" )
		{
			inpTools = i.second.toStringList();
		}
		else if ( k == "options" )
		{
			for ( auto &o: i.second.asTable() )
			{
				if ( o.first.type == Lua::KeyType::INDEX )
					throw std::runtime_error( "Expecting hash map of option name to option sets" );

				OptionSet &os = opts[o.first.tag];
				for ( auto &s: o.second.asTable() )
				{
					if ( s.first.type == Lua::KeyType::INDEX )
						throw std::runtime_error( "Expecting hash map of option commands to option names" );
					os[s.first.tag] = s.second.toStringList();
				}
			}
		}
		else if ( k == "option_defaults" )
		{
			for ( auto &od: i.second.asTable() )
			{
				if ( od.first.type == Lua::KeyType::INDEX )
					throw std::runtime_error( "Expecting hash map of option name to default value" );

				optDefaults[od.first.tag] = od.second.asString();
			}
		}
		else if ( k == "flag_prefixes" )
		{
			for ( auto &od: i.second.asTable() )
			{
				if ( od.first.type == Lua::KeyType::INDEX )
					throw std::runtime_error( "Expecting hash map of variable name to command line flag prefix" );

				flagPrefixes[od.first.tag] = od.second.asString();
			}
		}
		else if ( k == "implicit_dependencies" )
		{
			auto &id = i.second.asTable();
			auto idfn = id.find( "file" );
			auto idcmd = id.find( "cmd" );
			auto idst = id.find( "style" );

			if ( idfn == id.end() )
				throw std::runtime_error( "Expecting a file name definition for implicit_dependencies" );

			impFile = idfn->second.asString();
			if ( idcmd != id.end() )
				impCmd = idcmd->second.toStringList();
			if ( idst != id.end() )
				impStyle = idst->second.asString();
		}
		else if ( k == "cmd" )
		{
			cmd = i.second.toStringList();
		}
		else if ( k == "pool" )
			pool = i.second.asString();
		else if ( k == "output_restat" )
			outRestat = i.second.asBool();
	}

	std::shared_ptr<Tool> ret = std::make_shared<Tool>( tag, name );
	ret->myDescription = desc;
	ret->myExePointer = exePtr;
	ret->myExeName = exe;
	ret->myExtensions = inpExt;
	ret->myAltExtensions = altExt;
	ret->myOutputs = outpExt;
	ret->myOutputPrefix = outputPrefix;
	ret->myCommand = cmd;
	ret->myInputTools = inpTools;
	ret->myFlagPrefixes = flagPrefixes;
	ret->myOptions = opts;
	ret->myOptionDefaults = optDefaults;
	ret->myImplDepName = impFile;
	ret->myImplDepStyle = impStyle;
	ret->myImplDepCmd = impCmd;
	ret->myPool = pool;
	ret->myOutputRestat = outRestat;

	return ret;
}
예제 #5
0
파일: main.cpp 프로젝트: iKlui/z3ResEx
void extractionMain( TMemoryStream &msf )
{
	const unsigned int MAX_ERRORS( 50 );
	unsigned int items( 0 );

	FILEINDEX_ENTRY info;
	unsigned char method;

	char *strMRFN( nullptr ), *strName( nullptr );

	#define unpackString(buf,len) \
	{ \
		buf = new char[ len +1 ]; \
		msf.Read( buf, len ); \
		buf[ len ] = 0; \
	}

#ifdef SAVE_MSF_FILEINDEX
	msf.SaveToFile("z3debug_fileindex.msf");
#endif

	// Are we just listing files?
	if( user_opt_list_files )
	{
		std::string fname;

		printf("Listing filesystem contents\n\n");

		while( msf.Position() < msf.Size() )
		{
			method = msf.ReadByte();
			msf.Read( &info, sizeof( FILEINDEX_ENTRY ) );

			unpackString( strMRFN, info.lenMRFN );
			unpackString( strName, info.lenName );

			fname = fsRename( strMRFN, strName );
			printf("%s\n", fname.c_str());
			
			++items;

			delete strMRFN;
			delete strName;
		}

		fname.clear();
		printf("\nLocated %u files\n", items);
	}
	else
	// Run the main extraction loop
	{
		unsigned int errors( 0 );

		printf("Extracting filesystem contents\n\n");

		while( ( msf.Position() < msf.Size() ) && ( errors < MAX_ERRORS ) )
		{
			method = msf.ReadByte();
			msf.Read( &info, sizeof( FILEINDEX_ENTRY ) );

			unpackString( strMRFN, info.lenMRFN );
			unpackString( strName, info.lenName );

			if( !( extractItem( info, method, strMRFN, strName ) ) )
				++errors;

			++items;

			delete strMRFN;
			delete strName;
		}

		if( errors >= MAX_ERRORS )
			printf("ERROR: Extraction stopped as there were too many errors\n");
		else
			printf("\nExtracted %u files (%u problems)\n", items, errors);
	}
}
예제 #6
0
파일: scan.c 프로젝트: Maxsl/r-source
static SEXP scanVector(SEXPTYPE type, int maxitems, int maxlines,
		       int flush, SEXP stripwhite, int blskip, LocalData *d)
{
    SEXP ans, bns;
    int blocksize, c, i, n, linesread, nprev,strip, bch;
    char *buffer;
    R_StringBuffer strBuf = {NULL, 0, MAXELTSIZE};

    if (maxitems > 0) blocksize = maxitems;
    else blocksize = SCAN_BLOCKSIZE;

    R_AllocStringBuffer(0, &strBuf);
    PROTECT(ans = allocVector(type, blocksize));

    nprev = 0; n = 0; linesread = 0; bch = 1;

    if (d->ttyflag) sprintf(ConsolePrompt, "1: ");

    strip = asLogical(stripwhite);

    for (;;) {
	if(n % 10000 == 9999) R_CheckUserInterrupt();
	if (bch == R_EOF) {
	    if (d->ttyflag) R_ClearerrConsole();
	    break;
	}
	else if (bch == '\n') {
	    linesread++;
	    if (linesread == maxlines)
		break;
	    if (d->ttyflag) sprintf(ConsolePrompt, "%d: ", n + 1);
	    nprev = n;
	}
	if (n == blocksize) {
	    /* enlarge the vector*/
	    bns = ans;
	    if(blocksize > INT_MAX/2) error(_("too many items"));
	    blocksize = 2 * blocksize;
	    ans = allocVector(type, blocksize);
	    UNPROTECT(1);
	    PROTECT(ans);
	    copyVector(ans, bns);
	}
	buffer = fillBuffer(type, strip, &bch, d, &strBuf);
	if (nprev == n && strlen(buffer)==0 &&
	    ((blskip && bch =='\n') || bch == R_EOF)) {
	    if (d->ttyflag || bch == R_EOF)
		break;
	}
	else {
	    extractItem(buffer, ans, n, d);
	    if (++n == maxitems) {
		if (d->ttyflag && bch != '\n') { /* MBCS-safe */
		    while ((c = scanchar(FALSE, d)) != '\n')
			;
		}
		break;
	    }
	}
	if (flush && (bch != '\n') && (bch != R_EOF)) { /* MBCS-safe */
	    while ((c = scanchar(FALSE, d)) != '\n' && (c != R_EOF));
	    bch = c;
	}
    }
    if (!d->quiet) REprintf("Read %d item%s\n", n, (n == 1) ? "" : "s");
    if (d->ttyflag) ConsolePrompt[0] = '\0';

    if (n == 0) {
	UNPROTECT(1);
	R_FreeStringBuffer(&strBuf);
	return allocVector(type,0);
    }
    if (n == maxitems) {
	UNPROTECT(1);
	R_FreeStringBuffer(&strBuf);
	return ans;
    }

    bns = allocVector(type, n);
    switch (type) {
    case LGLSXP:
    case INTSXP:
	for (i = 0; i < n; i++)
	    INTEGER(bns)[i] = INTEGER(ans)[i];
	break;
    case REALSXP:
	for (i = 0; i < n; i++)
	    REAL(bns)[i] = REAL(ans)[i];
	break;
    case CPLXSXP:
	for (i = 0; i < n; i++)
	    COMPLEX(bns)[i] = COMPLEX(ans)[i];
	break;
    case STRSXP:
	for (i = 0; i < n; i++)
	    SET_STRING_ELT(bns, i, STRING_ELT(ans, i));
	break;
    case RAWSXP:
	for (i = 0; i < n; i++)
	    RAW(bns)[i] = RAW(ans)[i];
	break;
    default:
	UNIMPLEMENTED_TYPEt("scanVector", type);
    }
    UNPROTECT(1);
    R_FreeStringBuffer(&strBuf);
    return bns;
}
예제 #7
0
void
Package::extractItem(const char *filesPath, int32_t index, char outType) {
    extractItem(filesPath, items[index].name, index, outType);
}