all groups > dotnet clr > september 2004 >
You're in the

dotnet clr

group:

Renaming typedefs using the unmanaged reflection API (is it possib


Renaming typedefs using the unmanaged reflection API (is it possib Nadav
9/11/2004 11:39:01 AM
dotnet clr:
Hi,

I am using the unmanaged reflection API ( e.g. IMetaDataImport,
IMetaDataEmit, … ) and I wonder…. I couldn’t find a way renaming a
Field/Method name… How could I do that? Concerning fields, I have tried to
delete the filed and re-create the field with a different name; however the
runtime doesn’t recognize the new field upon execution… How can I rename a
method/field name??? is it possible through the un-managed API or should I
rather access the metadata memory directly????

--
Nadav
Re: Renaming typedefs using the unmanaged reflection API (is it possib Ben Schwehn
9/13/2004 10:53:25 PM
[quoted text, click to view]

don't think it's possible in an easy way

[quoted text, click to view]

problematic since then you would also have to update all references to
the new token. (the 'deleted' field doesn't really get deleted but just
renamed and it keeps its token value, a new field will have a different
token value)

[quoted text, click to view]

also not trivial. It's trivial as long as the new name isn't longer,
however if it is you'll have to shift all following things in the
#strings section and update all references to those strings in the
assembly. if the section gets too big you might even have to update the
header to use 4bytes indices instead of 2bytes ones.

The most reliable way i've found is to create a new assembly from
scratch. which is also very painful if you get to more complicated
assemblies.

--
Ben
Re: Renaming typedefs using the unmanaged reflection API (is it po Nadav
9/14/2004 3:19:02 AM
Hi Ben,

Thanks for your responce, Wouldn't Assembly re-writing require manipulation
to all of the exisiting IL code? A new method created in a new assembly will
have a new token ID ( different form the one associated with the method in
the original assembly ), I assume this token is being reffered to by the IL
code ( concerning the function is called internally by some other
implementation ), taking that in mind, reconstructing an assembly would
require all of the IL code to be passed through, 'old' token ids would have
to be replaces by the new tokens, is my assumption is true? isn't it an
overkill?

Nadav
http://www.ddevel.com

[quoted text, click to view]
Re: Renaming typedefs using the unmanaged reflection API (is it po Ben Schwehn
9/14/2004 1:00:06 PM
[quoted text, click to view]

if you call the metadata emit functions in the right order they will get
asssigned the same token. I've successfully reasssembled big modules
like system.data.dll... as long as there isn't any native code it works
rather well.

[quoted text, click to view]

not as long as there isn't an easier way :) perhaps there is one though...?

You could always do a ildasm/dasm roundtrip if you don't need to do it
programatically.

--
Ben
AddThis Social Bookmark Button