shuai 的个人资料娱乐精神照片日志 工具 帮助
2007/10/26

强暴.net程序集 之六 (Assembly表的结构和修改)


警告:本系列文章为本人原创,只作技术研究之用,您可以引用链接传播,禁止其它的转载方式,禁止用于商业或非法目的, 对于造成的一切后果本人概不负责

上回有一个TableRowSizes函数没有说,它是用来得到指定元数据表的行大小
以Assembly表为例,在Partition II Metadata中描述了它的结构:

The Assembly table has the following columns:
• HashAlgId (a 4-byte constant of type AssemblyHashAlgorithm, §23.1.1)
• MajorVersion, MinorVersion, BuildNumber, RevisionNumber (each being 2-byte constants)
• Flags (a 4-byte bitmask of type AssemblyFlags, §23.1.2)
• PublicKey (an index into the Blob heap)
• Name (an index into the String heap)
• Culture (an index into the String heap)

HashAlgId 4个字节
MajorVersion, MinorVersion, BuildNumber, RevisionNumber 共8个字节
Flags 4个字节,指定了在Side By Side模式运行时的限制
PublicKey、Name、Culture、是#Blob heap或#String heap的索引,Public Key是用于assembly的完整性及发布者验证;Name是Assembly的名字;Culture是此Assembly所支持的语言,要注意这几个字段都不是固定大小,而是能过HeapSize推算出来的

对于Blob heap或String heap的大小的值是通过META_COMPOSITE_HEADER的HeapSizes计算出来的
在Partition II Metadata有描述:
The HeapSizes field is a bitvector that encodes the width of indexes into the various heaps.  If bit 0 is set, indexes into the “#String” heap are 4 bytes wide; if bit 1 is set, indexes into the “#GUID” heap are 4 bytes wide; if bit 2 is set, indexes into the “#Blob” heap are 4 bytes wide.  Conversely, if the HeapSize bit for a particular heap is not set, indexes into that heap are 2 bytes wide.
Heap size flag Description
0x01 Size of “#String” stream >= 216.
0x02 Size of “#GUID” stream >= 216.
0x04 Size of “#Blob” stream >= 216.

这些信息正好是ildasm对.assembly 伪指令的输出,比如
.assembly CountDown
{ .hash algorithm 32772
  .ver 1:0:0:0
}

于是我们就可以求得总的行大小(Assembly表只有这一行)
  bytes = 4;
  bytes += 8;
  bytes += 4;
  bytes += (heapSizes & 0x04) ? 4 : 2;
  bytes += (heapSizes & 0x01) ? 4 : 2;
  bytes += (heapSizes & 0x01) ? 4 : 2;

现在我们改一下主版本号,注意我用的是内存映射文件
 PMETA_ASSEMBLY_TABLE assemblyTable = (PMETA_ASSEMBLY_TABLE)(tables[TableType::Assembly].Address);
 WORD* pVersion = &(assemblyTable->MajorVersion);
 *pVersion = atoi(szBuffer);

用ildasm看已经修改过来了:
.assembly query
{
  .ver 8:0:0:0
}

但是... ....

 

评论 (1)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

匿名 的图片
10 月 26 日

引用通告

此日志的引用通告 URL 是:
http://iauhsgnay.spaces.live.com/blog/cns!C7C5DB6D46321CDD!421.trak
引用此项的网络日志