-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.c
83 lines (66 loc) · 2.42 KB
/
parser.c
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
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Struct to store information about a file in the archive
typedef struct {
char filename[128];
int size[4];
char hash[64];
} FileInfo;
// Struct to store information about the .edata archive
typedef struct {
int archive_size;
int num_files;
FileInfo* files;
} ArchiveInfo;
// Function to parse a .edata file and extract its information
ArchiveInfo parse_edata(FILE* file) {
ArchiveInfo info;
// Read the archive size from the first 4 bytes of the file
fread(&info.archive_size, sizeof(int), 1, file);
// Read the number of files from the next 4 bytes of the file
fread(&info.num_files, sizeof(int), 1, file);
// Allocate memory for the FileInfo structs for each file
info.files = malloc(info.num_files * sizeof(FileInfo));
// Read the pointer jungle from 0x10
fseek(file, 0x10, SEEK_SET);
// Read the file headers from the next 10 * 4 bytes of the file
// (10 pointers to file headers, each 4 bytes long)
int file_headers[16];
fread(file_headers, sizeof(int), 16, file);
// Read the individual file headers and store the information in the FileInfo structs
for (int i = 0; i < info.num_files; i++) {
// Seek to the start of the file header
fseek(file, file_headers[i], SEEK_SET);
// Read the filename
fread(info.files[i].filename, 1, 128, file);
// Read the file size
fread(&info.files[i].size, sizeof(int), 4, file);
// Read the file hash
fread(info.files[i].hash, 1, 64, file);
}
return info;
}
int main(int argc, char** argv) {
if (argc < 2) {
printf("Usage: %s <edata file>\n", argv[0]);
return 1;
}
// Open the .edata file
FILE* file = fopen(argv[1], "r");
if (!file) {
printf("Error: Could not open file %s\n", argv[1]);
return 1;
}
// Parse the .edata file
ArchiveInfo info = parse_edata(file);
// Print the information extracted from the file
printf("Archive size: %d\n", info.archive_size);
printf("Number of files: %d\n", info.num_files);
printf("Files:\n");
for (int i = 0; i < info.num_files; i++) {
printf(" Name: %s\n", info.files[i].filename);
printf(" Size: %d\n", info.files[i].size);
printf(" Hash: %s\n\n", info.files[i].hash);
}
}