-
Notifications
You must be signed in to change notification settings - Fork 77
/
abstractfile.h
executable file
·75 lines (63 loc) · 1.86 KB
/
abstractfile.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
72
73
74
#ifndef ABSTRACTFILE_H
#define ABSTRACTFILE_H
#include "common.h"
#include <stdint.h>
typedef struct AbstractFile AbstractFile;
typedef struct AbstractFile2 AbstractFile2;
typedef size_t (*WriteFunc)(AbstractFile* file, const void* data, size_t len);
typedef size_t (*ReadFunc)(AbstractFile* file, void* data, size_t len);
typedef int (*SeekFunc)(AbstractFile* file, off_t offset);
typedef off_t (*TellFunc)(AbstractFile* file);
typedef void (*CloseFunc)(AbstractFile* file);
typedef off_t (*GetLengthFunc)(AbstractFile* file);
typedef void (*SetKeyFunc)(AbstractFile2* file, const unsigned int* key, const unsigned int* iv);
typedef enum AbstractFileType {
AbstractFileTypeFile,
AbstractFileType8900,
AbstractFileTypeImg2,
AbstractFileTypeImg3,
AbstractFileTypeLZSS,
AbstractFileTypeIBootIM,
AbstractFileTypeMem,
AbstractFileTypeMemFile,
AbstractFileTypeDummy
} AbstractFileType;
struct AbstractFile {
void* data;
WriteFunc write;
ReadFunc read;
SeekFunc seek;
TellFunc tell;
GetLengthFunc getLength;
CloseFunc close;
AbstractFileType type;
};
struct AbstractFile2 {
AbstractFile super;
SetKeyFunc setKey;
};
typedef struct {
size_t offset;
void** buffer;
size_t bufferSize;
} MemWrapperInfo;
typedef struct {
size_t offset;
void** buffer;
size_t* bufferSize;
size_t actualBufferSize;
} MemFileWrapperInfo;
#ifdef __cplusplus
extern "C" {
#endif
AbstractFile* createAbstractFileFromFile(FILE* file);
AbstractFile* createAbstractFileFromDummy();
AbstractFile* createAbstractFileFromMemory(void** buffer, size_t size);
AbstractFile* createAbstractFileFromMemoryFile(void** buffer, size_t* size);
AbstractFile* createAbstractFileFromMemoryFileBuffer(void** buffer, size_t* size, size_t actualBufferSize);
void abstractFilePrint(AbstractFile* file, const char* format, ...);
io_func* IOFuncFromAbstractFile(AbstractFile* file);
#ifdef __cplusplus
}
#endif
#endif