1 /*
2  *  Copyright (C) 2018-2022 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
3  *
4  *  Authors: Andrew Williams
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License version 2 as
8  *  published by the Free Software Foundation.
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, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  *  MA 02110-1301, USA.
19  */
20 
21 #include "execs.h"
22 #include <string.h>
23 
cli_exe_info_init(struct cli_exe_info * exeinfo,uint32_t offset)24 void cli_exe_info_init(struct cli_exe_info *exeinfo, uint32_t offset)
25 {
26 
27     if (NULL == exeinfo) {
28         return;
29     }
30 
31     memset(exeinfo, '\0', sizeof(*exeinfo));
32     exeinfo->offset = offset;
33 
34     // TODO Replace the memset above with the following once we can make
35     // certain that this is the only initialization needed (maybe run with
36     // MemorySanitizer?)
37 
38     ///* Initialize all of the members which are actually used by the matcher
39     // * and by the bytecode runtime.  The rest is executable specific and
40     // * we'll leave it to be populated by the exe parsing code. */
41     //exeinfo->offset = offset;
42     //exeinfo->sections = NULL;
43     //exeinfo->nsections = 0;
44     //exeinfo->ep = 0;
45     ///* NOTE: These are PE-specific to an extent, but we should still
46     // * initialize them for other exe types because they are used by
47     // * the matcher/bytecode runtime. */
48     //exeinfo->hdr_size = 0;
49     //exeinfo->res_addr = 0;
50     //cli_hashset_init_noalloc(&(exeinfo->vinfo));
51 }
52 
cli_exe_info_destroy(struct cli_exe_info * exeinfo)53 void cli_exe_info_destroy(struct cli_exe_info *exeinfo)
54 {
55 
56     if (NULL == exeinfo) {
57         return;
58     }
59 
60     if (NULL != exeinfo->sections) {
61         free(exeinfo->sections);
62         exeinfo->sections = NULL;
63     }
64 
65     cli_hashset_destroy(&(exeinfo->vinfo));
66 }
67