示例#1
0
        void InitializeScopes(CodeFile[] CodeFiles)
        {
            if (string.IsNullOrEmpty(AssemblyName))
            {
                throw new InvalidOperationException("Assembly hasn't been set up");
            }

            if (CodeOut == null || LibOut == null)
            {
                throw new InvalidOperationException("Output streams haven't been set up");
            }

            var Random   = new Random();
            var Assembly = new Assembly(this, AssemblyName);

            Assembly.Random = Random.Next();

            GlobalContainer = new GlobalContainer(this);
            GlobalContainer.OutputAssembly = Assembly;

            for (var i = 0; i < CodeFiles.Length; i++)
            {
                var AssemblyScope = new AssemblyScope(GlobalContainer, Assembly, CodeFiles[i]);
                GlobalContainer.GlobalNamespace.AddScope(AssemblyScope);
                GlobalContainer.Children.Add(AssemblyScope);
            }

            GlobalContainer.GlobalNamespaceScope = new AssemblyScope(GlobalContainer, Assembly);
            GlobalContainer.GlobalNamespace.AddScope(GlobalContainer.GlobalNamespaceScope);
            GlobalContainer.Children.Add(GlobalContainer.GlobalNamespaceScope);
        }
示例#2
0
        bool ReadChildAssemblies(GlobalContainer Global)
        {
            var RetValue = true;
            var Count    = ReadLEB128_Int();

            ChildAssemblies = new Assembly[Count];

            for (var i = 0; i < Count; i++)
            {
                var Name   = ReadLEB128_String();
                var Random = Reader.ReadInt32();
                ReadLEB128_Int();

                var Assembly = Global.GetLoadedAssembly(Name);
                if (Assembly == null)
                {
                    var Path = new AssemblyPath(Name, true);
                    Assembly = Global.LoadAssembly(Path);
                }

                if (Assembly == null || Random != Assembly.Random)
                {
                    RetValue = false;
                    continue;
                }

                ChildAssemblies[i] = Assembly;
            }

            return(RetValue);
        }
示例#3
0
        public Assembly LoadAssemblyDesc(GlobalContainer Global, Stream Stream)
        {
            this.Global = Global;
            this.State  = Global.State;

            Reader       = new BinaryReader(Stream);
            BeginningPos = Stream.Position;
            var IdListPtr = Reader.ReadInt64() + BeginningPos;

            var Name     = ReadLEB128_String();
            var DescName = ReadLEB128_String();
            var Index    = Global.LoadedAssemblies.Count;

            CurrentAssembly        = new Assembly(State, Name, DescName, Index);
            CurrentAssembly.Random = Reader.ReadInt32();
            Global.LoadedAssemblies.Add(CurrentAssembly);
            ReadLEB128_Int();

            var Scope = new AssemblyScope(Global, CurrentAssembly);

            Global.GlobalNamespace.AddScope(Scope);
            Global.Children.Add(Scope);

            if (!ReadChildAssemblies(Global))
            {
                return(null);
            }

            var ContentPos = Stream.Position;

            Stream.Seek(IdListPtr, SeekOrigin.Begin);
            ReadIdRefs();

            Stream.Seek(ContentPos, SeekOrigin.Begin);
            ReadIdList(Scope, Global.GlobalNamespace);

            Dereference();
            UpdateIds();
            return(CurrentAssembly);
        }
示例#4
0
        public void CreateAssemblyDesc(GlobalContainer Global, Stream Stream)
        {
            this.Global  = Global;
            BeginningPos = Stream.Position;
            Writer       = new BinaryWriter(Stream, new UTF8Encoding());

            var IdListPosPtr = Stream.Position;

            Writer.Seek(8, SeekOrigin.Current);

            WriteLEB128(Global.OutputAssembly.Name);
            WriteLEB128(Global.OutputAssembly.DescName);
            Writer.Write(Global.OutputAssembly.Random);

            if (Global.AssemblyEntry == null)
            {
                WriteLEB128(-1);
            }
            else
            {
                WriteLEB128(Global.AssemblyEntry.GlobalPointerIndex);
            }
            WriteChildAssemblies();

            if (Identifiers != null)
            {
                Identifiers.Clear();
            }
            else
            {
                Identifiers = new List <Identifier>();
            }
            WriteContent();

            WriteToPos(IdListPosPtr, Stream.Position - BeginningPos);
            WriteIdRefs();
        }
示例#5
0
 public AssemblyScope(GlobalContainer Parent, Assembly Assembly, CodeFile CodeFile = null)
     : base(Parent, CodeFile == null ? new CodeString() : new CodeString(CodeFile), Parent.GlobalNamespace)
 {
     this.Assembly = Assembly;
 }