00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "analy.h"
00022 #include "htatom.h"
00023 #include "htctrl.h"
00024 #include "htdebug.h"
00025 #include "httag.h"
00026 #include "htpal.h"
00027 #include "out_ht.h"
00028
00029 #include <string.h>
00030 #include <stdlib.h>
00031
00032 #define palclasskey_analyser "analyser"
00033 #define palkey_analyser_default "default"
00034
00035 void AnalyserHTOutput::init(Analyser *Analy)
00036 {
00037 analy_pal.data=NULL;
00038 analy_pal.size=0;
00039 AnalyserOutput::init(Analy);
00040 }
00041
00042 void AnalyserHTOutput::done()
00043 {
00044 if (analy_pal.data) free(analy_pal.data);
00045 AnalyserOutput::done();
00046 }
00047
00048 vcp AnalyserHTOutput::getcolor_analy(UINT pal_index)
00049 {
00050 return getcolorv(&analy_pal, pal_index);
00051 }
00052
00053 void AnalyserHTOutput::reloadPalette()
00054 {
00055 if (analy_pal.data) {
00056 free(analy_pal.data);
00057 analy_pal.data = NULL;
00058 }
00059 load_pal(palclasskey_analyser, palkey_analyser_default, &analy_pal);
00060 }
00061
00062 void AnalyserHTOutput::beginAddr()
00063 {
00064 AnalyserOutput::beginAddr();
00065 }
00066
00067 void AnalyserHTOutput::beginLine()
00068 {
00069 AnalyserOutput::beginLine();
00070 if (analy->mode & ANALY_SHOW_ADDRESS) {
00071 char temp[20];
00072 if (line==0) {
00073 #if 0
00074 char temp2[20];
00075 addr->stringify(temp2, sizeof temp2, ADDRESS_STRING_FORMAT_COMPACT);
00076 int s = strlen(temp2);
00077 int s2 = addr->stringSize();
00078 memset(temp, ' ', s2);
00079 memcpy(&temp[(s2-s)/2], temp2, s);
00080 temp[s2]=0;
00081 #endif
00082
00083 addr->stringify(temp, sizeof temp, ADDRESS_STRING_FORMAT_LEADING_WHITESPACE);
00084 char temp2[20];
00085 last = addr->stringify(temp2, sizeof temp2, ADDRESS_STRING_FORMAT_COMPACT);
00086 } else {
00087 int s = addr->stringSize();
00088 memset(temp, ' ', s);
00089 memset(&temp[s-last], '.', last);
00090
00091 temp[s] = 0;
00092 }
00093
00094 work_buffer = (byte *)tag_make_sel((TAGSTRING *)work_buffer, temp);
00095 }
00096
00097 if (analy->explored->contains(addr)) {
00098 write(" ! ");
00099 } else {
00100 write(" ");
00101 }
00102
00103 work_buffer_edit_bytes_insert = work_buffer;
00104 }
00105
00106 void AnalyserHTOutput::changeConfig()
00107 {
00108 reloadPalette();
00109 }
00110
00111 int AnalyserHTOutput::elementLength(const char *s)
00112 {
00113 return tag_strlen(s);
00114 }
00115
00116 void AnalyserHTOutput::endAddr()
00117 {
00118 AnalyserOutput::endAddr();
00119 }
00120
00121 void AnalyserHTOutput::endLine()
00122 {
00123 if ((analy->mode & ANALY_EDIT_BYTES) && bytes_line) {
00124 if (analy->validAddress(addr, scinitialized)) {
00125
00126
00127 FILEOFS a=analy->addressToFileofs(addr);
00128 assert(a != INVALID_FILE_OFS);
00129
00130 char workbuf2[1024];
00131 char *work_buffer2 = workbuf2;
00132
00133 for (int i=0; i < bytes_line; i++) {
00134 work_buffer2 = tag_make_edit_byte(work_buffer2, a+i);
00135 }
00136 for (int i=0; i <= analy->max_opcode_length*2-bytes_line*2; i++) {
00137 *(work_buffer2++)=' ';
00138 }
00139
00140
00141 *work_buffer = 0;
00142 memmove(work_buffer_edit_bytes_insert+(work_buffer2-workbuf2), work_buffer_edit_bytes_insert, tag_strlen((char*)work_buffer_edit_bytes_insert));
00143 memcpy(work_buffer_edit_bytes_insert, workbuf2, (work_buffer2-workbuf2));
00144 work_buffer += (work_buffer2-workbuf2);
00145 }
00146 }
00147 AnalyserOutput::endLine();
00148 }
00149
00150 char *AnalyserHTOutput::externalLink(char *s, int type1, int type2, int type3, int type4, void *special)
00151 {
00152 *(tag_make_ref(tmpbuffer, type1, type2, type3, type4, s)) = 0;
00153 return tmpbuffer;
00154 }
00155
00156
00157 char *AnalyserHTOutput::link(char *s, Address *Addr)
00158 {
00159
00160 if (Addr->byteSize()==4) {
00161 dword d;
00162 Addr->putIntoArray((byte*)&d);
00163 *(tag_make_ref(tmpbuffer, d, 0, 0, 0, s)) = 0;
00164 } else {
00165 qword d;
00166 Addr->putIntoArray((byte*)&d);
00167 *(tag_make_ref(tmpbuffer, d.hi, d.lo, 0, 0, s)) = 0;
00168 }
00169 return tmpbuffer;
00170 }
00171
00172 void AnalyserHTOutput::putElement(int element_type, const char *element)
00173 {
00174
00175 switch (element_type) {
00176 case ELEMENT_TYPE_PRE_COMMENT:
00177 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_comment));
00178 write(element);
00179 break;
00180 case ELEMENT_TYPE_COMMENT:
00181 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_comment));
00182 write(element);
00183 break;
00184 case ELEMENT_TYPE_POST_COMMENT:
00185 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_comment));
00186 write(element);
00187 break;
00188 case ELEMENT_TYPE_LABEL:
00189 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_label));
00190 write(element);
00191 break;
00192 case ELEMENT_TYPE_DATA_CODE:
00193 write(element);
00194 break;
00195 case ELEMENT_TYPE_HIGHLIGHT_DATA_CODE:
00196 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_default));
00197 write(" ");
00198 while (*element) {
00199 if (*element == '\e') {
00200 int len = tag_get_len(element);
00201 while (len--) *(work_buffer++) = *(element++);
00202 continue;
00203 }
00204 if (*element == '\\') {
00205 element++;
00206 if (*element == '@') {
00207 element++;
00208 switch (*element) {
00209 case '#':
00210 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_comment));
00211 break;
00212 case 'c':
00213 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_symbol));
00214 break;
00215 case 'd':
00216 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_default));
00217 break;
00218 case 'n':
00219 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_number));
00220 break;
00221 case 's':
00222 work_buffer = (byte *)tag_make_color((TAGSTRING *)work_buffer, getcolor_analy(palidx_analyser_string));
00223 break;
00224 }
00225 element++;
00226 } else {
00227 *work_buffer++ = '\\';
00228 *work_buffer++ = *(element++);
00229 }
00230 continue;
00231 }
00232 *(work_buffer++) = *(element++);
00233 }
00234 break;
00235 case ELEMENT_TYPE_INDENT_XREF:
00236 write(" ");
00237 break;
00238 }
00239 }
00240
00241