-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
64 lines (48 loc) · 1.6 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* File: Main.cpp
* Author: gkovalechyn
*
* Created on June 19, 2016, 2:28 AM
*/
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "CPL.h"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
std::ofstream hashFile("Hashes.txt");
char buff[10];
//CPL::getInstance()->connect();
//CPL::getInstance()->doHandshake();
for(int i = 1; i < argc; i++){
std::string cppString(argv[i]);
std::ifstream file(cppString, std::ios::binary | std::ios::ate);
if (!file.is_open()){
std::cout << "Could not open file: " << argv[i] << std::endl;
}else{
SHA256 sha256 = SHA256();
unsigned char hash[SHA256::DIGEST_SIZE];
std::streamsize size = file.tellg();
unsigned char* buffer;
memset(hash, 0, SHA256::DIGEST_SIZE);
std::cout << "Generating hash for: " << argv[i] << ", File size: " << size << std::endl;
hashFile << argv[i] << ": ";
file.seekg(0, std::ios::beg);
buffer = new unsigned char[size];
memset(buffer, 0 , size);
file.read((char*) buffer, size);
sha256.update(buffer, size);
sha256.final(hash);
delete[] buffer;
for(int i = 0; i < SHA256::DIGEST_SIZE; i++){
snprintf(buff, 10, "%02X", hash[i]);
hashFile << "(byte) 0x" << buff << ", ";
}
hashFile << std::endl;
}
}
return 0;
}