Ejemplo n.º 1
0
static bool ndspFindAndLoadComponent(void)
{
	Result rc;
	Handle rsrc;
	void* bin;

	componentProgMask = 0xFF;
	componentDataMask = 0xFF;

	// Try loading the DSP component from the filesystem
	do
	{
		static const char dsp_filename[] = "/3ds/dspfirm.cdc";
		FS_Archive arch = { ARCHIVE_SDMC, { PATH_EMPTY, 1, (u8*)"" }, 0 };
		FS_Path path = { PATH_ASCII, sizeof(dsp_filename), (u8*)dsp_filename };

		rc = FSUSER_OpenFileDirectly(&rsrc, arch, path, FS_OPEN_READ, 0);
		if (R_FAILED(rc)) break;

		u64 size = 0;
		rc = FSFILE_GetSize(rsrc, &size);
		if (R_FAILED(rc)) { FSFILE_Close(rsrc); break; }

		bin = malloc(size);
		if (!bin) { FSFILE_Close(rsrc); break; }

		u32 dummy = 0;
		rc = FSFILE_Read(rsrc, &dummy, 0, bin, size);
		FSFILE_Close(rsrc);
		if (R_FAILED(rc)) { free(bin); return false; }

		componentBin = bin;
		componentSize = size;
		componentFree = true;
		return true;
	} while (0);

	// Try loading the DSP component from hb:ndsp
	rsrc = envGetHandle("hb:ndsp");
	if (rsrc) do
	{
		extern u32 fake_heap_end;
		u32 mapAddr = (fake_heap_end+0xFFF) &~ 0xFFF;
		rc = svcMapMemoryBlock(rsrc, mapAddr, 0x3, 0x3);
		if (R_FAILED(rc)) break;

		componentSize = *(u32*)(mapAddr + 0x104);
		bin = malloc(componentSize);
		if (bin)
			memcpy(bin, (void*)mapAddr, componentSize);
		svcUnmapMemoryBlock(rsrc, mapAddr);
		if (!bin) break;

		componentBin = bin;
		componentFree = true;
		return true;
	} while (0);

	return false;
}
Ejemplo n.º 2
0
Result getFile(u8 ** buffer, u64 * size) {
	Result ret = 0;
	Handle filehandle = 0;
	u32 tmpval = 0;

	ret = FSUSER_OpenFile(&filehandle, extdata_archive, verListPath,
			FS_OPEN_READ, 0);
	if (ret != 0)
		return ret;

	ret = FSFILE_GetSize(filehandle, size);
	if (ret != 0)
		return ret;

	if (*size <= ENTRY_SIZE) {
		*size = 0;
		return ret;
	}

	if (mode == MODE_ALL)
		*size = ENTRY_SIZE;

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

	if (ret != 0)
		return ret;

	FSFILE_Close(filehandle);
	return ret;
}
Ejemplo n.º 3
0
Archivo: r5.c Proyecto: nicklausd/HANS
u8* loadSmdh(u64 tid, u8 mediatype)
{
	Result ret;
	Handle fileHandle;

	u32 archivePath[] = {tid & 0xFFFFFFFF, (tid >> 32) & 0xFFFFFFFF, mediatype, 0x00000000};
	static const u32 filePath[] = {0x00000000, 0x00000000, 0x00000002, 0x6E6F6369, 0x00000000}; // icon

	ret = FSUSER_OpenFileDirectly(NULL, &fileHandle, (FS_archive){0x2345678a, (FS_path){PATH_BINARY, 0x10, (u8*)archivePath}}, (FS_path){PATH_BINARY, 0x14, (u8*)filePath}, FS_OPEN_READ, FS_ATTRIBUTE_NONE);

	printf("loading smdh : %08X\n", (unsigned int)ret);

	u8* fileBuffer = NULL;
	u64 fileSize = 0;

	{
		u32 bytesRead;

		ret = FSFILE_GetSize(fileHandle, &fileSize);
		if(ret)return NULL;

		fileBuffer = malloc(fileSize);
		if(ret)return NULL;

		ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, fileBuffer, fileSize);
		if(ret)return NULL;

		ret = FSFILE_Close(fileHandle);
		if(ret)return NULL;

		printf("loaded code : %08X\n", (unsigned int)fileSize);
	}

	return fileBuffer;
}
Ejemplo n.º 4
0
bool _vf3dClose(struct VFile* vf) {
	struct VFile3DS* vf3d = (struct VFile3DS*) vf;

	FSFILE_Close(vf3d->handle);
	svcCloseHandle(vf3d->handle);
	return true;
}
Ejemplo n.º 5
0
Result FS_WriteFile(const char* path, const void* src, u64 size, FS_Archive archive, u32* bytesWritten)
{
	if (!path || !src || !archive || !bytesWritten) return -1;

	Result ret;
	Handle fileHandle;

	debug_print("FS_WriteFile:\n");

	ret = FSUSER_OpenFile(&fileHandle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_WRITE | FS_OPEN_CREATE, FS_ATTRIBUTE_NONE);
	r(" > FSUSER_OpenFile: %lx\n", ret);
	if (R_FAILED(ret)) return ret;

	if (R_SUCCEEDED(ret))
	{
		ret = FSFILE_Write(fileHandle, bytesWritten, 0L, src, size, FS_WRITE_FLUSH);
		r(" > FSFILE_Write: %lx\n", ret);
		if (R_FAILED(ret) || *bytesWritten != size) ret = -2;
	}

	FSFILE_Close(fileHandle);
	r(" > FSFILE_Close\n");

	return ret;
}
Ejemplo n.º 6
0
Result loadTitleInfoIcon(titleInfo_s* ti)
{
	if(!ti || ti->icon)return -1;

	ti->icon = malloc(sizeof(smdh_s));
	if(!ti->icon)return -1;

	Handle fileHandle;
	u32 archivePath[] = {ti->title_id & 0xFFFFFFFF, (ti->title_id >> 32) & 0xFFFFFFFF, ti->mediatype, 0x00000000};
	static const u32 filePath[] = {0x00000000, 0x00000000, 0x00000002, 0x6E6F6369, 0x00000000};	
	Result ret = FSUSER_OpenFileDirectly(&fileHandle, (FS_Archive){ARCHIVE_SAVEDATA_AND_CONTENT, (FS_Path){PATH_BINARY, 0x10, (u8*)archivePath}}, (FS_Path){PATH_BINARY, 0x14, (u8*)filePath}, FS_OPEN_READ, 0);

	if(ret)
	{
		free(ti->icon);
		ti->icon = NULL;
		return ret;
	}

	u32 bytesRead;	
	ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, ti->icon, sizeof(smdh_s));

	if(ret)
	{
		free(ti->icon);
		ti->icon = NULL;
	}

	FSFILE_Close(fileHandle);

	return ret;
}
Ejemplo n.º 7
0
static Result AM_GetSmdh(AM_TitleMediaEntry* title)
{
	if (!title || title->smdh) return -1;

	Result ret;
	u32 bytesRead;
	Handle fileHandle;

	debug_print("AM_GetSmdh:\n");

	u32 archivePath[] = { title->titleid & 0xFFFFFFFF, (title->titleid >> 32) & 0xFFFFFFFF, title->mediatype, 0x00000000 };
	u32 filePath[] = { 0x00000000, 0x00000000, 0x00000002, 0x6E6F6369, 0x00000000 };

	ret = FSUSER_OpenFileDirectly(&fileHandle, (FS_Archive) { ARCHIVE_SAVEDATA_AND_CONTENT , (FS_Path) { PATH_BINARY, 16, archivePath } }, (FS_Path) { PATH_BINARY, 20, filePath }, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	r(" > FSUSER_OpenFileDirectly: %lx\n", ret);

	if (R_SUCCEEDED(ret))
	{
		title->smdh = (smdh_s*) malloc(sizeof(smdh_s));

		ret = FSFILE_Read(fileHandle, &bytesRead, 0LL, title->smdh, sizeof(smdh_s));
		r(" > FSFILE_Read: %lx\n", ret);
	}

	if (R_FAILED(ret))
	{
		free(title->smdh);
		title->smdh = NULL;
	}

	FSFILE_Close(fileHandle);
	r(" > FSFILE_Close\n");

	return ret;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
static Result action_paste_files_open_dst(void* data, u32 index, void* initialReadBlock, u64 size, u32* handle) {
    paste_files_data* pasteData = (paste_files_data*) data;

    Result res = 0;

    char dstPath[FILE_PATH_MAX];
    action_paste_files_get_dst_path(pasteData, index, dstPath);

    FS_Path* fsPath = util_make_path_utf8(dstPath);
    if(fsPath != NULL) {
        Handle currHandle;
        pasteData->currExists = R_SUCCEEDED(FSUSER_OpenFile(&currHandle, pasteData->target->archive, *fsPath, FS_OPEN_READ, 0));
        if(pasteData->currExists) {
            FSFILE_Close(currHandle);
        } else {
            res = FSUSER_CreateFile(pasteData->target->archive, *fsPath, 0, size);
        }

        if(R_SUCCEEDED(res)) {
            res = FSUSER_OpenFile(handle, pasteData->target->archive, *fsPath, FS_OPEN_WRITE, 0);
        }

        util_free_path_utf8(fsPath);
    } else {
        res = R_FBI_OUT_OF_MEMORY;
    }

    return res;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
static Result action_paste_files_close_dst(void* data, u32 index, bool succeeded, u32 handle) {
    paste_files_data* pasteData = (paste_files_data*) data;

    Result res = 0;

    if(R_SUCCEEDED(res = FSFILE_Close(handle))) {
        char dstPath[FILE_PATH_MAX];
        action_paste_files_get_dst_path(pasteData, index, dstPath);

        char parentPath[FILE_PATH_MAX];
        util_get_parent_path(parentPath, dstPath, FILE_PATH_MAX);

        char baseDstPath[FILE_PATH_MAX];
        if(pasteData->target->attributes & FS_ATTRIBUTE_DIRECTORY) {
            strncpy(baseDstPath, pasteData->target->path, FILE_PATH_MAX);
        } else {
            util_get_parent_path(baseDstPath, pasteData->target->path, FILE_PATH_MAX);
        }

        if(strncmp(parentPath, baseDstPath, FILE_PATH_MAX) == 0) {
            list_item* dstItem = NULL;
            if(R_SUCCEEDED(task_create_file_item(&dstItem, pasteData->target->archive, dstPath, ((file_info*) ((list_item*) linked_list_get(&pasteData->contents, index))->data)->attributes & ~FS_ATTRIBUTE_READ_ONLY))) {
                linked_list_add(pasteData->items, dstItem);
            }
        }
    }

    return res;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
Result FS_ReadFile(const char* path, void* dst, u64 maxSize, FS_Archive archive, u32* bytesRead)
{
	if (!path || !dst || !archive || !bytesRead) return -1;

	Result ret;
	u64 size;
	Handle fileHandle;

	debug_print("FS_ReadFile:\n");

	ret = FSUSER_OpenFile(&fileHandle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	r(" > FSUSER_OpenFile: %lx\n", ret);
	if (R_FAILED(ret)) return ret;

	ret = FSFILE_GetSize(fileHandle, &size);
	r(" > FSFILE_GetSize: %lx\n", ret);
	if (R_FAILED(ret) || size > maxSize) ret = -2;

	if (R_SUCCEEDED(ret))
	{
		ret = FSFILE_Read(fileHandle, bytesRead, 0x0, dst, size);
		r(" > FSFILE_Read: %lx\n", ret);
		if (R_FAILED(ret) || *bytesRead < size) ret = -3;
	}

	FSFILE_Close(fileHandle);
	r(" > FSFILE_Close\n");

	return ret;
}
Ejemplo n.º 15
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");
}
Ejemplo n.º 16
0
std::vector<TitleInfo> getTitleInfos(FS_MediaType mediaType)
{
	char tmpStr[16];
	extern u8 sysLang; // We got this in main.c
	u32 count, bytesRead;
	Result res;
	Handle fileHandle;
	TitleInfo tmpTitleInfo;

	u32 archiveLowPath[4] = {0, 0, mediaType, 0};
	const FS_Archive iconArchive = {0x2345678A, {PATH_BINARY, 0x10, (u8*)archiveLowPath}};
	const u32 fileLowPath[5] = {0, 0, 2, 0x6E6F6369, 0};
	const FS_Path filePath = {PATH_BINARY, 0x14, (const u8*)fileLowPath};


	if((res = AM_GetTitleCount(mediaType, &count))) throw titleException(_FILE_, __LINE__, res, "Failed to get title count!");


	std::vector<TitleInfo> titleInfos; titleInfos.reserve(count);
	Buffer<u64> titleIdList(count, false);
	Buffer<AM_TitleEntry> titleList(count, false);
	Buffer<Icon> icon(1, false);



	if((res = AM_GetTitleIdList(mediaType, count, &titleIdList))) throw titleException(_FILE_, __LINE__, res, "Failed to get title ID list!");
	if((res = AM_ListTitles(mediaType, count, &titleIdList, &titleList))) throw titleException(_FILE_, __LINE__, res, "Failed to get title list!");
	for(u32 i=0; i<count; i++)
	{
		// Copy title ID, size and version directly
		memcpy(&tmpTitleInfo.titleID, &titleList[i].titleID, 18);
		if(AM_GetTitleProductCode(mediaType, titleIdList[i], tmpStr)) memset(tmpStr, 0, 16);
		tmpTitleInfo.productCode = tmpStr;

		// Copy the title ID into our archive low path
		memcpy(archiveLowPath, &titleIdList[i], 8);
		icon.clear();
		if(!FSUSER_OpenFileDirectly(&fileHandle, iconArchive, filePath, FS_OPEN_READ, 0))
		{
			// Nintendo decided to release a title with an icon entry but with size 0 so this will fail.
			// Ignoring errors because of this here.
			FSFILE_Read(fileHandle, &bytesRead, 0, &icon, sizeof(Icon));
			FSFILE_Close(fileHandle);
		}

		tmpTitleInfo.title = icon[0].appTitles[sysLang].longDesc;
		tmpTitleInfo.publisher = icon[0].appTitles[sysLang].publisher;
		memcpy(tmpTitleInfo.icon, icon[0].icon48, 0x1200);

		titleInfos.push_back(tmpTitleInfo);
	}

	return titleInfos;
}
Ejemplo n.º 17
0
Result write_savedata(const char* path, const void* data, size_t size)
{
    if(!path || !data || size == 0) return -1;

    Result ret = -1;
    int fail = 0;

    fsUseSession(save_session);
    ret = FSUSER_OpenArchive(&save_archive, ARCHIVE_SAVEDATA, (FS_Path){PATH_EMPTY, 1, (u8*)""});
    if(R_FAILED(ret))
    {
        fail = -1;
        goto writeFail;
    }

    // delete file
    FSUSER_DeleteFile(save_archive, fsMakePath(PATH_ASCII, path));
    FSUSER_ControlArchive(save_archive, ARCHIVE_ACTION_COMMIT_SAVE_DATA, NULL, 0, NULL, 0);

    Handle file = 0;
    ret = FSUSER_OpenFile(&file, save_archive, fsMakePath(PATH_ASCII, path), FS_OPEN_CREATE | FS_OPEN_WRITE, 0);
    if(R_FAILED(ret))
    {
        fail = -2;
        goto writeFail;
    }

    u32 bytes_written = 0;
    ret = FSFILE_Write(file, &bytes_written, 0, data, size, FS_WRITE_FLUSH | FS_WRITE_UPDATE_TIME);
    if(R_FAILED(ret))
    {
        fail = -3;
        goto writeFail;
    }

    ret = FSFILE_Close(file);
    if(R_FAILED(ret))
    {
        fail = -4;
        goto writeFail;
    }

    ret = FSUSER_ControlArchive(save_archive, ARCHIVE_ACTION_COMMIT_SAVE_DATA, NULL, 0, NULL, 0);
    if(R_FAILED(ret)) fail = -5;

writeFail:
    FSUSER_CloseArchive(save_archive);
    fsEndUseSession();
    if(fail) sprintf(status, "Failed to write to file: %d\n     %08lX %08lX", fail, ret, bytes_written);
    else sprintf(status, "Successfully wrote to file!\n     %08lX               ", bytes_written);

    return ret;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
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);
	}
}
Ejemplo n.º 20
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;
}
Ejemplo n.º 21
0
static int lua_unloadBMPV(lua_State *L){
int argc = lua_gettop(L);
    if (argc != 1) return luaL_error(L, "wrong number of arguments");
	BMPV* src = (BMPV*)luaL_checkint(L, 1);
	if (src->samplerate != 0 && src->audio_size != 0 && !GW_MODE){
	linearFree(src->audiobuf);
	if (src->audiotype == 2){
		linearFree(src->audiobuf2);
	}
	}
	FSFILE_Close(src->sourceFile);
	svcCloseHandle(src->sourceFile);
	free(src->framebuf);
	free(src);
	return 0;
}
Ejemplo n.º 22
0
/*! Close an open file
 *
 *  @param[in,out] r  newlib reentrancy struct
 *  @param[in]     fd Pointer to sdmc_file_t
 *
 *  @returns 0 for success
 *  @returns -1 for error
 */
static int
sdmc_close(struct _reent *r,
           int           fd)
{
  Result      rc;

  /* get pointer to our data */
  sdmc_file_t *file = (sdmc_file_t*)fd;

  rc = FSFILE_Close(file->fd);
  if(rc == 0)
    return 0;

  r->_errno = rc;
  return -1;
}
Ejemplo n.º 23
0
void dbg_save(char* path, void* buf, int size)
{
	Handle sram;
	FS_path sramPath;
	sramPath.type = PATH_CHAR;
	sramPath.size = strlen(path) + 1;
	sramPath.data = (u8*)path;
	
	Result res = FSUSER_OpenFile(NULL, &sram, sdmcArchive, sramPath, FS_OPEN_CREATE|FS_OPEN_WRITE, FS_ATTRIBUTE_NONE);
	if ((res & 0xFFFC03FF) == 0)
	{
		u32 byteswritten = 0;
		FSFILE_Write(sram, &byteswritten, 0, (u32*)buf, size, 0x10001);
		FSFILE_Close(sram);
	}
}
Ejemplo n.º 24
0
/*! Close an open file
 *
 *  @param[in,out] r  newlib reentrancy struct
 *  @param[in]     fd Pointer to sdmc_file_t
 *
 *  @returns 0 for success
 *  @returns -1 for error
 */
static int
sdmc_close(struct _reent *r,
           void          *fd)
{
  Result      rc;

  /* get pointer to our data */
  sdmc_file_t *file = (sdmc_file_t*)fd;

  rc = FSFILE_Close(file->fd);
  if(R_SUCCEEDED(rc))
    return 0;

  r->_errno = sdmc_translate_error(rc);
  return -1;
}
Ejemplo n.º 25
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;
}
Ejemplo n.º 26
0
Result loadGamecardIcon(smdh_s* out)
{
	if(!out)return -1;

	Handle fileHandle;
	static const u32 archivePath[] = {0x00000000, 0x00000000, 0x00000002, 0x00000000};
	static const u32 filePath[] = {0x00000000, 0x00000000, 0x00000002, 0x6E6F6369, 0x00000000};
	Result ret = FSUSER_OpenFileDirectly(&fileHandle, (FS_Archive){0x2345678a, (FS_Path){PATH_BINARY, 0x10, (u8*)archivePath}}, (FS_Path){PATH_BINARY, 0x14, (u8*)filePath}, FS_OPEN_READ, 0);
	if(ret)return ret;

	u32 bytesRead;
	ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, out, sizeof(smdh_s));

	FSFILE_Close(fileHandle);

	return ret;
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
0
static int lua_download(lua_State *L){
	int argc = lua_gettop(L);
	#ifndef SKIP_ERROR_HANDLING
		if (argc != 2) return luaL_error(L, "wrong number of arguments");
	#endif
	const char* url = luaL_checkstring(L,1);
	const char* file = luaL_checkstring(L,2);
	httpcContext context;
	Result ret = httpcOpenContext(&context, (char*)url , 0);
	#ifndef SKIP_ERROR_HANDLING
		if(ret==0){
	#endif
		httpcBeginRequest(&context);
		/*httpcReqStatus loading;
		httpcGetRequestState(&context, &loading);
		while (loading == 0x5){
			httpcGetRequestState(&context, &loading);
		}*/
		u32 statuscode=0;
		u32 contentsize=0;
		httpcGetResponseStatusCode(&context, &statuscode, 0);
		#ifndef SKIP_ERROR_HANDLING
			if (statuscode != 200) luaL_error(L, "download request error");
		#endif
		httpcGetDownloadSizeState(&context, NULL, &contentsize);
		u8* buf = (u8*)malloc(contentsize);
		memset(buf, 0, contentsize);
		httpcDownloadData(&context, buf, contentsize, NULL);
		Handle fileHandle;
		u32 bytesWritten;
		FS_Archive sdmcArchive=(FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
		FS_Path filePath=fsMakePath(PATH_ASCII, file);
		FSUSER_OpenFileDirectly( &fileHandle, sdmcArchive, filePath, FS_OPEN_CREATE|FS_OPEN_WRITE, 0x00000000);
		FSFILE_Write(fileHandle, &bytesWritten, 0, buf, contentsize,0x10001);
		FSFILE_Close(fileHandle);
		svcCloseHandle(fileHandle);
		free(buf);
	#ifndef SKIP_ERROR_HANDLING
		}else luaL_error(L, "error opening url");
	#endif
	httpcCloseContext(&context);
	return 0;
}
Ejemplo n.º 29
0
int main()
{
	initSrv();
		
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	Handle fileHandle;
	u32 bytesRead;
	FS_archive sdmcArchive=(FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FS_path filePath=(FS_path){PATH_CHAR, 10, (u8*)"/test.bin"};
	FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500);
	FSFILE_Close(fileHandle);

	aptSetupEventHandler();
	
	while(!aptGetStatus())
	{
		u32 PAD=hidSharedMem[7];
		renderEffect();
		swapBuffers();
		copyBuffer();
		u32 regData=PAD|0x01000000;
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
		svc_sleepThread(1000000000);
	}

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}
Ejemplo n.º 30
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;
}