aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Van Iseghem <[email protected]>2023-04-22 14:00:28 +0200
committerThomas Van Iseghem <[email protected]>2023-04-22 14:00:28 +0200
commita217dea43244881876c74450414706a696647dd8 (patch)
treeb00a530a5daa000def99c9c30b4c414646c6e2f4
parentcf8b912c6668d1ad5ea3d76afbe3a5897daf9ff1 (diff)
downloadOpenCortex-a217dea43244881876c74450414706a696647dd8.tar.gz
OpenCortex-a217dea43244881876c74450414706a696647dd8.zip
Decrypted file saves to disk
-rw-r--r--Capture-decryption/qc_decrypt.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/Capture-decryption/qc_decrypt.c b/Capture-decryption/qc_decrypt.c
index 0f86e5d..f04947f 100644
--- a/Capture-decryption/qc_decrypt.c
+++ b/Capture-decryption/qc_decrypt.c
@@ -48,6 +48,16 @@ int main(int argc, char **argv)
char *serialNumber = argv[1],
*inputFileName = argv[2];
+ printf("Input file name: %s\n", inputFileName);
+
+ // Split into the path and the file name
+ char *path = strrchr(inputFileName, '/');
+ if (path == NULL)
+ {
+ printf("No path found in %s\n", inputFileName);
+ return 1;
+ }
+
unsigned long serialSize = strlen(serialNumber);
if (serialSize != 9 && serialSize != 0)
{
@@ -132,12 +142,36 @@ int main(int argc, char **argv)
return 1;
}
- // print it
+ // Print and save the decrypted file
for (int i = 0; i < outlen; i++)
{
printf("%c", plaintext[i]);
}
printf("\n");
+ // Save the decrypted file to disk
+ // It should be saved to the same directory as the encrypted file with the extension .dec
+ char *outputFileName = (char *)malloc(strlen(inputFileName) + 5);
+ strcpy(outputFileName, inputFileName);
+ strcat(outputFileName, ".dec");
+
+ fp = fopen(outputFileName, "wb");
+ if (!fp)
+ {
+ printf("can't open %s\n", outputFileName);
+ return 1;
+ }
+
+ fwrite(plaintext, 1, outlen, fp);
+
+ fclose(fp);
+
+ free(key_material);
+ free(input);
+ free(plaintext);
+ free(outputFileName);
+
+ EVP_CIPHER_CTX_free(ctx);
+
return 0;
} \ No newline at end of file