MCPcopy Create free account
hub / github.com/StrongPC123/Far-Cry-1-Source-Full / GetRandomModuleProbe

Method GetRandomModuleProbe

CrySystem/DataProbe.cpp:718–779  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

716
717//////////////////////////////////////////////////////////////////////////
718bool CDataProbe::GetRandomModuleProbe( SDataProbeContext &ctx )
719{
720#ifndef WIN32
721 return false; // Not WIN32
722#else // WIN32
723 if (!ctx.pModuleBaseAddress)
724 {
725 // Try to find module handle from filename.
726 HMODULE hModule = GetModuleHandle( ctx.sFilename.c_str() );
727 if (!hModule)
728 return false;
729 ctx.pModuleBaseAddress = hModule;
730 }
731
732 void *pCodeAddress = 0;
733 int nCodeSize = 0;
734 // Get code sections pointers.
735 GetModuleCodeAddress( ctx.pModuleBaseAddress,&pCodeAddress,&nCodeSize );
736 if (!pCodeAddress || nCodeSize == 0)
737 return false;
738
739 // Choose small random offset from both sides.
740 int nOffset1 = 0;
741 int nOffset2 = 0;
742 do {
743 nOffset1 = GetRandom( 1000 );
744 nOffset2 = GetRandom( 1000 );
745 } while (nOffset1+nOffset2 >= nCodeSize+1);
746
747 ctx.pBuffer = pCodeAddress;
748 ctx.nOffset = nOffset1;
749 ctx.nSize = nCodeSize - nOffset1 - nOffset2;
750 if (IsBadReadPtr( (char*)pCodeAddress+nOffset1,ctx.nSize))
751 {
752 // Something wrong..., cant read code memory, skip it.
753 return false;
754 }
755
756 /*
757 //////////////////////////////////////////////////////////////////////////
758 // Write this to file....
759 CryLog( "[CodeModule] %s, base: %x",ctx.sFilename.c_str(),ctx.pModuleBaseAddress );
760 char *pBuf = (char*)malloc(ctx.nSize + 128);
761 memset(pBuf,0,ctx.nSize+64);
762 memcpy(pBuf,(char*)ctx.pBuffer+ctx.nOffset,ctx.nSize);
763 FILE *file;
764 if (!GetISystem()->IsDedicated())
765 file = fopen( (ctx.sFilename+".client_code").c_str(),"wb" );
766 else
767 file = fopen( (ctx.sFilename+".server_code").c_str(),"wb" );
768 fwrite( pBuf,ctx.nSize,1,file );
769 fclose(file);
770
771 unsigned int nCode = CRC_32( pBuf,ctx.nSize );
772 CryLog( "Code CRC32=%u, offset=%d,size=%d",nCode,ctx.nOffset,ctx.nSize );
773 free(pBuf);
774 //////////////////////////////////////////////////////////////////////////
775 */

Callers 1

Calls 3

GetModuleCodeAddressFunction · 0.85
GetRandomFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected