Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

out_html.cc

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      out_html.cc
00004  *
00005  *      Copyright (C) 1999-2002 Sebastian Biallas (sb@web-productions.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "analy_names.h"
00022 #include "htdebug.h"
00023 #include "htinfo.h"
00024 #include "out_html.h"
00025 #include "tools.h"
00026 #include "x86dis.h"
00027 #include "string.h"
00028 
00029 char *header = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html>\n<head>\n";
00030 char *footer = "</body>\n</html>\n";
00031 char *stylesheet = "<style type=\"text/css\">\n"
00032 "<!--\n"
00033 "body {\n"
00034 "\tfont: 10pt arial,helvetica,sans-serif;\n"
00035 "\tcolor:#000000;\n"
00036 "\tbackground:#ffffff;\n"
00037 "}\n"
00038 "A:link {\n"
00039 "\tcolor:#0000ff;\n"
00040 "\ttext-decoration: none;\n"
00041 "}\n"
00042 "A:active {\n"
00043 "\tcolor:#ff00ff;\n"
00044 "\ttext-decoration: none;\n"
00045 "}\n"
00046 "A:visited {\n"
00047 "\tcolor:#0000ff;\n"
00048 "\ttext-decoration: none;\n"
00049 "}\n"
00050 "td {\n"
00051 "\tfont: 12pt courier;\n"
00052 "\tcolor:#000000;\n"
00053 "\tvertical-align: top;\n"
00054 "}\n"
00055 "b {\n"
00056 "\tfont: bold 11pt arial,helvetica,sans-serif;\n"
00057 "\tcolor:#000000;\n"
00058 "}\n"
00059 "//-->\n"
00060 "</style>\n";
00061 
00062 int write_str(ht_stream *stream, char *s)
00063 {
00064         return stream->write(s, strlen(s));
00065 }
00066 
00067 Analyser *theanaly2;
00068 char html_buffer[1024];
00069 
00070 #if 0
00071 char *html_addr_sym_func(CPU_ADDR Addr, int *symstrlen)
00072 {
00073         /* should only be called/used/assigned if theanaly2 is set */
00074         Location *a = theanaly2->getLocationByAddress(Addr.addr32.offset);
00075         if ((a) && (a->label)){
00076                 int i = sprintf(html_buffer, "<a href=\"#A%08X\">%s</a>", Addr.addr32.offset, a->label->name);
00077                 if (symstrlen) *symstrlen=i;
00078                 return html_buffer;
00079         } else {
00080                 if (theanaly2->valid_addr(Addr.addr32.offset, scvalid)) {
00081                         int i = sprintf(html_buffer, "<a href=\"#A%08X\">%x</a>", Addr.addr32.offset, Addr.addr32.offset);
00082                         if (symstrlen) *symstrlen=i;
00083                         return html_buffer;
00084                 }
00085         }
00086         return NULL;
00087 }
00088 #endif
00089 
00090 int generate_html_output(Analyser *analy, ht_stream *stream, Address *from, Address *to)
00091 {
00092 #if 0
00093         if ((!analy) || (!stream)) return HTML_OUTPUT_ERR_GENERIC;
00094         if (analy->active) return HTML_OUTPUT_ERR_ANALY_NOT_FINISHED;
00095 
00096         write_str(stream, header);
00097         write_str(stream, "\t<title>Analysis of ");
00098         write_str(stream, analy->getname());
00099         write_str(stream, "</title>\n");
00100         write_str(stream, stylesheet);
00101         write_str(stream, "</head>\n<body bgcolor=\"#ffffff\">\n");
00102         write_str(stream, "Analysis of <i>");
00103         write_str(stream, analy->getname());
00104         write_str(stream, "</i><br>generated by <a href=\""ht_url"\">"ht_name" version "ht_version"</a>.\n<hr>\n");
00105         write_str(stream, "\n<table cellspacing=0 border=0>\n");
00106         // main loop:
00107         ADDR Addr = from;
00108         while (1) {
00109                 if (Addr > to) break;
00110                 write_str(stream, "\n<tr>\n");
00111 
00112                 taddr *a = analy->findaddr(Addr);
00113 
00114                 int length = 0;
00115 
00116                 char temp[1024];
00117 
00118                 sprintf(temp, "<td><a name=\"A%08X\">"HEX8FORMAT8"</a></td>\n", Addr, Addr);
00119                 write_str(stream, temp);
00120 
00121 
00122                 if (analy->explored->contains(Addr)) {
00123                         write_str(stream, "<td bgcolor=black>&nbsp;</td>\n");
00124                 } else {
00125                         write_str(stream, "<td>&nbsp;</td>\n");
00126                 }
00127 
00128 
00129                 if (a) {
00130                         write_str(stream, "<td>\n<table cellspacing=0 border=0>\n");
00131                         // comments
00132                         tcomment *c = a->comments;
00133                         if (c) {
00134                                 write_str(stream, "<tr><td colspan=2>\n");
00135                                 while (c)       {
00136                                         write_str(stream, c->text);
00137                                         write_str(stream, "<br>\n");
00138                                         c = c->next;
00139                                 }
00140                                 write_str(stream, "</td></tr>\n");
00141                         }
00142                         // label
00143                         write_str(stream, "<tr>\n<td width=500>");
00144                         if (a->label) {
00145                                 sprintf(temp, "<b>%s</b>:<br>\n", a->label->name);
00146                                 write_str(stream, temp);
00147                         }
00148                 } else {
00149                         write_str(stream, "<td width=500>");
00150                 }
00151 
00152                 if (analy->validcodeaddr(Addr)) {
00153                         taddr *nextaddr = analy->enum_addrs(Addr);
00154                         int op_len;
00155 
00156                         if (nextaddr) {
00157                                 op_len = MIN((dword)analy->maxopcodelength, (nextaddr->addr - Addr));
00158                         } else {
00159                                 op_len = analy->maxopcodelength;
00160                         }
00161 
00162                         if (analy->disasm) {
00163                                 byte buf[16];
00164                                 OPCODE *o=analy->disasm->decode(analy->bufptr(Addr, buf, sizeof(buf)), op_len, analy->mapaddr(Addr));
00165                                 /* inits for addr-sym transformations */
00166                                 theanaly2 = analy;
00167                                 addr_sym_func = &html_addr_sym_func;
00168                                 
00169                                 sprintf(temp, "  %s", analy->disasm->str(o, X86DIS_STYLE_HEX_NOZEROPAD));
00170                                 /* deinits for addr-sym transformations */
00171                                 theanaly2 = NULL;
00172                                 addr_sym_func = 0;
00173                                 
00174                                 length=analy->disasm->getsize(o);
00175                         } else {
00176                                 byte c;
00177                                 sprintf(temp, "  db      0%02xh", *(byte *)analy->bufptr(Addr, &c, 1));
00178                                 length=1;
00179                         }
00180                 } else {
00181                         if (analy->validaddr(Addr, scvalid)) {
00182                                 if ((a) && (a->type.type == dtint)) {
00183                                         length = a->type.length;
00184                                         assert(length);
00185                                         byte c[4];
00186                                         if (analy->validaddr(Addr, scinitialized)) {
00187                                                 switch (a->type.intsubtype) {
00188                                                         case dstiword:
00189                                                                 sprintf(temp, "  dw      0%04xh", *(word *)analy->bufptr(Addr, c, 2));
00190                                                                 break;
00191                                                         case dstidword:
00192                                                                 sprintf(temp, "  dd      0%08xh", *(dword *)analy->bufptr(Addr, c, 4));
00193                                                                 break;
00194                                                         case dstibyte:
00195                                                         default:
00196                                                                 analy->bufptr(Addr, c, 1);
00197                                                                 sprintf(temp, "  db      %02xh ; '%c'", c[0], (c[0]<32)?32:c[0]);
00198                                                 }
00199                                         } else {
00200                                                 switch (a->type.intsubtype) {
00201                                                         case dstiword:
00202                                                                 strcpy(temp, "  dw      ????");
00203                                                                 break;
00204                                                         case dstidword:
00205                                                                 strcpy(temp, "  dd      ????????");
00206                                                                 break;
00207                                                         case dstibyte:
00208                                                         default:
00209                                                                 strcpy(temp, "  db      ??");
00210                                                 }
00211                                         }
00212                                 } else {
00213                                         length =        1;
00214                                         if (analy->validaddr(Addr, scinitialized)) {
00215                                                 byte c;
00216                                                 analy->bufptr(Addr, &c, 1);
00217                                                 sprintf(temp, "  db      0%02xh ; '%c'", c, (c<32)?32:c);
00218                                         } else {
00219                                                 strcpy(temp, "  db      ??");
00220                                         }
00221                                 }
00222                         } else {
00223                                 ADDR next = analy->nextvalid(Addr);
00224                                 if (next != INVALID_ADDR) {
00225                                         length = next - Addr;
00226                                         sprintf(temp, "  db      ?? * %d", next - Addr);
00227                                 } else {
00228                                         length =        1;
00229                                         strcpy(temp, "  db      ??");
00230                                 }
00231                         }
00232                 }
00233 /*              if (mode & ANALY_EDIT_BYTES) {
00234                         if (validaddr(Addr, scinitialized)) {
00235 
00236                                 FILEADDR a=fileaddr(Addr);
00237                                 assert(a != INVALID_FILE_OFS);
00238                                 for (int i=0; i<(*length); i++) {
00239                                         buf = tag_make_edit_byte(buf, a+i);
00240                                 }
00241                                 for (int i=0; i<=(maxopcodelength*2)-(*length)*2; i++) {
00242                                         *(buf++)=' ';
00243                                 }
00244                                 *buf=0;
00245                         }
00246                 }*/
00247 
00248                 char *t = temp;
00249                 while (*t) {
00250                         if ((t[0]==' ') && (t[1]==' ')) {
00251                                 write_str(stream, "&nbsp;");
00252                         } else {
00253                                 stream->write(t, 1);
00254                         }
00255                         t++;
00256                 }
00257 
00258                 if (a) {
00259                         write_str(stream, "</td>\n<td>");
00260                         txref *x = a->xreflist;
00261                         int i=0;
00262                         while (x)       {
00263                                 if (i % 3==0) {
00264                                         write_str(stream, ";xref");
00265                                 }
00266                                 sprintf(temp, " %c<a href=\"#A%08X\">"HEX8FORMAT"</a>", xref_type_short(x->type), x->addr, x->addr);
00267                                 write_str(stream, temp);
00268                                 if (i % 3==2) {
00269                                         write_str(stream, "<br>\n");
00270                                 }
00271                                 i++;
00272                                 x = x->next;
00273                         }
00274                         write_str(stream, "</td>\n</tr></table>");
00275                 }
00276                 write_str(stream, "</td>\n</tr>\n");
00277 
00278                 Addr += length;
00279         }
00280         // end
00281         write_str(stream, "</table>\n");
00282         write_str(stream, footer);
00283         return HTML_OUTPUT_OK;
00284 #endif
00285         return HTML_OUTPUT_OK;
00286 }

Generated on Fri May 7 21:15:41 2004 by doxygen 1.3.5