File: out_html.cc

package info (click to toggle)
ht 2.0.20-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,324 kB
  • sloc: cpp: 97,563; ansic: 17,183; sh: 3,811; lex: 226; makefile: 213; yacc: 127
file content (218 lines) | stat: -rw-r--r-- 5,093 bytes parent folder | download | duplicates (8)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
 *	HT Editor
 *	out_html.cc
 *
 *	Copyright (C) 1999-2002 Sebastian Biallas (sb@biallas.net)
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 *
 *	This program 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 General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program; if not, write to the Free Software
 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "analy_names.h"
#include "htdebug.h"
#include "htinfo.h"
#include "out_html.h"
#include "tools.h"
#include "x86dis.h"
#include "string.h"
#include "snprintf.h"

static const char *header_str = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html>\n<head>\n";
static const char *footer_str = "</body>\n</html>\n";
static const char *stylesheet_str = "<style type=\"text/css\">\n"
"<!--\n"
"body {\n"
"\tfont: 10pt arial,helvetica,sans-serif;\n"
"\tcolor:#00ff00;\n"
"\tbackground:#000080;\n"
"}\n"
"A {\n"
"\tcolor:#ffffff;\n"
"\ttext-decoration: none;\n"
"}\n"
".c {\n"
"\tcolor:#c0c0c0;\n"
"}\n"
".l {\n"
"\tcolor:#ffff00;\n"
"}\n"
".sym {\n"
"\tcolor:#00ffff;\n"
"}\n"
".n {\n"
"\tcolor:#008080;\n"
"}\n"
".str {\n"
"\tcolor:#ff0000;\n"
"}\n"
"//-->\n"
"</style>\n";

void AnalyserHTMLOutput::init(Analyser *analy, Stream *s)
{
	AnalyserOutput::init(analy);
	stream = s;
	dis_style = DIS_STYLE_HIGHLIGHT+DIS_STYLE_HEX_NOZEROPAD+DIS_STYLE_HEX_ASMSTYLE+X86DIS_STYLE_OPTIMIZE_ADDR;
}

void AnalyserHTMLOutput::beginLine()
{
	AnalyserOutput::beginLine();
	char temp[20], temp3[20];
	if (line == 0) {
		addr->stringify(temp, sizeof temp, ADDRESS_STRING_FORMAT_LEADING_WHITESPACE);
		char temp2[20];
		last = addr->stringify(temp2, sizeof temp2, ADDRESS_STRING_FORMAT_COMPACT);
	} else {
		int s = addr->stringSize();
		memset(temp, ' ', s);
		memset(&temp[s-last], '.', last);
		temp[s] = 0;
	}

	write("<a name=\"");
	addr->stringify(temp3, sizeof temp, ADDRESS_STRING_FORMAT_LEADING_ZEROS | ADDRESS_STRING_FORMAT_ADD_H);
	write(temp3);
	write("\">");
	write(temp);
	write("</a>");

	if (analy->explored->contains(addr)) {
		write("<span class=\"n\"> ! </span>");
	} else {
		write("   ");
	}
}

void AnalyserHTMLOutput::endLine()
{
	write("\n");
	AnalyserOutput::endLine();
}

Stream *AnalyserHTMLOutput::getGenerateStream()
{
	return stream;
}

int AnalyserHTMLOutput::elementLength(const char *s)
{
	return strlen(s);
}

char *AnalyserHTMLOutput::link(char *s, Address *Addr)
{
	global_analyser_address_string_format = ADDRESS_STRING_FORMAT_LEADING_ZEROS | ADDRESS_STRING_FORMAT_ADD_H;
	ht_snprintf(tmpbuf, sizeof tmpbuf, "<a href=\"#%y\">%s</a>", Addr, s);
	return tmpbuf;
}

char *AnalyserHTMLOutput::externalLink(char *s, uint32 type1, uint32 type2, uint32 type3, uint32 type4, void *special)
{
	strcpy(tmpbuf, "test");
	return tmpbuf;
}

static void swrite(Stream *s, const char *str)
{
	s->writex(str, strlen(str));
}

void AnalyserHTMLOutput::footer()
{
	swrite(stream, footer_str);
}

void AnalyserHTMLOutput::putElement(int element_type, const char *element)
{
	switch (element_type) {
	case ELEMENT_TYPE_PRE_COMMENT:
	case ELEMENT_TYPE_COMMENT:
	case ELEMENT_TYPE_POST_COMMENT:
		write("<span class=\"c\">");
		write(element);
		write("</span>");
		break;
	case ELEMENT_TYPE_LABEL:
		write("<span class=\"l\">");
		write(element);
		write("</span>");
		break;
	case ELEMENT_TYPE_DATA_CODE:
		write(element);
		break;
	case ELEMENT_TYPE_HIGHLIGHT_DATA_CODE: {
		bool span = false;
		write("  ");
		while (*element) {
			if (*element == '\\') {
				element++;
				if (*element == '@') {
					element++;
					const char *cl = NULL;
					switch (*element) {
					case '#': // comment
						cl = "c";
						break;
					case 'c': // symbol
						cl = "sym";
						break;
					case 'd': // default
						break;
					case 'n': // number
						cl = "n";
						break;
					case 's': // string
						cl = "str";
						break;
					}
					if (span) write("</span>");
					span = false;
					if (cl) {
						write("<span class=\"");
						write(cl);
						write("\">");
						span = true;
					}
					element++;
				} else {
					*work_buffer++ = '\\';
					*work_buffer++ = *element++;
				}
				continue;
			}
			*work_buffer++ = *element++;
		}
		if (span) write("</span>");
		break;
	}
	case ELEMENT_TYPE_INDENT_XREF:
		write("  ");
		break;
	}
}

void AnalyserHTMLOutput::header()
{
	String name;
	analy->getName(name);
	swrite(stream, header_str);
	swrite(stream, "\t<title>Analysis of ");
	swrite(stream, name.contentChar());
	swrite(stream, "</title>\n");
	swrite(stream, stylesheet_str);
	swrite(stream, "</head>\n<body bgcolor=\"#ffffff\">\n\n");
	swrite(stream, "Analysis of <i>");
	swrite(stream, name.contentChar());
	swrite(stream, "</i><br>generated by <a href=\""ht_url"\">"ht_name" version "ht_version"</a>.\n<hr>\n<pre>\n");
}