|
|
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"
|
|
|
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 |
|
|
|
a3de1c |
/* status codes */
|
|
|
a3de1c |
#define PERK_OK 0x00
|
|
|
a3de1c |
#define PERK_USAGE 0x01
|
|
|
a3de1c |
#define PERK_BAD_OPT 0x02
|
|
|
a3de1c |
#define PERK_BAD_OPT_VAL 0x03
|
|
|
a3de1c |
#define PERK_IO_ERROR 0xA0
|
|
|
a3de1c |
#define PERK_MAP_ERROR 0xA1
|
|
|
a3de1c |
#define PERK_BAD_DOS_HEADER 0xA2
|
|
|
a3de1c |
#define PERK_BAD_COFF_HEADER 0xA3
|
|
|
a3de1c |
#define PERK_BAD_IMAGE_TYPE 0xA4
|
|
|
a3de1c |
#define PERK_MALFORMED_IMAGE 0xA5
|
|
|
a3de1c |
|
|
|
a3de1c |
/* driver flags */
|
|
|
a3de1c |
#define PERK_DRIVER_VERBOSITY_NONE 0x0000
|
|
|
a3de1c |
#define PERK_DRIVER_VERBOSITY_ERRORS 0x0001
|
|
|
a3de1c |
#define PERK_DRIVER_VERBOSITY_STATUS 0x0002
|
|
|
a3de1c |
#define PERK_DRIVER_VERBOSITY_USAGE 0x0004
|
|
|
a3de1c |
#define PERK_DRIVER_CLONE_VECTOR 0x0008
|
|
|
a3de1c |
|
|
|
8fd1f5 |
#define PERK_DRIVER_VERSION 0x0010
|
|
|
8fd1f5 |
#define PERK_DRIVER_DRY_RUN 0x0020
|
|
|
a3de1c |
|
|
|
a3de1c |
/* unit action flags */
|
|
|
8fd1f5 |
#define PERK_ACTION_MAP_READWRITE 0x0001
|
|
|
a3de1c |
|
|
|
b7025c |
struct pe_source_version {
|
|
|
b7025c |
int major;
|
|
|
b7025c |
int minor;
|
|
|
b7025c |
int revision;
|
|
|
b7025c |
const char * commit;
|
|
|
b7025c |
};
|
|
|
b7025c |
|
|
|
c0fbae |
struct pe_raw_image {
|
|
|
664d5b |
void * addr;
|
|
|
c0fbae |
size_t size;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_image_summary {
|
|
|
c3f597 |
int32_t nexpsyms;
|
|
|
c3f597 |
int32_t nimplibs;
|
|
|
c3f597 |
int32_t nrelocs;
|
|
|
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 |
|
|
|
a3de1c |
struct pe_symbol_ctx {
|
|
|
6e8138 |
const char ** attrs;
|
|
|
a3de1c |
const char ** append;
|
|
|
a3de1c |
const char ** exclude;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
a3de1c |
struct pe_output_ctx {
|
|
|
6e8138 |
const char ** attrs;
|
|
|
a3de1c |
const char * header;
|
|
|
a3de1c |
const char * footer;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
a3de1c |
struct pe_linker_ctx {
|
|
|
6e8138 |
const char ** attrs;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
a3de1c |
struct pe_server_ctx {
|
|
|
6e8138 |
const char ** attrs;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
76aabf |
struct pe_io_ctx {
|
|
|
76aabf |
int status;
|
|
|
76aabf |
int prot;
|
|
|
76aabf |
int mode;
|
|
|
a3de1c |
int fdin;
|
|
|
a3de1c |
int fdout;
|
|
|
a3de1c |
int fderr;
|
|
|
a3de1c |
int fdlog;
|
|
|
a3de1c |
int fdsrc;
|
|
|
a3de1c |
int fddst;
|
|
|
a3de1c |
int fdtmp;
|
|
|
76aabf |
};
|
|
|
76aabf |
|
|
|
76aabf |
struct pe_common_ctx {
|
|
|
a3de1c |
uint64_t drvflags;
|
|
|
a3de1c |
uint64_t actflags;
|
|
|
a3de1c |
uint64_t fmtflags;
|
|
|
a3de1c |
uint64_t lnkflags;
|
|
|
a3de1c |
const char * output;
|
|
|
a3de1c |
const char * srcdir;
|
|
|
a3de1c |
const char * dstdir;
|
|
|
a3de1c |
const char * tmpdir;
|
|
|
88e832 |
const struct pe_symbol_ctx * symctx;
|
|
|
88e832 |
const struct pe_output_ctx * outctx;
|
|
|
88e832 |
const struct pe_linker_ctx * lnkctx;
|
|
|
88e832 |
const struct pe_server_ctx * srvctx;
|
|
|
76aabf |
const struct pe_io_ctx * ioctx;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
a3de1c |
struct pe_driver_ctx {
|
|
|
a3de1c |
const char ** units;
|
|
|
a3de1c |
const char * program;
|
|
|
a3de1c |
const char * module;
|
|
|
c61328 |
const struct pe_common_ctx * cctx;
|
|
|
85119e |
void * any;
|
|
|
85119e |
int status;
|
|
|
85119e |
int nerrors;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
a3de1c |
struct pe_unit_ctx {
|
|
|
d7ed3e |
const char * const * path;
|
|
|
d7ed3e |
const struct pe_raw_image * map;
|
|
|
d7ed3e |
const struct pe_image_meta * meta;
|
|
|
d7ed3e |
const struct pe_common_ctx * cctx;
|
|
|
85119e |
void * any;
|
|
|
d7ed3e |
int status;
|
|
|
d7ed3e |
int nerrors;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
b7025c |
/* package info */
|
|
|
b7025c |
perk_api const struct pe_source_version * pe_source_version(void);
|
|
|
b7025c |
|
|
|
a3de1c |
/* driver api */
|
|
|
7d4640 |
perk_api int pe_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, struct pe_driver_ctx **);
|
|
|
fa22b4 |
perk_api void pe_free_driver_ctx (struct pe_driver_ctx *);
|
|
|
a3de1c |
|
|
|
a9788e |
perk_api int pe_get_unit_ctx (const struct pe_driver_ctx *, const char * path, struct pe_unit_ctx **);
|
|
|
fa22b4 |
perk_api void pe_free_unit_ctx (struct pe_unit_ctx *);
|
|
|
a3de1c |
|
|
|
c0fbae |
/* utility api */
|
|
|
2b7f36 |
perk_api int pe_output_export_symbols (const struct pe_image_meta *, const struct pe_common_ctx *, FILE *);
|
|
|
9c5807 |
perk_api int pe_output_import_libraries(const struct pe_image_meta *, const struct pe_common_ctx *, FILE *);
|
|
|
c0fbae |
|
|
|
c0fbae |
/* high-level api */
|
|
|
2b7f36 |
perk_api int pe_map_raw_image (int fd, const char * path, int prot, struct pe_raw_image *);
|
|
|
2b7f36 |
perk_api int pe_unmap_raw_image (struct pe_raw_image *);
|
|
|
c0fbae |
|
|
|
2b7f36 |
perk_api int pe_get_image_meta (const struct pe_raw_image *, struct pe_image_meta **);
|
|
|
2b7f36 |
perk_api void pe_free_image_meta (struct pe_image_meta *);
|
|
|
c0fbae |
|
|
|
2b7f36 |
perk_api int pe_get_named_section_index(const struct pe_image_meta *, const char * name);
|
|
|
2b7f36 |
perk_api int pe_get_block_section_index(const struct pe_image_meta *, const struct pe_block *);
|
|
|
c0fbae |
|
|
|
c0fbae |
/* low-level api */
|
|
|
2b7f36 |
perk_api int pe_read_dos_header (const struct pe_image_dos_hdr *, struct pe_meta_image_dos_hdr *);
|
|
|
2b7f36 |
perk_api int pe_read_coff_header (const struct pe_coff_file_hdr *, struct pe_meta_coff_file_hdr *);
|
|
|
2b7f36 |
perk_api int pe_read_optional_header (const union pe_opt_hdr *, struct pe_meta_opt_hdr *);
|
|
|
2b7f36 |
perk_api int pe_read_section_header (const struct pe_sec_hdr *, struct pe_meta_sec_hdr *);
|
|
|
2b7f36 |
perk_api int pe_read_export_header (const struct pe_export_hdr *, struct pe_meta_export_hdr *);
|
|
|
2b7f36 |
perk_api int pe_read_import_header (const struct pe_import_hdr *, struct pe_meta_import_hdr *);
|
|
|
7d4d3d |
perk_api int pe_read_import_lookup_item(const union pe_import_lookup_item *, struct pe_meta_import_lookup_item *, uint32_t magic);
|
|
|
c0fbae |
|
|
|
c0fbae |
#ifdef __cplusplus
|
|
|
c0fbae |
}
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
c0fbae |
#endif
|