Ejemplo n.º 1
0
static URI_INLINE int URI_FUNC(UriStringToFilename)(const URI_CHAR * uriString,
		URI_CHAR * filename, UriBool toUnix) {
	const URI_CHAR * const prefix = toUnix ? _UT("file://") : _UT("file:///");
	const int prefixLen = toUnix ? 7 : 8;
	URI_CHAR * walker = filename;
	size_t charsToCopy;
	const UriBool absolute = (URI_STRNCMP(uriString, prefix, prefixLen) == 0);
	const int charsToSkip = (absolute ? prefixLen : 0);

	charsToCopy = URI_STRLEN(uriString + charsToSkip) + 1;
	memcpy(filename, uriString + charsToSkip, charsToCopy * sizeof(URI_CHAR));
	URI_FUNC(UnescapeInPlaceEx)(filename, URI_FALSE, URI_BR_DONT_TOUCH);

	/* Convert forward slashes to backslashes */
	if (!toUnix) {
		while (walker[0] != _UT('\0')) {
			if (walker[0] == _UT('/')) {
				walker[0] = _UT('\\');
			}
			walker++;
		}
	}

	return URI_SUCCESS;
}
Ejemplo n.º 2
0
static void dbg_dump_sf_prefixes(struct STREAM *stream, uint8_t *sf_prefixes, int sf_prefixes_len)
{
	int i;

	if (!sf_prefixes)
	{
		safe_unistrncpy(stream, _UT("unknown"));
	}
	else
	{
		if (!sf_prefixes_len)
			safe_unistrncpy(stream, _UT("none"));
		else
		{
            for(i = 0; i < sf_prefixes_len; i++)
			{
				itoa(stream, sf_prefixes[i], 0x1, 0x0, 0x10);
				safe_unistrncpy(stream, _UT(", "));
			}
		}
	}

    stream ->bufflen += 2;
	stream ->buff -= 2;
	stream ->reallen -= 2;
}
Ejemplo n.º 3
0
static void dbg_dump_flags(struct STREAM *stream, struct INSTRUCTION *instr)
{
	if (!instr ->flags)
		safe_unistrncpy(stream, _UT("none"));
	else
	{
		if (instr ->flags & INSTR_FLAG_MODRM)
		{
			safe_unistrncpy(stream, _UT("MODRM ("));
			itoa(stream, instr ->modrm, 0x1, 0x0, 0x10);
			safe_unistrncpy(stream, _UT("), "));
		}
		if (instr ->flags & INSTR_FLAG_SIB)
		{
			safe_unistrncpy(stream, _UT("SIB ("));
			itoa(stream, instr ->sib, 0x1, 0x0, 0x10);
			safe_unistrncpy(stream, _UT("), "));
		}
		if (instr ->flags & INSTR_FLAG_SF_PREFIXES)
			safe_unistrncpy(stream, _UT("SF_PREFIXES, "));
        if (instr ->flags & INSTR_FLAG_IOPL)
            safe_unistrncpy(stream, _UT("IOPL, "));
        if (instr ->flags & INSTR_FLAG_RING0)
            safe_unistrncpy(stream, _UT("RING0, "));
        if (instr ->flags & INSTR_FLAG_SERIAL)
            safe_unistrncpy(stream, _UT("SERIAL, "));
        if (instr ->flags & INSTR_FLAG_UNDOC)
            safe_unistrncpy(stream, _UT("UNDOC, "));

		stream ->bufflen += 2;
		stream ->buff -= 2;
		stream ->reallen -= 2;
	}
}
Ejemplo n.º 4
0
static URI_INLINE int URI_FUNC(UriStringToFilename)(const URI_CHAR * uriString,
		URI_CHAR * filename, UriBool toUnix) {
	if ((uriString == NULL) || (filename == NULL)) {
		return URI_ERROR_NULL;
	}

	{
		const UriBool file_two_slashes =
				URI_STRNCMP(uriString, _UT("file://"), URI_STRLEN(_UT("file://"))) == 0;
		const UriBool file_three_slashes = file_two_slashes
				&& (URI_STRNCMP(uriString, _UT("file:///"), URI_STRLEN(_UT("file:///"))) == 0);

		const size_t charsToSkip = file_two_slashes
				? file_three_slashes
					? toUnix
						/* file:///bin/bash */
						? URI_STRLEN(_UT("file://"))
						/* file:///E:/Documents%20and%20Settings */
						: URI_STRLEN(_UT("file:///"))
					/* file://Server01/Letter.txt */
					: URI_STRLEN(_UT("file://"))
				: 0;
		const size_t charsToCopy = URI_STRLEN(uriString + charsToSkip) + 1;

		const UriBool is_windows_network_with_authority =
				(toUnix == URI_FALSE)
				&& file_two_slashes
				&& ! file_three_slashes;

		URI_CHAR * const unescape_target = is_windows_network_with_authority
				? (filename + 2)
				: filename;

		if (is_windows_network_with_authority) {
			filename[0] = '\\';
			filename[1] = '\\';
		}

		memcpy(unescape_target, uriString + charsToSkip, charsToCopy * sizeof(URI_CHAR));
		URI_FUNC(UnescapeInPlaceEx)(filename, URI_FALSE, URI_BR_DONT_TOUCH);
	}

	/* Convert forward slashes to backslashes */
	if (!toUnix) {
		URI_CHAR * walker = filename;
		while (walker[0] != _UT('\0')) {
			if (walker[0] == _UT('/')) {
				walker[0] = _UT('\\');
			}
			walker++;
		}
	}

	return URI_SUCCESS;
}
Ejemplo n.º 5
0
static void dbg_dump_eflags(struct STREAM *stream, uint8_t flags)
{
	if (!flags)
		safe_unistrncpy(stream, _UT("none"));
	else
	{
		if (flags & EFLAG_O)
			safe_unistrncpy(stream, _UT("OF, "));
		if (flags & EFLAG_D)
			safe_unistrncpy(stream, _UT("DF, "));
		if (flags & EFLAG_I)
			safe_unistrncpy(stream, _UT("IF, "));
		if (flags & EFLAG_S)
			safe_unistrncpy(stream, _UT("SF, "));
		if (flags & EFLAG_Z)
			safe_unistrncpy(stream, _UT("ZF, "));
		if (flags & EFLAG_A)
			safe_unistrncpy(stream, _UT("AF, "));
		if (flags & EFLAG_P)
			safe_unistrncpy(stream, _UT("PF, "));
		if (flags & EFLAG_C)
			safe_unistrncpy(stream, _UT("CF, "));

		stream ->bufflen += 2;
		stream ->buff -= 2;
		stream ->reallen -= 2;
	}
}
Ejemplo n.º 6
0
static int internal_dump_prefixes(struct STREAM *stream, struct INSTRUCTION *instr)
{
	if (instr ->prefixes & INSTR_PREFIX_LOCK)
		safe_unistrncpy(stream, _UT("lock "));
	if (instr ->prefixes & INSTR_PREFIX_REPZ)
		safe_unistrncpy(stream, _UT("repz "));
	if (instr ->prefixes & INSTR_PREFIX_REPNZ)
		safe_unistrncpy(stream, _UT("repnz "));

	return stream ->reallen;
}
Ejemplo n.º 7
0
int medi_dump(struct INSTRUCTION *instr, unichar_t *buff, int bufflen, int options)
{
	struct STREAM stream;

	stream.buff = buff;
	stream.bufflen = bufflen;
	stream.options = options;
	stream.reallen = 0;

	internal_dump_prefixes(&stream, instr);
	internal_dump_mnemonic(&stream, instr);

	if (instr ->ops[0].flags & OPERAND_FLAG_PRESENT)
	{
		unsigned int i;

		safe_copy_unichar(&stream, ' ');
		for (i = 0; i < 3; i++)
		{
			if (instr ->ops[i].flags & OPERAND_FLAG_PRESENT)
			{
				internal_dump_operand(&stream, instr, i);
				safe_unistrncpy(&stream, _UT(", "));
			}
		}
		stream.reallen -= 2;
		stream.bufflen += 2;
		stream.buff += 2;
	}

	return stream.reallen;
}
Ejemplo n.º 8
0
static int internal_dump_operand(struct STREAM *stream, struct INSTRUCTION *instr, int op_index)
{
	struct OPERAND *op;

	if (op_index > 3 || op_index < 0)
		return -1;

	op = instr ->ops + op_index;
	if (op ->flags & OPERAND_FLAG_PRESENT)
	{
        switch (op ->flags & OPERAND_TYPE_MASK)
		{
		case OPERAND_TYPE_REG:
			dump_reg(stream, op ->value.reg.type, op ->value.reg.code, op ->size);
			break;
		case OPERAND_TYPE_MEM:
			dump_addr(stream, instr, op);
			break;
		case OPERAND_TYPE_IMM:
			dump_imm(stream, op);
			break;
		case OPERAND_TYPE_DIR:
			dump_dir(stream, op);
			break;
		default:
			safe_unistrncpy(stream, _UT("internal error"));
			break;
		}
	}

	return stream ->reallen;
}
Ejemplo n.º 9
0
static void dump_reg(struct STREAM *stream, uint8_t type, uint8_t code, uint16_t size)
{
	switch(type)
	{
	case REG_TYPE_GEN:
		dump_reg_gen(stream, code, size);
		break;
	case REG_TYPE_SEG:
		dump_reg_sreg(stream, code);
		break;
	case REG_TYPE_FPU:
		dump_reg_freg(stream, code);
		break;
	case REG_TYPE_CR:
		dump_reg_creg(stream, code);
		break;
	case REG_TYPE_DBG:
		dump_reg_dreg(stream, code);
		break;
	case REG_TYPE_TR:
		dump_reg_treg(stream, code);
		break;
	case REG_TYPE_MMX:
		dump_reg_mreg(stream, code);
		break;
	case REG_TYPE_XMM:
		dump_reg_xreg(stream, code);
		break;
	default:
		safe_unistrncpy(stream, _UT("internal error"));
		break;
	}
}
Ejemplo n.º 10
0
/*
 * [ipFourAddress]->[decOctet]<.>[decOctet]<.>[decOctet]<.>[decOctet]
 */
int URI_FUNC(ParseIpFourAddress)(unsigned char * octetOutput,
		const URI_CHAR * first, const URI_CHAR * afterLast) {
	const URI_CHAR * after;
	UriIp4Parser parser;

	/* Essential checks */
	if ((octetOutput == NULL) || (first == NULL)
			|| (afterLast <= first)) {
		return URI_ERROR_SYNTAX;
	}

	/* Reset parser */
	parser.stackCount = 0;

	/* Octet #1 */
	after = URI_FUNC(ParseDecOctet)(&parser, first, afterLast);
	if ((after == NULL) || (after >= afterLast) || (*after != _UT('.'))) {
		return URI_ERROR_SYNTAX;
	}
	uriStackToOctet(&parser, octetOutput);

	/* Octet #2 */
	after = URI_FUNC(ParseDecOctet)(&parser, after + 1, afterLast);
	if ((after == NULL) || (after >= afterLast) || (*after != _UT('.'))) {
		return URI_ERROR_SYNTAX;
	}
	uriStackToOctet(&parser, octetOutput + 1);

	/* Octet #3 */
	after = URI_FUNC(ParseDecOctet)(&parser, after + 1, afterLast);
	if ((after == NULL) || (after >= afterLast) || (*after != _UT('.'))) {
		return URI_ERROR_SYNTAX;
	}
	uriStackToOctet(&parser, octetOutput + 2);

	/* Octet #4 */
	after = URI_FUNC(ParseDecOctet)(&parser, after + 1, afterLast);
	if (after != afterLast) {
		return URI_ERROR_SYNTAX;
	}
	uriStackToOctet(&parser, octetOutput + 3);

	return URI_SUCCESS;
}
Ejemplo n.º 11
0
static int __cdecl dprintf(int flags, LPCTSTR pszFormat, ...) 
{ 
   if (!(DebugFlags & flags))
       return 0;

   va_list va;
   va_start(va, pszFormat);
   int cch = bvprintf(g_bprint, pszFormat, va);
   va_end(va);

   // if this string ended in \n, flush the bprint buffer.
   if (g_bprint.cch > 0 && g_bprint.psz[g_bprint.cch-1] == _UT('\n'))
       bprint_Write();

   return cch;
}
Ejemplo n.º 12
0
static void dump_dir(struct STREAM *stream, struct OPERAND *op)
{
	switch (op ->size)
	{
	case OPERAND_SIZE_32:
		itoa(stream, op ->value.far_addr.far_addr32.seg, 0x2, 0x0, 0x10);
		safe_copy_unichar(stream, ':');
		itoa(stream, op ->value.far_addr.far_addr32.offset, 0x2, 0x0, 0x10);
		break;
	case OPERAND_SIZE_48:
		itoa(stream, op ->value.far_addr.far_addr48.seg, 0x2, 0x0, 0x10);
		safe_copy_unichar(stream, ':');
		itoa(stream, op ->value.far_addr.far_addr48.offset, 0x4, 0x0, 0x10);
		break;
	default:
		safe_unistrncpy(stream, _UT("internal error"));
		break;
	}
}
Ejemplo n.º 13
0
static void itoa(struct STREAM *stream, uint64_t num, uint16_t size, int is_signed, int radix)
{
	char dig;
	uint64_t div;
	uint64_t tmp;

	div = 1;
	if (is_signed)
	{
		uint8_t *ptr = (uint8_t *)&num;
		ptr += size - 1;
		if (*ptr & 0x80)
		{
			safe_copy_unichar(stream, '-');
			num = ~num; //Just to shut up warning.
			num++;
		}
	}

	tmp = 0xFFFFFFFFFFFFFFFFL;
	for(size = 8 - size + 1; size; size--)
	{
		num &= tmp;
		tmp >>= 0x8;
	}

	if (radix == 0x10)
		safe_unistrncpy(stream, _UT("0x"));

	while(num / div >= radix)
		div *= radix;
	while(div)
	{
		dig = (uint8_t)((num / div) % radix);
		if (dig >= 10)
			dig += 'A' - 10;
		else
			dig += '0';
		safe_copy_unichar(stream, dig);
		div /= radix;
	}
}
Ejemplo n.º 14
0
/*
 * [decOctetFour]-><NULL>
 * [decOctetFour]-><0>
 * [decOctetFour]-><1>
 * [decOctetFour]-><2>
 * [decOctetFour]-><3>
 * [decOctetFour]-><4>
 * [decOctetFour]-><5>
 */
static URI_INLINE const URI_CHAR * URI_FUNC(ParseDecOctetFour)(UriIp4Parser * parser,
		const URI_CHAR * first, const URI_CHAR * afterLast) {
	if (first >= afterLast) {
		return afterLast;
	}

	switch (*first) {
	case _UT('0'):
	case _UT('1'):
	case _UT('2'):
	case _UT('3'):
	case _UT('4'):
	case _UT('5'):
		uriPushToStack(parser, (unsigned char)(9 + *first - _UT('9')));
		return first + 1;

	default:
		return first;
	}
}
Ejemplo n.º 15
0
#include <stdio.h>
#include "mediana.h"

struct STREAM
{
	unichar_t *buff;
	int bufflen;
	unsigned int reallen;
	unsigned int options;
};

#if defined(MEDIANA_CTRL_DUMP) || defined(MEDIANA_CTRL_DBG_DUMP)

unichar_t *regs8[] = 
{
	_UT("al"), _UT("cl"), _UT("dl"), _UT("bl"), _UT("ah"), _UT("ch"), _UT("dh"), _UT("bh"),
	_UT("r8b"), _UT("r9b"), _UT("r10b"), _UT("r11b"), _UT("r12b"), _UT("r13b"), _UT("r14b"), _UT("r15b"),
	_UT("spl"), _UT("bpl"), _UT("sil"), _UT("dil"), _UT("badreg8")
};

unichar_t *regs16[] = 
{
	_UT("ax"), _UT("cx"), _UT("dx"), _UT("bx"), _UT("sp"), _UT("bp"), _UT("si"), _UT("di"),
	_UT("r8w"), _UT("r9w"), _UT("r10w"), _UT("r11w"), _UT("r12w"), _UT("r13w"), _UT("r14w"), _UT("r15w"),
	_UT("badreg16_1"), _UT("badreg16_2"), _UT("badreg16_3"), _UT("badreg16_4"), _UT("badreg16_5"),
};

unichar_t *regs32[] = 
{
	_UT("eax"), _UT("ecx"), _UT("edx"), _UT("ebx"), _UT("esp"), _UT("ebp"), _UT("esi"), _UT("edi"),
	_UT("r8d"), _UT("r9d"), _UT("r10d"), _UT("r11d"), _UT("r12d"), _UT("r13d"), _UT("r14d"), _UT("r15d"),
Ejemplo n.º 16
0
/*
 * [decOctet]-><0>
 * [decOctet]-><1>[decOctetOne]
 * [decOctet]-><2>[decOctetTwo]
 * [decOctet]-><3>[decOctetThree]
 * [decOctet]-><4>[decOctetThree]
 * [decOctet]-><5>[decOctetThree]
 * [decOctet]-><6>[decOctetThree]
 * [decOctet]-><7>[decOctetThree]
 * [decOctet]-><8>[decOctetThree]
 * [decOctet]-><9>[decOctetThree]
 */
static URI_INLINE const URI_CHAR * URI_FUNC(ParseDecOctet)(UriIp4Parser * parser,
		const URI_CHAR * first, const URI_CHAR * afterLast) {
	if (first >= afterLast) {
		return NULL;
	}

	switch (*first) {
	case _UT('0'):
		uriPushToStack(parser, 0);
		return first + 1;

	case _UT('1'):
		uriPushToStack(parser, 1);
		return (const URI_CHAR *)URI_FUNC(ParseDecOctetOne)(parser, first + 1, afterLast);

	case _UT('2'):
		uriPushToStack(parser, 2);
		return (const URI_CHAR *)URI_FUNC(ParseDecOctetTwo)(parser, first + 1, afterLast);

	case _UT('3'):
	case _UT('4'):
	case _UT('5'):
	case _UT('6'):
	case _UT('7'):
	case _UT('8'):
	case _UT('9'):
		uriPushToStack(parser, (unsigned char)(9 + *first - _UT('9')));
		return (const URI_CHAR *)URI_FUNC(ParseDecOctetThree)(parser, first + 1, afterLast);

	default:
		return NULL;
	}
}
Ejemplo n.º 17
0
static URI_INLINE int URI_FUNC(FilenameToUriString)(const URI_CHAR * filename,
		URI_CHAR * uriString, UriBool fromUnix) {
	const URI_CHAR * input = filename;
	const URI_CHAR * lastSep = input - 1;
	UriBool firstSegment = URI_TRUE;
	URI_CHAR * output = uriString;
	UriBool absolute;
	UriBool is_windows_network;

	if ((filename == NULL) || (uriString == NULL)) {
		return URI_ERROR_NULL;
	}

	is_windows_network = (filename[0] == _UT('\\')) && (filename[1] == _UT('\\'));
	absolute = fromUnix
			? (filename[0] == _UT('/'))
			: ((filename[0] != _UT('\0')) && (filename[1] == _UT(':'))
				|| is_windows_network);

	if (absolute) {
		const URI_CHAR * const prefix = fromUnix
				? _UT("file://")
				: is_windows_network
					? _UT("file:")
					: _UT("file:///");
		const int prefixLen = URI_STRLEN(prefix);

		/* Copy prefix */
		memcpy(uriString, prefix, prefixLen * sizeof(URI_CHAR));
		output += prefixLen;
	}

	/* Copy and escape on the fly */
	for (;;) {
		if ((input[0] == _UT('\0'))
				|| (fromUnix && input[0] == _UT('/'))
				|| (!fromUnix && input[0] == _UT('\\'))) {
			/* Copy text after last seperator */
			if (lastSep + 1 < input) {
				if (!fromUnix && absolute && (firstSegment == URI_TRUE)) {
					/* Quick hack to not convert "C:" to "C%3A" */
					const int charsToCopy = (int)(input - (lastSep + 1));
					memcpy(output, lastSep + 1, charsToCopy * sizeof(URI_CHAR));
					output += charsToCopy;
				} else {
					output = URI_FUNC(EscapeEx)(lastSep + 1, input, output,
							URI_FALSE, URI_FALSE);
				}
			}
			firstSegment = URI_FALSE;
		}

		if (input[0] == _UT('\0')) {
			output[0] = _UT('\0');
			break;
		} else if (fromUnix && (input[0] == _UT('/'))) {
			/* Copy separators unmodified */
			output[0] = _UT('/');
			output++;
			lastSep = input;
		} else if (!fromUnix && (input[0] == _UT('\\'))) {
			/* Convert backslashes to forward slashes */
			output[0] = _UT('/');
			output++;
			lastSep = input;
		}
		input++;
	}

	return URI_SUCCESS;
}
Ejemplo n.º 18
0
static void dump_ptr_size(struct STREAM *stream, struct OPERAND *op)
{
	switch(op ->size)
	{
	case OPERAND_SIZE_8:
		safe_unistrncpy(stream, _UT("byte ptr"));
		break;
	case OPERAND_SIZE_16:
		safe_unistrncpy(stream, _UT("word ptr"));
		break;
	case OPERAND_SIZE_32:
		safe_unistrncpy(stream, _UT("dword ptr"));
		break;
	case OPERAND_SIZE_48:
		safe_unistrncpy(stream, _UT("fword ptr"));
		break;
	case OPERAND_SIZE_64:
		safe_unistrncpy(stream, _UT("qword ptr"));
		break;
	case OPERAND_SIZE_80:
		safe_unistrncpy(stream, _UT("tbyte ptr"));
		break;
	case OPERAND_SIZE_128:
		safe_unistrncpy(stream, _UT("dqword ptr"));
		break;
	case OPERAND_SIZE_14:
		safe_unistrncpy(stream, _UT("14bytes ptr"));
		break;
	case OPERAND_SIZE_28:
		safe_unistrncpy(stream, _UT("28bytes ptr"));
		break;
	case OPERAND_SIZE_94:
		safe_unistrncpy(stream, _UT("94bytes ptr"));
		break;
	case OPERAND_SIZE_108:
		safe_unistrncpy(stream, _UT("108bytes ptr"));
		break;
	case OPERAND_SIZE_512:
		safe_unistrncpy(stream, _UT("512bytes ptr"));
		break;
	default:
		safe_unistrncpy(stream, _UT("strange ptr"));
		break;
	}
}
Ejemplo n.º 19
0
#  include <uriparser/UriDefsAnsi.h>
# else
#  include <uriparser/UriDefsUnicode.h>
#  include <wchar.h>
# endif



#ifndef URI_DOXYGEN
# include <uriparser/Uri.h>
# include "UriCommon.h"
#endif



/*extern*/ const URI_CHAR * const URI_FUNC(SafeToPointTo) = _UT("X");
/*extern*/ const URI_CHAR * const URI_FUNC(ConstPwd) = _UT(".");
/*extern*/ const URI_CHAR * const URI_FUNC(ConstParent) = _UT("..");



void URI_FUNC(ResetUri)(URI_TYPE(Uri) * uri) {
	memset(uri, 0, sizeof(URI_TYPE(Uri)));
}



/* Compares two text ranges for equal text content */
int URI_FUNC(CompareRange)(
		const URI_TYPE(TextRange) * a,
		const URI_TYPE(TextRange) * b) {
Ejemplo n.º 20
0
#define APP_CMD_SUBDIRS        11
#define APP_CMD_CONTINUE       12
#define APP_CMD_QUIET          13
#define APP_CMD_NODELETE       14


#define APP_CMD_BREAK_IN_DEBUG 666


// NOTE: do commands get translated???
//
static const CMDTABLE g_aAppCommands[] = {

// _UT("NOLOGO"),       APP_CMD_NOLOGO,       CMDF_GLOBAL, 0, NULL,     NULL,          _UT(""),
// _UT("LOGO"),         APP_CMD_LOGO,         CMDF_GLOBAL, 0, NULL,     NULL,          _UT(""),
   _UT("HELP"),         APP_CMD_USAGE,        CMDF_GLOBAL, 0, NULL,     NULL,          _UT("Print usage"),
   _UT("?"),            APP_CMD_USAGE,        CMDF_GLOBAL, 0, NULL,     NULL,          _UT("Print usage"),
   _UT("VERBOSE"),      APP_CMD_VERBOSE,      CMDF_GLOBAL, 0, NULL,     NULL,          _UT("Print detailed output."),
   _UT("DIAGNOSTIC"),   APP_CMD_DIAGNOSTIC,   CMDF_GLOBAL, 0, NULL,     NULL,          _UT("Print out internal flow of control information."),
   _UT("PATH"),         APP_CMD_PATH,         CMDF_GLOBAL, 1, NULL,     _UT("path"),   _UT("delete <path>"),
   _UT("S"),            APP_CMD_SUBDIRS,      CMDF_OPT,    0, NULL,     NULL,          _UT("include subdirectores"),
   _UT("C"),            APP_CMD_CONTINUE,     CMDF_OPT,    0, NULL,     NULL,          _UT("continue on access denied"),
   _UT("Q"),            APP_CMD_QUIET,        CMDF_OPT,	   0, NULL,     NULL,          _UT("Quiet mode - Print error output only."),
   _UT("NODEL"),        APP_CMD_NODELETE,     CMDF_OPT,    0, NULL,     NULL,          _UT("don't delete. (ACLs may still be changed)"),


  #ifdef DEBUG
   _UT("BREAK"),        APP_CMD_BREAK_IN_DEBUG,CMDF_GLOBAL,0, NULL,     NULL,             _UT("INLINE_BREAK during command line parsing."),
  #endif
   NULL, 0, 0, 0, NULL, NULL, NULL, // end of table
   };
Ejemplo n.º 21
0
int medi_dbg_dump(struct INSTRUCTION *instr, uint8_t *sf_prefixes, int sf_prefixes_len, unichar_t *buff, int len)
{
	unsigned int i;
	struct STREAM stream;

	stream.buff = buff;
	stream.bufflen = len;
	stream.reallen = 0;
	stream.options = (DUMP_OPTION_DISP_UHEX | DUMP_OPTION_IMM_UHEX);

	safe_unistrncpy(&stream, _UT("Superfluous prefixes:\n\t"));
    dbg_dump_sf_prefixes(&stream, sf_prefixes, sf_prefixes_len);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Prefixes:\n\t"));
	dbg_dump_prefixes(&stream, instr);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Mnemonic:\n\t"));
	safe_unistrncpy(&stream, _UT("************\n\t"));
	internal_dump_mnemonic(&stream, instr);
	safe_unistrncpy(&stream, _UT("\n\t************"));
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Instruction bytes offset:\n\t"));
	itoa(&stream, instr ->opcode_offset, 0x1, 0x0, 0x10);
	safe_copy_unichar(&stream, '\n');

    if (instr ->opsize)
    {
        safe_unistrncpy(&stream, _UT("Opsize:\n\t"));
        itoa(&stream, instr ->opsize, sizeof(i), 0, 0x10);
        safe_copy_unichar(&stream, '\n');
    }

	safe_unistrncpy(&stream, _UT("Flags:\n\t"));
	dbg_dump_flags(&stream, instr);
	safe_copy_unichar(&stream, '\n');

	for (i = 0; i < 3; i++)
	{
		safe_unistrncpy(&stream, _UT("OPERAND "));
		itoa(&stream, i, sizeof(i), 0, 0x10);
		safe_unistrncpy(&stream, _UT(":\n\t"));
		if ( !(instr ->ops[i].flags & OPERAND_FLAG_PRESENT) )
		{
			safe_unistrncpy(&stream, _UT("not present"));
		}
		else
		{
			internal_dump_operand(&stream, instr, i);
			if (instr ->ops[i].flags & OPERAND_TYPE_IMM)
			{
				safe_unistrncpy(&stream, _UT("; "));
				safe_unistrncpy(&stream, _UT("Offset: "));
				itoa(&stream, instr ->ops[i].value.imm.offset, 0x1, 0x0, 0x10);
                safe_unistrncpy(&stream, _UT("; "));
                safe_unistrncpy(&stream, _UT("Size in stream: "));
                itoa(&stream, instr ->ops[i].value.imm.size, 0x1, 0x0, 0x10);
                safe_unistrncpy(&stream, _UT("; "));
                safe_unistrncpy(&stream, _UT("Size: "));
                itoa(&stream, instr ->ops[i].size, 0x1, 0x0, 0x10);
    		}
			if ( (instr ->ops[i].flags & OPERAND_TYPE_MEM) && (instr ->ops[i].value.addr.mod & ADDR_MOD_DISP) )
			{
				safe_unistrncpy(&stream, _UT("; "));
				safe_unistrncpy(&stream, _UT("Offset: "));
				itoa(&stream, instr ->disp.offset, 0x1, 0x0, 0x10);
                safe_unistrncpy(&stream, _UT("; "));
                safe_unistrncpy(&stream, _UT("Size in stream: "));
                itoa(&stream, instr ->disp.size, 0x1, 0x0, 0x10);
			}
		}
		safe_copy_unichar(&stream, '\n');
	}
	
	safe_unistrncpy(&stream, _UT("Tested flags:\n\t"));
	dbg_dump_eflags(&stream, instr ->tested_flags);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Modified flags:\n\t"));
	dbg_dump_eflags(&stream, instr ->modified_flags);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Set flags:\n\t"));
	dbg_dump_eflags(&stream, instr ->set_flags);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Cleared flags:\n\t"));
	dbg_dump_eflags(&stream, instr ->cleared_flags);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Undefined flags:\n\t"));
	dbg_dump_eflags(&stream, instr ->undefined_flags);
	safe_copy_unichar(&stream, '\n');

	safe_unistrncpy(&stream, _UT("Groups:\n\t"));
	dbg_dump_groups(&stream, instr);

	return stream.reallen;
}
Ejemplo n.º 22
0
static void dbg_dump_groups(struct STREAM *stream, struct INSTRUCTION *instr)
{
	if (!instr ->groups)
		safe_unistrncpy(stream, _UT("none"));
	else
	{
		if (instr ->groups & GRP_GEN)
			safe_unistrncpy(stream, _UT("GEN, "));
		if (instr ->groups & GRP_SSE1)
			safe_unistrncpy(stream, _UT("SSE1, "));
		if (instr ->groups & GRP_ARITH)
			safe_unistrncpy(stream, _UT("ARITH, "));
		if (instr ->groups & GRP_BINARY)
			safe_unistrncpy(stream, _UT("BINARY, "));
		if (instr ->groups & GRP_STACK)
			safe_unistrncpy(stream, _UT("STACK, "));
		if (instr ->groups & GRP_SEGREG)
			safe_unistrncpy(stream, _UT("SEGREG, "));
		if (instr ->groups & GRP_LOGICAL)
			safe_unistrncpy(stream, _UT("LOGICAL, "));
		if (instr ->groups & GRP_PREFIX)
			safe_unistrncpy(stream, _UT("PREFIX, "));
		if (instr ->groups & GRP_BRANCH)
			safe_unistrncpy(stream, _UT("BRANCH, "));
		if (instr ->groups & GRP_COND)
			safe_unistrncpy(stream, _UT("COND, "));
		if (instr ->groups & GRP_DECIMAL)
			safe_unistrncpy(stream, _UT("DECIMAL, "));
		if (instr ->groups & GRP_BREAK)
			safe_unistrncpy(stream, _UT("BREAK, "));
		if (instr ->groups & GRP_SYSTEM)
			safe_unistrncpy(stream, _UT("SYSTEM, "));
		if (instr ->groups & GRP_INOUT)
			safe_unistrncpy(stream, _UT("INOUT, "));
		if (instr ->groups & GRP_STRING)
			safe_unistrncpy(stream, _UT("STRING, "));
		if (instr ->groups & GRP_DATAMOV)
			safe_unistrncpy(stream, _UT("DATAMOV, "));
		if (instr ->groups & GRP_CONTROL)
			safe_unistrncpy(stream, _UT("CONTROL, "));
		if (instr ->groups & GRP_CONVER)
			safe_unistrncpy(stream, _UT("CONVER, "));
		if (instr ->groups & GRP_X87FPU)
			safe_unistrncpy(stream, _UT("X87FPU, "));
		if (instr ->groups & GRP_FLGCTRL)
			safe_unistrncpy(stream, _UT("FLGCTRL, "));
		if (instr ->groups & GRP_SHFTROT)
			safe_unistrncpy(stream, _UT("SHFTROT, "));
		if (instr ->groups & GRP_SIMDFP)
			safe_unistrncpy(stream, _UT("SIMDFP, "));
		if (instr ->groups & GRP_SHUNPCK)
			safe_unistrncpy(stream, _UT("SHUNPCK, "));
		if (instr ->groups & GRP_FETCH)
			safe_unistrncpy(stream, _UT("FETCH, "));
		if (instr ->groups & GRP_CACHECT)
			safe_unistrncpy(stream, _UT("CACHECT, "));
		if (instr ->groups & GRP_COMPAR)
			safe_unistrncpy(stream, _UT("COMPAR, "));
		if (instr ->groups & GRP_TRANS)
			safe_unistrncpy(stream, _UT("TRANS, "));
		if (instr ->groups & GRP_SIMDINT)
			safe_unistrncpy(stream, _UT("SIMDINT, "));
		if (instr ->groups & GRP_PCKSCLR)
			safe_unistrncpy(stream, _UT("PCKSCLR, "));
		if (instr ->groups & GRP_PCKSP)
			safe_unistrncpy(stream, _UT("PCKSP, "));
		if (instr ->groups & GRP_UNPACK)
			safe_unistrncpy(stream, _UT("UNPACK, "));
		if (instr ->groups & GRP_SHIFT)
			safe_unistrncpy(stream, _UT("SHIFT, "));
		if (instr ->groups & GRP_BIT)
			safe_unistrncpy(stream, _UT("BIT, "));
		if (instr ->groups & GRP_SM)
			safe_unistrncpy(stream, _UT("SM, "));
		if (instr ->groups & GRP_MXCSRSM)
			safe_unistrncpy(stream, _UT("MXCSRSM, "));
		if (instr ->groups & GRP_ORDER)
			safe_unistrncpy(stream, _UT("ORDER, "));
		if (instr ->groups & GRP_SSE2)
			safe_unistrncpy(stream, _UT("SSE2, "));
		if (instr ->groups & GRP_SSSE3)
			safe_unistrncpy(stream, _UT("SSSE3, "));
		if (instr ->groups & GRP_MMX)
			safe_unistrncpy(stream, _UT("MMX, "));
		if (instr ->groups & GRP_SSE3)
			safe_unistrncpy(stream, _UT("SSE3, "));
		if (instr ->groups & GRP_SMX)
			safe_unistrncpy(stream, _UT("GRP_SMX, "));
		if (instr ->groups & GRP_VMX)
			safe_unistrncpy(stream, _UT("GRP_VMX, "));
		if (instr ->groups & GRP_SSE41)
			safe_unistrncpy(stream, _UT("GRP_SSE41, "));
		if (instr ->groups & GRP_SSE42)
			safe_unistrncpy(stream, _UT("GRP_SSE42, "));
		if (instr ->groups & GRP_STRTXT)
			safe_unistrncpy(stream, _UT("GRP_STRTXT, "));

		stream ->bufflen += 2;
		stream ->buff -= 2;
		stream ->reallen -= 2;
	}
}
Ejemplo n.º 23
0
static void dbg_dump_prefixes(struct STREAM *stream, struct INSTRUCTION *instr)
{
	if (!instr ->prefixes)
		safe_unistrncpy(stream, _UT("none"));
	else
	{
		if (instr ->prefixes & INSTR_PREFIX_CS)
			safe_unistrncpy(stream, _UT("CS, "));
		if (instr ->prefixes & INSTR_PREFIX_DS)
			safe_unistrncpy(stream, _UT("DS, "));
		if (instr ->prefixes & INSTR_PREFIX_ES)
			safe_unistrncpy(stream, _UT("ES, "));
		if (instr ->prefixes & INSTR_PREFIX_SS)
			safe_unistrncpy(stream, _UT("SS, "));
		if (instr ->prefixes & INSTR_PREFIX_FS)
			safe_unistrncpy(stream, _UT("FS, "));
		if (instr ->prefixes & INSTR_PREFIX_GS)
			safe_unistrncpy(stream, _UT("GS, "));
		if (instr ->prefixes & INSTR_PREFIX_OPSIZE)
			safe_unistrncpy(stream, _UT("OPSIZE, "));
		if (instr ->prefixes & INSTR_PREFIX_ADDRSIZE)
			safe_unistrncpy(stream, _UT("ADDRSIZE, "));
		if (instr ->prefixes & INSTR_PREFIX_REX)
		{
			safe_unistrncpy(stream, _UT("REX ("));
			itoa(stream, instr ->rex, 0x1, 0x0, 0x10);
			safe_unistrncpy(stream, _UT("), "));
		}
		if (instr ->prefixes & INSTR_PREFIX_LOCK)
			safe_unistrncpy(stream, _UT("LOCK, "));

		stream ->bufflen += 2;
		stream ->buff -= 2;
		stream ->reallen -= 2;
	}
}