示例#1
0
        public ObfuscatedClass GetClass(TypeKey key)
        {
            ObfuscatedClass c;

            if (!ClassMap.TryGetValue(key, out c))
            {
                c             = new ObfuscatedClass(key.ToString());
                ClassMap[key] = c;
            }

            return(c);
        }
示例#2
0
        public ObfuscatedThing GetEvent(EventKey key)
        {
            ObfuscatedClass c = GetClass(key.TypeKey);

            ObfuscatedThing t;

            if (!c.Events.TryGetValue(key, out t))
            {
                t             = new ObfuscatedThing(key.ToString());
                c.Events[key] = t;
            }

            return(t);
        }
示例#3
0
        public ObfuscatedThing GetMethod(MethodKey key)
        {
            ObfuscatedClass c = GetClass(key.TypeKey);

            ObfuscatedThing t;

            if (!c.Methods.TryGetValue(key, out t))
            {
                t = new ObfuscatedThing(key.ToString());
                c.Methods[key] = t;
            }

            return(t);
        }
示例#4
0
        public ObfuscatedThing GetProperty(PropertyKey key)
        {
            ObfuscatedClass c = GetClass(key.TypeKey);

            ObfuscatedThing t;

            if (!c.Properties.TryGetValue(key, out t))
            {
                t = new ObfuscatedThing(key.ToString());
                c.Properties[key] = t;
            }

            return(t);
        }
示例#5
0
        private void DumpClass(ObfuscatedClass classInfo)
        {
            writer.WriteLine();
            if (classInfo.Status == ObfuscationStatus.Renamed)
            {
                writer.WriteLine("{0} -> {1}", classInfo.Name, classInfo.StatusText);
            }
            else
            {
                Debug.Assert(classInfo.Status == ObfuscationStatus.Skipped,
                             "Status is expected to be either Renamed or Skipped.");
                writer.WriteLine("{0} skipped:  {1}", classInfo.Name, classInfo.StatusText);
            }
            writer.WriteLine("{");

            int numRenamed = 0;

            foreach (KeyValuePair <MethodKey, ObfuscatedThing> method in classInfo.Methods)
            {
                if (method.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpMethod(method.Key, method.Value);
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if (numRenamed < classInfo.Methods.Count)
            {
                writer.WriteLine();
            }

            foreach (KeyValuePair <MethodKey, ObfuscatedThing> method in classInfo.Methods)
            {
                if (method.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpMethod(method.Key, method.Value);
                }
            }

            // add a blank line to separate methods from field...it's pretty.
            if (classInfo.Methods.Count > 0 && classInfo.Fields.Count > 0)
            {
                writer.WriteLine();
            }

            numRenamed = 0;
            foreach (KeyValuePair <FieldKey, ObfuscatedThing> field in classInfo.Fields)
            {
                if (field.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpField(writer, field.Key, field.Value);
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if (numRenamed < classInfo.Fields.Count)
            {
                writer.WriteLine();
            }

            foreach (KeyValuePair <FieldKey, ObfuscatedThing> field in classInfo.Fields)
            {
                if (field.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpField(writer, field.Key, field.Value);
                }
            }

            // add a blank line to separate props...it's pretty.
            if (classInfo.Properties.Count > 0)
            {
                writer.WriteLine();
            }

            numRenamed = 0;
            foreach (KeyValuePair <PropertyKey, ObfuscatedThing> field in classInfo.Properties)
            {
                if (field.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpProperty(writer, field.Key, field.Value);
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if (numRenamed < classInfo.Properties.Count)
            {
                writer.WriteLine();
            }

            foreach (KeyValuePair <PropertyKey, ObfuscatedThing> field in classInfo.Properties)
            {
                if (field.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpProperty(writer, field.Key, field.Value);
                }
            }

            // add a blank line to separate events...it's pretty.
            if (classInfo.Events.Count > 0)
            {
                writer.WriteLine();
            }

            numRenamed = 0;
            foreach (KeyValuePair <EventKey, ObfuscatedThing> field in classInfo.Events)
            {
                if (field.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpEvent(writer, field.Key, field.Value);
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if (numRenamed < classInfo.Events.Count)
            {
                writer.WriteLine();
            }

            foreach (KeyValuePair <EventKey, ObfuscatedThing> field in classInfo.Events)
            {
                if (field.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpEvent(writer, field.Key, field.Value);
                }
            }

            writer.WriteLine("}");
        }
示例#6
0
        public void UpdateType(TypeKey key, ObfuscationStatus status, string text)
        {
            ObfuscatedClass c = GetClass(key);

            c.Update(status, text);
        }
示例#7
0
        private void DumpClass( ObfuscatedClass classInfo )
        {
            if ( classInfo.Status != ObfuscationStatus.Renamed )
            {
                Debug.Assert( classInfo.Status == ObfuscationStatus.Skipped,
                    "Status is expected to be either Renamed or Skipped." );
                writer.WriteStartElement("skippedClass");
                writer.WriteAttributeString("name", classInfo.Name);
                writer.WriteAttributeString("reason", classInfo.StatusText);
                writer.WriteEndElement();
                writer.WriteString("\r\n");
                return;
            }
            writer.WriteStartElement("renamedClass");
            writer.WriteAttributeString("oldName", classInfo.Name);
            writer.WriteAttributeString("newName", classInfo.StatusText);

            int numRenamed = 0;
            foreach ( KeyValuePair<MethodKey, ObfuscatedThing> method in classInfo.Methods )
            {
                if ( method.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpMethod( method.Key, method.Value );
                    numRenamed++;
                }
            }

            foreach ( KeyValuePair<MethodKey, ObfuscatedThing> method in classInfo.Methods )
            {
                if ( method.Value.Status == ObfuscationStatus.Skipped )
                    DumpMethod( method.Key, method.Value );
            }

            foreach ( KeyValuePair<FieldKey, ObfuscatedThing> field in classInfo.Fields )
            {
                if ( field.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpField( writer, field.Key, field.Value );
                }
            }

            //

            foreach ( KeyValuePair<FieldKey, ObfuscatedThing> field in classInfo.Fields )
            {
                if ( field.Value.Status == ObfuscationStatus.Skipped )
                    DumpField( writer, field.Key, field.Value );
            }

            foreach ( KeyValuePair<PropertyKey, ObfuscatedThing> field in classInfo.Properties )
            {
                if ( field.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpProperty( writer, field.Key, field.Value );
                }
            }

            foreach ( KeyValuePair<PropertyKey, ObfuscatedThing> field in classInfo.Properties )
            {
                if ( field.Value.Status == ObfuscationStatus.Skipped )
                    DumpProperty( writer, field.Key, field.Value );
            }

            foreach ( KeyValuePair<EventKey, ObfuscatedThing> field in classInfo.Events )
            {
                if ( field.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpEvent( writer, field.Key, field.Value );
                }
            }

            foreach ( KeyValuePair<EventKey, ObfuscatedThing> field in classInfo.Events )
            {
                if ( field.Value.Status == ObfuscationStatus.Skipped )
                    DumpEvent( writer, field.Key, field.Value );
            }

            writer.WriteEndElement();
            writer.WriteString("\r\n");
        }
示例#8
0
        private void DumpClass( ObfuscatedClass classInfo )
        {
            writer.WriteLine( );
            if ( classInfo.Status == ObfuscationStatus.Renamed )
                writer.WriteLine( "{0} -> {1}", classInfo.Name, classInfo.StatusText );
            else
            {
                Debug.Assert( classInfo.Status == ObfuscationStatus.Skipped,
                    "Status is expected to be either Renamed or Skipped." );
                writer.WriteLine( "{0} skipped:  {1}", classInfo.Name, classInfo.StatusText );
            }
            writer.WriteLine( "{" );

            int numRenamed = 0;
            foreach ( KeyValuePair<MethodKey, ObfuscatedThing> method in classInfo.Methods )
            {
                if ( method.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpMethod( method.Key, method.Value );
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if ( numRenamed < classInfo.Methods.Count )
                writer.WriteLine( );

            foreach ( KeyValuePair<MethodKey, ObfuscatedThing> method in classInfo.Methods )
            {
                if ( method.Value.Status == ObfuscationStatus.Skipped )
                    DumpMethod( method.Key, method.Value );
            }

            // add a blank line to separate methods from field...it's pretty.
            if ( classInfo.Methods.Count > 0 && classInfo.Fields.Count > 0 )
                writer.WriteLine( );

            numRenamed = 0;
            foreach ( KeyValuePair<FieldKey, ObfuscatedThing> field in classInfo.Fields )
            {
                if ( field.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpField( writer, field.Key, field.Value );
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if ( numRenamed < classInfo.Fields.Count )
                writer.WriteLine( );

            foreach ( KeyValuePair<FieldKey, ObfuscatedThing> field in classInfo.Fields )
            {
                if ( field.Value.Status == ObfuscationStatus.Skipped )
                    DumpField( writer, field.Key, field.Value );
            }

            // add a blank line to separate props...it's pretty.
            if ( classInfo.Properties.Count > 0 )
                writer.WriteLine( );

            numRenamed = 0;
            foreach ( KeyValuePair<PropertyKey, ObfuscatedThing> field in classInfo.Properties )
            {
                if ( field.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpProperty( writer, field.Key, field.Value );
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if ( numRenamed < classInfo.Properties.Count )
                writer.WriteLine( );

            foreach ( KeyValuePair<PropertyKey, ObfuscatedThing> field in classInfo.Properties )
            {
                if ( field.Value.Status == ObfuscationStatus.Skipped )
                    DumpProperty( writer, field.Key, field.Value );
            }

            // add a blank line to separate events...it's pretty.
            if ( classInfo.Events.Count > 0 )
                writer.WriteLine( );

            numRenamed = 0;
            foreach ( KeyValuePair<EventKey, ObfuscatedThing> field in classInfo.Events )
            {
                if ( field.Value.Status == ObfuscationStatus.Renamed )
                {
                    DumpEvent( writer, field.Key, field.Value );
                    numRenamed++;
                }
            }

            // add a blank line to separate renamed from skipped...it's pretty.
            if ( numRenamed < classInfo.Events.Count )
                writer.WriteLine( );

            foreach ( KeyValuePair<EventKey, ObfuscatedThing> field in classInfo.Events )
            {
                if ( field.Value.Status == ObfuscationStatus.Skipped )
                    DumpEvent( writer, field.Key, field.Value );
            }

            writer.WriteLine( "}" );
        }
示例#9
0
		public ObfuscatedClass GetClass(TypeKey key)
		{
			ObfuscatedClass c;

			if (!classMap.TryGetValue(key, out c))
			{
				c = new ObfuscatedClass(key.ToString());
				classMap[key] = c;
			}

			return c;
		}
示例#10
0
        private void DumpClass(ObfuscatedClass classInfo)
        {
            if (classInfo.Status != ObfuscationStatus.Renamed)
            {
                Debug.Assert(classInfo.Status == ObfuscationStatus.Skipped,
                             "Status is expected to be either Renamed or Skipped.");
                writer.WriteStartElement("skippedClass");
                writer.WriteAttributeString("name", classInfo.Name);
                writer.WriteAttributeString("reason", classInfo.StatusText);
            }
            else
            {
                writer.WriteStartElement("renamedClass");
                writer.WriteAttributeString("oldName", classInfo.Name);
                writer.WriteAttributeString("newName", classInfo.StatusText);
            }

            int numRenamed = 0;

            foreach (KeyValuePair <MethodKey, ObfuscatedThing> method in classInfo.Methods)
            {
                if (method.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpMethod(method.Key, method.Value);
                    numRenamed++;
                }
            }


            foreach (KeyValuePair <MethodKey, ObfuscatedThing> method in classInfo.Methods)
            {
                if (method.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpMethod(method.Key, method.Value);
                }
            }


            foreach (KeyValuePair <FieldKey, ObfuscatedThing> field in classInfo.Fields)
            {
                if (field.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpField(writer, field.Key, field.Value);
                }
            }

            //

            foreach (KeyValuePair <FieldKey, ObfuscatedThing> field in classInfo.Fields)
            {
                if (field.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpField(writer, field.Key, field.Value);
                }
            }


            foreach (KeyValuePair <PropertyKey, ObfuscatedThing> field in classInfo.Properties)
            {
                if (field.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpProperty(writer, field.Key, field.Value);
                }
            }


            foreach (KeyValuePair <PropertyKey, ObfuscatedThing> field in classInfo.Properties)
            {
                if (field.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpProperty(writer, field.Key, field.Value);
                }
            }


            foreach (KeyValuePair <EventKey, ObfuscatedThing> field in classInfo.Events)
            {
                if (field.Value.Status == ObfuscationStatus.Renamed)
                {
                    DumpEvent(writer, field.Key, field.Value);
                }
            }


            foreach (KeyValuePair <EventKey, ObfuscatedThing> field in classInfo.Events)
            {
                if (field.Value.Status == ObfuscationStatus.Skipped)
                {
                    DumpEvent(writer, field.Key, field.Value);
                }
            }

            writer.WriteEndElement();
            writer.WriteString("\r\n");
        }
示例#11
0
        private void DumpClass(int tabs, ObfuscatedClass cls, bool isLast = false)
        {
            var typeKey = _map.ClassMap.FirstOrDefault(el => el.Value == cls).Key;

            WriteLine(tabs, $"\"{cls.Name}\": {{");
            if (cls.Status == ObfuscationStatus.Renamed)
            {
                WriteLine(tabs + 1, $"\"NewName\": \"{cls.StatusText}\",");
            }
            else
            {
                WriteLine(tabs + 1, $"\"Reason\": \"{cls.StatusText}\",");
            }
            var genericParams = typeKey.TypeDefinition.GenericParameters;

            WriteLine(tabs + 1, "\"GenericParams\": [");
            for (var i = 0; i < genericParams.Count; i++)
            {
                var item = genericParams[i];
                WriteLine(tabs + 2, '"' + GetRawTypeName(item.FullName) + '"' + (i == genericParams.Count - 1 ? "" : ","));
            }
            WriteLine(tabs + 1, "],");


            #region Methods

            WriteLine(tabs + 1, "\"Methods\": {");
            var methods = cls.Methods.Where(el => el.Value.Status == ObfuscationStatus.Renamed).ToArray();
            for (var i = 0; i < methods.Length; i++)
            {
                var item = methods[i];
                DumpMethod(tabs + 2, item.Key, item.Value, i == methods.Length - 1 && methods.Length == cls.Methods.Count);
            }
            methods = cls.Methods.Where(el => el.Value.Status == ObfuscationStatus.Skipped).ToArray();
            for (var i = 0; i < methods.Length; i++)
            {
                var item = methods[i];
                DumpMethod(tabs + 2, item.Key, item.Value, i == methods.Length - 1);
            }
            WriteLine(tabs + 1, "},");

            #endregion

            #region Fields

            WriteLine(tabs + 1, "\"Fields\": {");
            var fields = cls.Fields.Where(el => el.Value.Status == ObfuscationStatus.Renamed).ToArray();
            for (var i = 0; i < fields.Length; i++)
            {
                var item = fields[i];
                DumpField(tabs + 2, item.Key, item.Value, i == fields.Length - 1 && fields.Length == cls.Fields.Count);
            }
            fields = cls.Fields.Where(el => el.Value.Status == ObfuscationStatus.Skipped).ToArray();
            for (var i = 0; i < fields.Length; i++)
            {
                var item = fields[i];
                DumpField(tabs + 2, item.Key, item.Value, i == fields.Length - 1);
            }
            WriteLine(tabs + 1, "},");

            #endregion

            #region Properties

            WriteLine(tabs + 1, "\"Properties\": {");
            var props = cls.Properties.Where(el => el.Value.Status == ObfuscationStatus.Renamed).ToArray();
            for (var i = 0; i < props.Length; i++)
            {
                var item = props[i];
                DumpProperty(tabs + 2, item.Key, item.Value, i == props.Length - 1 && props.Length == cls.Properties.Count);
            }
            props = cls.Properties.Where(el => el.Value.Status == ObfuscationStatus.Skipped).ToArray();
            for (var i = 0; i < props.Length; i++)
            {
                var item = props[i];
                DumpProperty(tabs + 2, item.Key, item.Value, i == props.Length - 1);
            }
            WriteLine(tabs + 1, "},");

            #endregion

            #region Events

            WriteLine(tabs + 1, "\"Events\": {");
            var events = cls.Events.Where(el => el.Value.Status == ObfuscationStatus.Renamed).ToArray();
            for (var i = 0; i < events.Length; i++)
            {
                var item = events[i];
                DumpEvent(tabs + 2, item.Key, item.Value, i == events.Length - 1 && events.Length == cls.Events.Count);
            }
            events = cls.Events.Where(el => el.Value.Status == ObfuscationStatus.Skipped).ToArray();
            for (var i = 0; i < events.Length; i++)
            {
                var item = events[i];
                DumpEvent(tabs + 2, item.Key, item.Value, i == events.Length - 1);
            }
            WriteLine(tabs + 1, "}");

            #endregion

            WriteLine(tabs, isLast ? "}" : "},");
        }