MCPcopy Create free account
hub / github.com/DacoTaco/priiloader / CalculateBinaryHash

Function CalculateBinaryHash

tools/HashGenerator/HashGenerator.cpp:110–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110char 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
156int main(int argc, char **argv)
157{

Callers 1

mainFunction · 0.85

Calls 3

ResetMethod · 0.80
InputMethod · 0.80
ResultMethod · 0.80

Tested by

no test coverage detected