public void ConvertFromHndzTaperedI(HndzITaperedProfile profile, HndzStructuralMaterial material)
 {
     Name       = profile.Name;
     Length     = 1;
     LengthType = LengthTypeEnum.Relative;
     StartSection.ConvertFromHndzIProfile(profile.StartProfile, material);
     EndSection.ConvertFromHndzIProfile(profile.EndProfile, material);
 }
        public HndzITaperedProfile ConvertToHndzTaperedI(ref HndzStructuralMaterial material)
        {
            HndzITaperedProfile profile = new HndzITaperedProfile();

            profile.Name         = Name;
            profile.StartProfile = StartSection.ConvertToHndzIProfile(ref material);
            profile.EndProfile   = EndSection.ConvertToHndzIProfile(ref material);
            return(profile);
        }
        public override SAPSection GetAssumedSection()
        {
            SAPISection startSection = (SAPISection)StartSection.GetAssumedSection();
            //SAPISection endSection = SAPISection.GetAssumedEndTaperSection(StartSection);
            SAPISection endSection;

            if (Math.Abs(EndSection.Height - startSection.Height) <= 40)
            {
                endSection = (SAPISection)EndSection.GetAssumedSection();
                endSection = (SAPISection)endSection.GetAssumedSection();
            }
            else
            {
                endSection = EndSection;
            }

            StringBuilder nameStr = new StringBuilder();

            nameStr.Append("I ");
            nameStr.Append(startSection.Height * 100);
            nameStr.Append("-");
            nameStr.Append(endSection.Height * 100);
            nameStr.Append("x");
            nameStr.Append(startSection.WebThickness * 100);
            nameStr.Append("-");
            nameStr.Append(endSection.WebThickness * 100);

            nameStr.Append("/");
            nameStr.Append(startSection.TopFlangeWidth * 100);
            nameStr.Append("x");
            nameStr.Append(startSection.TopFlangeThickness * 100);
            nameStr.Append("/");
            nameStr.Append(startSection.BotFlangeWidth * 100);
            nameStr.Append("x");
            nameStr.Append(startSection.BotFlangeThickness * 100);
            if (startSection == null)
            {
                return(null);
            }
            else if (endSection == null)
            {
                endSection = startSection;
            }
            return(new SAPITaperedSection(nameStr.ToString(), startSection, endSection, 1));
        }
Beispiel #4
0
        /// <summary>
        /// Reads the non-custom section with the given header.
        /// </summary>
        /// <param name="Header">The section header.</param>
        /// <returns>The parsed section.</returns>
        protected Section ReadKnownSectionPayload(SectionHeader Header)
        {
            switch (Header.Name.Code)
            {
            case SectionCode.Type:
                return(TypeSection.ReadSectionPayload(Header, this));

            case SectionCode.Import:
                return(ImportSection.ReadSectionPayload(Header, this));

            case SectionCode.Function:
                return(FunctionSection.ReadSectionPayload(Header, this));

            case SectionCode.Table:
                return(TableSection.ReadSectionPayload(Header, this));

            case SectionCode.Memory:
                return(MemorySection.ReadSectionPayload(Header, this));

            case SectionCode.Global:
                return(GlobalSection.ReadSectionPayload(Header, this));

            case SectionCode.Export:
                return(ExportSection.ReadSectionPayload(Header, this));

            case SectionCode.Start:
                return(StartSection.ReadSectionPayload(Header, this));

            case SectionCode.Element:
                return(ElementSection.ReadSectionPayload(Header, this));

            case SectionCode.Code:
                return(CodeSection.ReadSectionPayload(Header, this));

            case SectionCode.Data:
                return(DataSection.ReadSectionPayload(Header, this));

            default:
                return(ReadUnknownSectionPayload(Header));
            }
        }
Beispiel #5
0
            public override ListViewItem GetListViewItem()
            {
                ListViewItem m = new ListViewItem("");

                m.SubItems.Add(Point1.X.ToString("#####0.############"));
                m.SubItems.Add(Point1.Y.ToString("#####0.############"));

                m.SubItems.Add(Point2.X.ToString("#####0.############"));
                m.SubItems.Add(Point2.Y.ToString("#####0.############"));

                m.SubItems.Add(Sine.ToString("#####0.############"));
                m.SubItems.Add(Cosine.ToString("#####0.############"));
                m.SubItems.Add(Distance.ToString("#####0.############"));

                m.SubItems.Add(GotoSection.ToString());
                m.SubItems.Add(StartSection.ToString());
                m.SubItems.Add(KeyPointID.ToString());
                m.SubItems.Add(RespawnID.ToString());
                m.SubItems.Add(HexUtil.GetHexReverse(Unknown));
                return(m);
            }
        // strict parse means all sections must come in order
        public void ParseAsWASM(string filename, bool strict_parse = true)
        {
            if (!BitConverter.IsLittleEndian)
            {
                throw new NotImplementedException("LEB128 implementation only handles little endian systems");
            }

            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                BinaryReader reader = new BinaryReader(fs);
                uint         magic  = reader.ReadUInt32();
                if (magic != MAGIC)
                {
                    throw new Exception("Not a compiled Web Assembly file.");
                }

                uint version = reader.ReadUInt32();
                if (version > SUPPORTED_VERSION)
                {
                    throw new Exception($"Unsupported version. Expected version <= {SUPPORTED_VERSION}, received {version}.");
                }

                int last_parsed_module = int.MinValue;

                /* Read in each module */

                while (true)
                {
                    int id = reader.PeekChar();

                    // EOF
                    if (id == -1)
                    {
                        break;
                    }

                    if (strict_parse && id < last_parsed_module)
                    {
                        throw new Exception("File contains out of order sections.");
                    }
                    last_parsed_module = id;

                    switch (id)
                    {
                    case (int)WebAssemblyModuleID.Custom:
                        if (strict_parse && custom != null)
                        {
                            throw new Exception("File contains a duplicate custom section.");
                        }
                        custom = new CustomSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Type:
                        if (strict_parse && type != null)
                        {
                            throw new Exception("File contains a duplicate type section.");
                        }
                        type = new TypeSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Import:
                        if (strict_parse && import != null)
                        {
                            throw new Exception("File contains a duplicate import section.");
                        }
                        import = new ImportSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Function:
                        if (strict_parse && function != null)
                        {
                            throw new Exception("File contains a duplicate function section.");
                        }
                        function = new FunctionSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Table:
                        if (strict_parse && table != null)
                        {
                            throw new Exception("File contains a duplicate table section.");
                        }
                        table = new TableSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Memory:
                        if (strict_parse && memory != null)
                        {
                            throw new Exception("File contains a duplicate memory section.");
                        }
                        memory = new MemorySection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Global:
                        if (strict_parse && global != null)
                        {
                            throw new Exception("File contains a duplicate global section.");
                        }
                        global = new GlobalSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Export:
                        if (strict_parse && export != null)
                        {
                            throw new Exception("File contains a duplicate export section.");
                        }
                        export = new ExportSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Start:
                        if (strict_parse && start != null)
                        {
                            throw new Exception("File contains a duplicate start section.");
                        }
                        start = new StartSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Element:
                        if (strict_parse && element != null)
                        {
                            throw new Exception("File contains a duplicate element section.");
                        }
                        element = new ElementSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Code:
                        if (strict_parse && code != null)
                        {
                            throw new Exception("File contains a duplicate code section.");
                        }
                        code = new CodeSection(reader);
                        break;

                    case (int)WebAssemblyModuleID.Data:
                        if (strict_parse && data != null)
                        {
                            throw new Exception("File contains a duplicate data section.");
                        }
                        data = new DataSection(reader);
                        break;

                    // Error
                    default:
                        throw new Exception($"Unknown section {id}.");
                    }
                }

                /* Additional validation */

                // The lengths of vectors produced by the (possibly empty) function and code section must match up.
                if ((function != null && code == null) || (function == null && code != null))
                {
                    throw new Exception("File corrupt. Must include both function and code sections.");
                }
                if (function.types.Length != code.bodies.Length)
                {
                    throw new Exception("File corrupt. Function and code sections do not match up.");
                }

                // TODO: I don't actually check if data overlaps

                // TODO: Validate everything in this list
                // https://webassembly.github.io/spec/core/valid/modules.html
            }
        }