예제 #1
0
        // We try decently hard to avoid creating clashing names, and also sanitize any invalid names.
        // You can customize how naming works by modifying this function.
        private void InitializeNaming()
        {
            TypeNamespace = CreateNamespace();
            // Type names that may appear in the header
            foreach (var typeName in new string[] { "CustomAttributesCache", "CustomAttributeTypeCache", "EventInfo", "FieldInfo", "Hash16", "MemberInfo", "MethodInfo", "MethodVariableKind", "MonitorData", "ParameterInfo", "PInvokeArguments", "PropertyInfo", "SequencePointKind", "StackFrameType", "VirtualInvokeData" })
            {
                TypeNamespace.ReserveName(typeName);
            }
            TypeNamer = TypeNamespace.MakeNamer <TypeInfo>((ti) => {
                if (ti.IsArray)
                {
                    return(TypeNamer.GetName(ti.ElementType) + "__Array");
                }
                var name = ti.Name.ToCIdentifier();
                if (name.StartsWith("Il2Cpp"))
                {
                    name = "_" + name;
                }
                name = Regex.Replace(name, "__+", "_");
                // Work around a dumb IDA bug: enums can't be named the same as certain "built-in" types
                // like KeyCode, Position, ErrorType. This only applies to enums, not structs.
                if (ti.IsEnum)
                {
                    name += "__Enum";
                }
                return(name);
            });

            GlobalsNamespace = CreateNamespace();
            GlobalNamer      = GlobalsNamespace.MakeNamer <MethodBase>((method) => $"{TypeNamer.GetName(method.DeclaringType)}_{method.Name.ToCIdentifier()}");
            EnumNamer        = GlobalsNamespace.MakeNamer <FieldInfo>((field) => $"{TypeNamer.GetName(field.DeclaringType)}_{field.Name.ToCIdentifier()}");
        }
        // We try decently hard to avoid creating clashing names, and also sanitize any invalid names.
        // You can customize how naming works by modifying this function.
        private void InitializeNaming()
        {
            TypeNamespace = CreateNamespace();
            TypeNamer     = TypeNamespace.MakeNamer <TypeInfo>((ti) => {
                if (ti.IsArray)
                {
                    return(TypeNamer.GetName(ti.ElementType) + "__Array");
                }
                var name = ti.Name.ToCIdentifier();
                name     = Regex.Replace(name, "__+", "_");
                // Work around a dumb IDA bug: enums can't be named the same as certain "built-in" types
                // like KeyCode, Position, ErrorType. This only applies to enums, not structs.
                if (ti.IsEnum)
                {
                    name += "__Enum";
                }
                return(name);
            });

            GlobalsNamespace = CreateNamespace();
            GlobalNamer      = GlobalsNamespace.MakeNamer <MethodBase>((method) => $"{TypeNamer.GetName(method.DeclaringType)}_{method.Name.ToCIdentifier()}");
        }