All pastes #440064 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-14 19:18 UTC
rendered paste body
	bool found = false;
	size_t searchLen = searchString.length();
	size_t searchWidth = fileSize - searchLen + 1;
	
	for(size_t i=0; i<searchWidth; ++i)	// i is the initial offset for brute-forcing
	{
		unsigned char xorOffset = i & 0xFF;	// LSB
		bool match = true;
		for(size_t j=0; j<searchLen; ++j, xorOffset+=9)	// xorOffset increases by 9
		{
			// result = xorOffset ^ current byte
			unsigned char currChar = static_cast<unsigned char>(memFile[i+j]) ^ xorOffset;
			if(currChar != static_cast<unsigned char>(searchString[j]))
			{
				match = false;
				break;
			}
		}
		if(match)
		{
			found = true;
			cout << "Found at offset: " << i << "\t(0x" << dec2hex(i) << ")" << endl;
		}
	}
	if(!found)
		cout << "String not found." << endl;
	system("pause");