Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <vector>
- /*
- Tutoj kod dobyvajet iz .*dat arhivov igry Apocalypse 3000 .*png fajly
- */
- const unsigned char png_signature[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
- int find_png_signature(const std::vector<unsigned char>& data, int start) {
- for (int i = start; i < data.size() - sizeof(png_signature); ++i) {
- if (memcmp(&data[i], png_signature, sizeof(png_signature)) == 0) {
- return i;
- }
- }
- return -1;
- }
- int main() {
- std::string dat_file = "intro.dat";
- std::fstream file(dat_file, std::ios::binary | std::ios::in);
- if (!file.is_open()) {
- std::cerr << "Error: Could not open file: " << dat_file << std::endl;
- return 1;
- }
- file.seekg(0, std::ios::end);
- std::streamsize size = file.tellg();
- file.seekg(0, std::ios::beg);
- std::vector<unsigned char> data(size);
- file.read(reinterpret_cast<char*>(data.data()), size);
- int current_position = 0;
- int png_start = find_png_signature(data, current_position);
- int image_count = 0;
- while (png_start != -1) {
- std::vector<unsigned char> png_data(data.begin() + png_start, data.end());
- std::ofstream output_file("extracted_png_" + std::to_string(image_count) + ".png", std::ios::binary);
- if (!output_file.is_open()) {
- std::cerr << "Error: Could not create output file" << std::endl;
- } else {
- output_file.write(reinterpret_cast<char*>(png_data.data()), png_data.size());
- output_file.close();
- std::cout << "Extracted PNG: extracted_png_" << image_count << ".png" << std::endl;
- image_count++;
- }
- current_position = png_start + sizeof(png_signature);
- png_start = find_png_signature(data, current_position);
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment