void closeAssemblyOutput(char const *path) { char *pos; char labelBuf[6]; int unknownLength = strlen(UNKNOWN_ADDRESS); size_t length; callFunction(getFunction("main"), 0, NULL); char *buf2; asprintf(&buf2, "%s%s", assemblyBuffer, globalBuffer); free(assemblyBuffer); free(globalBuffer); assemblyBuffer = buf2; pos = assemblyBuffer; length = sprintf(labelBuf, "%d", instructionsCount()); while((pos = strstr(pos, "EOC"UNKNOWN_ADDRESS)) != NULL) { stringReplaceWithShorter(pos, 3 + unknownLength, labelBuf, length); } pos = assemblyBuffer; length = sprintf(labelBuf, "%d", instructionsCount() + globalCount); while((pos = strstr(pos, "EOF"UNKNOWN_ADDRESS)) != NULL) { stringReplaceWithShorter(pos, 3 + unknownLength, labelBuf, length); } pos = assemblyBuffer; while((pos = strstr(pos, "FUN"UNKNOWN_ADDRESS)) != NULL) { int functionIndex; int charatersConsumed; sscanf(pos + strlen("FUN"UNKNOWN_ADDRESS), "%d%n", &functionIndex, &charatersConsumed); function_t *function = getFunctionWithIndex(functionIndex); if(function->address == 0) { yyerror("La fonction %s n'a pas été définie !\n", function->name); } length = sprintf(labelBuf, "%d", function->address); stringReplaceWithShorter(pos, strlen("FUN"UNKNOWN_ADDRESS) + charatersConsumed, labelBuf, length); } replaceLabels(assemblyBuffer, "\n"UNKNOWN_IF_PREFIX, &ifLabels, labelBuf, unknownLength); replaceLabels(assemblyBuffer, "\n"UNKNOWN_LOOP_PREFIX, &loopLabels, labelBuf, unknownLength); { // On dépile la stack des goto dans la liste pour pouvoir utiliser le même algo que pour les if et while label_t newTab[MAX_SIZE]; for(int i = 0; i < gotoLabels.size; ++i) { free(gotoLabels.labels[i].name); gotoLabels.labels[i].name = NULL; newTab[i] = gotoLabels.labels[i]; } for(int i = 0; i < gotoLabels.stackSize; ++i) { gotoLabels.labels[i] = newTab[gotoLabels.stack[i] - gotoLabels.labels]; } gotoLabels.size = gotoLabels.stackSize; } replaceLabels(assemblyBuffer, "\n"UNKNOWN_GOTO_PREFIX, &gotoLabels, labelBuf, unknownLength); #ifdef STRIP_COMMENTS pos = assemblyBuffer; while((pos = strstr(pos, ";")) != NULL) { if(pos[-1] == ' ') --pos; char *pos2 = strstr(pos, "\n"); size_t length = pos2 - pos; stringReplaceWithShorter(pos, length, "", 0); } #endif if(errorsOccurred()) { fclose(output); remove(path); } else { fputs(assemblyBuffer, output); fclose(output); } free(assemblyBuffer); for(int i = 0; i < MAX_SIZE; ++i) { free(returnAddressStack.address[i]); } }
void EncryptDecryptFile::encryptDecrypt(const QString &inputFileName, const QString &outputFileName, const QString &keyFileName) { QFile inputFile(inputFileName); QFile outputFile(outputFileName); QFile keyFile(keyFileName); QString errorString; bool anErrorOccurred = false; register int i = 0; if(!inputFile.open(QIODevice::ReadOnly)) { errorString.append(tr("Could not open \"%1\" for reading.\n").arg(inputFileName)); anErrorOccurred = true; } else errorString.append(tr("Could successfully open \"%1\" for reading.\n").arg(inputFileName)); if(!outputFile.open(QIODevice::WriteOnly)) { errorString.append(tr("Could not open \"%1\" for writing.\n").arg(outputFileName)); anErrorOccurred = true; } else errorString.append(tr("Could successfully open \"%1\" for writing.\n").arg(outputFileName)); if(!keyFile.open((QIODevice::ReadOnly))) { errorString.append(tr("Could not open \"%1\" for reading.\n").arg(keyFileName)); anErrorOccurred = true; } else errorString.append(tr("Could successfully open \"%1\" for reading.\n").arg(keyFileName)); if(anErrorOccurred) { emit errorsOccurred(0, tr("Could not open someFiles!"), errorString); return; } char ioChar; char keyChar; emit fileSize(inputFile.size()); emit madeProgress(0); while(!inputFile.atEnd()) { if(!stopped) { inputFile.getChar(&ioChar); keyFile.getChar(&keyChar); encryptDecryptChar(ioChar, keyChar); outputFile.putChar(ioChar); if(keyFile.atEnd()) keyFile.reset(); if(i >= updateInterval) { emit madeProgress(inputFile.pos()); i = 0; } i++; } else { emit canceled(); break; } } inputFile.close(); outputFile.close(); keyFile.close(); if(!stopped) { emit madeProgress(inputFile.size()); emit successfullyFinished(); } stopped = false; }