Don't like ads? PRO users don't see any ads ;-)
Guest

main.cpp

By: The20 on Jun 1st, 2012  |  syntax: C++  |  size: 5.14 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Default header
  2. #include <vector>
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6. // My headers
  7. #include "MPuffer.h"
  8.  
  9. // Already in MPuffer.h (line 5)
  10. // typedef unsigned char byte;
  11.  
  12. // const values
  13. const _int64 startpos = 0x100000000; // Die ersten 4 GB enthalten anderen Kram
  14. const int schrittgroesse = 512; // Die Zellen fangen immer am Anfang eines Sektors an.
  15.  
  16. // Paths to various files
  17. const char * quellaufwerk =  "\\\\.\\PhysicalDrive1";
  18. const char * zieldateivob =  "F:\\Zwischenlager\\HDDAuswertung\\ausgabevob.txt";
  19. const char * zieldateicell = "F:\\Zwischenlager\\HDDAuswertung\\ausgabecell.txt";
  20. const char * logdatei =      "F:\\Zwischenlager\\HDDAuswertung\\ausgabe.txt";
  21.  
  22.  
  23. const char * MET_ORIGINAL =     "Original";
  24. const char * MET_512BBlock =    "512B Block";
  25. const char * MET_4KBBlock =     "4KB Block";
  26. const char * MET_MS =           "-Start";
  27. const char * MET_MS512BBlock =  "-Start & 512B Block";
  28. const char * MET_MS4KBBlock =   "-Start & 4KB Block";
  29. const char * MET_DEFAULT =      "<not found>";
  30.  
  31. const char * MET[] = {MET_ORIGINAL, MET_512BBlock, MET_4KBBlock, MET_MS, MET_MS512BBlock, MET_MS4KBBlock};
  32.  
  33. //                        // 00 00 01 BA 44 00 04 00 04
  34. const byte vobStartArr[] = { 0x0, 0x0, 0x1, 0xBA, 0x44, 0x0, 0x4, 0x0, 0x4 };
  35. const byte cellStartArr[] = { 0x0, 0x0, 0x1, 0xBA, 0x44 };
  36.  
  37. #define POS_VOB 1
  38. #define POS_CELL 2
  39.  
  40. // Check if a cell or a vob start at the given position.
  41. int testePosition(_int64 pos, MPuffer & puffer)
  42. {
  43.   int i = 0;
  44.   for(; i < 5; i++) if(puffer[pos + i] != cellStartArr[i]) return -1;
  45.   for(; i < 9; i++) if(puffer[pos + i] != vobStartArr[i]) return POS_CELL;
  46.   return POS_VOB;
  47. }
  48.  
  49. // Check if the given address can be found at the given position
  50. bool testePositionAufAdresse(_int64 adresse, _int64 pos, MPuffer & puffer)
  51. {
  52.   for(unsigned int i = 0; i < 8; i++)
  53.     if(puffer.get(pos + i) != ((byte*)&adresse)[i]) return false;
  54.   return true;
  55. }
  56.  
  57. // We are checking for several values: the original address, the original address minus the 4GB offset and some others.
  58. // Those are calculated here.
  59. void konstruiereArrays(_int64 adr, _int64 arr[])
  60. {
  61.   arr[0] = adr;
  62.   arr[1] = adr / 512;
  63.   arr[2] = adr / 4096;;
  64.   arr[3] = adr - startpos;
  65.   arr[4] = ( adr - startpos ) / 512;
  66.   arr[5] = ( adr - startpos ) / 4096;
  67. }
  68.  
  69. // There's a reason this function is called that way ...
  70. void ragequit()
  71. {
  72.   FILE * datei = fopen(quellaufwerk, "rb");
  73.   if(datei != NULL)
  74.   {
  75.     time_t start, mitte, ende;
  76.  
  77.     FILE * log = fopen(logdatei, "w");
  78.     fprintf(log, "Datei erfolgreich geoeffnet. Beginne mit Lesevorgang\nStartadresse: %llX\n", (_int64)startpos);
  79.  
  80.     std::vector<_int64> vobAdr;
  81.     std::vector<_int64> cellAdr;
  82.  
  83.     MPuffer puffer(datei);
  84.  
  85.     start = time(NULL);
  86.  
  87.     int result;
  88.     for(_int64 pos = startpos; pos < 0x300000000 && puffer[pos] != -1; pos += (_int64)schrittgroesse)
  89.     {
  90.       result = testePosition(pos, puffer);
  91.       if(result == POS_VOB)
  92.         vobAdr.push_back(pos);
  93.       else if(result == POS_CELL)
  94.         cellAdr.push_back(pos);
  95.     }
  96.  
  97.     mitte = time(NULL);
  98.  
  99.     printf("\nStartadressen fuer %d VOB-Dateien gefunden.\n", vobAdr.size());
  100.     fprintf(log, "\nStartadressen fuer %d VOB-Dateien gefunden.\n", vobAdr.size());
  101. //    for(size_t i = 0; i < vobAdr.size(); i++) fprintf(log, "%lld\n", (_int64)vobAdr[i]);
  102.  
  103.     printf("\nStartadressen fuer %d MPEG Zellen gefunden.\n", cellAdr.size());
  104.     fprintf(log, "\nStartadressen fuer %d MPEG Zellen gefunden:\n", cellAdr.size());
  105. //    for(size_t i = 0; i < cellAdr.size(); i++) fprintf(log, "%lld\n", (_int64)cellAdr[i]);
  106.  
  107.     fprintf(log, "\nSuche Adressen im ersten 4G Block ...\n");
  108.  
  109.     FILE * zielvob = fopen(zieldateivob, "w");
  110.     FILE * zielcell = fopen(zieldateicell, "w");
  111.  
  112.     _int64 adressen[6];
  113.     for(_int64 pos = 0; pos < 10000; pos ++)
  114.     {
  115. //      if(pos % 0x100 == 0)printf("Position: %lld\n", (_int64)pos);
  116.       for(size_t a = 0; a < vobAdr.size(); a++)
  117.       {
  118.         konstruiereArrays(vobAdr[a], adressen);
  119.         for(size_t ain = 0; ain < 6; ain++)
  120.           if(testePositionAufAdresse(adressen[ain], pos, puffer))
  121.             fprintf(zielvob, "%llX - %llX - %llX - %s\n", vobAdr[a], adressen[ain], pos, MET[ain]);
  122.       }
  123.  
  124.       for(size_t a = 0; a < cellAdr.size(); a++)
  125.       {
  126.         konstruiereArrays(cellAdr[a], adressen);
  127.         for(size_t ain = 0; ain < 6; ain++)
  128.           if(testePositionAufAdresse(adressen[ain], pos, puffer))
  129.             fprintf(zielcell, "%llX - %llX - %llX - %s\n", cellAdr[a], adressen[ain], pos, MET[ain]);
  130.       }
  131.     }
  132.     ende = time(NULL);
  133.  
  134.     fprintf(log, "\nSuche nach VOB und Zellstartpunkten nach %lld Sekunden abgeschlossen.\n", mitte - start);
  135.     fprintf(log, "Suche der Adressen im 4GB Block nach %lld Sekunden abgeschlossen.\n", ende - mitte);
  136.     fprintf(log, "Gesammtzeit: %lld Sekunden.\nSchliesse Dateien ...\n", ende - start);
  137.  
  138.     fclose(log);
  139.     fclose(zielvob);
  140.     fclose(zielcell);
  141.     fclose(datei);
  142.  
  143.     fprintf(log, "\nVorgang abgeschlossen.");
  144.   }
  145.   else printf("Konnte angegebenen Pfad nicht oeffnen, abbruch ...\n");
  146. }
  147.  
  148. int main(int argc, char** argv)
  149. {
  150.   ragequit();
  151.   return 0;
  152. }