File: fcml_renderer.h

package info (click to toggle)
fcml 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,536 kB
  • sloc: ansic: 57,510; cpp: 21,835; sh: 4,410; lex: 834; makefile: 508; yacc: 317
file content (124 lines) | stat: -rw-r--r-- 4,830 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * FCML - Free Code Manipulation Library.
 * Copyright (C) 2010-2020 Slawomir Wojtasiak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/** @file fcml_renderer.h
 * Structures and functions declarations related to FCML renderers
 *
 * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved.
 * This project is released under the GNU Lesser General Public License.
 */

#ifndef FCML_REND_H_
#define FCML_REND_H_

#include "fcml_lib_export.h"

#include "fcml_types.h"
#include "fcml_errors.h"
#include "fcml_dialect.h"
#include "fcml_disassembler.h"

#ifdef __cplusplus
extern "C" {
#endif

/** The rendered instruction size can not exceed this value. */
#define FCML_REND_MAX_BUFF_LEN					512

/**
 * @defgroup RENDERER_FLAGS_GROUP Flags configuring rendering process.
 * @{
 */

/** Render the instruction code as HEX string. */
#define FCML_REND_FLAG_RENDER_CODE				0x00000001
/** Render the immediate operand as HEX integer. */
#define FCML_REND_FLAG_HEX_IMM					0x00000002
/** Render the segment code register even if it is a default one. */
#define FCML_REND_FLAG_RENDER_DEFAULT_SEG		0x00000004
/** Render the displacement value as HEX integer. */
#define FCML_REND_FLAG_HEX_DISPLACEMENT			0x00000008
/** Render the conditional mnemonics using suffixes from first group. */
#define FCML_REND_FLAG_COND_GROUP_1				0x00000010
/** Render the conditional mnemonics using suffixes from second group. */
#define FCML_REND_FLAG_COND_GROUP_2				0x00000020
/** Render the conditional mnemonics using suffixes for 'carry'. */
#define FCML_REND_FLAG_COND_SHOW_CARRY			0x00000040
/** Render SIB operand hints. */
#define FCML_REND_FLAG_RENDER_SIB_HINT			0x00000080
/** Render ABS (Absolute offset) operand hints. */
#define FCML_REND_FLAG_RENDER_ABS_HINT			0x00000100
/** Render REL (Relative offset) operand hints. */
#define FCML_REND_FLAG_RENDER_REL_HINT			0x00000200
/** Render hints for absolute addressing. */
#define FCML_REND_FLAG_RENDER_INDIRECT_HINT		0x00000400
/** Renders repetition prefixes using the first group (repe,repne). */
#define FCML_REND_FLAG_REP_PREFIX_GROUP_1		0x00000800
/** Renders repetition prefixes using the second group (repz,repnz). */
#define FCML_REND_FLAG_REP_PREFIX_GROUP_2		0x00001000
/** Renders the code padding between the instruction code and the mnemonic. */
#define FCML_REND_FLAG_CODE_PADDING				0x00002000
/** Renders the mnemonic padding between the mnemonic and the operands. */
#define FCML_REND_FLAG_MNEMONIC_PADDING			0x00004000
/** Should be used only with FCML_REND_FLAG_HEX_IMM and FCML_REND_FLAG_
 * HEX_DISPLACEMENT flags. */
#define FCML_REND_FLAG_REMOVE_LEADING_ZEROS		0x00008000

/** Default set of the rendering flags. */
#define FCML_REND_DEFAULT_FLAGS				0
/** Default number of characters used as code padding. */
#define FCML_REND_DEFAULT_CODE_PADDING		8
/** Default number of characters used as mnemonic padding. */
#define FCML_REND_DEFAULT_MNEMONIC_PADDING	8

/** @} */

/** Renderer configuration. */
typedef struct fcml_st_render_config {
    /** Flags which allows to control rendering process. */
    fcml_uint32_t render_flags;
    /** Preferred mnemonic padding in characters. */
    fcml_uint16_t prefered_mnemonic_padding;
    /** Preferred code padding in HEX bytes (2 characters on one byte.). */
    fcml_uint16_t prefered_code_padding;
} fcml_st_render_config;

/**
 * Renders the disassembled instruction into its textual representation.
 * Prepares textual representation of the disassembled code using syntax
 * based on the provided dialect.
 *
 * @param dialect Dialect instance.
 * @param config Renderer configuration.
 * @param[out] buffer Destination buffer for the generated instruction.
 * @param buffer_len Size of the destination buffer.
 * @param result Disassembled instruction.
 * @return Error code or FCML_CEH_GEC_NO_ERROR.
 *
 */
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_render(
        const fcml_st_dialect *dialect, const fcml_st_render_config *config,
        fcml_char *buffer, fcml_usize buffer_len,
        const fcml_st_disassembler_result *result);

#ifdef __cplusplus
}
#endif

#endif /* FCML_REND_H_ */