gpt4 book ai didi

c# - 在 .net4 中尝试 Dll rebase 似乎不起作用

转载 作者:行者123 更新时间:2023-11-30 20:08:12 26 4
gpt4 key购买 nike

我正在试验 Dll rebase 基于一个在 .net4 上运行的小型测试解决方案,该解决方案由一个小型 .exe 和三个小型 .Dll 组成。程序集引用已正确设置,程序可以正常编译和运行。

本练习的目的是检查 rebase 的工作原理,以便我可以将其与 ngen 结合起来,并在我正在从事的大型项目中提高性能。

我尝试了许多不同的方法来重新设置 Dll 的基数,并使用 vmmap、visual studio 模块调试器窗口和进程资源管理器监视结果;到目前为止还没有成功:

  1. 我已将 Dll1.dll、Dll2.dll 和 Dll3.dll 的 Build->Advanced->DLL Base Address 设置分别设置为 0x41000000、0x42000000 和 0x43000000。这些地址肯定被保存为每个 Dll 中的首选基地址,但对于每次运行,Dll 都会不规则地将它们的图像重新定位到内存中的许多不同位置。

  2. 我试过使用 this应用。它生成的日志显示 Dll 确实内置了首选基地址(由我选择),但是在运行时结果仍然不稳定

  3. 我试过使用 ngen。这导致 .ni 版本的 Dll 与原始 Dll 一起加载,并且所有 6 个 Dll 的内存位置都不稳定,与我要求的位置相去甚远。

  4. 我已经尝试将我的图像粘贴到 GAC 中。令人振奋的是,只有 GAC 版本的 Dll 被加载,但它们的内存位置仍然不稳定。

  5. 我已经尝试过上述每种组合的感觉。没有成功。

在运行时使用 VMMap 进行检查表明,在 0x10000000 和 0x50000000 之间的地址空间中存在巨大的可用内存间隙,因此应该没有冲突,也不需要发生 Dll rebase 。 Dll 也非常小,我在它们之间留下的 0x01000000 间隙非常大,因此它们不应该相互冲突。

我错过了什么?

我在这个练习中的主要引用是 this这篇信息量很大的文章是 2006 年为 .Net2 写的:从那时到现在有什么根本性的变化吗?

我严重怀疑它有什么不同,但这里是我使用的代码以防万一:

程序.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Dll1;
using Dll2;
using Dll3;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Thread.CurrentThread.Name = "Poodle";
Console.ReadLine();
//Thread.Sleep(10000);
Blah();
}

static void Blah()
{
Console.WriteLine(Class2.shrooms(5, 'h'));
Class3.teenAngst();
Class1.Wait();
}
}
}

Class1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dll1
{
public static class Class1
{
public static void Wait()
{
Console.ReadLine();
Console.Write(" ");
}
}
}

Class2.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dll2
{
public static class Class2
{
public static string shrooms(int argc, char argv)
{
return "Ranchdaddyx ";
}
}
}

Class3.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dll3
{
public static class Class3
{
public static void teenAngst()
{
Console.Write("Belonging ");
}
}
}

最佳答案

不需要 rebase JIT 编译代码:

JIT-compiled code does not have a rebasing problem since the addresses are generated at run time based on where the code is placed in memory. Also, MSIL is rarely affected by base address misses since MSIL references are token-based, rather than address-based. Thus when the JIT compiler is used, the system is resilient to base address collisions.

.NET assemblies and DLL rebasing

If I want to rebase my DLL's, how do I go about doing it?

http://msdn.microsoft.com/en-us/magazine/cc163610.aspx

http://support.microsoft.com/kb/969305

关于c# - 在 .net4 中尝试 Dll rebase 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7382632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com