Received: by 10.66.72.131 with SMTP id d3mr2391416pav.28.1348495634129; Mon, 24 Sep 2012 07:07:14 -0700 (PDT) X-BeenThere: mono-cecil@googlegroups.com Received: by 10.68.237.161 with SMTP id vd1ls19528046pbc.3.gmail; Mon, 24 Sep 2012 07:07:13 -0700 (PDT) Received: by 10.66.84.168 with SMTP id a8mr2630542paz.25.1348495633267; Mon, 24 Sep 2012 07:07:13 -0700 (PDT) Received: by 10.66.84.168 with SMTP id a8mr2630541paz.25.1348495633256; Mon, 24 Sep 2012 07:07:13 -0700 (PDT) Return-Path: Received: from mail-pb0-f49.google.com (mail-pb0-f49.google.com [209.85.160.49]) by gmr-mx.google.com with ESMTPS id vw9si3570227pbc.2.2012.09.24.07.07.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 07:07:13 -0700 (PDT) Received-SPF: pass (google.com: domain of jbev...@gmail.com designates 209.85.160.49 as permitted sender) client-ip=209.85.160.49; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jbev...@gmail.com designates 209.85.160.49 as permitted sender) smtp.mail=jbev...@gmail.com; dkim=pass header...@gmail.com Received: by pbbrq8 with SMTP id rq8so13066247pbb.22 for ; Mon, 24 Sep 2012 07:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=t9941rf9PCcZqK9/DGXnoYqSjJ1CsKt7xRx+poyRd7Y=; b=yfhvXyqHGZT7zUgoCSt0yKB3q0Q/mbMoNg9p7fooT79UAvuIq4FtwNbYMcm7VNBZzF 5uR3sqdAei05X/r10SsxqdA0qchJI/qQv3ZyChOJAyLknVbAO9DHl2ikZX7xejafYhoh nq3FWeYGXF7TtQzpKHPB+MTto7nExITGf75ZVIzk9LcLc60ZysX+D90QPZ6TSDu5kYmJ un1tXDBvoFrLVW+k5TbBztITGZ3eTIBo0iR7U64fX2EaXUC+yUFJtnY4/Dn9/6xorsQ9 68dj3HyJO51TdZ0Ye8we3N1dqNOv8rfZsqnWSZre1M6cB2C1jnHvUX5rv4A4/71aK/FK xnSA== MIME-Version: 1.0 Received: by 10.68.239.5 with SMTP id vo5mr36980247pbc.102.1348495633035; Mon, 24 Sep 2012 07:07:13 -0700 (PDT) Received: by 10.68.138.134 with HTTP; Mon, 24 Sep 2012 07:07:13 -0700 (PDT) In-Reply-To: <212661c7-a587-4b9a-b6b0-a51747d7188b@googlegroups.com> References: <212661c7-a587-4b9a-b6b0-a51747d7188b@googlegroups.com> Date: Mon, 24 Sep 2012 16:07:13 +0200 Message-ID: Subject: Re: [mono-cecil] Renaming MethodDefinition name produces bad assembly. From: Jb Evain To: mono-cecil@googlegroups.com Content-Type: text/plain; charset=UTF-8 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 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 '.' from 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: [: .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