Debian Codegraph @

mingw-w64-tools/genpeimg/src/img.h

raw
1 /*
2 genpeimg - Modify Portable Executable flags and properties.
3 Copyright (C) 2009-2016 mingw-w64 project
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef IMG_HXX
19 #define IMG_HXX
20
21 typedef struct file_image {
22 unsigned char *data;
23 size_t data_len;
24 char *filename;
25 unsigned int is_modified : 1;
26 unsigned int want_save : 1;
27 } file_image;
28
29 file_image *fimg_create (void);
30 void fimg_free (file_image *pimg);
31 void fimg_show_stats (const file_image *pimg);
32 void fimg_dump_mem (const file_image *pimg, size_t len, FILE *out);
33 int fimg_load (file_image *pimg, const char *fname);
34 int fimg_rename (file_image *pimg, const char *newfname);
35 int fimg_save_as (file_image *pimg, const char *fname, size_t length);
36 int fimg_save (file_image *pimg);
37 int fimg_resize (file_image *pimg, size_t new_size);
38 file_image *fimg_clone (const file_image *pimg);
39 int fimg_replace_at (file_image *pimg, const void *dta, size_t pos, size_t length);
40 int fimg_insert_at (file_image *pimg, const void *dta, size_t pos, size_t length);
41 int fimg_remove_at (file_image *pimg, size_t pos, size_t length);
42
43 unsigned char fimg_get_uchar_at (const file_image *pimg, size_t pos);
44 int fimg_set_uchar_at (file_image *pimg, unsigned char val, size_t pos);
45 unsigned short fimg_get_ushort_at (const file_image *pimg, size_t pos, int big_endian);
46 int fimg_set_ushort_at (file_image *pimg, unsigned short val, size_t pos, int big_endian);
47 unsigned int fimg_get_uint_at (const file_image *pimg, size_t pos, int big_endian);
48 int fimg_set_uint_at (file_image *pimg, unsigned int val, size_t pos, int big_endian);
49 unsigned long long fimg_get_uquad_at (const file_image *pimg, size_t pos, int big_endian);
50 int fimg_set_uquad_at (file_image *pimg, unsigned long long val, size_t pos, int big_endian);
51
52 #define FIMG_POS_END ~((size_t) 0)
53
54 typedef struct pe_image {
55 file_image *pimg;
56 size_t start_pe;
57 size_t size_pe;
58 struct {
59 unsigned short machine;
60 unsigned short numsecs;
61 unsigned int timestamp;
62 unsigned int pointer2SymTab;
63 unsigned int numSyms;
64 unsigned short szOptHdr;
65 unsigned short characteristics;
66 } pe_filehdr;
67 size_t optional_hdr_pos;
68 size_t section_list;
69 size_t section_list_sz; /* Each section entry has 40 bytes size. */
70 unsigned int is_64bit : 1;
71 unsigned int is_bigendian : 1;
72 } pe_image;
73
74 pe_image *peimg_create (file_image *pimg);
75 pe_image *peimg_load (const char *fname);
76 void peimg_free (pe_image *ppeimg);
77 void peimg_show (pe_image *ppeimg, FILE *outfp);
78
79 void peimg_set_hdr_characeristics (pe_image *pe, unsigned short set, unsigned short mask);
80 void peimg_set_hdr_opt_dll_characteristics (pe_image *pe, unsigned short set, unsigned short mask);
81 void peimg_set_hdr_opt_subsystem (pe_image *pe, unsigned short subsystem);
82
83 #define PEIMG_GET_UCHAR(PEIMG, POS) fimg_get_uchar_at ((PEIMG)->pimg, ((PEIMG)->start_pe + (POS)))
84 #define PEIMG_GET_USHORT(PEIMG, POS) fimg_get_ushort_at ((PEIMG)->pimg, ((PEIMG)->start_pe + (POS)), (PEIMG)->is_bigendian)
85 #define PEIMG_GET_UINT(PEIMG, POS) fimg_get_uint_at ((PEIMG)->pimg, ((PEIMG)->start_pe + (POS)), (PEIMG)->is_bigendian)
86 #define PEIMG_GET_UQUAD(PEIMG, POS) fimg_get_uquad_at ((PEIMG)->pimg, ((PEIMG)->start_pe + (POS)), (PEIMG)->is_bigendian)
87
88 #define PEIMG_SET_UCHAR(PEIMG, POS, VAL) fimg_set_uchar_at ((PEIMG)->pimg, (unsigned char) (VAL), ((PEIMG)->start_pe + (POS)))
89 #define PEIMG_SET_USHORT(PEIMG, POS, VAL) fimg_set_ushort_at ((PEIMG)->pimg, (unsigned short) (VAL), ((PEIMG)->start_pe + (POS)), (PEIMG)->is_bigendian)
90 #define PEIMG_SET_UINT(PEIMG, POS, VAL) fimg_set_uint_at ((PEIMG)->pimg, (unsigned int) (VAL), ((PEIMG)->start_pe + (POS)), (PEIMG)->is_bigendian)
91 #define PEIMG_SET_UQUAD(PEIMG, POS, VAL) fimg_set_uquad_at ((PEIMG)->pimg, (unsigned long long) (VAL), ((PEIMG)->start_pe + (POS)), (PEIMG)->is_bigendian)
92
93 #endif