Ejemplo n.º 1
0
u32 Load_Dol_from_disc(u32 doloffset)
{
	int ret;
	void *dol_header;
	u32 entrypoint;

	dol_header = memalign(32, sizeof(dolheader));
	if (dol_header == NULL)
	{
#ifdef DEBTXT_ALTDOL
		DebTxt("Out of memory");
#endif		
		return -1;
	}

	ret = WDVD_Read(dol_header, sizeof(dolheader), (doloffset<<2));

	entrypoint = load_dol_start(dol_header);

	if (entrypoint == 0)
	{
#ifdef DEBTXT_ALTDOL
		DebTxt("entrypoint = 0");
#endif
		free(dol_header);
		return -1;
	}

	void *offset;
	u32 pos;
	u32 len;

	while (load_dol_image_modified(&offset, &pos, &len))
	{
		if (len != 0)
		{
			ret = WDVD_Read(offset, len, (doloffset<<2) + pos);

            DCFlushRange(offset, len);

			gamepatches(offset, len );

            DCFlushRange(offset, len);

			Remove_001_Protection(offset, len);
		}
	}

	free(dol_header);

	return entrypoint;
}
Ejemplo n.º 2
0
u32 Load_Dol_from_sd(void)
{
	int ret;
	FILE* file;
	void *dol_header;	
	u32 entrypoint;
	
	char fname[128];
	char gameidbuffer4[5];
	memset(gameidbuffer4, 0, 5);
	memcpy(gameidbuffer4, (char*)0x80000000, 4);		
	snprintf(fname, sizeof(fname), "%s/%s.dol", gAltDolPath, gameidbuffer4);
	if (CFG.verbosemode) printf(" %s\n", fname);

	file = fopen(fname, "rb");
	
	if(file == NULL) 
	{
		// Why we need two same error messages?
//		printf("    Not found.\n");
//		sleep(4);
		return 0;
	}
	
	int filesize;
	fseek(file, 0, SEEK_END);
	filesize = ftell(file);
	fseek(file, 0, SEEK_SET);

	dol_header = memalign(32, sizeof(dolheader));
	if (dol_header == NULL)
	{
		printf("[+] Out of memory!\n");
		sleep(2);
		fclose(file);
		return 0;
	}

	ret = fread( dol_header, 1, sizeof(dolheader), file);
	if(ret != sizeof(dolheader))
	{
		printf("[+] Error reading .dol header\n");
		sleep(2);
		free(dol_header);
		fclose(file);
		return 0;
	}
	
	entrypoint = load_dol_start(dol_header);
	
	if (entrypoint == 0)
	{
		printf("[+] Invalid .dol\n");
		sleep(2);
		free(dol_header);
		fclose(file);
		return 0;
	}
	
	void *offset;
	u32 pos;
	u32 len;
	int sec_idx = 0;
	
//	printf("    ...");
	while (load_dol_image(&offset, &pos, &len))
	{
		if(pos+len > filesize)
		{
			printf("[+] .dol too small\n");
			sleep(2);
			free(dol_header);
			fclose(file);
			return -1;
		}		
		
		if (len != 0)
		{
			//dbg_printf("\rdol [%d] @ 0x%08x [%6x] 0x%08x\n", sec_idx,
			//			(int)offset, len, (int)offset + len);
			fseek(file, pos, 0);
			ret = fread( offset, 1, len, file);
			if(ret != len)
			{
				printf("[+] Error reading .dol\n");
				sleep(2);
				free(dol_header);
				fclose(file);
				return -1;
			}
			maindolpatches(offset, len);
			Remove_001_Protection(offset, len);
		}	
		sec_idx++;
//		printf(".");
	}
	printf("\n");
	
	free(dol_header);
	fclose(file);

	return entrypoint;
} // Load_Dol_from_sd