[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/engine int_proto.h, 1.77, 1.78 int_table
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/engine int_proto.h, 1.77, 1.78 int_table.c, 1.80, 1.81 lib_reflect.c, 1.48, 1.49 |
Date: |
Wed, 20 Aug 2003 07:02:15 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv32037/engine
Modified Files:
int_proto.h int_table.c lib_reflect.c
Log Message:
New internalcalls to support "Assembly" and "AssemblyName".
Index: int_proto.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/int_proto.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -r1.77 -r1.78
*** int_proto.h 19 Aug 2003 05:56:59 -0000 1.77
--- int_proto.h 20 Aug 2003 11:02:12 -0000 1.78
***************
*** 9,16 ****
extern ILString * _IL_Enum_FormatEnumWithFlags(ILExecThread * _thread,
ILObject * _p1, ILObject * _p2);
extern ILString * _IL_Enum_GetEnumName(ILExecThread * _thread, ILObject *
_p1, ILObject * _p2);
extern ILObject * _IL_Enum_GetEnumValueFromName(ILExecThread * _thread,
ILObject * _p1, ILString * _p2, ILBool _p3);
extern ILBool _IL_Enum_IsEnumValue(ILExecThread * _thread, ILObject * _p1,
ILObject * _p2);
extern ILObject * _IL_Enum_EnumValueOr(ILExecThread * _thread, ILObject *
_p1, ILObject * _p2);
- extern ILObject * _IL_Enum_EnumIntToObject(ILExecThread * _thread, ILObject *
_p1, ILInt32 _p2);
extern ILObject * _IL_Enum_EnumLongToObject(ILExecThread * _thread, ILObject
* _p1, ILInt64 _p2);
--- 9,16 ----
extern ILString * _IL_Enum_FormatEnumWithFlags(ILExecThread * _thread,
ILObject * _p1, ILObject * _p2);
extern ILString * _IL_Enum_GetEnumName(ILExecThread * _thread, ILObject *
_p1, ILObject * _p2);
+ extern ILObject * _IL_Enum_EnumIntToObject(ILExecThread * _thread, ILObject *
_p1, ILInt32 _p2);
extern ILObject * _IL_Enum_GetEnumValueFromName(ILExecThread * _thread,
ILObject * _p1, ILString * _p2, ILBool _p3);
extern ILBool _IL_Enum_IsEnumValue(ILExecThread * _thread, ILObject * _p1,
ILObject * _p2);
extern ILObject * _IL_Enum_EnumValueOr(ILExecThread * _thread, ILObject *
_p1, ILObject * _p2);
extern ILObject * _IL_Enum_EnumLongToObject(ILExecThread * _thread, ILObject
* _p1, ILInt64 _p2);
***************
*** 253,257 ****
extern void _IL_Marshal_FreeHGlobal(ILExecThread * _thread, ILNativeInt _p1);
extern ILNativeInt _IL_Marshal_AllocHGlobal(ILExecThread * _thread,
ILNativeInt _p1);
- extern ILString * _IL_Marshal_PtrToStringUniInternal(ILExecThread * _thread,
ILNativeInt _p1, ILInt32 _p2);
extern ILString * _IL_Marshal_PtrToStringAnsiInternal(ILExecThread * _thread,
ILNativeInt _p1, ILInt32 _p2);
extern void _IL_Marshal_CopyMU(ILExecThread * _thread, ILObject * _p1,
ILInt32 _p2, ILNativeInt _p3, ILInt32 _p4);
--- 253,256 ----
***************
*** 259,262 ****
--- 258,262 ----
extern ILNativeInt _IL_Marshal_OffsetOfInternal(ILExecThread * _thread,
ILObject * _p1, ILString * _p2);
extern ILString * _IL_Marshal_PtrToStringAutoInternal(ILExecThread * _thread,
ILNativeInt _p1, ILInt32 _p2);
+ extern ILString * _IL_Marshal_PtrToStringUniInternal(ILExecThread * _thread,
ILNativeInt _p1, ILInt32 _p2);
extern ILBool _IL_Marshal_PtrToStructureInternal(ILExecThread * _thread,
ILNativeInt _p1, ILObject * _p2, ILBool _p3);
extern ILBool _IL_Marshal_DestroyStructureInternal(ILExecThread * _thread,
ILNativeInt _p1, ILObject * _p2);
***************
*** 294,297 ****
--- 294,298 ----
extern ILString * _IL_Assembly_GetSatellitePath(ILExecThread * _thread,
ILObject * _this, ILString * _p1);
extern ILObject * _IL_Assembly_LoadFromFile(ILExecThread * _thread, ILString
* _p1, ILInt32 * error, ILObject * _p3);
+ extern ILString * _IL_Assembly_GetFullName(ILExecThread * _thread, ILObject *
_this);
extern ILObject * _IL_Assembly_GetEntryAssembly(ILExecThread * _thread);
extern System_Array * _IL_Assembly_GetExportedTypes(ILExecThread * _thread,
ILObject * _this);
***************
*** 302,308 ****
extern System_Array * _IL_Assembly_GetTypes(ILExecThread * _thread, ILObject
* _this);
extern ILObject * _IL_Assembly_LoadFromName(ILExecThread * _thread, ILString
* _p1, ILInt32 * error, ILObject * _p3);
extern void _IL_Assembly_GetEntryPoint(ILExecThread * _thread, void *
_result, ILObject * _this);
extern ILString * _IL_Assembly_GetImageRuntimeVersion(ILExecThread * _thread,
ILObject * _this);
- extern ILString * _IL_Assembly_GetLocation(ILExecThread * _thread, ILObject *
_this);
extern ILObject * _IL_MethodBase_GetMethodFromHandle(ILExecThread * _thread,
void * _p1);
--- 303,310 ----
extern System_Array * _IL_Assembly_GetTypes(ILExecThread * _thread, ILObject
* _this);
extern ILObject * _IL_Assembly_LoadFromName(ILExecThread * _thread, ILString
* _p1, ILInt32 * error, ILObject * _p3);
+ extern ILString * _IL_Assembly_GetLocation(ILExecThread * _thread, ILObject *
_this);
+ extern void _IL_Assembly_FillAssemblyName(ILExecThread * _thread, ILObject *
_this, ILObject * _p1);
extern void _IL_Assembly_GetEntryPoint(ILExecThread * _thread, void *
_result, ILObject * _this);
extern ILString * _IL_Assembly_GetImageRuntimeVersion(ILExecThread * _thread,
ILObject * _this);
extern ILObject * _IL_MethodBase_GetMethodFromHandle(ILExecThread * _thread,
void * _p1);
***************
*** 341,344 ****
--- 343,348 ----
extern ILObject * _IL_ClrType_BindGenericParameters(ILExecThread * _thread,
ILObject * _this, System_Array * _p1);
extern ILObject * _IL_ClrType_GetGenericTypeDefinition(ILExecThread *
_thread, ILObject * _this);
+
+ extern ILInt32 _IL_AssemblyName_FillAssemblyNameFromFile(ILExecThread *
_thread, ILObject * _p1, ILString * _p2, ILObject * _p3);
extern ILObject * _IL_ClrConstructor_Invoke(ILExecThread * _thread, ILObject
* _this, ILInt32 _p1, ILObject * _p2, System_Array * _p3, ILObject * _p4);
Index: int_table.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/int_table.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -C2 -r1.80 -r1.81
*** int_table.c 19 Aug 2003 05:56:59 -0000 1.80
--- int_table.c 20 Aug 2003 11:02:13 -0000 1.81
***************
*** 50,56 ****
#if !defined(HAVE_LIBFFI)
! static void marshal_ppppb(void (*fn)(), void *rvalue, void **avalue)
{
! *((void * *)rvalue) = (*(void * (*)(void *, void *, void *,
ILInt8))fn)(*((void * *)(avalue[0])), *((void * *)(avalue[1])), *((void *
*)(avalue[2])), *((ILInt8 *)(avalue[3])));
}
--- 50,56 ----
#if !defined(HAVE_LIBFFI)
! static void marshal_pppi(void (*fn)(), void *rvalue, void **avalue)
{
! *((void * *)rvalue) = (*(void * (*)(void *, void *,
ILInt32))fn)(*((void * *)(avalue[0])), *((void * *)(avalue[1])), *((ILInt32
*)(avalue[2])));
}
***************
*** 59,65 ****
#if !defined(HAVE_LIBFFI)
! static void marshal_pppi(void (*fn)(), void *rvalue, void **avalue)
{
! *((void * *)rvalue) = (*(void * (*)(void *, void *,
ILInt32))fn)(*((void * *)(avalue[0])), *((void * *)(avalue[1])), *((ILInt32
*)(avalue[2])));
}
--- 59,65 ----
#if !defined(HAVE_LIBFFI)
! static void marshal_ppppb(void (*fn)(), void *rvalue, void **avalue)
{
! *((void * *)rvalue) = (*(void * (*)(void *, void *, void *,
ILInt8))fn)(*((void * *)(avalue[0])), *((void * *)(avalue[1])), *((void *
*)(avalue[2])), *((ILInt8 *)(avalue[3])));
}
***************
*** 81,88 ****
IL_METHOD("FormatEnumWithFlags",
"(oSystem.Type;oSystem.Object;)oSystem.String;", _IL_Enum_FormatEnumWithFlags,
marshal_pppp)
IL_METHOD("GetEnumName",
"(oSystem.Type;oSystem.Object;)oSystem.String;", _IL_Enum_GetEnumName,
marshal_pppp)
IL_METHOD("GetEnumValueFromName",
"(oSystem.Type;oSystem.String;Z)oSystem.Object;",
_IL_Enum_GetEnumValueFromName, marshal_ppppb)
IL_METHOD("IsEnumValue", "(oSystem.Type;oSystem.Object;)Z",
_IL_Enum_IsEnumValue, marshal_bppp)
IL_METHOD("EnumValueOr",
"(oSystem.Object;oSystem.Object;)oSystem.Object;", _IL_Enum_EnumValueOr,
marshal_pppp)
- IL_METHOD("EnumIntToObject", "(oSystem.Type;i)oSystem.Object;",
_IL_Enum_EnumIntToObject, marshal_pppi)
IL_METHOD("EnumLongToObject", "(oSystem.Type;l)oSystem.Object;",
_IL_Enum_EnumLongToObject, marshal_pppl)
IL_METHOD_END
--- 81,88 ----
IL_METHOD("FormatEnumWithFlags",
"(oSystem.Type;oSystem.Object;)oSystem.String;", _IL_Enum_FormatEnumWithFlags,
marshal_pppp)
IL_METHOD("GetEnumName",
"(oSystem.Type;oSystem.Object;)oSystem.String;", _IL_Enum_GetEnumName,
marshal_pppp)
+ IL_METHOD("EnumIntToObject", "(oSystem.Type;i)oSystem.Object;",
_IL_Enum_EnumIntToObject, marshal_pppi)
IL_METHOD("GetEnumValueFromName",
"(oSystem.Type;oSystem.String;Z)oSystem.Object;",
_IL_Enum_GetEnumValueFromName, marshal_ppppb)
IL_METHOD("IsEnumValue", "(oSystem.Type;oSystem.Object;)Z",
_IL_Enum_IsEnumValue, marshal_bppp)
IL_METHOD("EnumValueOr",
"(oSystem.Object;oSystem.Object;)oSystem.Object;", _IL_Enum_EnumValueOr,
marshal_pppp)
IL_METHOD("EnumLongToObject", "(oSystem.Type;l)oSystem.Object;",
_IL_Enum_EnumLongToObject, marshal_pppl)
IL_METHOD_END
***************
*** 1495,1499 ****
IL_METHOD("FreeHGlobal", "(j)V", _IL_Marshal_FreeHGlobal, marshal_vpj)
IL_METHOD("AllocHGlobal", "(j)j", _IL_Marshal_AllocHGlobal, marshal_jpj)
- IL_METHOD("PtrToStringUniInternal", "(ji)oSystem.String;",
_IL_Marshal_PtrToStringUniInternal, marshal_ppji)
IL_METHOD("PtrToStringAnsiInternal", "(ji)oSystem.String;",
_IL_Marshal_PtrToStringAnsiInternal, marshal_ppji)
IL_METHOD("CopyMU", "(oSystem.Array;iji)V", _IL_Marshal_CopyMU,
marshal_vppiji)
--- 1495,1498 ----
***************
*** 1501,1504 ****
--- 1500,1504 ----
IL_METHOD("OffsetOfInternal", "(oSystem.Type;oSystem.String;)j",
_IL_Marshal_OffsetOfInternal, marshal_jppp)
IL_METHOD("PtrToStringAutoInternal", "(ji)oSystem.String;",
_IL_Marshal_PtrToStringAutoInternal, marshal_ppji)
+ IL_METHOD("PtrToStringUniInternal", "(ji)oSystem.String;",
_IL_Marshal_PtrToStringUniInternal, marshal_ppji)
IL_METHOD("PtrToStructureInternal", "(joSystem.Object;Z)Z",
_IL_Marshal_PtrToStructureInternal, marshal_bpjpb)
IL_METHOD("DestroyStructureInternal", "(joSystem.Type;)Z",
_IL_Marshal_DestroyStructureInternal, marshal_bpjp)
***************
*** 1566,1569 ****
--- 1566,1570 ----
IL_METHOD("GetSatellitePath", "(ToSystem.String;)oSystem.String;",
_IL_Assembly_GetSatellitePath, marshal_pppp)
IL_METHOD("LoadFromFile",
"(oSystem.String;&ioSystem.Reflection.Assembly;)oSystem.Reflection.Assembly;",
_IL_Assembly_LoadFromFile, marshal_ppppp)
+ IL_METHOD("GetFullName", "(T)oSystem.String;",
_IL_Assembly_GetFullName, marshal_ppp)
IL_METHOD("GetEntryAssembly", "()oSystem.Reflection.Assembly;",
_IL_Assembly_GetEntryAssembly, marshal_pp)
IL_METHOD("GetExportedTypes", "(T)[oSystem.Type;",
_IL_Assembly_GetExportedTypes, marshal_ppp)
***************
*** 1574,1580 ****
IL_METHOD("GetTypes", "(T)[oSystem.Type;", _IL_Assembly_GetTypes,
marshal_ppp)
IL_METHOD("LoadFromName",
"(oSystem.String;&ioSystem.Reflection.Assembly;)oSystem.Reflection.Assembly;",
_IL_Assembly_LoadFromName, marshal_ppppp)
IL_METHOD("GetEntryPoint", "(T)vSystem.RuntimeMethodHandle;",
_IL_Assembly_GetEntryPoint, marshal_vppp)
IL_METHOD("GetImageRuntimeVersion", "(T)oSystem.String;",
_IL_Assembly_GetImageRuntimeVersion, marshal_ppp)
- IL_METHOD("GetLocation", "(T)oSystem.String;",
_IL_Assembly_GetLocation, marshal_ppp)
IL_METHOD_END
--- 1575,1582 ----
IL_METHOD("GetTypes", "(T)[oSystem.Type;", _IL_Assembly_GetTypes,
marshal_ppp)
IL_METHOD("LoadFromName",
"(oSystem.String;&ioSystem.Reflection.Assembly;)oSystem.Reflection.Assembly;",
_IL_Assembly_LoadFromName, marshal_ppppp)
+ IL_METHOD("GetLocation", "(T)oSystem.String;",
_IL_Assembly_GetLocation, marshal_ppp)
+ IL_METHOD("FillAssemblyName", "(ToSystem.Reflection.AssemblyName;)V",
_IL_Assembly_FillAssemblyName, marshal_vppp)
IL_METHOD("GetEntryPoint", "(T)vSystem.RuntimeMethodHandle;",
_IL_Assembly_GetEntryPoint, marshal_vppp)
IL_METHOD("GetImageRuntimeVersion", "(T)oSystem.String;",
_IL_Assembly_GetImageRuntimeVersion, marshal_ppp)
IL_METHOD_END
***************
*** 1661,1664 ****
--- 1663,1683 ----
#if !defined(HAVE_LIBFFI)
+ static void marshal_ipppp(void (*fn)(), void *rvalue, void **avalue)
+ {
+ *((ILNativeInt *)rvalue) = (*(ILInt32 (*)(void *, void *, void *, void
*))fn)(*((void * *)(avalue[0])), *((void * *)(avalue[1])), *((void *
*)(avalue[2])), *((void * *)(avalue[3])));
+ }
+
+ #endif
+
+ #ifndef _IL_AssemblyName_suppressed
+
+ IL_METHOD_BEGIN(AssemblyName_Methods)
+ IL_METHOD("FillAssemblyNameFromFile",
"(oSystem.Reflection.AssemblyName;oSystem.String;oSystem.Reflection.Assembly;)i",
_IL_AssemblyName_FillAssemblyNameFromFile, marshal_ipppp)
+ IL_METHOD_END
+
+ #endif
+
+ #if !defined(HAVE_LIBFFI)
+
static void marshal_pppippp(void (*fn)(), void *rvalue, void **avalue)
{
***************
*** 2831,2834 ****
--- 2850,2856 ----
#ifndef _IL_AssemblyBuilder_suppressed
{"AssemblyBuilder", "System.Reflection.Emit", AssemblyBuilder_Methods},
+ #endif
+ #ifndef _IL_AssemblyName_suppressed
+ {"AssemblyName", "System.Reflection", AssemblyName_Methods},
#endif
#ifndef _IL_BitConverter_suppressed
Index: lib_reflect.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_reflect.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -r1.48 -r1.49
*** lib_reflect.c 13 Aug 2003 21:43:03 -0000 1.48
--- lib_reflect.c 20 Aug 2003 11:02:13 -0000 1.49
***************
*** 2,6 ****
* lib_reflect.c - Internalcall methods for the reflection classes.
*
! * Copyright (C) 2001, 2002 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
--- 2,6 ----
* lib_reflect.c - Internalcall methods for the reflection classes.
*
! * Copyright (C) 2001, 2002, 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
***************
*** 22,25 ****
--- 22,26 ----
#include "lib_defs.h"
#include "il_serialize.h"
+ #include "il_crypt.h"
#ifdef __cplusplus
***************
*** 1455,1458 ****
--- 1456,1803 ----
*((void **)result) = 0;
}
+ }
+
+ /*
+ * Builtin public key values, to shortcut hashing for common assemblies.
+ */
+ static unsigned char const NeutralKey[] =
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ static unsigned char const NeutralKeyToken[] =
+ {0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89};
+ static char const MicrosoftKey[] =
+ {0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00,
+ 0x94, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00,
+ 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31,
+ 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
+ 0x07, 0xd1, 0xfa, 0x57, 0xc4, 0xae, 0xd9, 0xf0,
+ 0xa3, 0x2e, 0x84, 0xaa, 0x0f, 0xae, 0xfd, 0x0d,
+ 0xe9, 0xe8, 0xfd, 0x6a, 0xec, 0x8f, 0x87, 0xfb,
+ 0x03, 0x76, 0x6c, 0x83, 0x4c, 0x99, 0x92, 0x1e,
+ 0xb2, 0x3b, 0xe7, 0x9a, 0xd9, 0xd5, 0xdc, 0xc1,
+ 0xdd, 0x9a, 0xd2, 0x36, 0x13, 0x21, 0x02, 0x90,
+ 0x0b, 0x72, 0x3c, 0xf9, 0x80, 0x95, 0x7f, 0xc4,
+ 0xe1, 0x77, 0x10, 0x8f, 0xc6, 0x07, 0x77, 0x4f,
+ 0x29, 0xe8, 0x32, 0x0e, 0x92, 0xea, 0x05, 0xec,
+ 0xe4, 0xe8, 0x21, 0xc0, 0xa5, 0xef, 0xe8, 0xf1,
+ 0x64, 0x5c, 0x4c, 0x0c, 0x93, 0xc1, 0xab, 0x99,
+ 0x28, 0x5d, 0x62, 0x2c, 0xaa, 0x65, 0x2c, 0x1d,
+ 0xfa, 0xd6, 0x3d, 0x74, 0x5d, 0x6f, 0x2d, 0xe5,
+ 0xf1, 0x7e, 0x5e, 0xaf, 0x0f, 0xc4, 0x96, 0x3d,
+ 0x26, 0x1c, 0x8a, 0x12, 0x43, 0x65, 0x18, 0x20,
+ 0x6d, 0xc0, 0x93, 0x34, 0x4d, 0x5a, 0xd2, 0x93};
+ static unsigned char const MicrosoftKeyToken[] =
+ {0xb0, 0x3f, 0x5f, 0x7f, 0x11, 0xd5, 0x0a, 0x3a};
+
+ /*
+ * private String GetFullName();
+ */
+ ILString *_IL_Assembly_GetFullName(ILExecThread *thread, ILObject *_this)
+ {
+ ILProgramItem *item = (ILProgramItem *)_ILClrFromObject(thread, _this);
+ ILImage *image = ((item != 0) ? ILProgramItem_Image(item) : 0);
+ if(image)
+ {
+ ILAssembly *assem;
+ const char *name;
+ const ILUInt16 *version;
+ const char *locale;
+ const void *publicKey;
+ unsigned long publicKeyLen;
+ unsigned long publicKeyLenInChars;
+ char versbuf[64];
+ char *buf;
+ int posn;
+ ILString *str;
+ ILSHAContext sha;
+ unsigned char hash[IL_SHA_HASH_SIZE];
+
+ /* Collect up the assembly name components */
+ name = ILImageGetAssemblyName(image);
+ if(!name)
+ {
+ return 0;
+ }
+ assem = (ILAssembly *)ILImageTokenInfo
+ (image, IL_META_TOKEN_ASSEMBLY | 1);
+ version = ILAssemblyGetVersion(assem);
+ sprintf(versbuf, "%u.%u.%u.%u",
+ (unsigned)(version[0]), (unsigned)(version[1]),
+ (unsigned)(version[2]), (unsigned)(version[3]));
+ locale = ILAssembly_Locale(assem);
+ if(!locale)
+ {
+ locale = "neutral";
+ }
+ publicKeyLen = 0;
+ publicKey = ILAssemblyGetOriginator(assem, &publicKeyLen);
+ if(publicKey != 0 && publicKeyLen != 0)
+ {
+ publicKeyLenInChars = 16;
+ }
+ else
+ {
+ publicKeyLenInChars = 4; /* "null" */
+ }
+
+ /* Allocate a buffer big enough to hold the entire name */
+ buf = (char *)ILMalloc(strlen(name) + 10 /* ", Version=" */ +
+ strlen(versbuf) + 10
/* ", Culture=" */ +
+ strlen(locale) + 17
/* ", PublicKeyToken=" */ +
+ publicKeyLenInChars
+ 1);
+ if(!buf)
+ {
+ ILExecThreadThrowOutOfMemory(thread);
+ return 0;
+ }
+
+ /* Format the name */
+ sprintf(buf, "%s, Version=%s, Culture=%s, PublicKeyToken=",
+ name, versbuf, locale);
+ posn = strlen(buf);
+ if(publicKey != 0 && publicKeyLen != 0)
+ {
+ if(publicKeyLen == sizeof(NeutralKey) &&
+ !ILMemCmp(publicKey, NeutralKey, publicKeyLen))
+ {
+ sprintf(buf + posn,
"%02x%02x%02x%02x%02x%02x%02x%02x",
+ NeutralKeyToken[0],
NeutralKeyToken[1],
+ NeutralKeyToken[2],
NeutralKeyToken[3],
+ NeutralKeyToken[4],
NeutralKeyToken[5],
+ NeutralKeyToken[6],
NeutralKeyToken[7]);
+ }
+ else if(publicKeyLen == sizeof(MicrosoftKey) &&
+ !ILMemCmp(publicKey, MicrosoftKey,
publicKeyLen))
+ {
+ sprintf(buf + posn,
"%02x%02x%02x%02x%02x%02x%02x%02x",
+ MicrosoftKeyToken[0],
MicrosoftKeyToken[1],
+ MicrosoftKeyToken[2],
MicrosoftKeyToken[3],
+ MicrosoftKeyToken[4],
MicrosoftKeyToken[5],
+ MicrosoftKeyToken[6],
MicrosoftKeyToken[7]);
+ }
+ else
+ {
+ ILSHAInit(&sha);
+ ILSHAData(&sha, publicKey, publicKeyLen);
+ ILSHAFinalize(&sha, hash);
+ sprintf(buf + posn,
"%02x%02x%02x%02x%02x%02x%02x%02x",
+ hash[19], hash[18], hash[17],
hash[16],
+ hash[15], hash[14], hash[13],
hash[12]);
+ }
+ }
+ else
+ {
+ strcpy(buf + posn, "null");
+ }
+
+ /* Convert the buffer into a string object and return it */
+ str = ILStringCreateUTF8(thread, buf);
+ ILFree(buf);
+ return str;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ /*
+ * Call a method on the "AssemblyName" class.
+ */
+ static int CallAssemblyNameMethod(ILExecThread *thread, ILObject *nameInfo,
+ const char
*methodName,
+ const char
*signature, ILObject *param)
+ {
+ ILExecValue value;
+ value.objValue = param;
+ return ILExecThreadCallNamedVirtualV
+ (thread, "System.Reflection.AssemblyName",
+ methodName, signature, &value, nameInfo,
&value);
+ }
+ static int CallAssemblyNameMethodI4(ILExecThread *thread, ILObject *nameInfo,
+ const char
*methodName,
+ const char
*signature, ILInt32 param)
+ {
+ ILExecValue value;
+ value.int32Value = param;
+ return ILExecThreadCallNamedVirtualV
+ (thread, "System.Reflection.AssemblyName",
+ methodName, signature, &value, nameInfo,
&value);
+ }
+ static int CallAssemblyNameMethodV(ILExecThread *thread, ILObject *nameInfo,
+ const
ILUInt16 *param)
+ {
+ ILExecValue value[4];
+ value[0].int32Value = param[0];
+ value[1].int32Value = param[1];
+ value[2].int32Value = param[2];
+ value[3].int32Value = param[3];
+ return ILExecThreadCallNamedVirtualV
+ (thread, "System.Reflection.AssemblyName",
+ "SetVersion", "(Tiiii)V", value, nameInfo,
value);
+ }
+
+ /*
+ * Fill in an "AssemblyName" object with an image's name information.
+ */
+ static void FillAssemblyNameFromImage(ILExecThread *thread,
+
ILObject *nameInfo, ILImage *image)
+ {
+ ILString *name;
+ ILAssembly *assem;
+ const void *publicKey;
+ unsigned long publicKeyLen;
+ System_Array *array;
+
+ /* Set the assembly name */
+ name = ILStringCreateUTF8(thread, ILImageGetAssemblyName(image));
+ if(!name)
+ {
+ return;
+ }
+ if(CallAssemblyNameMethod(thread, nameInfo, "set_Name",
+
"(ToSystem.String;)V", (ILObject *)name))
+ {
+ return;
+ }
+
+ /* Get the first assembly structure for the image */
+ assem = (ILAssembly *)ILImageTokenInfo(image, IL_META_TOKEN_ASSEMBLY |
1);
+
+ /* Set the locale name */
+ if(ILAssembly_Locale(assem))
+ {
+ name = ILStringCreateUTF8(thread, ILAssembly_Locale(assem));
+ if(!name)
+ {
+ return;
+ }
+ if(CallAssemblyNameMethod(thread, nameInfo, "SetCultureByName",
+
"(ToSystem.String;)V", (ILObject *)name))
+ {
+ return;
+ }
+ }
+
+ /* Set the assembly name flags */
+ if(ILAssembly_HasPublicKey(assem))
+ {
+ if(CallAssemblyNameMethodI4(thread, nameInfo, "set_Flags",
+
"(TvSystem.Reflection.AssemblyNameFlags;)V",
+
(ILInt32)0x0001))
+ {
+ return;
+ }
+ }
+
+ /* Set the version information */
+ if(CallAssemblyNameMethodV(thread, nameInfo,
ILAssemblyGetVersion(assem)))
+ {
+ return;
+ }
+
+ /* Set the assembly's hash algorithm */
+ if(CallAssemblyNameMethodI4(thread, nameInfo, "set_HashAlgorithm",
+
"(TvSystem.Configuration.Assemblies.AssemblyHashAlgorithm;)V",
+ (ILInt32)(ILAssembly_HashAlg(assem))))
+ {
+ return;
+ }
+
+ /* Set the assembly's public key */
+ publicKeyLen = 0;
+ publicKey = ILAssemblyGetOriginator(assem, &publicKeyLen);
+ if(publicKey != 0 && publicKeyLen != 0)
+ {
+ array = (System_Array *)ILExecThreadNew(thread, "[B", "(Ti)V",
+
(ILVaInt)publicKeyLen);
+ if(!array)
+ {
+ return;
+ }
+ ILMemCpy(ArrayToBuffer(array), publicKey, publicKeyLen);
+ if(CallAssemblyNameMethod(thread, nameInfo, "SetPublicKey",
+ "(T[B)V",
(ILObject *)array))
+ {
+ return;
+ }
+ }
+ }
+
+ /*
+ * private void FillAssemblyName(AssemblyName nameInfo);
+ */
+ void _IL_Assembly_FillAssemblyName(ILExecThread *thread, ILObject *_this,
+ ILObject
*nameInfo)
+ {
+ ILProgramItem *item = (ILProgramItem *)_ILClrFromObject(thread, _this);
+ ILImage *image = ((item != 0) ? ILProgramItem_Image(item) : 0);
+ if(image)
+ {
+ FillAssemblyNameFromImage(thread, nameInfo, image);
+ }
+ }
+
+ /*
+ * private static int FillAssemblyNameFromFile
+ * (AssemblyName nameInfo, String assemblyFile, Assembly caller);
+ */
+ ILInt32 _IL_AssemblyName_FillAssemblyNameFromFile(ILExecThread *thread,
+
ILObject *nameInfo,
+
ILString *assemblyFile,
+
ILObject *caller)
+ {
+ ILContext *context;
+ ILImage *image;
+ int loadError;
+ char *filename;
+
+ /* Convert the filename into an ANSI string */
+ filename = ILStringToAnsi(thread, assemblyFile);
+ if(!filename)
+ {
+ return 0;
+ }
+
+ /* TODO: check security permissions */
+
+ /* We need to temporarily load the image to get its name information,
+ and then immediately discard it. Use a new context for that */
+ context = ILContextCreate();
+ if(!context)
+ {
+ ILExecThreadThrowOutOfMemory(thread);
+ return 0;
+ }
+
+ /* Attempt to load the file */
+ loadError = ILImageLoadFromFile(filename, context, &image,
+
IL_LOADFLAG_FORCE_32BIT |
+
IL_LOADFLAG_NO_RESOLVE, 0);
+ if(loadError != 0)
+ {
+ /* Convert the error code into something the C# library knows
about */
+ ILContextDestroy(context);
+ if(loadError == -1)
+ {
+ return LoadError_FileNotFound;
+ }
+ else if(loadError == IL_LOADERR_MEMORY)
+ {
+ ILExecThreadThrowOutOfMemory(thread);
+ return 0;
+ }
+ else
+ {
+ return LoadError_BadImage;
+ }
+ }
+
+ /* Fill the "AssemblyName" object with the image's name details */
+ FillAssemblyNameFromImage(thread, nameInfo, image);
+
+ /* Clean up the temporary context and exit */
+ ILContextDestroy(context);
+ return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/engine int_proto.h, 1.77, 1.78 int_table.c, 1.80, 1.81 lib_reflect.c, 1.48, 1.49,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/runtime Serialize.txt, 1.2, 1.3
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Messaging ConstructionCall.cs, 1.2, 1.3 MethodCall.cs, 1.3, 1.4
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/runtime Serialize.txt, 1.2, 1.3
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Remoting/Messaging ConstructionCall.cs, 1.2, 1.3 MethodCall.cs, 1.3, 1.4
- Index(es):