Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with weawing #911

Open
tdsrhh opened this issue Jun 5, 2023 · 0 comments
Open

Problem with weawing #911

tdsrhh opened this issue Jun 5, 2023 · 0 comments

Comments

@tdsrhh
Copy link

tdsrhh commented Jun 5, 2023

Hi

I am trying to remove some embedded resources.

// the list TmpRemove contains the list of resources to remove ...

        IEnumerable<MethodDefinition> TmpMethods
            = Asm.MainModule.Types.Where(o => o.IsClass == true && o.Name == "AssemblyLoader")
                                               .SelectMany(type => type.Methods)
                                               .Where(o => o.FullName.Contains("cctor"));

        MethodDefinition TmpMethod
            = null;

        if (TmpMethods != null && TmpMethods.Count() > 0)
            TmpMethod = TmpMethods.First();

        List<Instruction> TmpInstruction
            = new List<Instruction>();

        foreach (Resource res in TmpRemove)
        {
            Asm.MainModule.Resources.Remove(res);

            if (!res.Name.StartsWith("costura.tds.") && TmpMethod != null)
            {
                for (int i = 0; i < TmpMethod.Body.Instructions.Count; i++)
                {
                    if (TmpMethod.Body.Instructions[i].Operand != null && TmpMethod.Body.Instructions[i].Operand.Equals(res.Name))
                    {
                        TmpMethod.Body.SimplifyMacros();

                        TmpInstruction.Add(TmpMethod.Body.Instructions[i - 2]);
                        TmpInstruction.Add(TmpMethod.Body.Instructions[i - 1]);
                        TmpInstruction.Add(TmpMethod.Body.Instructions[i]);
                        TmpInstruction.Add(TmpMethod.Body.Instructions[i + 1]);

                        TmpMethod.Body.OptimizeMacros();
                    }
                }
            }
        }

        foreach (Instruction ins in TmpInstruction)
            TmpMethod.Body.Instructions.Remove(ins);

This works fine, the resources are removed from my dll.

But I have a problem with the PDB file not getting updated correctly :

        using (AssemblyDefinition TmpAssembly = AssemblyDefinition.ReadAssembly(TargetPath, new ReaderParameters { SymbolReaderProvider = new PdbReaderProvider(), ReadSymbols = true, ReadWrite = true }))
        {
            MemoryStream ms = null;
            Find(true, TmpExport, TmpAssembly, ref ms);

            TmpAssembly.Write(new WriterParameters()
            {
                WriteSymbols
                    = true,

                SymbolWriterProvider
                    = new Mono.Cecil.Pdb.PdbWriterProvider(),
            });
        }

I get this error -

1> Non-negative number required.
1> Parameter name: count

Any help is apprishiated .Anyone ?

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant