Example #1
0
/*
 * Dump the contents of a file.
 */
static int dumpFile(const char *filename, FILE *stream,
					int closeStream, ILContext *context,
					int dumpSections, int flags)
{
	int loadError;
	ILImage *image;
	int imageType;

	/* Attempt to load the image into memory */
	loadError = ILImageLoad(stream, filename, context, &image,
							IL_LOADFLAG_FORCE_32BIT |
							IL_LOADFLAG_PRE_VALIDATE |
							((flags & ILDASM_RESOLVE_ALL)
								? 0 : IL_LOADFLAG_NO_RESOLVE) |
							(dumpSections ? IL_LOADFLAG_NO_METADATA : 0));
	if(loadError != 0)
	{
		if(closeStream)
		{
			fclose(stream);
		}
		fprintf(stderr, "%s: %s\n", filename, ILImageLoadError(loadError));
		return 1;
	}

	/* Close the input stream, because we don't need it any more */
	if(closeStream)
	{
		fclose(stream);
	}

	/* Dump interesting information about the image in general */
	fprintf(outstream, "// Input: %s\n", filename);
	imageType = ILImageType(image);
	fprintf(outstream, "// Image type: %s\n",
		    (imageType == IL_IMAGETYPE_DLL ? "DLL" :
				(imageType == IL_IMAGETYPE_EXE ? "EXE" :
					(imageType == IL_IMAGETYPE_JAVA ? "Java" :
						(imageType == IL_IMAGETYPE_OBJ ? "OBJ" : "Unknown")))));
	fprintf(outstream, "// Native code present: %s\n",
		    (ILImageHadNative(image) ? "Yes" : "No"));
	fprintf(outstream, "// 32-bit only: %s\n",
		    (ILImageIs32Bit(image) ? "Yes" : "No"));
	fprintf(outstream, "// Length of IL data: %lu\n", ILImageLength(image));
	fprintf(outstream, "\n");

	/* How should we dump the image? */
	if(dumpSections)
	{
		dumpSectionData(image, (flags & ILDASM_REAL_OFFSETS) != 0);
	}
	else
	{
		dumpAssembly(image, flags);
	}

	/* Clean up and exit */
	ILImageDestroy(image);
	return 0;
}
Example #2
0
void UVDUvudecUnitTest::disassembleRangeTestDefaultEquivilenceTest(void)
{
	//Default and full range should be identical
	std::string defaultRange;
	std::string sameAsDefaultRange;
	std::string uselessExcludedrange;
	
	printf("Default range equivilence to specified\n");
	
	//Full analysis
	m_args.clear();
	generalDisassemble(defaultRange);

	//Range specified exactly to the full range should be same as default
	m_args.clear();
	m_args.push_back("--addr-include=0x0000,0xFFFF");
	generalDisassemble(sameAsDefaultRange);
	try
	{
		CPPUNIT_ASSERT(defaultRange == sameAsDefaultRange);
	}
	catch(...)
	{
		dumpAssembly("default range", defaultRange);
		dumpAssembly("sameAsDefaultRange", sameAsDefaultRange);
		throw;
	}

	//A range excluded outside of the analysis shouldn't effect output
	m_args.clear();
	m_args.push_back("--addr-exclude=0x10000,0x20000");
	generalDisassemble(uselessExcludedrange);
	try
	{
		CPPUNIT_ASSERT(defaultRange == uselessExcludedrange);
	}
	catch(...)
	{
		dumpAssembly("default range", defaultRange);
		dumpAssembly("useless excluded range", uselessExcludedrange);
		throw;
	}
}
Example #3
0
void UVDUvudecUnitTest::disassembleRangeTestComplexTest(void)
{
	/*
	This asssumes using the candela image

	0x00-0x02
		LJMP #0x0026
	0x0B-0x0E:
		LJMP #0x0DA9
		MOV R7, A
	*/

	std::string target =
		"LJMP #0x0026\n"
		"LJMP #0x0DA9\n"
		"MOV R7, A\n";
	std::string output;
	
	printf("Range deliminator compound\n");
	
	//Try all possible range delminators

	printf("Multiple inclusion range\n");
	m_args.push_back("--addr-include=0x0000-0x0002");
	m_args.push_back("--addr-include=0x000B-0x000E");
	generalDisassemble(output);

	try
	{
		CPPUNIT_ASSERT(output == target);
	}
	catch(...)
	{
		dumpAssembly("target", target);
		dumpAssembly("output", output);
		throw;
	}
}
Example #4
0
void UVDUvudecUnitTest::disassembleRangeTestDeliminatorsTest(void)
{
	/*
	This asssumes using the candela image

	From 0x0000:0x0010
	
	LJMP #0x0026
	MOV R7, A
	MOV R7, A
	MOV R7, A
	MOV R7, A
	MOV R7, A
	MOV R7, A
	MOV R7, A
	MOV R7, A
	LJMP #0x0DA9
	MOV R7, A
	MOV R7, A
	MOV R7, A
	*/

	std::string smallRangeTarget =
		"LJMP #0x0026\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"LJMP #0x0DA9\n"
		"MOV R7, A\n"
		"MOV R7, A\n"
		"MOV R7, A\n";

	std::string output;
	
	printf("Range deliminator tests\n");

	//Try all possible range delminators

	printf("- range deliminator\n");
	m_args.clear();
	m_args.push_back("--addr-include=0x0000-0x0010");
	generalDisassemble(output);
	try
	{
		CPPUNIT_ASSERT(output == smallRangeTarget);
	}
	catch(...)
	{
		dumpAssembly("smallRangeTarget", smallRangeTarget);
		dumpAssembly("output", output);
		throw;
	}
	
	printf(": range deliminator\n");
	m_args.clear();
	m_args.push_back("--addr-include=0x0000:0x0010");
	generalDisassemble(output);
	try
	{
		CPPUNIT_ASSERT(output == smallRangeTarget);
	}
	catch(...)
	{
		dumpAssembly("smallRangeTarget", smallRangeTarget);
		dumpAssembly("output", output);
		throw;
	}

	printf(", range deliminator\n");
	m_args.clear();
	m_args.push_back("--addr-include=0x0000,0x0010");
	generalDisassemble(output);
	try
	{
		CPPUNIT_ASSERT(output == smallRangeTarget);
	}
	catch(...)
	{
		dumpAssembly("smallRangeTarget", smallRangeTarget);
		dumpAssembly("output", output);
		throw;
	}
}