Debian Codegraph @

include/fcml_renderer.h

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /** @file fcml_renderer.h
21 * Structures and functions declarations related to FCML renderers
22 *
23 * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved.
24 * This project is released under the GNU Lesser General Public License.
25 */
26
27 #ifndef FCML_REND_H_
28 #define FCML_REND_H_
29
30 #include "fcml_lib_export.h"
31
32 #include "fcml_types.h"
33 #include "fcml_errors.h"
34 #include "fcml_dialect.h"
35 #include "fcml_disassembler.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /** The rendered instruction size can not exceed this value. */
42 #define FCML_REND_MAX_BUFF_LEN 512
43
44 /**
45 * @defgroup RENDERER_FLAGS_GROUP Flags configuring rendering process.
46 * @{
47 */
48
49 /** Render the instruction code as HEX string. */
50 #define FCML_REND_FLAG_RENDER_CODE 0x00000001
51 /** Render the immediate operand as HEX integer. */
52 #define FCML_REND_FLAG_HEX_IMM 0x00000002
53 /** Render the segment code register even if it is a default one. */
54 #define FCML_REND_FLAG_RENDER_DEFAULT_SEG 0x00000004
55 /** Render the displacement value as HEX integer. */
56 #define FCML_REND_FLAG_HEX_DISPLACEMENT 0x00000008
57 /** Render the conditional mnemonics using suffixes from first group. */
58 #define FCML_REND_FLAG_COND_GROUP_1 0x00000010
59 /** Render the conditional mnemonics using suffixes from second group. */
60 #define FCML_REND_FLAG_COND_GROUP_2 0x00000020
61 /** Render the conditional mnemonics using suffixes for 'carry'. */
62 #define FCML_REND_FLAG_COND_SHOW_CARRY 0x00000040
63 /** Render SIB operand hints. */
64 #define FCML_REND_FLAG_RENDER_SIB_HINT 0x00000080
65 /** Render ABS (Absolute offset) operand hints. */
66 #define FCML_REND_FLAG_RENDER_ABS_HINT 0x00000100
67 /** Render REL (Relative offset) operand hints. */
68 #define FCML_REND_FLAG_RENDER_REL_HINT 0x00000200
69 /** Render hints for absolute addressing. */
70 #define FCML_REND_FLAG_RENDER_INDIRECT_HINT 0x00000400
71 /** Renders repetition prefixes using the first group (repe,repne). */
72 #define FCML_REND_FLAG_REP_PREFIX_GROUP_1 0x00000800
73 /** Renders repetition prefixes using the second group (repz,repnz). */
74 #define FCML_REND_FLAG_REP_PREFIX_GROUP_2 0x00001000
75 /** Renders the code padding between the instruction code and the mnemonic. */
76 #define FCML_REND_FLAG_CODE_PADDING 0x00002000
77 /** Renders the mnemonic padding between the mnemonic and the operands. */
78 #define FCML_REND_FLAG_MNEMONIC_PADDING 0x00004000
79 /** Should be used only with FCML_REND_FLAG_HEX_IMM and FCML_REND_FLAG_
80 * HEX_DISPLACEMENT flags. */
81 #define FCML_REND_FLAG_REMOVE_LEADING_ZEROS 0x00008000
82
83 /** Default set of the rendering flags. */
84 #define FCML_REND_DEFAULT_FLAGS 0
85 /** Default number of characters used as code padding. */
86 #define FCML_REND_DEFAULT_CODE_PADDING 8
87 /** Default number of characters used as mnemonic padding. */
88 #define FCML_REND_DEFAULT_MNEMONIC_PADDING 8
89
90 /** @} */
91
92 /** Renderer configuration. */
93 typedef struct fcml_st_render_config {
94 /** Flags which allows to control rendering process. */
95 fcml_uint32_t render_flags;
96 /** Preferred mnemonic padding in characters. */
97 fcml_uint16_t prefered_mnemonic_padding;
98 /** Preferred code padding in HEX bytes (2 characters on one byte.). */
99 fcml_uint16_t prefered_code_padding;
100 } fcml_st_render_config;
101
102 /**
103 * Renders the disassembled instruction into its textual representation.
104 * Prepares textual representation of the disassembled code using syntax
105 * based on the provided dialect.
106 *
107 * @param dialect Dialect instance.
108 * @param config Renderer configuration.
109 * @param[out] buffer Destination buffer for the generated instruction.
110 * @param buffer_len Size of the destination buffer.
111 * @param result Disassembled instruction.
112 * @return Error code or FCML_CEH_GEC_NO_ERROR.
113 *
114 */
115 LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_render(
116 const fcml_st_dialect *dialect, const fcml_st_render_config *config,
117 fcml_char *buffer, fcml_usize buffer_len,
118 const fcml_st_disassembler_result *result);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* FCML_REND_H_ */