Example #1
0
//-----------------------------------------------------------------------------
// Purpose: called when a cvar value query is finished
//-----------------------------------------------------------------------------
void CSourcePython::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity,
	EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue )
{
	PythonLog(4, "Cvar query (cookie: %d, status: %d) - name: %s, value: %s", iCookie, eStatus, pCvarName, pCvarValue );
	unsigned int iEntityIndex;
	if (!IndexFromEdict(pPlayerEntity, iEntityIndex))
		return;

	CALL_LISTENERS(OnQueryCvarValueFinished, (int) iCookie, iEntityIndex, eStatus, pCvarName, pCvarValue);
}
void CUserMessageImplementation::send_message_internal()
{
	if (m_message != NULL  && m_message_index != -1)
	{
		engine->SendUserMessage(const_cast<MRecipientFilter&>(m_recipient_filter), m_message_index, *m_message);
	}
	else
	{
		PythonLog(1, "Could not send message '%s', invalid message name\n", m_message_name);
	}
}
Example #3
0
//-----------------------------------------------------------------------------
// Purpose: called when an event is fired
//-----------------------------------------------------------------------------
void CSourcePython::FireGameEvent( IGameEvent * event )
{
	const char * name = event->GetName();
	PythonLog(4, "CSourcePython::FireGameEvent: Got event \"%s\"", name );
}
Example #4
0
CPointer* CBinaryFile::FindSignature(object oSignature)
{
	unsigned char* sigstr = (unsigned char *) PyBytes_AsString(oSignature.ptr());
	if (!sigstr)
		BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Failed to read the given signature.");
	
	// Search for a cached signature
	PythonLog(4, "Searching for a cached signature...");
	for (std::list<Signature_t>::iterator iter=m_Signatures.begin(); iter != m_Signatures.end(); iter++)
	{
		Signature_t sig = *iter;
		if (strcmp((const char *) sig.m_szSignature, (const char *) sigstr) == 0)
		{
			PythonLog(4, "Found a cached signature!");
			return new CPointer(sig.m_ulAddr);
		}
	}
	
	PythonLog(4, "Could not find a cached signature. Searching in the binary...");

	// Search for a signature in the binary
	int iLength = len(oSignature);
	CPointer* pPtr = FindSignatureRaw(oSignature);

	// Found the signature?
	if (pPtr->IsValid())
	{
		PythonLog(4, "Found a signature in the binary!");

		// Add the signature to the cache
		Signature_t sig_t = {new unsigned char[iLength+1], pPtr->m_ulAddr};
		strcpy((char*) sig_t.m_szSignature, (char*) sigstr);
		m_Signatures.push_back(sig_t);

		// Return the result
		return pPtr;
	}

	delete pPtr;

	// Haven't found a match? Then seach for a hooked signature
	PythonLog(4, "Could not find the signature in the binary. Searching for a hooked signature...");

	// Check length of signature
	if (iLength <= 6)
		BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Signature is too short to search for a hooked signature.");

	// Create the hooked signature
	oSignature = import("binascii").attr("unhexlify")("E92A2A2A2A") + oSignature.slice(5, _);

	// Try to find the hooked signature
	pPtr = FindSignatureRaw(oSignature);

	// Couldn't find it?
	if (!pPtr->IsValid())
	{
		PythonLog(4, "Could not find a hooked signature.");
		delete pPtr;
	}
	// Yay, we found a match! Now, check if the signature is unique
	else
	{
		PythonLog(4, "Found a hooked signature! Checking if it's unique...");

		// Add iLength, so we start searching after the match
		CPointer new_ptr = CPointer(pPtr->m_ulAddr + iLength);

		// Got another match after the first one?
		CPointer* pNext = new_ptr.SearchBytes(oSignature, (m_ulAddr + m_ulSize) - new_ptr.m_ulAddr);
		bool bIsValid = pNext->IsValid();
		delete pNext;

		if (bIsValid)
			BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Found more than one hooked signatures. Please pass more bytes.");

		PythonLog(4, "Signature is unique!");

		// It's unique! So, add the original signature to the cache
		Signature_t sig_t = {new unsigned char[iLength+1], pPtr->m_ulAddr};
		strcpy((char*) sig_t.m_szSignature, (char*) sigstr);
		m_Signatures.push_back(sig_t);

		// Now, return the result
		return pPtr;
	}

	BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Could not find signature.");
	return new CPointer(); // To fix a warning. This will never get called.
}