56 lines
1.7 KiB
C
56 lines
1.7 KiB
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdint.h>
|
||
|
#include <sys/ksys.h>
|
||
|
#define SIGNATURE_SIZE 8
|
||
|
|
||
|
typedef struct {
|
||
|
char signature[SIGNATURE_SIZE];
|
||
|
uint32_t startAddress;
|
||
|
uint32_t fileSize;
|
||
|
uint32_t memRequired;
|
||
|
uint32_t espValue;
|
||
|
uint32_t paramAddress;
|
||
|
uint32_t filePathAddress;
|
||
|
uint32_t tlsDataAddress; // Only for MENUET02 signature
|
||
|
} ExecutableHeader;
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
if (argc < 2) {
|
||
|
printf("Error: Path to executable file not provided.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
ksys_ufile_t file = _ksys_load_file(argv[1]);
|
||
|
if (file.data == NULL) {
|
||
|
printf("Error: Unable to open file.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
ExecutableHeader header;
|
||
|
|
||
|
if (file.size < sizeof(ExecutableHeader)) {
|
||
|
printf("Error: Unable to read header information.\n");
|
||
|
return 1;
|
||
|
} else {
|
||
|
memcpy(&header, file.data, sizeof(ExecutableHeader));
|
||
|
}
|
||
|
|
||
|
if (strncmp(header.signature, "MENUET01", SIGNATURE_SIZE) != 0 && strncmp(header.signature, "MENUET02", SIGNATURE_SIZE) != 0) {
|
||
|
printf("Error: Invalid signature.\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
printf("Version: %.*s\n", SIGNATURE_SIZE, header.signature);
|
||
|
printf("Start Address: 0x%x\n", header.startAddress);
|
||
|
printf("File Size: %u bytes\n", header.fileSize);
|
||
|
printf("Memory Required: %u bytes\n", header.memRequired);
|
||
|
printf("ESP Value: 0x%x\n", header.espValue);
|
||
|
printf("Parameter Address: 0x%x\n", header.paramAddress);
|
||
|
printf("File Path Address: 0x%x\n", header.filePathAddress);
|
||
|
if (strncmp(header.signature, "MENUET02", SIGNATURE_SIZE) == 0) {
|
||
|
printf("TLS Data Address: 0x%x\n", header.tlsDataAddress);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|