Example #1
0
void Tree::addclass( Tree::Course& course ) {

	// Add class to text file
	std::ofstream coursefile( course_file, 
			std::fstream::out | std::fstream::app );
	if( coursefile.is_open() ) {
		coursefile << course.crn << " "
					  << course.term << " "
					  << course.year << " "
					  << course.subj << " "
					  << course.crse << std::endl;
		coursefile.close();
	}
	addtotree( course );
}
Example #2
0
void Tree::loadfromfile() {

	// Read from text file
	std::ifstream coursefile( course_file );
	if( coursefile.is_open() ) {
		while( true ) {
			Tree::Course c;
			coursefile >> c.crn >> c.term >> c.year >> c.subj >> c.crse;
			if( coursefile.eof() ) break;
			courses.push_back( c ); // Populate vector
			addtotree( c ); // Populate tree
		}
		coursefile.close();
	}
}
Example #3
0
void ImportName(char* name)
{
	FILE* infile;
	union
	{
		PE_HEADER pe;
		OBJECT_ENTRY obj;
	};
	unsigned long temp;
	unsigned long export_;	//секция с експортом
	unsigned long numobj;	//число объектов
	unsigned long posdll;	//позиция секции в файле
	unsigned long nameadr;	//таблица адресов имен
	unsigned long startname;	//начало имени
	unsigned long ordinallist, ordinalbase;
	unsigned int i, j;
	DLLLIST* newdll;
	APIPROC* listapi;

	if ((infile = fopen(name, "rb")) == NULL)
	{
		ErrOpenFile(name);
		return;
	}

	fseek(infile, 0x3C, SEEK_SET);

	if (fread(&temp, 4, 1, infile) != 1)
	{
errread:
		fprintf(stderr, "Unable to read from file %s.\n", name);
		fclose(infile);
		return;
	}

	fseek(infile, 0, SEEK_END);

	if ((unsigned long)ftell(infile) <= temp)
	{
		fprintf(stderr, "Bad file %s.\n", name);
		fclose(infile);
		return;
	}

	fseek(infile, temp, SEEK_SET);

	if (fread(&pe, sizeof(PE_HEADER), 1, infile) != 1)
	{
		goto errread;
	}

	if (pe.sign != ('P' + ('E' << 8)))
	{
		fprintf(stderr, "For DLL support only format PE.\n");
		fclose(infile);
		return;
	}

	if ((export_ = pe.exportRVA) == 0)
	{
		fprintf(stderr, "No export directory on %s.\n", name);
		fclose(infile);
		return;
	}

	numobj = pe.numobj;
	temp = pe.objAlig;

	while (numobj != 0)
	{
		if (fread(&obj, sizeof(OBJECT_ENTRY), 1, infile) != 1)
		{
			goto errread;
		}

		if ((obj.sectionRVA + Align(obj.psize, temp)) > export_)
		{
			break;
		}

		numobj--;
	}

	if (numobj == 0)
	{
		fprintf(stderr, "Bad object table in %s.\n", name);
		fclose(infile);
		return;
	}

	posdll = obj.pOffset + export_ - obj.sectionRVA;
	fseek(infile, posdll + 24, SEEK_SET);

	if (fread(&numobj, 4, 1, infile) != 1)
	{
		goto errread;
	}

	fseek(infile, posdll + 32, SEEK_SET);

	if (fread(&nameadr, 4, 1, infile) != 1)
	{
		goto errread;
	}

	if (fread(&ordinallist, 4, 1, infile) != 1)
	{
		goto errread;
	}

	nameadr -= export_;
	ordinallist -= export_;
	fseek(infile, posdll + 12, SEEK_SET);

	if (fread(&startname, 4, 1, infile) != 1)
	{
		goto errread;
	}

	if (fread(&ordinalbase, 4, 1, infile) != 1)
	{
		goto errread;
	}

	fseek(infile, posdll + startname - export_, SEEK_SET);
	j = 0;

	do
	{
		if (fread(&string[j], 1, 1, infile) != 1)
		{
			goto errread;
		}
	}
	while (string[j++] != 0);	//имя библиотеки

	newdll = FindDLL();
	listapi = newdll->list;

	for (i = 0; i < numobj; i++)
	{
		fseek(infile, posdll + nameadr, SEEK_SET);

		if (fread(&startname, 4, 1, infile) != 1)
		{
			goto errread;
		}

		fseek(infile, posdll + startname - export_, SEEK_SET);
		itok.size = -1;
		j = 0;
		unsigned char c;

		do
		{
			if (fread(&c, 1, 1, infile) != 1)
			{
				goto errread;
			}

			if (c == '@')
			{
				itok.name[j] = 0;
				break;
			}

			itok.name[j] = c;
			j++;
		}
		while (j <= IDLENGTH && c != 0);

		if (c == '@')
		{
			j = 0;

			do
			{
				if (fread(&c, 1, 1, infile) != 1)
				{
					goto errread;
				}

				string[j++] = c;
			}
			while (isdigit(c));

			itok.size = getnumber(string);
		}

		tok = tk_id;
		searchvar(itok.name);

		if (tok == tk_id)
		{
			fseek(infile, posdll + ordinallist, SEEK_SET);
			itok.sib = 0;

			if (fread(&itok.sib, 2, 1, infile) != 1)
			{
				goto errread;
			}

			itok.sib += ordinalbase;
			tok = tk_apiproc;
			itok.number = secondcallnum++;
			itok.segm = NOT_DYNAMIC;
			string[0] = 0;

			if (newdll->num == 0)
			{
				listapi = (APIPROC*)MALLOC(sizeof(APIPROC));    //первая в списке
			}
			else
			{
				listapi = (APIPROC*)REALLOC(listapi, sizeof(APIPROC) * (newdll->num + 1));
			}

			(listapi + newdll->num)->recapi = addtotree(itok.name);
			newdll->num++;
		}

		nameadr += 4;
		ordinallist += 2;
	}

	newdll->list = listapi;
	fclose(infile);
}