[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] pnet ChangeLog dumpasm/Makefile.am engine/debug...
From: |
Radek Polak |
Subject: |
[dotgnu-pnet-commits] pnet ChangeLog dumpasm/Makefile.am engine/debug... |
Date: |
Fri, 09 Feb 2007 21:54:17 +0000 |
CVSROOT: /sources/dotgnu-pnet
Module name: pnet
Changes by: Radek Polak <radekp> 07/02/09 21:54:16
Modified files:
. : ChangeLog
dumpasm : Makefile.am
engine : debugger.c
ildasm : Makefile.am ildasm_main.c
include : il_dumpasm.h
Added files:
dumpasm : dump_attrs.c dump_class.c dump_data.c
dump_global.c dump_java.c dump_method.c
dump_utils.c
Removed files:
ildasm : ildasm_attrs.c ildasm_class.c ildasm_data.c
ildasm_global.c ildasm_internal.h ildasm_java.c
ildasm_method.c ildasm_utils.c
Log message:
moved disassembled functions from ildasm program to dumpasm directory
so that debugger can use it
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3412&r2=1.3413
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/Makefile.am?cvsroot=dotgnu-pnet&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_attrs.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_class.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_data.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_global.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_java.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_method.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/dumpasm/dump_utils.c?cvsroot=dotgnu-pnet&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/debugger.c?cvsroot=dotgnu-pnet&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/Makefile.am?cvsroot=dotgnu-pnet&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_main.c?cvsroot=dotgnu-pnet&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_attrs.c?cvsroot=dotgnu-pnet&r1=1.4&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_class.c?cvsroot=dotgnu-pnet&r1=1.16&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_data.c?cvsroot=dotgnu-pnet&r1=1.4&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_global.c?cvsroot=dotgnu-pnet&r1=1.6&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_internal.h?cvsroot=dotgnu-pnet&r1=1.7&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_java.c?cvsroot=dotgnu-pnet&r1=1.5&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_method.c?cvsroot=dotgnu-pnet&r1=1.17&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/ildasm/ildasm_utils.c?cvsroot=dotgnu-pnet&r1=1.2&r2=0
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_dumpasm.h?cvsroot=dotgnu-pnet&r1=1.9&r2=1.10
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3412
retrieving revision 1.3413
diff -u -b -r1.3412 -r1.3413
--- ChangeLog 9 Feb 2007 18:39:50 -0000 1.3412
+++ ChangeLog 9 Feb 2007 21:54:16 -0000 1.3413
@@ -1,5 +1,25 @@
2007-02-09 Radek Polak <address@hidden>
+ * dumpasm/Makefile.am, ildasm/Makefile.am, ildasm/ildasm_main.c,
+ include/il_dumpasm.h: Move all disassembler functions to dumpasm
+ library so that debugger can use it.
+
+ * ildasm/ildasm_attrs.c, ildasm/ildasm_class.c, ildasm/ildasm_data.c,
+ ildasm/ildasm_global.c, ildasm/ildasm_java.c, ildasm/ildasm_method.c,
+ ildasm/ildasm_utils.c: Moved to dumpasm directory under appropriate
+ filenames.
+
+ * dumpasm/dump_attrs.c, dumpasm/dump_class.c, dumpasm/dump_data.c,
+ dumpasm/dump_global.c, dumpasm/dump_java.c, dumpasm/dump_method.c,
+ dumpasm/dump_utils.c: New files comming from ildasm directory.
+
+ * ildasm/ildasm_internal.h: Removed this file, the definitions are now
+ in il_dumpasm.h.
+
+ * engine/debugger.c: Make show_ildasm command work.
+
+2007-02-09 Radek Polak <address@hidden>
+
* pnet/engine/debugger.c: Make show_dasm command work with jit coder.
2007-02-06 Klaus Treichel <address@hidden>
Index: dumpasm/Makefile.am
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/dumpasm/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- dumpasm/Makefile.am 4 Jul 2002 04:59:12 -0000 1.4
+++ dumpasm/Makefile.am 9 Feb 2007 21:54:16 -0000 1.5
@@ -5,6 +5,13 @@
dump_guid.c \
dump_ident.c \
dump_string.c \
- dump_type.c
+ dump_type.c \
+ dump_attrs.c \
+ dump_class.c \
+ dump_data.c \
+ dump_global.c \
+ dump_method.c \
+ dump_utils.c \
+ dump_java.c
AM_CFLAGS = -I$(top_srcdir)/include
\ No newline at end of file
Index: engine/debugger.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/engine/debugger.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- engine/debugger.c 9 Feb 2007 18:39:50 -0000 1.11
+++ engine/debugger.c 9 Feb 2007 21:54:16 -0000 1.12
@@ -30,7 +30,6 @@
#include "engine.h"
#include "cvm.h"
#include "debugger.h"
-#include "../ildasm/ildasm_internal.h"
#ifdef IL_USE_JIT
#include <jit/jit-dump.h>
@@ -1758,24 +1757,41 @@
ILFree(str);
}
-/* TODO we need to link against ildasm
-
-#include "../ildasm/ildasm_utils.c"
-#include "../ildasm/ildasm_attrs.c"
-#include "../ildasm/ildasm_method.c"
-*/
-
/*
* show_ildasm command.
*/
void ShowIldasm(ILDebugger *debugger, FILE *stream)
{
- /* TODO we need to link against ildasm
ILImage *image;
+ char *str;
+ long pos;
+
+ /* Remeber current position before dump */
+ pos = ftell(stream);
+
image = ILClassToImage(ILMethod_Owner(debugger->dbthread->method));
ILDAsmDumpMethod(image, stream, debugger->dbthread->method, 0, 0);
- */
+
+ /* Read stream to memory so that we can dump with xml quoting */
+ str = ReadStream(stream);
+
+ /* Restore position */
+ fseek(stream, pos, SEEK_SET);
+
+ if(!str)
+ {
+ DumpError("Out of memory", stream);
+ return;
+ }
+
+ fputs("<ILDasm>\n", stream);
+ fputs("<Text>\n", stream);
+ DumpString(str + pos, stream);
+ fputs("</Text>\n", stream);
+ fputs("</ILDasm>\n", stream);
+
+ ILFree(str);
}
/*
Index: ildasm/Makefile.am
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ildasm/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- ildasm/Makefile.am 21 Aug 2005 15:33:24 -0000 1.8
+++ ildasm/Makefile.am 9 Feb 2007 21:54:16 -0000 1.9
@@ -1,15 +1,7 @@
bin_PROGRAMS = ildasm
man_MANS = ildasm.1
EXTRA_DIST = $(man_MANS)
-ildasm_SOURCES = ildasm_attrs.c \
- ildasm_class.c \
- ildasm_data.c \
- ildasm_global.c \
- ildasm_internal.h \
- ildasm_java.c \
- ildasm_main.c \
- ildasm_method.c \
- ildasm_utils.c
+ildasm_SOURCES = ildasm_main.c
ildasm_LDADD = ../dumpasm/libILDumpAsm.a ../image/libILImage.a \
../support/libILSupport.a $(GCLIBS)
Index: ildasm/ildasm_main.c
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/ildasm/ildasm_main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- ildasm/ildasm_main.c 23 Dec 2003 21:26:29 -0000 1.6
+++ ildasm/ildasm_main.c 9 Feb 2007 21:54:16 -0000 1.7
@@ -18,7 +18,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "ildasm_internal.h"
+#include "il_dumpasm.h"
+#include "il_system.h"
+#include "il_utils.h"
#ifdef __cplusplus
extern "C" {
Index: include/il_dumpasm.h
===================================================================
RCS file: /sources/dotgnu-pnet/pnet/include/il_dumpasm.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- include/il_dumpasm.h 15 Feb 2004 03:33:25 -0000 1.9
+++ include/il_dumpasm.h 9 Feb 2007 21:54:16 -0000 1.10
@@ -38,6 +38,15 @@
#define IL_DUMP_C_TYPES 32
/*
+ * Extra flags for altering the output, in addition to "IL_DUMP_xxx".
+ */
+#define ILDASM_REAL_OFFSETS (1 << 8)
+#define ILDASM_SUPPRESS_PREFIX (1 << 9)
+#define ILDASM_NO_IL (1 << 10)
+#define ILDASM_INSTRUCTION_BYTES (1 << 11)
+#define ILDASM_RESOLVE_ALL (1 << 12)
+
+/*
* Structure of a flag information block. This is used when
* dumping the contents of a flag mask. If "mask" is zero,
* then "flag" indicates the flag bit to be selected. If "mask"
@@ -153,6 +162,63 @@
*/
void ILDumpConstant(FILE *stream, ILProgramItem *item, int hexFloats);
+/*
+ * Dump a binary blob to an output stream.
+ */
+void ILDAsmDumpBinaryBlob(FILE *outstream, ILImage *image,
+ const void *blob, ILUInt32
blobLen);
+
+/*
+ * Walk a list of tokens and call a supplied callback for each one.
+ */
+typedef void (*ILDAsmWalkFunc)(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
void *data,
+ unsigned long
refToken);
+void ILDAsmWalkTokens(ILImage *image, FILE *outstream, int flags,
+ unsigned long tokenKind,
ILDAsmWalkFunc callback,
+ unsigned long refToken);
+
+/*
+ * Dump the contents of a method.
+ */
+void ILDAsmDumpMethod(ILImage *image, FILE *outstream,
+ ILMethod *method, int flags,
+ int isEntryPoint);
+
+/*
+ * Dump the contents of a Java method.
+ */
+void ILDAsmDumpJavaMethod(ILImage *image, FILE *outstream,
+ ILMethod *method, int flags);
+
+/*
+ * Dump custom attributes for a program item.
+ */
+void ILDAsmDumpCustomAttrs(ILImage *image, FILE *outstream, int flags,
+ int indent, ILProgramItem
*item);
+
+/*
+ * Dump global definitions such as modules, assemblies, etc.
+ */
+void ILDAsmDumpGlobal(ILImage *image, FILE *outstream, int flags);
+
+/*
+ * Dump all class definitions.
+ */
+void ILDAsmDumpClasses(ILImage *image, FILE *outstream, int flags);
+
+/*
+ * Dump the security information associated with a program item.
+ */
+void ILDAsmDumpSecurity(ILImage *image, FILE *outstream,
+ ILProgramItem *item, int flags);
+
+/*
+ * Dump the ".data" and ".tls" sections.
+ */
+void ILDAsmDumpDataSections(FILE *outstream, ILImage *image);
+
+
#ifdef __cplusplus
};
#endif
Index: dumpasm/dump_attrs.c
===================================================================
RCS file: dumpasm/dump_attrs.c
diff -N dumpasm/dump_attrs.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_attrs.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,381 @@
+/*
+ * dump_attrs.c - Dump custom attributes.
+ *
+ * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+#include "il_serialize.h"
+#include "il_system.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Dump a serialized attribute value.
+ */
+static int DumpAttrValue(FILE *outstream, ILSerializeReader *reader, int type)
+{
+ ILInt32 intValue;
+ ILUInt32 uintValue;
+ ILInt64 longValue;
+ ILUInt64 ulongValue;
+ ILFloat floatValue;
+ ILDouble doubleValue;
+ const char *strValue;
+ int strLen;
+
+ switch(type)
+ {
+ case IL_META_SERIALTYPE_BOOLEAN:
+ {
+ intValue = ILSerializeReaderGetInt32(reader, type);
+ if(intValue)
+ {
+ fputs("true", outstream);
+ }
+ else
+ {
+ fputs("false", outstream);
+ }
+ }
+ break;
+
+ case IL_META_SERIALTYPE_I1:
+ case IL_META_SERIALTYPE_U1:
+ {
+ intValue = ILSerializeReaderGetInt32(reader, type);
+ fprintf(outstream, "%ld /*0x%02lX*/",
+ (long)intValue, (long)intValue);
+ }
+ break;
+
+ case IL_META_SERIALTYPE_I2:
+ case IL_META_SERIALTYPE_U2:
+ case IL_META_SERIALTYPE_CHAR:
+ {
+ intValue = ILSerializeReaderGetInt32(reader, type);
+ fprintf(outstream, "%ld /*0x%04lX*/",
+ (long)intValue, (long)intValue);
+ }
+ break;
+
+ case IL_META_SERIALTYPE_I4:
+ {
+ intValue = ILSerializeReaderGetInt32(reader, type);
+ fprintf(outstream, "%ld /*0x%08lX*/",
+ (long)intValue, (long)intValue);
+ }
+ break;
+
+ case IL_META_SERIALTYPE_U4:
+ {
+ uintValue = ILSerializeReaderGetUInt32(reader, type);
+ fprintf(outstream, "%lu /*0x%08lX*/",
+ (unsigned long)uintValue, (unsigned
long)uintValue);
+ }
+ break;
+
+ case IL_META_SERIALTYPE_I8:
+ {
+ longValue = ILSerializeReaderGetInt64(reader);
+ fprintf(outstream, "0x%08lX%08lX",
+ (unsigned long)((longValue >> 32) &
IL_MAX_UINT32),
+ (unsigned long)(longValue &
IL_MAX_UINT32));
+ }
+ break;
+
+ case IL_META_SERIALTYPE_U8:
+ {
+ ulongValue = ILSerializeReaderGetUInt64(reader);
+ fprintf(outstream, "0x%08lX%08lX",
+ (unsigned long)((ulongValue >> 32) &
IL_MAX_UINT32),
+ (unsigned long)(ulongValue &
IL_MAX_UINT32));
+ }
+ break;
+
+ case IL_META_SERIALTYPE_R4:
+ {
+ floatValue = ILSerializeReaderGetFloat32(reader);
+ fprintf(outstream, "%.30e", (double)floatValue);
+ }
+ break;
+
+ case IL_META_SERIALTYPE_R8:
+ {
+ doubleValue = ILSerializeReaderGetFloat64(reader);
+ fprintf(outstream, "%.30e", (double)doubleValue);
+ }
+ break;
+
+ case IL_META_SERIALTYPE_STRING:
+ {
+ strLen = ILSerializeReaderGetString(reader, &strValue);
+ if(strLen == -1)
+ {
+ return 0;
+ }
+ if(strValue)
+ {
+ ILDumpStringLen(outstream, strValue, strLen);
+ }
+ else
+ {
+ fputs("null", outstream);
+ }
+ }
+ break;
+
+ case IL_META_SERIALTYPE_TYPE:
+ {
+ strLen = ILSerializeReaderGetString(reader, &strValue);
+ if(strLen == -1)
+ {
+ return 0;
+ }
+ fputs("typeof(", outstream);
+ if(strValue)
+ {
+ fwrite(strValue, 1, strLen, outstream);
+ }
+ else
+ {
+ fputs("null", outstream);
+ }
+ putc(')', outstream);
+ }
+ break;
+
+ default:
+ {
+ if((type & IL_META_SERIALTYPE_ARRAYOF) != 0)
+ {
+ intValue = ILSerializeReaderGetArrayLen(reader);
+ putc('{', outstream);
+ while(intValue > 0)
+ {
+ if(!DumpAttrValue(outstream, reader,
+ type
& ~IL_META_SERIALTYPE_ARRAYOF))
+ {
+ return 0;
+ }
+ --intValue;
+ if(intValue > 0)
+ {
+ fputs(", ", outstream);
+ }
+ }
+ putc('}', outstream);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ break;
+ }
+ return 1;
+}
+
+/*
+ * Dump the readable form of an attribute blob.
+ */
+static void DumpAttrBlob(FILE *outstream, ILImage *image, ILMethod *method,
+ const void *blob, unsigned
long blobLen)
+{
+ ILClass *classInfo;
+ const char *name;
+ int nameLen;
+ ILSerializeReader *reader;
+ ILUInt32 numParams;
+ int numExtra;
+ int type, needComma;
+ ILMember *member;
+
+ /* Dump the name of the attribute */
+ classInfo = ILMethod_Owner(method);
+ name = ILClass_Name(classInfo);
+ nameLen = strlen(name);
+ if(!strcmp(name + nameLen - 9, "Attribute"))
+ {
+ fwrite(name, 1, nameLen - 9, outstream);
+ }
+ else
+ {
+ fputs(name, outstream);
+ }
+
+ /* Initialize the serialization reader */
+ reader = ILSerializeReaderInit(method, blob, blobLen);
+ if(!reader)
+ {
+ fputs("(?)", outstream);
+ return;
+ }
+
+ /* Dump the parameters */
+ numParams = ILTypeNumParams(ILMethod_Signature(method));
+ needComma = 0;
+ putc('(', outstream);
+ while(numParams > 0)
+ {
+ if(needComma)
+ {
+ fputs(", ", outstream);
+ }
+ else
+ {
+ needComma = 1;
+ }
+ type = ILSerializeReaderGetParamType(reader);
+ if(type != -1)
+ {
+ if(!DumpAttrValue(outstream, reader, type))
+ {
+ ILSerializeReaderDestroy(reader);
+ return;
+ }
+ }
+ else
+ {
+ fputs("?)", outstream);
+ ILSerializeReaderDestroy(reader);
+ return;
+ }
+ --numParams;
+ }
+ putc(')', outstream);
+
+ /* Dump the extra field and property specifications */
+ numExtra = ILSerializeReaderGetNumExtra(reader);
+ while(numExtra > 0)
+ {
+ fputs(", ", outstream);
+ type = ILSerializeReaderGetExtra(reader, &member, &name,
&nameLen);
+ if(type == -1)
+ {
+ putc('?', outstream);
+ break;
+ }
+ fwrite(name, 1, nameLen, outstream);
+ putc('=', outstream);
+ if(!DumpAttrValue(outstream, reader, type))
+ {
+ putc('?', outstream);
+ break;
+ }
+ --numExtra;
+ }
+
+ /* Clean up and exit */
+ ILSerializeReaderDestroy(reader);
+}
+
+void ILDAsmDumpCustomAttrs(ILImage *image, FILE *outstream, int flags,
+ int indent, ILProgramItem
*item)
+{
+ ILAttribute *attr = 0;
+ ILProgramItem *type;
+ const void *value;
+ unsigned long valueLen;
+ ILClass *classInfo;
+ ILMethod *method;
+ ILTypeSpec *spec;
+ ILType *rawType;
+
+ while((attr = ILProgramItemNextAttribute(item, attr)) != 0)
+ {
+ /* Output the ".custom" header */
+ if(indent == 1)
+ {
+ fputs("\t", outstream);
+ }
+ else if(indent == 2)
+ {
+ fputs("\t\t", outstream);
+ }
+ fputs(".custom ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ",
+ (long)(ILProgramItem_Token(attr)));
+ }
+
+ /* Output the type */
+ method = 0;
+ if(ILAttributeTypeIsItem(attr))
+ {
+ type = ILAttributeTypeAsItem(attr);
+ if((spec = ILProgramItemToTypeSpec(type)) != 0)
+ {
+ rawType = ILTypeSpec_Type(spec);
+ ILDumpType(outstream, image, rawType, flags);
+ }
+ else if((classInfo = ILProgramItemToClass(type)) != 0)
+ {
+ ILDumpClassName(outstream, image, classInfo,
flags);
+ }
+ else if((method = ILProgramItemToMethod(type)) != 0)
+ {
+ ILDumpMethodType(outstream, image,
+
ILMethod_Signature(method), flags,
+
ILMethod_Owner(method),
+
ILMethod_Name(method),
+ method);
+ }
+ else
+ {
+ fputs("UNKNOWNTYPE", outstream);
+ }
+ }
+ else
+ {
+ fputs("STRING", outstream);
+ }
+
+ /* Output the value */
+ if((value = ILAttributeGetValue(attr, &valueLen)) != 0)
+ {
+ fputs(" =", outstream);
+ ILDAsmDumpBinaryBlob(outstream, image, value, valueLen);
+ }
+
+ /* Terminate the line */
+ putc('\n', outstream);
+
+ /* Output a readable version of the value */
+ if(value && method)
+ {
+ if(indent == 1)
+ {
+ fputs("\t", outstream);
+ }
+ else if(indent == 2)
+ {
+ fputs("\t\t", outstream);
+ }
+ fputs("// ", outstream);
+ DumpAttrBlob(outstream, image, method, value, valueLen);
+ putc('\n', outstream);
+ }
+ }
+}
+
+#ifdef __cplusplus
+};
+#endif
Index: dumpasm/dump_class.c
===================================================================
RCS file: dumpasm/dump_class.c
diff -N dumpasm/dump_class.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_class.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,623 @@
+/*
+ * dump_class.c - Disassemble class information.
+ *
+ * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+#include "il_system.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Dump a PInvoke definition.
+ */
+static void Dump_PInvoke(FILE *outstream, ILPInvoke *pinvoke, ILMember *member)
+{
+ if(pinvoke)
+ {
+ fputs("pinvokeimpl(", outstream);
+ ILDumpString(outstream,
+
ILModule_Name(ILPInvoke_Module(pinvoke)));
+ putc(' ', outstream);
+ if(strcmp(ILPInvoke_Alias(pinvoke), ILMember_Name(member)) != 0)
+ {
+ fputs("as ", outstream);
+ ILDumpString(outstream, ILPInvoke_Alias(pinvoke));
+ putc(' ', outstream);
+ }
+ ILDumpFlags(outstream, ILPInvoke_Attrs(pinvoke),
+ ILPInvokeImplementationFlags, 0);
+ fputs(") ", outstream);
+ }
+ else
+ {
+ fputs("pinvokeimpl() ", outstream);
+ }
+}
+
+/*
+ * Dump a method definition.
+ */
+static void Dump_MethodDef(ILImage *image, FILE *outstream, int flags,
+ ILMethod *method)
+{
+ ILUInt32 rva;
+ ILOverride *over;
+ int haveContents;
+
+ /* Skip the method if it is a reference (probably a vararg call site) */
+ if((ILMethod_Token(method) & IL_META_TOKEN_MASK) ==
+ IL_META_TOKEN_MEMBER_REF)
+ {
+ return;
+ }
+
+ /* Dump the header information for the method */
+ fputs("\t.method ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ",
+ (unsigned long)(ILMethod_Token(method)));
+ }
+ ILDumpFlags(outstream, ILMethod_Attrs(method), ILMethodDefinitionFlags,
0);
+ if(ILMethod_HasPInvokeImpl(method))
+ {
+ Dump_PInvoke(outstream, ILPInvokeFind(method), (ILMember
*)method);
+ }
+ ILDumpMethodType(outstream, image, ILMethod_Signature(method),
+ flags | IL_DUMP_GENERIC_PARAMS,
+ 0, ILMethod_Name(method), method);
+ putc(' ', outstream);
+ ILDumpFlags(outstream, ILMethod_ImplAttrs(method),
+ ILMethodImplementationFlags, 0);
+ rva = ILMethod_RVA(method);
+ haveContents = (ILProgramItem_HasAttrs(method) || rva ||
+ ILOverrideFromMethod(method));
+ if(haveContents)
+ {
+ fputs("\n\t{\n", outstream);
+ }
+ else
+ {
+ fputs("{}\n", outstream);
+ }
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 2,
ILToProgramItem(method));
+
+ /* Dump the security information, if any */
+ if((ILMethod_Attrs(method) & IL_META_METHODDEF_HAS_SECURITY) != 0)
+ {
+ ILDAsmDumpSecurity(image, outstream, (ILProgramItem *)method,
flags);
+ }
+
+ /* If this a body for an override, then declare it */
+ over = ILOverrideFromMethod(method);
+ if(over)
+ {
+ ILMethod *decl = ILOverride_Decl(over);
+ fputs("\t\t.override ", outstream);
+ ILDumpClassName(outstream, image, ILMethod_Owner(decl), flags);
+ fputs("::", outstream);
+ ILDumpIdentifier(outstream, ILMethod_Name(decl), 0, flags);
+ putc('\n', outstream);
+ }
+
+ /* If we have an RVA, then we need to dump the method's contents */
+ if(rva && (flags & ILDASM_NO_IL) == 0)
+ {
+ #ifdef IL_CONFIG_JAVA
+ if(ILMethod_IsJava(method))
+ {
+ ILDAsmDumpJavaMethod(image, outstream, method, flags);
+ }
+ else
+ #endif
+ {
+ ILDAsmDumpMethod(image, outstream, method, flags,
+
(ILMethod_Token(method) ==
+
ILImageGetEntryPoint(image)));
+ }
+ }
+
+ /* Output the method footer and exit */
+ if(haveContents)
+ {
+ fputs("\t}\n", outstream);
+ }
+}
+
+/*
+ * Dump a field definition.
+ */
+static void Dump_FieldDef(ILImage *image, FILE *outstream, int flags,
+ ILField *field)
+{
+ ILFieldLayout *layout;
+ fputs("\t.field ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ",
+ (unsigned long)(ILField_Token(field)));
+ }
+ layout = ILFieldLayoutGetFromOwner(field);
+ if(layout)
+ {
+ fprintf(outstream, "[%lu] ",
+ (unsigned long)(ILFieldLayout_Offset(layout)));
+ }
+ ILDumpFlags(outstream, ILField_Attrs(field), ILFieldDefinitionFlags, 0);
+ if((ILField_Attrs(field) & IL_META_FIELDDEF_HAS_FIELD_MARSHAL) != 0)
+ {
+ ILFieldMarshal *marshal = ILFieldMarshalGetFromOwner
+
((ILProgramItem *)field);
+ if(marshal)
+ {
+ const void *type;
+ unsigned long typeLen;
+ type = ILFieldMarshalGetType(marshal, &typeLen);
+ if(type)
+ {
+ fputs("marshal(", outstream);
+ ILDumpNativeType(outstream, type, typeLen,
flags);
+ fputs(") ", outstream);
+ }
+ }
+ }
+ if(ILField_HasPInvokeImpl(field))
+ {
+ Dump_PInvoke(outstream, ILPInvokeFindField(field), (ILMember
*)field);
+ }
+ ILDumpType(outstream, image, ILFieldGetTypeWithPrefixes(field), flags);
+ putc(' ', outstream);
+ ILDumpIdentifier(outstream, ILField_Name(field), 0, flags);
+ if((ILField_Attrs(field) & IL_META_FIELDDEF_HAS_FIELD_RVA) != 0)
+ {
+ ILFieldRVA *rva = ILFieldRVAGetFromOwner(field);
+ if(rva)
+ {
+ fprintf(outstream, " at D_0x%08lX",
+ (unsigned long)(ILFieldRVA_RVA(rva)));
+ }
+ }
+ if((ILField_Attrs(field) & IL_META_FIELDDEF_HAS_DEFAULT) != 0)
+ {
+ ILDumpConstant(outstream, (ILProgramItem *)field, 0);
+ }
+ putc('\n', outstream);
+ if(ILProgramItem_HasAttrs(field))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+
ILToProgramItem(field));
+ }
+}
+
+/*
+ * Dump a method association for an event or property.
+ */
+static void DumpMethodAssociation(ILImage *image, FILE *outstream,
+ int flags,
ILMethod *method)
+{
+ ILDumpMethodType(outstream, image, ILMethod_Signature(method), flags,
+ ILMethod_Owner(method),
ILMethod_Name(method), 0);
+}
+
+/*
+ * Dump an event definition.
+ */
+static void Dump_EventDef(ILImage *image, FILE *outstream, int flags,
+ ILEvent *event)
+{
+ ILMethod *method;
+
+ /* Dump the event header */
+ fputs("\t.event ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ",
+ (unsigned long)(ILEvent_Token(event)));
+ }
+ ILDumpFlags(outstream, ILEvent_Attrs(event), ILEventDefinitionFlags, 0);
+ if(ILEvent_Type(event) != ILType_Invalid)
+ {
+ ILDumpType(outstream, image, ILEvent_Type(event), flags);
+ putc(' ', outstream);
+ }
+ ILDumpIdentifier(outstream, ILEvent_Name(event), 0, flags);
+ fputs("\n\t{\n", outstream);
+
+ /* Dump the custom attributes */
+ if(ILProgramItem_HasAttrs(event))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+
ILToProgramItem(event));
+ }
+
+ /* Dump the event methods */
+ if((method = ILEvent_AddOn(event)) != 0)
+ {
+ fputs("\t\t.addon ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+ if((method = ILEvent_RemoveOn(event)) != 0)
+ {
+ fputs("\t\t.removeon ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+ if((method = ILEvent_Fire(event)) != 0)
+ {
+ fputs("\t\t.fire ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+ if((method = ILEvent_Other(event)) != 0)
+ {
+ fputs("\t\t.other ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+
+ /* Dump the event footer */
+ fputs("\t}\n", outstream);
+}
+
+/*
+ * Dump a property definition.
+ */
+static void Dump_PropertyDef(ILImage *image, FILE *outstream, int flags,
+ ILProperty *property)
+{
+ ILMethod *method;
+
+ /* Dump the property header */
+ fputs("\t.property ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ",
+ (unsigned long)(ILProperty_Token(property)));
+ }
+ ILDumpFlags(outstream, ILProperty_Attrs(property),
+ ILPropertyDefinitionFlags, 0);
+
+ /* Dump the calling conventions from the get/set method,
+ because the property signature doesn't contain them */
+ if((method = ILProperty_Getter(property)) != 0)
+ {
+ ILDumpFlags(outstream, ILMethod_CallConv(method),
+ ILMethodCallConvFlags, 0);
+ }
+ else if((method = ILProperty_Setter(property)) != 0)
+ {
+ ILDumpFlags(outstream, ILMethod_CallConv(method),
+ ILMethodCallConvFlags, 0);
+ }
+
+ /* Dump the property type */
+ ILDumpMethodType(outstream, image, ILProperty_Signature(property),
flags,
+ 0, ILProperty_Name(property), 0);
+ fputs("\n\t{\n", outstream);
+
+ /* Dump the custom attributes */
+ if(ILProgramItem_HasAttrs(property))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+
ILToProgramItem(property));
+ }
+
+ /* Dump the property methods */
+ if((method = ILProperty_Getter(property)) != 0)
+ {
+ fputs("\t\t.get ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+ if((method = ILProperty_Setter(property)) != 0)
+ {
+ fputs("\t\t.set ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+ if((method = ILProperty_Other(property)) != 0)
+ {
+ fputs("\t\t.other ", outstream);
+ DumpMethodAssociation(image, outstream, flags, method);
+ putc('\n', outstream);
+ }
+
+ /* Dump the event footer */
+ fputs("\t}\n", outstream);
+}
+
+/*
+ * Dump a class name with generic parameter information.
+ */
+static void DumpClassName(FILE *outstream, ILImage *image,
+ ILClass *info, int flags, int
withNamespace)
+{
+ ILType *type;
+ ILUInt32 genericNum;
+ ILGenericPar *genPar;
+ const char *name;
+ ILProgramItem *constraint;
+ ILTypeSpec *spec;
+
+ /* Use a different approach if the class is a type specification */
+ type = ILClassGetSynType(info);
+ if(type)
+ {
+ ILDumpType(outstream, image, type, flags);
+ return;
+ }
+
+ /* Dump the main part of the class name */
+ if(withNamespace)
+ {
+ ILDumpClassName(outstream, image, info, flags);
+ }
+ else
+ {
+ ILDumpIdentifier(outstream, ILClass_Name(info), 0, flags);
+ }
+
+ /* Dump the generic parameters, if any are present */
+ genericNum = 0;
+ genPar = ILGenericParGetFromOwner(ILToProgramItem(info), genericNum);
+ if(genPar)
+ {
+ putc('<', outstream);
+ do
+ {
+ if(genericNum > 0)
+ {
+ fputs(", ", outstream);
+ }
+ constraint = ILGenericPar_Constraint(genPar);
+ if(constraint)
+ {
+ putc('(', outstream);
+ spec = ILProgramItemToTypeSpec(constraint);
+ if(spec)
+ {
+ ILDumpType(outstream, image,
ILTypeSpec_Type(spec), flags);
+ }
+ else
+ {
+ ILDumpType(outstream, image,
+
ILClassToType((ILClass *)constraint), flags);
+ }
+ putc(')', outstream);
+ }
+ name = ILGenericPar_Name(genPar);
+ if(name)
+ {
+ ILDumpIdentifier(outstream, name, 0, flags);
+ }
+ else
+ {
+ fprintf(outstream, "G_%d", (int)(genericNum +
1));
+ }
+ ++genericNum;
+ genPar = ILGenericParGetFromOwner
+ (ILToProgramItem(info), genericNum);
+ }
+ while(genPar != 0);
+ putc('>', outstream);
+ }
+}
+
+/*
+ * Dump information about a type definition and its nested classes.
+ */
+static void Dump_TypeAndNested(ILImage *image, FILE *outstream,
+ int flags, ILClass
*info)
+{
+ ILMember *member;
+ ILImplements *impl;
+ ILClass *interface;
+ ILNestedInfo *nested;
+ int first;
+ int isModule = 0;
+ ILClassLayout *layout;
+ unsigned long size;
+ ILOverride *over;
+ ILMethod *decl;
+ ILMethod *body;
+
+ /* Dump the namespace if this class is not nested */
+ if(!ILClass_NestedParent(info) && ILClass_Namespace(info))
+ {
+ fputs(".namespace ", outstream);
+ ILDumpIdentifier(outstream, ILClass_Namespace(info), 0, flags);
+ fputs("\n{\n", outstream);
+ }
+
+ /* Dump the type header, if it is not "<Module>" */
+ if(strcmp(ILClass_Name(info), "<Module>") != 0 ||
+ ILClass_Namespace(info) != 0)
+ {
+ fputs(".class ", outstream);
+ ILDumpFlags(outstream, ILClass_Attrs(info),
ILTypeDefinitionFlags, 0);
+ DumpClassName(outstream, image, info, flags, 0);
+ if(ILClass_Parent(info))
+ {
+ fputs(" extends ", outstream);
+ DumpClassName(outstream, image, ILClass_Parent(info),
flags, 1);
+ }
+ first = 1;
+ impl = 0;
+ while((impl = ILClassNextImplements(info, impl)) != 0)
+ {
+ interface = ILImplementsGetInterface(impl);
+ if(first)
+ {
+ fputs(" implements ", outstream);
+ first = 0;
+ }
+ else
+ {
+ fputs(", ", outstream);
+ }
+ DumpClassName(outstream, image, interface, flags, 1);
+ }
+ fputs("\n{\n", outstream);
+
+ /* Dump the security information, if any */
+ if((ILClass_Attrs(info) & IL_META_TYPEDEF_HAS_SECURITY) != 0)
+ {
+ ILDAsmDumpSecurity(image, outstream, (ILProgramItem
*)info, flags);
+ }
+
+ /* Dump the class layout information, if any */
+ layout = ILClassLayoutGetFromOwner(info);
+ if(layout)
+ {
+ size = (unsigned
long)(ILClassLayout_PackingSize(layout));
+ if(size != 0)
+ {
+ fprintf(outstream, "\t.pack %lu\n", size);
+ }
+ size = (unsigned long)(ILClassLayout_ClassSize(layout));
+ if(size != 0)
+ {
+ fprintf(outstream, "\t.size %lu\n", size);
+ }
+ }
+
+ /* Dump the custom attributes for the class */
+ if(ILProgramItem_HasAttrs(info))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+
ILToProgramItem(info));
+ }
+ }
+ else
+ {
+ isModule = 1;
+ if(ILClassNextMember(info, 0) != 0)
+ {
+ fputs("// .class ", outstream);
+ ILDumpFlags(outstream, ILClass_Attrs(info),
+ ILTypeDefinitionFlags, 0);
+ ILDumpClassName(outstream, image, info, flags);
+ fputs("\n// { \n", outstream);
+ }
+ }
+
+ /* Dump the nested classes */
+ nested = 0;
+ while((nested = ILClassNextNested(info, nested)) != 0)
+ {
+ Dump_TypeAndNested(image, outstream, flags,
+
ILNestedInfoGetChild(nested));
+ }
+
+ /* Dump the class members */
+ member = 0;
+ while((member = ILClassNextMember(info, member)) != 0)
+ {
+ switch(ILMemberGetKind(member))
+ {
+ case IL_META_MEMBERKIND_METHOD:
+ {
+ Dump_MethodDef(image, outstream, flags,
(ILMethod *)member);
+ }
+ break;
+
+ case IL_META_MEMBERKIND_FIELD:
+ {
+ Dump_FieldDef(image, outstream, flags, (ILField
*)member);
+ }
+ break;
+
+ case IL_META_MEMBERKIND_EVENT:
+ {
+ Dump_EventDef(image, outstream, flags, (ILEvent
*)member);
+ }
+ break;
+
+ case IL_META_MEMBERKIND_PROPERTY:
+ {
+ Dump_PropertyDef(image, outstream, flags,
(ILProperty *)member);
+ }
+ break;
+ }
+ }
+
+ /* Dump overrides that don't have bodies in this class */
+ over = 0;
+ while((over = (ILOverride *)ILClassNextMemberByKind
+ (info, (ILMember *)over,
IL_META_MEMBERKIND_OVERRIDE)) != 0)
+ {
+ body = ILOverride_Body(over);
+ if(ILMethod_Owner(body) != info)
+ {
+ decl = ILOverride_Decl(over);
+ fputs("\t.override ", outstream);
+ ILDumpClassName(outstream, image, ILMethod_Owner(decl),
flags);
+ fputs("::", outstream);
+ ILDumpIdentifier(outstream, ILMethod_Name(decl), 0,
flags);
+ fputs(" with ", outstream);
+ ILDumpMethodType(outstream, image,
ILMethod_Signature(body), flags,
+ ILMethod_Owner(body),
ILMethod_Name(body), body);
+ putc('\n', outstream);
+ }
+ }
+
+ /* Dump the type footer, if it is not "<Module>" */
+ if(!isModule)
+ {
+ fputs("}\n", outstream);
+ }
+ else if(ILClassNextMember(info, 0) != 0)
+ {
+ fputs("// }\n", outstream);
+ }
+
+ /* Dump the namespace footer if this class is not nested */
+ if(!ILClass_NestedParent(info) && ILClass_Namespace(info))
+ {
+ fputs("}\n", outstream);
+ }
+}
+
+/*
+ * Dump information about a type definition.
+ */
+static void Dump_TypeDef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token, ILClass
*info,
+ unsigned long refToken)
+{
+ /* Ignore the type if it is nested: we'll get it elsewhere */
+ if(ILClass_IsPublic(info) || ILClass_IsPrivate(info))
+ {
+ Dump_TypeAndNested(image, outstream, flags, info);
+ }
+}
+
+void ILDAsmDumpClasses(ILImage *image, FILE *outstream, int flags)
+{
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_TYPE_DEF,
+ (ILDAsmWalkFunc)Dump_TypeDef, 0);
+}
+
+#ifdef __cplusplus
+};
+#endif
Index: dumpasm/dump_data.c
===================================================================
RCS file: dumpasm/dump_data.c
diff -N dumpasm/dump_data.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_data.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,184 @@
+/*
+ * dump_data.c - Dump ".data" blocks.
+ *
+ * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+#include "il_system.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Dump the contents of a data section, with labels inserted
+ * wherever fields reference the data.
+ */
+static void DumpData(FILE *outstream, ILImage *image, const char *heading,
+ unsigned long rva, void *addr,
unsigned long len,
+ unsigned long *fieldRVAs, unsigned
long numFieldRVAs)
+{
+ while(len > 0)
+ {
+ /* Scan for the next field >= the current address */
+ while(numFieldRVAs > 0 && *fieldRVAs < rva)
+ {
+ ++fieldRVAs;
+ --numFieldRVAs;
+ }
+ if(numFieldRVAs > 0 && *fieldRVAs >= (rva + len))
+ {
+ numFieldRVAs = 0;
+ }
+
+ /* Dump data before the next field */
+ if(numFieldRVAs > 0 && *fieldRVAs != rva)
+ {
+ fprintf(outstream, "%s D_0x%08lX = bytearray", heading,
rva);
+ ILDAsmDumpBinaryBlob(outstream, image, addr,
+
(ILUInt32)(*fieldRVAs - rva));
+ putc('\n', outstream);
+ addr = (void *)(((unsigned char *)addr) + (*fieldRVAs -
rva));
+ len -= (*fieldRVAs - rva);
+ rva = *fieldRVAs;
+ }
+
+ /* Dump the field or the remaining data */
+ fprintf(outstream, "%s D_0x%08lX = bytearray", heading, rva);
+ if(numFieldRVAs > 1)
+ {
+ ILDAsmDumpBinaryBlob(outstream, image, addr,
+
(ILUInt32)(fieldRVAs[1] - rva));
+ addr = (void *)(((unsigned char *)addr) + (fieldRVAs[1]
- rva));
+ len -= (fieldRVAs[1] - rva);
+ rva = fieldRVAs[1];
+ }
+ else
+ {
+ ILDAsmDumpBinaryBlob(outstream, image, addr, len);
+ len = 0;
+ }
+ putc('\n', outstream);
+ }
+}
+
+void ILDAsmDumpDataSections(FILE *outstream, ILImage *image)
+{
+ unsigned long *fieldRVAs;
+ unsigned long numFieldRVAs;
+ unsigned long posn;
+ unsigned long posn2;
+ unsigned long temp;
+ ILFieldRVA *rva;
+ void *dataAddr;
+ unsigned long dataRVA;
+ unsigned long dataLen;
+ void *tlsAddr;
+ unsigned long tlsRVA;
+ unsigned long tlsLen;
+
+ /* Collect all field RVA values so that we know where to
+ insert the data labels */
+ numFieldRVAs = ILImageNumTokens(image, IL_META_TOKEN_FIELD_RVA);
+ if(numFieldRVAs > 0)
+ {
+ fieldRVAs = (unsigned long *)ILMalloc
+ (sizeof(unsigned long) * numFieldRVAs);
+ if(!fieldRVAs)
+ {
+ numFieldRVAs = 0;
+ }
+ else
+ {
+ rva = 0;
+ posn = 0;
+ while((rva = (ILFieldRVA *)ILImageNextToken
+ (image,
IL_META_TOKEN_FIELD_RVA, rva)) != 0)
+ {
+ fieldRVAs[posn++] = ILFieldRVA_RVA(rva);
+ }
+ }
+ }
+ else
+ {
+ fieldRVAs = 0;
+ }
+
+ /* Sort the RVA list into ascending order */
+ if(numFieldRVAs > 1)
+ {
+ for(posn = 0; posn < (numFieldRVAs - 1); ++posn)
+ {
+ for(posn2 = posn + 1; posn2 < numFieldRVAs; ++posn2)
+ {
+ if(fieldRVAs[posn] > fieldRVAs[posn2])
+ {
+ temp = fieldRVAs[posn];
+ fieldRVAs[posn] = fieldRVAs[posn2];
+ fieldRVAs[posn2] = temp;
+ }
+ }
+ }
+ }
+
+ /* Find the extents of the ".data" and ".tls" sections */
+ if(ILImageGetSection(image, IL_SECTION_DATA, &dataAddr, &dataLen))
+ {
+ dataRVA = ILImageGetSectionAddr(image, IL_SECTION_DATA);
+ }
+ else
+ {
+ dataAddr = 0;
+ dataLen = 0;
+ dataRVA = 0;
+ }
+ if(ILImageGetSection(image, IL_SECTION_TLS, &tlsAddr, &tlsLen))
+ {
+ tlsRVA = ILImageGetSectionAddr(image, IL_SECTION_TLS);
+ }
+ else
+ {
+ tlsAddr = 0;
+ tlsLen = 0;
+ tlsRVA = 0;
+ }
+
+ /* Dump the ".data" section */
+ if(dataLen > 0)
+ {
+ DumpData(outstream, image, ".data", dataRVA, dataAddr, dataLen,
+ fieldRVAs, numFieldRVAs);
+ }
+
+ /* Dump the ".tls" section */
+ if(tlsLen > 0)
+ {
+ DumpData(outstream, image, ".data tls", tlsRVA, tlsAddr, tlsLen,
+ fieldRVAs, numFieldRVAs);
+ }
+
+ /* Free the "fieldRVAs" array and exit */
+ if(fieldRVAs)
+ {
+ ILFree(fieldRVAs);
+ }
+}
+
+#ifdef __cplusplus
+};
+#endif
Index: dumpasm/dump_global.c
===================================================================
RCS file: dumpasm/dump_global.c
diff -N dumpasm/dump_global.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_global.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,400 @@
+/*
+ * dump_global.c - Disassemble global information.
+ *
+ * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Dump information about a module.
+ */
+static void Dump_Module(ILImage *image, FILE *outstream, int flags,
+ unsigned long token, ILModule
*module,
+ unsigned long refToken)
+{
+ ILUInt32 generation;
+ const unsigned char *guid;
+ fputs(".module ", outstream);
+ ILDumpIdentifier(outstream, ILModule_Name(module), 0, flags);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, " /*%08lX*/", token);
+ }
+ generation = ILModuleGetGeneration(module);
+ if(generation != 0)
+ {
+ fprintf(outstream, "\n// Generation: %lu",
+ (unsigned long)generation);
+ }
+ fputs("\n// MVID: ", outstream);
+ ILDumpGUID(outstream, ILModuleGetMVID(module));
+ guid = ILModuleGetEncId(module);
+ if(guid)
+ {
+ fputs("\n// EncId: ", outstream);
+ ILDumpGUID(outstream, guid);
+ }
+ guid = ILModuleGetEncBaseId(module);
+ if(guid)
+ {
+ fputs("\n// EncBaseId: ", outstream);
+ ILDumpGUID(outstream, guid);
+ }
+ putc('\n', outstream);
+ if(ILProgramItem_HasAttrs(module))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 0,
+
ILToProgramItem(module));
+ }
+}
+
+/*
+ * Dump information about a module reference.
+ */
+static void Dump_ModuleRef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILModule *module,
+ unsigned long refToken)
+{
+ fputs(".module extern ", outstream);
+ ILDumpIdentifier(outstream, ILModule_Name(module), 0, flags);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, " /*%08lX*/", token);
+ }
+ putc('\n', outstream);
+ if(ILProgramItem_HasAttrs(module))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 0,
+
ILToProgramItem(module));
+ }
+}
+
+/*
+ * Dump information about an OS definition.
+ */
+static void Dump_OSDef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token, ILOSInfo
*osinfo,
+ unsigned long refToken)
+{
+ fprintf(outstream, "\t.os %lu .ver %lu:%lu\n",
+ (unsigned long)(ILOSInfo_Identifier(osinfo)),
+ (unsigned long)(ILOSInfo_Major(osinfo)),
+ (unsigned long)(ILOSInfo_Minor(osinfo)));
+}
+
+/*
+ * Dump information about a processor definition.
+ */
+static void Dump_ProcessorDef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILProcessorInfo *procinfo,
+ unsigned long
refToken)
+{
+ fprintf(outstream, "\t.processor %lu\n",
+ (unsigned long)ILProcessorInfo_Number(procinfo));
+}
+
+/*
+ * Dump information about an assembly.
+ */
+static void Dump_Assembly(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILAssembly *assem,
+ unsigned long refToken)
+{
+ const ILUInt16 *version;
+ const void *orig;
+ unsigned long origLen;
+ fputs(".assembly ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ", token);
+ }
+ ILDumpFlags(outstream, ILAssembly_Attrs(assem), ILAssemblyFlags, 0);
+ ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
+ fputs("\n{\n", outstream);
+ ILDAsmDumpSecurity(image, outstream, (ILProgramItem *)assem, flags);
+ if(ILAssembly_HashAlg(assem) != 0)
+ {
+ fprintf(outstream, "\t.hash algorithm 0x%08lX\n",
+ (unsigned long)(ILAssembly_HashAlg(assem)));
+ }
+ version = ILAssemblyGetVersion(assem);
+ fprintf(outstream, "\t.ver %lu:%lu:%lu:%lu\n",
+ (unsigned long)(version[0]), (unsigned
long)(version[1]),
+ (unsigned long)(version[2]), (unsigned
long)(version[3]));
+ if((orig = ILAssemblyGetOriginator(assem, &origLen)) != 0)
+ {
+ fputs("\t.publickey =", outstream);
+ ILDAsmDumpBinaryBlob(outstream, image, orig, origLen);
+ putc('\n', outstream);
+ }
+ if(ILAssembly_Locale(assem))
+ {
+ fputs("\t.locale ", outstream);
+ ILDumpString(outstream, ILAssembly_Locale(assem));
+ putc('\n', outstream);
+ }
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_OS_DEF,
+ (ILDAsmWalkFunc)Dump_OSDef, 0);
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_PROCESSOR_DEF,
+ (ILDAsmWalkFunc)Dump_ProcessorDef, 0);
+ if(ILProgramItem_HasAttrs(assem))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+
ILToProgramItem(assem));
+ }
+ fputs("}\n", outstream);
+}
+
+/*
+ * Dump information about an OS reference.
+ */
+static void Dump_OSRef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token, ILOSInfo
*osinfo,
+ unsigned long refToken)
+{
+ if(ILProgramItem_Token(ILOSInfo_Assembly(osinfo)) == refToken)
+ {
+ fprintf(outstream, "\t.os %lu .ver %lu:%lu\n",
+ (unsigned long)(ILOSInfo_Identifier(osinfo)),
+ (unsigned long)(ILOSInfo_Major(osinfo)),
+ (unsigned long)(ILOSInfo_Minor(osinfo)));
+ }
+}
+
+/*
+ * Dump information about a processor reference.
+ */
+static void Dump_ProcessorRef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILProcessorInfo *procinfo,
+ unsigned long
refToken)
+{
+ if(ILProgramItem_Token(ILProcessorInfo_Assembly(procinfo)) == refToken)
+ {
+ fprintf(outstream, "\t.processor %lu\n",
+ (unsigned
long)(ILProcessorInfo_Number(procinfo)));
+ }
+}
+
+/*
+ * Dump information about an assembly reference.
+ */
+static void Dump_AssemblyRef(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILAssembly *assem,
+ unsigned long refToken)
+{
+ const ILUInt16 *version;
+ const void *orig;
+ unsigned long origLen;
+ fputs(".assembly extern ", outstream);
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, "/*%08lX*/ ", token);
+ }
+ ILDumpFlags(outstream, ILAssembly_RefAttrs(assem),
+ ILAssemblyRefFlags, 0);
+ ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
+ fputs("\n{\n", outstream);
+ version = ILAssemblyGetVersion(assem);
+ fprintf(outstream, "\t.ver %lu:%lu:%lu:%lu\n",
+ (unsigned long)(version[0]), (unsigned
long)(version[1]),
+ (unsigned long)(version[2]), (unsigned
long)(version[3]));
+ if((orig = ILAssemblyGetOriginator(assem, &origLen)) != 0)
+ {
+ if(ILAssembly_HasFullOriginator(assem))
+ {
+ fputs("\t.publickey =", outstream);
+ }
+ else
+ {
+ fputs("\t.publickeytoken =", outstream);
+ }
+ ILDAsmDumpBinaryBlob(outstream, image, orig, origLen);
+ putc('\n', outstream);
+ }
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_OS_REF,
+ (ILDAsmWalkFunc)Dump_OSRef, token);
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_PROCESSOR_REF,
+ (ILDAsmWalkFunc)Dump_ProcessorRef,
token);
+ if(ILProgramItem_HasAttrs(assem))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+
ILToProgramItem(assem));
+ }
+ fputs("}\n", outstream);
+}
+
+/*
+ * Dump information about a file declaration.
+ */
+static void Dump_File(ILImage *image, FILE *outstream, int flags,
+ unsigned long token, ILFileDecl *decl,
+ unsigned long refToken)
+{
+ const void *hash;
+ unsigned long len;
+ fputs(".file ", outstream);
+ ILDumpFlags(outstream, ILFileDecl_Attrs(decl), ILFileFlags, 0);
+ ILDumpIdentifier(outstream, ILFileDecl_Name(decl), 0, flags);
+ if((hash = ILFileDeclGetHash(decl, &len)) != 0)
+ {
+ fputs(" .hash =", outstream);
+ ILDAsmDumpBinaryBlob(outstream, image, hash, len);
+ }
+ putc('\n', outstream);
+}
+
+/*
+ * Dump information about a manifest resource declaration.
+ */
+static void Dump_ManifestRes(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILManifestRes *res,
+ unsigned long refToken)
+{
+ ILFileDecl *decl;
+ ILAssembly *assem;
+ fputs(".mresource ", outstream);
+ ILDumpFlags(outstream, ILManifestRes_Attrs(res), ILManifestResFlags, 0);
+ ILDumpIdentifier(outstream, ILManifestRes_Name(res), 0, flags);
+ fputs("\n{\n", outstream);
+ if((decl = ILManifestResGetOwnerFile(res)) != 0)
+ {
+ fputs("\t.file ", outstream);
+ ILDumpIdentifier(outstream, ILFileDecl_Name(decl), 0, flags);
+ fprintf(outstream, " at 0x%08lu\n",
+ (unsigned long)(ILFileDecl_Attrs(decl)));
+ }
+ else if((assem = ILManifestResGetOwnerAssembly(res)) != 0)
+ {
+ fputs("\t.assembly extern ", outstream);
+ ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
+ putc('\n', outstream);
+ }
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
+ ILToProgramItem(res));
+ fputs("}\n", outstream);
+}
+
+/*
+ * Dump information about a exported type declaration.
+ */
+static void Dump_ExportedType(ILImage *image, FILE *outstream, int flags,
+ unsigned long token,
ILExportedType *type,
+ unsigned long
refToken)
+{
+ ILProgramItem *scope;
+ ILFileDecl *decl;
+ ILAssembly *assem;
+ ILExportedType *expType;
+
+ /* Dump the export heading */
+ fputs(".class extern ", outstream);
+ ILDumpFlags(outstream, ILExportedType_Attrs(type),
+ ILExportedTypeDefinitionFlags, 0);
+ ILDumpIdentifier(outstream, ILExportedType_Name(type),
+ ILExportedType_Namespace(type), flags);
+ fputs("\n{\n", outstream);
+
+ /* Dump the scope */
+ scope = ILExportedType_Scope(type);
+ if((decl = ILProgramItemToFileDecl(scope)) != 0)
+ {
+ fputs("\t.file ", outstream);
+ ILDumpIdentifier(outstream, ILFileDecl_Name(decl), 0, flags);
+ putc('\n', outstream);
+ }
+ else if((assem = ILProgramItemToAssembly(scope)) != 0)
+ {
+ fputs("\t.assembly extern ", outstream);
+ ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
+ putc('\n', outstream);
+ }
+ else if((expType = ILProgramItemToExportedType(scope)) != 0)
+ {
+ fputs("\t.comtype ", outstream);
+ ILDumpIdentifier(outstream, ILExportedType_Name(expType),
+
ILExportedType_Namespace(expType), flags);
+ putc('\n', outstream);
+ }
+
+ /* Dump the class identifier in the foreign scope */
+ fprintf(outstream, "\t.class 0x%08lx\n",
+ (unsigned long)(ILExportedType_Id(type)));
+
+ /* Dump any custom attributes associated with the exported type */
+ if(ILProgramItem_HasAttrs(type))
+ {
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 0,
+
ILToProgramItem(type));
+ }
+
+ /* Dump the export footer */
+ fputs("}\n", outstream);
+}
+
+void ILDAsmDumpGlobal(ILImage *image, FILE *outstream, int flags)
+{
+ /* Dump module references */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_MODULE_REF,
+ (ILDAsmWalkFunc)Dump_ModuleRef, 0);
+
+ /* Dump assembly reference information */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_ASSEMBLY_REF,
+ (ILDAsmWalkFunc)Dump_AssemblyRef, 0);
+
+ /* Dump file information */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_FILE,
+ (ILDAsmWalkFunc)Dump_File, 0);
+
+ /* Dump assembly information */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_ASSEMBLY,
+ (ILDAsmWalkFunc)Dump_Assembly, 0);
+
+ /* Dump manifest resource definitions */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_MANIFEST_RESOURCE,
+ (ILDAsmWalkFunc)Dump_ManifestRes, 0);
+
+ /* Dump module definitions */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_MODULE,
+ (ILDAsmWalkFunc)Dump_Module, 0);
+
+ /* Dump exported types */
+ ILDAsmWalkTokens(image, outstream, flags,
+ IL_META_TOKEN_EXPORTED_TYPE,
+ (ILDAsmWalkFunc)Dump_ExportedType, 0);
+
+ /* Dump the ".data" and ".tls" sections */
+ ILDAsmDumpDataSections(outstream, image);
+}
+
+#ifdef __cplusplus
+};
+#endif
Index: dumpasm/dump_java.c
===================================================================
RCS file: dumpasm/dump_java.c
diff -N dumpasm/dump_java.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_java.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,868 @@
+/*
+ * dump_java.c - Disassemble Java method contents.
+ *
+ * Copyright (C) 2002 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+#include "il_jopcodes.h"
+#include "il_system.h"
+#include "il_opcodes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef IL_CONFIG_JAVA
+
+/* "image/jopcodes.c" */
+extern ILOpcodeInfo const ILJavaOpcodeTable[256];
+
+/*
+ * Read big-endian quantities of various sizes.
+ */
+#define IL_BREAD_INT16(buf) ((ILInt16)(_IL_READ_BYTE((buf), 1) | \
+
_IL_READ_BYTE_SHIFT((buf), 0, 8)))
+#define IL_BREAD_UINT16(buf) ((ILUInt16)(_IL_READ_BYTE((buf), 1) | \
+
_IL_READ_BYTE_SHIFT((buf), 0, 8)))
+#define IL_BREAD_INT32(buf) ((ILInt32)(_IL_READ_BYTE((buf), 3) | \
+
_IL_READ_BYTE_SHIFT((buf), 2, 8) | \
+
_IL_READ_BYTE_SHIFT((buf), 1, 16) | \
+
_IL_READ_BYTE_SHIFT((buf), 0, 24)))
+#define IL_BREAD_UINT32(buf) ((ILUInt32)(_IL_READ_BYTE((buf), 3) | \
+
_IL_READ_BYTE_SHIFT((buf), 2, 8) | \
+
_IL_READ_BYTE_SHIFT((buf), 1, 16) | \
+
_IL_READ_BYTE_SHIFT((buf), 0, 24)))
+#define IL_BREAD_INT64(buf) \
+ (((ILInt64)(IL_BREAD_UINT32((buf) + 4))) | \
+ (((ILInt64)(IL_BREAD_INT32((buf)))) << 32))
+#define IL_BREAD_UINT64(buf) \
+ (((ILUInt64)(IL_BREAD_UINT32((buf) + 4))) | \
+ (((ILUInt64)(IL_BREAD_UINT32((buf)))) << 32))
+
+/*
+ * Determine the size of a Java instruction. Returns zero
+ * if the instruction is invalid.
+ */
+static unsigned long JavaInsnSize(unsigned char *buf, unsigned long size,
+ unsigned long
offset)
+{
+ unsigned long len;
+ ILInt32 tempa;
+ ILInt32 tempb;
+ ILUInt32 swsize;
+ if(*buf == JAVA_OP_WIDE)
+ {
+ /* Wide instruction */
+ if(size < 2)
+ {
+ return 0;
+ }
+ switch(buf[1])
+ {
+ case JAVA_OP_ILOAD:
+ case JAVA_OP_FLOAD:
+ case JAVA_OP_ALOAD:
+ case JAVA_OP_LLOAD:
+ case JAVA_OP_DLOAD:
+ case JAVA_OP_ISTORE:
+ case JAVA_OP_FSTORE:
+ case JAVA_OP_ASTORE:
+ case JAVA_OP_LSTORE:
+ case JAVA_OP_DSTORE:
+ case JAVA_OP_RET:
+ {
+ if(size < 4)
+ return 0;
+ else
+ return 4;
+ }
+ /* Not reached */
+
+ case JAVA_OP_IINC:
+ {
+ if(size < 6)
+ return 0;
+ else
+ return 6;
+ }
+ /* Not reached */
+ }
+ return 0;
+ }
+ else if(*buf == JAVA_OP_LOOKUPSWITCH)
+ {
+ /* Lookup switch instruction */
+ len = 1;
+ while(((offset + len) & 3) != 0)
+ {
+ ++len;
+ }
+ if(size < (len + 8))
+ {
+ return 0;
+ }
+ swsize = IL_BREAD_UINT32(buf + len + 4);
+ if(swsize > (ILInt32)0x20000000)
+ {
+ return 0;
+ }
+ len += 8 + swsize * 8;
+ if(size < len)
+ {
+ return 0;
+ }
+ return len;
+ }
+ else if(*buf == JAVA_OP_TABLESWITCH)
+ {
+ /* Table switch instruction */
+ len = 1;
+ while(((offset + len) & 3) != 0)
+ {
+ ++len;
+ }
+ if(size < (len + 12))
+ {
+ return 0;
+ }
+ tempa = IL_BREAD_INT32(buf + len + 4);
+ tempb = IL_BREAD_INT32(buf + len + 8);
+ if(tempa > tempb ||
+ (swsize = (ILUInt32)(tempb - tempa + 1)) >
(ILUInt32)0x20000000)
+ {
+ return 0;
+ }
+ len += 12 + swsize * 4;
+ if(size < len)
+ {
+ return 0;
+ }
+ return len;
+ }
+ else if(ILJavaOpcodeTable[*buf].args == IL_OPCODE_ARGS_INVALID)
+ {
+ /* Invalid instruction */
+ return 0;
+ }
+ else
+ {
+ /* Ordinary instruction */
+ return ILJavaOpcodeTable[*buf].size;
+ }
+}
+
+/*
+ * Mark a destination jump point.
+ */
+#define MarkDest(dest) \
+ do { \
+ unsigned long _dest = (unsigned long)(dest); \
+ if(_dest < size) \
+ { \
+ jumpPoints[_dest / 32] |= \
+ (ILUInt32)(1L << (_dest % 32));
\
+ } \
+ } while (0)
+
+/*
+ * Dump all Java instructions in a given buffer. Returns zero
+ * if there is something wrong with the buffer's format.
+ */
+static int DumpJavaInstructions(ILImage *image, ILClass *classInfo,
+ FILE *outstream,
+ unsigned char
*buf, unsigned long size,
+ unsigned long addr,
ILException *clauses,
+ int flags)
+{
+ ILUInt32 *jumpPoints;
+ int result = 0;
+ unsigned char *temp;
+ unsigned char *temp2;
+ unsigned long tsize;
+ unsigned long offset;
+ unsigned long dest;
+ unsigned long isize;
+ unsigned long args;
+ const ILOpcodeInfo *info;
+ int argType;
+ unsigned long numItems;
+ unsigned long item;
+ int isWide;
+
+ /* Allocate a helper array to mark jump points within the code */
+ jumpPoints = (ILUInt32 *)ILCalloc(((size + 3) & ~3), 1);
+ if(!jumpPoints)
+ {
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+ }
+
+ /* Mark the entry point to the method so we get a label for it */
+ jumpPoints[0] |= (ILUInt32)1;
+
+ /* Mark the position of exception clauses */
+ while(clauses != 0)
+ {
+ MarkDest(clauses->tryOffset);
+ MarkDest(clauses->tryOffset + clauses->tryLength);
+ MarkDest(clauses->handlerOffset);
+ clauses = clauses->next;
+ }
+
+ /* Scan the instruction list to locate jump points */
+ temp = buf;
+ tsize = size;
+ offset = 0;
+ while(tsize > 0)
+ {
+ isize = JavaInsnSize(temp, tsize, offset);
+ if(!isize)
+ {
+ fprintf(outstream, "\t\t// unknown instruction
0x%02X\n",
+ ((int)(temp[0])) & 0xFF);
+ goto cleanup;
+ }
+ info = &(ILJavaOpcodeTable[((int)(temp[0])) & 0xFF]);
+ if(info->args == IL_OPCODE_ARGS_SHORT_JUMP)
+ {
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT16(temp + 1)));
+ MarkDest(dest);
+ }
+ else if(info->args == IL_OPCODE_ARGS_LONG_JUMP)
+ {
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp + 1)));
+ MarkDest(dest);
+ }
+ else if(info->args == IL_OPCODE_ARGS_SWITCH)
+ {
+ /* Align the switch instruction's arguments */
+ args = 1;
+ while(((offset + args) & 3) != 0)
+ {
+ ++args;
+ }
+
+ /* Mark the default label */
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp + args)));
+ MarkDest(dest);
+
+ /* Process the bulk of the switch */
+ if(temp[0] == JAVA_OP_TABLESWITCH)
+ {
+ /* Mark all of the labels in a table-based
switch */
+ item = (unsigned long)(IL_BREAD_INT32(temp +
args + 8) -
+
IL_BREAD_INT32(temp + args + 4) + 1);
+ temp2 = temp + args + 12;
+ while(item > 0)
+ {
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp2)));
+ MarkDest(dest);
+ --item;
+ temp2 += 4;
+ }
+ }
+ else
+ {
+ /* Mark all of the labels in a lookup-based
switch */
+ item = (unsigned long)(IL_BREAD_UINT32(temp +
args + 4));
+ temp2 = temp + args + 8 + 4;
+ while(item > 0)
+ {
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp2)));
+ MarkDest(dest);
+ --item;
+ temp2 += 8;
+ }
+ }
+ }
+ offset += isize;
+ temp += isize;
+ tsize -= isize;
+ }
+
+ /* Dump the instructions */
+ temp = buf;
+ tsize = size;
+ offset = 0;
+ while(tsize > 0)
+ {
+ /* If this is a jump point, then print a label for it */
+ if((jumpPoints[offset / 32] & (ILUInt32)(1L << (offset % 32)))
!= 0)
+ {
+ fprintf(outstream, "\t?L%lx:\n", offset + addr);
+ }
+
+ /* Extract the instruction from the method input stream */
+ isize = JavaInsnSize(temp, tsize, offset);
+ info = &(ILJavaOpcodeTable[((int)(temp[0])) & 0xFF]);
+ if(*temp == JAVA_OP_WIDE)
+ {
+ /* Process a wide instruction */
+ info = &(ILJavaOpcodeTable[((int)(temp[1])) & 0xFF]);
+ isWide = 1;
+ args = 2;
+ }
+ else
+ {
+ /* Process an ordinary instruction */
+ isWide = 0;
+ args = 1;
+ }
+
+ /* Dump the instruction based on its argument type */
+ argType = info->args;
+ putc('\t', outstream);
+ putc('\t', outstream);
+ fputs(info->name, outstream);
+ if(argType != IL_OPCODE_ARGS_INVALID &&
+ argType != IL_OPCODE_ARGS_NONE)
+ {
+ numItems = (unsigned long)(strlen(info->name));
+ while(numItems < 10)
+ {
+ putc(' ', outstream);
+ ++numItems;
+ }
+ putc(' ', outstream);
+ }
+ switch(argType)
+ {
+ case IL_OPCODE_ARGS_INVALID: break;
+ case IL_OPCODE_ARGS_NONE: break;
+
+ case IL_OPCODE_ARGS_INT8:
+ {
+ fprintf(outstream, "%d",
(int)(ILInt8)(temp[args]));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_INT16:
+ {
+ fprintf(outstream, "%d",
+ (int)(ILInt16)(IL_BREAD_UINT16(temp +
args)));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_TOKEN:
+ case IL_OPCODE_ARGS_CALL:
+ {
+ /* An instruction that takes a constant pool
entry argument */
+ if(temp[0] == JAVA_OP_LDC)
+ {
+ item = (unsigned long)(temp[args]);
+ }
+ else
+ {
+ item = (unsigned
long)(IL_BREAD_UINT16(temp + args));
+ }
+ switch(ILJavaGetConstType(classInfo,
(ILUInt32)item))
+ {
+ case JAVA_CONST_UTF8:
+ {
+ const char *str;
+ ILUInt32 len;
+ str = ILJavaGetUTF8String
+ (classInfo,
(ILUInt32)item, &len);
+ if(str && len)
+ {
+
ILDumpStringLen(outstream, str, (int)len);
+ }
+ else
+ {
+ fputs("\"\"",
outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_INTEGER:
+ {
+ ILInt32 value;
+ if(ILJavaGetInteger(classInfo,
(ILUInt32)item, &value))
+ {
+ fprintf(outstream,
"%ld", (long)value);
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_FLOAT:
+ {
+ ILFloat value;
+ unsigned char buf[4];
+ if(ILJavaGetFloat(classInfo,
(ILUInt32)item, &value))
+ {
+ IL_WRITE_FLOAT(buf,
value);
+ fprintf(outstream,
"float32(0x%02X%02X%02X%02X)",
+
(((int)(buf[3])) & 0xFF),
+
(((int)(buf[2])) & 0xFF),
+
(((int)(buf[1])) & 0xFF),
+
(((int)(buf[0])) & 0xFF));
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_LONG:
+ {
+ ILInt64 value;
+ if(ILJavaGetLong(classInfo,
(ILUInt32)item, &value))
+ {
+ fprintf(outstream,
"0x%08lX%08lX",
+
(long)((value >> 32) & (long)0xFFFFFFFF),
+
(long)(value & (long)0xFFFFFFFF));
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_DOUBLE:
+ {
+ ILDouble value;
+ unsigned char buf[8];
+ if(ILJavaGetDouble(classInfo,
(ILUInt32)item, &value))
+ {
+ IL_WRITE_DOUBLE(buf,
value);
+ fprintf(outstream,
+
"float64(0x%02X%02X%02X%02X%02X%02X%02X%02X)",
+
(((int)(buf[7])) & 0xFF),
+
(((int)(buf[6])) & 0xFF),
+
(((int)(buf[5])) & 0xFF),
+
(((int)(buf[4])) & 0xFF),
+
(((int)(buf[3])) & 0xFF),
+
(((int)(buf[2])) & 0xFF),
+
(((int)(buf[1])) & 0xFF),
+
(((int)(buf[0])) & 0xFF));
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_CLASS:
+ {
+ ILClass *ref;
+ ref = ILJavaGetClass(classInfo,
(ILUInt32)item, 1);
+ if(ref)
+ {
+
ILDumpClassName(outstream, image, ref, flags);
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_STRING:
+ {
+ const char *str;
+ ILUInt32 len;
+ str =
ILJavaGetString(classInfo, (ILUInt32)item, &len);
+ if(str && len)
+ {
+
ILDumpStringLen(outstream, str, (int)len);
+ }
+ else
+ {
+ fputs("\"\"",
outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_FIELDREF:
+ {
+ ILField *field;
+ ILClass *info;
+ field =
ILJavaGetField(classInfo, (ILUInt32)item, 1,
+
(temp[0] == JAVA_OP_GETSTATIC ||
+
temp[0] == JAVA_OP_PUTSTATIC));
+ if(field)
+ {
+ ILDumpType(outstream,
image,
+
ILField_Type(field), flags);
+ putc(' ', outstream);
+ info =
ILField_Owner(field);
+
if(ILClassIsValueType(info))
+ {
+
fputs("valuetype ", outstream);
+ }
+ else
+ {
+ fputs("class ",
outstream);
+ }
+
ILDumpClassName(outstream, image, info, flags);
+ fputs("::", outstream);
+
ILDumpIdentifier(outstream,
+
ILField_Name(field), 0, flags);
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ case JAVA_CONST_METHODREF:
+ {
+ ILMethod *method;
+ method =
ILJavaGetMethod(classInfo, (ILUInt32)item, 1,
+
(temp[0] == JAVA_OP_INVOKESTATIC));
+ if(method)
+ {
+
ILDumpMethodType(outstream, image,
+
ILMethod_Signature(method), flags,
+
ILMethod_Owner(method),
+
ILMethod_Name(method),
+
method);
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ break;
+
+ default:
+ {
+ fputs("??", outstream);
+ }
+ break;
+ }
+ }
+ break;
+
+ case IL_OPCODE_ARGS_NEW:
+ {
+ /* "newarray" instruction */
+ switch(temp[args])
+ {
+ case JAVA_ARRAY_OF_BOOL:
+ {
+ fputs("bool", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_CHAR:
+ {
+ fputs("char", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_FLOAT:
+ {
+ fputs("float32", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_DOUBLE:
+ {
+ fputs("float64", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_BYTE:
+ {
+ fputs("int8", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_SHORT:
+ {
+ fputs("int16", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_INT:
+ {
+ fputs("int32", outstream);
+ }
+ break;
+
+ case JAVA_ARRAY_OF_LONG:
+ {
+ fputs("int64", outstream);
+ }
+ break;
+
+ default:
+ {
+ fprintf(outstream, "%d",
((int)(temp[args])) & 0xFF);
+ }
+ break;
+ }
+ }
+ break;
+
+ case IL_OPCODE_ARGS_SHORT_VAR:
+ {
+ if(!isWide)
+ {
+ fprintf(outstream, "%d",
((int)(temp[args])) & 0xFF);
+ }
+ else
+ {
+ fprintf(outstream, "%d",
+
((int)(IL_BREAD_UINT16(temp + args))));
+ }
+ }
+ break;
+
+ case IL_OPCODE_ARGS_SHORT_JUMP:
+ {
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT16(temp + 1)));
+ fprintf(outstream, "?L%lx", dest + addr);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_LONG_JUMP:
+ {
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_UINT32(temp + 1)));
+ fprintf(outstream, "?L%lx", dest + addr);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_CALLI:
+ {
+ /* Dump a call to an interface method */
+ ILMethod *method;
+ item = (unsigned long)(IL_BREAD_UINT16(temp +
args));
+ method = ILJavaGetMethod(classInfo,
(ILUInt32)item, 1, 0);
+ if(method)
+ {
+ ILDumpMethodType(outstream, image,
+
ILMethod_Signature(method), flags,
+
ILMethod_Owner(method),
+
ILMethod_Name(method),
+
method);
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ fprintf(outstream, " %d",
(int)(ILUInt8)(temp[args + 2]));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_SWITCH:
+ {
+ /* Align the switch instruction's arguments */
+ while(((offset + args) & 3) != 0)
+ {
+ ++args;
+ }
+
+ /* Output the default label */
+ dest = (unsigned long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp + args)));
+ fprintf(outstream, "?L%lx (", dest + addr);
+
+ /* Dump the bulk of the switch instruction */
+ if(temp[0] == JAVA_OP_TABLESWITCH)
+ {
+ /* Dump the base value for the
table-based switch */
+ fprintf(outstream, "%ld : ",
+ (long)(IL_BREAD_INT32(temp
+ args + 4)));
+
+ /* Determine the number of items */
+ numItems = (unsigned long)
+ (IL_BREAD_INT32(temp +
args + 8) -
+ IL_BREAD_INT32(temp +
args + 4) + 1);
+
+ /* Dump the labels for the items */
+ temp2 = temp + args + 12;
+ for(item = 0; item < numItems; ++item)
+ {
+ if(item != 0)
+ {
+ putc(',', outstream);
+ putc(' ', outstream);
+ }
+ dest = (unsigned
long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp2)));
+ fprintf(outstream, "?L%lx",
dest + addr);
+ temp2 += 4;
+ }
+ }
+ else
+ {
+ /* Lookup-based switch instruction */
+ numItems = (unsigned long)
+ (IL_BREAD_UINT32(temp +
args + 4));
+ temp2 = temp + args + 8;
+ for(item = 0; item < numItems; ++item)
+ {
+ if(item != 0)
+ {
+ putc(',', outstream);
+ putc(' ', outstream);
+ }
+ fprintf(outstream, "%ld : ",
+
(long)(IL_BREAD_INT32(temp2)));
+ dest = (unsigned
long)(((long)offset) +
+
(long)(IL_BREAD_INT32(temp2 + 4)));
+ fprintf(outstream, "?L%lx",
dest + addr);
+ temp2 += 8;
+ }
+ }
+
+ /* Terminate the switch instruction */
+ putc(')', outstream);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_ANN_ARG:
+ {
+ /* Used to indicate the "iinc" instruction */
+ if(!isWide)
+ {
+ fprintf(outstream, "%d, %d",
+ ((int)(temp[args])) &
0xFF,
+
((int)((ILInt8)(temp[args + 1]))));
+ }
+ else
+ {
+ fprintf(outstream, "%d, %d",
+
((int)(IL_BREAD_UINT16(temp + args))),
+
((int)(IL_BREAD_INT16(temp + args + 2))));
+ }
+ }
+ break;
+
+ default: break;
+ }
+ putc('\n', outstream);
+
+ /* Move on to the next instruction */
+ offset += isize;
+ temp += isize;
+ tsize -= isize;
+ }
+ result = 1;
+
+ /* Clean up and exit */
+cleanup:
+ ILFree(jumpPoints);
+ return result;
+}
+
+void ILDAsmDumpJavaMethod(ILImage *image, FILE *outstream,
+ ILMethod *method, int flags)
+{
+ unsigned long addr;
+ ILMethodCode code;
+ ILException *clauses;
+ ILException *tempClause;
+ ILClass *catchClass;
+
+ /* Read the method code and exception information */
+ if(!ILMethodGetCode(method, &code))
+ {
+ /* If we get here, then probably the method had an RVA,
+ but the code was not IL */
+ fputs("\t\t// Cannot dump the code for native methods\n",
outstream);
+ return;
+ }
+ if(!ILMethodGetExceptions(method, &code, &clauses))
+ {
+ return;
+ }
+
+ /* Determine the address of the first instruction in the method */
+ addr = ILMethod_RVA(method);
+ if((flags & ILDASM_REAL_OFFSETS) != 0)
+ {
+ addr = ILImageRealOffset(image, addr) + code.headerSize;
+ }
+ else
+ {
+ addr += code.headerSize;
+ }
+
+ /* Output method header information */
+ fprintf(outstream, "\t\t// Start of method header: %lx\n",
+ (unsigned long)(addr - code.headerSize));
+ fprintf(outstream, "\t\t.maxstack %lu\n", (unsigned
long)(code.maxStack));
+ fprintf(outstream, "\t\t.locals %lu\n", (unsigned
long)(code.javaLocals));
+
+ /* Dump the instructions within the method */
+ if(!DumpJavaInstructions(image, ILMethod_Owner(method),
+ outstream, (unsigned
char *)(code.code),
+ code.codeLen, addr,
clauses, flags))
+ {
+ ILMethodFreeExceptions(clauses);
+ return;
+ }
+
+ /* Dump information about the exceptions */
+ tempClause = clauses;
+ while(tempClause != 0)
+ {
+ fprintf(outstream, "\t\t.try ?L%lx to ?L%lx",
+ tempClause->tryOffset + addr,
+ tempClause->tryOffset + tempClause->tryLength +
addr);
+ if((tempClause->flags & IL_META_EXCEPTION_FINALLY) != 0)
+ {
+ /* Finally clause */
+ fprintf(outstream, " finally");
+ }
+ else
+ {
+ /* Catch clause */
+ fputs(" catch ", outstream);
+ catchClass = ILClass_FromToken(image,
tempClause->extraArg);
+ if(catchClass)
+ {
+ ILDumpClassName(outstream, image, catchClass,
flags);
+ }
+ else
+ {
+ fputs("??", outstream);
+ }
+ }
+ fprintf(outstream, " handler ?L%lx\n",
+ tempClause->handlerOffset + addr);
+ tempClause = tempClause->next;
+ }
+
+ /* Free the exception list and exit */
+ ILMethodFreeExceptions(clauses);
+}
+
+#endif /* IL_CONFIG_JAVA */
+
+#ifdef __cplusplus
+};
+#endif
Index: dumpasm/dump_method.c
===================================================================
RCS file: dumpasm/dump_method.c
diff -N dumpasm/dump_method.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_method.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,976 @@
+/*
+ * dump_method.c - Disassemble method contents.
+ *
+ * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+#include "il_opcodes.h"
+#include "il_system.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Get the size of a special instruction that does not
+ * have a fixed-length representation.
+ */
+static unsigned long GetSpecialSize(unsigned char *temp, unsigned long tsize)
+{
+ unsigned long numItems;
+ if(temp[0] == (unsigned char)IL_OP_SWITCH)
+ {
+ /* Switch lookup table */
+ if(tsize < 5)
+ {
+ return 0;
+ }
+ numItems = (unsigned long)(IL_READ_UINT32(temp + 1));
+ if(numItems >= ((unsigned long)0x40000000) ||
+ (numItems * 4) > (tsize - 5))
+ {
+ return 0;
+ }
+ return numItems * 4 + 5;
+ }
+ else if(temp[0] == (unsigned char)IL_OP_ANN_DATA_S)
+ {
+ /* Short form of annotation data */
+ if(tsize < 2)
+ {
+ return 0;
+ }
+ numItems = (((unsigned long)(temp[1])) & 0xFF);
+ if((tsize - 2) < numItems)
+ {
+ return 0;
+ }
+ return numItems + 2;
+ }
+ else if(temp[0] == (unsigned char)IL_OP_PREFIX &&
+ temp[1] == (unsigned char)IL_PREFIX_OP_ANN_DATA)
+ {
+ /* Long form of annotation data */
+ if(tsize < 6)
+ {
+ return 0;
+ }
+ numItems = (unsigned long)(IL_READ_UINT32(temp + 2));
+ if((tsize - 6) < numItems)
+ {
+ return 0;
+ }
+ return numItems + 6;
+ }
+ else if(temp[0] == (unsigned char)IL_OP_ANN_PHI)
+ {
+ /* Static single assignment annotation data */
+ if(tsize < 3)
+ {
+ return 0;
+ }
+ numItems = (unsigned long)(IL_READ_UINT16(temp + 1));
+ if((tsize - 3) < (numItems * 2))
+ {
+ return 0;
+ }
+ return numItems * 2 + 3;
+ }
+ return 0;
+}
+
+/*
+ * Dump a token.
+ */
+static void DumpToken(ILImage *image, FILE *outstream,
+ int flags, unsigned long token,
+ int prefixWithKind)
+{
+ ILClass *info;
+ ILField *field;
+ ILMethod *method;
+ ILMember *member;
+ ILMember *origMember;
+ ILTypeSpec *spec;
+ ILStandAloneSig *sig;
+ ILType *type;
+ ILMethodSpec *mspec;
+
+ switch(token & IL_META_TOKEN_MASK)
+ {
+ case IL_META_TOKEN_TYPE_REF:
+ case IL_META_TOKEN_TYPE_DEF:
+ {
+ /* A reference to a type */
+ info = ILClass_FromToken(image, token);
+ if(info)
+ {
+ if((flags & ILDASM_SUPPRESS_PREFIX) == 0)
+ {
+ if(ILClassIsValueType(info))
+ {
+ fputs("valuetype ", outstream);
+ }
+ else
+ {
+ fputs("class ", outstream);
+ }
+ }
+ ILDumpClassName(outstream, image, info, flags);
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ case IL_META_TOKEN_FIELD_DEF:
+ {
+ /* A reference to a field */
+ field = ILField_FromToken(image, token);
+ if(field)
+ {
+ dumpField:
+ if(prefixWithKind)
+ {
+ fputs("field ", outstream);
+ }
+ ILDumpType(outstream, image,
ILField_Type(field), flags);
+ putc(' ', outstream);
+ info = ILField_Owner(field);
+ ILDumpClassName(outstream, image, info, flags);
+ fputs("::", outstream);
+ ILDumpIdentifier(outstream,
ILField_Name(field), 0, flags);
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ case IL_META_TOKEN_METHOD_DEF:
+ {
+ /* A reference to a method */
+ method = ILMethod_FromToken(image, token);
+ if(method)
+ {
+ if(prefixWithKind)
+ {
+ fputs("method ", outstream);
+ }
+ ILDumpMethodType(outstream, image,
+
ILMethod_Signature(method), flags,
+
ILMethod_Owner(method),
+
ILMethod_Name(method),
+ 0/*method*/);
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ case IL_META_TOKEN_MEMBER_REF:
+ {
+ /* A reference to an external method or field */
+ member = ILMember_FromToken(image, token);
+ origMember = member;
+ member = (member ? ILMemberResolveRef(member) : 0);
+ if(member)
+ {
+ if(ILMember_IsMethod(member))
+ {
+ /* Use the signature from the original
member,
+ because this may be a "vararg" call
that has
+ type information supplied in the
call site */
+ if(prefixWithKind)
+ {
+ fputs("method ", outstream);
+ }
+ method = (ILMethod *)member;
+ ILDumpMethodType(outstream, image,
+
ILMember_Signature(origMember), flags,
+
ILMethod_Owner(method),
+
ILMethod_Name(method),
+
0/*method*/);
+ }
+ else if(ILMember_IsField(member))
+ {
+ field = (ILField *)member;
+ goto dumpField;
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ case IL_META_TOKEN_TYPE_SPEC:
+ {
+ /* A reference to a type specification */
+ spec = ILTypeSpec_FromToken(image, token);
+ if(spec)
+ {
+ ILDumpType(outstream, image,
ILTypeSpec_Type(spec), flags);
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ case IL_META_TOKEN_STAND_ALONE_SIG:
+ {
+ /* A reference to a stand-alone signature */
+ sig = ILStandAloneSig_FromToken(image, token);
+ if(sig)
+ {
+ type = ILStandAloneSig_Type(sig);
+ if(ILType_IsMethod(type))
+ {
+ ILDumpMethodType(outstream, image,
type, flags, 0, "", 0);
+ }
+ else
+ {
+ ILDumpType(outstream, image, type,
flags);
+ }
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ case IL_META_TOKEN_METHOD_SPEC:
+ {
+ /* A reference to a method with generic parameters */
+ mspec = ILMethodSpec_FromToken(image, token);
+ if(mspec)
+ {
+ if(prefixWithKind)
+ {
+ fputs("method ", outstream);
+ }
+ ILDumpMethodSpec(outstream, image, mspec,
flags);
+ }
+ else
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ }
+ break;
+
+ default:
+ {
+ fprintf(outstream, "#%lx", token);
+ }
+ break;
+ }
+
+ if((flags & IL_DUMP_SHOW_TOKENS) != 0)
+ {
+ fprintf(outstream, " /*%08lX*/", token);
+ }
+}
+
+/*
+ * Dump all IL instructions in a given buffer. Returns zero
+ * if there is something wrong with the buffer's format.
+ */
+static int DumpInstructions(ILImage *image, FILE *outstream,
+ unsigned char *buf,
unsigned long size,
+ unsigned long addr,
ILException *clauses,
+ int flags)
+{
+ ILUInt32 *jumpPoints;
+ int result = 0;
+ unsigned char *temp;
+ unsigned long tsize;
+ unsigned long offset;
+ unsigned long dest;
+ unsigned long isize;
+ unsigned long args;
+ const ILOpcodeInfo *info;
+ int argType;
+ unsigned long numItems;
+ unsigned long item;
+
+ /* Allocate a helper array to mark jump points within the code */
+ jumpPoints = (ILUInt32 *)ILCalloc(((size + 3) & ~3), 1);
+ if(!jumpPoints)
+ {
+ fprintf(stderr, "out of memory\n");
+ exit(1);
+ }
+
+ /* Mark the entry point to the method so we get a label for it */
+ jumpPoints[0] |= (ILUInt32)1;
+
+ /* Mark the position of exception clauses */
+ while(clauses != 0)
+ {
+ dest = clauses->tryOffset;
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
+ }
+ dest = clauses->tryOffset + clauses->tryLength;
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
+ }
+ dest = clauses->handlerOffset;
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
+ }
+ dest = clauses->handlerOffset + clauses->handlerLength;
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
+ }
+ if((clauses->flags & IL_META_EXCEPTION_FILTER) != 0)
+ {
+ dest = clauses->extraArg;
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest
% 32));
+ }
+ }
+ clauses = clauses->next;
+ }
+
+ /* Scan the instruction list to locate jump points */
+ temp = buf;
+ tsize = size;
+ offset = 0;
+ while(tsize > 0)
+ {
+ if(*temp == (unsigned char)0xFE)
+ {
+ /* Prefixed instruction */
+ if(tsize < 2)
+ {
+ break;
+ }
+ info = &(ILPrefixOpcodeTable[((int)(temp[1])) & 0xFF]);
+ if(!strncmp(info->name, "unused_", 7))
+ {
+ break;
+ }
+ if(!(info->size))
+ {
+ isize = GetSpecialSize(temp, tsize);
+ }
+ else
+ {
+ isize = info->size;
+ }
+ if(tsize < isize)
+ {
+ break;
+ }
+ }
+ else
+ {
+ /* Regular instruction */
+ info = &(ILMainOpcodeTable[((int)(*temp)) & 0xFF]);
+ if(!strncmp(info->name, "unused_", 7))
+ {
+ break;
+ }
+ if(!(info->size))
+ {
+ isize = GetSpecialSize(temp, tsize);
+ }
+ else
+ {
+ isize = info->size;
+ }
+ if(tsize < isize)
+ {
+ break;
+ }
+ if(info->args == IL_OPCODE_ARGS_SHORT_JUMP)
+ {
+ dest = (unsigned long)(((long)offset) + 2 +
+
(long)(ILInt8)(temp[1]));
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L
<< (dest % 32));
+ }
+ }
+ else if(info->args == IL_OPCODE_ARGS_LONG_JUMP)
+ {
+ dest = (unsigned long)(((long)offset) + 5 +
+
(long)(IL_READ_UINT32(temp + 1)));
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |= (ILUInt32)(1L
<< (dest % 32));
+ }
+ }
+ else if(info->args == IL_OPCODE_ARGS_SWITCH)
+ {
+ numItems = (unsigned long)(IL_READ_UINT32(temp
+ 1));
+ for(item = 0; item < numItems; ++item)
+ {
+ dest = (unsigned
long)(IL_READ_UINT32(temp + 5 + item * 4));
+ dest = (unsigned long)(((long)offset) +
5 +
+
((long)numItems) * 4 +
+
((long)dest));
+ if(dest < size)
+ {
+ jumpPoints[dest / 32] |=
(ILUInt32)(1L << (dest % 32));
+ }
+ }
+ }
+ }
+ offset += isize;
+ temp += isize;
+ tsize -= isize;
+ }
+
+ /* Dump the instructions */
+ temp = buf;
+ tsize = size;
+ offset = 0;
+ while(tsize > 0)
+ {
+ /* If this is a jump point, then print a label for it */
+ if((jumpPoints[offset / 32] & (ILUInt32)(1L << (offset % 32)))
!= 0)
+ {
+ fprintf(outstream, "\t?L%lx:\n", offset + addr);
+ }
+
+ /* Extract the instruction from the method input stream */
+ if(*temp == (unsigned char)0xFE)
+ {
+ /* Prefixed instruction */
+ if(tsize < 2)
+ {
+ goto truncated;
+ }
+ info = &(ILPrefixOpcodeTable[((int)(temp[1])) & 0xFF]);
+ if(!strncmp(info->name, "unused_", 7))
+ {
+ fprintf(outstream, "\t\t// unknown instruction
0xFE 0x%02X\n",
+ ((int)(temp[1])) & 0xFF);
+ goto cleanup;
+ }
+ if(!(info->size))
+ {
+ isize = GetSpecialSize(temp, tsize);
+ }
+ else
+ {
+ isize = info->size;
+ }
+ if(tsize < isize)
+ {
+ goto truncated;
+ }
+ args = 2;
+ }
+ else
+ {
+ /* Regular instruction */
+ info = &(ILMainOpcodeTable[((int)(*temp)) & 0xFF]);
+ if(!strncmp(info->name, "unused_", 7))
+ {
+ fprintf(outstream, "\t\t// unknown instruction
0x%02X\n",
+ ((int)(*temp)) & 0xFF);
+ goto cleanup;
+ }
+ if(!(info->size))
+ {
+ isize = GetSpecialSize(temp, tsize);
+ }
+ else
+ {
+ isize = info->size;
+ }
+ if(tsize < isize)
+ {
+ goto truncated;
+ }
+ args = 1;
+ }
+
+ /* Dump the instruction based on its argument type */
+ argType = info->args;
+ putc('\t', outstream);
+ putc('\t', outstream);
+ if((flags & ILDASM_INSTRUCTION_BYTES) != 0)
+ {
+ /* Dump the bytes of the instruction */
+ int posn;
+ putc('/', outstream);
+ putc('*', outstream);
+ putc(' ', outstream);
+ posn = 0;
+ while(posn < 6 && posn < isize)
+ {
+ fprintf(outstream, "%02X ", ((int)(temp[posn])
& 0xFF));
+ ++posn;
+ }
+ while(posn < 6)
+ {
+ fputs(" ", outstream);
+ ++posn;
+ }
+ putc(' ', outstream);
+ putc('*', outstream);
+ putc('/', outstream);
+ putc(' ', outstream);
+ }
+ fputs(info->name, outstream);
+ if(argType != IL_OPCODE_ARGS_INVALID &&
+ argType != IL_OPCODE_ARGS_NONE)
+ {
+ numItems = (unsigned long)(strlen(info->name));
+ while(numItems < 10)
+ {
+ putc(' ', outstream);
+ ++numItems;
+ }
+ putc(' ', outstream);
+ }
+ switch(argType)
+ {
+ case IL_OPCODE_ARGS_INVALID: break;
+ case IL_OPCODE_ARGS_NONE: break;
+
+ case IL_OPCODE_ARGS_INT8:
+ {
+ fprintf(outstream, "%d",
(int)(ILInt8)(temp[args]));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_UINT8:
+ {
+ fprintf(outstream, "%d", ((int)(temp[args])) &
0xFF);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_INT16:
+ {
+ fprintf(outstream, "%d",
+ (int)(ILInt16)(IL_READ_UINT16(temp +
args)));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_UINT16:
+ {
+ fprintf(outstream, "%lu",
+ (unsigned long)(IL_READ_UINT16(temp +
args)));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_INT32:
+ {
+ fprintf(outstream, "%ld",
+ (long)(ILInt32)(IL_READ_UINT32(temp +
args)));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_INT64:
+ {
+ fprintf(outstream, "0x%08lx%08lX",
+ (unsigned long)(IL_READ_UINT32(temp +
args + 4)),
+ (unsigned
long)(IL_READ_UINT32(temp + args)));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_FLOAT32:
+ {
+ fprintf(outstream,
"float32(0x%02X%02X%02X%02X)",
+ (((int)(temp[args + 3])) &
0xFF),
+ (((int)(temp[args + 2])) &
0xFF),
+ (((int)(temp[args + 1])) &
0xFF),
+ (((int)(temp[args + 0])) &
0xFF));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_FLOAT64:
+ {
+ fprintf(outstream,
+
"float64(0x%02X%02X%02X%02X%02X%02X%02X%02X)",
+ (((int)(temp[args + 7])) &
0xFF),
+ (((int)(temp[args + 6])) &
0xFF),
+ (((int)(temp[args + 5])) &
0xFF),
+ (((int)(temp[args + 4])) &
0xFF),
+ (((int)(temp[args + 3])) &
0xFF),
+ (((int)(temp[args + 2])) &
0xFF),
+ (((int)(temp[args + 1])) &
0xFF),
+ (((int)(temp[args + 0])) &
0xFF));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_TOKEN:
+ case IL_OPCODE_ARGS_NEW:
+ {
+ DumpToken(image, outstream, flags,
+ (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_LDTOKEN:
+ {
+ DumpToken(image, outstream, flags,
+ (unsigned
long)(IL_READ_UINT32(temp + args)), 1);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_SHORT_VAR:
+ case IL_OPCODE_ARGS_SHORT_ARG:
+ {
+ fprintf(outstream, "%d", ((int)(temp[args])) &
0xFF);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_LONG_VAR:
+ case IL_OPCODE_ARGS_LONG_ARG:
+ case IL_OPCODE_ARGS_ANN_DEAD:
+ case IL_OPCODE_ARGS_ANN_LIVE:
+ case IL_OPCODE_ARGS_ANN_ARG:
+ {
+ fprintf(outstream, "%lu",
+ (unsigned
long)(IL_READ_UINT16(temp + args)));
+ }
+ break;
+
+ case IL_OPCODE_ARGS_SHORT_JUMP:
+ {
+ dest = (unsigned long)(((long)offset) + 2 +
+
(long)(ILInt8)(temp[1]));
+ fprintf(outstream, "?L%lx", dest + addr);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_LONG_JUMP:
+ {
+ dest = (unsigned long)(((long)offset) + 5 +
+
(long)(IL_READ_UINT32(temp + 1)));
+ fprintf(outstream, "?L%lx", dest + addr);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_CALL:
+ {
+ DumpToken(image, outstream, flags,
+ (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_CALLI:
+ {
+ DumpToken(image, outstream, flags,
+ (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_CALLVIRT:
+ {
+ DumpToken(image, outstream, flags,
+ (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_SWITCH:
+ {
+ putc('(', outstream);
+ numItems = (unsigned long)(IL_READ_UINT32(temp
+ args));
+ for(item = 0; item < numItems; ++item)
+ {
+ dest = (unsigned long)(((long)offset) +
5 +
+ ((long)numItems) * 4
+
+
(long)(IL_READ_UINT32(temp + args + 4 +
+
item * 4)));
+ if(item != 0)
+ {
+ putc(',', outstream);
+ putc(' ', outstream);
+ }
+ fprintf(outstream, "?L%lx", dest +
addr);
+ }
+ putc(')', outstream);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_STRING:
+ {
+ dest = (unsigned long)(IL_READ_UINT32(temp + args));
+ if((dest & IL_META_TOKEN_MASK) ==
IL_META_TOKEN_STRING)
+ {
+ const char *str;
+ unsigned long strLen;
+ dest &= ~IL_META_TOKEN_MASK;
+ str = ILImageGetUserString(image, dest,
&strLen);
+ if(str)
+ {
+ ILDumpUnicodeString(outstream,
str, strLen);
+ }
+ else
+ {
+ fprintf(outstream, "#%lx",
+ (unsigned
long)(IL_READ_UINT32(temp + args)));
+ }
+ }
+ else
+ {
+ fprintf(outstream, "#%lx",
+ (unsigned
long)(IL_READ_UINT32(temp + args)));
+ }
+ }
+ break;
+
+ case IL_OPCODE_ARGS_ANN_DATA:
+ {
+ if(temp[0] == (unsigned char)IL_OP_ANN_DATA_S)
+ {
+ numItems = (((unsigned
long)(temp[args])) & 0xFF);
+ ++args;
+ }
+ else
+ {
+ numItems = (unsigned
long)(IL_READ_UINT32(temp + args));
+ args += 4;
+ }
+ putc('(', outstream);
+ for(item = 0; item < numItems; ++item)
+ {
+ if(item != 0)
+ {
+ putc(' ', outstream);
+ }
+ fprintf(outstream, "%02X",
+ (((int)(temp[args +
item])) & 0xFF));
+ }
+ putc(')', outstream);
+ }
+ break;
+
+ case IL_OPCODE_ARGS_ANN_REF:
+ {
+ if(temp[0] == (unsigned char)IL_OP_ANN_REF_S)
+ {
+ fprintf(outstream, "%d",
+ (((int)(temp[args])) &
0xFF));
+ }
+ else
+ {
+ fprintf(outstream, "%lu",
+ (unsigned
long)(IL_READ_UINT16(temp + args)));
+ }
+ }
+ break;
+
+ case IL_OPCODE_ARGS_ANN_PHI:
+ {
+ numItems =
+ (((unsigned long)(IL_READ_UINT16(temp +
args))) & 0xFF);
+ ++args;
+ fprintf(outstream, "%lu", numItems);
+ for(item = 0; item < numItems; ++item)
+ {
+ fprintf(outstream, " %lu",
+ (unsigned
long)(IL_READ_UINT16(temp + args +
+
item * 2)));
+ }
+ }
+ break;
+
+ default: break;
+ }
+ putc('\n', outstream);
+
+ /* Move on to the next instruction */
+ offset += isize;
+ temp += isize;
+ tsize -= isize;
+ }
+ result = 1;
+
+ /* Clean up and exit */
+cleanup:
+ ILFree(jumpPoints);
+ return result;
+truncated:
+ fprintf(outstream, "\t\t// truncated instruction\n");
+ goto cleanup;
+}
+
+/*
+ * Dump the local variables associated with a method.
+ */
+static void DumpLocals(ILImage *image, FILE *outstream,
+ ILStandAloneSig *sig, int flags)
+{
+ ILType *locals;
+ ILType *type;
+ unsigned long num;
+ unsigned long index;
+
+ /* Dump the locals */
+ locals = ILStandAloneSigGetType(sig);
+ num = ILTypeNumLocals(locals);
+ for(index = 0; index < num; ++index)
+ {
+ if(index != 0)
+ {
+ fputs(",\n\t\t ", outstream);
+ }
+ type = ILTypeGetLocalWithPrefixes(locals, index);
+ ILDumpType(outstream, image, type, flags);
+ }
+}
+
+/*
+ * Dump the custom attributes on the parameters.
+ */
+static void DumpParameterAttributes(ILImage *image, FILE *outstream,
+
ILMethod *method, int flags)
+{
+ ILParameter *param = 0;
+ ILAttribute *attr;
+ while((param = ILMethodNextParam(method, param)) != 0)
+ {
+ attr = ILProgramItemNextAttribute(ILToProgramItem(param), 0);
+ if(attr || ILConstantGetFromOwner(ILToProgramItem(param)) != 0)
+ {
+ fprintf(outstream, "\t\t.param [%ld]",
+ (long)(ILParameter_Num(param)));
+ ILDumpConstant(outstream, ILToProgramItem(param), 0);
+ putc('\n', outstream);
+ ILDAsmDumpCustomAttrs(image, outstream, flags, 2,
+
ILToProgramItem(param));
+ }
+ }
+}
+
+void ILDAsmDumpMethod(ILImage *image, FILE *outstream,
+ ILMethod *method, int flags,
+ int isEntryPoint)
+{
+ unsigned long addr;
+ ILMethodCode code;
+ ILException *clauses;
+ ILException *tempClause;
+
+ /* Read the method code and exception information */
+ if(!ILMethodGetCode(method, &code))
+ {
+ /* If we get here, then probably the method had an RVA,
+ but the code was not IL */
+ fputs("\t\t// Cannot dump the code for native methods\n",
outstream);
+ return;
+ }
+ if(!ILMethodGetExceptions(method, &code, &clauses))
+ {
+ return;
+ }
+
+ /* Determine the address of the first instruction in the method */
+ addr = ILMethod_RVA(method);
+ if((flags & ILDASM_REAL_OFFSETS) != 0)
+ {
+ addr = ILImageRealOffset(image, addr) + code.headerSize;
+ }
+ else
+ {
+ addr += code.headerSize;
+ }
+
+ /* Output method header information */
+ fprintf(outstream, "\t\t// Start of method header: %lx\n",
+ (unsigned long)(addr - code.headerSize));
+ DumpParameterAttributes(image, outstream, method, flags);
+ if(isEntryPoint)
+ {
+ fputs("\t\t.entrypoint\n", outstream);
+ }
+ fprintf(outstream, "\t\t.maxstack %lu\n", (unsigned
long)(code.maxStack));
+ if(code.localVarSig)
+ {
+ fprintf(outstream, "\t\t.locals %s(",
+ (code.initLocals ? "init " : ""));
+ DumpLocals(image, outstream, code.localVarSig, flags);
+ fputs(")\n", outstream);
+ }
+
+ /* Dump the instructions within the method */
+ if(!DumpInstructions(image, outstream, (unsigned char *)(code.code),
+ code.codeLen, addr, clauses,
flags))
+ {
+ ILMethodFreeExceptions(clauses);
+ return;
+ }
+
+ /* Dump information about the exceptions */
+ tempClause = clauses;
+ while(tempClause != 0)
+ {
+ fprintf(outstream, "\t\t.try ?L%lx to ?L%lx",
+ tempClause->tryOffset + addr,
+ tempClause->tryOffset + tempClause->tryLength +
addr);
+ if((tempClause->flags & IL_META_EXCEPTION_FILTER) != 0)
+ {
+ /* Filter clause */
+ fprintf(outstream, " filter ?L%lx",
tempClause->extraArg + addr);
+ }
+ else if((tempClause->flags & IL_META_EXCEPTION_FINALLY) != 0)
+ {
+ /* Finally clause */
+ fprintf(outstream, " finally");
+ }
+ else if((tempClause->flags & IL_META_EXCEPTION_FAULT) != 0)
+ {
+ /* Fault clause */
+ fprintf(outstream, " fault");
+ }
+ else
+ {
+ /* Catch clause */
+ fputs(" catch ", outstream);
+ DumpToken(image, outstream, flags |
ILDASM_SUPPRESS_PREFIX,
+ tempClause->extraArg, 0);
+ }
+ fprintf(outstream, " handler ?L%lx to ?L%lx\n",
+ tempClause->handlerOffset + addr,
+ tempClause->handlerOffset +
tempClause->handlerLength + addr);
+ tempClause = tempClause->next;
+ }
+
+ /* Free the exception list and exit */
+ ILMethodFreeExceptions(clauses);
+}
+
+#ifdef __cplusplus
+};
+#endif
Index: dumpasm/dump_utils.c
===================================================================
RCS file: dumpasm/dump_utils.c
diff -N dumpasm/dump_utils.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dumpasm/dump_utils.c 9 Feb 2007 21:54:16 -0000 1.1
@@ -0,0 +1,191 @@
+/*
+ * dump_utils.c - Utilities used by the disassembler.
+ *
+ * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "il_dumpasm.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void ILDAsmDumpBinaryBlob(FILE *outstream, ILImage *image,
+ const void *blob, ILUInt32
blobLen)
+{
+ unsigned char *ptr = (unsigned char *)blob;
+ ILUInt32 offset;
+ if(blobLen > 16)
+ {
+ /* Dump the blob on a separate line */
+ fputs("\n\t\t(", outstream);
+ while(blobLen > 16)
+ {
+ for(offset = 0; offset < 16; ++offset)
+ {
+ if(offset)
+ {
+ putc(' ', outstream);
+ }
+ fprintf(outstream, "%02X", ptr[offset]);
+ }
+ fputs(" // ", outstream);
+ for(offset = 0; offset < 16; ++offset)
+ {
+ if(ptr[offset] >= (unsigned char)' ' &&
+ ptr[offset] <= (unsigned char)0x7E)
+ {
+ putc((int)(ptr[offset]), outstream);
+ }
+ else
+ {
+ putc('.', outstream);
+ }
+ }
+ fputs("\n\t\t ", outstream);
+ ptr += 16;
+ blobLen -= 16;
+ }
+ for(offset = 0; offset < blobLen; ++offset)
+ {
+ if(offset)
+ {
+ putc(' ', outstream);
+ }
+ fprintf(outstream, "%02X", ptr[offset]);
+ }
+ fputs(") // ", outstream);
+ for(offset = 0; offset < blobLen; ++offset)
+ {
+ if(ptr[offset] >= (unsigned char)' ' &&
+ ptr[offset] <= (unsigned char)0x7E)
+ {
+ putc((int)(ptr[offset]), outstream);
+ }
+ else
+ {
+ putc('.', outstream);
+ }
+ }
+ }
+ else
+ {
+ /* Dump the blob on the same line */
+ fputs(" (", outstream);
+ for(offset = 0; offset < blobLen; ++offset)
+ {
+ if(offset)
+ {
+ putc(' ', outstream);
+ }
+ fprintf(outstream, "%02X", ptr[offset]);
+ }
+ fputs(") // ", outstream);
+ for(offset = 0; offset < blobLen; ++offset)
+ {
+ if(ptr[offset] >= (unsigned char)' ' &&
+ ptr[offset] <= (unsigned char)0x7E)
+ {
+ putc((int)(ptr[offset]), outstream);
+ }
+ else
+ {
+ putc('.', outstream);
+ }
+ }
+ }
+}
+
+void ILDAsmWalkTokens(ILImage *image, FILE *outstream, int flags,
+ unsigned long tokenKind,
ILDAsmWalkFunc callback,
+ unsigned long refToken)
+{
+ unsigned long numTokens;
+ unsigned long token;
+ void *data;
+ numTokens = ILImageNumTokens(image, tokenKind);
+ for(token = 1; token <= numTokens; ++token)
+ {
+ data = ILImageTokenInfo(image, tokenKind | token);
+ (*callback)(image, outstream, flags, tokenKind | token, data,
refToken);
+ }
+}
+
+void ILDAsmDumpSecurity(ILImage *image, FILE *outstream,
+ ILProgramItem *item, int flags)
+{
+ ILDeclSecurity *security;
+ const void *blob;
+ unsigned long blobLen;
+ ILUInt16 ch;
+
+ /* Get the security information, if any */
+ security = ILDeclSecurityGetFromOwner(item);
+ if(!security)
+ {
+ return;
+ }
+
+ /* Dump the security header */
+ fputs("\t.capability ", outstream);
+
+ /* Dump the type of security blob */
+ ILDumpFlags(outstream, ILDeclSecurity_Type(security), ILSecurityFlags,
0);
+
+ /* Dump the blob */
+ blob = ILDeclSecurityGetBlob(security, &blobLen);
+ if(blob)
+ {
+ putc('=', outstream);
+ ILDAsmDumpBinaryBlob(outstream, image, blob, blobLen);
+ }
+
+ /* Terminate the line */
+ putc('\n', outstream);
+
+ /* Dump the text version of the XML within the security blob */
+ if(blob)
+ {
+ fputs("\t// ", outstream);
+ while(blobLen >= 2)
+ {
+ ch = IL_READ_UINT16(blob);
+ if(ch == '\n')
+ {
+ if(blobLen >= 4)
+ {
+ fputs("\n\t// ", outstream);
+ }
+ }
+ else if(ch >= ' ' && ch <= 0x7E)
+ {
+ putc((int)ch, outstream);
+ }
+ else if(ch != '\r')
+ {
+ fprintf(outstream, "&#x%04lX;", (unsigned
long)ch);
+ }
+ blob = (const void *)(((const char *)blob) + 2);
+ blobLen -= 2;
+ }
+ putc('\n', outstream);
+ }
+}
+
+#ifdef __cplusplus
+};
+#endif
Index: ildasm/ildasm_attrs.c
===================================================================
RCS file: ildasm/ildasm_attrs.c
diff -N ildasm/ildasm_attrs.c
--- ildasm/ildasm_attrs.c 8 Jul 2004 05:40:52 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,380 +0,0 @@
-/*
- * ildasm_attrs.c - Dump custom attributes.
- *
- * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-#include "il_serialize.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Dump a serialized attribute value.
- */
-static int DumpAttrValue(FILE *outstream, ILSerializeReader *reader, int type)
-{
- ILInt32 intValue;
- ILUInt32 uintValue;
- ILInt64 longValue;
- ILUInt64 ulongValue;
- ILFloat floatValue;
- ILDouble doubleValue;
- const char *strValue;
- int strLen;
-
- switch(type)
- {
- case IL_META_SERIALTYPE_BOOLEAN:
- {
- intValue = ILSerializeReaderGetInt32(reader, type);
- if(intValue)
- {
- fputs("true", outstream);
- }
- else
- {
- fputs("false", outstream);
- }
- }
- break;
-
- case IL_META_SERIALTYPE_I1:
- case IL_META_SERIALTYPE_U1:
- {
- intValue = ILSerializeReaderGetInt32(reader, type);
- fprintf(outstream, "%ld /*0x%02lX*/",
- (long)intValue, (long)intValue);
- }
- break;
-
- case IL_META_SERIALTYPE_I2:
- case IL_META_SERIALTYPE_U2:
- case IL_META_SERIALTYPE_CHAR:
- {
- intValue = ILSerializeReaderGetInt32(reader, type);
- fprintf(outstream, "%ld /*0x%04lX*/",
- (long)intValue, (long)intValue);
- }
- break;
-
- case IL_META_SERIALTYPE_I4:
- {
- intValue = ILSerializeReaderGetInt32(reader, type);
- fprintf(outstream, "%ld /*0x%08lX*/",
- (long)intValue, (long)intValue);
- }
- break;
-
- case IL_META_SERIALTYPE_U4:
- {
- uintValue = ILSerializeReaderGetUInt32(reader, type);
- fprintf(outstream, "%lu /*0x%08lX*/",
- (unsigned long)uintValue, (unsigned
long)uintValue);
- }
- break;
-
- case IL_META_SERIALTYPE_I8:
- {
- longValue = ILSerializeReaderGetInt64(reader);
- fprintf(outstream, "0x%08lX%08lX",
- (unsigned long)((longValue >> 32) &
IL_MAX_UINT32),
- (unsigned long)(longValue &
IL_MAX_UINT32));
- }
- break;
-
- case IL_META_SERIALTYPE_U8:
- {
- ulongValue = ILSerializeReaderGetUInt64(reader);
- fprintf(outstream, "0x%08lX%08lX",
- (unsigned long)((ulongValue >> 32) &
IL_MAX_UINT32),
- (unsigned long)(ulongValue &
IL_MAX_UINT32));
- }
- break;
-
- case IL_META_SERIALTYPE_R4:
- {
- floatValue = ILSerializeReaderGetFloat32(reader);
- fprintf(outstream, "%.30e", (double)floatValue);
- }
- break;
-
- case IL_META_SERIALTYPE_R8:
- {
- doubleValue = ILSerializeReaderGetFloat64(reader);
- fprintf(outstream, "%.30e", (double)doubleValue);
- }
- break;
-
- case IL_META_SERIALTYPE_STRING:
- {
- strLen = ILSerializeReaderGetString(reader, &strValue);
- if(strLen == -1)
- {
- return 0;
- }
- if(strValue)
- {
- ILDumpStringLen(outstream, strValue, strLen);
- }
- else
- {
- fputs("null", outstream);
- }
- }
- break;
-
- case IL_META_SERIALTYPE_TYPE:
- {
- strLen = ILSerializeReaderGetString(reader, &strValue);
- if(strLen == -1)
- {
- return 0;
- }
- fputs("typeof(", outstream);
- if(strValue)
- {
- fwrite(strValue, 1, strLen, outstream);
- }
- else
- {
- fputs("null", outstream);
- }
- putc(')', outstream);
- }
- break;
-
- default:
- {
- if((type & IL_META_SERIALTYPE_ARRAYOF) != 0)
- {
- intValue = ILSerializeReaderGetArrayLen(reader);
- putc('{', outstream);
- while(intValue > 0)
- {
- if(!DumpAttrValue(outstream, reader,
- type
& ~IL_META_SERIALTYPE_ARRAYOF))
- {
- return 0;
- }
- --intValue;
- if(intValue > 0)
- {
- fputs(", ", outstream);
- }
- }
- putc('}', outstream);
- }
- else
- {
- return 0;
- }
- }
- break;
- }
- return 1;
-}
-
-/*
- * Dump the readable form of an attribute blob.
- */
-static void DumpAttrBlob(FILE *outstream, ILImage *image, ILMethod *method,
- const void *blob, unsigned
long blobLen)
-{
- ILClass *classInfo;
- const char *name;
- int nameLen;
- ILSerializeReader *reader;
- ILUInt32 numParams;
- int numExtra;
- int type, needComma;
- ILMember *member;
-
- /* Dump the name of the attribute */
- classInfo = ILMethod_Owner(method);
- name = ILClass_Name(classInfo);
- nameLen = strlen(name);
- if(!strcmp(name + nameLen - 9, "Attribute"))
- {
- fwrite(name, 1, nameLen - 9, outstream);
- }
- else
- {
- fputs(name, outstream);
- }
-
- /* Initialize the serialization reader */
- reader = ILSerializeReaderInit(method, blob, blobLen);
- if(!reader)
- {
- fputs("(?)", outstream);
- return;
- }
-
- /* Dump the parameters */
- numParams = ILTypeNumParams(ILMethod_Signature(method));
- needComma = 0;
- putc('(', outstream);
- while(numParams > 0)
- {
- if(needComma)
- {
- fputs(", ", outstream);
- }
- else
- {
- needComma = 1;
- }
- type = ILSerializeReaderGetParamType(reader);
- if(type != -1)
- {
- if(!DumpAttrValue(outstream, reader, type))
- {
- ILSerializeReaderDestroy(reader);
- return;
- }
- }
- else
- {
- fputs("?)", outstream);
- ILSerializeReaderDestroy(reader);
- return;
- }
- --numParams;
- }
- putc(')', outstream);
-
- /* Dump the extra field and property specifications */
- numExtra = ILSerializeReaderGetNumExtra(reader);
- while(numExtra > 0)
- {
- fputs(", ", outstream);
- type = ILSerializeReaderGetExtra(reader, &member, &name,
&nameLen);
- if(type == -1)
- {
- putc('?', outstream);
- break;
- }
- fwrite(name, 1, nameLen, outstream);
- putc('=', outstream);
- if(!DumpAttrValue(outstream, reader, type))
- {
- putc('?', outstream);
- break;
- }
- --numExtra;
- }
-
- /* Clean up and exit */
- ILSerializeReaderDestroy(reader);
-}
-
-void ILDAsmDumpCustomAttrs(ILImage *image, FILE *outstream, int flags,
- int indent, ILProgramItem
*item)
-{
- ILAttribute *attr = 0;
- ILProgramItem *type;
- const void *value;
- unsigned long valueLen;
- ILClass *classInfo;
- ILMethod *method;
- ILTypeSpec *spec;
- ILType *rawType;
-
- while((attr = ILProgramItemNextAttribute(item, attr)) != 0)
- {
- /* Output the ".custom" header */
- if(indent == 1)
- {
- fputs("\t", outstream);
- }
- else if(indent == 2)
- {
- fputs("\t\t", outstream);
- }
- fputs(".custom ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ",
- (long)(ILProgramItem_Token(attr)));
- }
-
- /* Output the type */
- method = 0;
- if(ILAttributeTypeIsItem(attr))
- {
- type = ILAttributeTypeAsItem(attr);
- if((spec = ILProgramItemToTypeSpec(type)) != 0)
- {
- rawType = ILTypeSpec_Type(spec);
- ILDumpType(outstream, image, rawType, flags);
- }
- else if((classInfo = ILProgramItemToClass(type)) != 0)
- {
- ILDumpClassName(outstream, image, classInfo,
flags);
- }
- else if((method = ILProgramItemToMethod(type)) != 0)
- {
- ILDumpMethodType(outstream, image,
-
ILMethod_Signature(method), flags,
-
ILMethod_Owner(method),
-
ILMethod_Name(method),
- method);
- }
- else
- {
- fputs("UNKNOWNTYPE", outstream);
- }
- }
- else
- {
- fputs("STRING", outstream);
- }
-
- /* Output the value */
- if((value = ILAttributeGetValue(attr, &valueLen)) != 0)
- {
- fputs(" =", outstream);
- ILDAsmDumpBinaryBlob(outstream, image, value, valueLen);
- }
-
- /* Terminate the line */
- putc('\n', outstream);
-
- /* Output a readable version of the value */
- if(value && method)
- {
- if(indent == 1)
- {
- fputs("\t", outstream);
- }
- else if(indent == 2)
- {
- fputs("\t\t", outstream);
- }
- fputs("// ", outstream);
- DumpAttrBlob(outstream, image, method, value, valueLen);
- putc('\n', outstream);
- }
- }
-}
-
-#ifdef __cplusplus
-};
-#endif
Index: ildasm/ildasm_class.c
===================================================================
RCS file: ildasm/ildasm_class.c
diff -N ildasm/ildasm_class.c
--- ildasm/ildasm_class.c 30 Sep 2003 01:38:14 -0000 1.16
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,622 +0,0 @@
-/*
- * ildasm_class.c - Disassemble class information.
- *
- * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Dump a PInvoke definition.
- */
-static void Dump_PInvoke(FILE *outstream, ILPInvoke *pinvoke, ILMember *member)
-{
- if(pinvoke)
- {
- fputs("pinvokeimpl(", outstream);
- ILDumpString(outstream,
-
ILModule_Name(ILPInvoke_Module(pinvoke)));
- putc(' ', outstream);
- if(strcmp(ILPInvoke_Alias(pinvoke), ILMember_Name(member)) != 0)
- {
- fputs("as ", outstream);
- ILDumpString(outstream, ILPInvoke_Alias(pinvoke));
- putc(' ', outstream);
- }
- ILDumpFlags(outstream, ILPInvoke_Attrs(pinvoke),
- ILPInvokeImplementationFlags, 0);
- fputs(") ", outstream);
- }
- else
- {
- fputs("pinvokeimpl() ", outstream);
- }
-}
-
-/*
- * Dump a method definition.
- */
-static void Dump_MethodDef(ILImage *image, FILE *outstream, int flags,
- ILMethod *method)
-{
- ILUInt32 rva;
- ILOverride *over;
- int haveContents;
-
- /* Skip the method if it is a reference (probably a vararg call site) */
- if((ILMethod_Token(method) & IL_META_TOKEN_MASK) ==
- IL_META_TOKEN_MEMBER_REF)
- {
- return;
- }
-
- /* Dump the header information for the method */
- fputs("\t.method ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ",
- (unsigned long)(ILMethod_Token(method)));
- }
- ILDumpFlags(outstream, ILMethod_Attrs(method), ILMethodDefinitionFlags,
0);
- if(ILMethod_HasPInvokeImpl(method))
- {
- Dump_PInvoke(outstream, ILPInvokeFind(method), (ILMember
*)method);
- }
- ILDumpMethodType(outstream, image, ILMethod_Signature(method),
- flags | IL_DUMP_GENERIC_PARAMS,
- 0, ILMethod_Name(method), method);
- putc(' ', outstream);
- ILDumpFlags(outstream, ILMethod_ImplAttrs(method),
- ILMethodImplementationFlags, 0);
- rva = ILMethod_RVA(method);
- haveContents = (ILProgramItem_HasAttrs(method) || rva ||
- ILOverrideFromMethod(method));
- if(haveContents)
- {
- fputs("\n\t{\n", outstream);
- }
- else
- {
- fputs("{}\n", outstream);
- }
- ILDAsmDumpCustomAttrs(image, outstream, flags, 2,
ILToProgramItem(method));
-
- /* Dump the security information, if any */
- if((ILMethod_Attrs(method) & IL_META_METHODDEF_HAS_SECURITY) != 0)
- {
- ILDAsmDumpSecurity(image, outstream, (ILProgramItem *)method,
flags);
- }
-
- /* If this a body for an override, then declare it */
- over = ILOverrideFromMethod(method);
- if(over)
- {
- ILMethod *decl = ILOverride_Decl(over);
- fputs("\t\t.override ", outstream);
- ILDumpClassName(outstream, image, ILMethod_Owner(decl), flags);
- fputs("::", outstream);
- ILDumpIdentifier(outstream, ILMethod_Name(decl), 0, flags);
- putc('\n', outstream);
- }
-
- /* If we have an RVA, then we need to dump the method's contents */
- if(rva && (flags & ILDASM_NO_IL) == 0)
- {
- #ifdef IL_CONFIG_JAVA
- if(ILMethod_IsJava(method))
- {
- ILDAsmDumpJavaMethod(image, outstream, method, flags);
- }
- else
- #endif
- {
- ILDAsmDumpMethod(image, outstream, method, flags,
-
(ILMethod_Token(method) ==
-
ILImageGetEntryPoint(image)));
- }
- }
-
- /* Output the method footer and exit */
- if(haveContents)
- {
- fputs("\t}\n", outstream);
- }
-}
-
-/*
- * Dump a field definition.
- */
-static void Dump_FieldDef(ILImage *image, FILE *outstream, int flags,
- ILField *field)
-{
- ILFieldLayout *layout;
- fputs("\t.field ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ",
- (unsigned long)(ILField_Token(field)));
- }
- layout = ILFieldLayoutGetFromOwner(field);
- if(layout)
- {
- fprintf(outstream, "[%lu] ",
- (unsigned long)(ILFieldLayout_Offset(layout)));
- }
- ILDumpFlags(outstream, ILField_Attrs(field), ILFieldDefinitionFlags, 0);
- if((ILField_Attrs(field) & IL_META_FIELDDEF_HAS_FIELD_MARSHAL) != 0)
- {
- ILFieldMarshal *marshal = ILFieldMarshalGetFromOwner
-
((ILProgramItem *)field);
- if(marshal)
- {
- const void *type;
- unsigned long typeLen;
- type = ILFieldMarshalGetType(marshal, &typeLen);
- if(type)
- {
- fputs("marshal(", outstream);
- ILDumpNativeType(outstream, type, typeLen,
flags);
- fputs(") ", outstream);
- }
- }
- }
- if(ILField_HasPInvokeImpl(field))
- {
- Dump_PInvoke(outstream, ILPInvokeFindField(field), (ILMember
*)field);
- }
- ILDumpType(outstream, image, ILFieldGetTypeWithPrefixes(field), flags);
- putc(' ', outstream);
- ILDumpIdentifier(outstream, ILField_Name(field), 0, flags);
- if((ILField_Attrs(field) & IL_META_FIELDDEF_HAS_FIELD_RVA) != 0)
- {
- ILFieldRVA *rva = ILFieldRVAGetFromOwner(field);
- if(rva)
- {
- fprintf(outstream, " at D_0x%08lX",
- (unsigned long)(ILFieldRVA_RVA(rva)));
- }
- }
- if((ILField_Attrs(field) & IL_META_FIELDDEF_HAS_DEFAULT) != 0)
- {
- ILDumpConstant(outstream, (ILProgramItem *)field, 0);
- }
- putc('\n', outstream);
- if(ILProgramItem_HasAttrs(field))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
-
ILToProgramItem(field));
- }
-}
-
-/*
- * Dump a method association for an event or property.
- */
-static void DumpMethodAssociation(ILImage *image, FILE *outstream,
- int flags,
ILMethod *method)
-{
- ILDumpMethodType(outstream, image, ILMethod_Signature(method), flags,
- ILMethod_Owner(method),
ILMethod_Name(method), 0);
-}
-
-/*
- * Dump an event definition.
- */
-static void Dump_EventDef(ILImage *image, FILE *outstream, int flags,
- ILEvent *event)
-{
- ILMethod *method;
-
- /* Dump the event header */
- fputs("\t.event ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ",
- (unsigned long)(ILEvent_Token(event)));
- }
- ILDumpFlags(outstream, ILEvent_Attrs(event), ILEventDefinitionFlags, 0);
- if(ILEvent_Type(event) != ILType_Invalid)
- {
- ILDumpType(outstream, image, ILEvent_Type(event), flags);
- putc(' ', outstream);
- }
- ILDumpIdentifier(outstream, ILEvent_Name(event), 0, flags);
- fputs("\n\t{\n", outstream);
-
- /* Dump the custom attributes */
- if(ILProgramItem_HasAttrs(event))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
-
ILToProgramItem(event));
- }
-
- /* Dump the event methods */
- if((method = ILEvent_AddOn(event)) != 0)
- {
- fputs("\t\t.addon ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
- if((method = ILEvent_RemoveOn(event)) != 0)
- {
- fputs("\t\t.removeon ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
- if((method = ILEvent_Fire(event)) != 0)
- {
- fputs("\t\t.fire ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
- if((method = ILEvent_Other(event)) != 0)
- {
- fputs("\t\t.other ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
-
- /* Dump the event footer */
- fputs("\t}\n", outstream);
-}
-
-/*
- * Dump a property definition.
- */
-static void Dump_PropertyDef(ILImage *image, FILE *outstream, int flags,
- ILProperty *property)
-{
- ILMethod *method;
-
- /* Dump the property header */
- fputs("\t.property ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ",
- (unsigned long)(ILProperty_Token(property)));
- }
- ILDumpFlags(outstream, ILProperty_Attrs(property),
- ILPropertyDefinitionFlags, 0);
-
- /* Dump the calling conventions from the get/set method,
- because the property signature doesn't contain them */
- if((method = ILProperty_Getter(property)) != 0)
- {
- ILDumpFlags(outstream, ILMethod_CallConv(method),
- ILMethodCallConvFlags, 0);
- }
- else if((method = ILProperty_Setter(property)) != 0)
- {
- ILDumpFlags(outstream, ILMethod_CallConv(method),
- ILMethodCallConvFlags, 0);
- }
-
- /* Dump the property type */
- ILDumpMethodType(outstream, image, ILProperty_Signature(property),
flags,
- 0, ILProperty_Name(property), 0);
- fputs("\n\t{\n", outstream);
-
- /* Dump the custom attributes */
- if(ILProgramItem_HasAttrs(property))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
-
ILToProgramItem(property));
- }
-
- /* Dump the property methods */
- if((method = ILProperty_Getter(property)) != 0)
- {
- fputs("\t\t.get ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
- if((method = ILProperty_Setter(property)) != 0)
- {
- fputs("\t\t.set ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
- if((method = ILProperty_Other(property)) != 0)
- {
- fputs("\t\t.other ", outstream);
- DumpMethodAssociation(image, outstream, flags, method);
- putc('\n', outstream);
- }
-
- /* Dump the event footer */
- fputs("\t}\n", outstream);
-}
-
-/*
- * Dump a class name with generic parameter information.
- */
-static void DumpClassName(FILE *outstream, ILImage *image,
- ILClass *info, int flags, int
withNamespace)
-{
- ILType *type;
- ILUInt32 genericNum;
- ILGenericPar *genPar;
- const char *name;
- ILProgramItem *constraint;
- ILTypeSpec *spec;
-
- /* Use a different approach if the class is a type specification */
- type = ILClassGetSynType(info);
- if(type)
- {
- ILDumpType(outstream, image, type, flags);
- return;
- }
-
- /* Dump the main part of the class name */
- if(withNamespace)
- {
- ILDumpClassName(outstream, image, info, flags);
- }
- else
- {
- ILDumpIdentifier(outstream, ILClass_Name(info), 0, flags);
- }
-
- /* Dump the generic parameters, if any are present */
- genericNum = 0;
- genPar = ILGenericParGetFromOwner(ILToProgramItem(info), genericNum);
- if(genPar)
- {
- putc('<', outstream);
- do
- {
- if(genericNum > 0)
- {
- fputs(", ", outstream);
- }
- constraint = ILGenericPar_Constraint(genPar);
- if(constraint)
- {
- putc('(', outstream);
- spec = ILProgramItemToTypeSpec(constraint);
- if(spec)
- {
- ILDumpType(outstream, image,
ILTypeSpec_Type(spec), flags);
- }
- else
- {
- ILDumpType(outstream, image,
-
ILClassToType((ILClass *)constraint), flags);
- }
- putc(')', outstream);
- }
- name = ILGenericPar_Name(genPar);
- if(name)
- {
- ILDumpIdentifier(outstream, name, 0, flags);
- }
- else
- {
- fprintf(outstream, "G_%d", (int)(genericNum +
1));
- }
- ++genericNum;
- genPar = ILGenericParGetFromOwner
- (ILToProgramItem(info), genericNum);
- }
- while(genPar != 0);
- putc('>', outstream);
- }
-}
-
-/*
- * Dump information about a type definition and its nested classes.
- */
-static void Dump_TypeAndNested(ILImage *image, FILE *outstream,
- int flags, ILClass
*info)
-{
- ILMember *member;
- ILImplements *impl;
- ILClass *interface;
- ILNestedInfo *nested;
- int first;
- int isModule = 0;
- ILClassLayout *layout;
- unsigned long size;
- ILOverride *over;
- ILMethod *decl;
- ILMethod *body;
-
- /* Dump the namespace if this class is not nested */
- if(!ILClass_NestedParent(info) && ILClass_Namespace(info))
- {
- fputs(".namespace ", outstream);
- ILDumpIdentifier(outstream, ILClass_Namespace(info), 0, flags);
- fputs("\n{\n", outstream);
- }
-
- /* Dump the type header, if it is not "<Module>" */
- if(strcmp(ILClass_Name(info), "<Module>") != 0 ||
- ILClass_Namespace(info) != 0)
- {
- fputs(".class ", outstream);
- ILDumpFlags(outstream, ILClass_Attrs(info),
ILTypeDefinitionFlags, 0);
- DumpClassName(outstream, image, info, flags, 0);
- if(ILClass_Parent(info))
- {
- fputs(" extends ", outstream);
- DumpClassName(outstream, image, ILClass_Parent(info),
flags, 1);
- }
- first = 1;
- impl = 0;
- while((impl = ILClassNextImplements(info, impl)) != 0)
- {
- interface = ILImplementsGetInterface(impl);
- if(first)
- {
- fputs(" implements ", outstream);
- first = 0;
- }
- else
- {
- fputs(", ", outstream);
- }
- DumpClassName(outstream, image, interface, flags, 1);
- }
- fputs("\n{\n", outstream);
-
- /* Dump the security information, if any */
- if((ILClass_Attrs(info) & IL_META_TYPEDEF_HAS_SECURITY) != 0)
- {
- ILDAsmDumpSecurity(image, outstream, (ILProgramItem
*)info, flags);
- }
-
- /* Dump the class layout information, if any */
- layout = ILClassLayoutGetFromOwner(info);
- if(layout)
- {
- size = (unsigned
long)(ILClassLayout_PackingSize(layout));
- if(size != 0)
- {
- fprintf(outstream, "\t.pack %lu\n", size);
- }
- size = (unsigned long)(ILClassLayout_ClassSize(layout));
- if(size != 0)
- {
- fprintf(outstream, "\t.size %lu\n", size);
- }
- }
-
- /* Dump the custom attributes for the class */
- if(ILProgramItem_HasAttrs(info))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
-
ILToProgramItem(info));
- }
- }
- else
- {
- isModule = 1;
- if(ILClassNextMember(info, 0) != 0)
- {
- fputs("// .class ", outstream);
- ILDumpFlags(outstream, ILClass_Attrs(info),
- ILTypeDefinitionFlags, 0);
- ILDumpClassName(outstream, image, info, flags);
- fputs("\n// { \n", outstream);
- }
- }
-
- /* Dump the nested classes */
- nested = 0;
- while((nested = ILClassNextNested(info, nested)) != 0)
- {
- Dump_TypeAndNested(image, outstream, flags,
-
ILNestedInfoGetChild(nested));
- }
-
- /* Dump the class members */
- member = 0;
- while((member = ILClassNextMember(info, member)) != 0)
- {
- switch(ILMemberGetKind(member))
- {
- case IL_META_MEMBERKIND_METHOD:
- {
- Dump_MethodDef(image, outstream, flags,
(ILMethod *)member);
- }
- break;
-
- case IL_META_MEMBERKIND_FIELD:
- {
- Dump_FieldDef(image, outstream, flags, (ILField
*)member);
- }
- break;
-
- case IL_META_MEMBERKIND_EVENT:
- {
- Dump_EventDef(image, outstream, flags, (ILEvent
*)member);
- }
- break;
-
- case IL_META_MEMBERKIND_PROPERTY:
- {
- Dump_PropertyDef(image, outstream, flags,
(ILProperty *)member);
- }
- break;
- }
- }
-
- /* Dump overrides that don't have bodies in this class */
- over = 0;
- while((over = (ILOverride *)ILClassNextMemberByKind
- (info, (ILMember *)over,
IL_META_MEMBERKIND_OVERRIDE)) != 0)
- {
- body = ILOverride_Body(over);
- if(ILMethod_Owner(body) != info)
- {
- decl = ILOverride_Decl(over);
- fputs("\t.override ", outstream);
- ILDumpClassName(outstream, image, ILMethod_Owner(decl),
flags);
- fputs("::", outstream);
- ILDumpIdentifier(outstream, ILMethod_Name(decl), 0,
flags);
- fputs(" with ", outstream);
- ILDumpMethodType(outstream, image,
ILMethod_Signature(body), flags,
- ILMethod_Owner(body),
ILMethod_Name(body), body);
- putc('\n', outstream);
- }
- }
-
- /* Dump the type footer, if it is not "<Module>" */
- if(!isModule)
- {
- fputs("}\n", outstream);
- }
- else if(ILClassNextMember(info, 0) != 0)
- {
- fputs("// }\n", outstream);
- }
-
- /* Dump the namespace footer if this class is not nested */
- if(!ILClass_NestedParent(info) && ILClass_Namespace(info))
- {
- fputs("}\n", outstream);
- }
-}
-
-/*
- * Dump information about a type definition.
- */
-static void Dump_TypeDef(ILImage *image, FILE *outstream, int flags,
- unsigned long token, ILClass
*info,
- unsigned long refToken)
-{
- /* Ignore the type if it is nested: we'll get it elsewhere */
- if(ILClass_IsPublic(info) || ILClass_IsPrivate(info))
- {
- Dump_TypeAndNested(image, outstream, flags, info);
- }
-}
-
-void ILDAsmDumpClasses(ILImage *image, FILE *outstream, int flags)
-{
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_TYPE_DEF,
- (ILDAsmWalkFunc)Dump_TypeDef, 0);
-}
-
-#ifdef __cplusplus
-};
-#endif
Index: ildasm/ildasm_data.c
===================================================================
RCS file: ildasm/ildasm_data.c
diff -N ildasm/ildasm_data.c
--- ildasm/ildasm_data.c 28 Feb 2003 00:05:00 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,183 +0,0 @@
-/*
- * ildasm_data.c - Dump ".data" blocks.
- *
- * Copyright (C) 2003 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Dump the contents of a data section, with labels inserted
- * wherever fields reference the data.
- */
-static void DumpData(FILE *outstream, ILImage *image, const char *heading,
- unsigned long rva, void *addr,
unsigned long len,
- unsigned long *fieldRVAs, unsigned
long numFieldRVAs)
-{
- while(len > 0)
- {
- /* Scan for the next field >= the current address */
- while(numFieldRVAs > 0 && *fieldRVAs < rva)
- {
- ++fieldRVAs;
- --numFieldRVAs;
- }
- if(numFieldRVAs > 0 && *fieldRVAs >= (rva + len))
- {
- numFieldRVAs = 0;
- }
-
- /* Dump data before the next field */
- if(numFieldRVAs > 0 && *fieldRVAs != rva)
- {
- fprintf(outstream, "%s D_0x%08lX = bytearray", heading,
rva);
- ILDAsmDumpBinaryBlob(outstream, image, addr,
-
(ILUInt32)(*fieldRVAs - rva));
- putc('\n', outstream);
- addr = (void *)(((unsigned char *)addr) + (*fieldRVAs -
rva));
- len -= (*fieldRVAs - rva);
- rva = *fieldRVAs;
- }
-
- /* Dump the field or the remaining data */
- fprintf(outstream, "%s D_0x%08lX = bytearray", heading, rva);
- if(numFieldRVAs > 1)
- {
- ILDAsmDumpBinaryBlob(outstream, image, addr,
-
(ILUInt32)(fieldRVAs[1] - rva));
- addr = (void *)(((unsigned char *)addr) + (fieldRVAs[1]
- rva));
- len -= (fieldRVAs[1] - rva);
- rva = fieldRVAs[1];
- }
- else
- {
- ILDAsmDumpBinaryBlob(outstream, image, addr, len);
- len = 0;
- }
- putc('\n', outstream);
- }
-}
-
-void ILDAsmDumpDataSections(FILE *outstream, ILImage *image)
-{
- unsigned long *fieldRVAs;
- unsigned long numFieldRVAs;
- unsigned long posn;
- unsigned long posn2;
- unsigned long temp;
- ILFieldRVA *rva;
- void *dataAddr;
- unsigned long dataRVA;
- unsigned long dataLen;
- void *tlsAddr;
- unsigned long tlsRVA;
- unsigned long tlsLen;
-
- /* Collect all field RVA values so that we know where to
- insert the data labels */
- numFieldRVAs = ILImageNumTokens(image, IL_META_TOKEN_FIELD_RVA);
- if(numFieldRVAs > 0)
- {
- fieldRVAs = (unsigned long *)ILMalloc
- (sizeof(unsigned long) * numFieldRVAs);
- if(!fieldRVAs)
- {
- numFieldRVAs = 0;
- }
- else
- {
- rva = 0;
- posn = 0;
- while((rva = (ILFieldRVA *)ILImageNextToken
- (image,
IL_META_TOKEN_FIELD_RVA, rva)) != 0)
- {
- fieldRVAs[posn++] = ILFieldRVA_RVA(rva);
- }
- }
- }
- else
- {
- fieldRVAs = 0;
- }
-
- /* Sort the RVA list into ascending order */
- if(numFieldRVAs > 1)
- {
- for(posn = 0; posn < (numFieldRVAs - 1); ++posn)
- {
- for(posn2 = posn + 1; posn2 < numFieldRVAs; ++posn2)
- {
- if(fieldRVAs[posn] > fieldRVAs[posn2])
- {
- temp = fieldRVAs[posn];
- fieldRVAs[posn] = fieldRVAs[posn2];
- fieldRVAs[posn2] = temp;
- }
- }
- }
- }
-
- /* Find the extents of the ".data" and ".tls" sections */
- if(ILImageGetSection(image, IL_SECTION_DATA, &dataAddr, &dataLen))
- {
- dataRVA = ILImageGetSectionAddr(image, IL_SECTION_DATA);
- }
- else
- {
- dataAddr = 0;
- dataLen = 0;
- dataRVA = 0;
- }
- if(ILImageGetSection(image, IL_SECTION_TLS, &tlsAddr, &tlsLen))
- {
- tlsRVA = ILImageGetSectionAddr(image, IL_SECTION_TLS);
- }
- else
- {
- tlsAddr = 0;
- tlsLen = 0;
- tlsRVA = 0;
- }
-
- /* Dump the ".data" section */
- if(dataLen > 0)
- {
- DumpData(outstream, image, ".data", dataRVA, dataAddr, dataLen,
- fieldRVAs, numFieldRVAs);
- }
-
- /* Dump the ".tls" section */
- if(tlsLen > 0)
- {
- DumpData(outstream, image, ".data tls", tlsRVA, tlsAddr, tlsLen,
- fieldRVAs, numFieldRVAs);
- }
-
- /* Free the "fieldRVAs" array and exit */
- if(fieldRVAs)
- {
- ILFree(fieldRVAs);
- }
-}
-
-#ifdef __cplusplus
-};
-#endif
Index: ildasm/ildasm_global.c
===================================================================
RCS file: ildasm/ildasm_global.c
diff -N ildasm/ildasm_global.c
--- ildasm/ildasm_global.c 28 Feb 2003 06:04:03 -0000 1.6
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,400 +0,0 @@
-/*
- * ildasm_global.c - Disassemble global information.
- *
- * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Dump information about a module.
- */
-static void Dump_Module(ILImage *image, FILE *outstream, int flags,
- unsigned long token, ILModule
*module,
- unsigned long refToken)
-{
- ILUInt32 generation;
- const unsigned char *guid;
- fputs(".module ", outstream);
- ILDumpIdentifier(outstream, ILModule_Name(module), 0, flags);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, " /*%08lX*/", token);
- }
- generation = ILModuleGetGeneration(module);
- if(generation != 0)
- {
- fprintf(outstream, "\n// Generation: %lu",
- (unsigned long)generation);
- }
- fputs("\n// MVID: ", outstream);
- ILDumpGUID(outstream, ILModuleGetMVID(module));
- guid = ILModuleGetEncId(module);
- if(guid)
- {
- fputs("\n// EncId: ", outstream);
- ILDumpGUID(outstream, guid);
- }
- guid = ILModuleGetEncBaseId(module);
- if(guid)
- {
- fputs("\n// EncBaseId: ", outstream);
- ILDumpGUID(outstream, guid);
- }
- putc('\n', outstream);
- if(ILProgramItem_HasAttrs(module))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 0,
-
ILToProgramItem(module));
- }
-}
-
-/*
- * Dump information about a module reference.
- */
-static void Dump_ModuleRef(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILModule *module,
- unsigned long refToken)
-{
- fputs(".module extern ", outstream);
- ILDumpIdentifier(outstream, ILModule_Name(module), 0, flags);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, " /*%08lX*/", token);
- }
- putc('\n', outstream);
- if(ILProgramItem_HasAttrs(module))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 0,
-
ILToProgramItem(module));
- }
-}
-
-/*
- * Dump information about an OS definition.
- */
-static void Dump_OSDef(ILImage *image, FILE *outstream, int flags,
- unsigned long token, ILOSInfo
*osinfo,
- unsigned long refToken)
-{
- fprintf(outstream, "\t.os %lu .ver %lu:%lu\n",
- (unsigned long)(ILOSInfo_Identifier(osinfo)),
- (unsigned long)(ILOSInfo_Major(osinfo)),
- (unsigned long)(ILOSInfo_Minor(osinfo)));
-}
-
-/*
- * Dump information about a processor definition.
- */
-static void Dump_ProcessorDef(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILProcessorInfo *procinfo,
- unsigned long
refToken)
-{
- fprintf(outstream, "\t.processor %lu\n",
- (unsigned long)ILProcessorInfo_Number(procinfo));
-}
-
-/*
- * Dump information about an assembly.
- */
-static void Dump_Assembly(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILAssembly *assem,
- unsigned long refToken)
-{
- const ILUInt16 *version;
- const void *orig;
- unsigned long origLen;
- fputs(".assembly ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ", token);
- }
- ILDumpFlags(outstream, ILAssembly_Attrs(assem), ILAssemblyFlags, 0);
- ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
- fputs("\n{\n", outstream);
- ILDAsmDumpSecurity(image, outstream, (ILProgramItem *)assem, flags);
- if(ILAssembly_HashAlg(assem) != 0)
- {
- fprintf(outstream, "\t.hash algorithm 0x%08lX\n",
- (unsigned long)(ILAssembly_HashAlg(assem)));
- }
- version = ILAssemblyGetVersion(assem);
- fprintf(outstream, "\t.ver %lu:%lu:%lu:%lu\n",
- (unsigned long)(version[0]), (unsigned
long)(version[1]),
- (unsigned long)(version[2]), (unsigned
long)(version[3]));
- if((orig = ILAssemblyGetOriginator(assem, &origLen)) != 0)
- {
- fputs("\t.publickey =", outstream);
- ILDAsmDumpBinaryBlob(outstream, image, orig, origLen);
- putc('\n', outstream);
- }
- if(ILAssembly_Locale(assem))
- {
- fputs("\t.locale ", outstream);
- ILDumpString(outstream, ILAssembly_Locale(assem));
- putc('\n', outstream);
- }
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_OS_DEF,
- (ILDAsmWalkFunc)Dump_OSDef, 0);
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_PROCESSOR_DEF,
- (ILDAsmWalkFunc)Dump_ProcessorDef, 0);
- if(ILProgramItem_HasAttrs(assem))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
-
ILToProgramItem(assem));
- }
- fputs("}\n", outstream);
-}
-
-/*
- * Dump information about an OS reference.
- */
-static void Dump_OSRef(ILImage *image, FILE *outstream, int flags,
- unsigned long token, ILOSInfo
*osinfo,
- unsigned long refToken)
-{
- if(ILProgramItem_Token(ILOSInfo_Assembly(osinfo)) == refToken)
- {
- fprintf(outstream, "\t.os %lu .ver %lu:%lu\n",
- (unsigned long)(ILOSInfo_Identifier(osinfo)),
- (unsigned long)(ILOSInfo_Major(osinfo)),
- (unsigned long)(ILOSInfo_Minor(osinfo)));
- }
-}
-
-/*
- * Dump information about a processor reference.
- */
-static void Dump_ProcessorRef(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILProcessorInfo *procinfo,
- unsigned long
refToken)
-{
- if(ILProgramItem_Token(ILProcessorInfo_Assembly(procinfo)) == refToken)
- {
- fprintf(outstream, "\t.processor %lu\n",
- (unsigned
long)(ILProcessorInfo_Number(procinfo)));
- }
-}
-
-/*
- * Dump information about an assembly reference.
- */
-static void Dump_AssemblyRef(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILAssembly *assem,
- unsigned long refToken)
-{
- const ILUInt16 *version;
- const void *orig;
- unsigned long origLen;
- fputs(".assembly extern ", outstream);
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, "/*%08lX*/ ", token);
- }
- ILDumpFlags(outstream, ILAssembly_RefAttrs(assem),
- ILAssemblyRefFlags, 0);
- ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
- fputs("\n{\n", outstream);
- version = ILAssemblyGetVersion(assem);
- fprintf(outstream, "\t.ver %lu:%lu:%lu:%lu\n",
- (unsigned long)(version[0]), (unsigned
long)(version[1]),
- (unsigned long)(version[2]), (unsigned
long)(version[3]));
- if((orig = ILAssemblyGetOriginator(assem, &origLen)) != 0)
- {
- if(ILAssembly_HasFullOriginator(assem))
- {
- fputs("\t.publickey =", outstream);
- }
- else
- {
- fputs("\t.publickeytoken =", outstream);
- }
- ILDAsmDumpBinaryBlob(outstream, image, orig, origLen);
- putc('\n', outstream);
- }
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_OS_REF,
- (ILDAsmWalkFunc)Dump_OSRef, token);
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_PROCESSOR_REF,
- (ILDAsmWalkFunc)Dump_ProcessorRef,
token);
- if(ILProgramItem_HasAttrs(assem))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
-
ILToProgramItem(assem));
- }
- fputs("}\n", outstream);
-}
-
-/*
- * Dump information about a file declaration.
- */
-static void Dump_File(ILImage *image, FILE *outstream, int flags,
- unsigned long token, ILFileDecl *decl,
- unsigned long refToken)
-{
- const void *hash;
- unsigned long len;
- fputs(".file ", outstream);
- ILDumpFlags(outstream, ILFileDecl_Attrs(decl), ILFileFlags, 0);
- ILDumpIdentifier(outstream, ILFileDecl_Name(decl), 0, flags);
- if((hash = ILFileDeclGetHash(decl, &len)) != 0)
- {
- fputs(" .hash =", outstream);
- ILDAsmDumpBinaryBlob(outstream, image, hash, len);
- }
- putc('\n', outstream);
-}
-
-/*
- * Dump information about a manifest resource declaration.
- */
-static void Dump_ManifestRes(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILManifestRes *res,
- unsigned long refToken)
-{
- ILFileDecl *decl;
- ILAssembly *assem;
- fputs(".mresource ", outstream);
- ILDumpFlags(outstream, ILManifestRes_Attrs(res), ILManifestResFlags, 0);
- ILDumpIdentifier(outstream, ILManifestRes_Name(res), 0, flags);
- fputs("\n{\n", outstream);
- if((decl = ILManifestResGetOwnerFile(res)) != 0)
- {
- fputs("\t.file ", outstream);
- ILDumpIdentifier(outstream, ILFileDecl_Name(decl), 0, flags);
- fprintf(outstream, " at 0x%08lu\n",
- (unsigned long)(ILFileDecl_Attrs(decl)));
- }
- else if((assem = ILManifestResGetOwnerAssembly(res)) != 0)
- {
- fputs("\t.assembly extern ", outstream);
- ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
- putc('\n', outstream);
- }
- ILDAsmDumpCustomAttrs(image, outstream, flags, 1,
- ILToProgramItem(res));
- fputs("}\n", outstream);
-}
-
-/*
- * Dump information about a exported type declaration.
- */
-static void Dump_ExportedType(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
ILExportedType *type,
- unsigned long
refToken)
-{
- ILProgramItem *scope;
- ILFileDecl *decl;
- ILAssembly *assem;
- ILExportedType *expType;
-
- /* Dump the export heading */
- fputs(".class extern ", outstream);
- ILDumpFlags(outstream, ILExportedType_Attrs(type),
- ILExportedTypeDefinitionFlags, 0);
- ILDumpIdentifier(outstream, ILExportedType_Name(type),
- ILExportedType_Namespace(type), flags);
- fputs("\n{\n", outstream);
-
- /* Dump the scope */
- scope = ILExportedType_Scope(type);
- if((decl = ILProgramItemToFileDecl(scope)) != 0)
- {
- fputs("\t.file ", outstream);
- ILDumpIdentifier(outstream, ILFileDecl_Name(decl), 0, flags);
- putc('\n', outstream);
- }
- else if((assem = ILProgramItemToAssembly(scope)) != 0)
- {
- fputs("\t.assembly extern ", outstream);
- ILDumpIdentifier(outstream, ILAssembly_Name(assem), 0, flags);
- putc('\n', outstream);
- }
- else if((expType = ILProgramItemToExportedType(scope)) != 0)
- {
- fputs("\t.comtype ", outstream);
- ILDumpIdentifier(outstream, ILExportedType_Name(expType),
-
ILExportedType_Namespace(expType), flags);
- putc('\n', outstream);
- }
-
- /* Dump the class identifier in the foreign scope */
- fprintf(outstream, "\t.class 0x%08lx\n",
- (unsigned long)(ILExportedType_Id(type)));
-
- /* Dump any custom attributes associated with the exported type */
- if(ILProgramItem_HasAttrs(type))
- {
- ILDAsmDumpCustomAttrs(image, outstream, flags, 0,
-
ILToProgramItem(type));
- }
-
- /* Dump the export footer */
- fputs("}\n", outstream);
-}
-
-void ILDAsmDumpGlobal(ILImage *image, FILE *outstream, int flags)
-{
- /* Dump module references */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_MODULE_REF,
- (ILDAsmWalkFunc)Dump_ModuleRef, 0);
-
- /* Dump assembly reference information */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_ASSEMBLY_REF,
- (ILDAsmWalkFunc)Dump_AssemblyRef, 0);
-
- /* Dump file information */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_FILE,
- (ILDAsmWalkFunc)Dump_File, 0);
-
- /* Dump assembly information */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_ASSEMBLY,
- (ILDAsmWalkFunc)Dump_Assembly, 0);
-
- /* Dump manifest resource definitions */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_MANIFEST_RESOURCE,
- (ILDAsmWalkFunc)Dump_ManifestRes, 0);
-
- /* Dump module definitions */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_MODULE,
- (ILDAsmWalkFunc)Dump_Module, 0);
-
- /* Dump exported types */
- ILDAsmWalkTokens(image, outstream, flags,
- IL_META_TOKEN_EXPORTED_TYPE,
- (ILDAsmWalkFunc)Dump_ExportedType, 0);
-
- /* Dump the ".data" and ".tls" sections */
- ILDAsmDumpDataSections(outstream, image);
-}
-
-#ifdef __cplusplus
-};
-#endif
Index: ildasm/ildasm_internal.h
===================================================================
RCS file: ildasm/ildasm_internal.h
diff -N ildasm/ildasm_internal.h
--- ildasm/ildasm_internal.h 1 Aug 2003 10:06:02 -0000 1.7
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,105 +0,0 @@
-/*
- * ildasm_internal.h - Internal definitions for the disassembler.
- *
- * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef _ILDASM_INTERNAL_H
-#define _ILDASM_INTERNAL_H
-
-#include <stdio.h>
-#include "il_system.h"
-#include "il_image.h"
-#include "il_dumpasm.h"
-#include "il_program.h"
-#include "il_opcodes.h"
-#include "il_utils.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Extra flags for altering the output, in addition to "IL_DUMP_xxx".
- */
-#define ILDASM_REAL_OFFSETS (1 << 8)
-#define ILDASM_SUPPRESS_PREFIX (1 << 9)
-#define ILDASM_NO_IL (1 << 10)
-#define ILDASM_INSTRUCTION_BYTES (1 << 11)
-#define ILDASM_RESOLVE_ALL (1 << 12)
-
-/*
- * Dump a binary blob to an output stream.
- */
-void ILDAsmDumpBinaryBlob(FILE *outstream, ILImage *image,
- const void *blob, ILUInt32
blobLen);
-
-/*
- * Walk a list of tokens and call a supplied callback for each one.
- */
-typedef void (*ILDAsmWalkFunc)(ILImage *image, FILE *outstream, int flags,
- unsigned long token,
void *data,
- unsigned long
refToken);
-void ILDAsmWalkTokens(ILImage *image, FILE *outstream, int flags,
- unsigned long tokenKind,
ILDAsmWalkFunc callback,
- unsigned long refToken);
-
-/*
- * Dump the contents of a method.
- */
-void ILDAsmDumpMethod(ILImage *image, FILE *outstream,
- ILMethod *method, int flags,
- int isEntryPoint);
-
-/*
- * Dump the contents of a Java method.
- */
-void ILDAsmDumpJavaMethod(ILImage *image, FILE *outstream,
- ILMethod *method, int flags);
-
-/*
- * Dump custom attributes for a program item.
- */
-void ILDAsmDumpCustomAttrs(ILImage *image, FILE *outstream, int flags,
- int indent, ILProgramItem
*item);
-
-/*
- * Dump global definitions such as modules, assemblies, etc.
- */
-void ILDAsmDumpGlobal(ILImage *image, FILE *outstream, int flags);
-
-/*
- * Dump all class definitions.
- */
-void ILDAsmDumpClasses(ILImage *image, FILE *outstream, int flags);
-
-/*
- * Dump the security information associated with a program item.
- */
-void ILDAsmDumpSecurity(ILImage *image, FILE *outstream,
- ILProgramItem *item, int flags);
-
-/*
- * Dump the ".data" and ".tls" sections.
- */
-void ILDAsmDumpDataSections(FILE *outstream, ILImage *image);
-
-#ifdef __cplusplus
-};
-#endif
-
-#endif /* _ILDASM_INTERNAL_H */
Index: ildasm/ildasm_java.c
===================================================================
RCS file: ildasm/ildasm_java.c
diff -N ildasm/ildasm_java.c
--- ildasm/ildasm_java.c 30 Sep 2003 01:38:14 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,866 +0,0 @@
-/*
- * ildasm_java.c - Disassemble Java method contents.
- *
- * Copyright (C) 2002 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-#include "il_jopcodes.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef IL_CONFIG_JAVA
-
-/* "image/jopcodes.c" */
-extern ILOpcodeInfo const ILJavaOpcodeTable[256];
-
-/*
- * Read big-endian quantities of various sizes.
- */
-#define IL_BREAD_INT16(buf) ((ILInt16)(_IL_READ_BYTE((buf), 1) | \
-
_IL_READ_BYTE_SHIFT((buf), 0, 8)))
-#define IL_BREAD_UINT16(buf) ((ILUInt16)(_IL_READ_BYTE((buf), 1) | \
-
_IL_READ_BYTE_SHIFT((buf), 0, 8)))
-#define IL_BREAD_INT32(buf) ((ILInt32)(_IL_READ_BYTE((buf), 3) | \
-
_IL_READ_BYTE_SHIFT((buf), 2, 8) | \
-
_IL_READ_BYTE_SHIFT((buf), 1, 16) | \
-
_IL_READ_BYTE_SHIFT((buf), 0, 24)))
-#define IL_BREAD_UINT32(buf) ((ILUInt32)(_IL_READ_BYTE((buf), 3) | \
-
_IL_READ_BYTE_SHIFT((buf), 2, 8) | \
-
_IL_READ_BYTE_SHIFT((buf), 1, 16) | \
-
_IL_READ_BYTE_SHIFT((buf), 0, 24)))
-#define IL_BREAD_INT64(buf) \
- (((ILInt64)(IL_BREAD_UINT32((buf) + 4))) | \
- (((ILInt64)(IL_BREAD_INT32((buf)))) << 32))
-#define IL_BREAD_UINT64(buf) \
- (((ILUInt64)(IL_BREAD_UINT32((buf) + 4))) | \
- (((ILUInt64)(IL_BREAD_UINT32((buf)))) << 32))
-
-/*
- * Determine the size of a Java instruction. Returns zero
- * if the instruction is invalid.
- */
-static unsigned long JavaInsnSize(unsigned char *buf, unsigned long size,
- unsigned long
offset)
-{
- unsigned long len;
- ILInt32 tempa;
- ILInt32 tempb;
- ILUInt32 swsize;
- if(*buf == JAVA_OP_WIDE)
- {
- /* Wide instruction */
- if(size < 2)
- {
- return 0;
- }
- switch(buf[1])
- {
- case JAVA_OP_ILOAD:
- case JAVA_OP_FLOAD:
- case JAVA_OP_ALOAD:
- case JAVA_OP_LLOAD:
- case JAVA_OP_DLOAD:
- case JAVA_OP_ISTORE:
- case JAVA_OP_FSTORE:
- case JAVA_OP_ASTORE:
- case JAVA_OP_LSTORE:
- case JAVA_OP_DSTORE:
- case JAVA_OP_RET:
- {
- if(size < 4)
- return 0;
- else
- return 4;
- }
- /* Not reached */
-
- case JAVA_OP_IINC:
- {
- if(size < 6)
- return 0;
- else
- return 6;
- }
- /* Not reached */
- }
- return 0;
- }
- else if(*buf == JAVA_OP_LOOKUPSWITCH)
- {
- /* Lookup switch instruction */
- len = 1;
- while(((offset + len) & 3) != 0)
- {
- ++len;
- }
- if(size < (len + 8))
- {
- return 0;
- }
- swsize = IL_BREAD_UINT32(buf + len + 4);
- if(swsize > (ILInt32)0x20000000)
- {
- return 0;
- }
- len += 8 + swsize * 8;
- if(size < len)
- {
- return 0;
- }
- return len;
- }
- else if(*buf == JAVA_OP_TABLESWITCH)
- {
- /* Table switch instruction */
- len = 1;
- while(((offset + len) & 3) != 0)
- {
- ++len;
- }
- if(size < (len + 12))
- {
- return 0;
- }
- tempa = IL_BREAD_INT32(buf + len + 4);
- tempb = IL_BREAD_INT32(buf + len + 8);
- if(tempa > tempb ||
- (swsize = (ILUInt32)(tempb - tempa + 1)) >
(ILUInt32)0x20000000)
- {
- return 0;
- }
- len += 12 + swsize * 4;
- if(size < len)
- {
- return 0;
- }
- return len;
- }
- else if(ILJavaOpcodeTable[*buf].args == IL_OPCODE_ARGS_INVALID)
- {
- /* Invalid instruction */
- return 0;
- }
- else
- {
- /* Ordinary instruction */
- return ILJavaOpcodeTable[*buf].size;
- }
-}
-
-/*
- * Mark a destination jump point.
- */
-#define MarkDest(dest) \
- do { \
- unsigned long _dest = (unsigned long)(dest); \
- if(_dest < size) \
- { \
- jumpPoints[_dest / 32] |= \
- (ILUInt32)(1L << (_dest % 32));
\
- } \
- } while (0)
-
-/*
- * Dump all Java instructions in a given buffer. Returns zero
- * if there is something wrong with the buffer's format.
- */
-static int DumpJavaInstructions(ILImage *image, ILClass *classInfo,
- FILE *outstream,
- unsigned char
*buf, unsigned long size,
- unsigned long addr,
ILException *clauses,
- int flags)
-{
- ILUInt32 *jumpPoints;
- int result = 0;
- unsigned char *temp;
- unsigned char *temp2;
- unsigned long tsize;
- unsigned long offset;
- unsigned long dest;
- unsigned long isize;
- unsigned long args;
- const ILOpcodeInfo *info;
- int argType;
- unsigned long numItems;
- unsigned long item;
- int isWide;
-
- /* Allocate a helper array to mark jump points within the code */
- jumpPoints = (ILUInt32 *)ILCalloc(((size + 3) & ~3), 1);
- if(!jumpPoints)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
-
- /* Mark the entry point to the method so we get a label for it */
- jumpPoints[0] |= (ILUInt32)1;
-
- /* Mark the position of exception clauses */
- while(clauses != 0)
- {
- MarkDest(clauses->tryOffset);
- MarkDest(clauses->tryOffset + clauses->tryLength);
- MarkDest(clauses->handlerOffset);
- clauses = clauses->next;
- }
-
- /* Scan the instruction list to locate jump points */
- temp = buf;
- tsize = size;
- offset = 0;
- while(tsize > 0)
- {
- isize = JavaInsnSize(temp, tsize, offset);
- if(!isize)
- {
- fprintf(outstream, "\t\t// unknown instruction
0x%02X\n",
- ((int)(temp[0])) & 0xFF);
- goto cleanup;
- }
- info = &(ILJavaOpcodeTable[((int)(temp[0])) & 0xFF]);
- if(info->args == IL_OPCODE_ARGS_SHORT_JUMP)
- {
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT16(temp + 1)));
- MarkDest(dest);
- }
- else if(info->args == IL_OPCODE_ARGS_LONG_JUMP)
- {
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp + 1)));
- MarkDest(dest);
- }
- else if(info->args == IL_OPCODE_ARGS_SWITCH)
- {
- /* Align the switch instruction's arguments */
- args = 1;
- while(((offset + args) & 3) != 0)
- {
- ++args;
- }
-
- /* Mark the default label */
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp + args)));
- MarkDest(dest);
-
- /* Process the bulk of the switch */
- if(temp[0] == JAVA_OP_TABLESWITCH)
- {
- /* Mark all of the labels in a table-based
switch */
- item = (unsigned long)(IL_BREAD_INT32(temp +
args + 8) -
-
IL_BREAD_INT32(temp + args + 4) + 1);
- temp2 = temp + args + 12;
- while(item > 0)
- {
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp2)));
- MarkDest(dest);
- --item;
- temp2 += 4;
- }
- }
- else
- {
- /* Mark all of the labels in a lookup-based
switch */
- item = (unsigned long)(IL_BREAD_UINT32(temp +
args + 4));
- temp2 = temp + args + 8 + 4;
- while(item > 0)
- {
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp2)));
- MarkDest(dest);
- --item;
- temp2 += 8;
- }
- }
- }
- offset += isize;
- temp += isize;
- tsize -= isize;
- }
-
- /* Dump the instructions */
- temp = buf;
- tsize = size;
- offset = 0;
- while(tsize > 0)
- {
- /* If this is a jump point, then print a label for it */
- if((jumpPoints[offset / 32] & (ILUInt32)(1L << (offset % 32)))
!= 0)
- {
- fprintf(outstream, "\t?L%lx:\n", offset + addr);
- }
-
- /* Extract the instruction from the method input stream */
- isize = JavaInsnSize(temp, tsize, offset);
- info = &(ILJavaOpcodeTable[((int)(temp[0])) & 0xFF]);
- if(*temp == JAVA_OP_WIDE)
- {
- /* Process a wide instruction */
- info = &(ILJavaOpcodeTable[((int)(temp[1])) & 0xFF]);
- isWide = 1;
- args = 2;
- }
- else
- {
- /* Process an ordinary instruction */
- isWide = 0;
- args = 1;
- }
-
- /* Dump the instruction based on its argument type */
- argType = info->args;
- putc('\t', outstream);
- putc('\t', outstream);
- fputs(info->name, outstream);
- if(argType != IL_OPCODE_ARGS_INVALID &&
- argType != IL_OPCODE_ARGS_NONE)
- {
- numItems = (unsigned long)(strlen(info->name));
- while(numItems < 10)
- {
- putc(' ', outstream);
- ++numItems;
- }
- putc(' ', outstream);
- }
- switch(argType)
- {
- case IL_OPCODE_ARGS_INVALID: break;
- case IL_OPCODE_ARGS_NONE: break;
-
- case IL_OPCODE_ARGS_INT8:
- {
- fprintf(outstream, "%d",
(int)(ILInt8)(temp[args]));
- }
- break;
-
- case IL_OPCODE_ARGS_INT16:
- {
- fprintf(outstream, "%d",
- (int)(ILInt16)(IL_BREAD_UINT16(temp +
args)));
- }
- break;
-
- case IL_OPCODE_ARGS_TOKEN:
- case IL_OPCODE_ARGS_CALL:
- {
- /* An instruction that takes a constant pool
entry argument */
- if(temp[0] == JAVA_OP_LDC)
- {
- item = (unsigned long)(temp[args]);
- }
- else
- {
- item = (unsigned
long)(IL_BREAD_UINT16(temp + args));
- }
- switch(ILJavaGetConstType(classInfo,
(ILUInt32)item))
- {
- case JAVA_CONST_UTF8:
- {
- const char *str;
- ILUInt32 len;
- str = ILJavaGetUTF8String
- (classInfo,
(ILUInt32)item, &len);
- if(str && len)
- {
-
ILDumpStringLen(outstream, str, (int)len);
- }
- else
- {
- fputs("\"\"",
outstream);
- }
- }
- break;
-
- case JAVA_CONST_INTEGER:
- {
- ILInt32 value;
- if(ILJavaGetInteger(classInfo,
(ILUInt32)item, &value))
- {
- fprintf(outstream,
"%ld", (long)value);
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- case JAVA_CONST_FLOAT:
- {
- ILFloat value;
- unsigned char buf[4];
- if(ILJavaGetFloat(classInfo,
(ILUInt32)item, &value))
- {
- IL_WRITE_FLOAT(buf,
value);
- fprintf(outstream,
"float32(0x%02X%02X%02X%02X)",
-
(((int)(buf[3])) & 0xFF),
-
(((int)(buf[2])) & 0xFF),
-
(((int)(buf[1])) & 0xFF),
-
(((int)(buf[0])) & 0xFF));
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- case JAVA_CONST_LONG:
- {
- ILInt64 value;
- if(ILJavaGetLong(classInfo,
(ILUInt32)item, &value))
- {
- fprintf(outstream,
"0x%08lX%08lX",
-
(long)((value >> 32) & (long)0xFFFFFFFF),
-
(long)(value & (long)0xFFFFFFFF));
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- case JAVA_CONST_DOUBLE:
- {
- ILDouble value;
- unsigned char buf[8];
- if(ILJavaGetDouble(classInfo,
(ILUInt32)item, &value))
- {
- IL_WRITE_DOUBLE(buf,
value);
- fprintf(outstream,
-
"float64(0x%02X%02X%02X%02X%02X%02X%02X%02X)",
-
(((int)(buf[7])) & 0xFF),
-
(((int)(buf[6])) & 0xFF),
-
(((int)(buf[5])) & 0xFF),
-
(((int)(buf[4])) & 0xFF),
-
(((int)(buf[3])) & 0xFF),
-
(((int)(buf[2])) & 0xFF),
-
(((int)(buf[1])) & 0xFF),
-
(((int)(buf[0])) & 0xFF));
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- case JAVA_CONST_CLASS:
- {
- ILClass *ref;
- ref = ILJavaGetClass(classInfo,
(ILUInt32)item, 1);
- if(ref)
- {
-
ILDumpClassName(outstream, image, ref, flags);
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- case JAVA_CONST_STRING:
- {
- const char *str;
- ILUInt32 len;
- str =
ILJavaGetString(classInfo, (ILUInt32)item, &len);
- if(str && len)
- {
-
ILDumpStringLen(outstream, str, (int)len);
- }
- else
- {
- fputs("\"\"",
outstream);
- }
- }
- break;
-
- case JAVA_CONST_FIELDREF:
- {
- ILField *field;
- ILClass *info;
- field =
ILJavaGetField(classInfo, (ILUInt32)item, 1,
-
(temp[0] == JAVA_OP_GETSTATIC ||
-
temp[0] == JAVA_OP_PUTSTATIC));
- if(field)
- {
- ILDumpType(outstream,
image,
-
ILField_Type(field), flags);
- putc(' ', outstream);
- info =
ILField_Owner(field);
-
if(ILClassIsValueType(info))
- {
-
fputs("valuetype ", outstream);
- }
- else
- {
- fputs("class ",
outstream);
- }
-
ILDumpClassName(outstream, image, info, flags);
- fputs("::", outstream);
-
ILDumpIdentifier(outstream,
-
ILField_Name(field), 0, flags);
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- case JAVA_CONST_METHODREF:
- {
- ILMethod *method;
- method =
ILJavaGetMethod(classInfo, (ILUInt32)item, 1,
-
(temp[0] == JAVA_OP_INVOKESTATIC));
- if(method)
- {
-
ILDumpMethodType(outstream, image,
-
ILMethod_Signature(method), flags,
-
ILMethod_Owner(method),
-
ILMethod_Name(method),
-
method);
- }
- else
- {
- fputs("??", outstream);
- }
- }
- break;
-
- default:
- {
- fputs("??", outstream);
- }
- break;
- }
- }
- break;
-
- case IL_OPCODE_ARGS_NEW:
- {
- /* "newarray" instruction */
- switch(temp[args])
- {
- case JAVA_ARRAY_OF_BOOL:
- {
- fputs("bool", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_CHAR:
- {
- fputs("char", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_FLOAT:
- {
- fputs("float32", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_DOUBLE:
- {
- fputs("float64", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_BYTE:
- {
- fputs("int8", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_SHORT:
- {
- fputs("int16", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_INT:
- {
- fputs("int32", outstream);
- }
- break;
-
- case JAVA_ARRAY_OF_LONG:
- {
- fputs("int64", outstream);
- }
- break;
-
- default:
- {
- fprintf(outstream, "%d",
((int)(temp[args])) & 0xFF);
- }
- break;
- }
- }
- break;
-
- case IL_OPCODE_ARGS_SHORT_VAR:
- {
- if(!isWide)
- {
- fprintf(outstream, "%d",
((int)(temp[args])) & 0xFF);
- }
- else
- {
- fprintf(outstream, "%d",
-
((int)(IL_BREAD_UINT16(temp + args))));
- }
- }
- break;
-
- case IL_OPCODE_ARGS_SHORT_JUMP:
- {
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT16(temp + 1)));
- fprintf(outstream, "?L%lx", dest + addr);
- }
- break;
-
- case IL_OPCODE_ARGS_LONG_JUMP:
- {
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_UINT32(temp + 1)));
- fprintf(outstream, "?L%lx", dest + addr);
- }
- break;
-
- case IL_OPCODE_ARGS_CALLI:
- {
- /* Dump a call to an interface method */
- ILMethod *method;
- item = (unsigned long)(IL_BREAD_UINT16(temp +
args));
- method = ILJavaGetMethod(classInfo,
(ILUInt32)item, 1, 0);
- if(method)
- {
- ILDumpMethodType(outstream, image,
-
ILMethod_Signature(method), flags,
-
ILMethod_Owner(method),
-
ILMethod_Name(method),
-
method);
- }
- else
- {
- fputs("??", outstream);
- }
- fprintf(outstream, " %d",
(int)(ILUInt8)(temp[args + 2]));
- }
- break;
-
- case IL_OPCODE_ARGS_SWITCH:
- {
- /* Align the switch instruction's arguments */
- while(((offset + args) & 3) != 0)
- {
- ++args;
- }
-
- /* Output the default label */
- dest = (unsigned long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp + args)));
- fprintf(outstream, "?L%lx (", dest + addr);
-
- /* Dump the bulk of the switch instruction */
- if(temp[0] == JAVA_OP_TABLESWITCH)
- {
- /* Dump the base value for the
table-based switch */
- fprintf(outstream, "%ld : ",
- (long)(IL_BREAD_INT32(temp
+ args + 4)));
-
- /* Determine the number of items */
- numItems = (unsigned long)
- (IL_BREAD_INT32(temp +
args + 8) -
- IL_BREAD_INT32(temp +
args + 4) + 1);
-
- /* Dump the labels for the items */
- temp2 = temp + args + 12;
- for(item = 0; item < numItems; ++item)
- {
- if(item != 0)
- {
- putc(',', outstream);
- putc(' ', outstream);
- }
- dest = (unsigned
long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp2)));
- fprintf(outstream, "?L%lx",
dest + addr);
- temp2 += 4;
- }
- }
- else
- {
- /* Lookup-based switch instruction */
- numItems = (unsigned long)
- (IL_BREAD_UINT32(temp +
args + 4));
- temp2 = temp + args + 8;
- for(item = 0; item < numItems; ++item)
- {
- if(item != 0)
- {
- putc(',', outstream);
- putc(' ', outstream);
- }
- fprintf(outstream, "%ld : ",
-
(long)(IL_BREAD_INT32(temp2)));
- dest = (unsigned
long)(((long)offset) +
-
(long)(IL_BREAD_INT32(temp2 + 4)));
- fprintf(outstream, "?L%lx",
dest + addr);
- temp2 += 8;
- }
- }
-
- /* Terminate the switch instruction */
- putc(')', outstream);
- }
- break;
-
- case IL_OPCODE_ARGS_ANN_ARG:
- {
- /* Used to indicate the "iinc" instruction */
- if(!isWide)
- {
- fprintf(outstream, "%d, %d",
- ((int)(temp[args])) &
0xFF,
-
((int)((ILInt8)(temp[args + 1]))));
- }
- else
- {
- fprintf(outstream, "%d, %d",
-
((int)(IL_BREAD_UINT16(temp + args))),
-
((int)(IL_BREAD_INT16(temp + args + 2))));
- }
- }
- break;
-
- default: break;
- }
- putc('\n', outstream);
-
- /* Move on to the next instruction */
- offset += isize;
- temp += isize;
- tsize -= isize;
- }
- result = 1;
-
- /* Clean up and exit */
-cleanup:
- ILFree(jumpPoints);
- return result;
-}
-
-void ILDAsmDumpJavaMethod(ILImage *image, FILE *outstream,
- ILMethod *method, int flags)
-{
- unsigned long addr;
- ILMethodCode code;
- ILException *clauses;
- ILException *tempClause;
- ILClass *catchClass;
-
- /* Read the method code and exception information */
- if(!ILMethodGetCode(method, &code))
- {
- /* If we get here, then probably the method had an RVA,
- but the code was not IL */
- fputs("\t\t// Cannot dump the code for native methods\n",
outstream);
- return;
- }
- if(!ILMethodGetExceptions(method, &code, &clauses))
- {
- return;
- }
-
- /* Determine the address of the first instruction in the method */
- addr = ILMethod_RVA(method);
- if((flags & ILDASM_REAL_OFFSETS) != 0)
- {
- addr = ILImageRealOffset(image, addr) + code.headerSize;
- }
- else
- {
- addr += code.headerSize;
- }
-
- /* Output method header information */
- fprintf(outstream, "\t\t// Start of method header: %lx\n",
- (unsigned long)(addr - code.headerSize));
- fprintf(outstream, "\t\t.maxstack %lu\n", (unsigned
long)(code.maxStack));
- fprintf(outstream, "\t\t.locals %lu\n", (unsigned
long)(code.javaLocals));
-
- /* Dump the instructions within the method */
- if(!DumpJavaInstructions(image, ILMethod_Owner(method),
- outstream, (unsigned
char *)(code.code),
- code.codeLen, addr,
clauses, flags))
- {
- ILMethodFreeExceptions(clauses);
- return;
- }
-
- /* Dump information about the exceptions */
- tempClause = clauses;
- while(tempClause != 0)
- {
- fprintf(outstream, "\t\t.try ?L%lx to ?L%lx",
- tempClause->tryOffset + addr,
- tempClause->tryOffset + tempClause->tryLength +
addr);
- if((tempClause->flags & IL_META_EXCEPTION_FINALLY) != 0)
- {
- /* Finally clause */
- fprintf(outstream, " finally");
- }
- else
- {
- /* Catch clause */
- fputs(" catch ", outstream);
- catchClass = ILClass_FromToken(image,
tempClause->extraArg);
- if(catchClass)
- {
- ILDumpClassName(outstream, image, catchClass,
flags);
- }
- else
- {
- fputs("??", outstream);
- }
- }
- fprintf(outstream, " handler ?L%lx\n",
- tempClause->handlerOffset + addr);
- tempClause = tempClause->next;
- }
-
- /* Free the exception list and exit */
- ILMethodFreeExceptions(clauses);
-}
-
-#endif /* IL_CONFIG_JAVA */
-
-#ifdef __cplusplus
-};
-#endif
Index: ildasm/ildasm_method.c
===================================================================
RCS file: ildasm/ildasm_method.c
diff -N ildasm/ildasm_method.c
--- ildasm/ildasm_method.c 13 Jun 2003 04:23:03 -0000 1.17
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,974 +0,0 @@
-/*
- * ildasm_method.c - Disassemble method contents.
- *
- * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Get the size of a special instruction that does not
- * have a fixed-length representation.
- */
-static unsigned long GetSpecialSize(unsigned char *temp, unsigned long tsize)
-{
- unsigned long numItems;
- if(temp[0] == (unsigned char)IL_OP_SWITCH)
- {
- /* Switch lookup table */
- if(tsize < 5)
- {
- return 0;
- }
- numItems = (unsigned long)(IL_READ_UINT32(temp + 1));
- if(numItems >= ((unsigned long)0x40000000) ||
- (numItems * 4) > (tsize - 5))
- {
- return 0;
- }
- return numItems * 4 + 5;
- }
- else if(temp[0] == (unsigned char)IL_OP_ANN_DATA_S)
- {
- /* Short form of annotation data */
- if(tsize < 2)
- {
- return 0;
- }
- numItems = (((unsigned long)(temp[1])) & 0xFF);
- if((tsize - 2) < numItems)
- {
- return 0;
- }
- return numItems + 2;
- }
- else if(temp[0] == (unsigned char)IL_OP_PREFIX &&
- temp[1] == (unsigned char)IL_PREFIX_OP_ANN_DATA)
- {
- /* Long form of annotation data */
- if(tsize < 6)
- {
- return 0;
- }
- numItems = (unsigned long)(IL_READ_UINT32(temp + 2));
- if((tsize - 6) < numItems)
- {
- return 0;
- }
- return numItems + 6;
- }
- else if(temp[0] == (unsigned char)IL_OP_ANN_PHI)
- {
- /* Static single assignment annotation data */
- if(tsize < 3)
- {
- return 0;
- }
- numItems = (unsigned long)(IL_READ_UINT16(temp + 1));
- if((tsize - 3) < (numItems * 2))
- {
- return 0;
- }
- return numItems * 2 + 3;
- }
- return 0;
-}
-
-/*
- * Dump a token.
- */
-static void DumpToken(ILImage *image, FILE *outstream,
- int flags, unsigned long token,
- int prefixWithKind)
-{
- ILClass *info;
- ILField *field;
- ILMethod *method;
- ILMember *member;
- ILMember *origMember;
- ILTypeSpec *spec;
- ILStandAloneSig *sig;
- ILType *type;
- ILMethodSpec *mspec;
-
- switch(token & IL_META_TOKEN_MASK)
- {
- case IL_META_TOKEN_TYPE_REF:
- case IL_META_TOKEN_TYPE_DEF:
- {
- /* A reference to a type */
- info = ILClass_FromToken(image, token);
- if(info)
- {
- if((flags & ILDASM_SUPPRESS_PREFIX) == 0)
- {
- if(ILClassIsValueType(info))
- {
- fputs("valuetype ", outstream);
- }
- else
- {
- fputs("class ", outstream);
- }
- }
- ILDumpClassName(outstream, image, info, flags);
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- case IL_META_TOKEN_FIELD_DEF:
- {
- /* A reference to a field */
- field = ILField_FromToken(image, token);
- if(field)
- {
- dumpField:
- if(prefixWithKind)
- {
- fputs("field ", outstream);
- }
- ILDumpType(outstream, image,
ILField_Type(field), flags);
- putc(' ', outstream);
- info = ILField_Owner(field);
- ILDumpClassName(outstream, image, info, flags);
- fputs("::", outstream);
- ILDumpIdentifier(outstream,
ILField_Name(field), 0, flags);
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- case IL_META_TOKEN_METHOD_DEF:
- {
- /* A reference to a method */
- method = ILMethod_FromToken(image, token);
- if(method)
- {
- if(prefixWithKind)
- {
- fputs("method ", outstream);
- }
- ILDumpMethodType(outstream, image,
-
ILMethod_Signature(method), flags,
-
ILMethod_Owner(method),
-
ILMethod_Name(method),
- 0/*method*/);
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- case IL_META_TOKEN_MEMBER_REF:
- {
- /* A reference to an external method or field */
- member = ILMember_FromToken(image, token);
- origMember = member;
- member = (member ? ILMemberResolveRef(member) : 0);
- if(member)
- {
- if(ILMember_IsMethod(member))
- {
- /* Use the signature from the original
member,
- because this may be a "vararg" call
that has
- type information supplied in the
call site */
- if(prefixWithKind)
- {
- fputs("method ", outstream);
- }
- method = (ILMethod *)member;
- ILDumpMethodType(outstream, image,
-
ILMember_Signature(origMember), flags,
-
ILMethod_Owner(method),
-
ILMethod_Name(method),
-
0/*method*/);
- }
- else if(ILMember_IsField(member))
- {
- field = (ILField *)member;
- goto dumpField;
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- case IL_META_TOKEN_TYPE_SPEC:
- {
- /* A reference to a type specification */
- spec = ILTypeSpec_FromToken(image, token);
- if(spec)
- {
- ILDumpType(outstream, image,
ILTypeSpec_Type(spec), flags);
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- case IL_META_TOKEN_STAND_ALONE_SIG:
- {
- /* A reference to a stand-alone signature */
- sig = ILStandAloneSig_FromToken(image, token);
- if(sig)
- {
- type = ILStandAloneSig_Type(sig);
- if(ILType_IsMethod(type))
- {
- ILDumpMethodType(outstream, image,
type, flags, 0, "", 0);
- }
- else
- {
- ILDumpType(outstream, image, type,
flags);
- }
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- case IL_META_TOKEN_METHOD_SPEC:
- {
- /* A reference to a method with generic parameters */
- mspec = ILMethodSpec_FromToken(image, token);
- if(mspec)
- {
- if(prefixWithKind)
- {
- fputs("method ", outstream);
- }
- ILDumpMethodSpec(outstream, image, mspec,
flags);
- }
- else
- {
- fprintf(outstream, "#%lx", token);
- }
- }
- break;
-
- default:
- {
- fprintf(outstream, "#%lx", token);
- }
- break;
- }
-
- if((flags & IL_DUMP_SHOW_TOKENS) != 0)
- {
- fprintf(outstream, " /*%08lX*/", token);
- }
-}
-
-/*
- * Dump all IL instructions in a given buffer. Returns zero
- * if there is something wrong with the buffer's format.
- */
-static int DumpInstructions(ILImage *image, FILE *outstream,
- unsigned char *buf,
unsigned long size,
- unsigned long addr,
ILException *clauses,
- int flags)
-{
- ILUInt32 *jumpPoints;
- int result = 0;
- unsigned char *temp;
- unsigned long tsize;
- unsigned long offset;
- unsigned long dest;
- unsigned long isize;
- unsigned long args;
- const ILOpcodeInfo *info;
- int argType;
- unsigned long numItems;
- unsigned long item;
-
- /* Allocate a helper array to mark jump points within the code */
- jumpPoints = (ILUInt32 *)ILCalloc(((size + 3) & ~3), 1);
- if(!jumpPoints)
- {
- fprintf(stderr, "out of memory\n");
- exit(1);
- }
-
- /* Mark the entry point to the method so we get a label for it */
- jumpPoints[0] |= (ILUInt32)1;
-
- /* Mark the position of exception clauses */
- while(clauses != 0)
- {
- dest = clauses->tryOffset;
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
- }
- dest = clauses->tryOffset + clauses->tryLength;
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
- }
- dest = clauses->handlerOffset;
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
- }
- dest = clauses->handlerOffset + clauses->handlerLength;
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest % 32));
- }
- if((clauses->flags & IL_META_EXCEPTION_FILTER) != 0)
- {
- dest = clauses->extraArg;
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L << (dest
% 32));
- }
- }
- clauses = clauses->next;
- }
-
- /* Scan the instruction list to locate jump points */
- temp = buf;
- tsize = size;
- offset = 0;
- while(tsize > 0)
- {
- if(*temp == (unsigned char)0xFE)
- {
- /* Prefixed instruction */
- if(tsize < 2)
- {
- break;
- }
- info = &(ILPrefixOpcodeTable[((int)(temp[1])) & 0xFF]);
- if(!strncmp(info->name, "unused_", 7))
- {
- break;
- }
- if(!(info->size))
- {
- isize = GetSpecialSize(temp, tsize);
- }
- else
- {
- isize = info->size;
- }
- if(tsize < isize)
- {
- break;
- }
- }
- else
- {
- /* Regular instruction */
- info = &(ILMainOpcodeTable[((int)(*temp)) & 0xFF]);
- if(!strncmp(info->name, "unused_", 7))
- {
- break;
- }
- if(!(info->size))
- {
- isize = GetSpecialSize(temp, tsize);
- }
- else
- {
- isize = info->size;
- }
- if(tsize < isize)
- {
- break;
- }
- if(info->args == IL_OPCODE_ARGS_SHORT_JUMP)
- {
- dest = (unsigned long)(((long)offset) + 2 +
-
(long)(ILInt8)(temp[1]));
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L
<< (dest % 32));
- }
- }
- else if(info->args == IL_OPCODE_ARGS_LONG_JUMP)
- {
- dest = (unsigned long)(((long)offset) + 5 +
-
(long)(IL_READ_UINT32(temp + 1)));
- if(dest < size)
- {
- jumpPoints[dest / 32] |= (ILUInt32)(1L
<< (dest % 32));
- }
- }
- else if(info->args == IL_OPCODE_ARGS_SWITCH)
- {
- numItems = (unsigned long)(IL_READ_UINT32(temp
+ 1));
- for(item = 0; item < numItems; ++item)
- {
- dest = (unsigned
long)(IL_READ_UINT32(temp + 5 + item * 4));
- dest = (unsigned long)(((long)offset) +
5 +
-
((long)numItems) * 4 +
-
((long)dest));
- if(dest < size)
- {
- jumpPoints[dest / 32] |=
(ILUInt32)(1L << (dest % 32));
- }
- }
- }
- }
- offset += isize;
- temp += isize;
- tsize -= isize;
- }
-
- /* Dump the instructions */
- temp = buf;
- tsize = size;
- offset = 0;
- while(tsize > 0)
- {
- /* If this is a jump point, then print a label for it */
- if((jumpPoints[offset / 32] & (ILUInt32)(1L << (offset % 32)))
!= 0)
- {
- fprintf(outstream, "\t?L%lx:\n", offset + addr);
- }
-
- /* Extract the instruction from the method input stream */
- if(*temp == (unsigned char)0xFE)
- {
- /* Prefixed instruction */
- if(tsize < 2)
- {
- goto truncated;
- }
- info = &(ILPrefixOpcodeTable[((int)(temp[1])) & 0xFF]);
- if(!strncmp(info->name, "unused_", 7))
- {
- fprintf(outstream, "\t\t// unknown instruction
0xFE 0x%02X\n",
- ((int)(temp[1])) & 0xFF);
- goto cleanup;
- }
- if(!(info->size))
- {
- isize = GetSpecialSize(temp, tsize);
- }
- else
- {
- isize = info->size;
- }
- if(tsize < isize)
- {
- goto truncated;
- }
- args = 2;
- }
- else
- {
- /* Regular instruction */
- info = &(ILMainOpcodeTable[((int)(*temp)) & 0xFF]);
- if(!strncmp(info->name, "unused_", 7))
- {
- fprintf(outstream, "\t\t// unknown instruction
0x%02X\n",
- ((int)(*temp)) & 0xFF);
- goto cleanup;
- }
- if(!(info->size))
- {
- isize = GetSpecialSize(temp, tsize);
- }
- else
- {
- isize = info->size;
- }
- if(tsize < isize)
- {
- goto truncated;
- }
- args = 1;
- }
-
- /* Dump the instruction based on its argument type */
- argType = info->args;
- putc('\t', outstream);
- putc('\t', outstream);
- if((flags & ILDASM_INSTRUCTION_BYTES) != 0)
- {
- /* Dump the bytes of the instruction */
- int posn;
- putc('/', outstream);
- putc('*', outstream);
- putc(' ', outstream);
- posn = 0;
- while(posn < 6 && posn < isize)
- {
- fprintf(outstream, "%02X ", ((int)(temp[posn])
& 0xFF));
- ++posn;
- }
- while(posn < 6)
- {
- fputs(" ", outstream);
- ++posn;
- }
- putc(' ', outstream);
- putc('*', outstream);
- putc('/', outstream);
- putc(' ', outstream);
- }
- fputs(info->name, outstream);
- if(argType != IL_OPCODE_ARGS_INVALID &&
- argType != IL_OPCODE_ARGS_NONE)
- {
- numItems = (unsigned long)(strlen(info->name));
- while(numItems < 10)
- {
- putc(' ', outstream);
- ++numItems;
- }
- putc(' ', outstream);
- }
- switch(argType)
- {
- case IL_OPCODE_ARGS_INVALID: break;
- case IL_OPCODE_ARGS_NONE: break;
-
- case IL_OPCODE_ARGS_INT8:
- {
- fprintf(outstream, "%d",
(int)(ILInt8)(temp[args]));
- }
- break;
-
- case IL_OPCODE_ARGS_UINT8:
- {
- fprintf(outstream, "%d", ((int)(temp[args])) &
0xFF);
- }
- break;
-
- case IL_OPCODE_ARGS_INT16:
- {
- fprintf(outstream, "%d",
- (int)(ILInt16)(IL_READ_UINT16(temp +
args)));
- }
- break;
-
- case IL_OPCODE_ARGS_UINT16:
- {
- fprintf(outstream, "%lu",
- (unsigned long)(IL_READ_UINT16(temp +
args)));
- }
- break;
-
- case IL_OPCODE_ARGS_INT32:
- {
- fprintf(outstream, "%ld",
- (long)(ILInt32)(IL_READ_UINT32(temp +
args)));
- }
- break;
-
- case IL_OPCODE_ARGS_INT64:
- {
- fprintf(outstream, "0x%08lx%08lX",
- (unsigned long)(IL_READ_UINT32(temp +
args + 4)),
- (unsigned
long)(IL_READ_UINT32(temp + args)));
- }
- break;
-
- case IL_OPCODE_ARGS_FLOAT32:
- {
- fprintf(outstream,
"float32(0x%02X%02X%02X%02X)",
- (((int)(temp[args + 3])) &
0xFF),
- (((int)(temp[args + 2])) &
0xFF),
- (((int)(temp[args + 1])) &
0xFF),
- (((int)(temp[args + 0])) &
0xFF));
- }
- break;
-
- case IL_OPCODE_ARGS_FLOAT64:
- {
- fprintf(outstream,
-
"float64(0x%02X%02X%02X%02X%02X%02X%02X%02X)",
- (((int)(temp[args + 7])) &
0xFF),
- (((int)(temp[args + 6])) &
0xFF),
- (((int)(temp[args + 5])) &
0xFF),
- (((int)(temp[args + 4])) &
0xFF),
- (((int)(temp[args + 3])) &
0xFF),
- (((int)(temp[args + 2])) &
0xFF),
- (((int)(temp[args + 1])) &
0xFF),
- (((int)(temp[args + 0])) &
0xFF));
- }
- break;
-
- case IL_OPCODE_ARGS_TOKEN:
- case IL_OPCODE_ARGS_NEW:
- {
- DumpToken(image, outstream, flags,
- (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
- }
- break;
-
- case IL_OPCODE_ARGS_LDTOKEN:
- {
- DumpToken(image, outstream, flags,
- (unsigned
long)(IL_READ_UINT32(temp + args)), 1);
- }
- break;
-
- case IL_OPCODE_ARGS_SHORT_VAR:
- case IL_OPCODE_ARGS_SHORT_ARG:
- {
- fprintf(outstream, "%d", ((int)(temp[args])) &
0xFF);
- }
- break;
-
- case IL_OPCODE_ARGS_LONG_VAR:
- case IL_OPCODE_ARGS_LONG_ARG:
- case IL_OPCODE_ARGS_ANN_DEAD:
- case IL_OPCODE_ARGS_ANN_LIVE:
- case IL_OPCODE_ARGS_ANN_ARG:
- {
- fprintf(outstream, "%lu",
- (unsigned
long)(IL_READ_UINT16(temp + args)));
- }
- break;
-
- case IL_OPCODE_ARGS_SHORT_JUMP:
- {
- dest = (unsigned long)(((long)offset) + 2 +
-
(long)(ILInt8)(temp[1]));
- fprintf(outstream, "?L%lx", dest + addr);
- }
- break;
-
- case IL_OPCODE_ARGS_LONG_JUMP:
- {
- dest = (unsigned long)(((long)offset) + 5 +
-
(long)(IL_READ_UINT32(temp + 1)));
- fprintf(outstream, "?L%lx", dest + addr);
- }
- break;
-
- case IL_OPCODE_ARGS_CALL:
- {
- DumpToken(image, outstream, flags,
- (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
- }
- break;
-
- case IL_OPCODE_ARGS_CALLI:
- {
- DumpToken(image, outstream, flags,
- (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
- }
- break;
-
- case IL_OPCODE_ARGS_CALLVIRT:
- {
- DumpToken(image, outstream, flags,
- (unsigned
long)(IL_READ_UINT32(temp + args)), 0);
- }
- break;
-
- case IL_OPCODE_ARGS_SWITCH:
- {
- putc('(', outstream);
- numItems = (unsigned long)(IL_READ_UINT32(temp
+ args));
- for(item = 0; item < numItems; ++item)
- {
- dest = (unsigned long)(((long)offset) +
5 +
- ((long)numItems) * 4
+
-
(long)(IL_READ_UINT32(temp + args + 4 +
-
item * 4)));
- if(item != 0)
- {
- putc(',', outstream);
- putc(' ', outstream);
- }
- fprintf(outstream, "?L%lx", dest +
addr);
- }
- putc(')', outstream);
- }
- break;
-
- case IL_OPCODE_ARGS_STRING:
- {
- dest = (unsigned long)(IL_READ_UINT32(temp + args));
- if((dest & IL_META_TOKEN_MASK) ==
IL_META_TOKEN_STRING)
- {
- const char *str;
- unsigned long strLen;
- dest &= ~IL_META_TOKEN_MASK;
- str = ILImageGetUserString(image, dest,
&strLen);
- if(str)
- {
- ILDumpUnicodeString(outstream,
str, strLen);
- }
- else
- {
- fprintf(outstream, "#%lx",
- (unsigned
long)(IL_READ_UINT32(temp + args)));
- }
- }
- else
- {
- fprintf(outstream, "#%lx",
- (unsigned
long)(IL_READ_UINT32(temp + args)));
- }
- }
- break;
-
- case IL_OPCODE_ARGS_ANN_DATA:
- {
- if(temp[0] == (unsigned char)IL_OP_ANN_DATA_S)
- {
- numItems = (((unsigned
long)(temp[args])) & 0xFF);
- ++args;
- }
- else
- {
- numItems = (unsigned
long)(IL_READ_UINT32(temp + args));
- args += 4;
- }
- putc('(', outstream);
- for(item = 0; item < numItems; ++item)
- {
- if(item != 0)
- {
- putc(' ', outstream);
- }
- fprintf(outstream, "%02X",
- (((int)(temp[args +
item])) & 0xFF));
- }
- putc(')', outstream);
- }
- break;
-
- case IL_OPCODE_ARGS_ANN_REF:
- {
- if(temp[0] == (unsigned char)IL_OP_ANN_REF_S)
- {
- fprintf(outstream, "%d",
- (((int)(temp[args])) &
0xFF));
- }
- else
- {
- fprintf(outstream, "%lu",
- (unsigned
long)(IL_READ_UINT16(temp + args)));
- }
- }
- break;
-
- case IL_OPCODE_ARGS_ANN_PHI:
- {
- numItems =
- (((unsigned long)(IL_READ_UINT16(temp +
args))) & 0xFF);
- ++args;
- fprintf(outstream, "%lu", numItems);
- for(item = 0; item < numItems; ++item)
- {
- fprintf(outstream, " %lu",
- (unsigned
long)(IL_READ_UINT16(temp + args +
-
item * 2)));
- }
- }
- break;
-
- default: break;
- }
- putc('\n', outstream);
-
- /* Move on to the next instruction */
- offset += isize;
- temp += isize;
- tsize -= isize;
- }
- result = 1;
-
- /* Clean up and exit */
-cleanup:
- ILFree(jumpPoints);
- return result;
-truncated:
- fprintf(outstream, "\t\t// truncated instruction\n");
- goto cleanup;
-}
-
-/*
- * Dump the local variables associated with a method.
- */
-static void DumpLocals(ILImage *image, FILE *outstream,
- ILStandAloneSig *sig, int flags)
-{
- ILType *locals;
- ILType *type;
- unsigned long num;
- unsigned long index;
-
- /* Dump the locals */
- locals = ILStandAloneSigGetType(sig);
- num = ILTypeNumLocals(locals);
- for(index = 0; index < num; ++index)
- {
- if(index != 0)
- {
- fputs(",\n\t\t ", outstream);
- }
- type = ILTypeGetLocalWithPrefixes(locals, index);
- ILDumpType(outstream, image, type, flags);
- }
-}
-
-/*
- * Dump the custom attributes on the parameters.
- */
-static void DumpParameterAttributes(ILImage *image, FILE *outstream,
-
ILMethod *method, int flags)
-{
- ILParameter *param = 0;
- ILAttribute *attr;
- while((param = ILMethodNextParam(method, param)) != 0)
- {
- attr = ILProgramItemNextAttribute(ILToProgramItem(param), 0);
- if(attr || ILConstantGetFromOwner(ILToProgramItem(param)) != 0)
- {
- fprintf(outstream, "\t\t.param [%ld]",
- (long)(ILParameter_Num(param)));
- ILDumpConstant(outstream, ILToProgramItem(param), 0);
- putc('\n', outstream);
- ILDAsmDumpCustomAttrs(image, outstream, flags, 2,
-
ILToProgramItem(param));
- }
- }
-}
-
-void ILDAsmDumpMethod(ILImage *image, FILE *outstream,
- ILMethod *method, int flags,
- int isEntryPoint)
-{
- unsigned long addr;
- ILMethodCode code;
- ILException *clauses;
- ILException *tempClause;
-
- /* Read the method code and exception information */
- if(!ILMethodGetCode(method, &code))
- {
- /* If we get here, then probably the method had an RVA,
- but the code was not IL */
- fputs("\t\t// Cannot dump the code for native methods\n",
outstream);
- return;
- }
- if(!ILMethodGetExceptions(method, &code, &clauses))
- {
- return;
- }
-
- /* Determine the address of the first instruction in the method */
- addr = ILMethod_RVA(method);
- if((flags & ILDASM_REAL_OFFSETS) != 0)
- {
- addr = ILImageRealOffset(image, addr) + code.headerSize;
- }
- else
- {
- addr += code.headerSize;
- }
-
- /* Output method header information */
- fprintf(outstream, "\t\t// Start of method header: %lx\n",
- (unsigned long)(addr - code.headerSize));
- DumpParameterAttributes(image, outstream, method, flags);
- if(isEntryPoint)
- {
- fputs("\t\t.entrypoint\n", outstream);
- }
- fprintf(outstream, "\t\t.maxstack %lu\n", (unsigned
long)(code.maxStack));
- if(code.localVarSig)
- {
- fprintf(outstream, "\t\t.locals %s(",
- (code.initLocals ? "init " : ""));
- DumpLocals(image, outstream, code.localVarSig, flags);
- fputs(")\n", outstream);
- }
-
- /* Dump the instructions within the method */
- if(!DumpInstructions(image, outstream, (unsigned char *)(code.code),
- code.codeLen, addr, clauses,
flags))
- {
- ILMethodFreeExceptions(clauses);
- return;
- }
-
- /* Dump information about the exceptions */
- tempClause = clauses;
- while(tempClause != 0)
- {
- fprintf(outstream, "\t\t.try ?L%lx to ?L%lx",
- tempClause->tryOffset + addr,
- tempClause->tryOffset + tempClause->tryLength +
addr);
- if((tempClause->flags & IL_META_EXCEPTION_FILTER) != 0)
- {
- /* Filter clause */
- fprintf(outstream, " filter ?L%lx",
tempClause->extraArg + addr);
- }
- else if((tempClause->flags & IL_META_EXCEPTION_FINALLY) != 0)
- {
- /* Finally clause */
- fprintf(outstream, " finally");
- }
- else if((tempClause->flags & IL_META_EXCEPTION_FAULT) != 0)
- {
- /* Fault clause */
- fprintf(outstream, " fault");
- }
- else
- {
- /* Catch clause */
- fputs(" catch ", outstream);
- DumpToken(image, outstream, flags |
ILDASM_SUPPRESS_PREFIX,
- tempClause->extraArg, 0);
- }
- fprintf(outstream, " handler ?L%lx to ?L%lx\n",
- tempClause->handlerOffset + addr,
- tempClause->handlerOffset +
tempClause->handlerLength + addr);
- tempClause = tempClause->next;
- }
-
- /* Free the exception list and exit */
- ILMethodFreeExceptions(clauses);
-}
-
-#ifdef __cplusplus
-};
-#endif
Index: ildasm/ildasm_utils.c
===================================================================
RCS file: ildasm/ildasm_utils.c
diff -N ildasm/ildasm_utils.c
--- ildasm/ildasm_utils.c 10 Nov 2001 05:53:42 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,191 +0,0 @@
-/*
- * ildasm_utils.c - Utilities used by the disassembler.
- *
- * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ildasm_internal.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void ILDAsmDumpBinaryBlob(FILE *outstream, ILImage *image,
- const void *blob, ILUInt32
blobLen)
-{
- unsigned char *ptr = (unsigned char *)blob;
- ILUInt32 offset;
- if(blobLen > 16)
- {
- /* Dump the blob on a separate line */
- fputs("\n\t\t(", outstream);
- while(blobLen > 16)
- {
- for(offset = 0; offset < 16; ++offset)
- {
- if(offset)
- {
- putc(' ', outstream);
- }
- fprintf(outstream, "%02X", ptr[offset]);
- }
- fputs(" // ", outstream);
- for(offset = 0; offset < 16; ++offset)
- {
- if(ptr[offset] >= (unsigned char)' ' &&
- ptr[offset] <= (unsigned char)0x7E)
- {
- putc((int)(ptr[offset]), outstream);
- }
- else
- {
- putc('.', outstream);
- }
- }
- fputs("\n\t\t ", outstream);
- ptr += 16;
- blobLen -= 16;
- }
- for(offset = 0; offset < blobLen; ++offset)
- {
- if(offset)
- {
- putc(' ', outstream);
- }
- fprintf(outstream, "%02X", ptr[offset]);
- }
- fputs(") // ", outstream);
- for(offset = 0; offset < blobLen; ++offset)
- {
- if(ptr[offset] >= (unsigned char)' ' &&
- ptr[offset] <= (unsigned char)0x7E)
- {
- putc((int)(ptr[offset]), outstream);
- }
- else
- {
- putc('.', outstream);
- }
- }
- }
- else
- {
- /* Dump the blob on the same line */
- fputs(" (", outstream);
- for(offset = 0; offset < blobLen; ++offset)
- {
- if(offset)
- {
- putc(' ', outstream);
- }
- fprintf(outstream, "%02X", ptr[offset]);
- }
- fputs(") // ", outstream);
- for(offset = 0; offset < blobLen; ++offset)
- {
- if(ptr[offset] >= (unsigned char)' ' &&
- ptr[offset] <= (unsigned char)0x7E)
- {
- putc((int)(ptr[offset]), outstream);
- }
- else
- {
- putc('.', outstream);
- }
- }
- }
-}
-
-void ILDAsmWalkTokens(ILImage *image, FILE *outstream, int flags,
- unsigned long tokenKind,
ILDAsmWalkFunc callback,
- unsigned long refToken)
-{
- unsigned long numTokens;
- unsigned long token;
- void *data;
- numTokens = ILImageNumTokens(image, tokenKind);
- for(token = 1; token <= numTokens; ++token)
- {
- data = ILImageTokenInfo(image, tokenKind | token);
- (*callback)(image, outstream, flags, tokenKind | token, data,
refToken);
- }
-}
-
-void ILDAsmDumpSecurity(ILImage *image, FILE *outstream,
- ILProgramItem *item, int flags)
-{
- ILDeclSecurity *security;
- const void *blob;
- unsigned long blobLen;
- ILUInt16 ch;
-
- /* Get the security information, if any */
- security = ILDeclSecurityGetFromOwner(item);
- if(!security)
- {
- return;
- }
-
- /* Dump the security header */
- fputs("\t.capability ", outstream);
-
- /* Dump the type of security blob */
- ILDumpFlags(outstream, ILDeclSecurity_Type(security), ILSecurityFlags,
0);
-
- /* Dump the blob */
- blob = ILDeclSecurityGetBlob(security, &blobLen);
- if(blob)
- {
- putc('=', outstream);
- ILDAsmDumpBinaryBlob(outstream, image, blob, blobLen);
- }
-
- /* Terminate the line */
- putc('\n', outstream);
-
- /* Dump the text version of the XML within the security blob */
- if(blob)
- {
- fputs("\t// ", outstream);
- while(blobLen >= 2)
- {
- ch = IL_READ_UINT16(blob);
- if(ch == '\n')
- {
- if(blobLen >= 4)
- {
- fputs("\n\t// ", outstream);
- }
- }
- else if(ch >= ' ' && ch <= 0x7E)
- {
- putc((int)ch, outstream);
- }
- else if(ch != '\r')
- {
- fprintf(outstream, "&#x%04lX;", (unsigned
long)ch);
- }
- blob = (const void *)(((const char *)blob) + 2);
- blobLen -= 2;
- }
- putc('\n', outstream);
- }
-}
-
-#ifdef __cplusplus
-};
-#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] pnet ChangeLog dumpasm/Makefile.am engine/debug...,
Radek Polak <=