public AttributeCleaner(ModuleReader moduleReader, Logger logger)
 {
     propertyAttributeNames = new List<string> {"DoNotNotifyAttribute", "NotifyPropertyAttribute", "DependsOnAttribute"};
     typeAttributeNames = new List<string> { "NotifyForAllAttribute", "DoNotNotifyAttribute" };
     this.moduleReader = moduleReader;
     this.logger = logger;
 }
 public AssemblyLoaderImporter(ModuleReader moduleReader, AssemblyResolver assemblyResolver, EmbedTask embedTask)
 {
     instructionConstructorInfo = typeof (Instruction).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] {typeof (OpCode), typeof (object)}, null);
     this.moduleReader = moduleReader;
     this.assemblyResolver = assemblyResolver;
     this.embedTask = embedTask;
 }
 public ModuleWriter(ModuleReader moduleReader, ProjectKeyReader projectKeyReader, Logger logger, WeavingTask config)
 {
     this.moduleReader = moduleReader;
     this.projectKeyReader = projectKeyReader;
     this.logger = logger;
     this.config = config;
 }
 public ResourceEmbedder(DependencyFinder dependencyFinder, ModuleReader moduleReader, EmbedTask embedTask, Logger logger)
 {
     streams = new List<Stream>();
     this.dependencyFinder = dependencyFinder;
     this.moduleReader = moduleReader;
     this.embedTask = embedTask;
     this.logger = logger;
 }
    public TypeEqualityFinder(ModuleReader moduleReader, MsCoreReferenceFinder msCoreReferenceFinder, TypeResolver typeResolver)
    {
        methodCache = new Dictionary<string, MethodReference>();

        this.moduleReader = moduleReader;
        this.msCoreReferenceFinder = msCoreReferenceFinder;
        this.typeResolver = typeResolver;
    }
Beispiel #6
0
 public virtual void Read(ModuleReader reader)
 {
     reader.Read(out memberType);
     reader.Read(out memberName);
     reader.Read(out memberFlags);
     reader.Read(out memberSize);
     reader.Read(out memberAttributes);
 }
    public MethodFinderTest()
    {
        var codeBase = typeof(MethodFinderTest).Assembly.CodeBase.Replace("file:///", string.Empty);
        var module = ModuleDefinition.ReadModule(codeBase);
        var moduleReader = new ModuleReader(null, null, Substitute.For<Logger>()) { Module = module };
        methodFinder = new MethodFinder(new MethodGenerifier(moduleReader), null, null, moduleReader, Substitute.For<Logger>(), null, new EventInvokerNameResolver(null));

        typeDefinition = module.Types.First(x => x.Name.EndsWith("MethodFinderTest"));
    }
Beispiel #8
0
 public void Read(ModuleReader reader)
 {
     reader.Read(out functionType);
     reader.Read(out numargs);
     reader.Read(out numlocals);
     reader.Read(out numblocks);
     reader.Read(out numexceptions);
     reader.Read(out vslot);
 }
 public IsChangedMethodFinder(MethodGenerifier methodGenerifier, Logger logger, MsCoreReferenceFinder msCoreReferenceFinder, TypeNodeBuilder typeNodeBuilder, ModuleReader moduleReader, TypeResolver typeResolver)
 {
     this.methodGenerifier = methodGenerifier;
     this.logger = logger;
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     this.typeNodeBuilder = typeNodeBuilder;
     this.moduleReader = moduleReader;
     this.typeResolver = typeResolver;
 }
Beispiel #10
0
 public void Read(ModuleReader reader)
 {
     reader.Read(out baseStructure);
     reader.Read(out numinterfaces);
     reader.Read(out numfields);
     reader.Read(out numvmethods);
     reader.Read(out numcontracts);
     reader.Read(out nummembers);
 }
 public MethodFinder(MethodGenerifier methodGenerifier, MethodInjector methodInjector, TypeNodeBuilder typeNodeBuilder, ModuleReader moduleReader, Logger logger, TypeResolver typeResolver, EventInvokerNameResolver eventInvokerNameResolver)
 {
     this.methodGenerifier = methodGenerifier;
     this.methodInjector = methodInjector;
     this.typeNodeBuilder = typeNodeBuilder;
     this.moduleReader = moduleReader;
     this.logger = logger;
     this.typeResolver = typeResolver;
     this.eventInvokerNameResolver = eventInvokerNameResolver;
 }
Beispiel #12
0
 internal static Type[] ReadMethodSpec(ModuleReader module, ByteReader br, IGenericContext context)
 {
     if (br.ReadByte() != GENERICINST)
     {
         throw new BadImageFormatException();
     }
     Type[] args = new Type[br.ReadCompressedInt()];
     for (int i = 0; i < args.Length; i++)
     {
         args[i] = ReadType(module, br, context);
     }
     return(args);
 }
Beispiel #13
0
        public static ModuleDefinition ReadModule(Stream stream, ReaderParameters parameters)
        {
            CheckStream(stream);
            if (!stream.CanRead || !stream.CanSeek)
            {
                throw new ArgumentException();
            }
            Mixin.CheckParameters(parameters);

            return(ModuleReader.CreateModuleFrom(
                       ImageReader.ReadImageFrom(stream),
                       parameters));
        }
Beispiel #14
0
        internal static new void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal interface and register it.
            Interface iface = new Interface(module);
            module.RegisterMember(iface);

            // Read the name.
            iface.name = module.GetString(header.memberName);
            iface.flags = (MemberFlags)header.memberFlags;

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
Beispiel #15
0
        public static SAMPLOAD SL_RegisterSample(SAMPLE s, int type, ModuleReader reader)
        {
            SAMPLOAD news;
            SAMPLOAD cruise = null;

            if (type == (int)SharpMikCommon.MDTypes.MD_MUSIC)
            {
                cruise = musiclist;
            }
            else if (type == (int)SharpMikCommon.MDTypes.MD_SNDFX)
            {
                cruise = sndfxlist;
            }
            else
            {
                return(null);
            }

            /* Allocate and add structure to the END of the list */
            news = new SAMPLOAD();

            if (cruise != null)
            {
                while (cruise.next != null)
                {
                    cruise = cruise.next;
                }
                cruise.next = news;
            }
            else
            {
                if (type == (int)SharpMikCommon.MDTypes.MD_MUSIC)
                {
                    musiclist = news;
                }
                else if (type == (int)SharpMikCommon.MDTypes.MD_SNDFX)
                {
                    sndfxlist = news;
                }
            }

            news.infmt     = (uint)(s.flags & SharpMikCommon.SF_FORMATMASK);
            news.outfmt    = news.infmt;
            news.reader    = reader;
            news.sample    = s;
            news.length    = s.length;
            news.loopstart = s.loopstart;
            news.loopend   = s.loopend;

            return(news);
        }
Beispiel #16
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal field and register it.
            FieldVariable field = new FieldVariable(module);

            module.RegisterMember(field);

            // Read the name and flags.
            field.SetName(module.GetString(header.memberName));
            field.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Beispiel #17
0
        internal new static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal interface and register it.
            Interface iface = new Interface(module);

            module.RegisterMember(iface);

            // Read the name.
            iface.name  = module.GetString(header.memberName);
            iface.flags = (MemberFlags)header.memberFlags;

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
Beispiel #18
0
        private static bool ML_LoadSamples(Module of, ModuleReader modreader)
        {
            int u;

            for (u = 0; u < of.numsmp; u++)
            {
                if (of.samples[u].length != 0)
                {
                    SampleLoader.SL_RegisterSample(of.samples[u], (int)SharpMikCommon.MDTypes.MD_MUSIC, modreader);
                }
            }

            return(true);
        }
Beispiel #19
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            EventVariable ev = new EventVariable(module);

            module.RegisterMember(ev);

            // Read the name and flags.
            ev.SetName(module.GetString(header.memberName));
            ev.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Beispiel #20
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Get the module.
            ChelaModule module = GetModule();

            // Read the type.
            type = module.GetType(reader.ReadUInt());

            // Read the add modifier.
            addModifier = (Function)module.GetMember(reader.ReadUInt());

            // Read the remove modifier.
            removeModifier = (Function)module.GetMember(reader.ReadUInt());
        }
        internal static FieldSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
        {
            if (br.ReadByte() != FIELD)
            {
                throw new BadImageFormatException();
            }
            Type fieldType;

            Type[] optionalCustomModifiers;
            Type[] requiredCustomModifiers;
            ReadCustomModifiers(module, br, context, out requiredCustomModifiers, out optionalCustomModifiers);
            fieldType = ReadType(module, br, context);
            return(new FieldSignature(fieldType, optionalCustomModifiers, requiredCustomModifiers));
        }
Beispiel #22
0
        private static Type ReadFunctionPointer(ModuleReader module, ByteReader br, IGenericContext context)
        {
            __StandAloneMethodSig sig = MethodSignature.ReadStandAloneMethodSig(module, br, context);

            if (module.universe.EnableFunctionPointers)
            {
                return(FunctionPointerType.Make(module.universe, sig));
            }
            else
            {
                // by default, like .NET we return System.IntPtr here
                return(module.universe.System_IntPtr);
            }
        }
Beispiel #23
0
        internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
        {
            byte flags = br.ReadByte();

            if ((flags & PROPERTY) == 0)
            {
                throw new BadImageFormatException();
            }
            CallingConventions callingConvention = CallingConventions.Standard;

            if ((flags & HASTHIS) != 0)
            {
                callingConvention |= CallingConventions.HasThis;
            }
            if ((flags & EXPLICITTHIS) != 0)
            {
                callingConvention |= CallingConventions.ExplicitThis;
            }
            Type returnType;

            Type[]   returnTypeRequiredCustomModifiers;
            Type[]   returnTypeOptionalCustomModifiers;
            Type[]   parameterTypes;
            Type[][] parameterRequiredCustomModifiers;
            Type[][] parameterOptionalCustomModifiers;
            int      paramCount = br.ReadCompressedInt();

            ReadCustomModifiers(module, br, context, out returnTypeRequiredCustomModifiers, out returnTypeOptionalCustomModifiers);
            returnType     = ReadRetType(module, br, context);
            parameterTypes = new Type[paramCount];
            parameterRequiredCustomModifiers = null;
            parameterOptionalCustomModifiers = null;
            for (int i = 0; i < parameterTypes.Length; i++)
            {
                if (IsCustomModifier(br.PeekByte()))
                {
                    if (parameterOptionalCustomModifiers == null)
                    {
                        parameterOptionalCustomModifiers = new Type[parameterTypes.Length][];
                        parameterRequiredCustomModifiers = new Type[parameterTypes.Length][];
                    }
                    ReadCustomModifiers(module, br, context, out parameterRequiredCustomModifiers[i], out parameterOptionalCustomModifiers[i]);
                }
                parameterTypes[i] = ReadParam(module, br, context);
            }
            return(new PropertySignature(callingConvention, returnType, returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
                                         parameterTypes, parameterOptionalCustomModifiers, parameterRequiredCustomModifiers));
        }
Beispiel #24
0
 private static Type ReadTypeOrByRef(ModuleReader module, ByteReader br, IGenericContext context)
 {
     if (br.PeekByte() == ELEMENT_TYPE_BYREF)
     {
         br.ReadByte();
         // LAMESPEC it is allowed (by C++/CLI, ilasm and peverify) to have custom modifiers after the BYREF
         // (which makes sense, as it is analogous to pointers)
         CustomModifiers mods = ReadCustomModifiers(module, br, context);
         // C++/CLI generates void& local variables, so we need to use ReadTypeOrVoid here
         return(ReadTypeOrVoid(module, br, context).__MakeByRefType(mods.required, mods.optional));
     }
     else
     {
         return(ReadType(module, br, context));
     }
 }
Beispiel #25
0
        protected static Type ReadRetType(ModuleReader module, ByteReader br, IGenericContext context)
        {
            switch (br.PeekByte())
            {
            case ELEMENT_TYPE_VOID:
                br.ReadByte();
                return(module.universe.System_Void);

            case ELEMENT_TYPE_TYPEDBYREF:
                br.ReadByte();
                return(module.universe.System_TypedReference);

            default:
                return(ReadTypeOrByRef(module, br, context));
            }
        }
Beispiel #26
0
        public CodeBlock DecompileCodeBlock(CodeBlockDefinition blockDefinition)
        {
            Position = blockDefinition.Offset;
            var instrBuilder = ImmutableArray.CreateBuilder <Instruction>();
            var refCollector = new ReferenceCollector(Module);
            ImmutableArray <byte> unrecognizedBytes = ImmutableArray <byte> .Empty;

            do
            {
                Instruction currInstruction = null;
                try
                {
                    currInstruction = NextInstruction();
                    if (currInstruction is EndOfScriptInstruction)
                    {
                        break;
                    }

                    if (instrBuilder.Count > 0)
                    {
                        var last = instrBuilder[instrBuilder.Count - 1];
                        currInstruction.Previous = last;
                        last.Next = currInstruction;
                    }
                }
                catch (UnrecognizedInstructionException)
                {
                    unrecognizedBytes = ModuleReader.ReadBytes(blockDefinition.EndOffset - Position).ToImmutableArray();
                    break;
                }

                instrBuilder.Add(currInstruction);
                refCollector.Visit(currInstruction);
            } while (Position < blockDefinition.EndOffset);

            return(new CodeBlock(blockDefinition)
            {
                Instructions = instrBuilder.ToImmutable(),
                UnrecognizedBytes = unrecognizedBytes,
                StringReferences = refCollector.Strings,
                CodeBlockReferences = refCollector.CodeBlocks,
                ExternalCodeBlockReferences = refCollector.ExternalCodeBlocks,
                DataBlockReferences = refCollector.DataBlocks
            });
        }
Beispiel #27
0
        private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context)
        {
            Type type;

            switch (br.ReadByte())
            {
            case ELEMENT_TYPE_CLASS:
                type = ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType();
                break;

            case ELEMENT_TYPE_VALUETYPE:
                type = ReadTypeDefOrRefEncoded(module, br, context).MarkValueType();
                break;

            default:
                throw new BadImageFormatException();
            }
            if (!type.__IsMissing && !type.IsGenericTypeDefinition)
            {
                throw new BadImageFormatException();
            }
            int genArgCount = br.ReadCompressedInt();

            Type[]   args   = new Type[genArgCount];
            Type[][] reqmod = null;
            Type[][] optmod = null;
            for (int i = 0; i < genArgCount; i++)
            {
                // LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it
                CustomModifiers mods = ReadCustomModifiers(module, br, context);
                if (mods.required != null || mods.optional != null)
                {
                    if (reqmod == null)
                    {
                        reqmod = new Type[genArgCount][];
                        optmod = new Type[genArgCount][];
                    }
                    reqmod[i] = mods.required;
                    optmod[i] = mods.optional;
                }
                args[i] = ReadType(module, br, context);
            }
            return(GenericTypeInstance.Make(type, args, reqmod, optmod));
        }
Beispiel #28
0
        private static Type ReadTypeDefOrRefEncoded(ModuleReader module, ByteReader br, IGenericContext context)
        {
            int encoded = br.ReadCompressedInt();

            switch (encoded & 3)
            {
            case 0:
                return(module.ResolveType((TypeDefTable.Index << 24) + (encoded >> 2), null, null));

            case 1:
                return(module.ResolveType((TypeRefTable.Index << 24) + (encoded >> 2), null, null));

            case 2:
                return(module.ResolveType((TypeSpecTable.Index << 24) + (encoded >> 2), context));

            default:
                throw new BadImageFormatException();
            }
        }
Beispiel #29
0
        private static CustomModifiers ReadCustomModifiers(ModuleReader module, ByteReader br, IGenericContext context)
        {
            CustomModifiers mods = new CustomModifiers();
            byte            b    = br.PeekByte();

            if (IsCustomModifier(b))
            {
                List <Type> required = new List <Type>();
                List <Type> optional = new List <Type>();
                while (IsCustomModifier(b))
                {
                    bool req  = br.ReadByte() == ELEMENT_TYPE_CMOD_REQD;
                    Type type = ReadTypeDefOrRefEncoded(module, br, context);
                    (req ? required : optional).Add(type);
                    b = br.PeekByte();
                }
                mods.required = required.ToArray();
                mods.optional = optional.ToArray();
            }
            return(mods);
        }
        private Module LoadModule(int index, byte[] rawModule, string name)
        {
            string location = name == null ? null : Path.Combine(Path.GetDirectoryName(this.location), name);

            if ((manifestModule.File.records[index].Flags & ContainsNoMetaData) != 0)
            {
                return(externalModules[index] = new ResourceModule(manifestModule, index, location));
            }
            else
            {
                if (rawModule == null)
                {
                    try
                    {
                        rawModule = File.ReadAllBytes(location);
                    }
                    catch (FileNotFoundException)
                    {
                        if (resolvers != null)
                        {
                            ResolveEventArgs arg = new ResolveEventArgs(name, this);
                            foreach (ModuleResolveEventHandler resolver in resolvers)
                            {
                                Module module = resolver(this, arg);
                                if (module != null)
                                {
                                    return(module);
                                }
                            }
                        }
                        if (universe.MissingMemberResolution)
                        {
                            return(externalModules[index] = new MissingModule(this, index));
                        }
                        throw;
                    }
                }
                return(externalModules[index] = new ModuleReader(this, manifestModule.universe, new MemoryStream(rawModule), location, false));
            }
        }
Beispiel #31
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Read the type and slot.
            uint typeId = reader.ReadUInt();

            slot = reader.ReadInt();

            // Load the field type.
            this.type = GetModule().GetType(typeId);

            uint initializerSize = header.memberSize - 8;

            if (!type.IsConstant() || IsExternal())
            {
                // Skip the initializer.
                reader.Skip(initializerSize);
            }
            else
            {
                // Load the initializer.
                initializer = ConstantValue.ReadQualified(GetModule(), reader);
            }
        }
    // Start is called before the first frame update
    void Awake()
    {
        outputStarted    = false;
        tilemapCompleted = false;

        modules              = modulesParent.GetComponentsInChildren <Module>().ToList();
        customGrid           = FindObjectOfType <CustomGrid>();
        customGrid.mapObject = mapObject;

        inputReader = new ModuleReader(modules.ToArray());

        for (int i = 0; i < mapObject.transform.childCount; ++i)
        {
            Destroy(mapObject.transform.GetChild(i).gameObject);
        }

        if (inputReader.GotInput)
        {
            InitializeGrid();
        }

        //GetPlayerPlacedTiles();
    }
Beispiel #33
0
 public static AssemblyName GetAssemblyName(string path)
 {
     try
     {
         path = Path.GetFullPath(path);
         using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             ModuleReader module = new ModuleReader(null, null, fs, path);
             if (module.Assembly == null)
             {
                 throw new BadImageFormatException("Module does not contain a manifest");
             }
             return(module.Assembly.GetName());
         }
     }
     catch (IOException x)
     {
         throw new FileNotFoundException(x.Message, x);
     }
     catch (UnauthorizedAccessException x)
     {
         throw new FileNotFoundException(x.Message, x);
     }
 }
Beispiel #34
0
        private void Th_Window_Init()
        {
            // icm32.dll
            ModuleReader.WaitForModule("mscms.dll", Process, null);
            Console.WriteLine($"{account.Nickname} configuring Windowsize");

            Window_MoveTo_Default();
            Window_ScaleTo_Default();

            int i = 0;

            while (i < 3 && account.Settings.WinConfig.IsConfigured(Process) != true)
            {
                try
                {
                    Window_MoveTo_Default();
                    Window_ScaleTo_Default();
                }
                catch { }

                Thread.Sleep(500);
                i++;
            }
        }
Beispiel #35
0
        internal static CustomModifiers Read(ModuleReader module, ByteReader br, IGenericContext context)
        {
            byte b = br.PeekByte();

            if (!IsCustomModifier(b))
            {
                return(new CustomModifiers());
            }
            List <Type> list = new List <Type>();
            Type        mode = Initial;

            do
            {
                Type cmod = br.ReadByte() == Signature.ELEMENT_TYPE_CMOD_REQD ? MarkerType.ModReq : MarkerType.ModOpt;
                if (mode != cmod)
                {
                    mode = cmod;
                    list.Add(mode);
                }
                list.Add(Signature.ReadTypeDefOrRefEncoded(module, br, context));
                b = br.PeekByte();
            }while (IsCustomModifier(b));
            return(new CustomModifiers(list.ToArray()));
        }
    /// <summary>
    /// Loads a new instance of <see cref="CILModule"/> with a contents from <paramref name="stream"/>.
    /// Useful for multi-module assemblies when one doesn't want to load whole assembly.
    /// </summary>
    /// <param name="ctx">The current <see cref="CILReflectionContext"/>.</param>
    /// <param name="stream">The stream to load module from.</param>
    /// <param name="eArgs">The <see cref="EmittingArguments"/> during loading. After successful module load, the additional information about the module will be available in this object.</param>
    /// <returns>A new instance of <see cref="CILModule"/> form the contents of the <paramref name="stream"/>.</returns>
    /// <exception cref="ArgumentNullException">If <paramref name="ctx"/> or <paramref name="stream"/> or <paramref name="eArgs"/> is <c>null</c>.</exception>
    /// <exception cref="BadImageFormatException">If the headers or metadata section of the stream has invalid values, or stream contents are otherwise malformed.</exception>
    /// <remarks>
    /// If the module returned by this method is main module, that is, its <c>Assembly</c> table has exactly one row, then the <see cref="EmittingArguments.ModuleAssemblyLoader"/> callback of <paramref name="eArgs"/> will never be used.
    /// Therefore it is ok to pass <c>null</c> as the callback to <paramref name="eArgs"/> if the caller is certain the module will always be the main module.
    /// However, when the module is not the main module, the callback will be used.
    /// If in that situation the callback is <c>null</c>, <see cref="InvalidOperationException"/> is thrown.
    /// The callback may be invoked only by accessing the <see cref="CILModule.Assembly"/> property of the returned <see cref="CILModule"/>.
    /// </remarks>
    public static CILModule LoadModule(this CILReflectionContext ctx, Stream stream, EmittingArguments eArgs)
    {
        ModuleReader mr = null; MetaDataReader md = null;
        var          ownerAssembly = eArgs.ModuleAssemblyLoader;
        var          result        = LoadModule((CILReflectionContextImpl)ctx, stream, eArgs, mod =>
        {
            CILAssemblyImpl ass;
            if (md.assembly.Length == 1)
            {
                ass = LoadAssembly((CILReflectionContextImpl)ctx, null, eArgs, mr, md, mod);
            }
            else
            {
                if (ownerAssembly == null)
                {
                    throw new InvalidOperationException("The callback to get assembly of this module was not provided.");
                }
                ass      = (CILAssemblyImpl)ownerAssembly(mod);
                var mods = ass.InternalModules;
                lock (mods.Lock)
                {
                    if (!mods.Value.CQ.Contains(mod))
                    {
                        mods.Value.Add(mod);
                    }
                }
            }
            return(ass);
        }, out mr, out md);

        if (!eArgs.LazyLoad)
        {
            ForceLoadModule(result);
        }
        return(result);
    }
 public FileChangedChecker(Logger logger, WeavingTask config, ModuleReader moduleReader)
 {
     namespaceKey = config.GetType().Namespace.Replace(".", string.Empty);
     this.logger = logger;
     this.moduleReader = moduleReader;
 }
 public MethodGenerifier(ModuleReader moduleReader)
 {
     this.moduleReader = moduleReader;
 }
Beispiel #39
0
    public void Execute()
    {
        try
        {

            var referenceFinder = new AssemblyReferenceFinder(this, Logger);
            referenceFinder.Execute();
            var assemblyResolver = new AssemblyResolver(referenceFinder);
            var reader = new ModuleReader
                             {
                                 AssemblyResolver = assemblyResolver,
                                 InnerWeaver = this,
                                 Logger = Logger
                             };
            reader.Execute();

            var weaverInitialiser = new WeaverInitialiser
                                        {
                                            ModuleDefinition = reader.ModuleDefinition,
                                            AssemblyResolver = assemblyResolver,
                                            InnerWeaver = this,
                                            Logger = Logger
                                        };
            weaverInitialiser.Execute();

            var weaverRunner = new ModuleWeaverRunner
                                   {
                                       Logger = Logger,
                                   };
            Logger.LogInfo("");
            foreach (var weaverInstance in weaverInitialiser.WeaverInstances)
            {
                var weaverName = ObjectTypeName.GetAssemblyName(weaverInstance);
                Logger.SetCurrentWeaverName(weaverName);
                try
                {
                    weaverRunner.Execute(weaverInstance);
                }
                catch (Exception exception)
                {
                    Logger.LogError(exception.ToFriendlyString());
                    return;
                }
                finally
                {
                    Logger.ClearWeaverName();
                }
            }

            var keyFinder = new StrongNameKeyFinder
                {
                    InnerWeaver = this,
                    Logger = Logger,
                    ModuleDefinition = reader.ModuleDefinition
                };
            keyFinder.Execute();
            var moduleWriter = new ModuleWriter
                                   {
                                       InnerWeaver = this,
                                       Logger = Logger,
                                       ModuleDefinition = reader.ModuleDefinition,
                                       StrongNameKeyFinder = keyFinder,
                                   };
            moduleWriter.Execute();

        }
        catch (Exception exception)
        {
            Logger.LogError(exception.ToFriendlyString());
        }
    }
 public InterceptorFinder(ModuleReader moduleReader)
 {
     this.moduleReader = moduleReader;
 }
Beispiel #41
0
 public FileChangedChecker(Logger logger, ModuleReader moduleReader)
 {
     this.logger = logger;
     this.moduleReader = moduleReader;
 }
Beispiel #42
0
        // see ECMA 335 CLI spec June 2006 section 23.2.12 for this production
        protected static Type ReadType(ModuleReader module, ByteReader br, IGenericContext context)
        {
            CustomModifiers mods;

            switch (br.ReadByte())
            {
            case ELEMENT_TYPE_CLASS:
            case ELEMENT_TYPE_VALUETYPE:
                return(ReadTypeDefOrRefEncoded(module, br, context));

            case ELEMENT_TYPE_BOOLEAN:
                return(module.universe.System_Boolean);

            case ELEMENT_TYPE_CHAR:
                return(module.universe.System_Char);

            case ELEMENT_TYPE_I1:
                return(module.universe.System_SByte);

            case ELEMENT_TYPE_U1:
                return(module.universe.System_Byte);

            case ELEMENT_TYPE_I2:
                return(module.universe.System_Int16);

            case ELEMENT_TYPE_U2:
                return(module.universe.System_UInt16);

            case ELEMENT_TYPE_I4:
                return(module.universe.System_Int32);

            case ELEMENT_TYPE_U4:
                return(module.universe.System_UInt32);

            case ELEMENT_TYPE_I8:
                return(module.universe.System_Int64);

            case ELEMENT_TYPE_U8:
                return(module.universe.System_UInt64);

            case ELEMENT_TYPE_R4:
                return(module.universe.System_Single);

            case ELEMENT_TYPE_R8:
                return(module.universe.System_Double);

            case ELEMENT_TYPE_I:
                return(module.universe.System_IntPtr);

            case ELEMENT_TYPE_U:
                return(module.universe.System_UIntPtr);

            case ELEMENT_TYPE_STRING:
                return(module.universe.System_String);

            case ELEMENT_TYPE_OBJECT:
                return(module.universe.System_Object);

            case ELEMENT_TYPE_VAR:
                return(context.GetGenericTypeArgument(br.ReadCompressedInt()));

            case ELEMENT_TYPE_MVAR:
                return(context.GetGenericMethodArgument(br.ReadCompressedInt()));

            case ELEMENT_TYPE_GENERICINST:
                return(ReadGenericInst(module, br, context));

            case ELEMENT_TYPE_SZARRAY:
                mods = ReadCustomModifiers(module, br, context);
                return(ReadType(module, br, context).__MakeArrayType(mods.required, mods.optional));

            case ELEMENT_TYPE_ARRAY:
                mods = ReadCustomModifiers(module, br, context);
                return(ReadType(module, br, context).__MakeArrayType(ReadArrayShape(br), mods.required, mods.optional));

            case ELEMENT_TYPE_PTR:
                mods = ReadCustomModifiers(module, br, context);
                return(ReadTypeOrVoid(module, br, context).__MakePointerType(mods.required, mods.optional));

            case ELEMENT_TYPE_FNPTR:
                return(ReadFunctionPointer(module, br, context));

            default:
                throw new BadImageFormatException();
            }
        }
Beispiel #43
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal field and register it.
            FieldVariable field = new FieldVariable(module);
            module.RegisterMember(field);

            // Read the name and flags.
            field.SetName(module.GetString(header.memberName));
            field.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
 public IsChangedMethodFinder(MethodGenerifier methodGenerifier, Logger logger, MsCoreReferenceFinder msCoreReferenceFinder, TypeNodeBuilder typeNodeBuilder, ModuleReader moduleReader, TypeResolver typeResolver)
 {
     this.methodGenerifier      = methodGenerifier;
     this.logger                = logger;
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     this.typeNodeBuilder       = typeNodeBuilder;
     this.moduleReader          = moduleReader;
     this.typeResolver          = typeResolver;
 }
Beispiel #45
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Read the type and slot.
            uint typeId = reader.ReadUInt();
            slot = reader.ReadInt();

            // Load the field type.
            this.type = GetModule().GetType(typeId);

            uint initializerSize = header.memberSize - 8;
            if(!type.IsConstant() || IsExternal())
            {
                // Skip the initializer.
                reader.Skip(initializerSize);
            }
            else
            {
                // Load the initializer.
                initializer = ConstantValue.ReadQualified(GetModule(), reader);
            }
        }
Beispiel #46
0
 public ModuleLoaderImporter(ModuleReader moduleReader, AssemblyLoaderImporter assemblyLoaderImporter, MsCoreReferenceFinder coreReferenceFinder)
 {
     this.moduleReader = moduleReader;
     this.assemblyLoaderImporter = assemblyLoaderImporter;
     this.coreReferenceFinder = coreReferenceFinder;
 }
Beispiel #47
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Get the module.
            ChelaModule module = GetModule();

            // Read the type.
            type = module.GetType(reader.ReadUInt());

            // Read the add modifier.
            addModifier = (Function)module.GetMember(reader.ReadUInt());

            // Read the remove modifier.
            removeModifier = (Function)module.GetMember(reader.ReadUInt());
        }
Beispiel #48
0
 internal RawModule(ModuleReader module)
 {
     this.module           = module;
     this.isManifestModule = module.Assembly != null;
 }
Beispiel #49
0
 public ResourceCaseFixer(DependencyFinder dependencyFinder, ModuleReader moduleReader, EmbedTask embedTask, Logger logger)
 {
     this.moduleReader = moduleReader;
 }
Beispiel #50
0
 public FieldToPropertyForwarder(ModuleReader moduleReader, FieldToPropertyConverter fieldToPropertyConverter, MsCoreReferenceFinder msCoreReferenceFinder)
 {
     this.moduleReader          = moduleReader;
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     forwardedFields            = fieldToPropertyConverter.ForwardedFields;
 }
 public FieldToPropertyForwarder(ModuleReader moduleReader, FieldToPropertyConverter fieldToPropertyConverter, MsCoreReferenceFinder msCoreReferenceFinder)
 {
     this.moduleReader = moduleReader;
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     forwardedFields = fieldToPropertyConverter.ForwardedFields;
 }
Beispiel #52
0
 internal ManifestResourceInfo(ModuleReader module, int index)
 {
     this.module = module;
     this.index  = index;
 }
 public TypeNodeBuilder(ModuleReader moduleReader, NotifyInterfaceFinder notifyInterfaceFinder, TypeResolver typeResolver)
 {
     this.moduleReader = moduleReader;
     this.notifyInterfaceFinder = notifyInterfaceFinder;
     this.typeResolver = typeResolver;
 }
Beispiel #54
0
        public void Read()
        {
            var reader = new ModuleReader(Input);

            Program.Assert(reader.ReadHeader(), "ReadHeader");

            SectionHeader sh;

            while (reader.ReadSectionHeader(out sh))
            {
                if (sh.StreamPayloadEnd > reader.Reader.BaseStream.Length)
                {
                    throw new Exception("Invalid header");
                }

                SectionHeaders.Add(sh);

                switch (sh.id)
                {
                case SectionTypes.Type:
                    Program.Assert(reader.ReadTypeSection(out Types));
                    break;

                case SectionTypes.Import:
                    Program.Assert(reader.ReadImportSection(out Imports));
                    break;

                case SectionTypes.Function:
                    Program.Assert(reader.ReadFunctionSection(out Functions));
                    break;

                case SectionTypes.Table:
                    // FIXME: Not tested
                    Program.Assert(reader.ReadTableSection(out Tables));
                    break;

                case SectionTypes.Global:
                    Program.Assert(reader.ReadGlobalSection(out Globals));
                    break;

                case SectionTypes.Export:
                    Program.Assert(reader.ReadExportSection(out Exports));
                    break;

                case SectionTypes.Element:
                    Program.Assert(reader.ReadElementSection(out Elements));
                    break;

                case SectionTypes.Code:
                    Program.Assert(reader.ReadCodeSection(out Code, FunctionBodyCallback));
                    break;

                case SectionTypes.Data:
                    DataSection ds;
                    Program.Assert(reader.ReadDataSection(out ds));
                    Input.BaseStream.Seek(sh.StreamPayloadEnd, SeekOrigin.Begin);
                    break;

                case SectionTypes.Custom:
                    if (sh.name == "name")
                    {
                        ReadNameSection(reader, Input, sh);
                    }
                    Input.BaseStream.Seek(sh.StreamPayloadEnd, SeekOrigin.Begin);
                    break;

                default:
                    Input.BaseStream.Seek(sh.StreamPayloadEnd, SeekOrigin.Begin);
                    break;
                }
            }
        }
 public ReferenceCleaner(ModuleReader moduleReader, Logger logger)
 {
     this.moduleReader = moduleReader;
     this.logger = logger;
 }
 public MsCoreReferenceFinder(ModuleReader moduleReader, IAssemblyResolver assemblyResolver)
 {
     this.moduleReader = moduleReader;
     this.assemblyResolver = assemblyResolver;
 }
Beispiel #57
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            EventVariable ev = new EventVariable(module);
            module.RegisterMember(ev);

            // Read the name and flags.
            ev.SetName(module.GetString(header.memberName));
            ev.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }