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

📄 httag.cc

📁 功能较全面的反汇编器:反汇编器ht-2.0.15.tar.gz
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* *	HT Editor *	httag.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 "htdebug.h"#include "strtools.h"#include "httag.h"#include "tools.h"#include <stdarg.h>#include <stdlib.h>#include <string.h>/**/// these 3 functions are evil. but they are only used in statictag_to_tag().// they should go sometime...static uint32 hexb(const char *s){	byte b=*(byte*)s;	b -= '0';	if (b > 9) b -= 'a'-'0'-10;	byte c = *(byte*)(s+1);	c -= '0';	if (c > 9) c -= 'a'-'0'-10;	return (b << 4) + c;}static uint32 hexw(const char *s){	return (hexb(s)<<8) | hexb(s+2);}static uint32 hexd(const char *s){	return (hexw(s)<<16) | hexw(s+4);}//static TAGSTRING *tag_error(TAGSTRING *buf, int maxlen){	while (maxlen-- > 0) {		*buf++ = 0;	}	return buf;}TAGSTRING *tag_make_sel(TAGSTRING *buf, int maxlen, const char *string){	return tag_make_ref(buf, maxlen, 0, 0, 0, 0, string);}TAGSTRING *tag_make_ref_len(TAGSTRING *buf, int maxlen, uint32 id128_1, uint32 id128_2, uint32 id128_3, uint32 id128_4, const char *string, int strlen){	if (maxlen <= (signed)sizeof (ht_tag_sel)) return tag_error(buf, maxlen);	if (maxlen <= (signed)sizeof (ht_tag_sel)+strlen) {		strlen = maxlen - sizeof (ht_tag_sel) - 1;	}	ht_tag_sel *tag=(ht_tag_sel*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_SEL;	UNALIGNED_MOVE(tag->id128_1, id128_1);	UNALIGNED_MOVE(tag->id128_2, id128_2);	UNALIGNED_MOVE(tag->id128_3, id128_3);	UNALIGNED_MOVE(tag->id128_4, id128_4);	UNALIGNED_MOVE(tag->strlen, strlen);	memcpy(buf+sizeof (ht_tag_sel), string, strlen);	return buf+sizeof (ht_tag_sel)+strlen;}TAGSTRING *tag_make_ref(TAGSTRING *buf, int maxlen, uint32 id128_1, uint32 id128_2, uint32 id128_3, uint32 id128_4, const char *string){	return tag_make_ref_len(buf, maxlen, id128_1, id128_2, id128_3, id128_4, string, strlen(string));}TAGSTRING *tag_make_flags(TAGSTRING *buf, int maxlen, uint32 id, FileOfs ofs){	if (maxlen <= (signed)sizeof (ht_tag_flags)) return tag_error(buf, maxlen);	ht_tag_flags *tag = (ht_tag_flags*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_FLAGS;	UNALIGNED_MOVE(tag->offset, ofs);	UNALIGNED_MOVE(tag->id, id);	return buf + sizeof (ht_tag_flags);}TAGSTRING *tag_make_group(TAGSTRING *buf, int maxlen){	if (maxlen <= (signed)sizeof (ht_tag_group)) return tag_error(buf, maxlen);	ht_tag_group *tag = (ht_tag_group*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_GROUP;	return buf + sizeof (ht_tag_group);}TAGSTRING *tag_make_color(TAGSTRING *buf, int maxlen, uint32 color){	if (maxlen <= (signed)sizeof (ht_tag_color)) return tag_error(buf, maxlen);	ht_tag_color *tag = (ht_tag_color*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_COLOR;	UNALIGNED_MOVE(tag->color, color);	return buf + sizeof (ht_tag_color);}TAGSTRING *tag_make_default_color(TAGSTRING *buf, int maxlen){	if (maxlen <= (signed)sizeof (ht_tag_color)) return tag_error(buf, maxlen);	ht_tag_color *tag = (ht_tag_color*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_COLOR;	UNALIGNED_MOVE_CONST(tag->color, 0xffffffff, uint32);	return buf + sizeof (ht_tag_color);}TAGSTRING *tag_make_edit_byte(TAGSTRING *buf, int maxlen, FileOfs ofs){	if (maxlen <= (signed)sizeof (ht_tag_edit_byte)) return tag_error(buf, maxlen);	ht_tag_edit_byte *tag = (ht_tag_edit_byte*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_EDIT_BYTE;	UNALIGNED_MOVE(tag->offset, ofs);	return buf + sizeof (ht_tag_edit_byte);}TAGSTRING *tag_make_edit_word(TAGSTRING *buf, int maxlen, FileOfs ofs, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_edit_word_generic)) return tag_error(buf, maxlen);	ht_tag_edit_word_generic *tag = (ht_tag_edit_word_generic*)buf;	tag->escape = '\e';	byte m = 0xff;	switch (e) {	case tag_endian_big:		m = HT_TAG_EDIT_WORD_BE;		break;	case tag_endian_little:		m = HT_TAG_EDIT_WORD_LE;		break;	case tag_endian_var:		m = HT_TAG_EDIT_WORD_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs);	return buf + sizeof (ht_tag_edit_word_generic);}TAGSTRING *tag_make_edit_dword(TAGSTRING *buf, int maxlen, FileOfs ofs, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_edit_dword_generic)) return tag_error(buf, maxlen);	ht_tag_edit_dword_generic *tag = (ht_tag_edit_dword_generic*)buf;	tag->escape = '\e';	byte m = 0xff;	switch (e) {	case tag_endian_big:		m = HT_TAG_EDIT_DWORD_BE;		break;	case tag_endian_little:		m = HT_TAG_EDIT_DWORD_LE;		break;	case tag_endian_var:		m = HT_TAG_EDIT_DWORD_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs);	return buf + sizeof (ht_tag_edit_dword_generic);}TAGSTRING *tag_make_edit_qword(TAGSTRING *buf, int maxlen, FileOfs ofs, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_edit_qword_generic)) return tag_error(buf, maxlen);	ht_tag_edit_qword_generic *tag = (ht_tag_edit_qword_generic*)buf;	tag->escape = '\e';	byte m = 0xff;	switch (e) {	case tag_endian_big:		m = HT_TAG_EDIT_QWORD_BE;		break;	case tag_endian_little:		m = HT_TAG_EDIT_QWORD_LE;		break;	case tag_endian_var:		m = HT_TAG_EDIT_QWORD_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs);	return buf + sizeof (ht_tag_edit_qword_generic);}TAGSTRING *tag_make_edit_time(TAGSTRING *buf, int maxlen, FileOfs ofs, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_edit_time)) return tag_error(buf, maxlen);	ht_tag_edit_time *tag = (ht_tag_edit_time*)buf;	tag->escape = '\e';	byte m = 0xff;		switch (e) {	case tag_endian_big:		m = HT_TAG_EDIT_TIME_BE;		break;	case tag_endian_little:		m = HT_TAG_EDIT_TIME_LE;		break;	case tag_endian_var:		m = HT_TAG_EDIT_TIME_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs);	return buf + sizeof (ht_tag_edit_time);}TAGSTRING *tag_make_edit_char(TAGSTRING *buf, int maxlen, FileOfs ofs){	if (maxlen <= (signed)sizeof (ht_tag_edit_char)) return tag_error(buf, maxlen);	ht_tag_edit_char *tag = (ht_tag_edit_char*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_EDIT_CHAR;	UNALIGNED_MOVE(tag->offset, ofs);	return buf + sizeof (ht_tag_edit_char);}TAGSTRING *tag_make_edit_bit(TAGSTRING *buf, int maxlen, FileOfs ofs, int bitidx){	if (maxlen <= (signed)sizeof (ht_tag_edit_bit)) return tag_error(buf, maxlen);	ht_tag_edit_bit *tag = (ht_tag_edit_bit*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_EDIT_BIT;	UNALIGNED_MOVE(tag->offset, ofs);	UNALIGNED_MOVE(tag->bitidx, bitidx);	return buf+sizeof (ht_tag_edit_bit);}TAGSTRING *tag_make_edit_selvis(TAGSTRING *buf, int maxlen, FileOfs offset, char ch){	if (maxlen <= (signed)sizeof (ht_tag_edit_selvis)) return tag_error(buf, maxlen);	ht_tag_edit_selvis *tag=(ht_tag_edit_selvis*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_EDIT_SELVIS;	UNALIGNED_MOVE(tag->offset, offset);	tag->ch = ch;	return buf + sizeof (ht_tag_edit_selvis);}TAGSTRING *tag_make_desc_byte(TAGSTRING *buf, int maxlen, FileOfs ofs32, uint32 id32){	if (maxlen <= (signed)sizeof (ht_tag_desc_byte)) return tag_error(buf, maxlen);	ht_tag_desc_byte *tag = (ht_tag_desc_byte*)buf;	tag->escape = '\e';	tag->magic = HT_TAG_DESC_BYTE;	UNALIGNED_MOVE(tag->offset, ofs32);	UNALIGNED_MOVE(tag->id, id32);	return buf + sizeof (ht_tag_desc_byte);}TAGSTRING *tag_make_desc_word(TAGSTRING *buf, int maxlen, FileOfs ofs32, uint32 id32, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_desc_word_generic)) return tag_error(buf, maxlen);	ht_tag_desc_word_generic *tag = (ht_tag_desc_word_generic*)buf;	tag->escape = '\e';	byte m = 0xff;	switch (e) {	case tag_endian_big:		m = HT_TAG_DESC_WORD_BE;		break;	case tag_endian_little:		m = HT_TAG_DESC_WORD_LE;		break;	case tag_endian_var:		m = HT_TAG_DESC_WORD_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs32);	UNALIGNED_MOVE(tag->id, id32);	return buf + sizeof (ht_tag_desc_word_generic);}TAGSTRING *tag_make_desc_dword(TAGSTRING *buf, int maxlen, FileOfs ofs32, uint32 id32, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_desc_dword_generic)) return tag_error(buf, maxlen);	ht_tag_desc_dword_generic *tag = (ht_tag_desc_dword_generic*)buf;	tag->escape = '\e';	byte m = 0xff;	switch (e) {	case tag_endian_big:		m = HT_TAG_DESC_DWORD_BE;		break;	case tag_endian_little:		m = HT_TAG_DESC_DWORD_LE;		break;	case tag_endian_var:		m = HT_TAG_DESC_DWORD_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs32);	UNALIGNED_MOVE(tag->id, id32);	return buf + sizeof (ht_tag_desc_dword_generic);}TAGSTRING *tag_make_desc_qword(TAGSTRING *buf, int maxlen, FileOfs ofs32, uint32 id32, tag_endian e){	if (maxlen <= (signed)sizeof (ht_tag_desc_qword_generic)) return tag_error(buf, maxlen);	ht_tag_desc_qword_generic *tag = (ht_tag_desc_qword_generic*)buf;	tag->escape = '\e';	byte m = 0xff;	switch (e) {	case tag_endian_big:		m = HT_TAG_DESC_QWORD_BE;		break;	case tag_endian_little:		m = HT_TAG_DESC_QWORD_LE;		break;	case tag_endian_var:		m = HT_TAG_DESC_QWORD_VE;		break;	}	tag->magic = m;	UNALIGNED_MOVE(tag->offset, ofs32);	UNALIGNED_MOVE(tag->id, id32);	return buf + sizeof (ht_tag_desc_qword_generic);}/**/void statictag_to_tag(const char *statictag_str, TAGSTRING *tag_str, int maxlen, uint64 relocation, bool std_bigendian){	if (maxlen < 1) return;	if (maxlen == 1) {		*tag_str = 0;		return;	}	FileOfs ofs = 0;	ID id;	TAGSTRING *tag_str_end = tag_str + maxlen - 1; 	while (*statictag_str) {		if (*statictag_str == '\e') {			switch ((byte)*(statictag_str+1)) {			case HT_STATICTAG_EDIT_BYTE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_byte(tag_str, tag_str_end-tag_str, ofs+relocation);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_WORD_LE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_word(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_DWORD_LE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_dword(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_QWORD_LE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_qword(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_WORD_BE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_word(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_big);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_DWORD_BE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_dword(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_big);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_QWORD_BE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_qword(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_big);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_WORD_VE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_word(tag_str, tag_str_end-tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_DWORD_VE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_dword(tag_str, tag_str_end-tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_QWORD_VE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_qword(tag_str, tag_str_end-tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_TIME_LE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_time(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_TIME_BE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_time(tag_str, tag_str_end-tag_str, ofs+relocation, tag_endian_big);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_TIME_VE:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_time(tag_str, tag_str_end-tag_str, ofs+relocation, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_CHAR:				ofs = hexd(statictag_str+2);				tag_str = tag_make_edit_char(tag_str, tag_str_end-tag_str, ofs+relocation);				statictag_str += 2+8;				break;			case HT_STATICTAG_EDIT_BIT: {				ofs = hexd(statictag_str+2);				int bitidx = hexb(statictag_str+2+8);				tag_str = tag_make_edit_bit(tag_str, tag_str_end-tag_str, ofs+relocation, bitidx);				statictag_str += 2+8+2;				break;			}			case HT_STATICTAG_EDIT_SELVIS: {				ofs = hexd(statictag_str+2);				char ch = hexb(statictag_str+2+8);				tag_str = tag_make_edit_selvis(tag_str, tag_str_end-tag_str, ofs+relocation, ch);				statictag_str += 2+8+2;				break;			}			case HT_STATICTAG_DESC_BYTE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_byte(tag_str, tag_str_end-tag_str, ofs+relocation, id);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_WORD_LE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_word(tag_str, tag_str_end-tag_str, ofs+relocation, id, tag_endian_little);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_DWORD_LE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_dword(tag_str, tag_str_end-tag_str, ofs+relocation, id, tag_endian_little);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_QWORD_LE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_qword(tag_str, tag_str_end-tag_str, ofs+relocation, id, tag_endian_little);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_WORD_BE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_word(tag_str, tag_str_end-tag_str, ofs+relocation, id, tag_endian_big);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_DWORD_BE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_dword(tag_str, tag_str_end-tag_str, ofs+relocation, id, tag_endian_big);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_QWORD_BE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_qword(tag_str, tag_str_end-tag_str, ofs+relocation, id, tag_endian_big);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_WORD_VE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_word(tag_str, tag_str_end-tag_str, ofs+relocation, id, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_DWORD_VE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_dword(tag_str, tag_str_end-tag_str, ofs+relocation, id, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_DESC_QWORD_VE:				ofs = hexd(statictag_str+2);				id = hexd(statictag_str+2+8);				tag_str = tag_make_desc_qword(tag_str, tag_str_end-tag_str, ofs+relocation, id, std_bigendian ? tag_endian_big : tag_endian_little);				statictag_str += 2+8+8;				break;			case HT_STATICTAG_SEL: {				uint32 id_1 = hexd(statictag_str+2);				uint32 id_2 = hexd(statictag_str+2+8);				uint32 id_3 = hexd(statictag_str+2+16);				uint32 id_4 = hexd(statictag_str+2+24);				byte len = hexb(statictag_str+2+8+8+8+8);				tag_str = tag_make_ref_len(tag_str, tag_str_end-tag_str, id_1, id_2, id_3, id_4, statictag_str+2+8+8+8+8+2, len);

⌨️ 快捷键说明

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