⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textedit.cc

📁 功能较全面的反汇编器:反汇编器ht-2.0.15.tar.gz
💻 CC
📖 第 1 页 / 共 4 页
字号:
/* *	HT Editor *	textedit.cc * *	Copyright (C) 1999-2002 Sebastian Biallas (sb@biallas.net) *	Copyright (C) 1999-2002 Stefan Weyergraf * *	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 "evalx.h"#include "cmds.h"#include "htctrl.h"#include "htdialog.h"#include "htmenu.h"#include "htobj.h"#include "htpal.h"#include "htclipboard.h"#include "htiobox.h"#include "textedit.h"#include "tools.h"#include "snprintf.h"#include <errno.h>#include <limits.h>#include <stdlib.h>#include <string.h>#include <unistd.h>/**/#include "atom.h"#include "hthist.h"#include "htsearch.h"static ht_search_request* create_request_hexascii(text_search_pos *start, text_search_pos *end, ht_view *f, uint search_class){	ht_hexascii_search_form *form=(ht_hexascii_search_form*)f;	ht_hexascii_search_form_data d;	ViewDataBuf vdb(form, &d, sizeof d);		ht_fxbin_search_request *request;		if (!d.str.textlen) {		throw MsgfException("%s: string is empty", "hex/ascii");	}/*	if (test_str_to_ofs(&start->offset, d.start.text, d.start.textlen, format, "start-offset")	&& test_str_to_ofs(&end->offset, d.end.text, d.end.textlen, format, "end-offset")) {*/		request = new ht_fxbin_search_request(search_class,			d.options.state & 1 ? SF_FXBIN_CASEINSENSITIVE: 0,			d.str.textlen, d.str.text);/*	} else {		request = NULL;	}*/	return request;}typedef ht_search_request* (*create_request_func)(text_search_pos *ret_start, text_search_pos *ret_end, ht_view *form, uint search_class);struct ht_text_search_method {	const char *name;	uint search_class;			// SC_*	uint search_mode_mask;		// SEARCHMODE_*	uint histid;	create_form_func create_form;	create_request_func create_request;	create_desc_func create_desc;};static ht_text_search_method text_search_methods[] ={	{ "bin: hex/ascii", SC_PHYSICAL, SEARCHMODE_BIN, HISTATOM_SEARCH_BIN,		create_form_hexascii, create_request_hexascii, create_desc_hexascii }};ht_search_request *text_search_dialog(ht_text_viewer *text_viewer, uint searchmodes, const text_viewer_pos *end_pos){	ht_search_request *result = NULL;	Bounds b;	b.w = 50;	b.h = 15;	b.x = (screen->w - b.w)/2;	b.y = (screen->h - b.h)/2;	ht_search_dialog *dialog = new ht_search_dialog();	dialog->init(&b, "search");	Bounds k;	dialog->search_mode_xgroup->getbounds(&k);	k.x = 0;	k.y = 0;	int modes = 0;	int i = 0;	ht_text_search_method *q = text_search_methods;	while (q->name) {		if (q->search_mode_mask & searchmodes) {			Bounds v = k;			ht_view *form = q->create_form(&v, q->histid);			dialog->insert_search_mode(i, q->name, form);			modes++;		}		q++;		i++;	}	//	dialog->select_search_mode(lastsearchmodeid);		if (dialog->run(false)) {		int modeid = dialog->get_search_modeid();//		lastsearchmodeid = modeid;		ht_text_search_method *s = &text_search_methods[modeid];		ht_view *form = dialog->get_search_modeform();		text_search_pos start, end;		try {			/* create history entry */			if (s->create_desc) {				char hist_desc[1024];				s->create_desc(hist_desc, sizeof hist_desc, form);				insert_history_entry((List*)getAtomValue(s->histid), hist_desc, form);			}			/* search */			switch (s->search_class) {				case SC_PHYSICAL: {					text_viewer_pos cursor;					text_viewer->get_cursor_pos(&cursor);					start.offset = 0;					text_viewer->pos_to_offset(&cursor, &start.offset);					end.offset = 0xffffffff;					break;				}			}			result = s->create_request(&start, &end, form, s->search_class);		} catch (const Exception &e) {			errorbox("error: %y", &e);		}	}	dialog->done();	delete dialog;	return result;}/* *	CLASS ht_undo_data */bool ht_undo_data::combine(ht_undo_data *ud){	return false;}/* *	CLASS ht_undo_data_delete_string */ht_undo_data_delete_string::ht_undo_data_delete_string(text_viewer_pos *APos, text_viewer_pos *BPos, void *String, uint Len){	apos = *APos;	bpos = *BPos;	if (Len) {		string = malloc(Len);		memcpy(string, String, Len);	} else {		string = NULL;	}	len = Len;}ht_undo_data_delete_string::~ht_undo_data_delete_string(){	free(string);}bool ht_undo_data_delete_string::combine(ht_undo_data *ud){	if (ud->getObjectID() == getObjectID()) {		ht_undo_data_delete_string *ud2 = (ht_undo_data_delete_string *)ud;		if (ud2->apos.line == apos.line) {			if (ud2->bpos.pofs + ud2->len == bpos.pofs) {				string = realloc(string, len+ud2->len);				memmove((byte*)string+ud2->len, string, len);				memcpy(string, ud2->string, ud2->len);				len += ud2->len;				bpos = ud2->bpos;				return true;			}		}	}	return false;}uint ht_undo_data_delete_string::getsize(){	return len + sizeof *this;}void ht_undo_data_delete_string::gettext(char *text, uint maxlen){	char *buf = ht_malloc(len+1);	bin2str(buf, string, len);	ht_snprintf(text, maxlen, "deletion of '%s' at %d:%d", buf, bpos.line+1, bpos.pofs+1);	free(buf);}ObjectID ht_undo_data_delete_string::getObjectID() const{	return ATOM_HT_UNDO_DATA_DELETE;}void ht_undo_data_delete_string::apply(ht_text_editor *te){	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);	te->delete_chars(bpos.line, bpos.pofs, len);	te->goto_line(bpos.line);	te->cursor_pput(bpos.pofs);}void ht_undo_data_delete_string::unapply(ht_text_editor *te, bool *goto_only){	if (*goto_only && (bpos.line != te->top_line + te->cursory || te->physical_cursorx()!=bpos.pofs)) {		te->goto_line(apos.line);		te->cursor_pput(apos.pofs);		te->goto_line(bpos.line);		te->cursor_pput(bpos.pofs);		return;	}	*goto_only = false;	if (string) {		te->insert_chars(bpos.line, bpos.pofs, string, len);	}	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);}/* *	CLASS ht_undo_data_delete_string2 */ht_undo_data_delete_string2::ht_undo_data_delete_string2(text_viewer_pos *APos, text_viewer_pos *BPos, void *String, uint Len){	apos = *APos;	bpos = *BPos;	if (Len) {		string = malloc(Len);		memcpy(string, String, Len);	} else {		string = NULL;	}	len = Len;}ht_undo_data_delete_string2::~ht_undo_data_delete_string2(){	free(string);}bool ht_undo_data_delete_string2::combine(ht_undo_data *ud){	if (ud->getObjectID() == getObjectID()) {		ht_undo_data_delete_string2 *ud2 = (ht_undo_data_delete_string2 *)ud;		if (ud2->apos.line == apos.line) {			if (ud2->apos.pofs == apos.pofs) {				string = realloc(string, len+ud2->len);				memcpy((byte*)string+len, ud2->string, ud2->len);				len += ud2->len;				return true;			}		}	}	return false;}uint ht_undo_data_delete_string2::getsize(){	return len + sizeof *this;}void ht_undo_data_delete_string2::gettext(char *text, uint maxlen){	char *buf = ht_malloc(len+1);	bin2str(buf, string, len);	ht_snprintf(text, maxlen, "deletion of '%s' at %d:%d", buf, apos.line+1, apos.pofs+1);	free(buf);}ObjectID ht_undo_data_delete_string2::getObjectID() const{	return ATOM_HT_UNDO_DATA_DELETE2;}void ht_undo_data_delete_string2::apply(ht_text_editor *te){	te->goto_line(bpos.line);	te->cursor_pput(bpos.pofs);	te->delete_chars(apos.line, apos.pofs, len);	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);}void ht_undo_data_delete_string2::unapply(ht_text_editor *te, bool *goto_only){	if (*goto_only && (apos.line != te->top_line + te->cursory || te->physical_cursorx()!=apos.pofs)) {		te->goto_line(bpos.line);		te->cursor_pput(bpos.pofs);		te->goto_line(apos.line);		te->cursor_pput(apos.pofs);		return;	}	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);	*goto_only = false;	if (string) {		te->insert_chars(apos.line, apos.pofs, string, len);	}}/* *	CLASS ht_undo_data_insert_string */ht_undo_data_insert_string::ht_undo_data_insert_string(text_viewer_pos *APos, text_viewer_pos *BPos, void *String, uint Len){	apos = *APos;	bpos = *BPos;	if (Len) {		string = malloc(Len);		memcpy(string, String, Len);	} else {		string = NULL;	}	len = Len;}ht_undo_data_insert_string::~ht_undo_data_insert_string(){	free(string);}bool ht_undo_data_insert_string::combine(ht_undo_data *ud){	if (ud->getObjectID() == getObjectID()) {		ht_undo_data_insert_string *ud2 = (ht_undo_data_insert_string *)ud;		if (ud2->cpos.line == cpos.line) {			if (ud2->apos.pofs == apos.pofs + len) {				string = realloc(string, len + ud2->len);				memcpy((byte*)string+len, ud2->string, ud2->len);				len += ud2->len;				bpos = ud2->bpos;				return true;			}		}	}	return false;}uint ht_undo_data_insert_string::getsize(){	return len + sizeof *this;}void ht_undo_data_insert_string::gettext(char *text, uint maxlen){	char *buf = ht_malloc(len+1);	bin2str(buf, string, len);	ht_snprintf(text, maxlen, "insertion of '%s' at %d:%d", buf, apos.line+1, apos.pofs+1);	free(buf);}ObjectID ht_undo_data_insert_string::getObjectID() const{	return ATOM_HT_UNDO_DATA_INSERT;}void ht_undo_data_insert_string::apply(ht_text_editor *te){	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);	if (string) {		uint l = te->get_line_length(apos.line);		cpos.line = apos.line;		if (apos.pofs > l) {			uint k = apos.pofs - l;               			te->indent(apos.line, l, k);			cpos.pofs = l;		} else {			cpos.pofs = apos.pofs;		}		te->insert_chars(apos.line, apos.pofs, string, len);	}	te->goto_line(bpos.line);	te->cursor_pput(bpos.pofs);}void ht_undo_data_insert_string::unapply(ht_text_editor *te, bool *goto_only){	if (*goto_only && (bpos.line != te->top_line + te->cursory || te->physical_cursorx()!=bpos.pofs)) {		te->goto_line(apos.line);		te->cursor_pput(apos.pofs);		te->goto_line(bpos.line);		te->cursor_pput(bpos.pofs);		return;	}	*goto_only = false;	te->unindent(cpos.line, cpos.pofs, bpos.pofs-cpos.pofs);	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);}/* *	CLASS ht_undo_data_overwrite_string */ht_undo_data_overwrite_string::ht_undo_data_overwrite_string(text_viewer_pos *APos, text_viewer_pos *BPos, void *String, uint Len, void *String2, uint Len2){	apos = *APos;	bpos = *BPos;	if (Len) {		string = malloc(Len);		memcpy(string, String, Len);	} else {		string = NULL;	}	len = Len;	if (Len2) {		string2 = malloc(Len2);		memcpy(string2, String2, Len2);	} else {		string2 = NULL;	}	len2 = Len2;}ht_undo_data_overwrite_string::~ht_undo_data_overwrite_string(){	free(string);	free(string2);}bool ht_undo_data_overwrite_string::combine(ht_undo_data *ud){	if (ud->getObjectID()==getObjectID()) {		ht_undo_data_overwrite_string *ud2 = (ht_undo_data_overwrite_string *)ud;		if (ud2->cpos.line == cpos.line) {			if (ud2->apos.pofs == apos.pofs + len) {				string = realloc(string, len + ud2->len);				memcpy((byte*)string+len, ud2->string, ud2->len);				len += ud2->len;				bpos = ud2->bpos;				if (ud2->len2) {					if (!len2) {						string2 = malloc(ud2->len2);						memcpy(string2, ud2->string2, ud2->len2);					} else {						string2 = realloc(string2, len2 + ud2->len2);						memcpy((byte*)string2+len2, ud2->string2, ud2->len2);					}					len2 += ud2->len;				}				return true;			}		}	}	return false;}uint ht_undo_data_overwrite_string::getsize(){	return len + len2 + sizeof(*this);}void ht_undo_data_overwrite_string::gettext(char *text, uint maxlen){	char *buf = ht_malloc(len+1);	bin2str(buf, string, len);	ht_snprintf(text, maxlen, "insertion of '%s' at %d:%d", buf, apos.line+1, apos.pofs+1);	free(buf);}ObjectID ht_undo_data_overwrite_string::getObjectID() const{	return ATOM_HT_UNDO_DATA_OVERWRITE;}void ht_undo_data_overwrite_string::apply(ht_text_editor *te){	if (len2) te->delete_chars(apos.line, apos.pofs, len2);	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);	if (string) {		uint l = te->get_line_length(apos.line);		cpos.line = apos.line;		if (apos.pofs > l) {			uint k = apos.pofs - l;               			te->indent(apos.line, l, k);			cpos.pofs = l;		} else {			cpos.pofs = apos.pofs;		}		te->insert_chars(apos.line, apos.pofs, string, len);	}	te->goto_line(bpos.line);	te->cursor_pput(bpos.pofs);}void ht_undo_data_overwrite_string::unapply(ht_text_editor *te, bool *goto_only){	if (*goto_only && (bpos.line != te->top_line + te->cursory || te->physical_cursorx()!=bpos.pofs)) {		te->goto_line(apos.line);		te->cursor_pput(apos.pofs);		te->goto_line(bpos.line);		te->cursor_pput(bpos.pofs);		return;	}	*goto_only = false;	te->unindent(cpos.line, cpos.pofs, bpos.pofs-cpos.pofs);	if (len2) te->insert_chars(apos.line, apos.pofs, string2, len2);	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);}/* *	CLASS ht_undo_data_split_line */ht_undo_data_split_line::ht_undo_data_split_line(text_viewer_pos *APos, text_viewer_pos *BPos, uint Indent){	apos = *APos;	bpos = *BPos;	indent = Indent;}uint ht_undo_data_split_line::getsize(){	return sizeof *this;}void ht_undo_data_split_line::gettext(char *text, uint maxlen){	ht_snprintf(text, maxlen, "split line at %d:%d", apos.line+1, apos.pofs+1);}ObjectID ht_undo_data_split_line::getObjectID() const{	return ATOM_HT_UNDO_DATA_SPLIT_LINE;}void ht_undo_data_split_line::apply(ht_text_editor *te){	te->split_line(apos.line, apos.pofs);	if (indent) te->indent(bpos.line, 0, indent);	te->goto_line(bpos.line);	te->cursor_pput(bpos.pofs);}void ht_undo_data_split_line::unapply(ht_text_editor *te, bool *goto_only){	if (*goto_only && (bpos.line != te->top_line + te->cursory || te->physical_cursorx()!=bpos.pofs)) {		te->goto_line(apos.line);		te->cursor_pput(apos.pofs);		te->goto_line(bpos.line);		te->cursor_pput(bpos.pofs);		return;	}	*goto_only = false;	if (indent) te->unindent(bpos.line, 0, indent);	te->concat_lines(apos.line);	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);}/* *	CLASS ht_undo_data_join_line */ht_undo_data_join_line::ht_undo_data_join_line(text_viewer_pos *APos, text_viewer_pos *BPos){	apos = *APos;	bpos = *BPos;}uint ht_undo_data_join_line::getsize(){	return sizeof *this;}void ht_undo_data_join_line::gettext(char *text, uint maxlen){	ht_snprintf(text, maxlen, "join lines %d and %d", bpos.line+1, bpos.line+2);}ObjectID ht_undo_data_join_line::getObjectID() const{	return ATOM_HT_UNDO_DATA_JOIN_LINE;}void ht_undo_data_join_line::apply(ht_text_editor *te){	uint l = te->get_line_length(apos.line);	cpos.line = apos.line;	if (apos.pofs > l) {		uint k = apos.pofs - l;		te->indent(apos.line, l, k);		cpos.pofs = l;	} else {		cpos.pofs = apos.pofs;	}	    	te->concat_lines(bpos.line);	te->goto_line(bpos.line);	te->cursor_pput(bpos.pofs);}void ht_undo_data_join_line::unapply(ht_text_editor *te, bool *goto_only){	if (*goto_only && (bpos.line != te->top_line + te->cursory || te->physical_cursorx()!=bpos.pofs)) {		te->goto_line(bpos.line);		te->cursor_pput(bpos.pofs);		return;     	}	*goto_only = false;	te->split_line(bpos.line, bpos.pofs);	if (cpos.line == bpos.line) te->unindent(cpos.line, cpos.pofs, bpos.pofs-cpos.pofs);	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);}/* *	INSERT/DELETE BLOCK */text_viewer_pos insert_text_block(ht_text_editor *te, text_viewer_pos apos, text_viewer_pos bpos, void *block, uint size){	text_viewer_pos cpos;	te->goto_line(apos.line);	te->cursor_pput(apos.pofs);	ht_textfile *textfile = te->get_textfile();	FileOfs o;		textfile->convert_line2ofs(apos.line, apos.pofs, &o);	uint l = te->get_line_length(apos.line);	cpos.line = apos.line;	if (apos.pofs > l) {		uint k = apos.pofs - l;		te->indent(apos.line, l, k);		cpos.pofs = l;		o += k;	} else {		cpos.pofs = apos.pofs;	}	textfile->seek(o);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -