-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
67 lines (63 loc) · 1.59 KB
/
main.cc
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
64
65
66
67
#include <iostream>
class OsecpuBinary {
public:
OsecpuBinary() {}
const static int bufSize = 1024 * 1024;
int Load(std::string path) {
{
FILE *fp = fopen(path.c_str(), "rb");
if (!fp) return -1;
binByteSize = fread(binBuf, 1, bufSize, fp);
fclose(fp);
}
if (bufSize == binByteSize) return -2;
CheckBinType();
return binByteSize;
}
uint8_t GetBinVersion() { return binVersion; }
bool GetIsFrontend() { return isFrontend; }
private:
uint8_t binBuf[bufSize];
int binByteSize;
uint8_t binVersion = 0x00;
bool isFrontend;
void CheckBinType() {
if (binBuf[0] != 0x05) {
binVersion = 0x00;
return;
}
switch (binBuf[1]) {
case 0xE1:
case 0xE2:
break;
default:
binVersion = 0x00;
return;
}
binVersion = binBuf[1];
isFrontend = binBuf[2] != 0x00;
}
};
int main(int argc, char *argv[]) {
if (argc <= 1) {
std::cout << "Usage: " << std::endl
<< "> osecpu <cmd> [<args> ...]" << std::endl
<< "cmd:" << std::endl
<< " file <path> : Check osecpu file type" << std::endl;
return 1;
}
if (strcmp(argv[1], "file") == 0) {
if (argc <= 2) {
std::cerr << "osecpu: Please specify file path." << std::endl;
return 1;
}
OsecpuBinary osebin;
osebin.Load(argv[2]);
std::cout << osebin.GetBinVersion();
std::cout << "Type: " << osebin.GetBinVersion() << osebin.GetIsFrontend()
<< std::endl;
return 0;
}
std::cerr << "osecpu: Unknown command: " << argv[1] << std::endl;
return 1;
}