Example #1
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Get a reading stream for the buffer
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<streamReader> buffer::getStreamReader()
{
	PUNTOEXE_FUNCTION_START(L"buffer::getStreamReader");

	// Lock the object
	///////////////////////////////////////////////////////////
	lockObject lockAccess(this);

	// If the object must be loaded from the original stream,
	//  then return the original stream
	///////////////////////////////////////////////////////////
	if(m_originalStream != 0 && (m_memory == 0 || m_memory->empty()) )
	{
		ptr<streamReader> reader(new streamReader(m_originalStream, m_originalBufferPosition, m_originalBufferLength));
		return reader;
	}


	// Build a stream from the buffer's memory
	///////////////////////////////////////////////////////////
	ptr<streamReader> reader;
	ptr<handlers::dataHandlerRaw> tempHandlerRaw = getDataHandlerRaw(false);
	if(tempHandlerRaw != 0)
	{
		ptr<baseStream> localStream(new bufferStream(tempHandlerRaw));
		reader = ptr<streamReader>(new streamReader(localStream));
	}

	return reader;

	PUNTOEXE_FUNCTION_END();
}
Example #2
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
// Return the buffer's size in bytes
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
imbxUint32 buffer::getBufferSizeBytes()
{
	PUNTOEXE_FUNCTION_START(L"buffer::getBufferSizeBytes");

	// Lock the object
	///////////////////////////////////////////////////////////
	lockObject lockAccess(this);

	ptr<memory> localMemory(m_memory);

	// The buffer has not been loaded yet
	///////////////////////////////////////////////////////////
	if(m_originalStream != 0 && (m_memory == 0 || m_memory->empty()) )
	{
		return m_originalBufferLength;
	}

	// The buffer has no memory
	///////////////////////////////////////////////////////////
	if(m_memory == 0)
	{
		return 0;
	}

	// Return the memory's size
	///////////////////////////////////////////////////////////
	return m_memory->size();

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Returns the numbero of allocated channels
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
imbxUint32 image::getChannelsNumber()
{
	PUNTOEXE_FUNCTION_START(L"image::getChannelsNumber");

	lockObject lockAccess(this);
	return m_channelsNumber;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Returns the colorspace
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
std::wstring image::getColorSpace()
{
	PUNTOEXE_FUNCTION_START(L"image::getColorSpace");

	lockObject lockAccess(this);
	return m_colorSpace;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Return the high bit
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
imbxUint32 image::getHighBit()
{
	PUNTOEXE_FUNCTION_START(L"image::getHighBit");

	lockObject lockAccess(this);
	return m_highBit;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Return the bit depth
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
image::bitDepth image::getDepth()
{
	PUNTOEXE_FUNCTION_START(L"image::getDepth");

	lockObject lockAccess(this);
	return m_imageDepth;

	PUNTOEXE_FUNCTION_END();
}
void image::setPalette(ptr<palette> imagePalette)
{
	PUNTOEXE_FUNCTION_START(L"image::getPalette");

	lockObject lockAccess(this);

	m_palette = imagePalette;

	PUNTOEXE_FUNCTION_END();
}
ptr<palette> image::getPalette()
{
	PUNTOEXE_FUNCTION_START(L"image::getPalette");

	lockObject lockAccess(this);

	return m_palette;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Set the depth
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void image::setHighBit(imbxUint32 highBit)
{
	PUNTOEXE_FUNCTION_START(L"image::setHighBit");

	lockObject lockAccess(this);

	m_highBit = highBit;

	PUNTOEXE_FUNCTION_END();
}
Example #10
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Set the charsets used by the buffer
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void buffer::setCharsetsList(charsetsList::tCharsetsList* pCharsetsList)
{
	PUNTOEXE_FUNCTION_START(L"buffer::setCharsetsList");

	lockObject lockAccess(this);

	m_charsetsList.clear();
	charsetsList::updateCharsets(pCharsetsList, &m_charsetsList);

	PUNTOEXE_FUNCTION_END();
}
Example #11
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Destructor
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
transaction::~transaction()
{
	PUNTOEXE_FUNCTION_START(L"transaction::~transaction");

	if(m_bCommit)
	{
		// We have to commit the changes
		///////////////////////////////////////////////////////////
		try
		{
			// Lock all the buffers involved in the commit
			///////////////////////////////////////////////////////////
			lockMultipleObjects::tObjectsList objectsList;
			for(tHandlersList::iterator findBuffers = m_transactionHandlers.begin(); findBuffers != m_transactionHandlers.end(); ++findBuffers)
			{
				objectsList.push_back(findBuffers->second->m_buffer);
			}
			lockMultipleObjects lockAccess(&objectsList);

			// Copy the data back to the buffers
			///////////////////////////////////////////////////////////
			for(tHandlersList::iterator scanHandlers = m_transactionHandlers.begin(); scanHandlers != m_transactionHandlers.end(); ++scanHandlers)
			{
				scanHandlers->second->copyBack();
			}

			// Commit the changes
			///////////////////////////////////////////////////////////
			for(tHandlersList::iterator scanCommits = m_transactionHandlers.begin(); scanCommits != m_transactionHandlers.end(); ++scanCommits)
			{
				scanCommits->second->commit();
			}

			// Remove all the data handlers
			///////////////////////////////////////////////////////////
			m_transactionHandlers.clear();
		}
		catch(...)
		{
			// The commit failed.
			// Abort the modifications and rethrow the exception
			///////////////////////////////////////////////////////////
			abort();
			transactionsManager::removeTransaction(m_threadId);
			PUNTOEXE_RETHROW("Commit failed");
		}
	}

	transactionsManager::removeTransaction(m_threadId);

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Returns the image's size in pixels
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void image::getSize(imbxUint32* pSizeX, imbxUint32* pSizeY)
{
	PUNTOEXE_FUNCTION_START(L"image::getSize");

	lockObject lockAccess(this);

	if(pSizeX)
		*pSizeX=m_sizeX;

	if(pSizeY)
		*pSizeY=m_sizeY;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Returns the image's size in millimeters
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void image::getSizeMm(double* pSizeMmX, double* pSizeMmY)
{
	PUNTOEXE_FUNCTION_START(L"image::getSizeMm");

	lockObject lockAccess(this);

	if(pSizeMmX)
		*pSizeMmX=m_sizeMmX;

	if(pSizeMmY)
		*pSizeMmY=m_sizeMmY;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Set the image's size in millimeters
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void image::setSizeMm(const double sizeMmX, const double sizeMmY)
{
	PUNTOEXE_FUNCTION_START(L"image::setSizeMm");

	lockObject lockAccess(this);

	if(sizeMmX)
		m_sizeMmX=sizeMmX;

	if(sizeMmY)
		m_sizeMmY=sizeMmY;

	PUNTOEXE_FUNCTION_END();
}
Example #15
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Register a codec
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void codecFactory::registerCodec(ptr<codec> pCodec)
{
	PUNTOEXE_FUNCTION_START(L"codecFactory::registerCodec");

	if(pCodec == 0)
	{
		return;
	}

	lockObject lockAccess(this);

	m_codecsList.push_back(pCodec);

	PUNTOEXE_FUNCTION_END();
}
Example #16
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Get a data handler (raw or normal) for the requested tag
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<handlers::dataHandler> dataGroup::getDataHandler(std::uint16_t tagId, std::uint32_t bufferId, bool bWrite, std::string defaultType)
{
	PUNTOEXE_FUNCTION_START(L"dataGroup::getDataHandler");

	lockObject lockAccess(this);

	ptr<data> tag=getTag(tagId, bWrite);

	if(tag == 0)
	{
		return ptr<handlers::dataHandler>(0);
	}

	return tag->getDataHandler(bufferId, bWrite, defaultType);

	PUNTOEXE_FUNCTION_END();
}
Example #17
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Return a raw data handler for the specified tag
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<handlers::dataHandlerRaw> dataGroup::getDataHandlerRaw(imbxUint16 tagId, imbxUint32 bufferId, bool bWrite, std::string defaultType)
{
	PUNTOEXE_FUNCTION_START(L"dataGroup::getDataHandlerRaw");

	lockObject lockAccess(this);

	ptr<data> tag=getTag(tagId, bWrite);

	if(tag == 0)
	{
		ptr<handlers::dataHandlerRaw> emptyDataHandler;
		return emptyDataHandler;
	}

	return tag->getDataHandlerRaw(bufferId, bWrite, defaultType);

	PUNTOEXE_FUNCTION_END();
}
Example #18
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Get a stream writer that works on the specified tag
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<streamWriter> dataGroup::getStreamWriter(std::uint16_t tagId, std::uint32_t bufferId, std::string dataType /* = "" */)
{
	PUNTOEXE_FUNCTION_START(L"dataGroup::getStream");

	lockObject lockAccess(this);

	ptr<streamWriter> returnStream;

	ptr<data> tag=getTag(tagId, true);

	if(tag != 0)
	{
		returnStream = tag->getStreamWriter(bufferId, dataType);
	}

	return returnStream;

	PUNTOEXE_FUNCTION_END();
}
Example #19
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Get a stream reader that works on the specified tag
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<streamReader> dataGroup::getStreamReader(std::uint16_t tagId, std::uint32_t bufferId)
{
	PUNTOEXE_FUNCTION_START(L"dataGroup::getStreamReader");

	lockObject lockAccess(this);

	ptr<streamReader> returnStream;

	ptr<data> tag=getTag(tagId, false);

	if(tag != 0)
	{
		returnStream = tag->getStreamReader(bufferId);
	}

	return returnStream;

	PUNTOEXE_FUNCTION_END();
}
Example #20
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Retrieve a codec that can handle the specified
//  transfer syntax
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<codec> codecFactory::getCodec(std::wstring transferSyntax)
{
	PUNTOEXE_FUNCTION_START(L"codecFactory::getCodec");

	ptr<codecFactory> pFactory(getCodecFactory());
	lockObject lockAccess(pFactory.get());

	for(std::list<ptr<codec> >::iterator scanCodecs=pFactory->m_codecsList.begin(); scanCodecs!=pFactory->m_codecsList.end(); ++scanCodecs)
	{
		if((*scanCodecs)->canHandleTransferSyntax(transferSyntax))
		{
			return (*scanCodecs)->createCodec();
		}
	}

	ptr<codec> emptyCodec;
	return emptyCodec;

	PUNTOEXE_FUNCTION_END();
}
Example #21
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Load the data from the specified stream and build a
//  dicomSet structure
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<dataSet> codecFactory::load(ptr<streamReader> pStream, std::uint32_t maxSizeBufferLoad /* = 0xffffffff */)
{
	PUNTOEXE_FUNCTION_START(L"codecFactory::load");

	// Copy the list of codecs in a local list so we don't have
	//  to lock the object for a long time
	///////////////////////////////////////////////////////////
	std::list<ptr<codec> > localCodecsList;
	ptr<codecFactory> pFactory(getCodecFactory());
	{
		lockObject lockAccess(pFactory.get());
		for(std::list<ptr<codec> >::iterator scanCodecs=pFactory->m_codecsList.begin(); scanCodecs!=pFactory->m_codecsList.end(); ++scanCodecs)
		{
			ptr<codec> copyCodec((*scanCodecs)->createCodec());
			localCodecsList.push_back(copyCodec);
		}
	}

	ptr<dataSet> pDataSet;
	for(std::list<ptr<codec> >::iterator scanCodecs=localCodecsList.begin(); scanCodecs != localCodecsList.end() && pDataSet == 0; ++scanCodecs)
	{
		try
		{
			return (*scanCodecs)->read(pStream, maxSizeBufferLoad);
		}
		catch(codecExceptionWrongFormat& /* e */)
		{
			exceptionsManager::getMessage(); // Reset the messages stack
			continue;
		}
	}

	if(pDataSet == 0)
	{
		PUNTOEXE_THROW(codecExceptionWrongFormat, "none of the codecs recognized the file format");
	}

	return pDataSet;

	PUNTOEXE_FUNCTION_END();
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Retrieve an handler to the image's buffer.
// The image's components are interleaved.
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<handlers::dataHandlerNumericBase> image::getDataHandler(const bool bWrite, imbxUint32* pRowSize, imbxUint32* pChannelPixelSize, imbxUint32* pChannelsNumber)
{
	PUNTOEXE_FUNCTION_START(L"image::getDataHandler");

	lockObject lockAccess(this);

	if(m_buffer == 0)
	{
		return ptr<handlers::dataHandlerNumericBase>(0);
	}

	*pRowSize=m_rowLength;
	*pChannelPixelSize=m_channelPixelSize;
	*pChannelsNumber=m_channelsNumber;

	ptr<handlers::dataHandler> imageHandler(m_buffer->getDataHandler(bWrite, m_sizeX * m_sizeY * m_channelsNumber));

	return ptr<handlers::dataHandlerNumericBase>(dynamic_cast<handlers::dataHandlerNumericBase*>(imageHandler.get()) );

	PUNTOEXE_FUNCTION_END();
}
Example #23
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Get a writing stream for the buffer
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<streamWriter> buffer::getStreamWriter()
{
	PUNTOEXE_FUNCTION_START(L"buffer::getStreamReader");

	// Lock the object
	///////////////////////////////////////////////////////////
	lockObject lockAccess(this);

	// Build a stream from the buffer's memory
	///////////////////////////////////////////////////////////
	ptr<streamWriter> writer;
	ptr<handlers::dataHandlerRaw> tempHandlerRaw = getDataHandlerRaw(true);
	if(tempHandlerRaw != 0)
	{
		ptr<baseStream> localStream(new bufferStream(tempHandlerRaw));
		writer = ptr<streamWriter>(new streamWriter(localStream, tempHandlerRaw->getSize()));
	}

	return writer;

	PUNTOEXE_FUNCTION_END();
}
Example #24
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
// Commit the changes made by copyBack
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void buffer::commit()
{
	PUNTOEXE_FUNCTION_START(L"buffer::commit");

	// Lock the object
	///////////////////////////////////////////////////////////
	lockObject lockAccess(this);

	// Commit the memory buffer
	///////////////////////////////////////////////////////////
	m_memory = m_temporaryMemory;
	m_temporaryMemory.release();

	// Commit the buffer type
	///////////////////////////////////////////////////////////
	m_bufferType = m_temporaryBufferType;
	m_temporaryBufferType.clear();

	// Commit the charsets
	///////////////////////////////////////////////////////////
	m_charsetsList.clear();
	charsetsList::copyCharsets(&m_temporaryCharsets, &m_charsetsList);
	m_temporaryCharsets.clear();

	// Increase the buffer's version
	///////////////////////////////////////////////////////////
	++m_version;

	// The buffer has been updated and the original stream
	//  is still storing the old version. We don't need
	//  the original stream anymore, then release it.
	///////////////////////////////////////////////////////////
	ptr<baseStream> emptyBaseStream;
	m_originalStream = emptyBaseStream;

	PUNTOEXE_FUNCTION_END();
}
Example #25
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
// Disconnect an handler from this buffer and copy the
//  data from the handler back to the buffer
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void buffer::copyBack(handlers::dataHandler* pDisconnectHandler)
{
	PUNTOEXE_FUNCTION_START(L"buffer::copyBack");

	// Lock the object
	///////////////////////////////////////////////////////////
	lockObject lockAccess(this);

	// Get the buffer's content
	///////////////////////////////////////////////////////////
	m_temporaryMemory = ptr<memory>(new memory);
	pDisconnectHandler->buildBuffer(m_temporaryMemory);

	// Update the charsets
	///////////////////////////////////////////////////////////
	m_temporaryCharsets.clear();
	charsetsList::copyCharsets(&m_charsetsList, &m_temporaryCharsets);
	charsetsList::tCharsetsList charsets;
	pDisconnectHandler->getCharsetsList(&charsets);
	charsetsList::updateCharsets(&charsets, &m_temporaryCharsets);

	// The buffer's size must be an even number
	///////////////////////////////////////////////////////////
	imbxUint32 memorySize = m_temporaryMemory->size();
	if((memorySize & 0x1) != 0)
	{
		m_temporaryMemory->resize(++memorySize);
		*(m_temporaryMemory->data() + (memorySize - 1)) = pDisconnectHandler->getPaddingByte();
	}

	// Adjust the buffer's type
	///////////////////////////////////////////////////////////
	m_temporaryBufferType = pDisconnectHandler->m_bufferType;

	PUNTOEXE_FUNCTION_END();
}
Example #26
0
void hook(void){
	static BOOL hooked=FALSE;
	lockAccess(_getpid());
#if HOOK_ENABLED
	if(!hooked){
		//-----------------------------
		//File operation functions (11)
		//-----------------------------
		AddRedirect_LOG("kernel32.dll","CopyFileExA",MyCopyFileEx);
		AddRedirect_LOG("kernel32.dll","CopyFileExW",MyCopyFileExW);
		AddRedirect_LOG("kernel32.dll","CopyFileA",MyCopyFile);
		AddRedirect_LOG("kernel32.dll","CopyFileW",MyCopyFileW);
		AddRedirect_LOG("kernel32.dll","CreateFileA",MyCreateFile);
		AddRedirect_LOG("kernel32.dll","CreateFileW",MyCreateFileW);
		AddRedirect_LOG("kernel32.dll","DeleteFileW",MyDeleteFileW);
		AddRedirect_LOG("kernel32.dll","DeleteFileA",MyDeleteFile);
		AddRedirect_LOG("kernel32.dll","MoveFileExA",MyMoveFileEx);
		AddRedirect_LOG("kernel32.dll","MoveFileExW",MyMoveFileExW);
		AddRedirect_LOG("kernel32.dll","MoveFileA",MyMoveFile);
		AddRedirect_LOG("kernel32.dll","MoveFileW",MyMoveFileW);

		AddRedirect_LOG("kernel32.dll","Sleep",MySleep);
		//-----------------------
		//Registry functions (14)
		//-----------------------
		
		AddRedirect_LOG("advapi32.dll","RegCreateKeyExA",MyRegCreateKeyEx);
		AddRedirect_LOG("advapi32.dll","RegCreateKeyExW",MyRegCreateKeyExW);
		AddRedirect_LOG("advapi32.dll","RegCreateKeyA",MyRegCreateKey);
		AddRedirect_LOG("advapi32.dll","RegCreateKeyW",MyRegCreateKeyW);
		AddRedirect_LOG("advapi32.dll","RegOpenKeyExW",MyRegOpenKeyExW);
		AddRedirect_LOG("advapi32.dll","RegOpenKeyExA",MyRegOpenKeyExA);
		AddRedirect_LOG("advapi32.dll","RegOpenKeyW",MyRegOpenKeyW);
		AddRedirect_LOG("advapi32.dll","RegOpenKeyA",MyRegOpenKey);
		AddRedirect_LOG("advapi32.dll","RegQueryValueExA",MyRegQueryValueExA);
		AddRedirect_LOG("advapi32.dll","RegQueryValueExW",MyRegQueryValueExW);
		AddRedirect_LOG("advapi32.dll","RegSetValueExA",MyRegSetValueEx);
		AddRedirect_LOG("advapi32.dll","RegSetValueExW",MyRegSetValueExW);
		AddRedirect_LOG("advapi32.dll","RegConnectRegistryA",MyRegConnectRegistry);
		AddRedirect_LOG("advapi32.dll","RegConnectRegistryW",MyRegConnectRegistryW);
		
		//------------------------
		//networking functions (7)
		//------------------------
		AddRedirect_LOG("ws2_32.dll","connect",Myconnect);
		AddRedirect_LOG("ws2_32.dll","getaddrinfo",Mygetaddrinfo);
		AddRedirect_LOG("ws2_32.dll","GetAddrInfoW",MyGetAddrInfoW);
		AddRedirect_LOG("Wininet.dll","InternetConnectA",MyInternetConnect);
		AddRedirect_LOG("Wininet.dll","InternetConnectW",MyInternetConnectW);
		AddRedirect_LOG("Wininet.dll","HttpOpenRequestA",MyHttpOpenRequest);
		AddRedirect_LOG("Wininet.dll","HttpOpenRequestW",MyHttpOpenRequestW);
		//---------------------
		//Process functions (9)
		//---------------------
		AddRedirect_LOG("kernel32.dll","OpenProcess",MyOpenProcess);
		AddRedirect_LOG("kernel32.dll","CreateProcessA",MyCreateProcess);
		AddRedirect_LOG("kernel32.dll","CreateProcessW",MyCreateProcessW);
		AddRedirect_LOG("kernel32.dll","ResumeThread",MyResumeThread);
		AddRedirect_LOG("kernel32.dll","WriteProcessMemory",MyWriteProcessMemory);
		AddRedirect_LOG("kernel32.dll","CreateRemoteThread",MyCreateRemoteThread);
		AddRedirect_LOG("kernel32.dll","CreateProcessInternalA",MyCreateProcessInternal);
		AddRedirect_LOG("advapi32.dll","CreateProcessAsUserA",MyCreateProcessAsUser);
		AddRedirect_LOG("advapi32.dll","CreateProcessAsUserW",MyCreateProcessAsUserW);
		//---------------------
		//loadlib functions (4)
		//---------------------
		AddRedirect_LOG("kernel32.dll","GetModuleHandleA",MyGetModuleHandle);
		AddRedirect_LOG("kernel32.dll","GetModuleHandleW",MyGetModuleHandleW);
		AddRedirect_LOG("kernel32.dll","GetProcAddress",MyGetProcAddress);
		AddRedirect_LOG("kernel32.dll","LoadLibraryA",MyLoadLibrary);
		AddRedirect_LOG("kernel32.dll","LoadLibraryW",MyLoadLibraryW);
	}else{
		//---------------------
		//Process functions (9)
		//---------------------
		HookAgain("OpenProcess");
		HookAgain("CreateProcessA");
		HookAgain("CreateProcessW");
		HookAgain("WriteProcessMemory");
		HookAgain("CreateRemoteThread");
		HookAgain("ResumeThread");
		HookAgain("CreateProcessInternalA");
		HookAgain("CreateProcessAsUserA");
		HookAgain("CreateProcessAsUserW");
		//-----------------------------
		//File operation functions (10)
		//-----------------------------
		HookAgain("CopyFileA");
		HookAgain("CopyFileW");
		HookAgain("CopyFileExA");
		HookAgain("CopyFileExW");
		HookAgain("CreateFileA");
		HookAgain("CreateFileW");
		HookAgain("DeleteFileA");
		HookAgain("DeleteFileW");
		HookAgain("MoveFileExA");
		HookAgain("MoveFileExW");
		HookAgain("MoveFileA");
		HookAgain("MoveFileW");

		HookAgain("Sleep");
		//-----------------------
		//Registry functions (14)
		//-----------------------
		
		HookAgain("RegCreateKeyExA");
		HookAgain("RegCreateKeyExW");
		HookAgain("RegCreateKeyA");
		HookAgain("RegCreateKeyW");
		HookAgain("RegOpenKeyExW");
		HookAgain("RegOpenKeyExA");
		HookAgain("RegOpenKeyW");
		HookAgain("RegOpenKeyA");
		HookAgain("RegQueryValueExA");
		HookAgain("RegQueryValueExW");
		HookAgain("RegSetValueExA");
		HookAgain("RegSetValueExW");
		HookAgain("RegConnectRegistryA");
		HookAgain("RegConnectRegistryW");
		//------------------------
		//networking functions (7)
		//------------------------
		HookAgain("connect");
		HookAgain("getaddrinfo");
		HookAgain("GetAddrInfoW");
		HookAgain("InternetConnectA");
		HookAgain("InternetConnectW");
		HookAgain("HttpOpenRequestA");
		HookAgain("HttpOpenRequestW");
		//---------------------
		//loadlib functions (4)
		//---------------------
		HookAgain("GetModuleHandleA");
		HookAgain("GetModuleHandleW");
		HookAgain("GetProcAddress");
		HookAgain("LoadLibraryA");
		HookAgain("LoadLibraryW");
	}
#endif	
	printf("[hooker] Hooked\n");
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Create an image with the specified size, colorspace and
//  bit depth
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<handlers::dataHandlerNumericBase> image::create(
						const imbxUint32 sizeX, 
						const imbxUint32 sizeY, 
						const bitDepth depth, 
						std::wstring inputColorSpace, 
						const imbxUint8 highBit)
{
	PUNTOEXE_FUNCTION_START(L"image::create");

	lockObject lockAccess(this);

	if(sizeX == 0 || sizeY == 0)
	{
		PUNTOEXE_THROW(imageExceptionInvalidSize, "An invalid image's size has been specified");
	}

	// Normalize the color space (remove _420 & _422 and
	//  make it uppercase).
	///////////////////////////////////////////////////////////
	m_colorSpace=transforms::colorTransforms::colorTransformsFactory::normalizeColorSpace(inputColorSpace);

	// Find the number of channels to allocate
	///////////////////////////////////////////////////////////
	m_channelsNumber = transforms::colorTransforms::colorTransformsFactory::getNumberOfChannels(inputColorSpace);
	if(m_channelsNumber == 0)
	{
		PUNTOEXE_THROW(imageExceptionUnknownColorSpace, "Cannot recognize the specified color space");
	}

	// Find the datatype to use to allocate the
	//  buffer (datatypes are in Dicom standard, plus SB
	//  for signed bytes).
	///////////////////////////////////////////////////////////
	m_channelPixelSize = 0;
	imbxUint8 defaultHighBit = 0;

	std::string bufferDataType;

	switch(depth)
	{
	case depthU8:
		bufferDataType = "OB";
		defaultHighBit=7;
		break;
	case depthS8:
		bufferDataType = "SB";
		defaultHighBit=7;
		break;
	case depthU16:
		bufferDataType = "US";
		defaultHighBit=15;
		break;
	case depthS16:
		bufferDataType = "SS";
		defaultHighBit=15;
		break;
	case depthU32:
		bufferDataType = "UL";
		defaultHighBit=31;
		break;
	case depthS32:
		bufferDataType = "SL";
		defaultHighBit=31;
		break;
	default:
		PUNTOEXE_THROW(imageExceptionUnknownDepth, "Unknown depth");
	}

	// Adjust the high bit value
	///////////////////////////////////////////////////////////
	if(highBit == 0 || highBit>defaultHighBit)
		m_highBit=defaultHighBit;
	else
		m_highBit=highBit;

	// If a valid buffer with the same data type is already
	//  allocated then use it.
	///////////////////////////////////////////////////////////
	if(m_buffer == 0 || !(m_buffer->isReferencedOnce()) )
	{
		ptr<buffer> tempBuffer(new buffer(this, bufferDataType));
		m_buffer = tempBuffer;
	}

	m_sizeX = m_sizeY = 0;
	
	ptr<handlers::dataHandler> imageHandler(m_buffer->getDataHandler(true, sizeX * sizeY * (imbxUint32)m_channelsNumber) );
	if(imageHandler != 0)
	{
		m_rowLength = m_channelsNumber*sizeX;
		
		imageHandler->setSize(m_rowLength*sizeY);
		m_channelPixelSize = imageHandler->getUnitSize();

		// Set the attributes
		///////////////////////////////////////////////////////////
		m_imageDepth=depth;
		m_sizeX=sizeX;
		m_sizeY=sizeY;
	}

	return ptr<handlers::dataHandlerNumericBase>(dynamic_cast<handlers::dataHandlerNumericBase*>(imageHandler.get()) );

	PUNTOEXE_FUNCTION_END();
}
Example #28
0
void BasicSubmarine::UI::updateUI(double dt, SubWindow& subWindow)
{
    auto vessel = mVessel.lock();
    if (vessel)
    {
        auto vesselPosition = vessel->getState().getLocation();

        double lat = vesselPosition.getLatitude();
        double lng = vesselPosition.getLongitude();
        double alt = vesselPosition.getAltitude();

        std::stringstream locationText;
        locationText << "Position and depth: " << std::endl;
        locationText << std::setprecision(6) << std::fixed << lat << " deg" << std::endl << std::setprecision(6) << std::fixed << lng << " deg" << std::endl;
        locationText << "Depth: " << std::setprecision(2) << alt << " m";

        mLocation->SetText(locationText.str());

        auto ocean = Ocean::getOcean();
        ocean->lockAccess();

        vessel->setHeading(mHeading->GetValue());
        vessel->setPitch(mPitch->GetValue());
        vessel->setVelocity(mVelocity->GetValue() * 0.514444444); //Convert to m/s.

        ocean->unlockAccess();

        BroadbandState state(0.3f, 0.3f, 5.0f);

        std::shared_ptr<GameManager> gameManager = GameManager::getCurrent().lock();
        BOOST_ASSERT_MSG(gameManager, "GameManager null");
        auto eigenrayMap = gameManager->getUsmlManager()->getEigenrayMap();

        //Iterate through all contacts we can hear.
        for (auto& contactKV : eigenrayMap)
        {
            //If the azimuth angle is NaN, that means that there were no eigenrays for this contact.
            if (!isnan(contactKV.second.source_az))
            {
                //Average the intensities across all frequencies.
                //TODO: don't weight them all the same, and figure out what the numbers USML gives us even mean.
                double intensitySum = 0;
                for (auto intensity : contactKV.second.intensity)
                {
                    if (intensity > 299.9999f)
                        continue; //TODO: What causes this?
                    intensitySum += intensity;
                }
                double intensityAverage = intensitySum / contactKV.second.intensity.size();

                float adjustedIntensity = (float)(intensityAverage / 300);

                state.pushContact(BroadbandState::BroadbandContact((float)contactKV.second.source_az, adjustedIntensity, 5.0f));
            }
        }

        mWaterfall->SetState(state);
    }
    else
    {
        subWindow.switchToScreen<MainMenu>();
    }
}
Example #29
0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Create a data handler and connect it to the buffer
// (raw or normal)
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
ptr<handlers::dataHandler> buffer::getDataHandler(bool bWrite, bool bRaw, imbxUint32 size)
{
	PUNTOEXE_FUNCTION_START(L"buffer::getDataHandler");

	// Lock the object
	///////////////////////////////////////////////////////////
	lockObject lockAccess(this);

	ptr<memory> localMemory(m_memory);

	// If the object must be loaded from the original stream,
	//  then load it...
	///////////////////////////////////////////////////////////
	if(m_originalStream != 0 && (localMemory == 0 || localMemory->empty()) )
	{
		localMemory = ptr<memory>(memoryPool::getMemoryPool()->getMemory(m_originalBufferLength));
		if(m_originalBufferLength != 0)
		{
			ptr<streamReader> reader(new streamReader(m_originalStream, m_originalBufferPosition, m_originalBufferLength));
			std::vector<imbxUint8> localBuffer;
			localBuffer.resize(m_originalBufferLength);
			reader->read(&localBuffer[0], m_originalBufferLength);
			if(m_originalWordLength != 0)
			{
				reader->adjustEndian(&localBuffer[0], m_originalWordLength, m_originalEndianType, m_originalBufferLength/m_originalWordLength);
			}
			localMemory->assign(&localBuffer[0], m_originalBufferLength);
		}
	}

	// Reset the pointer to the data handler
	///////////////////////////////////////////////////////////
	ptr<handlers::dataHandler> handler;

	// Allocate a raw data handler if bRaw==true
	///////////////////////////////////////////////////////////
	if(bRaw)
	{
		ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerRaw);
		handler = tempHandler;
	}
	else
	{
		// Retrieve an Application entity handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="AE")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringAE);
			handler = tempHandler;
		}

		// Retrieve an Age string data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="AS")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringAS);
			handler = tempHandler;
		}

		// Retrieve a Code string data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="CS")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringCS);
			handler = tempHandler;
		}

		// Retrieve a Decimal string data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="DS")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringDS);
			handler = tempHandler;
		}

		// Retrieve an Integer string data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="IS")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringIS);
			handler = tempHandler;
		}

		// Retrieve a Long string data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="LO")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringLO);
			handler = tempHandler;
		}

		// Retrieve a Long text data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="LT")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringLT);
			handler = tempHandler;
		}

		// Retrieve a Person Name data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="PN")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringPN);
			handler = tempHandler;
		}

		// Retrieve a Short string data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="SH")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringSH);
			handler = tempHandler;
		}

		// Retrieve a Short text data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="ST")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringST);
			handler = tempHandler;
		}

		// Retrieve an Unique Identifier data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="UI")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringUI);
			handler = tempHandler;
		}

		// Retrieve an Unlimited text data handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="UT")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerStringUT);
			handler = tempHandler;
		}

		// Retrieve an object handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="OB")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxUint8>);
			handler = tempHandler;
		}

		// Retrieve a signed-byte object handler.
		// Non standard: used by the images handler.
		///////////////////////////////////////////////////////////
		if(m_bufferType=="SB")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxInt8>);
			handler = tempHandler;
		}

		// Retrieve an unknown object handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="UN")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxUint8>);
			handler = tempHandler;
		}

		// Retrieve a WORD handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="OW")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxUint16>);
			handler = tempHandler;
		}

		// Retrieve a WORD handler (AT)
		///////////////////////////////////////////////////////////
		if(m_bufferType=="AT")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxUint16>);
			handler = tempHandler;
		}

		// Retrieve a float handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="FL")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<float>);
			handler = tempHandler;
		}

		// Retrieve a double float handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="FD")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<double>);
			handler = tempHandler;
		}

		// Retrieve a signed long handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="SL")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxInt32>);
			handler = tempHandler;
		}

		// Retrieve a signed short handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="SS")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxInt16>);
			handler = tempHandler;
		}

		// Retrieve an unsigned long handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="UL")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxUint32>);
			handler = tempHandler;
		}

		// Retrieve an unsigned short handler
		///////////////////////////////////////////////////////////
		if(m_bufferType=="US")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerNumeric<imbxUint16>);
			handler = tempHandler;
		}

		// Retrieve date
		///////////////////////////////////////////////////////////
		if(m_bufferType=="DA")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerDate);
			handler = tempHandler;
		}

		// Retrieve date-time
		///////////////////////////////////////////////////////////
		if(m_bufferType=="DT")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerDateTime);
			handler = tempHandler;
		}

		// Retrieve time
		///////////////////////////////////////////////////////////
		if(m_bufferType=="TM")
		{
			ptr<handlers::dataHandler> tempHandler(new handlers::dataHandlerTime);
			handler = tempHandler;
		}

	} // check bRaw

	// If an error occurred during the data handler creation,
	//  then throw an exception
	///////////////////////////////////////////////////////////
	if(handler == 0)
	{
		PUNTOEXE_THROW(bufferExceptionUnknownType, "Unknown data type requested");
	}

	//  Connect the handler to this buffer
	///////////////////////////////////////////////////////////
	if(localMemory == 0)
	{
		localMemory = ptr<memory>(new memory);
	}
	ptr<memory> parseMemory(localMemory);

	// Set the handler's attributes
	///////////////////////////////////////////////////////////
	if(bWrite)
	{
		ptr<buffer> tempBuffer(this);
		handler->m_buffer = tempBuffer;

		imbxUint32 actualMemorySize = localMemory->size();
		imbxUint32 newMemorySize = actualMemorySize;
		if(newMemorySize == 0)
		{
			newMemorySize = size * handler->getUnitSize();
		}
		ptr<memory> newMemoryBuffer(memoryPool::getMemoryPool()->getMemory(newMemorySize));
		if(actualMemorySize != 0)
		{
			newMemoryBuffer->copyFrom(localMemory);
		}
		parseMemory = newMemoryBuffer;

		// Add writing handlers to the current transaction
		///////////////////////////////////////////////////////////
		transactionsManager::addHandlerToTransaction(handler);
	}

	handler->m_bufferType = m_bufferType;
	handler->setCharsetsList(&m_charsetsList);
	handler->parseBuffer(parseMemory);

	// Rewind the data pointer
	///////////////////////////////////////////////////////////
	if(handler->getSize() != 0)
	{
		handler->setPointer(0);
	}

	// Return the allocated handler
	///////////////////////////////////////////////////////////
	return handler;

	PUNTOEXE_FUNCTION_END();
}