|
|
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_meta.h"
|
|
|
c0fbae |
|
|
|
c0fbae |
#ifdef __cplusplus
|
|
|
c0fbae |
extern "C" {
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
c0fbae |
/* pre-alpha */
|
|
|
c0fbae |
#ifndef PERK_APP
|
|
|
c0fbae |
#ifndef PERK_PRE_ALPHA
|
|
|
a5c7b3 |
#warning libperk: pre-alpha: ABI is not final!
|
|
|
a5c7b3 |
#warning pass -DPERK_PRE_ALPHA to suppress this warning.
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
d6e02b |
|
|
|
a3de1c |
/* status codes */
|
|
|
a3de1c |
#define PERK_OK 0x00
|
|
|
a3de1c |
#define PERK_USAGE 0x01
|
|
|
b0d024 |
#define PERK_ERROR 0x02
|
|
|
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 |
|
|
|
68f5d9 |
#define PERK_DRIVER_ANNOTATE_ALWAYS 0x1000
|
|
|
68f5d9 |
#define PERK_DRIVER_ANNOTATE_NEVER 0x2000
|
|
|
68f5d9 |
#define PERK_DRIVER_ANNOTATE_FULL 0x4000
|
|
|
68f5d9 |
|
|
|
a3de1c |
/* unit action flags */
|
|
|
8fd1f5 |
#define PERK_ACTION_MAP_READWRITE 0x0001
|
|
|
a3de1c |
|
|
|
e8769a |
/* error flags */
|
|
|
e8769a |
#define PERK_ERROR_TOP_LEVEL 0x0001
|
|
|
e8769a |
#define PERK_ERROR_NESTED 0x0002
|
|
|
e8769a |
#define PERK_ERROR_CHILD 0x0004
|
|
|
e8769a |
#define PERK_ERROR_CUSTOM 0x0008
|
|
|
e8769a |
|
|
|
ff121d |
enum pe_custom_error {
|
|
|
ff121d |
PERK_ERR_FLOW_ERROR,
|
|
|
ff121d |
PERK_ERR_FLEE_ERROR,
|
|
|
ff121d |
PERK_ERR_NULL_CONTEXT,
|
|
|
ff121d |
PERK_ERR_NULL_IMAGE,
|
|
|
ff121d |
PERK_ERR_INVALID_CONTEXT,
|
|
|
ff121d |
PERK_ERR_INVALID_IMAGE,
|
|
|
ff121d |
PERK_ERR_IMAGE_SIZE_ZERO,
|
|
|
ff121d |
PERK_ERR_IMAGE_MALFORMED,
|
|
|
ff121d |
PERK_ERR_BAD_DOS_HEADER,
|
|
|
ff121d |
PERK_ERR_BAD_COFF_HEADER,
|
|
|
ff121d |
PERK_ERR_BAD_IMAGE_TYPE,
|
|
|
c63b6d |
PERK_ERR_UNSUPPORTED_ABI,
|
|
|
ff121d |
PERK_ERR_CAP,
|
|
|
ff121d |
};
|
|
|
ff121d |
|
|
|
d6e02b |
struct pe_raw_image;
|
|
|
d6e02b |
struct pe_raw_image_dos_hdr;
|
|
|
d6e02b |
struct pe_raw_coff_image_hdr;
|
|
|
d6e02b |
struct pe_raw_coff_object_hdr;
|
|
|
d6e02b |
union pe_raw_opt_hdr;
|
|
|
d6e02b |
struct pe_raw_sec_hdr;
|
|
|
d6e02b |
struct pe_raw_export_hdr;
|
|
|
d6e02b |
struct pe_raw_import_hdr;
|
|
|
d6e02b |
struct pe_raw_coff_symbol;
|
|
|
d6e02b |
|
|
|
c0fbae |
struct pe_raw_image {
|
|
|
ed06fb |
void * map_addr;
|
|
|
ed06fb |
size_t map_size;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
cf4adc |
struct pe_expsym {
|
|
|
f0d194 |
const char * s_name;
|
|
|
f0d194 |
void * s_eaddr;
|
|
|
f0d194 |
void * s_maddr;
|
|
|
f0d194 |
uint32_t s_roffset;
|
|
|
cf4adc |
};
|
|
|
cf4adc |
|
|
|
753060 |
struct pe_meta_stats {
|
|
|
2111da |
int32_t t_nexpsyms;
|
|
|
2111da |
int32_t t_nimplibs;
|
|
|
20e8a3 |
int32_t t_ndsolibs;
|
|
|
20e8a3 |
int32_t t_ndsosyms;
|
|
|
2111da |
int32_t t_nrelocs;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
c0fbae |
struct pe_image_meta {
|
|
|
f3d26e |
struct pe_raw_image r_image;
|
|
|
f3d26e |
struct pe_raw_image_dos_hdr * r_dos;
|
|
|
f3d26e |
struct pe_raw_coff_image_hdr * r_coff;
|
|
|
f3d26e |
struct pe_raw_coff_object_hdr * r_obj;
|
|
|
f3d26e |
union pe_raw_opt_hdr * r_opt;
|
|
|
f3d26e |
struct pe_raw_sec_hdr * r_sectbl;
|
|
|
f3d26e |
|
|
|
f3d26e |
struct pe_raw_export_hdr * r_edata;
|
|
|
f3d26e |
struct pe_raw_import_hdr * r_idata;
|
|
|
f3d26e |
|
|
|
20e8a3 |
void * r_dsometa;
|
|
|
20e8a3 |
void * r_dsosyms;
|
|
|
20e8a3 |
char * r_dsostrs;
|
|
|
20e8a3 |
void * r_dsodata;
|
|
|
20e8a3 |
|
|
|
58ced9 |
struct pe_meta_stats m_stats;
|
|
|
58ced9 |
struct pe_meta_image_dos_hdr m_dos;
|
|
|
58ced9 |
struct pe_meta_coff_file_hdr m_coff;
|
|
|
58ced9 |
struct pe_meta_opt_hdr m_opt;
|
|
|
58ced9 |
struct pe_meta_sec_hdr * m_sectbl;
|
|
|
c0fbae |
|
|
|
58ced9 |
struct pe_meta_export_hdr m_edata;
|
|
|
58ced9 |
struct pe_meta_import_hdr * m_idata;
|
|
|
c004d0 |
|
|
|
25e3c0 |
struct pe_meta_sec_hdr * h_edata;
|
|
|
25e3c0 |
struct pe_meta_sec_hdr * h_idata;
|
|
|
20e8a3 |
|
|
|
20e8a3 |
struct pe_meta_sec_hdr * h_dsometa;
|
|
|
20e8a3 |
struct pe_meta_sec_hdr * h_dsosyms;
|
|
|
20e8a3 |
struct pe_meta_sec_hdr * h_dsostrs;
|
|
|
20e8a3 |
struct pe_meta_sec_hdr * h_dsodata;
|
|
|
867bfb |
|
|
|
867bfb |
enum pe_abi m_abi;
|
|
|
867bfb |
enum pe_subtype m_subtype;
|
|
|
867bfb |
enum pe_framework m_framework;
|
|
|
c0fbae |
};
|
|
|
c0fbae |
|
|
|
068b8d |
struct pe_source_version {
|
|
|
068b8d |
int major;
|
|
|
068b8d |
int minor;
|
|
|
068b8d |
int revision;
|
|
|
068b8d |
const char * commit;
|
|
|
068b8d |
};
|
|
|
068b8d |
|
|
|
a85d3e |
struct pe_fd_ctx {
|
|
|
a85d3e |
int fdin;
|
|
|
a85d3e |
int fdout;
|
|
|
a85d3e |
int fderr;
|
|
|
a85d3e |
int fdlog;
|
|
|
a85d3e |
int fdcwd;
|
|
|
a85d3e |
int fddst;
|
|
|
a85d3e |
};
|
|
|
a85d3e |
|
|
|
e8769a |
struct pe_error_info {
|
|
|
f006c4 |
const struct pe_driver_ctx * edctx;
|
|
|
f006c4 |
const struct pe_unit_ctx * euctx;
|
|
|
f006c4 |
const char * eunit;
|
|
|
f006c4 |
int esyscode;
|
|
|
f006c4 |
int elibcode;
|
|
|
f006c4 |
const char * efunction;
|
|
|
f006c4 |
int eline;
|
|
|
f006c4 |
unsigned eflags;
|
|
|
f006c4 |
void * eany;
|
|
|
e8769a |
};
|
|
|
e8769a |
|
|
|
76aabf |
struct pe_common_ctx {
|
|
|
a3de1c |
uint64_t drvflags;
|
|
|
a3de1c |
uint64_t actflags;
|
|
|
a3de1c |
uint64_t fmtflags;
|
|
|
d38fc0 |
uint64_t hdrdump;
|
|
|
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;
|
|
|
e8769a |
struct pe_error_info ** errv;
|
|
|
85119e |
void * any;
|
|
|
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;
|
|
|
85119e |
void * any;
|
|
|
a3de1c |
};
|
|
|
a3de1c |
|
|
|
bf447f |
struct pe_info_string {
|
|
|
bf447f |
char buffer[128];
|
|
|
bf447f |
};
|
|
|
bf447f |
|
|
|
a3de1c |
/* driver api */
|
|
|
4323e6 |
perk_api int pe_get_driver_ctx (char ** argv, char ** envp, uint32_t flags,
|
|
|
a85d3e |
const struct pe_fd_ctx *,
|
|
|
4323e6 |
struct pe_driver_ctx **);
|
|
|
4323e6 |
|
|
|
4323e6 |
perk_api void pe_free_driver_ctx (struct pe_driver_ctx *);
|
|
|
a3de1c |
|
|
|
4323e6 |
perk_api int pe_get_unit_ctx (const struct pe_driver_ctx *, const char * path,
|
|
|
4323e6 |
struct pe_unit_ctx **);
|
|
|
4323e6 |
|
|
|
4323e6 |
perk_api void pe_free_unit_ctx (struct pe_unit_ctx *);
|
|
|
a3de1c |
|
|
|
a85d3e |
perk_api int pe_get_driver_fdctx (const struct pe_driver_ctx *, struct pe_fd_ctx *);
|
|
|
a85d3e |
perk_api int pe_set_driver_fdctx (struct pe_driver_ctx *, const struct pe_fd_ctx *);
|
|
|
a85d3e |
|
|
|
c0fbae |
/* utility api */
|
|
|
e1a772 |
perk_api int pe_main (char **, char **, const struct pe_fd_ctx *);
|
|
|
a85d3e |
|
|
|
67bba7 |
perk_api int pe_output_image_category (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
67bba7 |
perk_api int pe_output_image_sections (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
67bba7 |
perk_api int pe_output_image_symbols (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
67bba7 |
perk_api int pe_output_image_strings (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
67bba7 |
perk_api int pe_output_export_symbols (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
67bba7 |
perk_api int pe_output_import_libraries(const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
67bba7 |
perk_api int pe_output_mdso_libraries (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
27496e |
|
|
|
71ed2f |
/* header dump api */
|
|
|
71ed2f |
perk_api int pe_hdrdump_image_dos_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
153cea |
perk_api int pe_hdrdump_coff_image_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
ec3678 |
perk_api int pe_hdrdump_coff_object_hdr(const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
7dfe4b |
perk_api int pe_hdrdump_coff_opt_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
1ce710 |
perk_api int pe_hdrdump_sec_tbl (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
225d90 |
perk_api int pe_hdrdump_export_hdr (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
8f30d9 |
perk_api int pe_hdrdump_import_tbl (const struct pe_driver_ctx *, const struct pe_image_meta *);
|
|
|
71ed2f |
|
|
|
27496e |
/* error trace api */
|
|
|
4323e6 |
perk_api int pe_output_error_record (const struct pe_driver_ctx *, const struct pe_error_info *);
|
|
|
4323e6 |
perk_api int pe_output_error_vector (const struct pe_driver_ctx *);
|
|
|
4323e6 |
|
|
|
4323e6 |
/* raw image api */
|
|
|
4323e6 |
perk_api int pe_map_raw_image (const struct pe_driver_ctx *,
|
|
|
4323e6 |
int fd, const char * path, int prot,
|
|
|
4323e6 |
struct pe_raw_image *);
|
|
|
c0fbae |
|
|
|
4323e6 |
perk_api int pe_unmap_raw_image (struct pe_raw_image *);
|
|
|
c0fbae |
|
|
|
4323e6 |
/* image meta api */
|
|
|
4323e6 |
perk_api int pe_get_image_meta (const struct pe_driver_ctx *,
|
|
|
4323e6 |
const struct pe_raw_image *,
|
|
|
4323e6 |
struct pe_image_meta **);
|
|
|
c0fbae |
|
|
|
4323e6 |
perk_api void pe_free_image_meta (struct pe_image_meta *);
|
|
|
4323e6 |
|
|
|
4323e6 |
perk_api int pe_get_named_section_index(const struct pe_image_meta *, const char *);
|
|
|
2b7f36 |
perk_api int pe_get_block_section_index(const struct pe_image_meta *, const struct pe_block *);
|
|
|
62b9db |
|
|
|
4323e6 |
perk_api int pe_get_roffset_from_rva (const struct pe_image_meta *, uint32_t, uint32_t *);
|
|
|
4323e6 |
perk_api int pe_get_rva_from_roffset (const struct pe_image_meta *, uint32_t, uint32_t *);
|
|
|
62b9db |
|
|
|
4323e6 |
perk_api int pe_get_expsym_by_name (const struct pe_image_meta *, const char *, struct pe_expsym *);
|
|
|
4323e6 |
perk_api int pe_get_expsym_by_index (const struct pe_image_meta *, unsigned, struct pe_expsym *);
|
|
|
c7ca52 |
|
|
|
bf447f |
/* info api */
|
|
|
4323e6 |
perk_api int pe_get_image_abi (const struct pe_image_meta *, struct pe_info_string *);
|
|
|
4323e6 |
perk_api int pe_get_image_subtype (const struct pe_image_meta *, struct pe_info_string *);
|
|
|
4323e6 |
perk_api int pe_get_image_subsystem (const struct pe_image_meta *, struct pe_info_string *);
|
|
|
4323e6 |
perk_api int pe_get_image_framework (const struct pe_image_meta *, struct pe_info_string *);
|
|
|
bf447f |
|
|
|
c0fbae |
/* low-level api */
|
|
|
4323e6 |
perk_api int pe_read_dos_header (const struct pe_raw_image_dos_hdr *, struct pe_meta_image_dos_hdr *);
|
|
|
4323e6 |
perk_api int pe_read_coff_header (const struct pe_raw_coff_image_hdr *, struct pe_meta_coff_file_hdr *);
|
|
|
4323e6 |
perk_api int pe_read_object_header (const struct pe_raw_coff_object_hdr *, struct pe_meta_coff_file_hdr *);
|
|
|
4323e6 |
perk_api int pe_read_optional_header (const union pe_raw_opt_hdr *, struct pe_meta_opt_hdr *);
|
|
|
4323e6 |
perk_api int pe_read_section_header (const struct pe_raw_sec_hdr *, struct pe_meta_sec_hdr *);
|
|
|
4323e6 |
perk_api int pe_read_export_header (const struct pe_raw_export_hdr *, struct pe_meta_export_hdr *);
|
|
|
4323e6 |
perk_api int pe_read_import_header (const struct pe_raw_import_hdr *, struct pe_meta_import_hdr *);
|
|
|
4323e6 |
|
|
|
4323e6 |
perk_api int pe_read_coff_symbol (const struct pe_raw_coff_symbol *, struct pe_meta_coff_symbol *,
|
|
|
4323e6 |
const struct pe_meta_coff_file_hdr *, void * base);
|
|
|
4323e6 |
|
|
|
91d87e |
perk_api int pe_read_import_lookup (const unsigned char *, struct pe_meta_import_lookup *,
|
|
|
4323e6 |
uint32_t magic);
|
|
|
4323e6 |
|
|
|
4323e6 |
/* package info */
|
|
|
4323e6 |
perk_api const struct pe_source_version * pe_source_version(void);
|
|
|
381efa |
|
|
|
c0fbae |
#ifdef __cplusplus
|
|
|
c0fbae |
}
|
|
|
c0fbae |
#endif
|
|
|
c0fbae |
|
|
|
c0fbae |
#endif
|