Ejemplo n.º 1
0
int main(int argc, char** argv)
{
	unsigned int i;
	FILE *file;
	string buffer;
	do
	{
		cout << "Please enter file directory:" << endl;
		cin >> buffer;
		fopen_s(&file, buffer.c_str(), "rb");
	}while(file == NULL);
	rewind(stdin);
	int readMode;
	do
	{
		cout << "Please choose method:" << endl;
		cout << "1. File part reading mode" << endl;
		cout << "2. File allocation mode" << endl;
		cin >> readMode;
	}while(readMode != 1 && readMode != 2);
	vector<ZipHeader> headers;
	if(readMode == 1)
	{
		headers = ZipHeader::getAllHeaders(file);
	}
	else
	{
		fseek(file, 0L, SEEK_END);
		int totalBytes = ftell(file);
		rewind(file);
		char* tempo = new char[totalBytes+1];
		readFullFile(tempo, totalBytes, file);
		headers = ZipHeader::getAllHeaders(tempo, totalBytes);
		delete[] tempo;
	}
	bool isClean = true;
	for(i = 0 ; i < headers.size() ; i++)
	{
		//headers[i].print(); // Test for debugging purpose
		if(headers[i].getCompressedSize() != 0 && headers[i].getUncompressedSize()/headers[i].getCompressedSize() > MAX_RATIO)
		{
			isClean = false;
			SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0xCF);
			cout << "The file " << headers[i].getFileName() << " looks like a ZIP bomb!" << endl;
		}
	}
	if(isClean)
	{
		SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0xAF);
		cout << "The file " << buffer << " looks ok from here!" << endl;
	}
	cout << "Done. Press enter to exit.";
	fclose(file);
	getchar(); // keep programm running
	getchar();
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
	double **K;
	byte *stream, *crypted;
	long n;
	FILE *fpkey;

	if (argc != NARGS) {
		printf("usage: %s keyfile inputfile outputfile\n", argv[PROGNAME]);
		return -1;
	}

	// Carregar o arquivo de chave de criptografia...
	fpkey = fopen(argv[KEYFILE], "r");
	if (fpkey == NULL) {
		printf("Could not open keyfile: %s\n", argv[KEYFILE]);
		return -2;
	}
	K = matrix_create(ROWS, COLS);
	matrix_fread(fpkey, K, ROWS, COLS);
	fclose(fpkey);

	// Ler o arquivo a ser criptografado...
	stream = readFullFile(argv[INPUTFILE], &n);

	// Criptografar...
	crypted = crypt(stream, (int) n, K, ROWS, COLS);

	// Salvar em um arquivo...
	writeFullFile(argv[OUTPUTFILE], crypted, n*64);

	free(stream);
	free(crypted);
	matrix_free(K, ROWS);

	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
	byte *stream;
	long n;
	char *strings, *queryString, *string;
	char **allwords, **uniquewords;
	int i, nwords, maxlength, newwords;
	double **allvectors, **A, **query;

	if (argc != NARGS) {
		printf("usage: %s filename\n", argv[PROGNAME]);
		return -1;
	}

	printf("READING INPUT FILE...\n");
	stream = readFullFile(argv[FILENAME], &n);

	printf("PREPROCESSING...\n");
	strings = preprocessing(stream, n);
	printf("preprocessed: %s\n\n", strings);

	printf("EXTRACTING WORDS...\n");
	allwords = words(strings, &nwords);
	for (i = 0; i < nwords; i++) {
		printf("%s\n", allwords[i]);
	}

	printf("NORMALIZING WORDS...\n");
	maxlength = normalize(allwords, nwords);

	printf("EXTRACTING UNIQUE WORDS...\n");
	uniquewords = unique(allwords, nwords, &newwords);

	printf("PREPARING THE VECTORS {+1,-1}...\n");
	allvectors = vectors(uniquewords, newwords, maxlength);

	printf("GENERATING MATRIX A...\n");
	A = bam_training(allvectors, newwords, maxlength*BITS_IN_BYTE);

	query = (double **) malloc(sizeof(double *));
	// query (double **)
	//    |
	//    ----> double *

	while (1) {
		printf("Type a word: ");
		queryString = readLine(maxlength);
		printf("Word: %s\n", queryString);

		if (strcmp(queryString, "q") == 0) {
			free(queryString);
			break;
		}

		query[FIRST_ROW] = char2vec(queryString, maxlength);
		string = bam_testing(A, maxlength*BITS_IN_BYTE, maxlength*BITS_IN_BYTE, query);
		printf("Did you mean '%s'?\n", string);
		free(query[FIRST_ROW]);
		free(queryString);
		free(string);
	}

	free(query);
	free(stream);
	free(strings);
	for (i = 0; i < nwords; i++) free(allwords[i]); free(allwords);
	for (i = 0; i < newwords; i++) free(uniquewords[i]); free(uniquewords);
	matrix_free(allvectors, newwords);
	matrix_free(A, maxlength * BITS_IN_BYTE);

	return 0;
}
Ejemplo n.º 4
0
QString readFile( const QString & fileName )
{
	return readFullFile( findFile( fileName ) );
}