00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __HTFORMAT_H__
00022 #define __HTFORMAT_H__
00023
00024 class ht_format_group;
00025
00026 #include "evalx.h"
00027 #include "htdata.h"
00028 #include "htobj.h"
00029 #include "htstring.h"
00030 #include "formats.h"
00031
00032 class ht_sub;
00033
00034 struct LINE_ID {
00035 ID id1;
00036 ID id2;
00037 ID id3;
00038 ID id4;
00039 ID id5;
00040 };
00041
00042 struct uformat_viewer_pos {
00043
00044 ht_sub *sub;
00045 LINE_ID line_id;
00046
00047 int tag_group;
00048 int tag_idx;
00049 };
00050
00051 union viewer_pos {
00052 uformat_viewer_pos u;
00053 };
00054
00055
00056
00057
00058
00059 class ht_search_request: public Object {
00060 public:
00061 UINT search_class;
00062 UINT type;
00063 UINT flags;
00064
00065 ht_search_request(UINT search_class, UINT type, UINT flags);
00066 };
00067
00068
00069
00070
00071
00072 class ht_search_result: public Object {
00073 public:
00074 UINT search_class;
00075
00076 ht_search_result(UINT search_class);
00077 };
00078
00079
00080
00081
00082
00083 class ht_physical_search_result: public ht_search_result {
00084 public:
00085 FILEOFS offset;
00086 UINT size;
00087
00088 ht_physical_search_result();
00089 };
00090
00091
00092
00093
00094
00095 class ht_visual_search_result: public ht_search_result {
00096 public:
00097 viewer_pos pos;
00098 UINT xpos;
00099 UINT length;
00100
00101 ht_visual_search_result();
00102 };
00103
00104
00105
00106
00107
00108 class ht_format_loc: public Object {
00109 public:
00110 char *name;
00111 FILEOFS start;
00112 UINT length;
00113 };
00114
00115
00116
00117
00118
00119
00120 #define VC_NULL 0x0000
00121 #define VC_EDIT 0x0001
00122 #define VC_GOTO 0x0002
00123 #define VC_SEARCH 0x0004
00124 #define VC_REPLACE 0x0008
00125 #define VC_RESIZE 0x0010
00126
00127 class ht_viewer: public ht_view {
00128 protected:
00129 UINT caps;
00130
00131
00132 virtual char *func(UINT i, bool execute);
00133 public:
00134 void init(bounds *b, const char *desc, UINT caps);
00135 virtual void done();
00136
00137 virtual void handlemsg(htmsg *msg);
00138 };
00139
00140
00141
00142
00143
00144 class ht_format_viewer: public ht_viewer {
00145 protected:
00146 ht_streamfile *file;
00147
00148 ht_search_request *last_search_request;
00149 bool last_search_physical;
00150 union {
00151 FILEOFS last_search_end_ofs;
00152 viewer_pos last_search_end_pos;
00153 };
00154
00155
00156 virtual bool compeq_viewer_pos(viewer_pos *a, viewer_pos *b);
00157
00158 virtual void vstate_restore(Object *view_state);
00159 virtual Object *vstate_create();
00160
00161 virtual bool next_logical_pos(viewer_pos pos, viewer_pos *npos);
00162 virtual bool next_logical_offset(FILEOFS ofs, FILEOFS *nofs);
00163 public:
00164 ht_format_group *format_group;
00165
00166 void init(bounds *b, const char *desc, UINT caps, ht_streamfile *file, ht_format_group *format_group);
00167 virtual void done();
00168
00169 virtual void handlemsg(htmsg *msg);
00170
00171 virtual bool pos_to_offset(viewer_pos pos, FILEOFS *ofs);
00172 virtual bool offset_to_pos(FILEOFS ofs, viewer_pos *pos);
00173
00174 virtual void get_pindicator_str(char *buf);
00175
00176 virtual bool get_hscrollbar_pos(int *pstart, int *psize);
00177 virtual bool get_vscrollbar_pos(int *pstart, int *psize);
00178
00179 virtual void loc_enum_start();
00180 virtual bool loc_enum_next(ht_format_loc *loc);
00181
00182
00183 virtual bool get_current_offset(FILEOFS *ofs);
00184 virtual bool goto_offset(FILEOFS ofs, bool save_vstate);
00185 virtual UINT pread(FILEOFS ofs, void *buf, UINT size);
00186 virtual ht_search_result *psearch(ht_search_request *search, FILEOFS start, FILEOFS end);
00187 virtual void pselect_add(FILEOFS start, FILEOFS end);
00188 virtual void pselect_get(FILEOFS *start, FILEOFS *end);
00189 virtual void pselect_set(FILEOFS start, FILEOFS end);
00190 virtual UINT pwrite(FILEOFS ofs, void *buf, UINT size);
00191 virtual bool string_to_offset(char *string, FILEOFS *ofs);
00192 virtual bool qword_to_offset(qword q, FILEOFS *ofs);
00193
00194 virtual bool get_current_real_offset(FILEOFS *ofs);
00195
00196
00197 virtual bool get_current_pos(viewer_pos *pos);
00198 virtual bool goto_pos(viewer_pos pos, bool save_vstate);
00199 virtual UINT vread(viewer_pos pos, void *buf, UINT size);
00200 virtual ht_search_result *vsearch(ht_search_request *search, viewer_pos start, viewer_pos end);
00201 virtual void vselect_add(viewer_pos start, viewer_pos end);
00202 virtual void vselect_get(viewer_pos *start, viewer_pos *end);
00203 virtual void vselect_set(viewer_pos start, viewer_pos end);
00204 virtual UINT vwrite(viewer_pos pos, void *buf, UINT size);
00205 virtual bool string_to_pos(char *string, viewer_pos *pos);
00206 virtual bool qword_to_pos(qword q, viewer_pos *pos);
00207
00208
00209 virtual int func_handler(eval_scalar *result, char *name, eval_scalarlist *params);
00210 virtual int symbol_handler(eval_scalar *result, char *name);
00211
00212
00213 bool continue_search();
00214 virtual bool show_search_result(ht_search_result *result);
00215
00216 void clear_viewer_pos(viewer_pos *p);
00217 ht_streamfile *get_file();
00218 bool string_to_qword(char *string, qword *q);
00219 bool vstate_save();
00220 };
00221
00222
00223
00224
00225
00226 class ht_format_viewer_entry: public Object {
00227 public:
00228 ht_view *instance;
00229 format_viewer_if *interface;
00230 };
00231
00232
00233
00234
00235
00236 class ht_format_group: public ht_format_viewer {
00237 protected:
00238 ht_clist *format_views;
00239 void *shared_data;
00240 bool editable_file;
00241 bool own_file;
00242 ht_xgroup *xgroup;
00243
00244
00245 void init_ifs(format_viewer_if **ifs);
00246 void done_ifs();
00247
00248 bool init_if(format_viewer_if *i);
00249 bool done_if(format_viewer_if *i, ht_view *v);
00250
00251 bool edit();
00252 public:
00253 void init(bounds *b, int options, const char *desc, ht_streamfile *file, bool own_file, bool editable_file, format_viewer_if **ifs, ht_format_group *format_group);
00254 virtual void done();
00255
00256 virtual int childcount();
00257 virtual int focus(ht_view *view);
00258 virtual char *func(UINT i, bool execute);
00259 void getbounds(bounds *b);
00260 virtual ht_view *getfirstchild();
00261 virtual ht_view *getselected();
00262 virtual void get_pindicator_str(char *buf);
00263 virtual bool get_hscrollbar_pos(int *pstart, int *psize);
00264 virtual bool get_vscrollbar_pos(int *pstart, int *psize);
00265 virtual void handlemsg(htmsg *msg);
00266 virtual void move(int x, int y);
00267 virtual void receivefocus();
00268 virtual void redraw();
00269 virtual void releasefocus();
00270 virtual void resize(int rw, int rh);
00271 virtual void setgroup(ht_group *group);
00272
00273 virtual void insert(ht_view *view);
00274 void remove(ht_view *view);
00275 void *get_shared_data();
00276 };
00277
00278
00279
00280
00281
00282 #define cursor_state_visible 0
00283 #define cursor_state_invisible 1
00284 #define cursor_state_disabled 2
00285
00286 class ht_uformat_viewer: public ht_format_viewer {
00287 protected:
00288 ht_sub *first_sub, *last_sub;
00289
00290 uformat_viewer_pos top;
00291
00292 uformat_viewer_pos cursor;
00293 int cursor_ypos;
00294 int cursor_state;
00295 bool cursor_select;
00296 FILEOFS cursor_select_start;
00297 dword cursor_select_cursor_length;
00298 int cursor_tag_micropos;
00299
00300 FILEOFS sel_start;
00301 FILEOFS sel_end;
00302
00303 int cursor_visual_xpos;
00304 int cursor_visual_length;
00305
00306 int cursor_tag_class;
00307 union {
00308 FILEOFS cursor_tag_offset;
00309 struct {
00310 LINE_ID id;
00311 } cursor_tag_id;
00312 };
00313 char cursor_line[1024];
00314
00315 palette tagpal;
00316
00317 int xscroll;
00318
00319 bool uf_initialized;
00320
00321 bool isdirty_cursor_line;
00322
00323
00324 virtual char *func(UINT i, bool execute);
00325 virtual bool next_logical_pos(viewer_pos pos, viewer_pos *npos);
00326 virtual bool next_logical_offset(FILEOFS ofs, FILEOFS *nofs);
00327 virtual Object *vstate_create();
00328 virtual void vstate_restore(Object *view_state);
00329
00330 int address_input(const char *title, char *buf, int buflen, dword histid);
00331 void adjust_cursor_group();
00332 void adjust_cursor_idx();
00333 int center_view(viewer_pos p);
00334 void clear_subs();
00335 bool compeq_viewer_pos(uformat_viewer_pos *a, uformat_viewer_pos *b);
00336 void check_cursor_visibility();
00337 void clear_viewer_pos(uformat_viewer_pos *p);
00338 int cursor_left();
00339 int cursor_right();
00340 int cursor_down(int n);
00341 int cursor_up(int n);
00342 int cursor_home();
00343 int cursor_end();
00344 void cursor_tab();
00345 void cursorline_dirty();
00346 void cursorline_get();
00347 virtual int cursormicro_forward();
00348 virtual int cursormicro_backward();
00349 virtual int cursormicroedit_forward();
00350 bool edit_end();
00351 bool edit_input(byte b);
00352 int edit_input_c2h(byte b);
00353 int edit_input_c2d(byte b);
00354 void edit_input_correctpos();
00355 bool edit_start();
00356 bool edit_update();
00357 bool edit();
00358 bool find_first_tag(uformat_viewer_pos *p, int limit);
00359 bool find_first_edit_tag_with_offset(uformat_viewer_pos *p, int limit, FILEOFS offset);
00360 void focus_cursor();
00361 vcp getcolor_tag(UINT pal_index);
00362 int get_current_tag(char **tag);
00363 int get_current_tag_size(dword *size);
00364 vcp get_tag_color_edit(FILEOFS tag_offset, UINT size, bool atcursoroffset, bool iscursor);
00365 int next_line(uformat_viewer_pos *p, int n);
00366 int prev_line(uformat_viewer_pos *p, int n);
00367 void print_tagstring(int x, int y, int maxlen, int xscroll, char *tagstring, bool cursor_in_line);
00368 virtual int ref();
00369 int ref_desc(ID id, FILEOFS offset, UINT size, bool bigendian);
00370 int ref_flags(ID id, FILEOFS offset);
00371 virtual int ref_sel(LINE_ID *id);
00372 virtual void reloadpalette();
00373 UINT render_tagstring(char *chars, vcp *colors, UINT maxlen, char *tagstring, bool cursor_in_line);
00374 void render_tagstring_desc(char **string, int *length, vcp *tag_color, char *tag, UINT size, bool bigendian, bool is_cursor);
00375 UINT render_tagstring_single(char *chars, vcp *colors, UINT maxlen, UINT offset, char *text, UINT len, vcp color);
00376 void scroll_up(int n);
00377 void scroll_down(int n);
00378 void select_mode_off();
00379 void select_mode_on();
00380 void select_mode_pre();
00381 void select_mode_post(bool lastpos);
00382 bool set_cursor(uformat_viewer_pos p);
00383 void update_micropos();
00384 void update_misc_info();
00385 void update_visual_info();
00386 void update_ypos();
00387 public:
00388 UINT search_caps;
00389
00390 void init(bounds *b, const char *desc, int caps, ht_streamfile *file, ht_format_group *format_group);
00391 virtual void done();
00392
00393 virtual void clear_viewer_pos(viewer_pos *p);
00394 virtual void draw();
00395 virtual bool get_current_offset(FILEOFS *offset);
00396 virtual bool get_current_pos(viewer_pos *pos);
00397 virtual bool goto_offset(FILEOFS offset, bool save_vstate);
00398 virtual bool goto_pos(viewer_pos pos, bool save_vstate);
00399 virtual void handlemsg(htmsg *msg);
00400 virtual ht_search_result *psearch(ht_search_request *search, FILEOFS start, FILEOFS end);
00401 virtual void pselect_add(FILEOFS start, FILEOFS end);
00402 virtual void pselect_get(FILEOFS *start, FILEOFS *end);
00403 virtual void pselect_set(FILEOFS start, FILEOFS end);
00404 virtual UINT pwrite(FILEOFS ofs, void *buf, UINT size);
00405 virtual bool qword_to_offset(qword q, FILEOFS *ofs);
00406 virtual ht_search_result *vsearch(ht_search_request *search, viewer_pos start, viewer_pos end);
00407
00408 virtual bool compeq_viewer_pos(viewer_pos *a, viewer_pos *b);
00409 void complete_init();
00410 virtual void insertsub(ht_sub *sub);
00411 void sendsubmsg(int msg);
00412 void sendsubmsg(htmsg *msg);
00413 };
00414
00415
00416
00417
00418
00419
00420 #define SR_NOT_FOUND 0
00421 #define SR_FOUND 1
00422 #define SR_NOT_SUPPORTED 2
00423
00424 class ht_sub: public Object {
00425 protected:
00426 ht_streamfile *file;
00427 public:
00428 ht_uformat_viewer *uformat_viewer;
00429 ht_sub *prev, *next;
00430
00431 void init(ht_streamfile *file);
00432 virtual void done();
00433
00434 virtual bool convert_ofs_to_id(const FILEOFS offset, LINE_ID *line_id);
00435 virtual bool convert_id_to_ofs(const LINE_ID line_id, FILEOFS *offset);
00436 virtual bool closest_line_id(LINE_ID *line_id);
00437 virtual void first_line_id(LINE_ID *line_id);
00438 virtual bool getline(char *line, const LINE_ID line_id);
00439 virtual void handlemsg(htmsg *msg);
00440 virtual void last_line_id(LINE_ID *line_id);
00441 virtual int next_line_id(LINE_ID *line_id, int n);
00442 virtual int prev_line_id(LINE_ID *line_id, int n);
00443 virtual bool ref(LINE_ID *id);
00444 virtual ht_search_result *search(ht_search_request *search, FILEOFS start, FILEOFS end);
00445 };
00446
00447
00448
00449
00450
00451 class ht_linear_sub: public ht_sub {
00452 protected:
00453 FILEOFS fofs;
00454 dword fsize;
00455 public:
00456 void init(ht_streamfile *file, FILEOFS offset, int size);
00457 virtual void done();
00458
00459 virtual void handlemsg(htmsg *msg);
00460 virtual ht_search_result *search(ht_search_request *search, FILEOFS start, FILEOFS end);
00461 };
00462
00463
00464
00465
00466
00467 class ht_hex_sub: public ht_linear_sub {
00468 protected:
00469 dword vaddrinc;
00470 dword balign;
00471 dword line_length;
00472 UINT uid;
00473 public:
00474 void init(ht_streamfile *file, FILEOFS ofs, dword size, UINT line_length, UINT uid, dword vaddrinc=0);
00475 virtual void done();
00476 int get_line_length();
00477 void set_line_length(int line_length);
00478
00479 virtual bool convert_ofs_to_id(const FILEOFS offset, LINE_ID *line_id);
00480 virtual bool convert_id_to_ofs(const LINE_ID line_id, FILEOFS *offset);
00481 virtual void first_line_id(LINE_ID *line_id);
00482 virtual bool getline(char *line, const LINE_ID line_id);
00483 virtual void handlemsg(htmsg *msg);
00484 virtual void last_line_id(LINE_ID *line_id);
00485 virtual int next_line_id(LINE_ID *line_id, int n);
00486 virtual int prev_line_id(LINE_ID *line_id, int n);
00487 };
00488
00489
00490
00491
00492
00493 struct ht_mask_ptable {
00494 char *desc;
00495 char *fields;
00496 };
00497
00498 class ht_mask_sub: public ht_sub {
00499 protected:
00500 ht_string_list *masks;
00501 char temp[512];
00502 UINT uid;
00503 public:
00504 void init(ht_streamfile *file, UINT uid);
00505 virtual void done();
00506
00507 virtual void first_line_id(LINE_ID *line_id);
00508 virtual bool getline(char *line, const LINE_ID line_id);
00509 virtual void last_line_id(LINE_ID *line_id);
00510 virtual int next_line_id(LINE_ID *line_id, int n);
00511 virtual int prev_line_id(LINE_ID *line_id, int n);
00512
00513 virtual void add_mask(char *tagstr);
00514 virtual void add_mask_table(char **tagstr);
00515 virtual void add_staticmask(char *statictag_str, FILEOFS reloc, bool std_bigendian);
00516 virtual void add_staticmask_table(char **statictag_table, FILEOFS reloc, bool std_bigendian);
00517 virtual void add_staticmask_ptable(ht_mask_ptable *statictag_ptable, FILEOFS reloc, bool std_bigendian);
00518 };
00519
00520
00521
00522
00523
00524 class ht_layer_sub: public ht_sub {
00525 protected:
00526 ht_sub *sub;
00527 bool own_sub;
00528 public:
00529 void init(ht_streamfile *file, ht_sub *sub, bool own_sub);
00530 virtual void done();
00531
00532 virtual bool convert_ofs_to_id(const FILEOFS offset, LINE_ID *line_id);
00533 virtual bool convert_id_to_ofs(const LINE_ID line_id, FILEOFS *offset);
00534 virtual bool closest_line_id(LINE_ID *line_id);
00535 virtual void first_line_id(LINE_ID *line_id);
00536 virtual bool getline(char *line, const LINE_ID line_id);
00537 virtual void handlemsg(htmsg *msg);
00538 virtual void last_line_id(LINE_ID *line_id);
00539 virtual int next_line_id(LINE_ID *line_id, int n);
00540 virtual int prev_line_id(LINE_ID *line_id, int n);
00541 virtual bool ref(LINE_ID *id);
00542 virtual ht_search_result *search(ht_search_request *search, FILEOFS start, FILEOFS end);
00543 };
00544
00545
00546
00547
00548
00549 class ht_collapsable_sub: public ht_layer_sub {
00550 protected:
00551 char *nodestring;
00552 bool collapsed;
00553 LINE_ID fid;
00554 LINE_ID myfid;
00555 public:
00556 void init(ht_streamfile *file, ht_sub *sub, bool own_sub, char *nodename, bool collapsed);
00557 virtual void done();
00558
00559 virtual bool convert_ofs_to_id(const FILEOFS offset, LINE_ID *line_id);
00560 virtual bool convert_id_to_ofs(const LINE_ID line_id, FILEOFS *offset);
00561 virtual void first_line_id(LINE_ID *line_id);
00562 virtual bool getline(char *line, const LINE_ID line_id);
00563 virtual void last_line_id(LINE_ID *line_id);
00564 virtual int next_line_id(LINE_ID *line_id, int n);
00565 virtual int prev_line_id(LINE_ID *line_id, int n);
00566 virtual bool ref(LINE_ID *id);
00567 virtual ht_search_result *search(ht_search_request *search, FILEOFS start, FILEOFS end);
00568 };
00569
00570
00571
00572
00573
00574 class ht_group_sub: public ht_sub {
00575 protected:
00576 ht_clist *subs;
00577 public:
00578 void init(ht_streamfile *file);
00579 virtual void done();
00580
00581 virtual bool convert_ofs_to_id(const FILEOFS offset, LINE_ID *line_id);
00582 virtual bool convert_id_to_ofs(const LINE_ID line_id, FILEOFS *offset);
00583 virtual void first_line_id(LINE_ID *line_id);
00584 virtual bool getline(char *line, const LINE_ID line_id);
00585 virtual void handlemsg(htmsg *msg);
00586 virtual void last_line_id(LINE_ID *line_id);
00587 virtual int next_line_id(LINE_ID *line_id, int n);
00588 virtual int prev_line_id(LINE_ID *line_id, int n);
00589 virtual bool ref(LINE_ID *id);
00590 virtual ht_search_result *search(ht_search_request *search, FILEOFS start, FILEOFS end);
00591
00592 void insertsub(ht_sub *sub);
00593 };
00594
00595
00596
00597
00598
00599 class ht_data_tagstring: public ht_data_string {
00600 public:
00601 ht_data_tagstring(char *tagstr=0);
00602 virtual ~ht_data_tagstring();
00603 };
00604
00605 ht_search_result *linear_expr_search(ht_search_request *search, FILEOFS start, FILEOFS end, ht_sub *sub, ht_uformat_viewer *ufv, FILEOFS fofs, dword fsize);
00606 ht_search_result *linear_bin_search(ht_search_request *search, FILEOFS start, FILEOFS end, ht_streamfile *file, FILEOFS fofs, dword fsize);
00607
00608 void clear_line_id(LINE_ID *l);
00609 bool compeq_line_id(const LINE_ID &a, const LINE_ID &b);
00610
00611 #endif
00612