예제 #1
0
//-----------------------------------------------------------------------------
bool HoneDumpcap::Initialize(QStringList args, QString appPath)
{
	m_args = args;
	if (!ParseArgs()) {
		return false;
	}

#ifdef WIN32
	m_dumpcapFileName = QString("%1/dumpcap_orig.exe").arg(appPath);
#else
	m_dumpcapFileName = QString("%1/dumpcap_orig").arg(appPath);
#endif

	if (m_operation == OperationCapture) {
		if (m_haveHoneInterface) {
			m_captureStart = QDateTime::currentMSecsSinceEpoch();
			if (m_parentPid.isEmpty()) {
				Log("Capturing on 'Hone'");
			}
			if (!OpenDriver() || !OpenCaptureFile()) {
				return false;
			}
		} else {
			connect(&m_dumpcapProcess, SIGNAL(error(QProcess::ProcessError)),      this, SLOT(OnError(QProcess::ProcessError)));
			connect(&m_dumpcapProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(OnFinished(int,QProcess::ExitStatus)));
			connect(&m_dumpcapProcess, SIGNAL(readyReadStandardError()),           this, SLOT(OnReadyReadStandardError()));
			connect(&m_dumpcapProcess, SIGNAL(readyReadStandardOutput()),          this, SLOT(OnReadyReadStandardOutput()));
			m_dumpcapProcess.start(m_dumpcapFileName, m_args);
			m_needEventLoop = true;
		}
	}
	return true;
}
예제 #2
0
파일: filelpt.cpp 프로젝트: Ailick/dosbox-x
bool CFileLPT::OpenFile() {
	switch(filetype) {
	case FILE_DEV:
		file = fopen(name.c_str(),"wb");
		break;
	case FILE_CAPTURE:
		file = OpenCaptureFile("Parallel Port Stream",".prt");
		break;
	case FILE_APPEND:
		file = fopen(name.c_str(),"ab");
		break;
	}

	if(timeout != 0) setEvent(0, (float)(timeout + 1));

	if(file==NULL) {
		LOG_MSG("Parallel %d: Failed to open %s",port_nr+1,name.c_str());
		fileOpen = false;
		return false;
	} else {
		fileOpen = true;
		return true;
	}
}
예제 #3
0
void CAPTURE_AddImage(Bitu width, Bitu height, Bitu bpp, Bitu pitch, Bitu flags, float fps, Bit8u * data, Bit8u * pal) {
#if (C_SSHOT)
	Bitu i;
	Bit8u doubleRow[SCALER_MAXWIDTH*4];
	Bitu countWidth = width;

	if (flags & CAPTURE_FLAG_DBLH)
		height *= 2;
	if (flags & CAPTURE_FLAG_DBLW)
		width *= 2;

	if (height > SCALER_MAXHEIGHT)
		return;
	if (width > SCALER_MAXWIDTH)
		return;
	
	if (CaptureState & CAPTURE_IMAGE) {
		png_structp png_ptr;
		png_infop info_ptr;
		png_color palette[256];

		CaptureState &= ~CAPTURE_IMAGE;
		/* Open the actual file */
		FILE * fp=OpenCaptureFile("Screenshot",".png");
		if (!fp) goto skip_shot;
		/* First try to allocate the png structures */
		png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL, NULL);
		if (!png_ptr) goto skip_shot;
		info_ptr = png_create_info_struct(png_ptr);
		if (!info_ptr) {
			png_destroy_write_struct(&png_ptr,(png_infopp)NULL);
			goto skip_shot;
		}
	
		/* Finalize the initing of png library */
		png_init_io(png_ptr, fp);
		png_set_compression_level(png_ptr,Z_BEST_COMPRESSION);
		
		/* set other zlib parameters */
		png_set_compression_mem_level(png_ptr, 8);
		png_set_compression_strategy(png_ptr,Z_DEFAULT_STRATEGY);
		png_set_compression_window_bits(png_ptr, 15);
		png_set_compression_method(png_ptr, 8);
		png_set_compression_buffer_size(png_ptr, 8192);
	
		if (bpp==8) {
			png_set_IHDR(png_ptr, info_ptr, width, height,
				8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
				PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
			for (i=0;i<256;i++) {
				palette[i].red=pal[i*4+0];
				palette[i].green=pal[i*4+1];
				palette[i].blue=pal[i*4+2];
			}
			png_set_PLTE(png_ptr, info_ptr, palette,256);
		} else {
			png_set_bgr( png_ptr );
			png_set_IHDR(png_ptr, info_ptr, width, height,
				8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
				PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
		}
#ifdef PNG_TEXT_SUPPORTED
		int fields = 1;
		png_text text[1];
		const char* text_s = "DOSBox " VERSION;
		size_t strl = strlen(text_s);
		char* ptext_s = new char[strl + 1];
		strcpy(ptext_s, text_s);
		char software[9] = { 'S','o','f','t','w','a','r','e',0};
		text[0].compression = PNG_TEXT_COMPRESSION_NONE;
		text[0].key  = software;
		text[0].text = ptext_s;
		png_set_text(png_ptr, info_ptr, text, fields);
#endif
		png_write_info(png_ptr, info_ptr);
#ifdef PNG_TEXT_SUPPORTED
		delete [] ptext_s;
#endif
		for (i=0;i<height;i++) {
			void *rowPointer;
			void *srcLine;
			if (flags & CAPTURE_FLAG_DBLH)
				srcLine=(data+(i >> 1)*pitch);
			else
				srcLine=(data+(i >> 0)*pitch);
			rowPointer=srcLine;
			switch (bpp) {
			case 8:
				if (flags & CAPTURE_FLAG_DBLW) {
   					for (Bitu x=0;x<countWidth;x++)
						doubleRow[x*2+0] =
						doubleRow[x*2+1] = ((Bit8u *)srcLine)[x];
					rowPointer = doubleRow;
				}
				break;
			case 15:
				if (flags & CAPTURE_FLAG_DBLW) {
					for (Bitu x=0;x<countWidth;x++) {
						Bitu pixel = ((Bit16u *)srcLine)[x];
						doubleRow[x*6+0] = doubleRow[x*6+3] = ((pixel& 0x001f) * 0x21) >>  2;
						doubleRow[x*6+1] = doubleRow[x*6+4] = ((pixel& 0x03e0) * 0x21) >>  7;
						doubleRow[x*6+2] = doubleRow[x*6+5] = ((pixel& 0x7c00) * 0x21) >>  12;
					}
				} else {
					for (Bitu x=0;x<countWidth;x++) {
						Bitu pixel = ((Bit16u *)srcLine)[x];
						doubleRow[x*3+0] = ((pixel& 0x001f) * 0x21) >>  2;
						doubleRow[x*3+1] = ((pixel& 0x03e0) * 0x21) >>  7;
						doubleRow[x*3+2] = ((pixel& 0x7c00) * 0x21) >>  12;
					}
				}
				rowPointer = doubleRow;
				break;
			case 16:
				if (flags & CAPTURE_FLAG_DBLW) {
					for (Bitu x=0;x<countWidth;x++) {
						Bitu pixel = ((Bit16u *)srcLine)[x];
						doubleRow[x*6+0] = doubleRow[x*6+3] = ((pixel& 0x001f) * 0x21) >> 2;
						doubleRow[x*6+1] = doubleRow[x*6+4] = ((pixel& 0x07e0) * 0x41) >> 9;
						doubleRow[x*6+2] = doubleRow[x*6+5] = ((pixel& 0xf800) * 0x21) >> 13;
					}
				} else {
					for (Bitu x=0;x<countWidth;x++) {
예제 #4
0
//-----------------------------------------------------------------------------
bool HoneDumpcap::CapturePackets(void)
{
	while (m_captureState != CaptureStateDone) {

#ifdef WIN32
		if (m_signalPipeHandle != InvalidFileHandle) {
			DWORD bytesAvailable;
			const BOOL rc = ::PeekNamedPipe(m_signalPipeHandle, NULL, 0, NULL, &bytesAvailable, NULL);
			if (!rc || (bytesAvailable > 0)) {
				Log(QString("Parent process %1 is closing us").arg(m_parentPid));
				m_markCleanup = true;
			}
		}
#else // #ifdef WIN32
		fd_set readfds;
#endif // #ifdef WIN32

		if (m_markCleanup && (m_captureState != CaptureStateCleanUp)) {
			if (!MarkRestart()) {
				return false;
			}
			m_captureState = CaptureStateCleanUp;
			m_markCleanup  = false;
		}
		if (m_markRotate && (m_captureState == CaptureStateNormal)) {
			if (!MarkRestart()) {
				return false;
			}
			m_captureState = CaptureStateRotate;
			m_markRotate       = false;
		}

		quint32 bytesRead;
		if (!ReadDriver(bytesRead)) {
			return false;
		}

		if (bytesRead) {
			const qint32 packetCount  = CountPackets(bytesRead);
			const qint64 bytesWritten = m_captureFile.write(m_captureData.data(), bytesRead);
			if (bytesWritten == -1) {
				return LogError(QString("Cannot write %L1 bytes to %2: %3").arg(bytesRead)
						.arg(m_captureFile.fileName(), m_captureFile.errorString()));
			}
			if (bytesRead != bytesWritten) {
				return LogError(QString("Only wrote %L1 of %L2 bytes to %3").arg(bytesWritten).arg(bytesRead)
						.arg(m_captureFile.fileName()));
			}
			if (!m_captureFile.flush()) {
				return LogError(QString("Cannot flush %1: %2").arg(m_captureFile.fileName(),m_captureFile.errorString()));
			}

			m_captureFileSize    += bytesWritten;
			m_packetCount += packetCount;
			if (m_parentPid.isEmpty()) {
				Log(QString("\rPackets: %1").arg(m_packetCount), false);
			} else {
				WriteCommand('P', QString::number(packetCount));
			}

			// Handle stop and rotate conditions
			if (
					(m_autoStopFileCount    && (m_captureFileCount   >= m_autoStopFileCount  )) ||
					(m_autoStopFileSize     && (m_captureFileSize    >= m_autoStopFileSize   )) ||
					(m_autoStopPacketCount  && (m_packetCount >= m_autoStopPacketCount)) ||
					(m_autoStopMilliseconds && ((QDateTime::currentMSecsSinceEpoch() - m_captureStart) > m_autoStopMilliseconds))) {
				m_markCleanup = true;
			} else if (
					(m_autoRotateFileSize     && (m_captureFileSize >= m_autoRotateFileSize)) ||
					(m_autoRotateMilliseconds && ((QDateTime::currentMSecsSinceEpoch() - m_captureStart) > m_autoRotateMilliseconds))) {
				m_markRotate = true;
			}
		} else { // No data to read
			switch (m_captureState) {
			case CaptureStateCleanUp:
#ifndef WIN32
				if (::ioctl(m_driverHandle, HEIO_GET_AT_HEAD) <= 0) {
					break;
				}
#endif // #ifdef WIN32
				m_captureState = CaptureStateDone;
				break;
			case CaptureStateDone:
				break;
			case CaptureStateNormal:
#ifdef WIN32
				::Sleep(500);
#else // #ifdef WIN32
				FD_ZERO(&readfds);
				FD_SET(m_driverHandle, &readfds);
				if (-1 == ::select(m_driverHandle+1, &readfds, NULL, NULL, NULL)) {
					if (errno == EINTR) {
						m_markCleanup = true;
					} else {
						return LogError("Cannot check for data from the driver", true);
					}
				}
#endif // #ifdef WIN32
				break;
			case CaptureStateRotate:
#ifndef WIN32
				if (::ioctl(m_driverHandle, HEIO_GET_AT_HEAD) <= 0) {
					break;
				}
#endif // #ifdef WIN32
				if (!OpenCaptureFile()) {
					return false;
				}
				m_captureState = CaptureStateNormal;
				break;
			}
		}
	}

	return true;
}