Diagnostics in code retrieving JPG files

1

In a course exercise I have to write a program that retrieves JPG images from a file. The code below is not ready, but it should find the signatures of JPG (0xffd8ffe0 or 0xffd8ffe1) inside the file jumping from 512 in 512 bytes (FAT) and print a text. Doubt:

  • The code does not work, I can not diagnose, what are the problems?

File: link

Code:

/**********************************
 * recover.c
 * CC50 Pset5
 * Recupera imagens JPG. Matheus.
 *********************************/

#include <stdint.h>
#include <stdio.h>

int
main(void)
{
    // Boas Vindas
    printf("3[1;30;47mPOWERED BY RAMALHOLIVEIRA3[0m\nIniciando operação.\n");

    // Abrir Arquivo
    FILE *fpr = fopen("card.raw", "r");
    if (fpr == NULL)
    {
        printf("3[31mErro ao abrir o arquivo.3[0m\n");
        return 1;
    }

    // Variáveis
    uint32_t cursor = 0;
    uint32_t assinatura = 0x00;
    FILE *saida = fopen("saida", "w");
    int n = 1;

    // Se 'fread' retornar 0 o loop acaba
    do
    {
        // Lê 4 bytes e armazena em 'assinatura'
        cursor = fread(&assinatura, 4, 1, fpr);
        fwrite(&assinatura, 4, 1, saida);
        if (assinatura == 0xffd8ffe0 || assinatura == 0xffd8ffe1)
        {
            printf("%d Encontrado!\n", n);
            ++n;
        }
        fseek(fpr, 512, SEEK_CUR);
    }
    while (cursor != 0);

    // Isso é tudo, pessoal :)
    fclose(fpr);
    fclose(saida);
    printf("Isso é tudo, pessoal.\n");
    return 0;
}
    
asked by anonymous 07.11.2017 / 21:51

0 answers