-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (48 loc) · 1.45 KB
/
main.cpp
File metadata and controls
55 lines (48 loc) · 1.45 KB
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
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <cstdint>
#pragma pack(push, 1)
using namespace std;
uint32_t reverseBytes(uint32_t value) {
return ((value >> 24) & 0xff) |
((value << 8) & 0xff0000) |
((value >> 8) & 0xff00) |
((value << 24) & 0xff000000);
}
struct MainChunks {
uint32_t Lenght;
uint32_t Type;
};
#pragma pack(pop)
void read_chunks (vector<char> data) {
int offset = 8;
while (offset < data.size()) {
MainChunks* chunk_header = reinterpret_cast<MainChunks*>(&data[offset]);
uint32_t chunkLenght = reverseBytes(int(chunk_header->Lenght));
const char* chunkType = reinterpret_cast<const char*>(&data[offset+4]);
string outline(chunkType, 4);
cout << "Lenght: " << hex << chunkLenght <<endl;
cout << "Type: " << outline <<endl;
cout << "Offset: " << hex << offset << endl;
offset += sizeof(MainChunks) + chunkLenght+4;
}
}
int main()
{
ifstream png_file("D:\\dz\\png\\promo.png", ios::binary);
if (png_file.is_open()){
cout << "open ok" << endl;
png_file.seekg(0, ios::end);
int fileSize = png_file.tellg();
cout << "File size: " << fileSize << endl;
png_file.seekg(0, ios::beg);
vector<char> png_data(fileSize, 0);
png_file.read(png_data.data(), fileSize);
read_chunks(png_data);
}
else {
cout << "not open" << endl;
}
}