1 /**
2  * @namespace   biew
3  * @file        reg_form.h
4  * @brief       This file contains structure prototypes for embededding new
5  *              file formats, disassemblers, translation modes e.t.c. in BIEW.
6  * @version     -
7  * @remark      this source file is part of Binary vIEW project (BIEW).
8  *              The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
9  *              All rights reserved. This software is redistributable under the
10  *              licence given in the file "Licence.en" ("Licence.ru" in russian
11  *              translation) distributed in the BIEW archive.
12  * @note        Requires POSIX compatible development system
13  *
14  * @author      Nickols_K
15  * @since       1995
16  * @note        Development, fixes and improvements
17 **/
18 #ifndef __REG_FORM__H
19 #define __REG_FORM__H
20 
21 #ifndef __FILE_INI_RUNTIME_SUPPORT_SYSTEM__
22 #include "biewlib/file_ini.h"
23 #endif
24 
25 #ifndef __TWIN_H
26 #include "biewlib/twin.h"
27 #endif
28 
29 #ifdef __cplusplus
30 #define extern "C" {
31 #endif
32 
33 typedef __filesize_t  (__FASTCALL__ *BinFunc)( void );
34 typedef tBool         (__FASTCALL__ *ModFunc)( void );
35 
36 #define APREF_NORMAL      0x0000 /**< Append references in short form if it really present in binary */
37 #define APREF_USE_TYPE    0x0001 /**< Append references in detail form if it really present in binary */
38 #define APREF_TRY_LABEL   0x0002 /**< Append references in short form even if it not present in binary (smart method) */
39 #define APREF_SAVE_VIRT   0x0004 /**< Notifies plugin about preserving of virtual address, if binding is local */
40 #define APREF_TRY_PIC     0x0008 /**< Append references in short form assuming that shift is offset in .GOT table where references are binded */
41 
42 /**
43    Appends disassembler reference to string.
44    * @param str          string buffer for append to
45    * @param shift        physical address of field, that required of binding
46    * @param flags        see above
47    * @param codelen      length of field, that required binding
48    * @param r_shift      used only if APPREF_TRY_LABEL mode is set, contains real value of field, that required binding
49    * @return             one of RAPREF_* constants (see biewutil.h file for detail)
50 */
51 typedef unsigned long (__FASTCALL__ *AppRefs)(char *str,__filesize_t shift,int flags,int codelen,__filesize_t r_shift);
52 
53 /***************************************************************\
54 *  This form registry binary file formats                       *
55 \***************************************************************/
56 
57 /** List of DisAssembler Bitness */
58 
59 #define DAB_USE16   0
60 #define DAB_USE32   1
61 #define DAB_USE64   2
62 #define DAB_USE128  3
63 #define DAB_USE256  4
64 #define DAB_AUTO    0xFFFFU /**< never must return! Only for selection */
65 
66 /** List of DisAssembler Endian */
67 #define DAE_LITTLE	0
68 #define DAE_BIG		1
69 
70 /** Public symbols classes */
71 
72 #define SC_LOCAL    0 /**< means: present as entry but not exported */
73 #define SC_GLOBAL   1 /**< means: exported entry point */
74 
75 /** object classes */
76 
77 #define OC_CODE      0 /**< for code objects */
78 #define OC_DATA      1 /**< for any data objects */
79 #define OC_NOOBJECT -1 /**< for non objects (means: relocs, resources, tables ...) */
80 
81 /*
82    Binary plugins state constants:
83      First called 'check_format' - plugin in UNPLUGGED state.
84      Second called 'init' - plugin turn into PLUGGED IN state.
85      Last called 'destroy' - plugin turn into UNPLUGGED state.
86      These foundamental state is not defined through PS_XXX constants,
87      because it meaningless.
88      General purpose for PS_XXX state is activating of preemptive memory
89      allocation mechanism. Means: when plugin in PS_INACTIVE state (when
90      references resolving is 'None') then on low memory it can freed some
91      buffers. (This need for prevent of infinity loop of memory
92      allocation/freing, that possible in some case).
93 */
94 
95 #define PS_INACTIVE    0
96 #define PS_ACTIVE      1
97 
98 typedef struct tag_REGISTRY_BIN
99 {
100   const char * name;                            /**< name of binary format */
101   const char * prompt[10];                      /**< on ALT-Fx selection */
102   BinFunc   action[10];                         /**< action on ALT-Fx selection */
103   tBool   (__FASTCALL__ *check_format)( void ); /**< Checks format */
104   void    (__FASTCALL__ *init)( void );         /**< Inits plugin (if check o'k) (constructor) */
105   void    (__FASTCALL__ *destroy)( void );      /**< Destroys plugin (destructor) */
106   BinFunc   showHdr;                            /**< if not an MZ style format */
107   AppRefs   bind;                               /**< for show references */
108 
109                          /** This function is called, when activity of plugin is changed.
110                            * @param state      See PS_XXX constants.
111                            * @note             Plugin must support counter of
112                            *                   states. (For multiple call purpose)
113                           **/
114   void    (__FASTCALL__ *set_state)(int state);
115 
116                          /** Returns CPU platform, that required by format.
117                            * @note           Full list of platform please see in
118                            *                 plugins/disasm.h file. If this
119                            *                 function return -1 then platform is
120                            *                 undefined.
121                           **/
122   int     (__FASTCALL__ *query_platform)( void );
123 
124                          /** Returns DAB_XXX. Quick version for disassembler */
125   int     (__FASTCALL__ *query_bitness)(__filesize_t);
126 
127                          /** Returns DAE_XXX. */
128   int     (__FASTCALL__ *query_endian)(__filesize_t);
129 
130                          /** For displaying offset within struct in left address column.
131                            * @return         False if string is not modified.
132                           **/
133   tBool   (__FASTCALL__ *AddressResolving)(char *,__filesize_t);
134 
135                          /** Converts virtual address to physical (means file offset).
136                            * @param va       indicates virtual address to be converted
137                            * @return         0 if operation meaningless
138                           **/
139  __filesize_t (__FASTCALL__ *va2pa)(__filesize_t va);
140 
141                          /** Converts physical address to virtual.
142                            * @param pa       indicates physical address to be converted
143                            * @note           seg pointer can be NULL
144                           **/
145   __filesize_t (__FASTCALL__ *pa2va)(__filesize_t pa);
146 
147 
148 /*-- Below placed functions for 'put structures' method of save as dialog --*/
149 
150                          /** Fills the string with public symbol
151                            * @param str       pointer to the string to be filled
152                            * @param cb_str    indicates maximal length of string
153                            * @param _class    pointer to the memory where can be stored class of symbol (See SC_* conatnts)
154                            * @param pa        indicates physical offset within file
155                            * @param as_prev   indicates direction of symbol searching from given physical offset
156                            * @return          0 - if no symbol name available
157                            *                  in given direction (as_prev)
158                            *                  physical address of public symbol
159                            *                  which is found in given direction
160                           **/
161   __filesize_t (__FASTCALL__ *GetPubSym)(char *str,unsigned cb_str,unsigned *_class,
162                              __filesize_t pa,tBool as_prev);
163 
164                          /** Determines attributes of object at given physical file address.
165                            * @param pa        indicates physical file offset of object
166                            * @param name      pointer to the string which is to be filled with object name
167                            * @param cb_name   indicates maximal length of string
168                            * @param start     pointer to the memory where must be stored start of given object, as file offset.
169                            * @param end       pointer to the memory where must be stored end of given object, as file offset.
170                            * @param _class    pointer to the memory where must be stored _class of object (See OC_* constants).
171                            * @param bitness   pointer to the memory where must be stored bitness of object (See DAB_* constants).
172                            * @return          logical number of object or 0 if at given offset is no object.
173                            * @note            all arguments exclude name of object
174                            *                  must be filled.
175                            * @remark          For example: if exe-format - new
176                            *                  exe i.e. contains MZ and NEW
177                            *                  header and given file offset
178                            *                  points to old exe stub then start
179                            *                  = 0, end = begin of first data or
180                            *                  code object).
181                           **/
182   unsigned    (__FASTCALL__ *GetObjAttr)(__filesize_t pa,char *name,unsigned cb_name,
183                               __filesize_t *start,__filesize_t *end,int *_class,int *bitness);
184 
185                          /** Prepares internal buffers for work file structures.
186                            * @param start     indicates start position in the file, that is required for disassembler
187                            * @param end       indicates end position in the file, that is required for disassembler
188                            * return           False if success, True if an error
189                            *                  is occured (sample: out of memory)
190                            * @note            It is called before GetPubSym and GetObjAttr
191                           **/
192   tBool         (__FASTCALL__ *prepare_structs)(__filesize_t start,__filesize_t end);
193                          /** Cleans internal buffers after stopping of structural disassembler */
194   void          (__FASTCALL__ *drop_structs)( void );
195 }REGISTRY_BIN;
196 
197 extern REGISTRY_BIN *detectedFormat;
198 
199 /***************************************************************\
200 * This form registry modes of translation file                  *
201 \***************************************************************/
202 
203 #define __MF_NONE          0x0000 /**< Indicates that no flags were defined */
204 #define __MF_TEXT          0x0001 /**< Indicates that plugin is text browser */
205 #define __MF_DISASM        0x0002 /**< Indicates that plugin is disassembler */
206 #define __MF_USECODEGUIDE  0x0004 /**< Indicates that plugin uses code guider */
207 
208 #define __MAX_SYMBOL_SIZE  4 /**< Insicates maximal size of multibyte symbol. (For optimization purposes only).*/
209 
210 typedef struct tag_REGISTRY_MODE
211 {
212   const char *  name;
213   const char *  prompt[10];                   /**< on Ctrl-Fx selection */
214   ModFunc       action[10];                   /**< action on Ctrl-Fx selection */
215   tBool         (__FASTCALL__ *detect)(void); /**< detects possibility to assign this mode as default mode for openned file. */
216   unsigned       flags;                       /**< see __MF_* constants */
217 
218                          /** Paints the file on the screen.
219                            * @param keycode   indicates keyboard code which caused repainting
220                            * @param textshift indicates shift of text. Useful only for text mode.
221                            * return           new shift of text
222                           **/
223   unsigned      (__FASTCALL__ *paint)(unsigned keycode,unsigned textshift);
224 
225                          /** Converts buffer with using selected NLS as xlat table.
226                            * @param str       string to be converted
227                            * @param len       length of string
228                            * @param use_fs_nls specifies usage of nls of file
229                                               system but not screen.
230                            * @return          new size of blocks after conversation
231                           **/
232   unsigned      (__FASTCALL__ *convert_cp)(char *str,unsigned len, tBool use_fs_nls);
233 
234   unsigned      (__FASTCALL__ *get_symbol_size)( void ); /**< Returns symbol size in bytes for selected NLS codepage */
235   const char *  (__FASTCALL__ *misckey_name)( void );    /**< F4 key name */
236   void          (__FASTCALL__ *misc_action)( void );     /**< F4 action */
237   unsigned long (__FASTCALL__ *PrevPageSize)(void);      /**< Get previous page size */
238   unsigned long (__FASTCALL__ *CurPageSize)(void);       /**< Get current page size */
239   unsigned long (__FASTCALL__ *PrevLineWidth)( void );   /**< Get previous line width */
240   unsigned long (__FASTCALL__ *CurLineWidth)( void );    /**< Get current line width */
241   void          (__FASTCALL__ *help)( void );            /**< display help about mode */
242   void          (__FASTCALL__ *read_ini)( hIniProfile * );  /**< reads biew.ini file if need */
243   void          (__FASTCALL__ *save_ini)( hIniProfile * );  /**< writes to biew.ini if need */
244   void          (__FASTCALL__ *init)( void );            /**< initialize mode (constructor) */
245   void          (__FASTCALL__ *term)( void );            /**< destroy mode (destructor) */
246                          /** Performs search in plugin's output
247                            * @param pwnd      indicates handle of Percent window with progress indicator
248                            * @param start     indicates start offset within file where search must be performed
249                            * @param slen      on output contains length of found sequence
250                            * @param flags     indicates flags (SF_* family) of search.
251                            * @param is_continue indicates initialization of search
252                            *                  If set then search should be continued
253                            * @param is_found  on output must contain True if result is really found
254                            * @return          offset of found sequence or ULONG(LONG)_MAX if not found
255                           **/
256 __filesize_t (__FASTCALL__ *search_engine)(TWindow *pwnd, __filesize_t start, __filesize_t *slen, unsigned flags, tBool is_continue, tBool *is_found);
257 }REGISTRY_MODE;
258 
259 extern REGISTRY_MODE *activeMode;
260 extern tBool SelectMode( void );
261 extern void QuickSelectMode( void );
262 
263 typedef struct tag_REGISTRY_TOOL
264 {
265   const char *  name;                /**< Tool name */
266   void          (*tool)( void );     /**< Tool body */
267   void          (*read_ini)( void ); /**< read biew.ini if need */
268   void          (*save_ini)( void ); /**< write to biew.ini if need */
269 }REGISTRY_TOOL;
270 
271 typedef struct tag_REGISTRY_SYSINFO
272 {
273   const char *  name;                /**< System depended information name */
274   void          (*sysinfo)( void );  /**< System depended information body */
275   void          (*read_ini)( void ); /**< reads biew.ini if need */
276   void          (*save_ini)( void ); /**< writes to biew.ini if need */
277 }REGISTRY_SYSINFO;
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 
283 #endif
284