Exemple #1
0
static BOOL CALLBACK enum_metafile_proc(EmfPlusRecordType record_type, unsigned int flags,
    unsigned int dataSize, const unsigned char *pStr, void *userdata)
{
    emfplus_check_state *state = (emfplus_check_state*)userdata;
    emfplus_record actual;

    actual.todo = 0;
    actual.record_type = record_type;

    if (dataSize == 0)
        ok(pStr == NULL, "non-NULL pStr\n");

    if (state->expected[state->count].record_type)
    {
        check_record(state->count, state->desc, &state->expected[state->count], &actual);

        state->count++;
    }
    else
    {
        ok(0, "%s: Unexpected EMF 0x%x record\n", state->desc, record_type);
    }

    return TRUE;
}
Exemple #2
0
int modeCheck(int c,int recordSelected,int *cursorLeft,int *cursorArea, char *subject,Cursor *cursor,Area rArea,Record **hovered,struct RecordList **activeBuffer,  struct RecordList *RLBuffer) {
	int redraw = FALSE;
	if(commandMode(*cursorArea)) {
		if(KEY_MODE_RECORDS(c) || KEY_MODE_ESCAPE(c)) {
			redraw = check_record(cursorArea,hovered,activeBuffer,RLBuffer);
		}
		else if (KEY_MODE_ADD(c)) {
			redraw = init_add(cursorArea,cursor);
		}
		else if (KEY_MODE_SEARCH(c)){
			redraw = init_search(subject,cursor,cursorArea);
		}
		else if (KEY_MODE_EDIT(c)) {
			if(*hovered) redraw = init_edit(recordSelected,cursorLeft,cursorArea,cursor,rArea,*hovered,*activeBuffer);
		} else if(KEY_MODE_DELETE(c)) {
			if(*hovered) redraw = init_delete(recordSelected,cursorArea,*hovered,*activeBuffer);
		}
	}
	return redraw;
}
Exemple #3
0
int edit_line_end(void *closure)
{
    struct edit_line *el = closure;

    if (el->phase > 1) {
	if (el->reversed)
	    Vect_line_reverse(el->Points);

	if (el->Points->n_points > 1) {
	    Vect_rewrite_line(&Map, el->line, el->line_type, el->Points,
			      el->Cats);
	    updated_lines_and_nodes_erase_refresh_display();
	}
	else {
	    int i;

	    /* delete lines with less than two points */
	    Vect_delete_line(&Map, el->line);
	    for (i = 0; i < el->Cats->n_cats; i++) {
		check_record(el->Cats->field[i], el->Cats->cat[i]);
	    }
	}


	Vect_destroy_line_struct(el->Points);
	Vect_destroy_cats_struct(el->Cats);
    }

    i_prompt("");
    i_prompt_buttons("", "", "");
    i_coor(COOR_NULL, COOR_NULL);

    G_debug(3, "edit_line(): End");

    return 1;
}
int process_args(int argc, char *argv[], char batch_mode)
{
	int c;
	char mode = 0;
	char time_ok = 0;
	char room = 0;
	char *filename;
	record *rec = calloc(1, sizeof(record));
	record *first = NULL;
	record *last = NULL;
	EVP_CIPHER_CTX en_ctx, de_ctx;

	optind = 0;
	opterr = 0;
	while ((c = getopt(argc, argv, ":T:K:E:G:ALR:B:")) != -1)
		switch (c)
		{
		case 'T':
			if (mode == BATCH_MODE) 
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (strtoi(optarg, &(rec->timestamp)) || !rec->timestamp)
				return print_error(ARG_ERROR);
			time_ok = 1;
			break;
		case 'K':
			if (mode == BATCH_MODE)
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (!is_token_valid(optarg))
				return print_error(ARG_ERROR);
			rec->token = optarg;
			break;
		case 'E':
			if (mode == BATCH_MODE)
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (rec->ptype == GUEST)
				return print_error(ARG_ERROR);
			rec->ptype = EMPLOYEE;
			if (!is_name_valid(optarg))
				return print_error(ARG_ERROR);
			rec->name = optarg;
			break;
		case 'G':
			if (mode == BATCH_MODE)
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (rec->ptype == EMPLOYEE)
				return print_error(ARG_ERROR);
			rec->ptype = GUEST;
			if (!is_name_valid(optarg))
				return print_error(ARG_ERROR);
			rec->name = optarg;
			break;
		case 'A':
			if (mode == BATCH_MODE)
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (rec->etype == DEPARTURE)
				return print_error(ARG_ERROR);
			rec->etype = ARRIVAL;
			break;
		case 'L':
			if (mode == BATCH_MODE)
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (rec->etype == ARRIVAL)
				return print_error(ARG_ERROR);
			rec->etype = DEPARTURE;
			break;
		case 'R':
			if (mode == BATCH_MODE)
				return print_error(ARG_ERROR);
			mode = DEFAULT_MODE;
			if (strtoi(optarg, &(rec->room_id)))
				return print_error(ARG_ERROR);
			room = 1;
			break;
		case 'B':
			if (mode == DEFAULT_MODE || batch_mode)
				return print_error(ARG_ERROR);
			mode = BATCH_MODE;
			filename = optarg;
			break;
		default:
			return print_error(ARG_ERROR);
		}
	
	if (mode == BATCH_MODE)
	{
		free(rec);
		if (batch(filename))
			return print_error(ARG_ERROR);
		return NO_ERROR;
	}

	//Checa opcoes mandatorias
	if (mode != DEFAULT_MODE || !time_ok || rec->token == NULL || rec->name == NULL 
	  || rec->etype == UNDEF_E || optind >= argc)
		return print_error(ARG_ERROR);

	//Ajusta o evento de acordo com a presenca de sala
	if (!room)
	{
		if (rec->etype == ARRIVAL)
			rec->etype = G_ARRIVAL;
		else
			rec->etype = G_DEPARTURE;
	}

	//Inicia contextos de seguranca
	if ((aes_init((unsigned char *) rec->token, strlen(rec->token), &en_ctx, &de_ctx)))
		return print_error(ARG_ERROR);

	//validacoes de consistencia
	c = read_records(&first, argv[optind], &last, &de_ctx);
	if (c)
	{
		EVP_CIPHER_CTX_cleanup(&en_ctx);
		EVP_CIPHER_CTX_cleanup(&de_ctx);
		return c;
	}

	if ((c = check_record(first, rec)))
	{
		del_records(&first);
		free(rec);
		EVP_CIPHER_CTX_cleanup(&en_ctx);
		EVP_CIPHER_CTX_cleanup(&de_ctx);
		return print_error(ARG_ERROR);
	}

	if (!first)
		first = rec;
	else
	{
		if (!last)
			last = first;
		last->next = rec;
	}
	write_record(first, argv[optind], &en_ctx);

	//TODO em batch, esses registros poderiam ser mantidos para evitar reler o arquivo.
	if (first != rec)
	{
		last->next = NULL;
		del_records(&first);
	}

	free(rec);
	EVP_CIPHER_CTX_cleanup(&en_ctx);
	EVP_CIPHER_CTX_cleanup(&de_ctx);

	return NO_ERROR;
}
Exemple #5
0
static int CALLBACK enum_emf_proc(HDC hDC, HANDLETABLE *lpHTable, const ENHMETARECORD *lpEMFR,
    int nObj, LPARAM lpData)
{
    emfplus_check_state *state = (emfplus_check_state*)lpData;
    emfplus_record actual;

    if (lpEMFR->iType == EMR_GDICOMMENT)
    {
        const EMRGDICOMMENT *comment = (const EMRGDICOMMENT*)lpEMFR;

        if (comment->cbData >= 4 && memcmp(comment->Data, "EMF+", 4) == 0)
        {
            int offset = 4;

            while (offset + sizeof(EmfPlusRecordHeader) <= comment->cbData)
            {
                const EmfPlusRecordHeader *record = (const EmfPlusRecordHeader*)&comment->Data[offset];

                ok(record->Size == record->DataSize + sizeof(EmfPlusRecordHeader),
                    "%s: EMF+ record datasize %u and size %u mismatch\n", state->desc, record->DataSize, record->Size);

                ok(offset + record->DataSize <= comment->cbData,
                    "%s: EMF+ record truncated\n", state->desc);

                if (offset + record->DataSize > comment->cbData)
                    return 0;

                if (state->expected[state->count].record_type)
                {
                    actual.todo = 0;
                    actual.record_type = record->Type;

                    check_record(state->count, state->desc, &state->expected[state->count], &actual);

                    state->count++;
                }
                else
                {
                    ok(0, "%s: Unexpected EMF+ 0x%x record\n", state->desc, record->Type);
                }

                offset += record->Size;
            }

            ok(offset == comment->cbData, "%s: truncated EMF+ record data?\n", state->desc);

            return 1;
        }
    }

    if (state->expected[state->count].record_type)
    {
        actual.todo = 0;
        actual.record_type = lpEMFR->iType;

        check_record(state->count, state->desc, &state->expected[state->count], &actual);

        state->count++;
    }
    else
    {
        ok(0, "%s: Unexpected EMF 0x%x record\n", state->desc, lpEMFR->iType);
    }

    return 1;
}
Exemple #6
0
static void test_packagecoltypes(void)
{
    MSIHANDLE hdb, view, rec;
    char path[MAX_PATH];
    LPCSTR query;
    UINT r, count;

    CoInitialize(NULL);

    lstrcpy(path, CURR_DIR);
    lstrcat(path, "\\");
    lstrcat(path, msifile);

    r = MsiOpenDatabase(path, MSIDBOPEN_READONLY, &hdb);
    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);

    query = "SELECT * FROM `Media`";
    r = MsiDatabaseOpenView( hdb, query, &view );
    todo_wine
    {
        ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
    }

    r = MsiViewGetColumnInfo( view, MSICOLINFO_NAMES, &rec );
    count = MsiRecordGetFieldCount( rec );
    todo_wine
    {
        ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
        ok(count == 6, "Expected 6, got %d\n", count);
        ok(check_record(rec, 1, "DiskId"), "wrong column label\n");
        ok(check_record(rec, 2, "LastSequence"), "wrong column label\n");
        ok(check_record(rec, 3, "DiskPrompt"), "wrong column label\n");
        ok(check_record(rec, 4, "Cabinet"), "wrong column label\n");
        ok(check_record(rec, 5, "VolumeLabel"), "wrong column label\n");
        ok(check_record(rec, 6, "Source"), "wrong column label\n");
    }

    r = MsiViewGetColumnInfo( view, MSICOLINFO_TYPES, &rec );
    count = MsiRecordGetFieldCount( rec );
    todo_wine
    {
        ok(r == ERROR_SUCCESS, "MsiViewGetColumnInfo failed\n");
        ok(count == 6, "Expected 6, got %d\n", count);
        ok(check_record(rec, 1, "i2"), "wrong column label\n");
        ok(check_record(rec, 2, "i4"), "wrong column label\n");
        ok(check_record(rec, 3, "L64"), "wrong column label\n");
        ok(check_record(rec, 4, "S255"), "wrong column label\n");
        ok(check_record(rec, 5, "S32"), "wrong column label\n");
        ok(check_record(rec, 6, "S72"), "wrong column label\n");
    }

    MsiCloseHandle(hdb);
    DeleteFile(msifile);
}
Exemple #7
0
/**** Starts here **********/ 
int parse_record(struct database *db, char *tablename, char* key, char* the_value, char *returnString, int len)
{
	struct Table *t = DB_getTable(db, tablename);
    	if(t == NULL) 
    	{
		strcpy(returnString, "E TABLE");
		return -1;
    	}
printf("the value %s\n",  the_value);
	int predicate_cnt = 0;
	int col_per_table = 0;
	int stat;
    
	// parse predicate string and store in a data structure
	char predicate_col_name[MAX_COLUMNS_PER_TABLE][MAX_COLNAME_LEN+1];
	char predicate_col_value[MAX_COLUMNS_PER_TABLE][MAX_STRTYPE_SIZE+1];

	int init2 = 0;
	
	while(init2 < MAX_COLUMNS_PER_TABLE)
	{
		memset(predicate_col_name[init2], '\0', sizeof(predicate_col_name[init2]));
		memset(predicate_col_value[init2], '\0', sizeof(predicate_col_value[init2]));
		init2++;
	}

	while(the_value[predicate_cnt] != '\0')
	{
		int col_name_cnt = 0;
		int col_value_cnt = 0;
		while(the_value[predicate_cnt] == ' ')
		{
			predicate_cnt++;
		}
		while((the_value[predicate_cnt] != ' ')&&(the_value[predicate_cnt] != '\0'))
		{		
			if(isalnum(the_value[predicate_cnt]) == 0)
			{
				strcpy(returnString, "E INVALID_PARAM");
				return -3;
			}
					
			predicate_col_name[col_per_table][col_name_cnt] = the_value[predicate_cnt];
			predicate_cnt++;
			col_name_cnt++;
		}

		while(the_value[predicate_cnt] == ' ')
		{
			predicate_cnt++;
		}
		while((the_value[predicate_cnt] != ',')&&(the_value[predicate_cnt] != '\0'))
		{
			if(the_value[predicate_cnt] == '+') 
			{
				predicate_cnt++;
			}
			if(the_value[predicate_cnt] == '-')
			{
				;
			}
			else if(isalnum(the_value[predicate_cnt]) == 0)
			{
				if(the_value[predicate_cnt] != ' ')
				{
					strcpy(returnString, "E INVALID_PARAM");
					return -3;
				}
			}				
			predicate_col_value[col_per_table][col_value_cnt] = the_value[predicate_cnt];
			predicate_cnt++;
			col_value_cnt++;
		}

		int length = (strlen(predicate_col_value[col_per_table])-1);

		while(predicate_col_value[col_per_table][length] == ' ')
		{
			predicate_col_value[col_per_table][length] = '\0';
			length -= 1;
		}

		if(the_value[predicate_cnt] == ',')
		{
			predicate_cnt++;
		}
		col_per_table++;
	}

	// check for matching cases
	stat = check_record(db, t, key, predicate_col_name, predicate_col_value, returnString);
	return stat;
		
	
}
Exemple #8
0
//Returns a record matching qurey or null pointer
USN_RECORD * Engine::GetUSN(std::wstring & CheckFor){
	MFT_ENUM_DATA mft_enum_data;
	DWORD bytecount = 1;
	void * buffer;
	USN_RECORD * record;
	USN_RECORD * recordend;
	USN_JOURNAL_DATA * journal;
	DWORDLONG nextid;
	DWORDLONG filecount = 0;

	buffer = VirtualAlloc(NULL, BUFFER_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

	if (buffer == NULL)
	{
		//printf("VirtualAlloc: %u\n", GetLastError());
		return nullptr;
	}

	//TODO: CHECK ALL NTFS DRIVES
	drive = CreateFile("\\\\?\\C:", GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING, NULL);

	if (drive == INVALID_HANDLE_VALUE)
	{
		//printf("CreateFile: %u\n", GetLastError());
		return nullptr;
	}

	if (!DeviceIoControl(drive, FSCTL_QUERY_USN_JOURNAL, NULL, 0, buffer, BUFFER_SIZE, &bytecount, NULL))
	{
		//printf("FSCTL_QUERY_USN_JOURNAL: %u\n", GetLastError());
		return nullptr;
	}

	journal = (USN_JOURNAL_DATA *)buffer;

	//printf("UsnJournalID: %lu\n", journal->UsnJournalID);
	//printf("FirstUsn: %lu\n", journal->FirstUsn);
	//printf("NextUsn: %lu\n", journal->NextUsn);
	//printf("LowestValidUsn: %lu\n", journal->LowestValidUsn);
	//printf("MaxUsn: %lu\n", journal->MaxUsn);
	//printf("MaximumSize: %lu\n", journal->MaximumSize);
	//printf("AllocationDelta: %lu\n", journal->AllocationDelta);

	maxusn = journal->MaxUsn;

	mft_enum_data.StartFileReferenceNumber = 0;
	mft_enum_data.LowUsn = 0;
	mft_enum_data.HighUsn = maxusn;

	//FSCTL_ENUM_USN_DATA
	for (;;)
	{

		if (!DeviceIoControl(drive, FSCTL_ENUM_USN_DATA, &mft_enum_data, sizeof(mft_enum_data), buffer, BUFFER_SIZE, &bytecount, NULL))
		{
			//printf("FSCTL_ENUM_USN_DATA: %u\n", GetLastError());
			//printf("Final ID: %lu\n", nextid);
			//printf("File count: %lu\n", filecount);
			return nullptr;
		}

		nextid = *((DWORDLONG *)buffer);
		record = (USN_RECORD *)((USN *)buffer + 1);
		recordend = (USN_RECORD *)(((BYTE *)buffer) + bytecount);

		while (record < recordend)
		{
			filecount++;
			if (check_record(record, CheckFor)) { return record; };
			//show_record(record);
			record = (USN_RECORD *)(((BYTE *)record) + record->RecordLength);
		}

		mft_enum_data.StartFileReferenceNumber = nextid;
	}

	if (buffer) VirtualFree(buffer, NULL, MEM_RELEASE);

	return nullptr;
}
Exemple #9
0
int main(int argc, char *argv[])
{
	int ch;
	std::string blob_file, index_file;

	while ((ch = getopt(argc, argv, "i:o:h")) != -1) {
		switch (ch) {
			case 'i':
				blob_file.assign(optarg);
				break;
			case 'o':
				index_file.assign(optarg);
				break;
			case 'h':
			default:
				print_usage(argv[0]);
				/* not reached */
		}
	}

	if (blob_file.empty() || index_file.empty()) {
		std::cerr << "You must specify input and output parameters\n\n";
		print_usage(argv[0]);
	}

	off_t ret = get_file_size(blob_file);
	if (ret <= 0) {
		std::cerr << "Blob file " << blob_file << " is empty. Exiting..." << std::endl;
		return 1;
	}
	size_t blob_length = static_cast<size_t>(ret);

	struct eblob_disk_control dc;
	uint64_t total = 0, removed = 0;
	uint64_t offset = 0;

	try {
		std::ifstream blob(blob_file.c_str(), std::ifstream::in | std::ifstream::binary);

		if (!blob.is_open())
			throw std::runtime_error("Blob is not opened");

		std::ofstream index(index_file.c_str(), std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);

		if (!index.is_open())
			throw std::runtime_error("Index is not opened");

		while (!blob.eof()) {
			blob.seekg(offset);
			blob.read(reinterpret_cast<char *>(&dc), sizeof(dc));

			if (blob.gcount() == 0)
				break;

			if (blob.gcount() != sizeof(dc)) {
				std::cerr << "Index read failed at " << blob.tellg() << std::endl;
				throw std::runtime_error("Index read failed");
			}

			eblob_convert_disk_control(&dc);

			if (!check_record(dc, offset, blob_length))
				throw std::runtime_error("Found malformed entry");

			++total;
			if (dc.flags & BLOB_DISK_CTL_REMOVE)
				++removed;

			eblob_convert_disk_control(&dc);
			index.write(reinterpret_cast<char *>(&dc), sizeof(dc));
			offset += dc.disk_size;
		}
	} catch (const std::exception &e) {
		std::cerr << e.what() << std::endl;
		std::cout << "Index extraction aborted" << std::endl;
		return 1;
	}

	std::cout << "Total records: " << total << std::endl;
	std::cout << "Removed records: " << removed << std::endl;

	return 0;
}
Exemple #10
0
int delete_line_update(void *closure, int sxn, int syn, int button)
{
    struct delete_line *dl = closure;
    double x = D_d_to_u_col(sxn);
    double y = D_d_to_u_row(syn);

    G_debug(3, "button = %d x = %d = %f y = %d = %f", button, sxn, x, syn, y);

    /* Display last highlighted in normal color */
    if (dl->last_line > 0) {
	display_line(dl->last_line, SYMB_DEFAULT, 1);
    }

    if (button == 3)		/* Quit tool */
	return 1;

    if (button == 1) {		/* Confirm / select */
	/* Delete last if any */
	if (dl->last_line > 0) {
	    int node1, node2;
	    int i;

	    /* Erase line and nodes !!! (because if the line is not connected to any other, nodes will die */
	    display_line(dl->last_line, SYMB_BACKGROUND, 1);
	    Vect_get_line_nodes(&Map, dl->line, &node1, &node2);
	    G_debug(2, "delete line = %d node1 = %d node2 = %d",
		    dl->last_line, node1, node2);

	    display_node(node1, SYMB_BACKGROUND, 1);
	    display_node(node2, SYMB_BACKGROUND, 1);

	    Vect_read_line(&Map, NULL, dl->Cats, dl->last_line);
	    Vect_delete_line(&Map, dl->last_line);
	    for (i = 0; i < dl->Cats->n_cats; i++) {
		check_record(dl->Cats->field[i], dl->Cats->cat[i]);
	    }

	    for (i = 0; i < Vect_get_num_updated_lines(&Map); i++)
		G_debug(2, "Updated line: %d",
			Vect_get_updated_line(&Map, i));

	    for (i = 0; i < Vect_get_num_updated_nodes(&Map); i++)
		G_debug(2, "Updated node: %d",
			Vect_get_updated_node(&Map, i));

	    updated_lines_and_nodes_erase_refresh_display();
	}

	/* Find neares point or line */
	dl->line =
	    Vect_find_line(&Map, x, y, 0, GV_POINT | GV_CENTROID, dl->thresh,
			   0, 0);
	G_debug(2, "point found = %d", dl->line);
	if (dl->line == 0)
	    dl->line =
		Vect_find_line(&Map, x, y, 0, GV_LINE | GV_BOUNDARY,
			       dl->thresh, 0, 0);
	G_debug(2, "line found = %d", dl->line);

	/* Display new selected line if any */
	if (dl->line > 0) {
	    display_line(dl->line, SYMB_HIGHLIGHT, 1);
	}
    }
    else {			/* button == 2 -> unselect */
	dl->line = 0;
    }

    if (dl->line > 0)
	i_prompt_buttons(_("Confirm and select next"), _("Unselect"), _("Quit tool"));
    else
	i_prompt_buttons(_("Select"), _("Unselect"), _("Quit tool"));

    dl->last_line = dl->line;
    dl->first = 0;

    return 0;
}