bool CimTask::checkFile() { string ftpfile = m_ftpPath+"/" +m_cimName; string workfile = m_workPath + "/" +m_cimName; if (ACE_OS::access(workfile.c_str(),0) == -1) { // 工作目录文件不存在,不用比较,直接把文件拷贝到工作目录 if(!fileCopy(ftpfile.c_str(),workfile.c_str())) { return false; } else { LOG->message("拷贝CIM文件到工作目录成功"); return true; } } else { // 如果工作目录已经存在文件,则进行文件比较,比较最后修改时间 if (needUpdate(workfile.c_str(),ftpfile.c_str())) { if(fileCopy(workfile.c_str(),ftpfile.c_str())) { LOG->message("拷贝CIM文件到工作目录成功"); return true; } } } return false; }
// AddFile //------------------------------------------------------------------------------ void VSProjectGenerator::AddFile( const AString & file, bool filterByExtension ) { // ensure slash consistency which we rely on later AStackString<> fileCopy( file ); fileCopy.Replace( FORWARD_SLASH, BACK_SLASH ); // filtering by extension? size_t numAllowedFileExtensions = m_AllowedFileExtensions.GetSize(); if ( filterByExtension && numAllowedFileExtensions ) { bool keep = false; for ( size_t i=0; i<numAllowedFileExtensions; ++i ) { if ( file.EndsWithI( m_AllowedFileExtensions[ i ] ) ) { keep = true; break; } } if ( !keep ) { return; } } ASSERT( !m_Files.Find( fileCopy ) ); m_Files.Append( fileCopy ); }
void copyImgAndMeta(const char *src, const char *dst) { char * src_meta_file = appendExt(src, ".meta"); char * src_img_file = appendExt(src, ".img"); char * dst_meta_file = appendExt(dst, ".meta"); char * dst_img_file = appendExt(dst, ".img"); fileCopy(src_meta_file, dst_meta_file); fileCopy(src_img_file, dst_img_file); free(src_meta_file); free(src_img_file); free(dst_meta_file); free(dst_img_file); }
// AddFile //------------------------------------------------------------------------------ void VSProjectGenerator::AddFile( const AString & file ) { // ensure slash consistency which we rely on later AStackString<> fileCopy( file ); fileCopy.Replace( FORWARD_SLASH, BACK_SLASH ); ASSERT( !m_Files.Find( fileCopy ) ); m_Files.Append( fileCopy ); }
void filter_srfs(char *sensor, char *beam_mode, char *input_dir, char *output_dir) { struct dirent *dp; struct stat statbuf; DIR *dir; int nFiles= 0; char file_name[25], source[1024], target[1024]; // Some more error checking on beam modes if (strcmp_case(sensor, "R1") == 0) { if (strcmp_case(beam_mode, "FN1") != 0 && strcmp_case(beam_mode, "FN2") != 0 && strcmp_case(beam_mode, "FN3") != 0 && strcmp_case(beam_mode, "FN4") != 0 && strcmp_case(beam_mode, "FN5") != 0 && strcmp_case(beam_mode, "ST1") != 0 && strcmp_case(beam_mode, "ST2") != 0 && strcmp_case(beam_mode, "ST3") != 0 && strcmp_case(beam_mode, "ST4") != 0 && strcmp_case(beam_mode, "ST5") != 0 && strcmp_case(beam_mode, "ST6") != 0 && strcmp_case(beam_mode, "ST7") != 0) asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n", beam_mode, sensor); } else if (strcmp_case(sensor, "E1") == 0 || strcmp_case(sensor, "E2") == 0 || strcmp_case(sensor, "J1") == 0) { if (strcmp_case(beam_mode, "STD") != 0) asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n", beam_mode, sensor); } // Read directory for scan results files of sensor + beam mode asfPrintStatus("Filtering scan results file directory ...\n\n"); chdir(input_dir); dir = opendir(input_dir); while ((dp = readdir(dir)) != NULL) { if (stat(dp->d_name, &statbuf) == -1) continue; sprintf(file_name, "%s", dp->d_name); if (get_basic_info(file_name, sensor, beam_mode) && !S_ISDIR(statbuf.st_mode)) { sprintf(source, "%s/%s", input_dir, file_name); sprintf(target, "%s/%s", output_dir, file_name); fileCopy(source, target); nFiles++; asfPrintStatus("\rNumber of scan results files read: %6d", nFiles); } } closedir(dir); printf("\n"); }
/* Function: watch(char*, char**) * Parameters: filePath - The path to the file to watch * message - A pointer to a string that will contain error msgs * Return: EXIT_SUCCESS - No error occured * EXIT_FAILURE - Error(s) occurred and message is set * This function creates the watch directory (If it doesn't exist) and then * makes a copy of the specified file in the watch directory. This will allow * us to diff the contents of the file in the watch directory with files that * are being changed. */ int watch(const char* filePath, char** message) { /* First thing we need to do is see if the specified file exists */ int statResults; struct stat fileInfo; char destPath[BUFSIZ]; FILE* sourceFile; FILE* destFile; char watchFilePath[BUFSIZ]; /* Call stat on the file to see if it exists */ statResults = stat(filePath, &fileInfo); if (statResults == -1) { asprintf(message, ERROR_FILE_DOES_NOT_EXIST, filePath); return EXIT_FAILURE; } /* We are sure that the file exists. Now check to see if the watch * directory exists */ statResults = stat(WATCH_DIR, &fileInfo); if (statResults == -1) { /* The watch directory doesn't exist. Create it */ mkdir(WATCH_DIR, 0700); } /* Good. The watch directory and file to watch are present. Now copy the * file to watch into the watch directory */ strcpy(watchFilePath, filePath); strcpy(destPath, WATCH_DIR); strcat(destPath, watchFilePath); sourceFile = fopen(filePath, "r"); destFile = fopen(destPath, "w"); if (sourceFile == NULL) { asprintf(message, ERROR_WATCH_READ_FAIL, filePath); return EXIT_FAILURE; } if (destFile == NULL) { asprintf(message, ERROR_WATCH_WRITE_FAIL, filePath); return EXIT_FAILURE; } if (fileCopy(sourceFile, destFile) == EXIT_FAILURE) { /* An error occured with the copy */ asprintf(message, ERROR_WATCH_COPY_FAIL, filePath); return EXIT_FAILURE; } /* Now the file is copied so it is considered to be watched. */ return EXIT_SUCCESS; }
/*! * regTestCheckFile() * * Input: rp (regtest parameters) * localname (name of output file from reg test) * Return: 0 if OK, 1 on error (a failure in comparison is not an error) * * Notes: * (1) This function does one of three things, depending on the mode: * * "generate": makes a "golden" file as a copy @localname. * * "compare": compares @localname contents with the golden file * * "display": makes the @localname file but does no comparison * (2) The canonical format of the golden filenames is: * /tmp/golden/<root of main name>_golden.<index>.<ext of localname> * e.g., * /tmp/golden/maze_golden.0.png * It is important to add an extension to the local name, because * the extension is added to the name of the golden file. */ l_int32 regTestCheckFile(L_REGPARAMS *rp, const char *localname) { char *ext; char namebuf[256]; l_int32 ret, same; PROCNAME("regTestCheckFile"); if (!rp) return ERROR_INT("rp not defined", procName, 1); if (!localname) { rp->success = FALSE; return ERROR_INT("local name not defined", procName, 1); } if (rp->mode != L_REG_GENERATE && rp->mode != L_REG_COMPARE && rp->mode != L_REG_DISPLAY) { rp->success = FALSE; return ERROR_INT("invalid mode", procName, 1); } rp->index++; if (rp->mode == L_REG_DISPLAY) return 0; /* Generate the golden file name; used in 'generate' and 'compare' */ splitPathAtExtension(localname, NULL, &ext); snprintf(namebuf, sizeof(namebuf), "/tmp/golden/%s_golden.%d%s", rp->testname, rp->index, ext); FREE(ext); if (rp->mode == L_REG_GENERATE) { /* Save the file as a golden file */ /* fprintf(stderr, "%d: %s\n", rp->index, namebuf); */ ret = fileCopy(localname, namebuf); if (!ret) fprintf(stderr, "Copy: %s to %s\n", localname, namebuf); return ret; } /* Compare mode: test and record on failure */ filesAreIdentical(localname, namebuf, &same); if (!same) { fprintf(rp->fp, "Failure in %s_reg, index %d: comparing %s with %s\n", rp->testname, rp->index, localname, namebuf); fprintf(stderr, "Failure in %s_reg, index %d: comparing %s with %s\n", rp->testname, rp->index, localname, namebuf); rp->success = FALSE; } return 0; }
int main(int argc, char *argv[]) { int status = 0; char opt; int recurse = 0; int count; setlocale(LC_ALL, getenv(ENV_LANG)); textdomain("cp"); // There need to be at least a source and destination name if (argc < 3) { usage(argv[0]); return (status = ERR_ARGUMENTCOUNT); } // Check options while (strchr("Rr?", (opt = getopt(argc, argv, "Rr")))) { switch (opt) { case 'r': case 'R': // Recurse recurse = 1; break; default: fprintf(stderr, _("Unknown option '%c'\n"), optopt); usage(argv[0]); return (status = ERR_INVALID); } } for (count = optind; count < (argc - 1); count ++) { if (recurse) status = fileCopyRecursive(argv[count], argv[argc - 1]); else status = fileCopy(argv[count], argv[argc - 1]); if (status < 0) { fprintf(stderr, "%s: ", argv[count]); errno = status; perror(argv[0]); } } return (status); }
void Encrypt(PK0304* le, AE_EXTRA* ae, char* password) { char *salt, *key1, *key2, *check, digest[40]; u32 key_len = KeySize*2 + 2; u32 dig_len = 40; salt = BUF; key1 = salt+SaltSize; key2 = key1+KeySize; check = key2+KeySize; /* Gets a random salt (8-16 byte) */ sprng_read(salt, SaltSize, 0); /* Generates 2 keys for AES and HMAC, plus 2-byte password verification value */ if (pkcs_5_alg2(password, strlen(password), salt, SaltSize, 1000, 0, key1, &key_len) != CRYPT_OK) Z_ERROR("Failed to derive encryption keys"); // dump("salt", salt, SaltSize); // dump("key", key1, KeySize); if (ctr_start(0, IV, key1, KeySize, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr) != CRYPT_OK) Z_ERROR("Failed to setup AES CTR encoder"); #ifdef GLADMAN_HMAC hmac_sha1_begin(&hmac); hmac_sha1_key(key2, KeySize, &hmac); #else if (hmac_init(&hmac, 0, key2, KeySize) != CRYPT_OK) Z_ERROR("Failed to setup HMAC-SHA1"); #endif if (AE2) le->Crc32 = 0; le->Flag |= 1; le->CompMethod = 99; le->ExtraLen += 11; le->CompSize += SaltSize + 12; /* variable salt, fixed password check and hmac */ safeWrite(ZOUT, le, sizeof(PK0304)); fileCopy(ZOUT, ZIN, le->NameLen+le->ExtraLen-11); safeWrite(ZOUT, ae, 11); safeWrite(ZOUT, salt, SaltSize); safeWrite(ZOUT, check, 2); /* encrypt contents */ fileFilter(ZOUT, ZIN, le->CompSize-SaltSize-12); #ifdef GLADMAN_HMAC hmac_sha1_end(digest, dig_len, &hmac); #else if (hmac_done(&hmac, digest, &dig_len) != CRYPT_OK) Z_ERROR("Failed to computate HMAC"); #endif safeWrite(ZOUT, digest, 10); ctr_done(&ctr); }
static Boolean dir_copy(DirPtr dir, String target, Boolean absolute) { if (dirNFilesSelected(dir)) { SelPtr sel = selFromDir(dir); Boolean ret = fileCopy(sel, target, absolute); selFree(sel); update(); return ret; } else { root_modified = cur_modified = shelf_modified = cur_changed = False; return False; } }
/*! * regTestCheckFile() * * Input: stream (for output; use NULL to generate golden files) * argv ([0] == name of reg test) * localname (name of output file from reg test) * index (of the output file under test; 0-based for the reg test) * &success (<return> 0 on failure; input value on success) * Return: 0 if OK, 1 on error (a failure in comparison is not an error) * * Notes: * (1) This function either compares an input file with a "golden" file, * or generates a "golden" file as a copy @localname. * Call with @fp == NULL to generate a new golden file. * (2) This function can be called repeatedly in a single reg test. * (3) The value for @success is initialized to TRUE in the reg test * setup before this function is called for the first time. * A failure in any single file comparison is registered * as a failure of the regression test. * (4) The canonical format of the golden filenames is: * /tmp/<root of main name>_golden.<index>.<ext of localname> * e.g., * /tmp/maze_golden.0.png */ l_int32 regTestCheckFile(FILE *fp, char **argv, const char *localname, l_int32 index, l_int32 *psuccess) { char *root, *ext; char namebuf[64]; l_int32 ret, same; PROCNAME("regTestCheckFile"); if (!psuccess) return ERROR_INT("&success not defined", procName, 1); if (!localname) return ERROR_INT("local name not defined", procName, 1); if (index < 0) return ERROR_INT("index is negative", procName, 1); /* Generate the golden file name */ if ((root = getRootNameFromArgv0(argv[0])) == NULL) return ERROR_INT("invalid root", procName, 1); splitPathAtExtension(localname, NULL, &ext); snprintf(namebuf, sizeof(namebuf), "/tmp/%s_golden.%d%s", root, index, ext); FREE(root); FREE(ext); /* Save the file as a golden file */ if (!fp) { ret = fileCopy(localname, namebuf); if (!ret) fprintf(stderr, "Copy: %s to %s\n", localname, namebuf); return ret; } /* Test and record on failure */ filesAreIdentical(localname, namebuf, &same); if (!same) { fprintf(fp, "Failure in %s: comparing %s with %s\n", argv[0], localname, namebuf); fprintf(stderr, "Failure in %s: comparing %s with %s\n", argv[0], localname, namebuf); *psuccess = 0; } return 0; }
void GuiAppInstance::handleFileOpenEvent(const std::string &filename) { QString fileCopy( QString::fromUtf8( filename.c_str() ) ); fileCopy.replace( QLatin1Char('\\'), QLatin1Char('/') ); QString ext = QtCompat::removeFileExtension(fileCopy); if ( ext == QString::fromUtf8(NATRON_PROJECT_FILE_EXT) ) { AppInstance* app = getGui()->openProject(filename); if (!app) { Dialogs::errorDialog(tr("Project").toStdString(), tr("Failed to open project").toStdString() + ' ' + filename); } } else { appPTR->handleImageFileOpenRequest(filename); } }
FILE* android_fopen(const char* filename, const char* mode) { FILE* fp = NULL; char* resPath = VBStringGetCString(VBEngineGetResourcePath());//getResourcePath(); if ( strstr(filename, resPath) ) { if (access(filename, R_OK) == 0) { fp = fopen(filename, mode); } else { char name[128] = {0,}; char temp[256] = {0,}; char* p = NULL; const char* delim = "/"; strcpy(temp, filename); p = strtok((char*)temp, delim); if (p) { strcpy(name, p); } while (p) { p = strtok(NULL, delim); if (p) { strcpy(name, p); } } if (fileCopy(name, filename)) { fp = fopen(filename, mode); } else { return fp; } } } else { fp = fopen(filename, mode); } //LOGD("android_fopen() filename: %s, fp: %x", filename, fp); return fp; }
bool android_fcheck(const char* filename) { bool ret = false; char* resPath = getResourcePath(); if ( strstr(filename, (const char*)getResourcePath) ) { if (access(filename, R_OK) == 0) { ret = true; } else { char name[128] = {0,}; char temp[256] = {0,}; char* p = NULL; const char* delim = "/"; strcpy(temp, filename); p = strtok((char*)temp, delim); if (p) { strcpy(name, p); } while (p) { p = strtok(NULL, delim); if (p) { strcpy(name, p); } } if (fileCopy(name, filename)) { ret = true; } else { ret = false; } } } //LOGD("android_fcheck() filename: %s, ret: %x", filename, ret); return ret; }
/** * @brief backup a file */ bool OpenNICSystem::backup(QString filename) { return fileCopy(filename,QDateTime::currentDateTime().toString("yyMMddhhmmss")+filename+".bak"); }
int main() { SceCtrlData pad; int cancel = 0, uninstall = 0, reinstall = 0, lftv = 0, ok = 0, installed = 0, uninstalled = 0, autoExit = 0; SetupCallbacks(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_LTRIGGER) { quickinstall = 1; lftv = 1; } else if (pad.Buttons & PSP_CTRL_RTRIGGER) { quickinstall = 1; } if (fileExist(PRX_LFTVBACKUP) | fileExist(PRX_RPLYBACKUP)) uninstall = 1; sceGuInit(); sceGuStart(GU_DIRECT, list); sceGuClearColor(0xFFFFFFFF); sceGuDrawBuffer(GU_PSM_8888, (void*)0, BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH); sceGuDepthBuffer((void*)0x110000, BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH / 2), 2048 - (SCR_HEIGHT / 2)); sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT); sceGuDepthRange(0xc350, 0x2710); sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuDisable(GU_DEPTH_TEST); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuEnable(GU_TEXTURE_2D); sceGuTexMode(GU_PSM_8888, 0, 0, 0); sceGuTexImage(0, 256, 128, 256, font); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); sceGuTexEnvColor(0x0); sceGuTexOffset(0.0f, 0.0f); sceGuTexScale(1.0f / 256.0f, 1.0f / 128.0f); sceGuTexWrap(GU_REPEAT, GU_REPEAT); sceGuTexFilter(GU_NEAREST, GU_NEAREST); sceGuFinish(); sceGuSync(0,0); sceGuDisplay(GU_TRUE); // Check for low battery. if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); drawStringCenter("Battery charge should be at least 25% when modifying flash!", 40 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("Connect the AC adapter to ignore this warning and continue!", 40 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter(uninstall ? "Press any button to cancel uninstallation of warPSP." : "Press any button to cancel installation of warPSP.", 50 + (10 * i), 0xFF0000FF, 8); i += 2; drawObjects(); while (!scePowerIsPowerOnline()) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) { cancel = 1; break; } } } if (!cancel) { float c = 0.0; for (c = 10.0; c <= 100.0; c++) { unsigned int col = 0xFF000000 | (unsigned int)((c / 100.0) * 255.0f) << 16 | (unsigned int)((c / 100.0) * 255.0f) << 8 | (unsigned int)((c / 100.0) * 255.0f) << 0; sceGuClearColor(col); clearScreenPrintHeader(90); if (quickinstall & (c > 50)) drawStringCenter("Quick Install Activated!", 250, 0xFF006600, 8); drawObjects(); } sceKernelDelayThread(3000000); for (c = 100.0; c >= 10.0; c--) { unsigned int col = 0xFF000000 | (unsigned int)((c / 100.0) * 255.0f) << 16 | (unsigned int)((c / 100.0) * 255.0f) << 8 | (unsigned int)((c / 100.0) * 255.0f) << 0; sceGuClearColor(col); clearScreenPrintHeader(90); drawObjects(); } } sceGuClearColor(0xFFFFFFFF); // Show disclaimer and options. if (!cancel & !quickinstall) { sceGuStart(GU_DIRECT, list); sceGuClear(GU_COLOR_BUFFER_BIT); drawStringCenter("!!! DISCLAIMER !!!", 40 + (10 * i), 0xFF0000FF, 10); i += 2; drawStringCenter("This program modifies the flash drive of your Sony PSP.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("You accept the risk when running this installation app.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("DO NOT REMOVE THE MEMORY STICK WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("DO NOT TURN OFF THE PSP SYSTEM WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("Press START to acknowledge and to continue to briefing.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("Press SELECT to decline and to abort installing warPSP.", 60 + (10 * i), 0xFF0000FF, 8); i += 2; drawStringCenter("THE AUTHOR DOES NOT HOLD RESPONSIBILITY FOR ANY DAMAGE.", 60 + (10 * i), 0xFF0000FF, 8); i++; drawStringCenter("THIS SOFTWARE IS PRESENTED WITHOUT WARRANTY/GUARANTEES.", 60 + (10 * i), 0xFF0000FF, 8); i += 4; drawObjects(); while (1) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_START) { break; } if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; } } } // Check if backup file exists. if (!cancel & !quickinstall) { swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawStringCenter("Briefing", 50 + (10 * i), 0xFF000000, 0); i+= 2; drawStringCenter("Thanks for your interest in the warPSP Software Suite!", 50 + (10 * i), 0xFF006600, 0); i += 2; drawStringCenter("warPSP is an advanced warXing utility for the Sony PSP.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawStringCenter("Please see the README.TXT file for more information.", 50 + (10 * i), 0xFF660000, 8); i += 3; drawStringCenter("Options", 50 + (10 * i), 0xFF000000, 0); i += 2; if (uninstall) { drawStringCenter("Press SQUARE to uninstall warPSP and restore backup files.", 50 + (10 * i), 0xFF000000, 8); i++; drawStringCenter("Press CIRCLE to reinstall warPSP to the last slot selected.", 50 + (10 * i), 0xFF000000, 8); i++; } else { drawStringCenter("Press SQUARE to install warPSP to the LFTV Player slot.", 50 + (10 * i), 0xFF000000, 8); i++; drawStringCenter("Press CIRCLE to install warPSP to the Remote Play slot.", 50 + (10 * i), 0xFF000000, 8); i++; } drawStringCenter(uninstall ? "Press SELECT to cancel uninstallation of warPSP and exit." : "Press SELECT to cancel installation of warPSP and exit.", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects(); while (1) { sceCtrlReadBufferPositive(&pad, 1); if (uninstall) { if (pad.Buttons & PSP_CTRL_SQUARE) { break; } if (pad.Buttons & PSP_CTRL_CIRCLE) { uninstall = 0; reinstall = 1; if (fileExist(PRX_LFTVBACKUP)) lftv = 1; else lftv = 0; break; } } else { if (pad.Buttons & PSP_CTRL_SQUARE) { lftv = 1; break; } if (pad.Buttons & PSP_CTRL_CIRCLE) { lftv = 0; break; } } if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; } } } if (!cancel) { if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter(" Battery is below 25%% and AC adapter is not connected!", 50 + (10 * i), 0xFF000099, 0); i += 2; cancel = 1; drawObjects(); } } if (cancel) { swapBuffers(); sceGuStart(GU_DIRECT, list); sprintf(buffer, "%sstallation cancelled!", uninstall ? "Unin" : "In"); drawStringCenter(buffer, 50 + (10 * i), 0xFF0000FF, 0); i += 2; drawObjects(); sceKernelDelayThread(1000000); } // Perform installation, uninstallation or reinstallation. if (!cancel) { scePowerLock(0); swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter(uninstall ? "Uninstallation" : "Installation", 50 + (10 * i), 0xFF990000, 0); i += 2; if (quickinstall) { drawStringCenter("Quick installing warPSP to the location free player slot.", 50 + (10 * i), 0xFF990000, 0); i += 2; } drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list); if (uninstall) { if (fileExist(PRX_LFTVBACKUP)) { lftv = 1; ok = 1; } else if (fileExist(PRX_RPLYBACKUP)) { lftv = 0; ok = 1; } if (ok) { drawStringCenter("Backup prx found. Ok to uninstall!", 50 + (10 * i), 0xFF990000, 8); i++; drawStringCenter("The backup prx will be copied to the flash drive of your PSP!", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects(); if (fileCopy(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstalled successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP); uninstalled = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstallation failed!", 50 + (10 * i), 0xFF000099, 8); } i += 2; drawObjects(); if (uninstalled) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("To reinstall warPSP, rerun the Easy Installation Program.", 50 + (10 * i), 0xFF990000, 8); i += 2; drawObjects(); } } } else { if (fileExist(PRX_WARPSP_XMB)) { sceIoRemove(PRX_WARPSP_XMB); sceKernelDelayThread(1000000); } drawStringCenter("Extracting warPSP.prx to the root of the memory stick.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects(); sceKernelDelayThread(2000000); // Open PBP file and read contents into the buffer. int pbpFile, prxFile, pkgSize = 0, prxSize = 0; char buf[1024*1024]; pbpFile = sceIoOpen(PBP_WARPSP_EIP, PSP_O_RDONLY, 0); sceKernelDelayThread(1000000); if (pbpFile) { // Get size of entire package. pkgSize = sceIoRead(pbpFile, buf, sizeof(buf)); sceKernelDelayThread(1000000); if (pkgSize > 0) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP loaded into memory successfully!", 50 + (10 * i), 0xFF006600, 8); i += 2; drawObjects(); // Calculate size of prx to extract (size of entire package - size of eboot.pbp). prxSize = pkgSize - pbpSize; // Open PRX file and write buffer into the contents. prxFile = sceIoOpen(PRX_WARPSP_XMB, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777); sceKernelDelayThread(100000); if (prxFile) { // Write prx file from end of eboot.pbp. sceIoWrite(prxFile, buf + pbpSize, prxSize); sceKernelDelayThread(1000000); sceIoClose(prxFile); sceKernelDelayThread(1000000); swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extracted from memory successfully!", 50 + (10 * i), 0xFF006600, 8); drawObjects(); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extraction from memory failed!", 50 + (10 * i), 0xFF000099, 8); drawObjects(); } i += 2; } sceIoClose(pbpFile); sceKernelDelayThread(1000000); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP load into memory failed!", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects(); } buf[0] = (char)"\0"; swapBuffers(); sceGuStart(GU_DIRECT, list); if (!fileExist(PRX_WARPSP_XMB)) { drawStringCenter("warPSP.prx not found! Install cancelled!", 50 + (10 * i), 0xFF000099, 8); } else { drawStringCenter("warPSP.prx found. Ok to install!", 50 + (10 * i), 0xFF006600, 8); ok = 1; } i += 2; drawObjects(); // Create backup of original file and install warPSP. if (ok) { if (!reinstall) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("The backup file will be copied to the memory stick!", 50 + (10 * i), 0xFF990000, 8); i++; drawObjects(); if (fileCopy(lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY, lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file backed up successfully!", 50 + (10 * i), 0xFF006600, 8); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file back up failed!", 50 + (10 * i), 0xFF000099, 8); } i += 2; drawObjects(); } if (fileCopy(PRX_WARPSP_XMB, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installed successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(PRX_WARPSP_XMB); installed = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installation failed!", 50 + (10 * i), 0xFF000099, 8); installed = 0; } i += 2; drawObjects(); } } scePowerUnlock(0); } if (installed | uninstalled) { sceKernelDelayThread(1000000); } if (!quickinstall) { swapBuffers(); sceGuStart(GU_DIRECT, list); sprintf(buffer, "Press any button to %s! (Auto-Exit in 10s).", (installed | uninstalled) ? "restart the PSP" : "return to the xmb"); drawStringCenter(buffer, 50 + (10 * i), 0xFF000000, 8); i++; if (installed) { drawStringCenter("Happy warXing!", 50 + (10 * i), 0xFF006600, 8); i++; } else if (uninstalled) { drawStringCenter("Thank you for using warPSP", 50 + (10 * i), 0xFF990000, 8); i++; } drawObjects(); // Wait for exit. while (1) { if (autoExit >= 1000) break; sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) break; sceKernelDelayThread(10000); autoExit++; } } if (quickinstall) { sceKernelDelayThread(1000000); } swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Exiting!", 50 + (10 * i), (installed | uninstalled) ? 0xFF990000 : 0xFF0000FF, 8); drawObjects(); if (installed | uninstalled) { sceKernelExitGame(); scePower_0442D852(50000); } else { sceKernelExitGame(); } return 0; }
int makeStartupHtml (struct ViewerApp *param) { FILE *fp; char helphtmlpath[1024]; char imtypehtmlpath[1024]; char cursorhtmlpath[1024]; char viewhtmlpath[1024]; char viewtemplatepath[1024]; char planeoptionpath[1024]; char **arr; char imfile[1024]; char fpath[1024]; char str[1024]; char *cptr; char imcontroltemplatepath[1024]; char graylistoptionPath[1024]; char redlistoptionPath[1024]; char grnlistoptionPath[1024]; char bluelistoptionPath[1024]; char srctbloptionPath[1024]; char iminfooptionPath[1024]; char rootname[128]; char suffix[20]; char varstr[32768]; char status[32]; int l; int istatus; int selectedIndx; int fileExist; int viewhtmlExist; int helphtmlExist; int imtypehtmlExist; int cursorhtmlExist; double cdelt3; double crval3; int debugfile = 1; if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "From makeStartupHtml\n"); fprintf (fp_debug, "isimcube= [%d]\n", param->isimcube); fprintf (fp_debug, "gridvis[0]= [%d]\n", param->gridvis[0]); fprintf (fp_debug, "redfile= [%s] grnfile= [%s] bluefile= [%s]\n", param->redfile, param->grnfile, param->bluefile); fprintf (fp_debug, "viewhtml= [%s]\n", param->viewhtml); fprintf (fp_debug, "directory= [%s]\n", param->directory); fprintf (fp_debug, "Make viewhtml from template\n"); fflush (fp_debug); } /* Check if viewhtml is in workspace or datadir. */ if ((int)strlen(param->helphtml) > 0) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "\nhelphtml specified: helphtml= [%s]\n", param->helphtml); fflush (fp_debug); } helphtmlExist = checkFileExist (param->helphtml, rootname, suffix, param->datadir, fpath); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "checkFileExist(helphtml): helphtmlExist= [%d]\n", helphtmlExist); fprintf (fp_debug, "fpath= [%s]\n", fpath); fflush (fp_debug); } if (helphtmlExist) { sprintf (helphtmlpath, "%s/%s", param->directory, param->helphtml); if (strcasecmp (fpath, helphtmlpath) != 0) { istatus = fileCopy (fpath, helphtmlpath, param->errmsg); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "helphtml copied from datadir to directory"); fflush (fp_debug); } } else { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "helphtmlpath= [%s] already exists\n", imtypehtmlpath); fflush (fp_debug); } } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "helphtmlpath= [%s]\n", helphtmlpath); fflush (fp_debug); } } if ((int)strlen(param->imtypehtml) > 0) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "\nimtypehtml specified in inparam file\n"); fflush (fp_debug); } imtypehtmlExist = checkFileExist (param->imtypehtml, rootname, suffix, param->datadir, fpath); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "checkFileExist(imtypehtml): imtypehtmlExist= [%d]\n", imtypehtmlExist); fprintf (fp_debug, "fpath= [%s]\n", fpath); fflush (fp_debug); } if (imtypehtmlExist) { sprintf (imtypehtmlpath, "%s/%s", param->directory, param->imtypehtml); if (strcasecmp (fpath, imtypehtmlpath) != 0) { istatus = fileCopy (fpath, imtypehtmlpath, param->errmsg); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "imtypehtml copied from datadir to directory"); fflush (fp_debug); } } else { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "imtypehtmlpath= [%s] already exists\n", imtypehtmlpath); fflush (fp_debug); } } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "imtypehtmlpath= [%s]\n", imtypehtmlpath); fflush (fp_debug); } } if ((int)strlen(param->cursorhtml) > 0) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "\ncursorhtml specified in inparam file\n"); fflush (fp_debug); } cursorhtmlExist = checkFileExist (param->cursorhtml, rootname, suffix, param->datadir, fpath); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "checkFileExist(cursorhtml): cursorhtmlExist= [%d]\n", cursorhtmlExist); fprintf (fp_debug, "fpath= [%s]\n", fpath); fflush (fp_debug); } if (cursorhtmlExist) { sprintf (cursorhtmlpath, "%s/%s", param->directory, param->cursorhtml); if (strcasecmp (fpath, cursorhtmlpath) != 0) { istatus = fileCopy (fpath, cursorhtmlpath, param->errmsg); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "cursorhtml copied from datadir to directory"); fflush (fp_debug); } } else { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "cursorhtmlpath= [%s] already exists\n", cursorhtmlpath); fflush (fp_debug); } } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "cursorhtmlpath= [%s]\n", cursorhtmlpath); fflush (fp_debug); } } if ((int)strlen(param->viewhtml) > 0) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "\nviewhtml specified in inparam file\n"); fflush (fp_debug); } viewhtmlExist = checkFileExist (param->viewhtml, rootname, suffix, param->datadir, fpath); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "checkFileExist(viewhtml): viewhtmlExist= [%d]\n", viewhtmlExist); fprintf (fp_debug, "fpath= [%s]\n", fpath); fflush (fp_debug); } if (viewhtmlExist) { sprintf (viewhtmlpath, "%s/%s", param->directory, param->viewhtml); istatus = fileCopy (fpath, viewhtmlpath, param->errmsg); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "viewhtml copied from datadir to directory"); fflush (fp_debug); } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "viewhtmlpath= [%s]\n", viewhtmlpath); fflush (fp_debug); } } else { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "Make viewhtml from template\n"); fflush (fp_debug); } strcpy (str, param->viewtemplate); cptr = (char *)NULL; cptr = strrchr (str, '.'); if (cptr != (char *)NULL) { *cptr = '\0'; } sprintf (param->viewhtml, "%s.html", str); sprintf (param->viewhtmlpath, "%s/%s", param->directory, param->viewhtml); fileExist = checkFileExist (param->viewtemplate, rootname, suffix, param->datadir, viewtemplatepath); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "viewtemplate fileExist= [%d] in datadir= [%s])\n", fileExist, param->datadir); fprintf (fp_debug, "viewtemplatepath= [%s]\n", viewtemplatepath); fflush (fp_debug); } if (!fileExist) { strcpy (param->errmsg, "Failed to find view template in either datadir\n"); return (-1); } /* Read FitsHdr to extract special keywords: objname, filter, and pixscale for display. If it is a fits cube, find out nfitsplane too. Note: Only deal with grayfile at present. */ if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "nfitsplane= [%d]\n", param->nfitsplane); fflush (fp_debug); } if (param->isimcube) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here1: isimcube\n"); fflush (fp_debug); } if (param->nfitsplane > 0) { sprintf (planeoptionpath, "%s/planeoption.txt", param->directory); arr = (char **)malloc (param->nfitsplane*sizeof(char *)); for (l=0; l<param->nfitsplane; l++) { arr[l] = (char *)malloc (10*sizeof(char)); sprintf (arr[l], "%d", (l+1)); } selectedIndx = 0; if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "call writeOptionList\n"); fflush (fp_debug); } istatus = writeOptionList (planeoptionpath, param->nfitsplane, arr, selectedIndx, param->errmsg); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "returned writeOptionList\n"); fflush (fp_debug); } } } /* If nim_gray > 1, make imlistoption interface for replace image */ if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "nim_gray= [%d]\n", param->nim_gray); fflush (fp_debug); } if (param->nim_gray > 1) { sprintf (graylistoptionPath, "%s/graylistoption.txt", param->directory); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "graylistoptionPath= [%s]\n", graylistoptionPath); fflush (fp_debug); } fp = (FILE *)NULL; param->errmsg[0] = '\0'; if ((fp = fopen(graylistoptionPath, "w+")) == (FILE *)NULL) { sprintf (param->errmsg, "Failed to create file [%s] in workspace", graylistoptionPath); return (-1); } fprintf (fp, "<option vallue=\"\" selected=\"selected\">\n"); fprintf (fp, "</option>\n"); for (l=0; l<param->nim_gray; l++) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "l= [%d] imfile= [%s]\n", l, param->imfile[l]); fflush (fp_debug); } fprintf (fp, "<option vallue=\"%s\">%s</option>\n", param->imfile[l], param->imfile[l]); } fclose (fp); } else { redlistoptionPath[0] = '\0'; grnlistoptionPath[0] = '\0'; bluelistoptionPath[0] = '\0'; } /* If nsrctbl > 1, make srctbloption interface for adding srctbl */ if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "nsrctbl= [%d]\n", param->nsrctbl); fflush (fp_debug); } if (param->nsrctbl > 0) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "\nwrite srctblOption file for html page\n"); fflush (fp_debug); } sprintf (srctbloptionPath, "%s/srctbloption.txt", param->directory); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "srctbloptionPath= [%s]\n", srctbloptionPath); fflush (fp_debug); } fp = (FILE *)NULL; param->errmsg[0] = '\0'; if ((fp = fopen(srctbloptionPath, "w+")) == (FILE *)NULL) { sprintf (param->errmsg, "Failed to create file [%s] in workspace", srctbloptionPath); return (-1); } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here2\n"); fflush (fp_debug); } fprintf (fp, "<option vallue=\"\" selected=\"selected\">\n"); fprintf (fp, "</option>\n"); for (l=0; l<param->nsrctbl; l++) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "l= [%d] srctblfile= [%s]\n", l, param->srctblfile[l]); fflush (fp_debug); } fprintf (fp, "<option vallue=\"%s\">%s</option>\n", param->srctblfile[l], param->srctblfile[l]); } fclose (fp); } /* If niminfo >= 1, make iminfooption interface for adding iminfo */ if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "niminfo= [%d]\n", param->niminfo); fflush (fp_debug); } if (param->niminfo > 0) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here3\n"); fflush (fp_debug); } sprintf (iminfooptionPath, "%s/iminfooption.txt", param->directory); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "iminfooptionPath= [%s]\n", iminfooptionPath); fflush (fp_debug); } fp = (FILE *)NULL; param->errmsg[0] = '\0'; if ((fp = fopen(iminfooptionPath, "w+")) == (FILE *)NULL) { sprintf (param->errmsg, "Failed to create file [%s] in workspace", iminfooptionPath); return (-1); } fprintf (fp, "<option vallue=\"\" selected=\"selected\">\n"); fprintf (fp, "</option>\n"); for (l=0; l<param->niminfo; l++) { if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "l= [%d] iminfofile= [%s]\n", l, param->iminfofile[l]); fflush (fp_debug); } fprintf (fp, "<option vallue=\"%s\">%s</option>\n", param->iminfofile[l], param->iminfofile[l]); } fclose (fp); } /* Make viewer html from template -- always requires a template */ if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here4\n"); fflush (fp_debug); } if (param->isimcube) { strcpy (imfile, param->imcubepath); } else { strcpy (imfile, param->grayfile); } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "isimcube= [%d]\n", param->isimcube); fprintf (fp_debug, "imfile= [%s]\n", imfile); fprintf (fp_debug, "cdelt3= [%lf]\n", param->cdelt3); fprintf (fp_debug, "crval3= [%lf]\n", param->crval3); fflush (fp_debug); } varcmd (varstr, 32768, "htmlgen", "%s", viewtemplatepath, "%s", param->viewhtmlpath, "winname", "%s", param->winname, "workspace", "%s", param->workspace, "httpurl", "%s", param->baseurl, "isimcube", "%d", param->isimcube, "nplane", "%d", param->nfitsplane, "cdelt3", "%lf", param->cdelt3, "crval3", "%lf", param->crval3, "imfile", "%s", imfile, "grayfile", "%s", param->grayfile, "imcubepath", "%s", param->imcubepath, "redfile", "%s", param->redfile, "grnfile", "%s", param->grnfile, "bluefile", "%s", param->bluefile, "jsonfile", "%s", param->jsonfile, "planeoption", "%s", planeoptionpath, "title", "%s", param->divname, "imname", "%s", param->imname, "divname", "%s", param->divname, "viewdiv", "%sview", param->divname, "refdiv", "%sref", param->divname, "canvaswidth", "%d", param->canvaswidth, "canvasheight", "%d", param->canvasheight, "refwidth", "%d", param->refwidth, "refheight", "%d", param->refheight, "viewcgiurl", "%s", param->viewcgiurl, "tblcgiurl", "%s", param->tblcgiurl, "tblwidth", "%d", param->tblwidth, "tblheight", "%d", param->tblheight, "graylistoption", "%s", graylistoptionPath, "srctbloption", "%s", srctbloptionPath, "iminfooption", "%s", iminfooptionPath, "objname", "%s", param->objname, "filter", "%s", param->filter, "pixscale", "%s", param->pixscale, "END_PARM"); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr); fflush (fp_debug); } /* Add imlist, srctbl and iminfo list elements */ if (param->nim_gray > 0) { for (l=0; l<param->nim_gray; l++) { sprintf (str, " \"imfile%d\" \"%s\"", l, param->imfile[l]); strcat (varstr, str); } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr); fflush (fp_debug); } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here5\n"); fflush (fp_debug); } if (param->nim_color > 0) { for (l=0; l<param->nim_color; l++) { sprintf (str, " \"rimfile%d\" \"%s\"", l, param->rimfile[l]); strcat (varstr, str); sprintf (str, " \"gimfile%d\" \"%s\"", l, param->gimfile[l]); strcat (varstr, str); sprintf (str, " \"bimfile%d\" \"%s\"", l, param->bimfile[l]); strcat (varstr, str); } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr); fflush (fp_debug); } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here6\n"); fflush (fp_debug); } if (param->nsrctbl > 0) { for (l=0; l<param->nsrctbl; l++) { sprintf (str, " \"srctblfile%d\" \"%s\"", l, param->srctblfile[l]); strcat (varstr, str); } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr); fflush (fp_debug); } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "here7\n"); fflush (fp_debug); } if (param->niminfo > 0) { for (l=0; l<param->niminfo; l++) { sprintf (str, " \"iminfofile%d\" \"%s\"", l, param->iminfofile[l]); strcat (varstr, str); } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr); fflush (fp_debug); } } if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "Run varstr (viewhtml)= [%s]\n", varstr); fflush (fp_debug); } istatus = svc_run (varstr); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "returned svc_run: istatus= [%d]\n", istatus); fflush (fp_debug); } strcpy( status, svc_value( "stat" )); if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "status= [%s]\n", status); fflush (fp_debug); } if (strcasecmp( status, "error") == 0) { strcpy (param->errmsg, svc_value("msg")); return (-1); } } /* If input paramfile provides neither tbldisphtml nor tbldisptemplate, return error. */ if ((debugfile) && (fp_debug != (FILE *)NULL)) { fprintf (fp_debug, "nsrctbl= [%d] niminfo= [%d]\n", param->nsrctbl, param->niminfo); fflush (fp_debug); } return (0); }
void Rimp::copyFromDatastoreToRepository(const std::string& virtualMachineUUID, const std::string& snapshot, const std::string& destinationRepositoryPathIn, const std::string& sourceDatastorePathIn) { string error(""); RimpException rexecption; checkRimpConfiguration(); string destinationRepositoryPath(repository); destinationRepositoryPath = destinationRepositoryPath.append(destinationRepositoryPathIn); string sourceDatastorePath(sourceDatastorePathIn); if (destinationRepositoryPath.at(destinationRepositoryPath.size() - 1) != '/') { destinationRepositoryPath = destinationRepositoryPath.append("/"); } if (sourceDatastorePath.at(sourceDatastorePath.size() - 1) != '/') { sourceDatastorePath = sourceDatastorePath.append("/"); } /** * TODO destination repository concat configured ''repository'' * */ LOG("[DEBUG] [RIMP] Creating virtual machine [%s] instance [%s] from [%s] to [%s]", virtualMachineUUID.c_str(), snapshot.c_str(), sourceDatastorePath.c_str(), destinationRepositoryPath.c_str()); // Check destination repository folder exist and can be written if (access(destinationRepositoryPath.c_str(), F_OK | W_OK) == -1) { int err = mkdir(destinationRepositoryPath.c_str(), S_IRWXU | S_IRWXG); if (err == -1) { error = error.append("Can not create destination ''repository'' folder at :"); error = error.append(destinationRepositoryPath).append(" Caused by: ").append(strerror(errno)); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } } string viDatastoreSource(sourceDatastorePath); viDatastoreSource = viDatastoreSource.append(virtualMachineUUID); // Check source file exist and can be read if (access(viDatastoreSource.c_str(), F_OK | R_OK) == -1) { error = error.append("Source file does not exist or can not be read: "); error = error.append(viDatastoreSource); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } string viRepositoryDestination(destinationRepositoryPath); viRepositoryDestination = viRepositoryDestination.append(snapshot); // Check target path do not exist if (access(viRepositoryDestination.c_str(), F_OK) == 0) { error = error.append("Snapshot already exists on the repository: "); error = error.append(viRepositoryDestination); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } // Checking there are enough free space to copy unsigned long int viSize = getFileSize(viDatastoreSource); unsigned long int repositoryFreeSize = getFreeSpaceOn(destinationRepositoryPath); if (repositoryFreeSize < viSize) { error = error.append("There is no enough space left to copy the file :"); error = error.append(viDatastoreSource).append(" to :").append(viRepositoryDestination); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } string errorCopy = fileCopy(viDatastoreSource, viRepositoryDestination); if (!errorCopy.empty()) { error = error.append("Can not copy to :"); error = error.append(viRepositoryDestination).append("\nCaused by :").append(errorCopy); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } LOG("[INFO] [RIMP] Created snapshot [%s] from virtual machine [%s]", snapshot.c_str(), virtualMachineUUID.c_str()); }
/*! * regTestCheckFile() * * Input: rp (regtest parameters) * localname (name of output file from reg test) * Return: 0 if OK, 1 on error (a failure in comparison is not an error) * * Notes: * (1) This function does one of three things, depending on the mode: * * "generate": makes a "golden" file as a copy @localname. * * "compare": compares @localname contents with the golden file * * "display": makes the @localname file but does no comparison * (2) The canonical format of the golden filenames is: * /tmp/golden/<root of main name>_golden.<index>.<ext of localname> * e.g., * /tmp/golden/maze_golden.0.png * It is important to add an extension to the local name, because * the extension is added to the name of the golden file. */ l_int32 regTestCheckFile(L_REGPARAMS *rp, const char *localname) { char *ext; char namebuf[256]; l_int32 ret, same, format; PIX *pix1, *pix2; PROCNAME("regTestCheckFile"); if (!rp) return ERROR_INT("rp not defined", procName, 1); if (!localname) { rp->success = FALSE; return ERROR_INT("local name not defined", procName, 1); } if (rp->mode != L_REG_GENERATE && rp->mode != L_REG_COMPARE && rp->mode != L_REG_DISPLAY) { rp->success = FALSE; return ERROR_INT("invalid mode", procName, 1); } rp->index++; /* If display mode, no generation and no testing */ if (rp->mode == L_REG_DISPLAY) return 0; /* Generate the golden file name; used in 'generate' and 'compare' */ splitPathAtExtension(localname, NULL, &ext); snprintf(namebuf, sizeof(namebuf), "/tmp/golden/%s_golden.%02d%s", rp->testname, rp->index, ext); FREE(ext); /* Generate mode. No testing. */ if (rp->mode == L_REG_GENERATE) { /* Save the file as a golden file */ ret = fileCopy(localname, namebuf); #if 0 /* Enable for details on writing of golden files */ if (!ret) { char *local = genPathname(localname, NULL); char *golden = genPathname(namebuf, NULL); L_INFO("Copy: %s to %s\n", procName, local, golden); FREE(local); FREE(golden); } #endif return ret; } /* Compare mode: test and record on failure. GIF compression * is lossless for images with up to 8 bpp (but not for RGB * because it must generate a 256 color palette). Although * the read/write cycle for GIF is idempotent in the image * pixels for bpp <= 8, it is not idempotent in the actual * file bytes. Tests comparing file bytes before and after * a GIF read/write cycle will fail. So for GIF we uncompress * the two images and compare the actual pixels. From my tests, * PNG, in addition to being lossless, is idempotent in file * bytes on read/write, so comparing the pixels is not necessary. * (It also increases the regression test time by an an average * of about 8%.) JPEG is lossy and not idempotent in the image * pixels, so no tests are constructed that would require it. */ findFileFormat(localname, &format); if (format == IFF_GIF) { same = 0; pix1 = pixRead(localname); pix2 = pixRead(namebuf); pixEqual(pix1, pix2, &same); pixDestroy(&pix1); pixDestroy(&pix2); } else { filesAreIdentical(localname, namebuf, &same); } if (!same) { fprintf(rp->fp, "Failure in %s_reg, index %d: comparing %s with %s\n", rp->testname, rp->index, localname, namebuf); fprintf(stderr, "Failure in %s_reg, index %d: comparing %s with %s\n", rp->testname, rp->index, localname, namebuf); rp->success = FALSE; } return 0; }
void MainWindow::startDcp() { QString path; QString filename; QFileInfo source; QFileInfo destination; QMessageBox msgBox; QString DCP_FAIL_MSG; asset_list_t reelList[MAX_REELS]; opendcp_t *xmlContext = opendcp_create(); DCP_FAIL_MSG = tr("DCP Creation Failed"); // process options xmlContext->log_level = 0; if (ui->digitalSignatureCheckBox->checkState()) { xmlContext->xml_signature.sign = 1; xmlContext->xml_signature.use_external = 0; } dcp_log_init(xmlContext->log_level, ".log"); strcpy(xmlContext->xml.title, ui->cplTitleEdit->text().toStdString().c_str()); strcpy(xmlContext->xml.annotation, ui->cplAnnotationEdit->text().toStdString().c_str()); strcpy(xmlContext->xml.issuer, ui->cplIssuerEdit->text().toStdString().c_str()); strcpy(xmlContext->xml.kind, ui->cplKindComboBox->currentText().toStdString().c_str()); strcpy(xmlContext->xml.rating, ui->cplRatingComboBox->currentText().toStdString().c_str()); // check picture track is supplied if (ui->reelPictureEdit->text().isEmpty()) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("An MXF picture track is required.")); goto Done; } // check durations if ((!ui->reelSoundEdit->text().isEmpty() && ui->reelPictureDurationSpinBox->value() != ui->reelSoundDurationSpinBox->value()) || (!ui->reelSubtitleEdit->text().isEmpty() && ui->reelPictureDurationSpinBox->value() != ui->reelSubtitleDurationSpinBox->value())) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("The duration of all MXF tracks must be the same.")); goto Done; } // copy assets reelList->asset_count = 0; if (!ui->reelPictureEdit->text().isEmpty()) { strcpy(reelList[0].asset_list[0].filename, ui->reelPictureEdit->text().toStdString().c_str()); reelList->asset_count++; } if (!ui->reelSoundEdit->text().isEmpty()) { strcpy(reelList[0].asset_list[1].filename, ui->reelSoundEdit->text().toStdString().c_str()); reelList->asset_count++; } if (!ui->reelSubtitleEdit->text().isEmpty()) { strcpy(reelList[0].asset_list[2].filename, ui->reelSubtitleEdit->text().toStdString().c_str()); reelList->asset_count++; } // add pkl to the DCP (only one PKL currently support) add_pkl(xmlContext); // add cpl to the DCP/PKL (only one CPL currently support) add_cpl(xmlContext, &xmlContext->pkl[0]); if (add_reel(xmlContext, &xmlContext->pkl[0].cpl[0],reelList[0]) != OPENDCP_NO_ERROR) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("Could not add reel to CPL.")); goto Done; } // adjust durations xmlContext->pkl[0].cpl[0].reel[0].asset[0].duration = ui->reelPictureDurationSpinBox->value(); xmlContext->pkl[0].cpl[0].reel[0].asset[0].entry_point = ui->reelPictureOffsetSpinBox->value(); xmlContext->pkl[0].cpl[0].reel[0].asset[1].duration = ui->reelSoundDurationSpinBox->value(); xmlContext->pkl[0].cpl[0].reel[0].asset[1].entry_point = ui->reelSoundOffsetSpinBox->value(); xmlContext->pkl[0].cpl[0].reel[0].asset[2].duration = ui->reelSubtitleDurationSpinBox->value(); xmlContext->pkl[0].cpl[0].reel[0].asset[2].entry_point = ui->reelSubtitleOffsetSpinBox->value(); if (validate_reel(xmlContext,&xmlContext->pkl[0].cpl[0],0) != OPENDCP_NO_ERROR) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("Could not valiate reel.")); goto Done; } // set filenames path = QFileDialog::getExistingDirectory(this, tr("Choose destination folder"),QString::null); if (path.isEmpty()) { goto Done; } filename = path + "/" + xmlContext->pkl[0].cpl[0].uuid + "_cpl.xml"; strcpy(xmlContext->pkl[0].cpl[0].filename,filename.toStdString().c_str()); filename = path + "/" + xmlContext->pkl[0].uuid + "_pkl.xml"; strcpy(xmlContext->pkl[0].filename,filename.toStdString().c_str()); if (xmlContext->ns == XML_NS_SMPTE) { filename = path + "/" + "ASSETMAP.xml"; strcpy(xmlContext->assetmap.filename,filename.toStdString().c_str()); filename = path + "/" + "VOLINDEX.xml"; strcpy(xmlContext->volindex.filename,filename.toStdString().c_str()); } else { filename = path + "/" + "ASSETMAP"; strcpy(xmlContext->assetmap.filename,filename.toStdString().c_str()); filename = path + "/" + "VOLINDEX"; strcpy(xmlContext->volindex.filename,filename.toStdString().c_str()); } // write XML Files if (write_cpl(xmlContext,&xmlContext->pkl[0].cpl[0]) != OPENDCP_NO_ERROR) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("Failed to create composition playlist.")); goto Done; } if (write_pkl(xmlContext,&xmlContext->pkl[0]) != OPENDCP_NO_ERROR) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("Failed to create packaging list.")); goto Done; } if (write_volumeindex(xmlContext) != OPENDCP_NO_ERROR) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("Failed to create volume index.")); goto Done; } if (write_assetmap(xmlContext) != OPENDCP_NO_ERROR) { QMessageBox::critical(this, DCP_FAIL_MSG, tr("Failed to create assetmap.")); goto Done; } // copy the picture mxf files source.setFile(xmlContext->pkl[0].cpl[0].reel[0].asset[0].filename); destination.setFile(path + "/" + source.fileName()); if (!ui->reelPictureEdit->text().isEmpty() && source.absoluteFilePath() != destination.absoluteFilePath()) { if (destination.isFile()) { if (QMessageBox::question(this,tr("Move MXF File"),tr("The destination picture MXF already exists, do you want to replace?"), QMessageBox::No,QMessageBox::Yes) == QMessageBox::Yes) { QFile::remove(destination.absoluteFilePath()); } } if (ui->rbMoveMxf->isChecked()) { QFile::rename(source.absoluteFilePath(), destination.absoluteFilePath()); } else { //QMessageBox* msgBox = new QMessageBox( this ); //msgBox->setWindowTitle("File Copy"); //msgBox->setText("Copying picture file..."); //msgBox->open(); fileCopy(source.absoluteFilePath(), destination.absoluteFilePath()); //msgBox->close();; } } // copy the sound mxf files source.setFile(xmlContext->pkl[0].cpl[0].reel[0].asset[1].filename); destination.setFile(path + "/" + source.fileName()); if (!ui->reelSoundEdit->text().isEmpty() && source.absoluteFilePath() != destination.absoluteFilePath()) { if (destination.isFile()) { if (QMessageBox::question(this,tr("Move MXF File"),tr("The destination sound MXF already exists, do you want to replace?"), QMessageBox::No,QMessageBox::Yes) == QMessageBox::Yes) { QFile::remove(destination.absoluteFilePath()); } } if (ui->rbMoveMxf->isChecked()) { QFile::rename(source.absoluteFilePath(), destination.absoluteFilePath()); } else { QMessageBox* msgBox = new QMessageBox( this ); //msgBox->setAttribute( QWidget::WA_DeleteOnClose ); msgBox->setWindowTitle("File Copy"); msgBox->setText("Copying sound file..."); msgBox->open(); QFile::copy(source.absoluteFilePath(), destination.absoluteFilePath()); msgBox->close(); } } // copy the subtitle mxf files source.setFile(xmlContext->pkl[0].cpl[0].reel[0].asset[2].filename); destination.setFile(path + "/" + source.fileName()); if (!ui->reelSubtitleEdit->text().isEmpty() && source.absoluteFilePath() != destination.absoluteFilePath()) { if (destination.isFile()) { if (QMessageBox::question(this,tr("Move MXF File"),tr("The destination subtitle MXF already exists, do you want to replace?"), QMessageBox::No,QMessageBox::Yes) == QMessageBox::Yes) { QFile::remove(destination.absoluteFilePath()); } } if (ui->rbMoveMxf->isChecked()) { QFile::rename(source.absoluteFilePath(), destination.absoluteFilePath()); } else { QMessageBox* msgBox = new QMessageBox( this ); msgBox->setWindowTitle("File Copy"); msgBox->setText("Copying subtitle file..."); msgBox->open(); QFile::copy(source.absoluteFilePath(), destination.absoluteFilePath()); msgBox->close();; } } msgBox.setText("DCP Created successfully"); msgBox.exec(); Done: opendcp_delete(xmlContext); return; }
int main(int argc,char** argv) { char pm, operation=-1, found=1, pw1[128], pw2[128], ae1[15], ae2[15]; u32 i; PK0102 ce; PK0304 le; PK0506 ed; for (pm=1; pm < argc; pm++) { char opt; if (argv[pm][0] != '/') continue; if (argv[pm][1] == '?') { printf( "Encrypts or decrypts an archive following WinZip(R) 9 specifications.\n\n" \ "ZAES /D | /E:keysize [/2] archive.zip\n\n" \ " /D decrypts AES encrypted entries\n" \ " /E:keysize encrypts with 128, 192 or 256-bit keys (keysize 1, 2 or 3)\n" \ " /2 AE-2 format (sets CRC-32 to zero)\n"); return 1; } opt = toupper(argv[pm][1]); if (opt== 'E') { Mode = atol(&argv[pm][3]); operation = 0; filter = encrypt_authenticate; if (Mode < 1 || Mode > 3) Z_ERROR("Bad encryption mode specified!"); SaltSize = KS[Mode].Salt; KeySize = KS[Mode].Key; found++; continue; } if (opt== 'D') { operation = 1; filter = authenticate_decrypt; found++; continue; } if (opt== '2') { AE2 = 1; found++; printf("WARNING: according to AE-2 specifications, CRC-32 will be set to zero\n"\ "in encrypted entries. Reverting to original archive after decryption will\n"\ "be impossible with this utility!\n"); continue; } } argv+=found; argc-=found; if (operation == -1) Z_ERROR("You must specify /E or /D switch!\nTry ZAES /?"); if (argc < 1) Z_ERROR("You must give a ZIP archive to process!"); register_prng(&sprng_desc); register_cipher(&aes_desc); register_hash(&sha1_desc); //~ printf("DEBUG: sha1 id=%d, aes id=%d\n", find_hash("sha1"), find_cipher("aes")); if ( (ZIN=fopen(argv[0],"rb")) == 0 || (ZIN2=fopen(argv[0],"rb")) == 0 ) Z_ERROR("Can't open input ZIP archive"); if ( (ZOUT=topen(ae1)) == 0 || (ZTMP=topen(ae2)) == 0) Z_ERROR("Can't open temporary output files"); setvbuf(ZIN , 0, _IOFBF, BLOCK); setvbuf(ZOUT, 0, _IOFBF, BLOCK); /* assumiamo uno ZIP senza commento! */ fseek(ZIN2,-22,SEEK_END); safeRead(&ed, ZIN2, sizeof(PK0506)); if (ed.Sig != 0x06054B50) #ifdef HANDLE_COMMENT { fseek(ZIN2, -0xFFFF, SEEK_END); fread(p, 1, 4, ZIN2); #else Z_ERROR("End directory marker not found!"); #endif /* verifica un minimo di coerenza nella ENDDIR */ if (ed.Disk != 0) Z_ERROR("Can't process a spanned archive"); while(1) { printf("Enter password: "******"\rFor your safety, please use a password of 8 characters or more.\n"); continue; } if (operation) { printf("\n"); break; } printf("\rVerify password: "******"Passwords don't match!\n"); continue; } printf("\n"); break; } #define PUTN(x) { fileCopy(stdout, ZIN, x.NameLen); fseek(ZIN, -x.NameLen, SEEK_CUR); } fseek(ZIN2, ed.Offset, SEEK_SET); for (i=0; i < ed.Total; i++) { safeRead(&ce, ZIN2, sizeof(PK0102)); if (ce.Sig != 0x02014B50) Z_ERROR("Expected central directory marker not found"); /* Assume i dati corretti dalla LE */ fseek(ZIN, ce.Offset, SEEK_SET); safeRead(&le, ZIN, sizeof(PK0304)); if (le.Sig != 0x04034B50) Z_ERROR("Expected local entry marker not found"); if ( ((le.Flag & 1) && !operation) || /* doesn't encrypt already encrypted */ (!(le.Flag & 1) && operation) || /* doesn't decrypt already decrypted */ ((le.Flag & 1) && operation && le.CompMethod != 99) || /* doesn't decrypt not AES encrypted */ !le.CompSize ) { ce.Offset = ftell(ZOUT); safeWrite(ZOUT, &le, sizeof(PK0304)); printf(" copying: "); PUTN(le); fileCopy(ZOUT, ZIN, le.NameLen+le.ExtraLen+le.CompSize); printf("\n"); safeWrite(ZTMP, &ce, sizeof(PK0102)); fileCopy(ZTMP, ZIN2, ce.NameLen+ce.ExtraLen); continue; } if (!operation) { AE_EXTRA ae = {0x9901, 7, AE2+1, 0x4541, Mode, 0}; ae.CompMethod = ce.CompMethod; ce.CompMethod = 99; if (AE2) ce.Crc32 = 0; ce.Flag |= 1; ce.ExtraLen += 11; ce.CompSize += SaltSize + 12; /* variable salt, fixed password check and hmac */ ce.Offset = ftell(ZOUT); safeWrite(ZTMP, &ce, sizeof(PK0102)); fileCopy(ZTMP, ZIN2, ce.NameLen+ce.ExtraLen-11); safeWrite(ZTMP, &ae, 11); printf(" encrypting: "); PUTN(le); Encrypt(&le, &ae, pw1); printf("\n"); } else { ce.Offset = ftell(ZOUT); printf(" decrypting: "); PUTN(le); Decrypt(&le, pw1); /* Decrypts contents */ printf("\n"); ce.CompMethod = le.CompMethod; if (AE2) ce.Crc32 = 0; ce.Flag ^= 1; ce.ExtraLen -= 11; ce.CompSize = le.CompSize; safeWrite(ZTMP, &ce, sizeof(PK0102)); /* Copy the extra data (may be LE != CE) */ fileCopy(ZTMP, ZIN2, ce.NameLen); for(ce.ExtraLen+=11; ce.ExtraLen;) { u16 u[2]; safeRead(u, ZIN2, 4); ce.ExtraLen -= (4 + u[1]); if (u[0] == 0x9901) { fseek(ZIN2, u[1], SEEK_CUR); continue; } safeWrite(ZTMP, u, 4); fileCopy(ZTMP, ZIN2, u[1]); } } } ed.Offset = ftell(ZOUT); /* new central directory start */ ed.Size = ftell(ZTMP); /* new central directory size */ fseek(ZTMP, 0, SEEK_SET); fclose(ZIN); fclose(ZIN2); /* Copies central directory */ fileCopy(ZOUT, ZTMP, ed.Size); safeWrite(ZOUT, &ed, sizeof(PK0506)); fclose(ZTMP); fclose(ZOUT); remove(ae2); if (remove(argv[0])) { printf("Can't remove old archive; new one is in file '%s'\n", ae1); } else if (rename(ae1, argv[0])) { printf("Can't rename old archive; new one is in file '%s'\n", ae1); } memset(&BUF, 0, sizeof(BUF)); memset(&ctr, 0, sizeof(ctr)); memset(pw1, 0, 128); memset(pw2, 0, 128); return 0; }
void Decrypt(PK0304 *le, char *password) { char *salt, *key1, *key2, *check, digest[40]; u32 key_len, dig_len = 40, start, xlen; AE_EXTRA ae; start = ftell(ZIN); /* Searches for AE-1 header */ fseek(ZIN, le->NameLen, SEEK_CUR); for(xlen=le->ExtraLen; xlen;) { safeRead(&ae, ZIN, 4); xlen -= (4 + ae.Size); if (ae.Sig == 0x9901) { safeRead(&ae.Version, ZIN, 7); continue; } fseek(ZIN, ae.Size, SEEK_CUR); } if (ae.Sig != 0x9901) Z_ERROR("Fatal! Can't find AE extra header!"); if (ae.Strength < 1 || ae.Strength > 3) Z_ERROR("Bad encryption strength"); SaltSize = KS[ae.Strength].Salt; KeySize = KS[ae.Strength].Key; salt = BUF; key1 = salt+SaltSize; key2 = key1+KeySize; check = key2+KeySize; key_len = KeySize*2+2; /* Loads salt and password check value, and regenerates original crypto material */ fseek(ZIN, start+le->NameLen+le->ExtraLen, SEEK_SET); safeRead(salt, ZIN, SaltSize); safeRead(check+2, ZIN, 2); point1: if (pkcs_5_alg2(password, strlen(password), salt, SaltSize, 1000, 0, key1, &key_len) != CRYPT_OK) Z_ERROR("Failed to derive encryption keys"); if (memcmp(check, check+2, 2)) { printf("\nCan't decrypt data: try another password.\nNew password: "******"\n"); goto point1; } if (ctr_start(0, IV, key1, KeySize, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr) != CRYPT_OK) Z_ERROR("Failed to setup AES CTR decoder"); #ifdef GLADMAN_HMAC hmac_sha1_begin(&hmac); hmac_sha1_key(key2, KeySize, &hmac); #else if (hmac_init(&hmac, 0, key2, KeySize) != CRYPT_OK) Z_ERROR("Failed to setup HMAC-SHA1"); #endif /* Adjusts local header */ le->Flag ^= 1; le->CompMethod = ae.CompMethod; le->ExtraLen -= 11; le->CompSize -= (SaltSize + 12); /* Writes local header and copies extra, except 0x9901 */ safeWrite(ZOUT, le, sizeof(PK0304)); fseek(ZIN, start, SEEK_SET); fileCopy(ZOUT, ZIN, le->NameLen); for(xlen=le->ExtraLen+11; xlen;) { safeRead(&ae, ZIN, 4); xlen -= (4 + ae.Size); if (ae.Sig == 0x9901) { safeRead(&ae.Version, ZIN, 7); continue; } safeWrite(ZOUT, &ae, 4); fileCopy(ZOUT, ZIN, ae.Size); } fseek(ZIN, SaltSize+2, SEEK_CUR); fileFilter(ZOUT, ZIN, le->CompSize); #ifdef GLADMAN_HMAC hmac_sha1_end(digest, dig_len, &hmac); #else if (hmac_done(&hmac, digest, &dig_len) != CRYPT_OK) Z_ERROR("Failed to computate HMAC"); #endif /* Retrieves and checks HMACs */ safeRead(digest+10, ZIN, 10); if (memcmp(digest, digest+10, 10)) printf(" authentication failed, contents were lost!"); ctr_done(&ctr); }
void onSdManagerMenu(const char *result) { TCHAR lfn[_MAX_LFN+1]; // TODO possible buffer overflows here! uint8_t index = m_posVert-s_pgOfs; char *line = reusableBuffer.sdmanager.lines[index]; if (result == STR_SD_INFO) { pushMenu(menuGeneralSdManagerInfo); } else if (result == STR_SD_FORMAT) { POPUP_CONFIRMATION(STR_CONFIRM_FORMAT); } else if (result == STR_COPY_FILE) { clipboard.type = CLIPBOARD_TYPE_SD_FILE; f_getcwd(clipboard.data.sd.directory, CLIPBOARD_PATH_LEN); strncpy(clipboard.data.sd.filename, line, CLIPBOARD_PATH_LEN-1); } else if (result == STR_PASTE) { f_getcwd(lfn, _MAX_LFN); POPUP_WARNING(fileCopy(clipboard.data.sd.filename, clipboard.data.sd.directory, lfn)); REFRESH_FILES(); } else if (result == STR_RENAME_FILE) { char *ext = getFileExtension(line, SD_SCREEN_FILE_LENGTH+1); if (ext) { memcpy(reusableBuffer.sdmanager.originalName, line, sizeof(reusableBuffer.sdmanager.originalName)); // write spaces to allow a longer filename memset(ext, ' ', SD_SCREEN_FILE_LENGTH-LEN_FILE_EXTENSION-(ext-line)); line[SD_SCREEN_FILE_LENGTH-LEN_FILE_EXTENSION] = '\0'; s_editMode = EDIT_MODIFY_STRING; editNameCursorPos = 0; } } else if (result == STR_DELETE_FILE) { getSelectionFullPath(lfn); f_unlink(lfn); strncpy(statusLineMsg, line, 13); strcpy_P(statusLineMsg+min((uint8_t)strlen(statusLineMsg), (uint8_t)13), STR_REMOVED); showStatusLine(); REFRESH_FILES(); if (m_posVert == reusableBuffer.sdmanager.count-1) { m_posVert--; } } else if (result == STR_PLAY_FILE) { getSelectionFullPath(lfn); audioQueue.stopAll(); audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER); } else if (result == STR_ASSIGN_BITMAP) { strAppendFilename(g_model.header.bitmap, line, sizeof(g_model.header.bitmap)); memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap)); eeDirty(EE_MODEL); } else if (result == STR_VIEW_TEXT) { getSelectionFullPath(lfn); pushMenuTextView(lfn); } else if (result == STR_FLASH_BOOTLOADER) { getSelectionFullPath(lfn); flashBootloader(lfn); } else if (result == STR_FLASH_INTERNAL_MODULE) { getSelectionFullPath(lfn); flashSportDevice(INTERNAL_MODULE, lfn); } else if (result == STR_FLASH_EXTERNAL_DEVICE) { getSelectionFullPath(lfn); flashSportDevice(EXTERNAL_MODULE, lfn); } #if defined(LUA) else if (result == STR_EXECUTE_FILE) { getSelectionFullPath(lfn); luaExec(lfn); } #endif }
void Rimp::copyFromRepositoryToDatastore(const std::string& virtualImageRepositoryPath, std::string& datastore, const std::string& virtualMachineUUID) { string error(""); RimpException rexecption; // check datastore path end with '/' if (datastore.at(datastore.size() - 1) != '/') { datastore = datastore.append("/"); } checkRimpConfiguration(); if (!checkDatastore(datastore)) { error = error.append("Provided ''datastore'' :").append(datastore).append(" can not be used"); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } LOG("[DEBUG] [RIMP] Instantiating virtual image [%s] for virtual machine [%s]", virtualImageRepositoryPath.c_str(), virtualMachineUUID.c_str()); string viRepositoryPath(repository); viRepositoryPath = viRepositoryPath.append(virtualImageRepositoryPath); // Check the source file (on the repository) exist and can be read if (access(viRepositoryPath.c_str(), F_OK | R_OK) == -1) { error = error.append("Source file does not exist at [").append(viRepositoryPath).append("]"); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } unsigned long int viSize = getFileSize(viRepositoryPath); /** Copy from ''Local Repository'' to ''Datastore''. */ string viDatastorePath(datastore); viDatastorePath = viDatastorePath.append(virtualMachineUUID); // if the file exist on the datastore delete it if (access(viDatastorePath.c_str(), F_OK) == 0) { if (autorestore && autobackup) { // Sometimes an undeploy fails and the origional image does not get re/moved so we don't want to delete it and we don't need to try to recover so there is nothing to do. // NOTE: You really do want this, don't over think it. LOG("[INFO] [RIMP] Not checking for backup; existing virtual image instance found for virtual machine [%s]", virtualMachineUUID.c_str()); return; } LOG("[WARNING] [RIMP] File with the same UUID already present on the ''datastore'' [%s], removing it.", viDatastorePath.c_str()); remove(viDatastorePath.c_str()); } if (autorestore) { string viDatastorePathBackup(datastore); viDatastorePathBackup = viDatastorePathBackup.append("backup/"); viDatastorePathBackup = viDatastorePathBackup.append(virtualMachineUUID); if (access(viDatastorePathBackup.c_str(), F_OK | R_OK) == 0) { // Then perform a recovery rather then a full deploy. string renameError2 = fileRename(viDatastorePathBackup, viDatastorePath); if (!renameError2.empty()) { error = error.append("Can not move :").append(viDatastorePathBackup).append(" to :").append(viDatastorePath).append("\nCaused by :").append(renameError2); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } LOG("[INFO] [RIMP] Recovered virtual image instance for virtual machine [%s]", virtualMachineUUID.c_str()); return; } } // XXX viSize is the same on the repository and on the local repository unsigned long int datastoreFreeSize = getFreeSpaceOn(datastore); if (datastoreFreeSize < viSize) { error = error.append("There is no enough space left to copy the file :"); error = error.append(viRepositoryPath).append(" to :").append(datastore); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } string copyError2 = fileCopy(viRepositoryPath, viDatastorePath); if (!copyError2.empty()) { error = error.append("Can not copy to :").append(viDatastorePath).append("\nCaused by :").append(copyError2); LOG("[ERROR] [RIMP] %s", error.c_str()); rexecption.description = error; throw rexecption; } LOG("[INFO] [RIMP] Created virtual image instance for virtual machine [%s]", virtualMachineUUID.c_str()); }