Last active
July 6, 2016 13:55
-
-
Save sentenzo/e45b59e30f13ca87a6c094bd8d040f30 to your computer and use it in GitHub Desktop.
SQL Server backup version definer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> // sprintf(), fopen(), fscanf(), printf() | |
#include <stdlib.h> // malloc() | |
unsigned char bArr0[] = {0x20, 0x00, 0x53, 0x00, 0x51, 0x00, 0x4c, 0x00}; | |
int takeByteArr(char* fName, int bStart, int bLength, unsigned char* out) { | |
FILE* f = fopen(fName, "rb"); | |
if(fseek(f, bStart, SEEK_SET) != 0) { | |
fclose(f); | |
return -1; | |
} | |
unsigned char* buf = NULL; | |
buf = (unsigned char*)malloc(bLength*sizeof(unsigned char)); | |
if(fread(buf, 1, bLength, f) < bLength) { | |
fclose(f); | |
free(buf); | |
return -2; | |
} | |
for(int i=0; i<bLength; i++) { | |
out[i] = buf[i]; | |
} | |
return 1; | |
} | |
int main(int c, char **v) { | |
if(c < 2) { | |
printf("Не указан bac-файл для анализа\n"); | |
return 0; | |
} | |
unsigned char str8[8]; | |
if(takeByteArr(v[1], 0x70, 8, str8) == 1) { | |
for(int i=0; i<8; i++) { | |
if(str8[i] != bArr0[i]) { | |
printf("Формат не опознан\n"); | |
return 0; | |
} | |
} | |
} else { | |
printf("Не удалось прочитать файл\n"); | |
return 0; | |
} | |
unsigned char str2[2]; | |
if(takeByteArr(v[1], 0x65d, 2, str2) == 1) { | |
switch(str2[0]) { | |
case 8: | |
printf("MS SQL 2000 "); | |
break; | |
case 9: | |
printf("MS SQL 2005 "); | |
break; | |
case 10: | |
printf("MS SQL 2008 "); | |
break; | |
case 11: | |
printf("MS SQL 2012 "); | |
break; | |
case 12: | |
printf("MS SQL 2014 "); | |
break; | |
case 14: | |
printf("MS SQL 2016 "); | |
break; | |
default: | |
printf("0x%02x ", str2[0]); | |
break; | |
} | |
switch(str2[1]) { | |
case 0x00: | |
printf(" \n"); | |
break; | |
case 0x32: | |
printf("R2\n"); | |
break; | |
default: | |
printf("0x%02x ", str2[1]); | |
break; | |
} | |
} else { | |
printf("Не удалось прочитать файл\n"); | |
return 0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment