refactoring + added obj library info

This commit is contained in:
rgimad 2024-03-20 17:29:28 +03:00
parent 929f757016
commit 1d985b790b
2 changed files with 66 additions and 33 deletions

BIN
kexview

Binary file not shown.

View File

@ -1,55 +1,88 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.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;
uint32_t start_address;
uint32_t file_size;
uint32_t memory_required;
uint32_t esp_value;
uint32_t param_address;
uint32_t file_path_address;
uint32_t tls_data_address; // This field is only for MENUET02 signature
} menuet_header_t;
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]);
void show_menuet_xx(const char *fpath) {
ksys_ufile_t file = _ksys_load_file(fpath);
if (file.data == NULL) {
printf("Error: Unable to open file.\n");
return 1;
printf("Error: Unable to open file.");
return;
}
ExecutableHeader header;
if (file.size < sizeof(ExecutableHeader)) {
printf("Error: Unable to read header information.\n");
return 1;
menuet_header_t header;
if (file.size < sizeof(menuet_header_t)) {
printf("Error: Unable to read header information.");
return;
} else {
memcpy(&header, file.data, sizeof(ExecutableHeader));
memcpy(&header, file.data, sizeof(menuet_header_t));
}
if (strncmp(header.signature, "MENUET01", SIGNATURE_SIZE) != 0 && strncmp(header.signature, "MENUET02", SIGNATURE_SIZE) != 0) {
printf("Error: Invalid signature.\n");
return 1;
return;
}
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);
printf("Start Address: 0x%x\n", header.start_address);
printf("File Size: %u bytes\n", header.file_size);
printf("Memory Required: %u bytes\n", header.memory_required);
printf("ESP Value: 0x%x\n", header.esp_value);
printf("Parameter Address: 0x%x\n", header.param_address);
printf("File Path Address: 0x%x\n", header.file_path_address);
if (strncmp(header.signature, "MENUET02", SIGNATURE_SIZE) == 0) {
printf("TLS Data Address: 0x%x\n", header.tlsDataAddress);
printf("TLS Data Address: 0x%x\n", header.tls_data_address);
}
}
void show_library(const char *fpath) {
ksys_dll_t *table = _ksys_dlopen(fpath);
if (table == NULL) {
printf("Failed to load library.");
return;
}
size_t i = 0;
for (;;) {
char *func_name = (table + i)->func_name;
void *func_ptr = (table + i)->func_ptr;
if (func_name == NULL) {
if (i == 0) {
printf("No functions in export table.");
}
return;
} else {
printf("%s %p\n", func_name, func_ptr);
}
i++;
}
}
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage:\nkexview <kex_file> - view info about kex program\nkexview -l <obj_file> - view info about obj library");
return;
}
if (strcmp(argv[1], "-l") == 0) {
if (argc < 3) {
printf("Error: library expected after -l");
return;
}
show_library(argv[2]);
} else {
show_menuet_xx(argv[1]);
}
return 0;