Jump to content
Tuts 4 You

[dnlib] .Net Renamer problem


Sniper.ps

Recommended Posts

Posted

Hello Guys


 


I am gonna to make a simple renamer for .Net Apps .. the problem is : after rename the (modules, types,methods .. etc) the file is not working


 


this is the code which i am using



        private void button1_Click(object sender, EventArgs e)
        {
            Rename(AssemblyDef.Load("C:\\MyApp.exe"));
        }         public void Rename(AssemblyDef AsmDef)
        {
            int xMod = 0;
            int xType = 0;
            int xMethod = 0;
            int xParameter = 0;
            int xField = 0;
            int xProperty = 0;
            foreach (ModuleDef ModDef in AsmDef.Modules)
            {                 ModDef.Name = "Mod_" + xMod;
                xMod += 1;                 foreach (TypeDef TypDef in ModDef.Types)
                {
                    TypDef.Name = "Type_" + xType;
                    xType += 1;
                    foreach (MethodDef MthdDef in TypDef.Methods)
                    {
                        if (!MthdDef.IsConstructor && !MthdDef.IsRuntimeSpecialName)
                        {
                            MthdDef.Name = "Method_" + xMethod;
                            xMethod += 1;                             foreach (ParamDef PrmDef in MthdDef.ParamDefs)
                            {
                                PrmDef.Name = "Parameter_" + xParameter;
                                xParameter += 1;
                            }
                        }
                    }                     foreach (FieldDef FldDef in TypDef.Fields)
                    {
                        FldDef.Name = "Field_" + xField;
                        xField += 1;
                    }                     foreach (PropertyDef PropDef in TypDef.Properties)
                    {
                        PropDef.Name = "Property_" + xProperty;
                        xProperty += 1;
                    }                 }
            }
            AsmDef.Write("C:\\MyApp11.exe");
        }

and this is the problem shown by dotNet Tracer v20.0


 


i_6634cb91081.png


 


 


Thanks for you


 


Posted

  private void button1_Click(object sender, EventArgs e)
        {
            Rename(AssemblyDef.Load("C:\\MyApp.exe"));
        }        public void Rename(AssemblyDef AsmDef)
        {
            int xMod = 0;
            int xType = 0;
            int xMethod = 0;
            int xParameter = 0;
            int xField = 0;
            int xProperty = 0;
            foreach (ModuleDef ModDef in AsmDef.Modules)
            {                ModDef.Name = "Mod_" + xMod.Tostring();
                xMod += 1;                foreach (TypeDef TypDef in ModDef.Types)
                {
                    TypDef.Name = "Type_" + xType.Tostring();
                    xType += 1;
                    foreach (MethodDef MthdDef in TypDef.Methods)
                    {
                        if (!MthdDef.IsSpecialName && !MthdDef.IsRuntimeSpecialName)
                        {
                            MthdDef.Name = "Method_" + xMethod.Tostring();
                            xMethod += 1;                            foreach (ParamDef PrmDef in MthdDef.ParamDefs)
                            {
                                PrmDef.Name = "Parameter_" + xParameter.Tostring();
                                xParameter += 1;
                            }
                        }
                    }                    foreach (FieldDef FldDef in TypDef.Fields)
                    {
                        FldDef.Name = "Field_" + xField.Tostring();
                        xField += 1;
                    }                    foreach (PropertyDef PropDef in TypDef.Properties)
                    {
                        PropDef.Name = "Property_" + xProperty.Tostring();
                        xProperty += 1;
                    }                }
            }
            AsmDef.Write("D:\\MyApp11.exe");
        }
Test.............

  • Like 1
Posted (edited)

Thank you hakouabs brother .. unfortunately it does not work .. so temporarily i add this condition in "ModDef.Types" loop to ignore the Namespace shown in figure below .. because the problem come from it .. and its work fine



                    if(TypDef.Namespace.EndsWith(".My"))
                    {
                        continue;
                    }

i_2bb8c9de0b1.png


 


 


i need some solution to rename it also like in "Phoenix Protector" for example like this


 


i_d1f9dce2c41.png


Edited by Sniper.ps
li0nsar3c00l
Posted

there is a reason why de4dot's renaming code is a bit longer than these couple lines. If you don't want to use it, which would be the easiest solution, i'd recommend to check the source tho


  • Like 4
Posted

You need to exclude some things, certain symbols can't be renamed, or at least require further modification.

For example resourcemanager, p/invokes etc..

  • Like 1
Posted

Thank you li0nsar3c00l .. I'll read the de4dot code and learn from it

 

You need to exclude some things, certain symbols can't be renamed, or at least require further modification.
For example resourcemanager, p/invokes etc..

 

Thank you yq8 .. that's what I'll do .. and I'll study some of Obfuscators to know what should i modify .. Thank you again.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...