コード例 #1
0
ファイル: AbcDataReader.cs プロジェクト: shhadi/SwfLib
        private AsTraitsInfo[] ReadMutlipleTraits()
        {
            var res = new AsTraitsInfo[ReadU30()];

            for (var i = 0; i < res.Length; i++)
            {
                res[i] = ReadTrait();
            }
            return(res);
        }
コード例 #2
0
ファイル: AbcDataReader.cs プロジェクト: shhadi/SwfLib
        private AsTraitsInfo ReadTrait()
        {
            var r = new AsTraitsInfo {
                Name  = ReadU30(),
                Flags = ReadU8()
            };

            switch (r.Kind)
            {
            case AsTraitKind.Slot:
            case AsTraitKind.Const:
                r.Slot.SlotId     = ReadU30();
                r.Slot.TypeName   = ReadU30();
                r.Slot.ValueIndex = ReadU30();
                if (r.Slot.ValueIndex != 0)
                {
                    r.Slot.ValueKind = (AsConstantKind)ReadU8();
                }
                else
                {
                    r.Slot.ValueKind = AsConstantKind.Void;
                }
                break;

            case AsTraitKind.Class:
                r.Class.SlotId = ReadU30();
                r.Class.Class  = ReadU30();
                break;

            case AsTraitKind.Function:
                r.Function.SlotId   = ReadU30();
                r.Function.Function = ReadU30();
                break;

            case AsTraitKind.Method:
            case AsTraitKind.Getter:
            case AsTraitKind.Setter:
                r.Method.DispId = ReadU30();
                r.Method.Method = ReadU30();
                break;

            default:
                throw new Exception("Unknown trait kind");
            }
            if (r.HasMetadata)
            {
                r.Metadata = ReadMultipleU30();
            }
            return(r);
        }
コード例 #3
0
ファイル: AbcDataWriter.cs プロジェクト: shhadi/SwfLib
        private void WriteTrait(AsTraitsInfo trait)
        {
            WriteU30(trait.Name);
            WriteU8(trait.Flags);
            switch (trait.Kind)
            {
            case AsTraitKind.Slot:
            case AsTraitKind.Const:
                WriteU30(trait.Slot.SlotId);
                WriteU30(trait.Slot.TypeName);
                WriteU30(trait.Slot.ValueIndex);
                if (trait.Slot.ValueIndex != 0)
                {
                    WriteU8((byte)trait.Slot.ValueKind);
                }
                break;

            case AsTraitKind.Class:
                WriteU30(trait.Class.SlotId);
                WriteU30(trait.Class.Class);
                break;

            case AsTraitKind.Function:
                WriteU30(trait.Function.SlotId);
                WriteU30(trait.Function.Function);
                break;

            case AsTraitKind.Method:
            case AsTraitKind.Getter:
            case AsTraitKind.Setter:
                WriteU30(trait.Method.DispId);
                WriteU30(trait.Method.Method);
                break;

            default:
                throw new Exception("Unknown trait kind");
            }
            if (trait.HasMetadata)
            {
                WriteMutipleU30(trait.Metadata);
            }
        }
コード例 #4
0
ファイル: AbcFileLoader.cs プロジェクト: liwq-net/SwfLib
        private AbcTrait GetTrait(AsTraitsInfo traitInfo)
        {
            AbcTrait trait;
            switch (traitInfo.Kind) {
                case AsTraitKind.Const:
                    trait = new AbcConstTrait {
                        SlotId = traitInfo.Slot.SlotId,
                        TypeName = GetMultiname(traitInfo.Slot.TypeName, AbcMultiname.Any),
                        Value = GetConstantValue(traitInfo.Slot.ValueKind, traitInfo.Slot.ValueIndex)
                    };
                    break;
                case AsTraitKind.Slot:
                    trait = new AbcSlotTrait {
                        SlotId = traitInfo.Slot.SlotId,
                        TypeName = GetMultiname(traitInfo.Slot.TypeName, AbcMultiname.Any),
                        Value = GetConstantValue(traitInfo.Slot.ValueKind, traitInfo.Slot.ValueIndex)
                    };
                    break;
                case AsTraitKind.Class:
                    trait = new AbcClassTrait {
                        SlotId = traitInfo.Class.SlotId,
                        Class = GetClass(traitInfo.Class.Class)
                    };
                    break;
                case AsTraitKind.Function:
                    trait = new AbcFunctionTrait {
                        SlotId = traitInfo.Function.SlotId,
                        Method = GetMethod(traitInfo.Function.Function)
                    };
                    break;
                case AsTraitKind.Method:
                    trait = new AbcMethodTrait {
                        DispId = traitInfo.Method.DispId,
                        Method = GetMethod(traitInfo.Method.Method)
                    };
                    break;
                case AsTraitKind.Getter:
                    trait = new AbcGetterTrait {
                        DispId = traitInfo.Method.DispId,
                        Method = GetMethod(traitInfo.Method.Method)
                    };
                    break;
                case AsTraitKind.Setter:
                    trait = new AbcSetterTrait {
                        DispId = traitInfo.Method.DispId,
                        Method = GetMethod(traitInfo.Method.Method)
                    };
                    break;
                default:
                    throw new Exception("unsupported trait kind " + traitInfo.Kind);
            }

            trait.Name = GetMultiname(traitInfo.Name, null);
            trait.Final = traitInfo.Final;
            trait.Override = traitInfo.Override;

            if (traitInfo.Metadata != null) {
                foreach (var metaIndex in traitInfo.Metadata) {
                    var meta = GetMetadata(metaIndex);
                    trait.Metadata.Add(meta);
                }
            }
            return trait;
        }
コード例 #5
0
ファイル: AbcDataReader.cs プロジェクト: liwq-net/SwfLib
 private AsTraitsInfo ReadTrait()
 {
     var r = new AsTraitsInfo {
         Name = ReadU30(),
         Flags = ReadU8()
     };
     switch (r.Kind) {
         case AsTraitKind.Slot:
         case AsTraitKind.Const:
             r.Slot.SlotId = ReadU30();
             r.Slot.TypeName = ReadU30();
             r.Slot.ValueIndex = ReadU30();
             if (r.Slot.ValueIndex != 0)
                 r.Slot.ValueKind = (AsConstantKind)ReadU8();
             else
                 r.Slot.ValueKind = AsConstantKind.Void;
             break;
         case AsTraitKind.Class:
             r.Class.SlotId = ReadU30();
             r.Class.Class = ReadU30();
             break;
         case AsTraitKind.Function:
             r.Function.SlotId = ReadU30();
             r.Function.Function = ReadU30();
             break;
         case AsTraitKind.Method:
         case AsTraitKind.Getter:
         case AsTraitKind.Setter:
             r.Method.DispId = ReadU30();
             r.Method.Method = ReadU30();
             break;
         default:
             throw new Exception("Unknown trait kind");
     }
     if (r.HasMetadata) {
         r.Metadata = ReadMultipleU30();
     }
     return r;
 }
コード例 #6
0
ファイル: AbcDataReader.cs プロジェクト: liwq-net/SwfLib
 private AsTraitsInfo[] ReadMutlipleTraits()
 {
     var res = new AsTraitsInfo[ReadU30()];
     for (var i = 0; i < res.Length; i++) {
         res[i] = ReadTrait();
     }
     return res;
 }
コード例 #7
0
ファイル: AbcDataWriter.cs プロジェクト: liwq-net/SwfLib
 private void WriteTrait(AsTraitsInfo trait)
 {
     WriteU30(trait.Name);
     WriteU8(trait.Flags);
     switch (trait.Kind) {
         case AsTraitKind.Slot:
         case AsTraitKind.Const:
             WriteU30(trait.Slot.SlotId);
             WriteU30(trait.Slot.TypeName);
             WriteU30(trait.Slot.ValueIndex);
             if (trait.Slot.ValueIndex != 0) {
                 WriteU8((byte)trait.Slot.ValueKind);
             }
             break;
         case AsTraitKind.Class:
             WriteU30(trait.Class.SlotId);
             WriteU30(trait.Class.Class);
             break;
         case AsTraitKind.Function:
             WriteU30(trait.Function.SlotId);
             WriteU30(trait.Function.Function);
             break;
         case AsTraitKind.Method:
         case AsTraitKind.Getter:
         case AsTraitKind.Setter:
             WriteU30(trait.Method.DispId);
             WriteU30(trait.Method.Method);
             break;
         default:
             throw new Exception("Unknown trait kind");
     }
     if (trait.HasMetadata) {
         WriteMutipleU30(trait.Metadata);
     }
 }
コード例 #8
0
ファイル: AbcDataWriter.cs プロジェクト: liwq-net/SwfLib
 private void WriteMultipleTraits(AsTraitsInfo[] traits)
 {
     WriteU30((uint)traits.Length);
     foreach (var trait in traits) {
         WriteTrait(trait);
     }
 }