1 /**
2 * @namespace biew_plugins_II
3 * @file plugins/disasm/null_da.c
4 * @brief This file contains implementation of Data disassembler.
5 * @version -
6 * @remark this source file is part of Binary vIEW project (BIEW).
7 * The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
8 * All rights reserved. This software is redistributable under the
9 * licence given in the file "Licence.en" ("Licence.ru" in russian
10 * translation) distributed in the BIEW archive.
11 * @note Requires POSIX compatible development system
12 *
13 * @author Nickols_K
14 * @since 1999
15 * @note Development, fixes and improvements
16 **/
17 #include <string.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20
21 #include "reg_form.h"
22 #include "plugins/disasm.h"
23 #include "bconsole.h"
24 #include "biewhelp.h"
25 #include "biewutil.h"
26 #include "reg_form.h"
27 #include "biewlib/file_ini.h"
28 #include "biewlib/pmalloc.h"
29
30 static int nulWidth = 1;
31
32 static const char *width_names[] =
33 {
34 "~Byte",
35 "~Word",
36 "~Double word",
37 "~Quad word"
38 };
39
nulSelect_width(void)40 static tBool __FASTCALL__ nulSelect_width( void )
41 {
42 unsigned nModes;
43 int i;
44 nModes = sizeof(width_names)/sizeof(char *);
45 i = SelBoxA(width_names,nModes," Select bitness mode: ",nulWidth);
46 if(i != -1)
47 {
48 nulWidth = i;
49 return True;
50 }
51 return False;
52 }
53
54 static char *outstr;
55
nulDisassembler(__filesize_t ulShift,MBuffer buffer,unsigned flags)56 static DisasmRet __FASTCALL__ nulDisassembler(__filesize_t ulShift,
57 MBuffer buffer,
58 unsigned flags)
59 {
60 DisasmRet ret;
61 int type,cl;
62 const char *preface;
63 if(!((flags & __DISF_SIZEONLY) == __DISF_SIZEONLY))
64 {
65 memset(&ret,0,sizeof(ret));
66 ret.str = outstr;
67 switch(nulWidth)
68 {
69 case 0: preface = "db ";
70 type = DISARG_BYTE;
71 cl = 1;
72 break;
73 default:
74 case 1: preface = "dw ";
75 type = DISARG_WORD;
76 cl = 2;
77 break;
78 case 2: preface = "dd ";
79 type = DISARG_DWORD;
80 cl = 4;
81 break;
82 case 3: preface = "dq ";
83 type = DISARG_QWORD;
84 cl = 8;
85 break;
86 }
87 ret.codelen = cl;
88 strcpy(outstr,preface);
89 disAppendDigits(outstr,ulShift,APREF_USE_TYPE,cl,buffer,type);
90 }
91 else
92 if(flags & __DISF_GETTYPE) ret.pro_clone = __INSNT_ORDINAL;
93 else
94 switch(nulWidth)
95 {
96 case 0: ret.codelen = 1; break;
97 default:
98 case 1: ret.codelen = 2; break;
99 case 2: ret.codelen = 4; break;
100 case 3: ret.codelen = 8; break;
101 }
102 return ret;
103 }
104
nulHelpAsm(void)105 static void __FASTCALL__ nulHelpAsm( void )
106 {
107 hlpDisplay(20010);
108 }
109
nulMaxInsnLen(void)110 static int __FASTCALL__ nulMaxInsnLen( void ) { return 8; }
nulGetAsmColor(unsigned long clone)111 static ColorAttr __FASTCALL__ nulGetAsmColor( unsigned long clone )
112 {
113 UNUSED(clone);
114 return disasm_cset.cpu_cset[0].clone[0];
115 }
nulGetBitness(void)116 static int __FASTCALL__ nulGetBitness( void ) { return DAB_USE16; }
nulGetClone(unsigned long clone)117 static char __FASTCALL__ nulGetClone( unsigned long clone )
118 {
119 UNUSED(clone);
120 return ' ';
121 }
nulInit(void)122 static void __FASTCALL__ nulInit( void )
123 {
124 outstr = PMalloc(1000);
125 if(!outstr)
126 {
127 MemOutBox("Data disassembler initialization");
128 exit(EXIT_FAILURE);
129 }
130 }
131
nulTerm(void)132 static void __FASTCALL__ nulTerm( void )
133 {
134 PFREE(outstr);
135 }
136
nulReadIni(hIniProfile * ini)137 static void __FASTCALL__ nulReadIni( hIniProfile *ini )
138 {
139 char tmps[10];
140 if(isValidIniArgs())
141 {
142 biewReadProfileString(ini,"Biew","Browser","SubSubMode3","1",tmps,sizeof(tmps));
143 nulWidth = (int)strtoul(tmps,NULL,10);
144 if(nulWidth > 3) nulWidth = 0;
145 }
146 }
147
nulWriteIni(hIniProfile * ini)148 static void __FASTCALL__ nulWriteIni( hIniProfile *ini )
149 {
150 char tmps[10];
151 sprintf(tmps,"%i",nulWidth);
152 biewWriteProfileString(ini,"Biew","Browser","SubSubMode3",tmps);
153 }
154
155 REGISTRY_DISASM Null_Disasm =
156 {
157 DISASM_DATA,
158 "~Data",
159 { NULL, "Width ", NULL, NULL },
160 { NULL, nulSelect_width, NULL, NULL },
161 nulDisassembler,
162 NULL,
163 nulHelpAsm,
164 nulMaxInsnLen,
165 nulGetAsmColor,
166 NULL,
167 nulGetAsmColor,
168 NULL,
169 nulGetBitness,
170 nulGetClone,
171 nulInit,
172 nulTerm,
173 nulReadIni,
174 nulWriteIni
175 };
176
177
178
179
180