Einzelnen Beitrag anzeigen
Alt 22.01.2022, 00:00   #2
murrsky
Mitglied
 
Registriert seit: 20.04.2007
Ort: -
Fahrzeug: 728i (1999), 740xd (2015)
Standard

Die folgenden, wenigen Zeilen C-Code übernehmen genau diese Aufgabe: Das Invertieren sämtlicher Bits.
Code:
#include <stdio.h>                                                                                                              
#include <stdlib.h>

// Simple converter (de-obfuscator) for silly .BR25 files

#define ERROR(Str) \
   { \
      printf ("%s\n", Str); \
      exit (2); \
   }

int main(int argc, char *argv[])
{
    FILE *pFileIn;
    FILE *pFileOut;
    size_t Size;
    unsigned char *pBuf;
    unsigned char   Key=0xFF;

    if (argc != 3)
    {
        printf ("Usage: %s <input file> <output file>\n", argv[0]);
        printf ("<input file>  : BR25 file to be converted\n");
        printf ("<output file> : Output file with converted data, created by this program\n");
        exit (1);
    }
    if ((pFileIn = fopen (argv[1], "rb")) == NULL)        ERROR ("Cannot open input file")
    if (fseek (pFileIn, 0L, SEEK_END))                    ERROR ("Seek error on input file")
    if ((Size = ftell (pFileIn)) < 0)                     ERROR ("Unable to get size of input file")
    if (fseek (pFileIn, 0L, SEEK_SET))                    ERROR ("Seek error on input file")
    if ((pBuf = (unsigned char *) malloc (Size)) == NULL) ERROR ("Cannot allocate memory")
    if (fread (pBuf, Size, 1, pFileIn) != 1)              ERROR ("Error while reading input file" )
    if (fclose (pFileIn))                                 ERROR ("Cannot close input file")

    for (int i=0; i<Size; i++)
       pBuf[i] = pBuf[i] ^ Key;

    if ((pFileOut = fopen (argv[2], "wb")) == NULL) ERROR ("Cannot open output file")
    if (fwrite (pBuf, Size, 1, pFileOut) != 1)      ERROR ("Error while writing to output file")
    if (fclose (pFileOut))                          ERROR ("Cannot close output file")

    free(pBuf);
    exit(0);
}

Geändert von murrsky (22.01.2022 um 13:17 Uhr). Grund: Forum-Software frisst (trotz CODE-Anweisung!) die Backslahes
murrsky ist offline   Antwort Mit Zitat antworten