|
|
c0fbae |
#ifndef PERK_H
|
|
|
c0fbae |
#define PERK_H
|
|
|
c0fbae |
|
|
|
c0fbae |
#include <stdint.h>
|
|
|
c0fbae |
#include <stdio.h>
|
|
|
c0fbae |
|
|
|
1ef003 |
#include "perk_api.h"
|
|
|
c65ad9 |
#include "perk_consts.h"
|
|
|
c65ad9 |
#include "perk_structs.h"
|
|
|
c65ad9 |
#include "perk_meta.h"
|
|
|
c65ad9 |
#include "perk_output.h"
|
|
|
c0fbae |
|
|
|
c0fbae |
#ifdef __cplusplus
|
|
|
c0fbae |
extern "C" {
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
c0fbae |
/* pre-alpha */
|
|
|
c0fbae |
#ifndef PERK_APP
|
|
|
c0fbae |
#ifndef PERK_PRE_ALPHA
|
|
|
c0fbae |
#error libperk: pre-alpha: ABI is not final!
|
|
|
c0fbae |
#error to use the library, please pass -DPERK_PRE_ALPHA to the compiler.
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
c0fbae |
/* exec flags */
|
|
|
c0fbae |
#define PERK_HELP 0x01
|
|
|
c0fbae |
|
|
|
c0fbae |
/* errors */
|
|
|
c0fbae |
#define PERK_OK 0x00
|
|
|
c0fbae |
#define PERK_BAD_OPT 0xA1
|
|
|
c0fbae |
#define PERK_BAD_OPT_VAL 0xA2
|
|
|
c0fbae |
#define PERK_IO_ERROR 0xA3
|
|
|
c0fbae |
#define PERK_MAP_ERROR 0xA4
|
|
|
c0fbae |
#define PERK_BAD_DOS_HEADER 0xA5
|
|
|
c0fbae |
#define PERK_BAD_COFF_HEADER 0xA6
|
|
|
c0fbae |
#define PERK_BAD_IMAGE_TYPE 0xA7
|
|
|
c0fbae |
#define PERK_MALFORMED_IMAGE 0xA8
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_raw_image {
|
|
|
664d5b |
void * addr;
|
|
|
c0fbae |
size_t size;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_image_summary {
|
|
|
c0fbae |
uint32_t num_of_export_syms;
|
|
|
c0fbae |
uint32_t num_of_implibs;
|
|
|
c0fbae |
uint32_t num_of_relocs;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_image_meta {
|
|
|
c0fbae |
struct pe_raw_image image;
|
|
|
c0fbae |
struct pe_image_summary summary;
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_meta_image_dos_hdr dos;
|
|
|
c0fbae |
struct pe_meta_coff_file_hdr coff;
|
|
|
c0fbae |
struct pe_meta_opt_hdr opt;
|
|
|
c0fbae |
struct pe_meta_sec_hdr * sectbl;
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_image_dos_hdr * ados;
|
|
|
c0fbae |
struct pe_coff_file_hdr * acoff;
|
|
|
c0fbae |
union pe_opt_hdr * aopt;
|
|
|
c0fbae |
struct pe_sec_hdr * asectbl;
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_meta_export_hdr edata;
|
|
|
c0fbae |
struct pe_export_hdr * aedata;
|
|
|
c0fbae |
struct pe_meta_sec_hdr * hedata;
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_meta_import_hdr * idata;
|
|
|
c0fbae |
struct pe_import_hdr * aidata;
|
|
|
c0fbae |
struct pe_meta_sec_hdr * hidata;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
c0fbae |
/* utility api */
|
|
|
1ef003 |
perk_api int pe_output_export_symbols (const struct pe_image_meta *, uint32_t flags, FILE *);
|
|
|
c0fbae |
|
|
|
c0fbae |
/* high-level api */
|
|
|
2b71e8 |
perk_api int pe_map_raw_image (int fd, const char * name, int prot, struct pe_raw_image *);
|
|
|
1ef003 |
perk_api int pe_unmap_raw_image (struct pe_raw_image *);
|
|
|
c0fbae |
|
|
|
1ef003 |
perk_api int pe_get_image_meta (const struct pe_raw_image *, struct pe_image_meta **);
|
|
|
1ef003 |
perk_api int pe_free_image_meta (struct pe_image_meta *);
|
|
|
c0fbae |
|
|
|
1ef003 |
perk_api int pe_get_named_section_index (const struct pe_image_meta *, const char * name);
|
|
|
1ef003 |
perk_api int pe_get_block_section_index (const struct pe_image_meta *, const struct pe_block *);
|
|
|
c0fbae |
|
|
|
c0fbae |
/* low-level api */
|
|
|
1ef003 |
perk_api int pe_read_dos_header (const struct pe_image_dos_hdr *, struct pe_meta_image_dos_hdr *);
|
|
|
ca4943 |
perk_api int pe_read_coff_header (const struct pe_coff_file_hdr *, struct pe_meta_coff_file_hdr *);
|
|
|
1ef003 |
perk_api int pe_read_optional_header (const union pe_opt_hdr *, struct pe_meta_opt_hdr *);
|
|
|
1ef003 |
perk_api int pe_read_section_header (const struct pe_sec_hdr *, struct pe_meta_sec_hdr *);
|
|
|
1ef003 |
perk_api int pe_read_export_header (const struct pe_export_hdr *, struct pe_meta_export_hdr *);
|
|
|
1ef003 |
perk_api int pe_read_import_header (const struct pe_import_hdr *, struct pe_meta_import_hdr *);
|
|
|
1ef003 |
perk_api int pe_read_import_lookup_item (const struct pe_import_lookup_item *, struct pe_meta_import_lookup_item *,uint32_t magic);
|
|
|
c0fbae |
|
|
|
c0fbae |
#ifdef __cplusplus
|
|
|
c0fbae |
}
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
c0fbae |
#endif
|