Ejemplo n.º 1
0
static int lua_ZipExtract(lua_State *L)
{
    int argc = lua_gettop(L);
    
    if(argc != 2 && argc != 3)
        return luaL_error(L, "Argument error: ZIP.extract(zip, dirto, [password]) takes two or three arguments.");
    
    const char *password;
    const char *filetoextract = luaL_checkstring(L, 1);
    mkdir("ms0:/tempLPP", 0777);
    CopiaFile(filetoextract,"ms0:/tempLPP/temp.zip");
    Zip *handle = ZipOpen("ms0:/tempLPP/temp.zip");
    if(argc == 3)
        password = luaL_checkstring(L, 3);
    else
        password = NULL;
    
    int result = ZipExtract(handle, password);
    ZipClose(handle);
    const char *dir = luaL_checkstring(L, 2);
    sceIoMvdir("ms0:/tempLPP",dir);
    char ziptemp[256];
    sprintf(ziptemp,"%s/temp.zip",dir);
    remove(ziptemp);
    lua_pushboolean(L, result);
    
    return 1;
}
Ejemplo n.º 2
0
BOOL ZWZipExtract(LPCTSTR lpszSourceFile, LPCTSTR lpszDestFolder)
{
    return ZipExtract(lpszSourceFile, lpszDestFolder);
}
Ejemplo n.º 3
0
bool CExtInstaller::InstallCRX()
{
	tstring crxPath = m_CurrentDir+_T("/") + SAMPLE_CRX_PATH;
	HANDLE hFile = ::CreateFile(crxPath.c_str(),
		GENERIC_READ,          
		FILE_SHARE_READ,                      
		NULL,                  
		OPEN_EXISTING,          
		FILE_ATTRIBUTE_NORMAL,      
		NULL); 

	if ( INVALID_HANDLE_VALUE == hFile )
	{
		DWORD dwError = GetLastError();
		SHOW_LOG( _T("CExtInstaller::InstallCRX CreateFile [ERROR CODE]%d\n"), dwError);
		return false;
	}
	ULARGE_INTEGER liFileSize;
	liFileSize.QuadPart = 0;
	liFileSize.LowPart = ::GetFileSize(hFile, &liFileSize.HighPart);
	if( liFileSize.LowPart > CHROME_CRX_HEADER_LEN + 2/*PK header len */)
	{
		byte*  byteOriginBuffer = new byte[liFileSize.LowPart],*byteBuffer = byteOriginBuffer; 
		DWORD dwReadSize = 0;
		byteBuffer = (byte*)((size_t)byteBuffer+CHROME_CRX_HEADER_LEN);
		BOOL bRet = ::ReadFile(hFile,(LPVOID)byteOriginBuffer,liFileSize.LowPart,&dwReadSize,NULL);
		if( 'P' == *(char*)((size_t)byteBuffer+1) && 'K' == *(char*)((size_t)byteBuffer+2) )
		{
			int writeLen = liFileSize.LowPart - CHROME_CRX_HEADER_LEN;
			DWORD outwriteLen = 0;
			tstring tmpZipPath = m_CurrentDir+_T("/") + TMP_CRX_ZIP_PATH;
			HANDLE houtZipFile = ::CreateFile(tmpZipPath.c_str(),
				GENERIC_READ|GENERIC_WRITE,          
				FILE_SHARE_READ,                      
				NULL,                  
				CREATE_ALWAYS,          
				FILE_ATTRIBUTE_NORMAL,      
				NULL); 
			WriteFile(houtZipFile, (LPVOID)byteBuffer, writeLen, &outwriteLen, NULL);
			CloseHandle(houtZipFile);
			HANDLE hZipFile = CreateZip(tmpZipPath.c_str(),false);
			tstring extractPath = GetChromeExtPath(CHROME_SAMPLE_CRX_ID_W, CHROME_SAMPLE_CRX_VER);
			CreateDeepDirectory(extractPath.c_str(), NULL);
			if( false == ZipExtract(hZipFile, extractPath.c_str()))
			{
				SHOW_LOG( " CExtInstaller::InstallCRX extractFile error:%d\n",GetLastError());
			}
			CloseZip(hZipFile,false);
			DeleteFile(tmpZipPath.c_str());
			
		}
		else
			return false;
		if( NULL != byteOriginBuffer)
		{
			delete [] byteOriginBuffer;
		}
	}
	CloseHandle(hFile);
	return true;
Ejemplo n.º 4
0
bool installTTP(char* path, u8 mediatype) { // Install a TTP file. (needs libzip and installCIA)

	Result res;
	FS_Archive archive = {ARCHIVE_SDMC, {PATH_EMPTY, 0, 0}};
	FSUSER_OpenArchive(&archive);
	FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_ASCII, "/tmp/cias"));
	FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/tmp/cias"), 0);
	FILE* ttp = fopen(path, "rb");
	FILE* tmp = fopen("/tmp/cias/ttp.tmp", "wb");

	u32 titlesAmount;
	AM_GetTitleCount(mediatype, &titlesAmount);
	u64* titleIDs = malloc(sizeof(u64) * titlesAmount);
	AM_GetTitleIdList(mediatype, titlesAmount, titleIDs);

	u32 size;
	fseek(ttp, 0x19, SEEK_SET);
	fread(&size, 0x4, 1, ttp);
	fseek(ttp, 0x1D, SEEK_SET);

	u32 blockAmount = size / 0x160000; // Finds how many blocks of 4MB you have in the file
	u32 i;
	char* block = malloc(0x160000);
	for (i = 0; i < blockAmount; i++) {
		fread(block, 1, 0x160000, ttp);
		fwrite(block, 1, 0x160000, tmp);
	}

	if (size % 0x160000 != 0) {
		fread(block, 1, size-0x160000*blockAmount, ttp);
		fwrite(block, 1, size-0x160000*blockAmount, tmp);
	}

	free(block);

	fclose(ttp);
	fclose(tmp);

	FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_ASCII, "/tmp/cias"));
	FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/tmp/cias"), 0);

	Zip *zipHandle = ZipOpen("/tmp/cias/ttp.tmp");
	ZipExtract(zipHandle, NULL);
	ZipClose(zipHandle);

	Handle ciaDir;
	FS_Archive fsarchive;
	u32 actualAmount;
	FS_DirectoryEntry* entries;

	FSUSER_DeleteFile(archive, fsMakePath(PATH_ASCII, "/tmp/cias/ttp.tmp"));
	res = FSUSER_OpenDirectory(&ciaDir, fsarchive, fsMakePath(PATH_ASCII, "/tmp/cias"));
	if (res != 0) { free(titleIDs); return false; }
	entries = malloc(256 * sizeof(FS_DirectoryEntry));
	res = FSDIR_Read(ciaDir, &actualAmount, 256, entries);
	if (res != 0) { free(titleIDs); return false; }

	char* ciaPath;
	Handle ciaFileHandle;
	AM_TitleEntry ciaInfo;
	for (i = 0; i < actualAmount; i++) {
		ciaPath = malloc(14 + strlen(entries[i].shortName));
		strcpy(ciaPath, "/tmp/cias/");
		strcat(ciaPath, entries[i].shortName);
		strcat(ciaPath, ".cia");
		
		FSUSER_OpenFile(&ciaFileHandle, archive, fsMakePath(PATH_ASCII, ciaPath), FS_OPEN_READ, 0);
		AM_GetCiaFileInfo(mediatype, &ciaInfo, ciaFileHandle);
		FSFILE_Close(ciaFileHandle);
		
		if (ciaInfo.titleID == 0x0004013800000002LL || ciaInfo.titleID == 0x0004013820000002LL) {
			if (!installCIA(ciaPath, mediatype, titleIDs, entries[i].shortName))
				if (!installCIA(ciaPath, mediatype, titleIDs, entries[i].shortName)) // Tries to install the CIA 3 times then give up. If it has to give up, that probably means brick.
					if (!installCIA(ciaPath, mediatype, titleIDs, entries[i].shortName))
						return false;

			break;
		}
		free(ciaPath);
	}

	for (i = 0; i < actualAmount; i++) {
		ciaPath = malloc(14 + strlen(entries[i].shortName));
		strcpy(ciaPath, "/tmp/cias/");
		strcat(ciaPath, entries[i].shortName);
		strcat(ciaPath, ".cia");
		if (!installCIA(ciaPath, mediatype, titleIDs, entries[i].shortName))
			if (!installCIA(ciaPath, mediatype, titleIDs, entries[i].shortName)) // Tries to install the CIA 3 times then give up. If it has to give up, that probably means brick.
				installCIA(ciaPath, mediatype, titleIDs, entries[i].shortName);

		free(ciaPath);
	}

	FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_ASCII, "/tmp/cias"));

	FSUSER_CloseArchive(&archive);

	free(titleIDs);

	return true;

}