FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
magic.cpp
Go to the documentation of this file.
1
8
9#include <fstream>
10#include <iostream>
11
19int main(int argc, char** argv)
20{
21 // Check arg count
22 if (argc != 2)
23 {
24 std::cerr << "Invalid parameters" << std::endl;
25 return 1;
26 }
27
28 // Define magic
29 unsigned char arr_magic[] = {'F', 'I', 0x01};
30
31 // Open the file in binary mode for rw
32 std::fstream file (argv[1], std::ios::in | std::ios::out | std::ios::binary);
33 if (!file)
34 {
35 std::cerr << "Error opening file" << std::endl;
36 return -1;
37 }
38
39 // Seek
40 file.seekp(8);
41
42 // Check for seek errors
43 if (!file)
44 {
45 std::cerr << "Error seeking position" << std::endl;
46 file.close();
47 return -1;
48 }
49
50 // Write the new bytes to the specified position
51 file.write(reinterpret_cast<const char*>(arr_magic), sizeof(arr_magic));
52
53 // Check for errors after writing
54 if (!file)
55 {
56 std::cerr << "Error writing to file" << std::endl;
57 file.close();
58 return -1;
59 }
60
61 // Close the file
62 file.close();
63
64 std::cout << "Patched file " << argv[1] << std::endl;
65
66 return 0;
67}
68
69// cmd: !g++ %:p -o %:p:r
70/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
int main()
Entry point for the portal daemon.