| 108 | } |
| 109 | |
| 110 | char CalculateBinaryHash(char* filename, unsigned int* hash) |
| 111 | { |
| 112 | if (filename == NULL || hash == NULL) |
| 113 | return -1; |
| 114 | |
| 115 | printf("opening dol...\n"); |
| 116 | FILE* dolFile = fopen(filename, "rb"); |
| 117 | if (!dolFile) |
| 118 | { |
| 119 | printf("failed to open %s\n", filename); |
| 120 | return -2; |
| 121 | } |
| 122 | |
| 123 | printf("opened\nreading Dol data...\n"); |
| 124 | |
| 125 | // obtain file size: |
| 126 | fseek(dolFile, 0, SEEK_END); |
| 127 | long dolSize = ftell(dolFile); |
| 128 | rewind(dolFile); |
| 129 | |
| 130 | SHA1 sha; // SHA-1 class |
| 131 | sha.Reset(); |
| 132 | memset(hash, 0, 20); |
| 133 | char input = fgetc(dolFile); |
| 134 | for (int i = 0; i < dolSize; i++) |
| 135 | { |
| 136 | sha.Input(input); |
| 137 | input = fgetc(dolFile); |
| 138 | } |
| 139 | fclose(dolFile); |
| 140 | if (!sha.Result(hash)) |
| 141 | { |
| 142 | printf("sha: could not compute Hash for stable release!\n"); |
| 143 | return -3; |
| 144 | } |
| 145 | |
| 146 | printf("Hash : %08X %08X %08X %08X %08X\n", |
| 147 | hash[0], |
| 148 | hash[1], |
| 149 | hash[2], |
| 150 | hash[3], |
| 151 | hash[4]); |
| 152 | |
| 153 | return 1; |
| 154 | } |
| 155 | |
| 156 | int main(int argc, char **argv) |
| 157 | { |