Ejemplo n.º 1
0
CPointer CObjects::Get(char* szObjectName)
{
	CBaseObject*	pvObject;
	CPointer		pObject;

	pvObject = GetFromMemory(szObjectName);
	if (pvObject)
	{
		pObject.AssignObject(pvObject);
		return pObject;
	}

	pvObject = GetFromDatabase(szObjectName);
	if (pvObject)
	{
		pObject.AssignObject(pvObject);
		return pObject;
	}

	pvObject = GetFromSources(szObjectName);
	if (pvObject)
	{
		pObject.AssignObject(pvObject);
		return pObject;
	}

	return Null();
}
Ejemplo n.º 2
0
void CKadHandler::HandleNodeRes(const CVariant& NodeRes, CKadNode* pNode, CComChannel* pChannel)
{
	if(GetParent<CKademlia>()->Cfg()->GetBool("DebugRT"))
		LogLine(LOG_DEBUG, L"Recived 'Node Response' from %s", pNode->GetID().ToHex().c_str());

	CVariant List = NodeRes["LIST"];
	if(List.Count() > (uint32)GetParent<CKademlia>()->Cfg()->GetInt("NodeReqCount"))
		throw CException(LOG_ERROR, L"Node returned more nodes than requested (spam)");
	
	SKadData* pData = pChannel->GetData<SKadData>();
	// Note: if pData->pLookup is NULL this was just a bootstrap request

	NodeMap Nodes;
	for(uint32 i = 0; i<List.Count(); i++)
	{
		CPointer<CKadNode> pNewNode = new CKadNode(GetParent<CKademlia>()->Root());
		pNewNode->Load(List.At(i));
		if(GetParent<CKademlia>()->Root()->AddNode(pNewNode) && pData->pLookup)
		{
			CUInt128 uDistance = pData->pLookup->GetID() ^ pNewNode->GetID();
			Nodes.insert(NodeMap::value_type(uDistance, pNewNode));
		}
	}

	if(pData->pLookup)
		GetParent<CKademlia>()->Manager()->AddNodes(pData->pLookup, pNode, pChannel, Nodes);
}
Ejemplo n.º 3
0
void TestObjectsFlushClearGetByName(void)
{
	CFileUtil						cFileUtil;
	CPointer						pObject;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/Dehollowfication");

	ObjectsInit("Output/Dehollowfication");
	SetupObjectsConstructors();

	pRoot = ORoot();
	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	pRoot->Add(pDouble);
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	pObject = gcObjects.Get(3);
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(3, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumDatabaseNames());

	pObject = gcObjects.Get("Double");
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	ObjectsKill();
}
Ejemplo n.º 4
0
CPointer CObjects::TestGetFromMemory(OIndex oi)
{
	CPointer	pObject;

	pObject.AssignObject(GetFromMemory(oi));
	return pObject;
}
Ejemplo n.º 5
0
CPointer CObjects::TestGetFromMemory(char* szName)
{
	CPointer	pObject;

	pObject.AssignObject(GetFromMemory(szName));
	return pObject;
}
Ejemplo n.º 6
0
uint32 CKademlia::LoadNodes()
{
	wstring ConfigPath = Cfg()->GetString("ConfigPath");
	if(ConfigPath.empty())
		return 0;

	uint32 Count = 0;
	try
	{
		CVariant NeoNodes;
		ReadFile(ConfigPath + L"NeoNodes.dat", NeoNodes);
		const CVariant& NodeList = NeoNodes["Nodes"];
		for(uint32 i=0; i < NodeList.Count(); i++)
		{
			CPointer<CKadNode> pNode = new CKadNode(m_pRootZone);

			pNode->Load(NodeList.At(i), true);
			if(pNode->GetAddresses().empty())
				continue;

			Count++;
			m_pRootZone->AddNode(pNode);
		}
		m_pKadHandler->SetLastContact(NeoNodes["LastContact"]);
	}
	catch(const CException&)
	{
		ASSERT(0);
	}
	return Count;
}
Ejemplo n.º 7
0
void TestObjectDehollowfication(void)
{
	CFileUtil						cFileUtil;
	CPointer						pPointer;
	CTestDoubleNamedString*			pcInternal;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CTestNamedString>			pSingle;
	int								iClassSize;
	OIndex							oiOld;
	OIndex							oiNew;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/Dehollowfication");
	ObjectsInit("Output/Dehollowfication");
	SetupObjectsForDehollowfication();
	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(9, gcObjects.NumDatabaseObjects());
	ObjectsKill();

	ObjectsInit("Output/Dehollowfication");
	SetupObjectsConstructors();
	AssertLongLongInt(9, gcObjects.NumDatabaseObjects());

	AssertTrue(gcObjects.Contains("Double"));

	pPointer = gcObjects.Get("Double");
	AssertNotNull(pPointer.Object());
	AssertString("CTestDoubleNamedString", pPointer.ClassName());

	pcInternal = (CTestDoubleNamedString*)pPointer.Object();
	AssertTrue(pcInternal->mpSplit1.IsNotNull());
	AssertTrue(pcInternal->mpSplit1.IsHollow());
	AssertTrue(pcInternal->mpSplit2.IsNotNull());
	AssertTrue(pcInternal->mpSplit2.IsHollow());

	pDouble = pPointer;

	oiOld = pDouble->mpSplit1.GetIndex();
	AssertTrue(pcInternal->mpSplit1.IsHollow());  //Making sure we haven't de-hollowed the object by calling GetIndex.

	//Problem - An oi of 1 is briefly assigned to the de-hollowed object and then it is reassigned back to its original value.
	iClassSize = pDouble->mpSplit1->ClassSize();  //The method call - ClassSize() - is irrelevant as long as the -> operator on mpSplit1 is invoked.
	AssertTrue(pcInternal->mpSplit1.IsNotNull());
	AssertFalse(pcInternal->mpSplit1.IsHollow());
	AssertInt(sizeof(CTestNamedString), iClassSize);
	AssertString("CTestNamedString", pcInternal->mpSplit1.ClassName());
	oiNew = pDouble->mpSplit1.GetIndex();
	AssertLongLongInt(oiOld, oiNew);

	pSingle = pDouble->mpSplit2;
	AssertTrue(pcInternal->mpSplit2.IsNotNull());
	AssertTrue(pcInternal->mpSplit2.IsHollow());

	ObjectsKill();
}
void TestObjectReaderSimpleDeserialised(void)
{
	WriteObjectReaderSimpleFile();

	CObjectReaderSimpleDisk		cReader;
	CObjectGraphDeserialiser	cGraphDeserialiser;
	CPointer					cBase;

	Ptr<CTestNamedString>		cNS1;
	Ptr<CTestNamedString>		cNS2;
	CPointer					cTemp;

	CObjectAllocator			cAllocator;
	CDependentReadObjects		cDependentReadObjects;

	MemoryInit();
	ObjectsInit();

	gcObjects.AddConstructor<CTestNamedString>();

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumMemoryIndexes());

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cReader.Init("Output\\ObjectReaderSimple\\Test\\");
	cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cBase = cGraphDeserialiser.Read("Waggy");

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());

	cNS1 = gcObjects.Get("Waggy");
	AssertTrue(cNS1.IsNotNull());
	AssertString("NS1", cNS1->mszEmbedded.Text());

	cNS2 = gcObjects.Get("Dog");
	AssertTrue(cNS2.IsNotNull());
	AssertString("NS2", cNS2->mszEmbedded.Text());

	AssertTrue(cBase.IsNotNull());
	AssertString("CTestNamedString", cBase->ClassName());
	AssertPointer(&cNS1, &cBase);

	AssertPointer(&cNS2, &cNS1->mpAnother);
	AssertPointer(NULL, &cNS2->mpAnother);

	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();
	cReader.Kill();

	ObjectsKill();
}
Ejemplo n.º 9
0
CPointer* CBinaryFile::FindPointer(object oIdentifier, int iOffset, unsigned int iLevel)
{
	CPointer* ptr = FindAddress(oIdentifier);
	if (ptr->IsValid())
	{
		ptr->m_ulAddr += iOffset;
		while (iLevel > 0)
		{
			ptr = ptr->GetPtr();
			iLevel = iLevel - 1;
		}
	}
	return ptr;
}
Ejemplo n.º 10
0
void CKadHandler::HandleRouteReq(const CVariant& RouteReq, CKadNode* pNode, CComChannel* pChannel)
{
	if(GetParent<CKademlia>()->Cfg()->GetBool("DebugRU"))
		LogLine(LOG_DEBUG, L"Recived 'Route Resuest' from %s", pNode->GetID().ToHex().c_str());

	CVariant RouteRes(CVariant::EMap);

	SKadData* pData = pChannel->GetData<SKadData>();
	CPointer<CKadRelay> pRelay = pData->pLookup->Cast<CKadRelay>();
	if(!pRelay)
	{
		if(!RouteReq.Has("TID")) // this is optional it is not send on a refresn
			throw CException(LOG_ERROR, L"Invalid Lookup Request");

		if(pData->pLookup)
			throw CException(LOG_ERROR, L"Recived Route Resuest for a lookup that is not a CKadRelay");

		CLookupManager* pLookupManager = GetParent<CKademlia>()->Manager();
		pRelay = pLookupManager->GetRelayEx(RouteReq["EID"], RouteReq["TID"]); // find already existing relay for this Entity and target combination
		//ASSERT(pRelay == pLookupManager->GetLookup(RouteReq["LID"])->Cast<CKadRelay>()); // lookup ID should be consistent

		if(!pRelay)
		{
			pRelay = new CKadRelay(RouteReq["TID"], pLookupManager);
			if(pRelay->InitRelay(RouteReq)) // if false it means the lookup is invalid
			{
				pRelay->SetHopLimit(RouteReq.Get("JMPS"));
				pRelay->SetJumpCount(RouteReq.Get("HOPS"));

				pRelay->SetBrancheCount(RouteReq.Get("BRCH"));

				pRelay->SetLookupID(RouteReq["LID"]);
				pLookupManager->StartLookup(pRelay.Obj());

				if(RouteReq.Has("TRACE"))
					pRelay->EnableTrace();
			}
		}

		// For this cahnnel the relay was new, setup BC
		pData->pLookup = CPointer<CKadLookup>(pRelay, true); // weak pointer
		pChannel->AddUpLimit(pData->pLookup->GetUpLimit());
		pChannel->AddDownLimit(pData->pLookup->GetDownLimit());
	}

	string Error = pRelay->AddDownLink(pNode, pChannel); // add or update
	if(!Error.empty())
		RouteRes["ERR"] = Error;

	if(GetParent<CKademlia>()->Cfg()->GetBool("DebugRU"))
		LogLine(LOG_DEBUG, L"Sending 'Route Response' to %s", pNode->GetID().ToHex().c_str());
	pChannel->QueuePacket(KAD_ROUTE_RESPONSE, RouteRes);
}
int WriteObjectReaderChunkedFile(void)
{
	CPointer				cBase;
	CObjectWriterChunked	cWriter;
	CObjectGraphSerialiser	cGraphSerialiser;

	cBase = SetupObjectReaderChunkedChunkFile();

	cWriter.Init("Output\\ObjectReaderChunked\\Test\\", "", "Reader");
	cGraphSerialiser.Init(&cWriter);
	AssertTrue(cGraphSerialiser.Write(cBase.BaseObject()));
	cGraphSerialiser.Kill();
	cWriter.Kill();

	return (int)gcObjects.NumMemoryIndexes();
}
Ejemplo n.º 12
0
CPointer<CJSScript> CKadScript::MakeScript(const string& Source, const wstring& Name, uint32 Version)
{
	CPointer<CJSScript> pScript = new CJSScript(this);

	CDebugScope Debug(this); // this may origined with a operation but is a global event

	wstring FileName = ToHex(m_CodeID.GetData(), m_CodeID.GetSize()) + L"/" + Name;

	map<string, CObject*> Objects;
	Objects["debug"] = new CDebugObj(FileName + L"-v" + GetVersion(Version), LineLogger, this);
	Objects["kademlia"] = GetParent<CKademlia>();
	Objects["script"] = this;
	if(CBinaryCache* pCache = GetParent<CKademlia>()->Engine()->GetCache())
		Objects["cache"] = pCache;
	wstring wSource;
	Utf8ToWStr(wSource, Source);
	pScript->Initialize(wSource, FileName, Objects); // this can fron a CException
	return pScript;
}
Ejemplo n.º 13
0
CPointer CObjects::Get(OIndex oi)
{
	CBaseObject*	pvObject;
	CPointer	pObject;

	pvObject = mcMemory.Get(oi);
	if (pvObject)
	{
		pObject.AssignObject(pvObject);
		return pObject;
	}

	pvObject = GetFromDatabase(oi);
	if (pvObject)
	{
		pObject.AssignObject(pvObject);
		return pObject;
	}

	return Null();
}
void WriteObjectReaderSimpleFile(void)
{
	MemoryInit();
	ObjectsInit();
	gcObjects.AddConstructor<CTestNamedString>();

	CPointer				cBase;
	CObjectWriterSimple		cWriter;
	CObjectGraphSerialiser	cGraphSerialiser;

	cBase = SetupObjectReaderSimpleFile();

	cWriter.Init("Output\\ObjectReaderSimple\\Test\\", "");
	cGraphSerialiser.Init(&cWriter);
	AssertTrue(cGraphSerialiser.Write(cBase.BaseObject()));
	cGraphSerialiser.Kill();
	cWriter.Kill();

	ObjectsKill();
	MemoryKill();
}
Ejemplo n.º 15
0
void CKadHandler::ResumeExchange(CPointer<CKadNode> pNode)
{
	TExchangeMap::iterator X = m_KeyExchanges.find(SKadNode(pNode));
	if(CTrustedKey* pTrustedKey = pNode->GetTrustedKey())
	{
		TExchangeMap::iterator I = X;
		X = m_KeyExchanges.end();
		for(; I != m_KeyExchanges.end() && I->first.pNode == pNode; I++) // for each exchange for this node
		{
			if(I->second.pExchange)
				continue;

			if(pTrustedKey->IsAuthenticated() || !I->second.bAuthenticate) // the key we know is eider authenticated or we dont need authentication
				SendCryptoRequest(I->first.pNode, I->first.pChannel, &I->second, pTrustedKey); // try to activate this key
			else if(X == m_KeyExchanges.end())
				X = I;
		}
	}
	if(X != m_KeyExchanges.end() && X->second.pExchange == NULL)
		SendCryptoRequest(X->first.pNode, X->first.pChannel, &X->second, NULL);
}
Ejemplo n.º 16
0
CVariant CKademlia::SetupRoute(const CUInt128& TargetID, CPrivateKey* pEntityKey, int HopLimit, int JumpCount, bool bTrace)
{
	if(!m_pKadHandler)
		return CVariant();

	CPointer<CKadRoute> pRoute = new CKadRouteImpl(TargetID, pEntityKey, m_pLookupManager);

	if(HopLimit != -1)
		pRoute->SetHopLimit(HopLimit);
	if(JumpCount != -1)
		pRoute->SetJumpCount(JumpCount);
	if(bTrace)
		pRoute->EnableTrace();

	if(CKadRoute* pOldRoute = m_pLookupManager->GetRelay(pRoute->GetEntityID())->Cast<CKadRoute>())
		m_pLookupManager->StopLookup(pOldRoute);

	m_pLookupManager->StartLookup(pRoute.Obj());

	return pRoute->GetEntityID();
}
void TestObjectReaderChunkedDeserialised(void)
{
	CObjectReaderChunkFileDisk	cReader;
	CObjectGraphDeserialiser	cGraphDeserialiser;
	CPointer					cBase;
	Ptr<CTestWithArray>			cA1;
	Ptr<CTestWithArray>			cA2;
	Ptr<CTestNamedString>		cNS1;
	Ptr<CTestNamedString>		cNS2;
	Ptr<CTestNamedString>		cNS3;
	Ptr<CTestNamedString>		cNS4;
	Ptr<CString>				sz1;
	Ptr<CString>				sz2;
	Ptr<CString>				sz3;
	CPointer					cTemp;
	Ptr<CTestInteger>			cI1;
	Ptr<CTestInteger>			cI2;
	Ptr<CTestInteger>			cI3;
	CObjectAllocator			cAllocator;
	CDependentReadObjects		cDependentReadObjects;
	OIndex						oiI1;
	OIndex						oiI2;
	OIndex						oiI3;
	int							iNumMemoryIndexes;

	gcObjects.AddConstructor<CTestWithArray>();
	gcObjects.AddConstructor<CTestInteger>();
	gcObjects.AddConstructor<CTestNamedString>();
	gcObjects.AddConstructor<CString>();
	gcObjects.AddConstructor<CArrayObject>();

	iNumMemoryIndexes = WriteObjectReaderChunkedFile();

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(14, iNumMemoryIndexes);

	ObjectsKill();
	ObjectsInit();

	gcObjects.AddConstructor<CTestWithArray>();
	gcObjects.AddConstructor<CTestInteger>();
	gcObjects.AddConstructor<CTestNamedString>();
	gcObjects.AddConstructor<CString>();
	gcObjects.AddConstructor<CArrayObject>();

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumMemoryIndexes());

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cReader.Init("Output\\ObjectReaderChunked\\Test\\", "Reader");
	cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cBase = cGraphDeserialiser.Read("Array 1");
	AssertTrue(cBase.IsNotNull());
	AssertString("CTestWithArray", cBase.ClassName());

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(14, gcObjects.NumMemoryIndexes());

	cA1 = gcObjects.Get("Array 1");
	AssertTrue(cA1.IsNotNull());
	AssertString("CTestWithArray", cA1->ClassName());
	AssertString("Something with One", cA1->mszString.Text());
	AssertInt(1, cA1->mx);

	AssertPointer(cBase.Object(), cA1.Object());

	cA2 = gcObjects.Get("Array X");
	AssertTrue(cA2.IsNotNull());
	AssertString("CTestWithArray", cA2.ClassName());
	AssertString("An with 2", cA2->mszString.Text());
	AssertInt(2, cA2->mx);

	cNS1 = gcObjects.Get("NamedString 1");
	AssertTrue(cNS1.IsNotNull());
	AssertString("CTestNamedString", cNS1->ClassName());
	AssertString("In Named 1", cNS1->mszEmbedded.Text());

	cNS2 = gcObjects.Get("NamedString 2");
	AssertTrue(cNS2.IsNotNull());
	AssertString("CTestNamedString", cNS2->ClassName());
	AssertString("Another in 2", cNS2->mszEmbedded.Text());

	cNS3 = gcObjects.Get("NamedString 3");
	AssertTrue(cNS3.IsNotNull());
	AssertString("CTestNamedString", cNS3->ClassName());
	AssertString("Three", cNS3->mszEmbedded.Text());

	cNS4 = gcObjects.Get("NamedString 4");
	AssertTrue(cNS4.IsNotNull());

	AssertTrue(cBase.IsNotNull());
	AssertString("CTestWithArray", cBase->ClassName());
	AssertPointer(&cA1, &cBase);
	
	AssertNotNull(&cA1->mcArray);
	AssertInt(6, cA1->mcArray->NumElements())
	sz2 = cA1->mcArray->Get(0);
	AssertString("Ye!", sz2->Text());
	cTemp = cA1->mcArray->Get(1);
	AssertPointer(&cNS1, &cTemp);

	oiI1 = cGraphDeserialiser.GetNewIndexFromOld(5LL);
	oiI2 = cGraphDeserialiser.GetNewIndexFromOld(6LL);
	oiI3 = cGraphDeserialiser.GetNewIndexFromOld(7LL);

	cI1 = gcObjects.Get(oiI1);
	AssertString("CTestInteger", cI1->ClassName());
	cI2 = gcObjects.Get(oiI2);
	AssertString("CTestInteger", cI2->ClassName());
	cI3 = gcObjects.Get(oiI3);
	AssertString("CTestInteger", cI3->ClassName());

	AssertInt(3, cI1->mx);
	AssertInt(2, cI1->my);
	AssertInt(1, cI1->mz);

	AssertPointer(&cNS2, &cNS1->mpAnother);
	AssertPointer(&cI1, &cA1->mcArray->Get(2));
	AssertPointer(&cNS3, &cA1->mcArray->Get(3));
	AssertPointer(&cNS1, &cNS3->mpAnother);
	AssertPointer(&cI2, &cA1->mcArray->Get(4));
	AssertPointer(&cA2, &cA1->mcArray->Get(5));

	AssertNotNull(&cA2->mcArray);
	AssertInt(4, cA2->mcArray->NumElements());
	AssertPointer(&cI3, &cA2->mcArray->Get(0));
	AssertPointer(&cNS2, &cA2->mcArray->Get(1));
	AssertPointer(&cNS3, &cNS2->mpAnother);
	AssertPointer(&cI1, &cA2->mcArray->Get(2));
	AssertPointer(&cNS4, &cA2->mcArray->Get(3));
	AssertPointer(NULL, &cNS4->mpAnother);
	AssertPointer(NULL, &cNS4->mszString);

	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();
	cReader.Kill();
}
Ejemplo n.º 18
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.
}
Ejemplo n.º 19
0
CVariant CKademlia::StartLookup(const CUInt128& TargetID, const CVariant& CodeID, const TCallMap& Execute, const TStoreMap& Store, CPrivateKey* pStoreKey, const TLoadMap& Load
									, int Timeout, int HopLimit, int JumpCount, int SpreadCount, bool bTrace, const wstring& Name)
{
	if(!m_pKadHandler)
		return CVariant();

	if(!CodeID.IsValid() && Store.empty() && Load.empty())
	{
		LogLine(LOG_ERROR, L"Attempted to start an empty Lookup");
		return CVariant();
	}

	CPointer<CKadTask> pLookup = new CKadTask(TargetID, m_pLookupManager);
	pLookup->SetName(Name);

	if(Timeout != -1)
		pLookup->SetTimeOut(Timeout);

	if(HopLimit != -1)
		pLookup->SetHopLimit(HopLimit);
	if(JumpCount != -1)
		pLookup->SetJumpCount(JumpCount);
	if(SpreadCount != -1)
		pLookup->SetSpreadCount(SpreadCount);
	if(bTrace)
		pLookup->EnableTrace();

	if(pStoreKey)
		pLookup->SetStoreKey(pStoreKey);

	for(TStoreMap::const_iterator I = Store.begin(); I != Store.end(); I++)
		pLookup->Store(I->first, I->second.Path, I->second.Data);
	
	for(TLoadMap::const_iterator I = Load.begin(); I != Load.end(); I++)
		pLookup->Load(I->first, I->second.Path);

	if(CodeID.IsValid())
	{
		if(!pLookup->SetupScript(CodeID))
		{
			LogLine(LOG_ERROR, L"Attempted to start a smart lookup with an unavailable script: %s", ToHex(CodeID.GetData(), CodeID.GetSize()).c_str());
			return CVariant();
		}
	
		for(TCallMap::const_iterator I = Execute.begin(); I != Execute.end(); I++)
			pLookup->AddCall(I->second.Function, I->second.Parameters, I->first);
	}

	CVariant LookupID = m_pLookupManager->StartLookup(pLookup.Obj());

	return LookupID;
}