// Default header
#include <vector>
#include <stdio.h>
#include <time.h>
// My headers
#include "MPuffer.h"
// Already in MPuffer.h (line 5)
// typedef unsigned char byte;
// const values
const _int64 startpos = 0x100000000; // Die ersten 4 GB enthalten anderen Kram
const int schrittgroesse = 512; // Die Zellen fangen immer am Anfang eines Sektors an.
// Paths to various files
const char * quellaufwerk = "\\\\.\\PhysicalDrive1";
const char * zieldateivob = "F:\\Zwischenlager\\HDDAuswertung\\ausgabevob.txt";
const char * zieldateicell = "F:\\Zwischenlager\\HDDAuswertung\\ausgabecell.txt";
const char * logdatei = "F:\\Zwischenlager\\HDDAuswertung\\ausgabe.txt";
const char * MET_ORIGINAL = "Original";
const char * MET_512BBlock = "512B Block";
const char * MET_4KBBlock = "4KB Block";
const char * MET_MS = "-Start";
const char * MET_MS512BBlock = "-Start & 512B Block";
const char * MET_MS4KBBlock = "-Start & 4KB Block";
const char * MET_DEFAULT = "<not found>";
const char * MET[] = {MET_ORIGINAL, MET_512BBlock, MET_4KBBlock, MET_MS, MET_MS512BBlock, MET_MS4KBBlock};
// // 00 00 01 BA 44 00 04 00 04
const byte vobStartArr[] = { 0x0, 0x0, 0x1, 0xBA, 0x44, 0x0, 0x4, 0x0, 0x4 };
const byte cellStartArr[] = { 0x0, 0x0, 0x1, 0xBA, 0x44 };
#define POS_VOB 1
#define POS_CELL 2
// Check if a cell or a vob start at the given position.
int testePosition(_int64 pos, MPuffer & puffer)
{
int i = 0;
for(; i < 5; i++) if(puffer[pos + i] != cellStartArr[i]) return -1;
for(; i < 9; i++) if(puffer[pos + i] != vobStartArr[i]) return POS_CELL;
return POS_VOB;
}
// Check if the given address can be found at the given position
bool testePositionAufAdresse(_int64 adresse, _int64 pos, MPuffer & puffer)
{
for(unsigned int i = 0; i < 8; i++)
if(puffer.get(pos + i) != ((byte*)&adresse)[i]) return false;
return true;
}
// We are checking for several values: the original address, the original address minus the 4GB offset and some others.
// Those are calculated here.
void konstruiereArrays(_int64 adr, _int64 arr[])
{
arr[0] = adr;
arr[1] = adr / 512;
arr[2] = adr / 4096;;
arr[3] = adr - startpos;
arr[4] = ( adr - startpos ) / 512;
arr[5] = ( adr - startpos ) / 4096;
}
// There's a reason this function is called that way ...
void ragequit()
{
FILE * datei = fopen(quellaufwerk, "rb");
if(datei != NULL)
{
time_t start, mitte, ende;
FILE * log = fopen(logdatei, "w");
fprintf(log, "Datei erfolgreich geoeffnet. Beginne mit Lesevorgang\nStartadresse: %llX\n", (_int64)startpos);
std::vector<_int64> vobAdr;
std::vector<_int64> cellAdr;
MPuffer puffer(datei);
start = time(NULL);
int result;
for(_int64 pos = startpos; pos < 0x300000000 && puffer[pos] != -1; pos += (_int64)schrittgroesse)
{
result = testePosition(pos, puffer);
if(result == POS_VOB)
vobAdr.push_back(pos);
else if(result == POS_CELL)
cellAdr.push_back(pos);
}
mitte = time(NULL);
printf("\nStartadressen fuer %d VOB-Dateien gefunden.\n", vobAdr.size());
fprintf(log, "\nStartadressen fuer %d VOB-Dateien gefunden.\n", vobAdr.size());
// for(size_t i = 0; i < vobAdr.size(); i++) fprintf(log, "%lld\n", (_int64)vobAdr[i]);
printf("\nStartadressen fuer %d MPEG Zellen gefunden.\n", cellAdr.size());
fprintf(log, "\nStartadressen fuer %d MPEG Zellen gefunden:\n", cellAdr.size());
// for(size_t i = 0; i < cellAdr.size(); i++) fprintf(log, "%lld\n", (_int64)cellAdr[i]);
fprintf(log, "\nSuche Adressen im ersten 4G Block ...\n");
FILE * zielvob = fopen(zieldateivob, "w");
FILE * zielcell = fopen(zieldateicell, "w");
_int64 adressen[6];
for(_int64 pos = 0; pos < 10000; pos ++)
{
// if(pos % 0x100 == 0)printf("Position: %lld\n", (_int64)pos);
for(size_t a = 0; a < vobAdr.size(); a++)
{
konstruiereArrays(vobAdr[a], adressen);
for(size_t ain = 0; ain < 6; ain++)
if(testePositionAufAdresse(adressen[ain], pos, puffer))
fprintf(zielvob, "%llX - %llX - %llX - %s\n", vobAdr[a], adressen[ain], pos, MET[ain]);
}
for(size_t a = 0; a < cellAdr.size(); a++)
{
konstruiereArrays(cellAdr[a], adressen);
for(size_t ain = 0; ain < 6; ain++)
if(testePositionAufAdresse(adressen[ain], pos, puffer))
fprintf(zielcell, "%llX - %llX - %llX - %s\n", cellAdr[a], adressen[ain], pos, MET[ain]);
}
}
ende = time(NULL);
fprintf(log, "\nSuche nach VOB und Zellstartpunkten nach %lld Sekunden abgeschlossen.\n", mitte - start);
fprintf(log, "Suche der Adressen im 4GB Block nach %lld Sekunden abgeschlossen.\n", ende - mitte);
fprintf(log, "Gesammtzeit: %lld Sekunden.\nSchliesse Dateien ...\n", ende - start);
fclose(log);
fclose(zielvob);
fclose(zielcell);
fclose(datei);
fprintf(log, "\nVorgang abgeschlossen.");
}
else printf("Konnte angegebenen Pfad nicht oeffnen, abbruch ...\n");
}
int main(int argc, char** argv)
{
ragequit();
return 0;
}