forked from ponchio/untrunc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
atom.h
71 lines (57 loc) · 1.67 KB
/
atom.h
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
68
69
70
71
#ifndef ATOM_H
#define ATOM_H
extern "C" {
#include <stdint.h>
}
#include <vector>
#include <string>
#include "file.h"
class Atom {
public:
int64_t start; //including 8 header bytes
int64_t length; //including 8 header bytes
char name[5];
char head[4];
char version[4];
std::vector<unsigned char> content;
std::vector<Atom *> children;
Atom(): start(0), length(-1) {
name[0] = name[1] = name[2] = name[3] = name[4] = 0;
length = 0;
start = 0;
}
~Atom();
void parseHeader(File &file); //read just name and length
void parse(File &file);
virtual void write(File &file);
void print(int offset);
std::vector<Atom *> atomsByName(std::string name);
Atom *atomByName(std::string name);
void replace(Atom *original, Atom *replacement);
void prune(std::string name);
virtual void updateLength();
virtual int64_t contentSize() { return content.size(); }
static bool isParent(char *id);
static bool isDual(char *id);
static bool isVersioned(char *id);
virtual int readInt(int64_t offset);
void writeInt(int value, int64_t offset);
void readChar(char *str, int64_t offset, int64_t length);
};
class BufferedAtom: public Atom {
public:
File file;
int64_t file_begin;
int64_t file_end;
unsigned char *buffer;
int64_t buffer_begin;
int64_t buffer_end;
BufferedAtom(std::string filename);
~BufferedAtom();
unsigned char *getFragment(int64_t offset, int64_t size);
int64_t contentSize() { return file_end - file_begin; }
void updateLength();
int readInt(int64_t offset);
void write(File &file);
};
#endif // ATOM_H