Hi.

To begin with, you'll break constructors.
Then for generic methods, and maybe some other scenarios depending on
the compiler, you'll find MethodReference that map conceptually to a
MethodDefinition. You'd have to rename those too.

Jb

On Mon, Sep 24, 2012 at 9:03 AM, master131 <[email protected]> wrote:
> I'm trying to rename methods inside an assembly by using the .Name property
> inside the MethodDefinition class. Here's a small snippet of what I'm trying
> to do.
>
>> AssemblyDefinition assembly =
>> AssemblyDefiniton.ReadAssembly("target.exe");
>>
>> foreach(var module in assembly.Modules)
>> {
>>     foreach(var type in module.Types)
>>     {
>>         foreach(var method in type.Methods)
>>         {
>>             method.Name = GenerateRandomName();
>>         }
>>     }
>> }
>>
>> assembly.Write("out.exe");
>
>
> Now, when I try running the outputted assembly, it crashes with a
> System.TypeLoadException with a message of:
>>
>> Could not load type '<namespace>.<classname>' from assembly '<assembly
>> name>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
>
>
> When I try to run peverify on the outputted assembly, this is what it tells
> me:
>>
>> [IL]: Error: [<path>: <namespace>.Program::Main][offset 0x0000000B] Unable
>> to resolve token.
>> [token  0x02000003] Type load failed.
>> [token  0x02000004] Type load failed.
>> [token  0x02000005] Type load failed.
>> [token  0x02000006] Type load failed.
>
>
> When I use the same sort of code to rename the fields and type names, it
> works perfectly fine with no problems. Any ideas as to what is happening?
>
> --
> --
> mono-cecil

-- 
--
mono-cecil

Reply via email to