Esempio n. 1
0
int main() {
	unsigned long long segmnt;
	char ppath[PATH_MAX];
	struct stat st;
	char tmp[64];
	int fd;

	if ((mem_fd = open("/dev/mem",O_RDONLY)) < 0) {
		fprintf(stderr,"Unable to open /dev/mem, %s\n",strerror(errno));
		return 1;
	}
	if (fstat(mem_fd,&st)) {
		fprintf(stderr,"Unable to stat opened /dev/mem handle, %s\n",strerror(errno));
		return 1;
	}
	if (!S_ISCHR(st.st_mode)) {
		fprintf(stderr,"/dev/mem is NOT character device\n");
		return 1;
	}

	/* NTS: This code assumes you are compiling with _FILE_OFFSET_BITS == 64 so that
	 *      on 32-bit systems the limitations of the original mmap() call do not interfere
	 *      with our attempt here */
	ROM = mmap(NULL,ROM_size,PROT_READ,MAP_SHARED,mem_fd,ROM_offset);
	if (ROM == MAP_FAILED) {
		fprintf(stderr,"Unable to mmap ROM\n");
		return 1;
	}

	printf(HELLO);
	printf("Press ENTER to start\n");
	waitforenter();

	/* write it out */
	for (segmnt=ROM_offset;segmnt < (ROM_offset+(unsigned long long)ROM_size);segmnt += (unsigned long long)ROM_blocksize) {
		while (freespace() < (66UL << 10UL)) {
			if (getcwd(ppath,sizeof(ppath)) == NULL) {
				fprintf(stderr,"Unable to get current directory\n");
				return 1;
			}

			/* Linux counts the mountpoint as being in use if a file is open there or
			 * a program has it as it's current working directory. so to allow the user
			 * to remove the floppy (or whatever) we have to change our working directory */
			if (chdir("/")) {
				fprintf(stderr,"Unable to bail out to root\n");
				return 1;
			}

			printf("Unmount and remove disk, move files off on another computer,\n");
			printf("re-mount and re-insert and hit ENTER\n");
			waitforenter();

			/* assuming the user has reloaded the disk/flash drive/whatever and remounted
			 * at the same point, jump back into the directory and try to resume our work */
			if (chdir(ppath)) {
				fprintf(stderr,"Unable to reenter capture dir\n");
				return 1;
			}
		}

		sprintf(tmp,CAPTURE_SPRINTF,segmnt);
		printf("Writing ... %s\n",tmp);
		fd = open(tmp,O_WRONLY|O_CREAT|O_TRUNC,0644);
		if (fd < 0) {
			fprintf(stderr,"Unable to open file, %s\n",strerror(errno));
			return 1;
		}
		if ((size_t)write(fd,ROM+segmnt-ROM_offset,ROM_blocksize) != ROM_blocksize) {
			fprintf(stderr,"Unable to write ROM block\n");
			return 1;
		}
		close(fd);
	}

	munmap(ROM,ROM_size);
	close(mem_fd);
	return 0;
}
Esempio n. 2
0
int main() {
    unsigned long long segmnt;
    LARGE_INTEGER viewbase;
    size_t vaddress,maplen;
    WCHAR ppath[PATH_MAX];
    NTSTATUS status;
    char tmp[64];
    int fd;

    if (OpenPhysMem()) {
        fprintf(stderr,"Unable to open physical memory device\n");
        return 1;
    }

    memset(&viewbase,0,sizeof(viewbase));
    viewbase.QuadPart = (ULONGLONG)ROM_offset;
    maplen = ROM_size-1;
    vaddress = 0;

    status = ZwMapViewOfSection(mem_fd,(HANDLE)-1,(PVOID*)(&vaddress),0UL,
                                ROM_size-1,&viewbase,(PDWORD)(&maplen),ViewShare,0,PAGE_READONLY);
    if (!NT_SUCCESS(status)) {
        fprintf(stderr,"Failed to map view of section for %08llx status=0x%08lx\n",viewbase.QuadPart,(unsigned long)status);
        return 1;
    }
    ROM = (unsigned char*)((size_t)vaddress);

    printf(HELLO);
    printf("Press ENTER to start\n");
    waitforenter();

    /* write it out */
    for (segmnt=ROM_offset; segmnt < (ROM_offset+(unsigned long long)ROM_size); segmnt += (unsigned long long)ROM_blocksize) {
        while (freespace() < (66UL << 10UL)) {
            if (GetCurrentDirectoryW(sizeof(ppath),ppath) == 0) {
                fprintf(stderr,"Unable to get current directory\n");
                return 1;
            }

            /* chdir() off the drive so that it is safe for the user to remove the
             * pen drive, floppy, etc. */
            if (SetCurrentDirectoryW(L"C:\\"/*FIXME*/) == 0) {
                fprintf(stderr,"Unable to bail out to root\n");
                return 1;
            }

            printf("Unmount and remove disk, move files off on another computer,\n");
            printf("re-mount and re-insert and hit ENTER\n");
            waitforenter();

            /* assuming the user has reloaded the disk/flash drive/whatever and remounted
             * at the same point, jump back into the directory and try to resume our work */
            if (SetCurrentDirectoryW(ppath) == 0) {
                fprintf(stderr,"Unable to reenter capture dir\n");
                return 1;
            }
        }

        sprintf(tmp,CAPTURE_SPRINTF,segmnt);
        printf("Writing ... %s\n",tmp);
        fd = open(tmp,O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0644);
        if (fd < 0) {
            fprintf(stderr,"Unable to open file, %s\n",strerror(errno));
            return 1;
        }
        if ((size_t)write(fd,ROM+segmnt-ROM_offset,ROM_blocksize) != ROM_blocksize) {
            fprintf(stderr,"Unable to write ROM block\n");
            return 1;
        }
        close(fd);
    }

    ZwUnmapViewOfSection((HANDLE)-1,(PVOID)vaddress);
    ClosePhysMem();
    return 0;
}
Esempio n. 3
0
int main()
{
	char **txt1 = NULL, **txt2 = NULL;
	short isprogend = 0, istxt1 = 0, istxt2 = 0, strct;

	SetConsoleCP(1251);
	SetConsoleOutputCP(1251);
	system("title = Курсовая работа. Обработка текста");

	do
	{
		system("cls");
		switch (menu())
		{
		case '1': //ввод текста
			if (txt1 != NULL)
				txt1 = (char**)dsfree((void**)txt1, strct);
			if (txt2 != NULL)
				txt2 = (char**)(dsfree((void**)txt2, strct));
			istxt1 = 1;
			istxt2 = 0;
			system("cls");
			rewind(stdin);
			txt1 = gettxt(&strct);
			printf_s("\nВвод завершен!\n");
			waitforenter();
			break;
		case '2': //вывод исходного текста
			system("cls");
			if (istxt1)
			{
					printf_s("Исходный текст:\n");
					putstrings(txt1, strct);
			}
			else
				printf_s("Ошибка! Сначала введите исходный текст");
			printf_s("\n");
			waitforenter();
			break;
		case '3': //обработка исходного текста
			system("cls");
			if (istxt1)
			{
				if (txt2 == NULL)
				{
					istxt2 = 1;
					txt2 = wordproc(txt1, strct);
					printf_s("Текст обработан");
				}
				else
					printf_s("Текст уже был обработан");
			}
			else
				printf_s("Ошибка! Сначала введите исходный текст");
			printf_s("\n");
			waitforenter();
			break;
		case '4': //вывод текста
			system("cls");
			if (istxt2)
			{
				printf_s("Результирующий текст:\n");
				putstrings(txt2, strct);
			}
			else
				printf_s("Ошибка! Сначала обработайте исходный текст");
			printf_s("\n");
			waitforenter();
			break;
		case '5': //справка
			system("cls");
			reference();
			printf_s("\n");
			waitforenter();
			break;
		case '6': //выход
			system("cls");
			printf_s("Вы уверены, что хотите выйти?(1-Да/0-Нет): ");
			scanf_s("%hi", &isprogend);
			rewind(stdin);
			break;
		default:
			printf_s("Ошибка! Введите существующий пункт меню\n");
			waitforenter();
		}
	} while (!isprogend);
	if (txt1 != NULL)
		txt1 = (char**)dsfree((void**)txt1, strct);
	if (txt1 != NULL)
		txt1 = (char**)dsfree((void**)txt1, strct);
	return 0;
}