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

📄 blockop.cc

📁 功能较全面的反汇编器:反汇编器ht-2.0.15.tar.gz
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* *	HT Editor *	blockop.cc * *	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 <stdlib.h>#include <string.h>#include "blockop.h"#include "cmds.h"#include "atom.h"#include "htctrl.h"#include "endianess.h"#include "hteval.h"#include "except.h"#include "hthist.h"#include "htiobox.h"#include "keyb.h"#include "strtools.h"#include "htprocess.h"#include "snprintf.h"#include "evalx.h"/* *	CLASS ht_blockop_dialog */void ht_blockop_dialog::init(Bounds *b, FileOfs pstart, FileOfs pend, List *history){	ht_dialog::init(b, "operate on block", FS_TITLE | FS_KILLER | FS_MOVE);	Bounds c;	bool prerange = (pend > pstart);	ht_statictext *text;	ht_label *s;		List *addrhist = (List*)getAtomValue(HISTATOM_GOTO);	/* start */	c = *b;	c.h = 1;	c.w = 13;	c.x = 7;	c.y = 1;	start = new ht_strinputfield();	start->init(&c, 64, addrhist);	insert(start);	if (prerange) {		char t[32];		ht_snprintf(t, sizeof t, "0x%qx", pstart);		ht_inputfield_data d;		d.textlen = strlen(t);		d.text = (byte*)t;		start->databuf_set(&d, sizeof d);	}	/* start_desc */	c.x = 1;	c.w = 6;	s = new ht_label();	s->init(&c, "~start", start);	insert(s);		/* end */	c = *b;	c.h = 1;	c.w = 13;	c.x = 27;	c.y = 1;	end=new ht_strinputfield();	end->init(&c, 64, addrhist);	insert(end);	if (prerange) {		char t[32];		ht_snprintf(t, sizeof t, "0x%qx", pend);		ht_inputfield_data d;		d.textlen = strlen(t);		d.text = (byte*)t;		end->databuf_set(&d, sizeof d);	}	/* end_desc */	c.x = 23;	c.w = 3;	s = new ht_label();	s->init(&c, "~end", end);	insert(s);	/* mode */	c = *b;	c.h = 1;	c.w = 16;	c.x = 7;	c.y = 3;	mode = new ht_listpopup();	mode->init(&c);	mode->insertstring("byte (8-bit)");	mode->insertstring("word (16-bit)");	mode->insertstring("dword (32-bit)");	mode->insertstring("qword (64-bit)");	mode->insertstring("string");	insert(mode);	/* mode_desc */	c.x = 1;	c.w = 12;	c.y = 3;	s = new ht_label();	s->init(&c, "~mode", mode);	insert(s);	/* action_expl */	c = *b;	c.x = 1;	c.y = 5;	c.w -= 3;	c.h = 1;	text = new ht_statictext();	text->init(&c, "set each element to", align_left);	insert(text);		/* action */	List *ehist = (List*)getAtomValue(HISTATOM_EVAL_EXPR);	c = *b;	c.h = 1;	c.w = 40;	c.x = 7;	c.y = 6;	action = new ht_strinputfield();	action->init(&c, 4096, ehist);	insert(action);	/* action_desc */	c.x = 1;	c.w = 27;	c.y = 6;	s = new ht_label();	s->init(&c, "e~xpr", action);	insert(s);	/* help *//*	c=*b;	c.x=1;	c.y=8;	c.w-=c.x+2;	c.h-=c.y+2;	text=new ht_statictext();	text->init(&c,		"special vars:          special funcs:\n"		"o - file offset        readbyte(ofs)\n"		"i - iteration index    readstring(ofs, n)", align_left);	insert(text);*/	/* functions */	ht_button *bhelp = new ht_button();	c = *b;	c.x = 1;	c.y = 8;	c.w = 12;	c.h = 2;	bhelp->init(&c, "~Functions", 100);	insert(bhelp);}void ht_blockop_dialog::done(){	ht_dialog::done();}struct ht_blockop_dialog_data {	ht_inputfield_data start;	ht_inputfield_data end;	ht_listpopup_data mode;	ht_inputfield_data action;};/* *   blockop_dialog */static FileOfs blockop_i;static FileOfs blockop_o;static bool blockop_expr_is_const;static bool blockop_symbol_eval(eval_scalar *r, char *symbol){	if (strcmp(symbol, "i") == 0) {		r->type = SCALAR_INT;		r->scalar.integer.value = blockop_i;		r->scalar.integer.type = TYPE_UNKNOWN;		blockop_expr_is_const = false;		return true;	} else if (strcmp(symbol, "o") == 0) {		r->type = SCALAR_INT;		r->scalar.integer.value = blockop_o;		r->scalar.integer.type = TYPE_UNKNOWN;		blockop_expr_is_const = false;		return true;	}	return false;}static int func_readint(eval_scalar *result, eval_int *offset, int size, Endianess e){		File *f = (File*)eval_get_context();	byte buf[8];	try {		f->seek(offset->value);		f->readx(buf, size);	} catch (const IOException&) {		set_eval_error("i/o error (couldn't read %d bytes from ofs %qd (0x%qx))", size, offset->value, offset->value);		return 0;	}	scalar_create_int_q(result, createHostInt64(buf, size, e));	return 1;}static int func_readbyte(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 1, little_endian);}static int func_read16le(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 2, little_endian);}static int func_read32le(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 4, little_endian);}static int func_read64le(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 8, little_endian);}static int func_read16be(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 2, big_endian);}static int func_read32be(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 4, big_endian);}static int func_read64be(eval_scalar *result, eval_int *offset){	return func_readint(result, offset, 8, big_endian);}static int func_readstring(eval_scalar *result, eval_int *offset, eval_int *len){	File *f = (File*)eval_get_context();	uint l = len->value;	void *buf = malloc(l);	/* FIXME: may be too slow... */	if (buf) {		eval_str s;		uint c = 0;		try {			f->seek(offset->value);			f->readx(buf, l);		} catch (const IOException&) {			free(buf);			set_eval_error("i/o error (couldn't read %d bytes from ofs %d (0x%qx))", l, c, offset->value, offset->value);			return 0;		}		s.value = (char*)buf;		s.len = l;		scalar_create_str(result, &s);		free(buf);		return 1;	}	set_eval_error("out of memory");	return 0;}static bool blockop_func_eval(eval_scalar *result, char *name, eval_scalarlist *params){	/* FIXME: non-constant funcs (e.g. rand()) should	   set blockop_expr_is_const to false */	eval_func myfuncs[] = {		{"i", 0, {SCALAR_INT}, "iteration index"},		{"o", 0, {SCALAR_INT}, "current offset"},		{"readbyte", (void*)&func_readbyte, {SCALAR_INT}, "read byte from offset"},		{"read16le", (void*)&func_read16le, {SCALAR_INT}, "read little endian 16 bit word from offset"},		{"read32le", (void*)&func_read32le, {SCALAR_INT}, "read little endian 32 bit word from offset"},		{"read64le", (void*)&func_read64le, {SCALAR_INT}, "read little endian 64 bit word from offset"},		{"read16be", (void*)&func_read16be, {SCALAR_INT}, "read big endian 16 bit word from offset"},		{"read32be", (void*)&func_read32be, {SCALAR_INT}, "read big endian 32 bit word from offset"},		{"read64be", (void*)&func_read64be, {SCALAR_INT}, "read big endian 64 bit word from offset"},		{"readstring", (void*)&func_readstring, {SCALAR_INT, SCALAR_INT}, "read string (offset, length)"},		{NULL}	};		blockop_expr_is_const = false;			return std_eval_func_handler(result, name, params, myfuncs);}/* *	BLOCKOP STRING */class ht_blockop_str_context: public Object {public:	File *file;	FileOfs ofs;	uint len;	uint size;	bool netendian;	char *action;	uint i;	FileOfs o;	bool expr_const;	eval_str v;	~ht_blockop_str_context()	{

⌨️ 快捷键说明

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