diff --git a/premake5.lua b/premake5.lua index 407c444..8ca2580 100644 --- a/premake5.lua +++ b/premake5.lua @@ -18,6 +18,7 @@ solution "Rec0ver_H4rv4rd" configuration "Debug" defines {"DEBUG"} symbols "On" + os.copyfile("rsc/card.raw" , "build/debug/card.raw") configuration "Release" defines {"NDEBUG"} diff --git a/readme.md b/readme.md index b80fc12..2f0e4ae 100644 --- a/readme.md +++ b/readme.md @@ -32,3 +32,7 @@ Usage: ./recover image $ ./recover card.raw ``` +## Resources +**Harvard CS50 exercise:** [https://cs50.harvard.edu/x/2020/psets/4/recover/#:~:text=y%20card,%20but%20t](https://cs50.harvard.edu/x/2020/psets/4/recover/#:~:text=y%20card,%20but%20t) + + diff --git a/src/recover.c b/src/recover.c index 1a403e9..3caa916 100644 --- a/src/recover.c +++ b/src/recover.c @@ -2,6 +2,39 @@ #include int main(int argc, char *argv[]) -{ - printf("Hello world!"); +{ + FILE* file = fopen("G:\\Users\\Nigel\\Code\\Rec0ver_H4rv4rd\\rsc\\card.raw", "rb"); + if (!file) { + exit(-1); + } + + const char* ReadBuffer = malloc(sizeof(char) * 512); + if (ReadBuffer == NULL) { + exit(-2); + } + + + int read = 0 ; + int total_read = 0; + do { + read = fread(ReadBuffer, sizeof(char), 512, file); + total_read += read; + printf("==============Begin Block==============\n"); + for (int i = 0; i < 512 ; i++) + { + if ( i % 50 == 0){ + printf("\n"); + } + printf("%x", ReadBuffer[i]); + } + printf("==============End Block===============\n"); + + printf("Bytes read total : %X\n", total_read); + + } while (read != 0); + + printf("Total read: %i bytes\n", total_read); + + free(ReadBuffer); + fclose(file); }