Ejemplo n.º 1
0
        public static void Skip(ModuleReader reader)
        {
            // Skip the attribute class and ctor id.
            reader.Skip(8);

            // Read the number of arguments.
            int numargs = reader.ReadByte();

            // Skip them.
            for(int i = 0; i < numargs; ++i)
                ConstantValue.SkipQualified(reader);

            // Read the number of properties.
            int numprops = reader.ReadByte();

            // Skip them.
            for(int i = 0; i < numprops; ++i)
            {
                // Skip the property id.
                reader.Skip(4);

                // Skip the property value.
                ConstantValue.SkipQualified(reader);
            }
        }
Ejemplo n.º 2
0
 public void Read(ModuleReader reader)
 {
     reader.Read(out machineType);
     reader.Read(out numSections);
     reader.Read(out timeStamp);
     reader.Read(out symbolTablePointer);
     reader.Read(out numSymbols);
     reader.Read(out optionalHeaderSize);
     reader.Read(out characteristics);
 }
Ejemplo n.º 3
0
 public void Read(ModuleReader reader)
 {
     name = reader.ReadString(8);
     reader.Read(out virtualSize);
     reader.Read(out virtualAddress);
     reader.Read(out rawDataSize);
     reader.Read(out rawDataPointer);
     reader.Read(out relocationsPointer);
     reader.Read(out lineNumberPointer);
     reader.Read(out numRelocations);
     reader.Read(out numLineNumbers);
     reader.Read(out characteristics);
 }
Ejemplo n.º 4
0
        internal static new void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal structure and register it.
            Class clazz = new Class(module);
            module.RegisterMember(clazz);

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

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 5
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            PropertyVariable prop = new PropertyVariable(module);

            module.RegisterMember(prop);

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

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 6
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal type name and register it.
            TypeNameMember typeName = new TypeNameMember(module);

            module.RegisterMember(typeName);

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

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 7
0
        internal new static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal structure and register it.
            Class clazz = new Class(module);

            module.RegisterMember(clazz);

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

            // Skip the class elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 8
0
        public static GenericInstance Read(GenericPrototype prototype, ModuleReader reader, ChelaModule module)
        {
            // Read the type count.
            int count = reader.ReadByte();

            // Read the types.
            IChelaType[] types = new IChelaType[count];
            for (int i = 0; i < count; ++i)
            {
                types[i] = module.GetType(reader.ReadUInt());
            }

            // Create the readed instance.
            return(new GenericInstance(prototype, types));
        }
Ejemplo n.º 9
0
        public static void GetEmbeddedModule(ModuleReader reader)
        {
            // Read the MZ signature.
            if (reader.ReadByte() != 'M' || reader.ReadByte() != 'Z')
            {
                throw new ModuleException("Invalid PE signature.");
            }

            // Read the PE offset.
            reader.SetPosition(0x3c);
            uint peOffset = reader.ReadUInt();

            // Read the PE\0\0 sinature
            reader.SetPosition(peOffset);
            if (reader.ReadByte() != 'P' || reader.ReadByte() != 'E' ||
                reader.ReadByte() != 0 || reader.ReadByte() != 0)
            {
                throw new ModuleException("Unsupported MS DOS programs.");
            }

            // Read the COFF header.
            CoffHeader header = new CoffHeader();

            header.Read(reader);

            // Ignore the optional header.
            reader.Skip(header.optionalHeaderSize);

            // Read the sections until finding the .cbm section.
            CoffSectionHeader sectionHeader = new CoffSectionHeader();

            for (int i = 0; i < header.numSections; ++i)
            {
                // Read the section header.
                sectionHeader.Read(reader);

                // If this is the .cbm section, done.
                if (sectionHeader.name == ".cbm")
                {
                    reader.SetPosition(sectionHeader.rawDataPointer);
                    return;
                }
            }

            // Couldn't find embedded module.
            throw new ModuleException("Couldn't find embedded Chela module.");
        }
Ejemplo n.º 10
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Check if the function is a method.
            MemberFlags instanceFlags = (MemberFlags)header.memberFlags & MemberFlags.InstanceMask;
            bool        method        = instanceFlags != MemberFlags.Static &&
                                        instanceFlags != MemberFlags.StaticConstructor;

            // Create the temporal function and register it.
            Function function = method ? new Method(module) : new Function(module);

            module.RegisterMember(function);

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

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 11
0
        public static GenericPrototype Read(ModuleReader reader, ChelaModule module)
        {
            byte count;
            uint placeHolder;

            // Read the place holder count;
            reader.Read(out count);

            // Read the place holders.
            PlaceHolderType[] placeHolders = new PlaceHolderType[count];
            for (int i = 0; i < count; ++i)
            {
                reader.Read(out placeHolder);
                placeHolders[i] = (PlaceHolderType)module.GetType(placeHolder);
            }

            // Return the prototype.
            return(new GenericPrototype(placeHolders));
        }
Ejemplo n.º 12
0
        public static void GetEmbeddedModule(ModuleReader reader)
        {
            // Read the MZ signature.
            if(reader.ReadByte() != 'M' || reader.ReadByte() != 'Z')
                throw new ModuleException("Invalid PE signature.");

            // Read the PE offset.
            reader.SetPosition(0x3c);
            uint peOffset = reader.ReadUInt();

            // Read the PE\0\0 sinature
            reader.SetPosition(peOffset);
            if(reader.ReadByte() != 'P' || reader.ReadByte() != 'E' ||
                reader.ReadByte() != 0 || reader.ReadByte() != 0)
                throw new ModuleException("Unsupported MS DOS programs.");

            // Read the COFF header.
            CoffHeader header = new CoffHeader();
            header.Read(reader);

            // Ignore the optional header.
            reader.Skip(header.optionalHeaderSize);

            // Read the sections until finding the .cbm section.
            CoffSectionHeader sectionHeader = new CoffSectionHeader();
            for(int i = 0; i < header.numSections; ++i)
            {
                // Read the section header.
                sectionHeader.Read(reader);

                // If this is the .cbm section, done.
                if(sectionHeader.name == ".cbm")
                {
                    reader.SetPosition(sectionHeader.rawDataPointer);
                    return;
                }
            }

            // Couldn't find embedded module.
            throw new ModuleException("Couldn't find embedded Chela module.");
        }
Ejemplo n.º 13
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Read the function header.
            FunctionHeader fheader = new FunctionHeader();

            fheader.Read(reader);

            // Read the function type.
            type = (FunctionType)GetModule().GetType(fheader.functionType);

            // Read the generic prototype.
            genericPrototype = GenericPrototype.Read(reader, GetModule());

            // Read the vslot.
            if (IsMethod())
            {
                Method method = (Method)this;
                method.vslot = fheader.vslot;
            }

            // Skip the elements.
            reader.Skip(header.memberSize - FunctionHeader.HeaderSize - genericPrototype.GetSize());
        }
Ejemplo n.º 14
0
        public static void GetEmbeddedModule(ModuleReader reader)
        {
            // Read the elf identifier.
            byte[] ident;
            reader.Read(out ident, (int)ElfIdent.EI_NIDENT);

            // Check the magic number.
            for (int i = 0; i < ElfMagic.Length; ++i)
            {
                if (ident[i] != ElfMagic[i])
                {
                    throw new ModuleException("File is not an ELF.");
                }
            }

            // Check the version.
            if (ident[(int)ElfIdent.EI_VERSION] != (int)ElfVersion.EV_CURRENT)
            {
                throw new ModuleException("Invalid elf version.");
            }

            // Check the elf class.
            ElfClass clazz = (ElfClass)ident[(int)ElfIdent.EI_CLASS];

            if (clazz == ElfClass.ELFCLASS32)
            {
                GetEmbeddedModule32(reader, ident);
            }
            else if (clazz == ElfClass.ELFCLASS64)
            {
                GetEmbeddedModule64(reader, ident);
            }
            else
            {
                throw new ModuleException("Unsupported ELF class.");
            }
        }
Ejemplo n.º 15
0
 internal override void Read(ModuleReader reader, MemberHeader header)
 {
     reader.Read(out rawData, (int)header.memberSize);
 }
Ejemplo n.º 16
0
        private void ReadData()
        {
            // Only read once the data.
            if(readedData)
                return;
            readedData = true;

            ModuleReader reader = new ModuleReader(new MemoryStream(rawData));

            // Get the module.
            ChelaModule module = GetModule();

            // Read the template.
            template = (Structure)module.GetMember(reader.ReadUInt());

            // Read the factory.
            factory = (Scope)module.GetMember(reader.ReadUInt());

            // Read the generic instance.
            genericInstance = GenericInstance.Read(template.GetGenericPrototype(), reader, module);

            // Initialize.
            Initialize(template, genericInstance);
            rawData = null;
        }
Ejemplo n.º 17
0
        public static ChelaModule LoadModule(string filename, bool fullLoad)
        {
            // Open the file.
            FileStream file = new FileStream(filename, FileMode.Open);

            // Create the module reader.
            ModuleReader reader = new ModuleReader(file);

            // Read the module.
            ChelaModule res = LoadModule(reader, fullLoad);

            // Set the loaded module filename.
            res.SetFileName(filename);

            // Return the module.
            return res;
        }
Ejemplo n.º 18
0
            public void Read(ModuleReader reader, bool big)
            {
                reader.Read(out sh_name);
                reader.Read(out sh_type);
                reader.Read(out sh_flags);
                reader.Read(out sh_addr);
                reader.Read(out sh_offset);
                reader.Read(out sh_size);
                reader.Read(out sh_link);
                reader.Read(out sh_info);
                reader.Read(out sh_addralign);
                reader.Read(out sh_entsize);

                if(big)
                {
                    ModuleReader.SwapBytesD(ref sh_name);
                    ModuleReader.SwapBytesD(ref sh_type);
                    ModuleReader.SwapBytesD(ref sh_flags);
                    ModuleReader.SwapBytesD(ref sh_addr);
                    ModuleReader.SwapBytesD(ref sh_offset);
                    ModuleReader.SwapBytesD(ref sh_size);
                    ModuleReader.SwapBytesD(ref sh_link);
                    ModuleReader.SwapBytesD(ref sh_info);
                    ModuleReader.SwapBytesD(ref sh_addralign);
                    ModuleReader.SwapBytesD(ref sh_entsize);
                }
            }
Ejemplo n.º 19
0
        public static ChelaModule LoadModule(ModuleReader reader, bool fullLoad)
        {
            // Try to guess the file type.
            uint moduleStart = reader.GetPosition();
            byte[] signature;
            reader.Read(out signature, 8);

            // Check for elf file type.
            bool isElf = true;
            for(int i = 0; i < 4; ++i)
            {
                if(signature[i] != ElfFormat.ElfMagic[i])
                {
                    isElf = false;
                    break;
                }
            }

            // Check for PE.
            bool isPE = signature[0] == 'M' && signature[1] == 'Z';

            // Find the module content.
            reader.SetPosition(moduleStart);
            if(isElf)
            {
                // Move to the embedded module.
                ElfFormat.GetEmbeddedModule(reader);
                reader.FixBase();
            }
            else if(isPE)
            {
                // Move to the embedded module.
                PEFormat.GetEmbeddedModule(reader);
                reader.FixBase();
            }

            // Read the module header.
            ModuleHeader header = new ModuleHeader();
            header.Read(reader);

            // Create the output module.
            ChelaModule result = new ChelaModule();

            // Read the string table.
            reader.SetPosition(header.stringTableOffset);
            for(uint i = 0; i < header.stringTableEntries; ++i)
            {
                uint id = i+1u;
                string s = reader.ReadString();
                result.stringTable.Add(s);
                result.registeredStrings.Add(s, id);
            }

            // Read myself data.
            ModuleReference modref = new ModuleReference();
            reader.SetPosition(header.moduleRefTableOffset);
            modref.Read(reader);
            result.SetName(result.GetString(modref.moduleName));

            // Read the module type.
            result.moduleType = (ModuleType)header.moduleType;

            // Read the referenced modules.
            for(uint i = 1; i < header.moduleRefTableEntries; ++i)
            {
                // Read the referenced module.
                modref.Read(reader);

                // Load it.
                ChelaModule referencedModule = LoadNamedModule(result.GetString(modref.moduleName));
                result.referencedModules.Add(referencedModule);
            }

            // Preload the members.
            reader.SetPosition(header.memberTableOffset);
            uint end = header.memberTableOffset + header.memberTableSize;
            MemberHeader mheader = new MemberHeader();
            while(reader.GetPosition() < end)
            {
                // Read the member header.
                mheader.Read(reader);

                // Skip the attributes.
                SkipAttributes(reader, mheader.memberAttributes);

                // Preload the member.
                MemberHeaderType mtype = (MemberHeaderType)mheader.memberType;
                switch(mtype)
                {
                case MemberHeaderType.Namespace:
                    Namespace.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Structure:
                    Structure.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Class:
                    Class.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Interface:
                    Interface.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Function:
                    Function.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Field:
                    FieldVariable.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.FunctionGroup:
                    FunctionGroup.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.TypeInstance:
                    StructureInstance.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Property:
                    PropertyVariable.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Event:
                    EventVariable.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.TypeName:
                    TypeNameMember.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.MemberInstance:
                case MemberHeaderType.FunctionInstance:
                    // Ignore the member instance.
                    result.memberTable.Add(null);
                    reader.Skip(mheader.memberSize);
                    break;
                case MemberHeaderType.TypeGroup:
                    TypeGroup.PreloadMember(result, reader, mheader);
                    break;
                case MemberHeaderType.Reference:
                    {
                        // Read the module id.
                        byte moduleId = reader.ReadByte();

                        // Get the referenced module.
                        ChelaModule refMod = result.GetReferenced(moduleId);

                        // Find the member there.
                        ScopeMember member = refMod.GetMember(result.GetString(mheader.memberName));
                        result.memberTable.Add(member);
                    }
                    break;
                default:
                    // Unknown member.
                    System.Console.WriteLine("add unknown member {0}", mtype);
                    result.memberTable.Add(null);
                    reader.Skip(mheader.memberSize);
                    break;
                }
            }

            // Read the type table.
            reader.SetPosition(header.typeTableOffset);
            for(uint i = 0; i < header.typeTableEntries; ++i)
            {
                // Read the type reference.
                TypeReference typeRef = new TypeReference();
                typeRef.Read(reader);

                // Try to load direct members.
                TypeKind kind = (ChelaModule.TypeKind)typeRef.typeKind;
                if(kind == TypeKind.Class || kind == TypeKind.Interface ||
                   kind == TypeKind.Structure || kind == TypeKind.Instance)
                {
                    // Store the actual type.
                    result.typeTable.Add(result.GetMember(typeRef.memberId));
                }
                else
                {
                    // Store the reference for delayed loading.
                    result.typeTable.Add(typeRef);
                }
            }

            // Read the anonymous types.
            reader.SetPosition(header.anonTypeTableOffset);
            end = header.anonTypeTableOffset + header.anonTypeTableSize;
            while(reader.GetPosition() < end)
            {
                // Read the anonymous type data.
                AnonTypeHeader anonType = new AnonTypeHeader();
                anonType.Read(reader);

                // Store it in the anonymous type table.
                result.anonymousTypes.Add(anonType);
            }

            // Now, read the actual members.
            reader.SetPosition(header.memberTableOffset);
            for(int i = 0; i < result.memberTable.Count; ++i)
            {
                // Get the preloaded member.
                ScopeMember member = result.memberTable[i];

                // Read his header.
                mheader.Read(reader);

                // Skip the attributes.
                SkipAttributes(reader, mheader.memberAttributes);

                // Read the member.
                if(member != null && mheader.memberType != (int)MemberHeaderType.Reference)
                    member.Read(reader, mheader);
                else
                    reader.Skip(mheader.memberSize); // Skip unknown members.
            }

            // The first member must be the global namespace.
            result.globalNamespace = (Namespace)result.GetMember(1);

            // Update the parent children relationship.
            result.globalNamespace.UpdateParent(null);

            // Now, perform second read pass, required by function groups.
            reader.SetPosition(header.memberTableOffset);
            for(int i = 0; i < result.memberTable.Count; ++i)
            {
                // Get the preloaded member.
                ScopeMember member = result.memberTable[i];

                // Read his header.
                mheader.Read(reader);

                // Skip the attributes.
                SkipAttributes(reader, mheader.memberAttributes);

                // Read the member.
                if(member != null && mheader.memberType != (int)MemberHeaderType.Reference)
                    member.Read2(reader, mheader);
                else
                    reader.Skip(mheader.memberSize); // Skip unknown members.
            }

            // Finish all of the loading.
            result.globalNamespace.FinishLoad();

            // Register the member names.
            for(int i = 0; i < result.memberTable.Count; ++i)
            {
                ScopeMember member = result.memberTable[i];
                if(member != null)
                    result.memberNameTable[member.GetFullName()] = member;
            }

            // Load the runtime classes.
            if(result.referencedModules.Count == 0)
                result.LoadRuntimeReferences(result);

            // Dump the readed module.
            //result.Dump();

            // Return the result module.
            return result;
        }
Ejemplo n.º 20
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Read the function header.
            FunctionHeader fheader = new FunctionHeader();
            fheader.Read(reader);

            // Read the function type.
            type = (FunctionType)GetModule().GetType(fheader.functionType);

            // Read the generic prototype.
            genericPrototype = GenericPrototype.Read(reader, GetModule());

            // Read the vslot.
            if(IsMethod())
            {
                Method method = (Method)this;
                method.vslot = fheader.vslot;
            }

            // Skip the elements.
            reader.Skip(header.memberSize - FunctionHeader.HeaderSize - genericPrototype.GetSize());
        }
Ejemplo n.º 21
0
 internal override void Read(ModuleReader reader, MemberHeader header)
 {
     // Read the types into the member list.
     memberList = new List<Structure>();
     int numtypes = (int)header.memberSize / 4;
     for (int i = 0; i < numtypes; ++i)
         memberList.Add((Structure)GetModule().GetMember (reader.ReadUInt ()));
 }
Ejemplo n.º 22
0
            public void Read(ModuleReader reader, bool big)
            {
                reader.Read(out e_type);
                reader.Read(out e_machine);
                reader.Read(out e_version);
                reader.Read(out e_entry);
                reader.Read(out e_phoff);
                reader.Read(out e_shoff);
                reader.Read(out e_flags);
                reader.Read(out e_ehsize);
                reader.Read(out e_phentsize);
                reader.Read(out e_phnum);
                reader.Read(out e_shentsize);
                reader.Read(out e_shnum);
                reader.Read(out e_shstrndex);

                // Swap bytes.
                if(big)
                {
                    ModuleReader.SwapBytesD(ref e_type);
                    ModuleReader.SwapBytesD(ref e_machine);
                    ModuleReader.SwapBytesD(ref e_version);
                    ModuleReader.SwapBytesD(ref e_entry);
                    ModuleReader.SwapBytesD(ref e_phoff);
                    ModuleReader.SwapBytesD(ref e_shoff);
                    ModuleReader.SwapBytesD(ref e_flags);
                    ModuleReader.SwapBytesD(ref e_ehsize);
                    ModuleReader.SwapBytesD(ref e_phentsize);
                    ModuleReader.SwapBytesD(ref e_phnum);
                    ModuleReader.SwapBytesD(ref e_shentsize);
                    ModuleReader.SwapBytesD(ref e_shnum);
                    ModuleReader.SwapBytesD(ref e_shstrndex);
                }
            }
Ejemplo n.º 23
0
        internal override void Read(ModuleReader reader, MemberHeader header)
        {
            // Get the module.
            ChelaModule module = GetModule();

            // Read the type.
            actualType = module.GetType(reader.ReadUInt());
        }
Ejemplo n.º 24
0
 public void Read(ModuleReader reader)
 {
     reader.Read(out moduleName);
     reader.Read(out versionMajor);
     reader.Read(out versionMinor);
     reader.Read(out versionMicro);
 }
Ejemplo n.º 25
0
 public void Read(ModuleReader reader)
 {
     reader.Read(out typeName);
     reader.Read(out typeKind);
     reader.Read(out memberId);
 }
Ejemplo n.º 26
0
 internal override void Read(ModuleReader reader, MemberHeader header)
 {
     // Read the children.
     uint nummembers = header.memberSize/4u;
     for(uint i = 0; i < nummembers; ++i)
     {
         uint child = reader.ReadUInt();
         AddMember(GetModule().GetMember(child));
     }
 }
Ejemplo n.º 27
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal namespace and register it.
            Namespace space = new Namespace(module);
            module.RegisterMember(space);

            // Read the name.
            space.name = module.GetString(header.memberName);

            // Skip the namespace elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 28
0
 internal virtual void Read2(ModuleReader reader, MemberHeader header)
 {
     reader.Skip(header.memberSize);
 }
Ejemplo n.º 29
0
            public void Read(ModuleReader reader)
            {
                // Read the signature.
                string sign = reader.ReadString(8);
                if(sign != Signature)
                    throw new ModuleException("Invalid module signature. " + sign);

                // Read the header members
                reader.Read(out moduleSize);
                reader.Read(out formatVersionMajor);
                reader.Read(out formatVersionMinor);
                reader.Read(out moduleType);
                reader.Read(out entryPoint);
                reader.Read(out moduleRefTableEntries);
                reader.Read(out moduleRefTableOffset);
                reader.Read(out memberTableOffset);
                reader.Read(out memberTableSize);
                reader.Read(out anonTypeTableOffset);
                reader.Read(out anonTypeTableSize);
                reader.Read(out typeTableEntries);
                reader.Read(out typeTableOffset);
                reader.Read(out stringTableEntries);
                reader.Read(out stringTableOffset);
                reader.Read(out libTableOffset);
                reader.Read(out libTableEntries);
                reader.Read(out debugInfoSize);
                reader.Read(out debugInfoOffset);
                reader.Read(out resourceDataSize);
                reader.Read(out resourceDataOffset);
            }
Ejemplo n.º 30
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            TypeGroup tgroup = new TypeGroup (module);
            module.RegisterMember (tgroup);

            // Read the name.
            tgroup.name = module.GetString (header.memberName);

            // Skip the structure elements.
            reader.Skip (header.memberSize);
        }
Ejemplo n.º 31
0
 public void Read(ModuleReader reader)
 {
     reader.Read(out typeKind);
     reader.Read(out recordSize);
     reader.Read(out readedData, (int)recordSize);
 }
Ejemplo n.º 32
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Check if the function is a method.
            MemberFlags instanceFlags = (MemberFlags)header.memberFlags & MemberFlags.InstanceMask;
            bool method = instanceFlags != MemberFlags.Static &&
                          instanceFlags != MemberFlags.StaticConstructor;

            // Create the temporal function and register it.
            Function function = method ? new Method(module) : new Function(module);
            module.RegisterMember(function);

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

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 33
0
        internal static new void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal structure instance.
            StructureInstance instance = new StructureInstance(module);
            module.RegisterMember(instance);

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 34
0
 public void Read(ModuleReader reader)
 {
     name = reader.ReadString(8);
     reader.Read(out virtualSize);
     reader.Read(out virtualAddress);
     reader.Read(out rawDataSize);
     reader.Read(out rawDataPointer);
     reader.Read(out relocationsPointer);
     reader.Read(out lineNumberPointer);
     reader.Read(out numRelocations);
     reader.Read(out numLineNumbers);
     reader.Read(out characteristics);
 }
Ejemplo n.º 35
0
 internal override void Read(ModuleReader reader, MemberHeader header)
 {
     reader.Read(out rawData, (int)header.memberSize);
 }
Ejemplo n.º 36
0
 private static void SkipAttributes(ModuleReader reader, int count)
 {
     for(int i = 0; i < count; ++i)
         AttributeConstant.Skip(reader);
 }
Ejemplo n.º 37
0
        internal override void Read2(ModuleReader reader, MemberHeader header)
        {
            // Skip the data.
            reader.Skip(header.memberSize);

            // Handle type instance dependencies.
            ReadData();
        }
Ejemplo n.º 38
0
        private static void GetEmbeddedModule64(ModuleReader reader, byte[] ident)
        {
            // Read the endiannes.
            bool big = ident[(int)ElfIdent.EI_DATA] == (int)ElfData.ELFDATA2MSB;

            // Read the header.
            Elf64_Ehdr header = new Elf64_Ehdr();

            header.Read(reader, big);

            // Reject files without section names.
            if (header.e_shstrndex == (int)ElfSectionNumber.SHN_UNDEF)
            {
                throw new ModuleException("Unsupported elfs without section names");
            }

            // Read the "section names" section.
            reader.SetPosition(header.e_shoff + (ulong)header.e_shstrndex * header.e_shentsize);
            Elf64_Shdr namesHeader = new Elf64_Shdr();

            namesHeader.Read(reader, big);

            // Reject files without real section names.
            if (namesHeader.sh_size == 0)
            {
                throw new ModuleException("This elf doesn't have section names.");
            }

            // Read the name table.
            byte[] nameTable;
            reader.SetPosition(namesHeader.sh_offset);
            reader.Read(out nameTable, (int)namesHeader.sh_size);

            // Move to the section header table.
            reader.SetPosition(header.e_shoff);

            // Read the section until hit '.cbm'.
            Elf64_Shdr    sectionHeader = new Elf64_Shdr();
            bool          found         = false;
            StringBuilder builder       = new StringBuilder();

            for (int i = 0; i < header.e_shnum; ++i)
            {
                // Read the section header.
                sectionHeader.Read(reader, big);

                // Check the section name.
                if (sectionHeader.sh_name >= nameTable.Length)
                {
                    throw new ModuleException("Invalid section name.");
                }

                // Build the section name.
                builder.Length = 0;
                int pos = (int)sectionHeader.sh_name;
                while (nameTable[pos] != 0)
                {
                    builder.Append((char)nameTable[pos++]);
                }
                string sectionName = builder.ToString();

                // Compare the section name.
                if (sectionName == ".cbm")
                {
                    found = true;
                    break;
                }

                // Skip the extra data.
                reader.Skip(header.e_shentsize - Elf64_Shdr.Size);
            }

            // Make sure the section was found.
            if (!found)
            {
                throw new ModuleException("The elf doesn't have a chela module.");
            }

            // Make sure the section type is PROGBITS.
            if (sectionHeader.sh_type != (int)ElfSectionType.SHT_PROGBITS)
            {
                throw new ModuleException("The elf section that can have the module is not supported.");
            }

            // Move to the section offset.
            reader.SetPosition(sectionHeader.sh_offset);
        }
Ejemplo n.º 39
0
 internal override void Read(ModuleReader reader, MemberHeader header)
 {
     // Read the functions into the member list.
     memberList = new List<Function> ();
     int numfunctions = (int)header.memberSize/4;
     for(int i = 0; i < numfunctions; ++i)
         memberList.Add((Function)GetModule().GetMember(reader.ReadUInt()));
 }
Ejemplo n.º 40
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal type name and register it.
            TypeNameMember typeName = new TypeNameMember(module);
            module.RegisterMember(typeName);

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

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 41
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            PropertyVariable prop = new PropertyVariable(module);
            module.RegisterMember(prop);

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

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Ejemplo n.º 42
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 number of indices.
            int numIndices = reader.ReadByte();
            if(numIndices > 0)
                indices = new IChelaType[numIndices];

            // Read the indices.
            for(int i = 0; i < numIndices; ++i)
                indices[i] = module.GetType(reader.ReadUInt());

            // Read the get accessor.
            getAccessor = (Function)module.GetMember(reader.ReadUInt());

            // Read the set accessor.
            setAccessor = (Function)module.GetMember(reader.ReadUInt());
        }
Ejemplo n.º 43
0
        private static void GetEmbeddedModule64(ModuleReader reader, byte[] ident)
        {
            // Read the endiannes.
            bool big = ident[(int)ElfIdent.EI_DATA] == (int)ElfData.ELFDATA2MSB;

            // Read the header.
            Elf64_Ehdr header = new Elf64_Ehdr();
            header.Read(reader, big);

            // Reject files without section names.
            if(header.e_shstrndex == (int)ElfSectionNumber.SHN_UNDEF)
                throw new ModuleException("Unsupported elfs without section names");

            // Read the "section names" section.
            reader.SetPosition(header.e_shoff + (ulong)header.e_shstrndex*header.e_shentsize);
            Elf64_Shdr namesHeader = new Elf64_Shdr();
            namesHeader.Read(reader, big);

            // Reject files without real section names.
            if(namesHeader.sh_size == 0)
                throw new ModuleException("This elf doesn't have section names.");

            // Read the name table.
            byte[] nameTable;
            reader.SetPosition(namesHeader.sh_offset);
            reader.Read(out nameTable, (int)namesHeader.sh_size);

            // Move to the section header table.
            reader.SetPosition(header.e_shoff);

            // Read the section until hit '.cbm'.
            Elf64_Shdr sectionHeader = new Elf64_Shdr();
            bool found = false;
            StringBuilder builder = new StringBuilder();
            for(int i = 0; i < header.e_shnum; ++i)
            {
                // Read the section header.
                sectionHeader.Read(reader, big);

                // Check the section name.
                if(sectionHeader.sh_name >= nameTable.Length)
                    throw new ModuleException("Invalid section name.");

                // Build the section name.
                builder.Length = 0;
                int pos = (int)sectionHeader.sh_name;
                while(nameTable[pos] != 0)
                    builder.Append((char)nameTable[pos++]);
                string sectionName = builder.ToString();

                // Compare the section name.
                if(sectionName == ".cbm")
                {
                    found = true;
                    break;
                }

                // Skip the extra data.
                reader.Skip(header.e_shentsize - Elf64_Shdr.Size);
            }

            // Make sure the section was found.
            if(!found)
                throw new ModuleException("The elf doesn't have a chela module.");

            // Make sure the section type is PROGBITS.
            if(sectionHeader.sh_type != (int)ElfSectionType.SHT_PROGBITS)
                throw new ModuleException("The elf section that can have the module is not supported.");

            // Move to the section offset.
            reader.SetPosition(sectionHeader.sh_offset);
        }