예제 #1
0
파일: main.cpp 프로젝트: CCJY/coliru
int main()
{
    std::cout << MakeSig(JInt, (JString, JBool)) << "\n";
    std::cout << MakeSig(JInt, NoArgs) << "\n";
    std::cout << Sig(JBool)[JInt, JInt, JString] << "\n";
}
예제 #2
0
void SymbolMap::UseFuncSignaturesFile(const char *filename, u32 maxAddress)
{
	sigs.clear();
	//SymbolMap::ResetSymbolMap();
	//#1: Read the signature file and put them in a fast data structure
	FILE *f = fopen(filename, "r");
	int count;
	if (fscanf(f, "%08x\n", &count) != 1)
		count = 0;
	char name[256];
	for (int a=0; a<count; a++)
	{
		u32 inst, size, hash;
		if (fscanf(f,"%08x\t%08x\t%08x\t%s\n",&inst,&size,&hash,name)!=EOF)
			sigs.push_back(Sig(inst,size,hash,name));
		else
			break;
	}
	size_t numSigs = sigs.size();
	fclose(f);
	std::sort(sigs.begin(), sigs.end());

	f = fopen("C:\\mojs.txt", "w");
	fprintf(f,"00000000\n");
	for (size_t j=0; j<numSigs; j++)
		fprintf(f, "%08x\t%08x\t%08x\t%s\n", sigs[j].inst, sigs[j].size, sigs[j].hash, sigs[j].name);    
	fseek(f,0,SEEK_SET);
	fprintf(f,"%08x", (unsigned int)numSigs);
	fclose(f);

	u32 last = 0xc0d3babe;
	for (size_t i=0; i<numSigs; i++)
	{
		if (sigs[i].inst != last)
		{
			sigmap.insert(Sigmap::value_type(sigs[i].inst, &sigs[i]));
			last = sigs[i].inst;
		}
	}

	//#2: Scan/hash the memory and locate functions
	char temp[256];
	u32 lastAddr=0;
	for (u32 addr = 0x80000000; addr<maxAddress; addr+=4)
	{
		if ((addr&0xFFFF0000) != (lastAddr&0xFFFF0000))
		{
			sprintf(temp,"Scanning: %08x",addr);
			lastAddr=addr;
		}
		u32 inst = Memory::Read_Instruction(addr);
		if (!inst) 
			continue;

		Sigmap::iterator iter = sigmap.find(inst);
		if (iter != sigmap.end())
		{
			Sig *sig = iter->second;
			while (true)
			{
				if (sig->inst != inst)
					break;

				u32 hash = ComputeHash(addr,sig->size);				
				if (hash==sig->hash)
				{
					//MATCH!!!!
					MapEntry e;
					e.address=addr;
					e.size= sig->size;
					e.vaddress = addr;
					e.type=ST_FUNCTION;
					strcpy(e.name,sig->name);
					addr+=sig->size-4; //don't need to check function interior
					entries.push_back(e);
					break;
				}
				sig++;
			}
		}
	}
	//ensure code coloring even if symbols were loaded before
	SymbolMap::SortSymbols();
}