-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
52 lines (50 loc) · 1.16 KB
/
test.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
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
uint64_t bytes2uint(char* bytes)
{
uint64_t a = *(uint64_t*)bytes;
return a;
}
int main(){
ifstream in("./bin.temp", ios::in|ios::binary);
char *buffer;
unsigned int size, l, m;
l = in.tellg();
in.seekg(0, ios::end);
m = in.tellg();
size = m - l;
buffer = (char *)malloc(size);
auto temp = buffer;
in.seekg(0, ios::beg);
in.read(buffer, size);
uint64_t mbase, msize, total = 0;
while(true)
{
mbase = bytes2uint(buffer);
msize = bytes2uint(buffer+8);
//cout << hex << mbase << endl;
//cout << hex << msize << endl;
for(uint64_t i = 0; i < msize; i++){
cout << hex << setw(2) << setfill('0') << (int) static_cast <unsigned char>(*(buffer+16+i)) << ' ';
}
cout << endl << endl;
buffer = buffer+16+msize;
total = total + 16 + msize;
if(total >= size){
break;
}
}
//in >> buffer;
/*
cout << hex << bytes2uint(buffer) << endl;
cout << hex << bytes2uint(buffer+8) << endl;
for(int i = 0; i < size; i++){
cout << hex << setw(2) << setfill('0') << (int) static_cast <unsigned char>(buffer[i]) << ' ';
}*/
cout << endl;
in.close();
delete temp;
return 0;
}