Home All Groups Group Topic Archive Search About
Author
9 Mar 2007 11:34 PM
Lee
I am trying to develop an easy way to manage dll load addresses for my .NET
controls and libraries. I was wondering if through reflection or some other
type of mechanism in .NET that I could examine the compiled dll to determine
what its base load address is and its size? With that information I could
create a visual map to use to organize my dll's and ensure they all play
nicely.

Thanks...

Author
10 Mar 2007 12:26 AM
Barry Kelly
Lee wrote:

> I am trying to develop an easy way to manage dll load addresses for my .NET
> controls and libraries. I was wondering if through reflection or some other
> type of mechanism in .NET that I could examine the compiled dll to determine
> what its base load address is and its size? With that information I could
> create a visual map to use to organize my dll's and ensure they all play
> nicely.

Read the PE /COFF file format specification:

http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx

The format isn't too hard to work with. A set of indirections will get
you to where you want to go. For example, at offset 0x3C into the file,
there is the offset to the Signature (PE\0\0) followed immediately by
the PE / COFF File Header, which is 20 bytes long. In .EXEs and .DLLs,
it's immediately followed by the Optional header. The Optional Header
has different magic (first word) (0x10B or 0x20B) depending on 32-bit
(PE32) or 64-bit (PE32+) image. At offset 28 (PE32) or offset 24 (PE32+)
is the image base, which is 4 bytes in PE32 and 8 bytes in PE32+.

You should be able to make a combination of FileStream and BinaryReader
read this.

-- Barry

Author
10 Mar 2007 4:09 AM
Barry Kelly
Barry Kelly wrote:

Show quote
> Lee wrote:
>
> > I am trying to develop an easy way to manage dll load addresses for my .NET
> > controls and libraries. I was wondering if through reflection or some other
> > type of mechanism in .NET that I could examine the compiled dll to determine
> > what its base load address is and its size? With that information I could
> > create a visual map to use to organize my dll's and ensure they all play
> > nicely.
>
> Read the PE /COFF file format specification:
>
> http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx

> You should be able to make a combination of FileStream and BinaryReader
> read this.

However, I should point out that if you want accurate representations of
the total virtual memory usage, you're going to have to iterate through
the image sections and check their RVAs and sizes.

-- Barry

Author
11 Mar 2007 11:59 AM
유철호
yo.
Show quote
"Lee" <L**@discussions.microsoft.com> 님이 다음 메시지를 작성했습니다.
news:6178961F-DCFF-4CF8-A77E-EBF2ED1A3BDE@microsoft.com...
>I am trying to develop an easy way to manage dll load addresses for my .NET
> controls and libraries. I was wondering if through reflection or some
> other
> type of mechanism in .NET that I could examine the compiled dll to
> determine
> what its base load address is and its size? With that information I could
> create a visual map to use to organize my dll's and ensure they all play
> nicely.
>
> Thanks...
Author
12 Mar 2007 7:49 PM
Ben Voigt
"Lee" <L**@discussions.microsoft.com> wrote in message
news:6178961F-DCFF-4CF8-A77E-EBF2ED1A3BDE@microsoft.com...
>I am trying to develop an easy way to manage dll load addresses for my .NET
> controls and libraries. I was wondering if through reflection or some
> other
> type of mechanism in .NET that I could examine the compiled dll to
> determine
> what its base load address is and its size? With that information I could
> create a visual map to use to organize my dll's and ensure they all play
> nicely.

..NET dlls don't have load addresses, because they don't contain compiled
code.  The JIT reads the MSIL from the assembly, compiles it, linking
dynamically so there's no need for fixups, and write the compiled code out
(sequentially?) somewhere in memory.  The size isn't known, and may vary
from run to run depending on whether all code paths are accessed.

C++/CLI mixed assemblies are a different story.  Like native dlls, they do
have compiled code that needs fixups if there is a base load address
conflict.

Show quote
>
> Thanks...
Author
12 Mar 2007 9:36 PM
Austin Ehlers
Show quote
On Mon, 12 Mar 2007 14:49:36 -0500, "Ben Voigt" <rbv@nospam.nospam>
wrote:

>
>"Lee" <L**@discussions.microsoft.com> wrote in message
>news:6178961F-DCFF-4CF8-A77E-EBF2ED1A3BDE@microsoft.com...
>>I am trying to develop an easy way to manage dll load addresses for my .NET
>> controls and libraries. I was wondering if through reflection or some
>> other
>> type of mechanism in .NET that I could examine the compiled dll to
>> determine
>> what its base load address is and its size? With that information I could
>> create a visual map to use to organize my dll's and ensure they all play
>> nicely.
>
>.NET dlls don't have load addresses, because they don't contain compiled
>code.  The JIT reads the MSIL from the assembly, compiles it, linking
>dynamically so there's no need for fixups, and write the compiled code out
>(sequentially?) somewhere in memory.  The size isn't known, and may vary
>from run to run depending on whether all code paths are accessed.

Sorry, they do.  See /baseaddress option for the C# compiler.  It's
usually only important for NGEN'd assemblies.  See
http://msdn.microsoft.com/msdnmag/issues/06/05/clrinsideout/default.aspx#S4

Austin
<snip>
Author
12 Mar 2007 10:00 PM
Ben Voigt
Show quote
"Austin Ehlers" <austin.ehlers.spam.@gmail.com> wrote in message
news:2qhbv25oqgk6ed5o3ptkc8bgjetehef1hq@4ax.com...
> On Mon, 12 Mar 2007 14:49:36 -0500, "Ben Voigt" <rbv@nospam.nospam>
> wrote:
>
>>
>>"Lee" <L**@discussions.microsoft.com> wrote in message
>>news:6178961F-DCFF-4CF8-A77E-EBF2ED1A3BDE@microsoft.com...
>>>I am trying to develop an easy way to manage dll load addresses for my
>>>.NET
>>> controls and libraries. I was wondering if through reflection or some
>>> other
>>> type of mechanism in .NET that I could examine the compiled dll to
>>> determine
>>> what its base load address is and its size? With that information I
>>> could
>>> create a visual map to use to organize my dll's and ensure they all play
>>> nicely.
>>
>>.NET dlls don't have load addresses, because they don't contain compiled
>>code.  The JIT reads the MSIL from the assembly, compiles it, linking
>>dynamically so there's no need for fixups, and write the compiled code out
>>(sequentially?) somewhere in memory.  The size isn't known, and may vary
>>from run to run depending on whether all code paths are accessed.
>
> Sorry, they do.  See /baseaddress option for the C# compiler.  It's
> usually only important for NGEN'd assemblies.  See
> http://msdn.microsoft.com/msdnmag/issues/06/05/clrinsideout/default.aspx#S4

Yes, you're right.  In essence, ngen converts a pure MSIL assembly such as
C# generates, into a mixed assembly, and so load addresses and fixups become
important again.  I think I did make mention of mixed assemblies, thanks for
pointing out that they aren't necessarily C++/CLI when ngen is used.

Show quote
>
> Austin
> <snip>
Author
12 Mar 2007 10:06 PM
Ben Voigt
"Lee" <L**@discussions.microsoft.com> wrote in message
news:6178961F-DCFF-4CF8-A77E-EBF2ED1A3BDE@microsoft.com...
>I am trying to develop an easy way to manage dll load addresses for my .NET
> controls and libraries. I was wondering if through reflection or some
> other
> type of mechanism in .NET that I could examine the compiled dll to
> determine
> what its base load address is and its size? With that information I could
> create a visual map to use to organize my dll's and ensure they all play
> nicely.

For example, SymGetModuleInfo64 and SymEnumerateModules64

Details at http://msdn2.microsoft.com/en-us/library/ms681408.aspx

Show quote
>
> Thanks...

AddThis Social Bookmark Button