Пример #1
0
// ==================================================
Result FS_loadFile(char* path, void* dst, FS_archive* fsArchive, Handle* fsHandle, u64 maxSize, u32* bytesRead)
// --------------------------------------------------
{
	if (!path || !dst || !fsArchive) return -1;

	Result ret = 0;
	u64 size;
	Handle fileHandle;

	if (!ret)
	{
		ret = FSUSER_OpenFile(fsHandle, &fileHandle, *fsArchive, FS_makePath(PATH_CHAR, path), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
		if (ret) return ret;
	}

	if (!ret)
	{
		ret = FSFILE_GetSize(fileHandle, &size);
		if (ret || size > maxSize) ret = -2;
	}

	if (!ret)
	{
		ret = FSFILE_Read(fileHandle, bytesRead, 0, dst, size);
		if (ret || *bytesRead < size) ret=-3;
	}

	FSFILE_Close(fileHandle);
	return ret;
}
Пример #2
0
void NES_LoadSelectedGame() {
	u32    bytesRead = 0;
	u32    SRAM_Size = 0;
	u32    ROMDIR_Size = (strlen("/3DNES/ROMS/") + strlen(fileSystem.fileList[fileSystem.currFile]) + 1);
	Handle fileHandle;


	CPU_Running = false;

	/* Alloc ROM Directory */
	char ROM_DIR[ROMDIR_Size];

	/* Clear ROM_Dir */
	memset(ROM_DIR, 0x0, ROMDIR_Size);


	//FS_StringConc(ROM_DIR,  "/3DNES/ROMS/", fileSystem.fileList[fileSystem.currFile]);

	/* TODO: FIX IT
	/*if (SRAM_Name != NULL) {
		linearFree(SRAM_Name);
		SRAM_Size = (strlen(fileSystem.fileList[fileSystem.currFile]) - 4);
		SRAM_Name = linearAlloc(SRAM_Size);
		strncpy((char*)SRAM_Name, fileSystem.fileList[fileSystem.currFile], SRAM_Size);
	}
	*/
	
	FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, FS_makePath(PATH_CHAR, ROM_DIR), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	FSFILE_GetSize(fileHandle, &ROM_Size);
	FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)ROM_Cache, (u32)ROM_Size);
	FSFILE_Close(fileHandle);

	/* Start Emulation */
	inGame = true;
}
Пример #3
0
/*! Create a directory
 *
 *  @param[in,out] r    newlib reentrancy struct
 *  @param[in]     path Path of directory to create
 *  @param[in]     mode Permissions of created directory
 *
 *  @returns 0 for success
 *  @returns -1 for error
 */
static int
sdmc_mkdir(struct _reent *r,
           const char    *path,
           int           mode)
{
  Result rc;
  const char *pathptr = NULL;

  pathptr = sdmc_fixpath(path);

  if(pathptr==NULL)
  {
    r->_errno=EINVAL;
    return -1;
  }

  /* TODO: Use mode to set directory attributes. */

  rc = FSUSER_CreateDirectory(NULL, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
  if(rc == 0)
    return 0;

  r->_errno = ENOSYS;
  return -1;
}
Пример #4
0
void NES_LOADROMLIST() {
	Handle romHandle;
	
	FS_dirent dirStruct;
	FS_path dirPath = FS_makePath(PATH_CHAR, "/3DNES/ROMS");

	// init SDMC archive
	sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FSUSER_OpenArchive(NULL, &sdmcArchive);
	FSUSER_OpenDirectory(NULL, &romHandle, sdmcArchive, dirPath);

	// Get number of files in directory
	fileSystem.totalFiles = 0
	while(1) {
		u32 dataRead = 0;
		FSDIR_Read(romHandle, &dataRead, 1, &dirStruct);
		if(dataRead == 0) break;
		fileSystem.totalFiles++;
	}

	fileSystem.fileList = linearAlloc(MAX_FILENAME_SIZE * fileSystem.totalFiles);

	FSUSER_OpenDirectory(NULL, &romHandle, sdmcArchive, dirPath);

	fileSystem.totalFiles = 0;
	while(1) {
		u32 dataRead = 0;
		FSDIR_Read(romHandle, &dataRead, 1, &dirStruct);
		if(dataRead == 0) break;
		unicodeToChar(&fileSystem.fileList[MAX_FILENAME_SIZE * fileSystem.totalFiles), dirStruct.name);
		fileSystem.totalFiles++;
	}

	FSDIR_Close(romHandle);
}
Пример #5
0
/*! Open a directory
 *
 *  @param[in,out] r        newlib reentrancy struct
 *  @param[in]     dirState Pointer to open directory state
 *  @param[in]     path     Path of directory to open
 *
 *  @returns dirState for success
 *  @returns NULL for error
 */
static DIR_ITER*
sdmc_diropen(struct _reent *r,
             DIR_ITER      *dirState,
             const char    *path)
{
  Handle         fd;
  Result         rc;
  const char     *pathptr = NULL;

  pathptr = sdmc_fixpath(path);

  if(pathptr==NULL)
  {
    r->_errno=EINVAL;
    return NULL;
  }

  /* get pointer to our data */
  sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);

  /* open the directory */
  rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
  if(rc == 0)
  {
    dir->fd = fd;
    memset(&dir->entry_data, 0, sizeof(dir->entry_data));
    return dirState;
  }

  r->_errno = rc;
  return NULL;
}
Пример #6
0
Result archive_getfilesize(Archive archive, char *path, u32 *outsize)
{
	Result ret=0;
	struct stat filestats;
	u64 tmp64=0;
	Handle filehandle=0;

	char filepath[256];

	if(archive==SDArchive)
	{
		memset(filepath, 0, 256);
		strncpy(filepath, path, 255);

		if(stat(filepath, &filestats)==-1)return errno;

		*outsize = filestats.st_size;

		return 0;
	}

	ret = FSUSER_OpenFile(NULL, &filehandle, extdata_archive, FS_makePath(PATH_CHAR, path), 1, 0);
	if(ret!=0)return ret;

	ret = FSFILE_GetSize(filehandle, &tmp64);
	if(ret==0)*outsize = (u32)tmp64;

	FSFILE_Close(filehandle);

	return ret;
}
Пример #7
0
void scanHomebrewDirectory(menu_s* m, char* path)
{
	if(!path)return;

	Handle dirHandle;
	FS_path dirPath=FS_makePath(PATH_CHAR, path);
	FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
	
	static char fullPath[1024];
	u32 entriesRead;
	do
	{
		static FS_dirent entry;
		memset(&entry,0,sizeof(FS_dirent));
		entriesRead=0;
		FSDIR_Read(dirHandle, &entriesRead, 1, &entry);
		if(entriesRead)
		{
			strncpy(fullPath, path, 1024);
			int n=strlen(fullPath);
			unicodeToChar(&fullPath[n], entry.name, 1024-n);
			if(entry.isDirectory) //directories
			{
				addDirectoryToMenu(m, fullPath);
			}else{ //stray executables
				n=strlen(fullPath);
				if(n>5 && !strcmp(".3dsx", &fullPath[n-5]))addFileToMenu(m, fullPath);
			}
		}
	}while(entriesRead);

	FSDIR_Close(dirHandle);
}
Пример #8
0
Result write_savedata(char* path, u8* data, u32 size)
{
	if(!path || !data || !size)return -1;

	Handle outFileHandle;
	u32 bytesWritten;
	Result ret = 0;
	int fail = 0;

	ret = FSUSER_OpenFile(&saveGameFsHandle, &outFileHandle, saveGameArchive, FS_makePath(PATH_CHAR, path), FS_OPEN_CREATE | FS_OPEN_WRITE, FS_ATTRIBUTE_NONE);
	if(ret){fail = -8; goto writeFail;}

	ret = FSFILE_Write(outFileHandle, &bytesWritten, 0x0, data, size, 0x10001);
	if(ret){fail = -9; goto writeFail;}

	ret = FSFILE_Close(outFileHandle);
	if(ret){fail = -10; goto writeFail;}

	ret = FSUSER_ControlArchive(saveGameFsHandle, saveGameArchive);

	writeFail:
	if(fail)sprintf(status, "Failed to write to file: %d\n     %08X %08X", fail, (unsigned int)ret, (unsigned int)bytesWritten);
	else sprintf(status, "Successfully wrote to file!\n     %08X               ", (unsigned int)bytesWritten);

	return ret;
}
Пример #9
0
/*! Change current working directory
 *
 *  @param[in,out] r    newlib reentrancy struct
 *  @param[in]     name Path to new working directory
 *
 *  @returns 0 for success
 *  @returns -1 for error
 */
static int
sdmc_chdir(struct _reent *r,
           const char    *name)
{
  Handle fd;
  Result rc;
  const char     *pathptr = NULL;

  pathptr = sdmc_fixpath(name);

  if(pathptr==NULL)
  {
    r->_errno=EINVAL;
    return -1;
  }

  rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr));
  if(rc == 0)
  {
    FSDIR_Close(fd);
    strncpy(__cwd,pathptr,PATH_MAX);
  }
  else
  {
    r->_errno=EINVAL;
    return -1;
  }

  return 0;

}
Пример #10
0
// ==================================================
Result FS_createDirectory(char* path, Handle* fsHandle, FS_archive* fsArchive)
// --------------------------------------------------
{
	if (!path || !fsHandle || !fsArchive) return -1;

	Result ret;

	ret = FSUSER_CreateDirectory(fsHandle, *fsArchive, FS_makePath(PATH_CHAR, path));

	return ret;
}
Пример #11
0
// ==================================================
Result FS_deleteFile(char* path, Handle* fsHandle, FS_archive* fsArchive)
// --------------------------------------------------
{
	if (!path || !fsHandle || !fsArchive) return -1;

	Result ret;

	ret = FSUSER_DeleteFile(fsHandle, *fsArchive, FS_makePath(PATH_CHAR, path));

	return ret;
}
Пример #12
0
int saveBitmap(const char* filename, u8* buffer, u32 w, u32 h)
{
	u8* temp=(u8*)malloc(w*h*3+sizeof(INFOHEADER)+sizeof(HEADER));

	HEADER* header=(HEADER*)temp;
	INFOHEADER* infoheader=(INFOHEADER*)(temp+sizeof(HEADER));

	write16(&header->type, 0x4D42);
	write32(&header->size, w*h*3+sizeof(INFOHEADER)+sizeof(HEADER));
	write32(&header->offset, sizeof(INFOHEADER)+sizeof(HEADER));
	write16(&header->reserved1, 0);
	write16(&header->reserved2, 0);

	write16(&infoheader->bits, 24);
	write32(&infoheader->size, sizeof(INFOHEADER));
	write32(&infoheader->compression, 0);
	write32(&infoheader->width, w);
	write32(&infoheader->height, h);
	write16(&infoheader->planes, 1);
	write32(&infoheader->imagesize, w*h*3);
	write32(&infoheader->xresolution, 0);
	write32(&infoheader->yresolution, 0);
	write32(&infoheader->importantcolours, 0);
	write32(&infoheader->ncolours, 0);
	int y,x;
	for(y=0;y<h;y++)
	{
		for(x=0;x<w;x++)
		{
			temp[((y*w)+x)*3+sizeof(INFOHEADER)+sizeof(HEADER)]=buffer[(x*h+y)*3+0];
			temp[((y*w)+x)*3+1+sizeof(INFOHEADER)+sizeof(HEADER)]=buffer[(x*h+y)*3+1];
			temp[((y*w)+x)*3+2+sizeof(INFOHEADER)+sizeof(HEADER)]=buffer[(x*h+y)*3+2];
		}
	}

	Handle file;
	Result ret=FSUSER_OpenFile(NULL, &file, configuration.sdmc, FS_makePath(PATH_CHAR, filename), FS_OPEN_WRITE|FS_OPEN_CREATE, FS_ATTRIBUTE_NONE);
	if(ret){svcCloseHandle(file); return -2;}

	u32 size=w*h*3+sizeof(INFOHEADER)+sizeof(HEADER);
	u32 bytesWritten=0;

	ret=FSFILE_Write(file, &bytesWritten, 0, temp, size, FS_WRITE_FLUSH);
	if(ret || bytesWritten!=size)return -2;

	FSFILE_Close(file);
	svcCloseHandle(file);
	free(temp);

	return 0;
}
Пример #13
0
void GBAConfigDirectory(char* out, size_t outLength) {
	struct VFile* portable;
#ifdef _WIN32
	wchar_t wpath[MAX_PATH];
	wchar_t wprojectName[MAX_PATH];
	MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH);
	HMODULE hModule = GetModuleHandleW(NULL);
	GetModuleFileNameW(hModule, wpath, MAX_PATH);
	PathRemoveFileSpecW(wpath);
	WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0);
	StringCchCatA(out, outLength, "\\portable.ini");
	portable = VFileOpen(out, O_RDONLY);
	if (portable) {
		portable->close(portable);
	} else {
		wchar_t* home;
		SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home);
		StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName);
		CoTaskMemFree(home);
		CreateDirectoryW(wpath, NULL);
	}
	WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0);
#elif defined(PSP2)
	UNUSED(portable);
	snprintf(out, outLength, "cache0:/%s", projectName);
	sceIoMkdir(out, 0777);
#elif defined(GEKKO)
	UNUSED(portable);
	snprintf(out, outLength, "/%s", projectName);
	mkdir(out, 0777);
#elif defined(_3DS)
	snprintf(out, outLength, "/%s", projectName);
	FSUSER_CreateDirectory(0, sdmcArchive, FS_makePath(PATH_CHAR, out));
#else
	getcwd(out, outLength);
	strncat(out, PATH_SEP "portable.ini", outLength - strlen(out));
	portable = VFileOpen(out, O_RDONLY);
	if (portable) {
		getcwd(out, outLength);
		portable->close(portable);
		return;
	}

	char* home = getenv("HOME");
	snprintf(out, outLength, "%s/.config", home);
	mkdir(out, 0755);
	snprintf(out, outLength, "%s/.config/%s", home, binaryName);
	mkdir(out, 0755);
#endif
}
Пример #14
0
bool fileExists(char *path) {
    if (!path)return false;

    Result ret;
    Handle fileHandle;

    ret = FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, FS_makePath(PATH_CHAR, path),
                          FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    if (ret != 0)return false;

    ret = FSFILE_Close(fileHandle);
    if (ret != 0)return false;

    return true;
}
Пример #15
0
void getNextScreenshotCnt()
{
	//open files while incrementing screenshotCnt until file doesn't exist
	static char path[256];
	Result ret=0;
	while(!ret && screenshotCnt<MAX_SCREENSHOTS)
	{
		screenshotCnt++;
		snprintf(path, 256, "%s/scr_%d_left.bmp", configuration.path, screenshotCnt);
		Handle file;
		ret=FSUSER_OpenFile(NULL, &file, configuration.sdmc, FS_makePath(PATH_CHAR, path), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
		FSFILE_Close(file);
		svcCloseHandle(file);
	}
}
Пример #16
0
void scanHomebrewDirectory(menu_s* m, char* path) {
    if(!path)return;

    Handle dirHandle;
    FS_path dirPath=FS_makePath(PATH_CHAR, path);
    FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath);

    static char fullPath[1024][1024];
    u32 entriesRead;
    int totalentries = 0;
    do
    {
        static FS_dirent entry;
        memset(&entry,0,sizeof(FS_dirent));
        entriesRead=0;
        FSDIR_Read(dirHandle, &entriesRead, 1, &entry);
        if(entriesRead)
        {
            strncpy(fullPath[totalentries], path, 1024);
            int n=strlen(fullPath[totalentries]);
            unicodeToChar(&fullPath[totalentries][n], entry.name, 1024-n);
            if(entry.isDirectory) //directories
            {
                //addDirectoryToMenu(m, fullPath[totalentries]);
                totalentries++;
            }else{ //stray executables
                n=strlen(fullPath[totalentries]);
                if(n>5 && !strcmp(".3dsx", &fullPath[totalentries][n-5])){
                    //addFileToMenu(m, fullPath[totalentries]);
                    totalentries++;
                }
                if(n>4 && !strcmp(".xml", &fullPath[totalentries][n-4])) {
                    //addFileToMenu(m, fullPath[totalentries]);
                    totalentries++;
                }
            }
        }
    }while(entriesRead);

    FSDIR_Close(dirHandle);

    bool sortAlpha = getConfigBoolForKey("sortAlpha", false, configTypeMain);
    addMenuEntries(fullPath, totalentries, strlen(path), m, sortAlpha);

    updateMenuIconPositions(m);
}
Пример #17
0
// ==================================================
Result FS_saveFile(char* path, void* src, u64 size, FS_archive* fsArchive, Handle* fsHandle, u32* bytesWritten)
// --------------------------------------------------
{
	if (!path || !src || !fsArchive) return -1;

	Result ret;
	Handle fileHandle;

	ret = FSUSER_OpenFile(fsHandle, &fileHandle, *fsArchive, FS_makePath(PATH_CHAR, path), FS_OPEN_WRITE | FS_OPEN_CREATE, FS_ATTRIBUTE_NONE);
	if (ret) return ret;

	ret = FSFILE_Write(fileHandle, bytesWritten, 0, src, size, FS_WRITE_NOFLUSH);
	if (ret) return ret;

	FSFILE_Close(fileHandle);
	return ret;
}
Пример #18
0
void dumpFolder(char *path, u32 lowpath_id, char *dumpfolder, u8 *filebuffer, size_t bufsize) {
	Handle extdata_dir;
	Result ret = FSUSER_OpenDirectory(NULL, &extdata_dir, extdata_archive, FS_makePath(PATH_CHAR, path));
	if (ret!=0) {
		printf("could not open dir\n");
		gfxFlushBuffers();
		gfxSwapBuffers();
		return;
	}
	char dirname[0x120];
	sprintf(dirname, "%s/%08x%s", dumpfolder, (unsigned int) lowpath_id, path);
	mkdir(dirname, 0777);
	
	FS_dirent dirStruct;
	char fileName[0x106] = "";
	int cont = 0;
	while(1) {
		u32 dataRead = 0;
		FSDIR_Read(extdata_dir, &dataRead, 1, &dirStruct);
		if(dataRead == 0) break;
		unicodeToChar(fileName, dirStruct.name);
		printf("name: %s%s%s\n", path, fileName, dirStruct.isDirectory ? " (DIRECTORY)" : "");
		gfxFlushBuffers();
		gfxSwapBuffers();
		cont++;
		if (dirStruct.isDirectory) {
			char newpath[0x120];
			sprintf(newpath, "%s%s/", path, fileName);
			dumpFolder(newpath, lowpath_id, dumpfolder, filebuffer, bufsize);
		} else {
			char file_inpath[0x120];
			char file_outpath[0x120];
			char file_display_path[0x120];

			sprintf(file_inpath, "%s%s", path, fileName);
			sprintf(file_outpath, "%s/%08x%s%s", dumpfolder, (unsigned int) lowpath_id, path, fileName);
			sprintf(file_display_path, "%08x%s%s", (unsigned int) lowpath_id, path, fileName);
			archive_copyfile(Extdata_Archive, SDArchive, file_inpath, file_outpath, filebuffer, 0, bufsize, file_display_path);
		}
	}
	printf("total files in 0x%08x%s: %d\n", (unsigned int) lowpath_id, path, (unsigned int) cont);
	gfxFlushBuffers();
	gfxSwapBuffers();
	FSDIR_Close(extdata_dir);
}
Пример #19
0
Result archive_writefile(Archive archive, char *path, u8 *buffer, u32 size)
{
	Result ret=0;
	Handle filehandle=0;
	u32 tmpval=0;
	FILE *f;

	char filepath[256];

	if(archive==SDArchive)
	{
		memset(filepath, 0, 256);
		strncpy(filepath, path, 255);

		f = fopen(filepath, "w+");
		if(f==NULL)return errno;

		tmpval = fwrite(buffer, 1, size, f);

		fclose(f);

		if(tmpval!=size)return -2;

		return 0;
	}

	FS_path fspath = FS_makePath(PATH_CHAR, path);
	
	ret = FSUSER_DeleteFile(NULL, extdata_archive, fspath);
	
	ret = FSUSER_CreateFile(NULL, extdata_archive, fspath, size);
	if(ret!=0)return ret;
	
	ret = FSUSER_OpenFile(NULL, &filehandle, extdata_archive, fspath, FS_OPEN_WRITE, 0);
	if(ret!=0)return ret;

	ret = FSFILE_Write(filehandle, &tmpval, 0, buffer, size, FS_WRITE_FLUSH);

	FSFILE_Close(filehandle);

	if(ret==0 && tmpval!=size)ret=-2;

	return ret;
}
Пример #20
0
void DumpSharedRomFS(u8* archive_binary_lowpath) {    
    std::string output_file = BuildSharedRomFSFilename(archive_binary_lowpath);
    
    // Read RomFS bin from SaveDataCheck...
    
    Handle romfs_handle;
    u64    romfs_size        = 0;
    u32    romfs_bytes_read  = 0;
    
    FS_archive savedatacheck_archive    = { 0x2345678a, { PATH_BINARY, 16, archive_binary_lowpath } };
    u8         file_binary_lowpath[20]  = {};
    FS_path    romfs_path               = { PATH_BINARY, 20, file_binary_lowpath };
    
    print(GFX_TOP, "Dumping SaveDataCheck RomFS (%s)... ", output_file.c_str());

    FSUSER_OpenFileDirectly(NULL, &romfs_handle, savedatacheck_archive, romfs_path, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    FSFILE_GetSize(romfs_handle, &romfs_size);
    
    std::unique_ptr<u8> romfs_data_buffer(new u8[romfs_size]);
    FSFILE_Read(romfs_handle, &romfs_bytes_read, 0, romfs_data_buffer.get(), romfs_size);
    FSFILE_Close(romfs_handle);
    
    // Dump RomFS bin to SDMC...
    
    Handle     file_handle;
    u32        bytes_written = 0;
    FS_path    fs_path       = FS_makePath(PATH_CHAR, output_file.c_str());
    FS_archive sdmc_archive  = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
    
    FSUSER_OpenArchive(NULL, &sdmc_archive);
    FSUSER_OpenFile(NULL, &file_handle, sdmc_archive, fs_path, FS_OPEN_CREATE | FS_OPEN_WRITE, FS_ATTRIBUTE_NONE);
    Result res = FSFILE_Write(file_handle, &bytes_written, 0x0, romfs_data_buffer.get(), romfs_size, FS_WRITE_FLUSH);
    FSFILE_Close(file_handle);
    FSUSER_CloseArchive(NULL, &sdmc_archive);
    
    // Check result...
    
    if (res == 0 && bytes_written == romfs_size)
        print(GFX_TOP, "Done!\n");
    else
        print(GFX_TOP, "Failed!\n");
}
Пример #21
0
s32 main (void) {
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();
	fsInit();
	sdmcInit();
	hbInit();
	qtmInit();
	
	Handle fileHandle;
	u32 bytesRead;
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, "/rxTools.dat");
    Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if(ret) goto EXIT;
    FSFILE_Read(fileHandle, &bytesRead, 0x20000, 0x14400000, 320*1024);
    FSFILE_Close(fileHandle);
	
	consoleInit(GFX_BOTTOM, NULL);
	if (brahma_init()) {
		quick_boot_firm(1);
		printf("[!] Quickload failed\n");
		brahma_exit();

	} else {
		printf("* BRAHMA *\n\n[!]Not enough memory\n");
		wait_any_key();
	}
  EXIT:
	hbExit();
	sdmcExit();
	fsExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	// Return to hbmenu
	return 0;
}
Пример #22
0
App appGetCiaInfo(const std::string file, MediaType mediaType) {
    if(!serviceRequire("am")) {
        return {};
    }

    FS_archive archive = (FS_archive) {ARCH_SDMC, (FS_path) {PATH_EMPTY, 1, (u8*) ""}};
    Result archiveResult = FSUSER_OpenArchive(NULL, &archive);
    if(archiveResult != 0) {
        platformSetError(serviceParseError((u32) archiveResult));
        return {};
    }

    Handle handle = 0;
    Result openResult = FSUSER_OpenFile(NULL, &handle, archive, FS_makePath(PATH_CHAR, file.c_str()), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
    if(openResult != 0) {
        platformSetError(serviceParseError((u32) openResult));
        return {};
    }

    TitleList titleInfo;
    Result infoResult = AM_GetCiaFileInfo(appMediatypeToByte(mediaType), &titleInfo, handle);
    if(infoResult != 0) {
        platformSetError(serviceParseError((u32) infoResult));
        return {};
    }

    FSFILE_Close(handle);
    FSUSER_CloseArchive(NULL, &archive);

    App app;
    app.titleId = titleInfo.titleID;
    app.uniqueId = ((u32*) &titleInfo.titleID)[0];
    strcpy(app.productCode, "<N/A>");
    app.mediaType = mediaType;
    app.platform = appPlatformFromId(((u16*) &titleInfo.titleID)[3]);
    app.category = appCategoryFromId(((u16*) &titleInfo.titleID)[2]);
    app.version = titleInfo.titleVersion;
    app.size = titleInfo.size;
    return app;
}
Пример #23
0
s32 main(void) {
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();
	gfxSet3D(true);
	fsInit();
	sdmcInit();
	hbInit();
	qtmInit();
	gfxSwapBuffers();

	Handle fileHandle;
	u32 bytesRead;
	FS_archive sdmcArchive = (FS_archive){ ARCH_SDMC, (FS_path){ PATH_EMPTY, 1, (u8*)"" } };
	FS_path filePath = FS_makePath(PATH_CHAR, "/" CODE_PATH);
	Result ret = FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if (ret) goto EXIT;
	FSFILE_Read(fileHandle, &bytesRead, 0x14000, 0x14400000, 320 * 1024);
	FSFILE_Close(fileHandle);


	if (brahma_init())
	{
		quick_boot_firm(1);
		brahma_exit();
	}

EXIT:
	hbExit();
	sdmcExit();
	fsExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	// Return to hbmenu
	return 0;
}
Пример #24
0
static int lua_loadBMPV(lua_State *L)
{
    int argc = lua_gettop(L);
    if (argc != 1) return luaL_error(L, "wrong number of arguments");
	const char *file_tbo = luaL_checkstring(L, 1);
	Handle fileHandle;
	FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FS_path filePath=FS_makePath(PATH_CHAR, file_tbo);
	Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if(ret) return luaL_error(L, "error opening file");
	u32 magic,frame_size,bytesRead;
	u64 size;
	FSFILE_GetSize(fileHandle, &size);
	FSFILE_Read(fileHandle, &bytesRead, 0, &magic, 4);
	if (magic == 0x56504D42){
	BMPV* BMPV_file = (BMPV*)malloc(sizeof(BMPV));
	FSFILE_Read(fileHandle, &bytesRead, 4, &(BMPV_file->framerate), 4);
	FSFILE_Read(fileHandle, &bytesRead, 8, &(BMPV_file->width), 4);
	FSFILE_Read(fileHandle, &bytesRead, 12,&(BMPV_file->height), 4);
	if (!GW_MODE) FSFILE_Read(fileHandle, &bytesRead, 16,&(BMPV_file->audiotype), 2);
	FSFILE_Read(fileHandle, &bytesRead, 18,&(BMPV_file->bytepersample), 2);
	FSFILE_Read(fileHandle, &bytesRead, 20,&(BMPV_file->samplerate), 4);
	FSFILE_Read(fileHandle, &bytesRead, 24,&(BMPV_file->audio_size), 4);
	BMPV_file->isPlaying = false;
	BMPV_file->currentFrame = 0;
	BMPV_file->sourceFile = fileHandle;
	BMPV_file->tick = 0;
	BMPV_file->audiobuf = NULL;
	BMPV_file->audiobuf2 = NULL;
	frame_size = BMPV_file->width*BMPV_file->height*3;
	u8* framebuf = (u8*)(malloc(frame_size));
	BMPV_file->framebuf = framebuf;
	int tot_frame = (size-28-BMPV_file->audio_size)/frame_size;
	BMPV_file->mem_size = BMPV_file->audio_size;
	BMPV_file->tot_frame = tot_frame;
	lua_pushnumber(L, (u32)BMPV_file);
	}
	return 1;
}
Пример #25
0
Result archive_readfile(Archive archive, char *path, u8 *buffer, u32 size)
{
	Result ret=0;
	Handle filehandle=0;
	u32 tmpval=0;
	FILE *f;

	char filepath[256];

	if(archive==SDArchive)
	{
		memset(filepath, 0, 256);
		strncpy(filepath, path, 255);

		f = fopen(filepath, "r");
		if(f==NULL)return errno;

		tmpval = fread(buffer, 1, size, f);

		fclose(f);

		if(tmpval!=size)return -2;

		return 0;
	}

	ret = FSUSER_OpenFile(NULL, &filehandle, extdata_archive, FS_makePath(PATH_CHAR, path), FS_OPEN_READ, 0);
	if(ret!=0)return ret;

	ret = FSFILE_Read(filehandle, &tmpval, 0, buffer, size);

	FSFILE_Close(filehandle);

	if(ret==0 && tmpval!=size)ret=-2;

	return ret;
}
Пример #26
0
int loadFile(char* path, void* dst, FS_archive* archive, u64 maxSize)
{
	if(!path || !dst || !archive)return -1;

	u64 size;
	u32 bytesRead;
	Result ret;
	Handle fileHandle;

	ret=FSUSER_OpenFile(&fileHandle, *archive, FS_makePath(PATH_CHAR, path), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if(ret!=0)return ret;

	ret=FSFILE_GetSize(fileHandle, &size);
	if(ret!=0)goto loadFileExit;
	if(size>maxSize){ret=-2; goto loadFileExit;}

	ret=FSFILE_Read(fileHandle, &bytesRead, 0x0, dst, size);
	if(ret!=0)goto loadFileExit;
	if(bytesRead<size){ret=-3; goto loadFileExit;}

	loadFileExit:
	FSFILE_Close(fileHandle);
	return ret;
}
Пример #27
0
directoryContents * contentsOfDirectoryAtPath(char * path, bool dirsOnly) {
    directoryContents * contents = malloc(sizeof(directoryContents));

    int numPaths = 0;

    Handle dirHandle;
    FS_path dirPath=FS_makePath(PATH_CHAR, path);
    FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath);

    u32 entriesRead;
    do
    {
        static FS_dirent entry;
        memset(&entry,0,sizeof(FS_dirent));
        entriesRead=0;
        FSDIR_Read(dirHandle, &entriesRead, 1, &entry);
        if(entriesRead) {
            if(!dirsOnly || (dirsOnly && entry.isDirectory)) {
                char fullPath[1024];
                strncpy(fullPath, path, 1024);
                int n=strlen(path);
                unicodeToChar(&fullPath[n], entry.name, 1024-n);

                strcpy(contents->paths[numPaths], fullPath);
                numPaths++;
            }
        }
    }while(entriesRead);

    FSDIR_Close(dirHandle);

//    qsort(contents->paths, numPaths, 1024, compareStrings);

    contents->numPaths = numPaths;
    return contents;
}
Пример #28
0
int _main()
{
	Handle* gspHandle=(Handle*)CN_GSPHANDLE_ADR;
	Result (*_GSPGPU_FlushDataCache)(Handle* handle, Handle kprocess, u32* addr, u32 size)=(void*)CN_GSPGPU_FlushDataCache_ADR;

	// drawString(CN_TOPFBADR1,"ninjhaxx",0,0);
	// drawString(CN_TOPFBADR2,"ninjhaxx",0,0);

	Handle* srvHandle=(Handle*)CN_SRVHANDLE_ADR;

	int line=10;
	Result ret;

	Handle* addressArbiterHandle=(Handle*)0x334960;

	Result (*_DSP_UnloadComponent)(Handle* handle)=(void*)0x002BA368;
	Result (*_DSP_RegisterInterruptEvents)(Handle* handle, Handle event, u32 param0, u32 param1)=(void*)0x002AED20;
	Handle** dspHandle=(Handle**)0x334EFC;

	_DSP_UnloadComponent(*dspHandle);
	_DSP_RegisterInterruptEvents(*dspHandle, 0x0, 0x2, 0x2);

	//close threads
		//patch gsp event handler addr to kill gsp thread ASAP
		*((u32*)(0x356208+0x10+4*0x4))=0x002ABEDC; //svc 0x9 addr

		//patch waitSyncN
		patchMem(gspHandle, computeCodeAddress(0x00192200), 0x200, 0x19, 0x4F);
		patchMem(gspHandle, computeCodeAddress(0x00192600), 0x200, 0x7, 0x13);
		patchMem(gspHandle, computeCodeAddress(0x001CA200), 0x200, 0xB, 0x1E);
		// patchMem(gspHandle, computeCodeAddress(0x000C6100), 0x200, 0x3C, 0x52);

		//patch arbitrateAddress
		patchMem(gspHandle, computeCodeAddress(0x001C9E00), 0x200, 0x14, 0x40);

		//wake threads
		svc_arbitrateAddress(*addressArbiterHandle, 0x35811c, 0, -1, 0);
		svc_signalEvent(((Handle*)0x3480d0)[2]);
		s32 out; svc_releaseSemaphore(&out, *(Handle*)0x357490, 1);

		//kill thread5 without panicking the kernel...
		*(u8*)0x359935=0x00;

	svc_sleepThread(0x10000000);

	//load secondary payload
	u32 secondaryPayloadSize;
	{
		Result ret;
		Handle* fsuHandle=(Handle*)CN_FSHANDLE_ADR;
		FS_archive saveArchive=(FS_archive){0x00000004, (FS_path){PATH_EMPTY, 1, (u8*)""}};

		//write secondary payload file
		Handle fileHandle;
		ret=_FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, saveArchive, FS_makePath(PATH_CHAR, "/edit/payload.bin"), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
		if(ret)*(u32*)NULL=0xC0DF0002;
		ret=_FSFILE_Read(fileHandle, &secondaryPayloadSize, 0x0, (u32*)0x14300000, 0x00011000);
		if(ret)*(u32*)NULL=0xC0DF0003;
		ret=_FSFILE_Close(fileHandle);
		if(ret)*(u32*)NULL=0xC0DF0004;
	}

	//decompress it
	{
		lzss_decompress((u8*)0x14300000, secondaryPayloadSize, (u8*)0x14100000, lzss_get_decompressed_size((u8*)0x14300000, secondaryPayloadSize));
	}

	ret=_GSPGPU_FlushDataCache(gspHandle, 0xFFFF8001, (u32*)0x14100000, 0x300000);

	doGspwn((u32*)(0x14100000), (u32*)computeCodeAddress(CN_3DSX_LOADADR-0x00100000), 0x0000C000);

	svc_sleepThread(0x3B9ACA00);

	// //close thread handles
	// ret=svc_closeHandle(*((Handle*)0x359938));
	// ret=svc_closeHandle(*((Handle*)0x34FEA4));
	// ret=svc_closeHandle(*((Handle*)0x356274));
	// ret=svc_closeHandle(*((Handle*)0x334730));
	// ret=svc_closeHandle(*((Handle*)0x334F64));

	void (*reset)(int size)=(void*)CN_3DSX_LOADADR;
	reset(0);

	while(1);
	return 0;
}
Пример #29
0
int _main()
{
	Handle* gspHandle=(Handle*)CN_GSPHANDLE_ADR;
	Result (*_GSPGPU_FlushDataCache)(Handle* handle, Handle kprocess, u32* addr, u32 size)=(void*)CN_GSPGPU_FlushDataCache_ADR;

	paintScreen(0x00,0x00,0x00);
	// drawString((u8*)CN_TOPFBADR1,"ninjhaxx",0,0);
	// drawString((u8*)CN_TOPFBADR2,"ninjhaxx",0,0);

	Handle* srvHandle=(Handle*)CN_SRVHANDLE_ADR;

	int line=10;
	Result ret;

	Handle* addressArbiterHandle=(Handle*)0x003414B0;

	Result (*_DSP_UnloadComponent)(Handle* handle)=(void*)0x002C3A78;
	Handle** dspHandle=(Handle**)0x341A4C;

	_DSP_UnloadComponent(*dspHandle);

	//close threads
		//patch gsp event handler addr to kill gsp thread ASAP
		*((u32*)(0x362DA8+0x10+4*0x4))=0x002B5D14; //svc 0x9 addr

		//patch waitSyncN
		patchMem(gspHandle, computeCodeAddress(0x0019BD00), 0x200, 0xB, 0x41);
		patchMem(gspHandle, computeCodeAddress(0x0019C000), 0x200, 0x39, 0x45);
		patchMem(gspHandle, computeCodeAddress(0x001D3700), 0x200, 0x7, 0x1A);
		// patchMem(gspHandle, computeCodeAddress(0x000C9100), 0x200, 0x2E, 0x44);
		// patchMem(gspHandle, computeCodeAddress(0x000EFE00), 0x200, 0x2C, 0x31);

		//patch arbitrateAddress
		patchMem(gspHandle, computeCodeAddress(0x001D3300), 0x200, 0x10, 0x3C);

		//wake threads
		svc_arbitrateAddress(*addressArbiterHandle, 0x364ccc, 0, -1, 0);
		svc_signalEvent(((Handle*)0x354ba8)[2]);
		s32 out; svc_releaseSemaphore(&out, *(Handle*)0x341AB0, 1); //CHECK !

		//kill thread5 without panicking the kernel...
		*(u8*)(0x3664D8+0xd)=0x00;

	//load secondary payload
	u32 secondaryPayloadSize;
	{
		Result ret;
		Handle* fsuHandle=(Handle*)CN_FSHANDLE_ADR;
		FS_archive saveArchive=(FS_archive){0x00000004, (FS_path){PATH_EMPTY, 1, (u8*)""}};

		//read secondary payload file
		Handle fileHandle;
		ret=_FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, saveArchive, FS_makePath(PATH_CHAR, "/edit/payload.bin"), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
		if(ret)*(u32*)NULL=0xC0DF0002;
		ret=_FSFILE_Read(fileHandle, &secondaryPayloadSize, 0x0, (u32*)0x14100000, 0x00011000);
		if(ret)*(u32*)NULL=0xC0DF0003;
		ret=_FSFILE_Close(fileHandle);
		if(ret)*(u32*)NULL=0xC0DF0004;
	}

	//decrypt it
	{
		Result (*blowfishKeyScheduler)(u32* dst)=(void*)0x001A5900;
		Result (*blowfishDecrypt)(u32* blowfishKeyData, u32* src, u32* dst, u32 size)=(void*)0x001A5F48;

		blowfishKeyScheduler((u32*)0x14200000);
		blowfishDecrypt((u32*)0x14200000, (u32*)0x14100000, (u32*)0x14100000, secondaryPayloadSize);
	}

	ret=_GSPGPU_FlushDataCache(gspHandle, 0xFFFF8001, (u32*)0x14100000, 0x300000);

	doGspwn((u32*)(0x14100000), (u32*)computeCodeAddress(CN_3DSX_LOADADR-0x00100000), 0x0000A000);

	svc_sleepThread(0x3B9ACA00);

	void (*reset)(int size)=(void*)CN_3DSX_LOADADR;
	reset(0);

	while(1);
	return 0;
}
Пример #30
0
unsigned char loadROM(char *filename) {
	char name[17];
	enum romType type;
	int romSize;
	int ramSize;
	
	int i;
	
	#ifdef DS3
	u64 length;
	u32 bytesRead;
	
	FS_archive sdmcArchive = (FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FS_path filePath = FS_makePath(PATH_CHAR, filename); // /filename
	
	Result ret = FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if(ret) return false;
	
	ret = FSFILE_GetSize(fileHandle, &length);
	if(ret) return false;
	
	ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, cart, length);
	if(ret || length != bytesRead) return false;
	
	memset(name, '\0', 17);
	for(i = 0; i < 16; i++) {
		if(cart[i + ROM_OFFSET_NAME] == 0x80 || cart[i + ROM_OFFSET_NAME] == 0xc0) name[i] = '\0';
		else name[i] = cart[i + ROM_OFFSET_NAME];
	}
	
	printf("Internal ROM name: %s\n", name);
	
	type = cart[ROM_OFFSET_TYPE];
	
	if(!romTypeString[type]) {
		printf("Unknown ROM type: %#02x\n", type);
		return false;
	}
	
	printf("ROM type: %s\n", romTypeString[type]);
	
	if(type != ROM_PLAIN) {
		printf("Only 32KB games with no mappers are supported!\n");
		return false;
	}
	
	romSize = cart[ROM_OFFSET_ROM_SIZE];
	
	if((romSize & 0xF0) == 0x50) romSize = (int)pow(2.0, (double)(((0x52) & 0xF) + 1)) + 64;
	else romSize = (int)pow(2.0, (double)(romSize + 1));
	
	printf("ROM size: %dKB\n", romSize * 16);
	
	if(romSize * 16 != 32) {
		printf("Only 32KB games with no mappers are supported!\n");
		return false;
	}
	
	if(length != romSize * 16 * 1024) {
		printf("ROM filesize does not equal ROM size!\n");
		return false;
	}
	
	ramSize = cart[ROM_OFFSET_RAM_SIZE];
	
	ramSize = (int)pow(4.0, (double)ramSize) / 2;
	printf("RAM size: %dKB\n", ramSize);
	
	ramSize = ceil(ramSize / 8.0f);
	
	ret = FSFILE_Close(fileHandle);
	if(ret) return false;
	
	return 1;
#else
#ifdef PS4
	void ps4loadROM(void);
	ps4loadROM();
	return 1;
#else
	FILE *f;
	size_t length;
	
	unsigned char header[0x180];
	
	f = fopen(filename, "rb");
	if(!f) return 0;
	
	fseek(f, 0, SEEK_END);
	length = ftell(f);
	if(length < 0x180) {
		printf("ROM is too small!\n");
		fclose(f);
		return 0;
	}
	
	rewind(f);
	fread(header, 0x180, 1, f);
	
	memset(name, '\0', 17);
	for(i = 0; i < 16; i++) {
		if(header[i + ROM_OFFSET_NAME] == 0x80 || header[i + ROM_OFFSET_NAME] == 0xc0) name[i] = '\0';
		else name[i] = header[i + ROM_OFFSET_NAME];
	}
	
	printf("Internal ROM name: %s\n", name);
	
	type = header[ROM_OFFSET_TYPE];
	
	if(!romTypeString[type]) {
		printf("Unknown ROM type: %#02x\n", type);
		fclose(f);
		return 0;
	}
	
	printf("ROM type: %s\n", romTypeString[type]);
	
	if(type != ROM_PLAIN) {
		printf("Only 32KB games with no mappers are supported!\n");
		fclose(f);
		return 0;
	}
	
	romSize = header[ROM_OFFSET_ROM_SIZE];
	
	#ifndef PSP
		if((romSize & 0xF0) == 0x50) romSize = (int)pow(2.0, (double)(((0x52) & 0xF) + 1)) + 64;
		else romSize = (int)pow(2.0, (double)(romSize + 1));
	#else
		// PSP doesn't support pow...
		romSize = 2;
	#endif
	
	printf("ROM size: %dKB\n", romSize * 16);
	
	if(romSize * 16 != 32) {
		printf("Only 32KB games with no mappers are supported!\n");
		fclose(f);
		return 0;
	}
	
	if(length != romSize * 16 * 1024) {
		printf("ROM filesize does not equal ROM size!\n");
		//fclose(f);
		//return 0;
	}
	
	ramSize = header[ROM_OFFSET_RAM_SIZE];
	
	#ifndef PSP
		ramSize = (int)pow(4.0, (double)(ramSize)) / 2;
	#else
		// PSP doesn't support pow...
		ramSize = 0;
	#endif
	
	printf("RAM size: %dKB\n", ramSize);
	
	ramSize = ceil(ramSize / 8.0f);
	
	/*cart = malloc(length);
	if(!cart) {
		printf("Could not allocate memory!\n");
		fclose(f);
		return 0;
	}*/
	
	rewind(f);
	fread(cart, length, 1, f);
	
	fclose(f);
	
	return 1;
	#endif
#endif
}