fuzzterm.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include "putty.h"
  5. #include "dialog.h"
  6. #include "terminal.h"
  7. /* For Unix in particular, but harmless if this main() is reused elsewhere */
  8. const bool buildinfo_gtk_relevant = false;
  9. static const TermWinVtable fuzz_termwin_vt;
  10. int main(int argc, char **argv)
  11. {
  12. char blk[512];
  13. size_t len;
  14. Terminal *term;
  15. Conf *conf;
  16. struct unicode_data ucsdata;
  17. TermWin termwin;
  18. termwin.vt = &fuzz_termwin_vt;
  19. conf = conf_new();
  20. do_defaults(NULL, conf);
  21. init_ucs(&ucsdata, conf_get_str(conf, CONF_line_codepage),
  22. conf_get_bool(conf, CONF_utf8_override),
  23. CS_NONE, conf_get_int(conf, CONF_vtmode));
  24. term = term_init(conf, &ucsdata, &termwin);
  25. term_size(term, 24, 80, 10000);
  26. term->ldisc = NULL;
  27. /* Tell american fuzzy lop that this is a good place to fork. */
  28. #ifdef __AFL_HAVE_MANUAL_CONTROL
  29. __AFL_INIT();
  30. #endif
  31. while (!feof(stdin)) {
  32. len = fread(blk, 1, sizeof(blk), stdin);
  33. term_data(term, false, blk, len);
  34. }
  35. term_update(term);
  36. return 0;
  37. }
  38. /* functions required by terminal.c */
  39. static bool fuzz_setup_draw_ctx(TermWin *tw) { return true; }
  40. static void fuzz_draw_text(
  41. TermWin *tw, int x, int y, wchar_t *text, int len,
  42. unsigned long attr, int lattr, truecolour tc)
  43. {
  44. int i;
  45. printf("TEXT[attr=%08lx,lattr=%02x]@(%d,%d):", attr, lattr, x, y);
  46. for (i = 0; i < len; i++) {
  47. printf(" %x", (unsigned)text[i]);
  48. }
  49. printf("\n");
  50. }
  51. static void fuzz_draw_cursor(
  52. TermWin *tw, int x, int y, wchar_t *text, int len,
  53. unsigned long attr, int lattr, truecolour tc)
  54. {
  55. int i;
  56. printf("CURS[attr=%08lx,lattr=%02x]@(%d,%d):", attr, lattr, x, y);
  57. for (i = 0; i < len; i++) {
  58. printf(" %x", (unsigned)text[i]);
  59. }
  60. printf("\n");
  61. }
  62. static void fuzz_draw_trust_sigil(TermWin *tw, int x, int y)
  63. {
  64. printf("TRUST@(%d,%d)\n", x, y);
  65. }
  66. static int fuzz_char_width(TermWin *tw, int uc) { return 1; }
  67. static void fuzz_free_draw_ctx(TermWin *tw) {}
  68. static void fuzz_set_cursor_pos(TermWin *tw, int x, int y) {}
  69. static void fuzz_set_raw_mouse_mode(TermWin *tw, bool enable) {}
  70. static void fuzz_set_scrollbar(TermWin *tw, int total, int start, int page) {}
  71. static void fuzz_bell(TermWin *tw, int mode) {}
  72. static void fuzz_clip_write(
  73. TermWin *tw, int clipboard, wchar_t *text, int *attrs,
  74. truecolour *colours, int len, bool must_deselect) {}
  75. static void fuzz_clip_request_paste(TermWin *tw, int clipboard) {}
  76. static void fuzz_refresh(TermWin *tw) {}
  77. static void fuzz_request_resize(TermWin *tw, int w, int h) {}
  78. static void fuzz_set_title(TermWin *tw, const char *title) {}
  79. static void fuzz_set_icon_title(TermWin *tw, const char *icontitle) {}
  80. static void fuzz_set_minimised(TermWin *tw, bool minimised) {}
  81. static void fuzz_set_maximised(TermWin *tw, bool maximised) {}
  82. static void fuzz_move(TermWin *tw, int x, int y) {}
  83. static void fuzz_set_zorder(TermWin *tw, bool top) {}
  84. static void fuzz_palette_set(TermWin *tw, unsigned start, unsigned ncolours,
  85. const rgb *colours) {}
  86. static void fuzz_palette_get_overrides(TermWin *tw, Terminal *term) {}
  87. static const TermWinVtable fuzz_termwin_vt = {
  88. .setup_draw_ctx = fuzz_setup_draw_ctx,
  89. .draw_text = fuzz_draw_text,
  90. .draw_cursor = fuzz_draw_cursor,
  91. .draw_trust_sigil = fuzz_draw_trust_sigil,
  92. .char_width = fuzz_char_width,
  93. .free_draw_ctx = fuzz_free_draw_ctx,
  94. .set_cursor_pos = fuzz_set_cursor_pos,
  95. .set_raw_mouse_mode = fuzz_set_raw_mouse_mode,
  96. .set_scrollbar = fuzz_set_scrollbar,
  97. .bell = fuzz_bell,
  98. .clip_write = fuzz_clip_write,
  99. .clip_request_paste = fuzz_clip_request_paste,
  100. .refresh = fuzz_refresh,
  101. .request_resize = fuzz_request_resize,
  102. .set_title = fuzz_set_title,
  103. .set_icon_title = fuzz_set_icon_title,
  104. .set_minimised = fuzz_set_minimised,
  105. .set_maximised = fuzz_set_maximised,
  106. .move = fuzz_move,
  107. .set_zorder = fuzz_set_zorder,
  108. .palette_set = fuzz_palette_set,
  109. .palette_get_overrides = fuzz_palette_get_overrides,
  110. };
  111. void ldisc_send(Ldisc *ldisc, const void *buf, int len, bool interactive) {}
  112. void ldisc_echoedit_update(Ldisc *ldisc) {}
  113. void modalfatalbox(const char *fmt, ...) { exit(0); }
  114. void nonfatal(const char *fmt, ...) { }
  115. /* needed by timing.c */
  116. void timer_change_notify(unsigned long next) { }
  117. /* needed by config.c and sercfg.c */
  118. void dlg_radiobutton_set(union control *ctrl, dlgparam *dp, int whichbutton) { }
  119. int dlg_radiobutton_get(union control *ctrl, dlgparam *dp) { return 0; }
  120. void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked) { }
  121. bool dlg_checkbox_get(union control *ctrl, dlgparam *dp) { return false; }
  122. void dlg_editbox_set(union control *ctrl, dlgparam *dp, char const *text) { }
  123. char *dlg_editbox_get(union control *ctrl, dlgparam *dp)
  124. { return dupstr("moo"); }
  125. void dlg_listbox_clear(union control *ctrl, dlgparam *dp) { }
  126. void dlg_listbox_del(union control *ctrl, dlgparam *dp, int index) { }
  127. void dlg_listbox_add(union control *ctrl, dlgparam *dp, char const *text) { }
  128. void dlg_listbox_addwithid(union control *ctrl, dlgparam *dp,
  129. char const *text, int id) { }
  130. int dlg_listbox_getid(union control *ctrl, dlgparam *dp, int index)
  131. { return 0; }
  132. int dlg_listbox_index(union control *ctrl, dlgparam *dp) { return -1; }
  133. bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
  134. { return false; }
  135. void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index) { }
  136. void dlg_text_set(union control *ctrl, dlgparam *dp, char const *text) { }
  137. void dlg_filesel_set(union control *ctrl, dlgparam *dp, Filename *fn) { }
  138. Filename *dlg_filesel_get(union control *ctrl, dlgparam *dp) { return NULL; }
  139. void dlg_fontsel_set(union control *ctrl, dlgparam *dp, FontSpec *fn) { }
  140. FontSpec *dlg_fontsel_get(union control *ctrl, dlgparam *dp) { return NULL; }
  141. void dlg_update_start(union control *ctrl, dlgparam *dp) { }
  142. void dlg_update_done(union control *ctrl, dlgparam *dp) { }
  143. void dlg_set_focus(union control *ctrl, dlgparam *dp) { }
  144. void dlg_label_change(union control *ctrl, dlgparam *dp, char const *text) { }
  145. union control *dlg_last_focused(union control *ctrl, dlgparam *dp)
  146. { return NULL; }
  147. void dlg_beep(dlgparam *dp) { }
  148. void dlg_error_msg(dlgparam *dp, const char *msg) { }
  149. void dlg_end(dlgparam *dp, int value) { }
  150. void dlg_coloursel_start(union control *ctrl, dlgparam *dp,
  151. int r, int g, int b) { }
  152. bool dlg_coloursel_results(union control *ctrl, dlgparam *dp,
  153. int *r, int *g, int *b) { return false; }
  154. void dlg_refresh(union control *ctrl, dlgparam *dp) { }
  155. bool dlg_is_visible(union control *ctrl, dlgparam *dp) { return false; }
  156. const char *const appname = "FuZZterm";
  157. const int ngsslibs = 0;
  158. const char *const gsslibnames[0] = { };
  159. const struct keyvalwhere gsslibkeywords[0] = { };
  160. /*
  161. * Default settings that are specific to Unix plink.
  162. */
  163. char *platform_default_s(const char *name)
  164. {
  165. if (!strcmp(name, "TermType"))
  166. return dupstr(getenv("TERM"));
  167. if (!strcmp(name, "SerialLine"))
  168. return dupstr("/dev/ttyS0");
  169. return NULL;
  170. }
  171. bool platform_default_b(const char *name, bool def)
  172. {
  173. return def;
  174. }
  175. int platform_default_i(const char *name, int def)
  176. {
  177. return def;
  178. }
  179. FontSpec *platform_default_fontspec(const char *name)
  180. {
  181. return fontspec_new("");
  182. }
  183. Filename *platform_default_filename(const char *name)
  184. {
  185. if (!strcmp(name, "LogFileName"))
  186. return filename_from_str("putty.log");
  187. else
  188. return filename_from_str("");
  189. }
  190. char *x_get_default(const char *key)
  191. {
  192. return NULL; /* this is a stub */
  193. }