From 5e74675d99e96141403bbe77c2897ceb13a9cc66 Mon Sep 17 00:00:00 2001 From: PaulusParssinen Date: Thu, 1 Feb 2024 03:06:02 +0200 Subject: [PATCH] Run dotnet format --- Flazzy/ABC/ABCFile.cs | 379 +++-- Flazzy/ABC/AS3Item.cs | 23 +- Flazzy/ABC/ASClass.cs | 59 +- Flazzy/ABC/ASConstantPool.cs | 295 ++-- Flazzy/ABC/ASContainer.cs | 283 ++-- Flazzy/ABC/ASException.cs | 61 +- Flazzy/ABC/ASInstance.cs | 203 ++- Flazzy/ABC/ASMethod.cs | 290 ++-- Flazzy/ABC/ASMethodBody.cs | 117 +- Flazzy/ABC/ASMultiname.cs | 120 +- Flazzy/ABC/ASNamespace.cs | 133 +- Flazzy/ABC/ASNamespaceSet.cs | 119 +- Flazzy/ABC/ASParameter.cs | 105 +- Flazzy/ABC/ASScript.cs | 39 +- Flazzy/ABC/ASTrait.cs | 304 ++-- Flazzy/ABC/AVM2/ASCode.cs | 1383 ++++++++--------- Flazzy/ABC/AVM2/ASMachine.cs | 23 +- Flazzy/ABC/AVM2/Instructions/ASInstruction.cs | 447 +++--- Flazzy/ABC/AVM2/Instructions/ApplyTypeIns.cs | 41 +- .../AVM2/Instructions/Arithmetic/AddIIns.cs | 19 +- .../AVM2/Instructions/Arithmetic/AddIns.cs | 19 +- .../Instructions/Arithmetic/Computation.cs | 87 +- .../Instructions/Arithmetic/DecrementIIns.cs | 43 +- .../Instructions/Arithmetic/DecrementIns.cs | 43 +- .../AVM2/Instructions/Arithmetic/DivideIns.cs | 19 +- .../AVM2/Instructions/Arithmetic/EqualsIns.cs | 19 +- .../Arithmetic/GreaterEqualsIns.cs | 19 +- .../Instructions/Arithmetic/GreaterThanIns.cs | 19 +- .../ABC/AVM2/Instructions/Arithmetic/InIns.cs | 39 +- .../Instructions/Arithmetic/IncrementIIns.cs | 43 +- .../Instructions/Arithmetic/IncrementIns.cs | 43 +- .../Instructions/Arithmetic/IsTypeLateIns.cs | 39 +- .../Instructions/Arithmetic/LessEqualsIns.cs | 19 +- .../Instructions/Arithmetic/LessThanIns.cs | 19 +- .../AVM2/Instructions/Arithmetic/ModuloIns.cs | 19 +- .../Instructions/Arithmetic/MultiplyIIns.cs | 19 +- .../Instructions/Arithmetic/MultiplyIns.cs | 19 +- .../Instructions/Arithmetic/NegateIIns.cs | 43 +- .../AVM2/Instructions/Arithmetic/NegateIns.cs | 43 +- .../Arithmetic/StrictEqualsIns.cs | 25 +- .../Instructions/Arithmetic/SubtractIIns.cs | 19 +- .../Instructions/Arithmetic/SubtractIns.cs | 19 +- Flazzy/ABC/AVM2/Instructions/AsTypeIns.cs | 69 +- Flazzy/ABC/AVM2/Instructions/AsTypeLateIns.cs | 39 +- .../Bit Manipulation/BitAndIns.cs | 49 +- .../Bit Manipulation/BitNotIns.cs | 43 +- .../Instructions/Bit Manipulation/BitOrIns.cs | 49 +- .../Bit Manipulation/BitXorIns.cs | 49 +- .../Bit Manipulation/LShiftIns.cs | 49 +- .../Bit Manipulation/RShiftIns.cs | 49 +- .../Bit Manipulation/URShiftIns.cs | 39 +- Flazzy/ABC/AVM2/Instructions/CallIns.cs | 73 +- Flazzy/ABC/AVM2/Instructions/CallMethodIns.cs | 89 +- .../ABC/AVM2/Instructions/CallPropLexIns.cs | 93 +- .../ABC/AVM2/Instructions/CallPropVoidIns.cs | 87 +- .../ABC/AVM2/Instructions/CallPropertyIns.cs | 97 +- Flazzy/ABC/AVM2/Instructions/CallStaticIns.cs | 91 +- Flazzy/ABC/AVM2/Instructions/CallSuperIns.cs | 93 +- .../ABC/AVM2/Instructions/CallSuperVoidIns.cs | 93 +- .../ABC/AVM2/Instructions/CheckFilterIns.cs | 37 +- Flazzy/ABC/AVM2/Instructions/ConstructIns.cs | 71 +- .../ABC/AVM2/Instructions/ConstructPropIns.cs | 97 +- .../AVM2/Instructions/ConstructSuperIns.cs | 61 +- .../Containers/IPropertyContainer.cs | 11 +- .../Control Transfer/IfEqualIns.cs | 31 +- .../Control Transfer/IfFalseIns.cs | 29 +- .../Control Transfer/IfGreaterEqualIns.cs | 31 +- .../Control Transfer/IfGreaterThanIns.cs | 31 +- .../Control Transfer/IfLessEqualIns.cs | 31 +- .../Control Transfer/IfLessThanIns.cs | 31 +- .../Control Transfer/IfNotEqualIns.cs | 31 +- .../Control Transfer/IfNotGreaterEqualIns.cs | 31 +- .../Control Transfer/IfNotGreaterThanIns.cs | 31 +- .../Control Transfer/IfNotLessEqualIns.cs | 31 +- .../Control Transfer/IfNotLessThanIns.cs | 31 +- .../Control Transfer/IfStrictEqualIns.cs | 33 +- .../Control Transfer/IfStrictNotEqualIns.cs | 33 +- .../Control Transfer/IfTrueIns.cs | 25 +- .../Instructions/Control Transfer/JumpIns.cs | 25 +- .../Instructions/Control Transfer/Jumper.cs | 119 +- Flazzy/ABC/AVM2/Instructions/DebugFileIns.cs | 43 +- Flazzy/ABC/AVM2/Instructions/DebugIns.cs | 65 +- Flazzy/ABC/AVM2/Instructions/DebugLineIns.cs | 41 +- .../AVM2/Instructions/DeletePropertyIns.cs | 71 +- Flazzy/ABC/AVM2/Instructions/DupIns.cs | 29 +- Flazzy/ABC/AVM2/Instructions/DxnsIns.cs | 25 +- Flazzy/ABC/AVM2/Instructions/DxnsLateIns.cs | 27 +- Flazzy/ABC/AVM2/Instructions/Enums/OPCode.cs | 1159 +++++++------- Flazzy/ABC/AVM2/Instructions/EscXAttrIns.cs | 43 +- Flazzy/ABC/AVM2/Instructions/EscXElemIns.cs | 37 +- .../AVM2/Instructions/FindPropStrictIns.cs | 69 +- .../ABC/AVM2/Instructions/FindPropertyIns.cs | 69 +- .../AVM2/Instructions/GetDescendantsIns.cs | 71 +- .../AVM2/Instructions/GetGlobalScopeIns.cs | 27 +- Flazzy/ABC/AVM2/Instructions/GetLexIns.cs | 59 +- .../ABC/AVM2/Instructions/GetPropertyIns.cs | 71 +- .../AVM2/Instructions/GetScopeObjectIns.cs | 57 +- Flazzy/ABC/AVM2/Instructions/GetSlotIns.cs | 67 +- Flazzy/ABC/AVM2/Instructions/GetSuperIns.cs | 71 +- Flazzy/ABC/AVM2/Instructions/HasNext2Ins.cs | 65 +- Flazzy/ABC/AVM2/Instructions/HasNextIns.cs | 39 +- .../ABC/AVM2/Instructions/InitPropertyIns.cs | 63 +- Flazzy/ABC/AVM2/Instructions/InstanceOfIns.cs | 39 +- Flazzy/ABC/AVM2/Instructions/LabelIns.cs | 13 +- .../ABC/AVM2/Instructions/LookUpSwitchIns.cs | 81 +- .../ABC/AVM2/Instructions/NewActivationIns.cs | 27 +- Flazzy/ABC/AVM2/Instructions/NewArrayIns.cs | 71 +- Flazzy/ABC/AVM2/Instructions/NewCatchIns.cs | 57 +- Flazzy/ABC/AVM2/Instructions/NewClassIns.cs | 69 +- .../ABC/AVM2/Instructions/NewFunctionIns.cs | 59 +- Flazzy/ABC/AVM2/Instructions/NewObjectIns.cs | 71 +- Flazzy/ABC/AVM2/Instructions/NextNameIns.cs | 39 +- Flazzy/ABC/AVM2/Instructions/NextValueIns.cs | 39 +- Flazzy/ABC/AVM2/Instructions/NopIns.cs | 13 +- Flazzy/ABC/AVM2/Instructions/NotIns.cs | 45 +- Flazzy/ABC/AVM2/Instructions/PopIns.cs | 27 +- Flazzy/ABC/AVM2/Instructions/PopScopeIns.cs | 19 +- Flazzy/ABC/AVM2/Instructions/PushScopeIns.cs | 29 +- .../ABC/AVM2/Instructions/PushUndefinedIns.cs | 27 +- Flazzy/ABC/AVM2/Instructions/PushWithIns.cs | 29 +- .../Register Management/DecLocalIIns.cs | 31 +- .../Register Management/DecLocalIns.cs | 31 +- .../Register Management/GetLocal0Ins.cs | 21 +- .../Register Management/GetLocal1Ins.cs | 21 +- .../Register Management/GetLocal2Ins.cs | 21 +- .../Register Management/GetLocal3Ins.cs | 21 +- .../Register Management/GetLocalIns.cs | 19 +- .../Register Management/IncLocalIIns.cs | 31 +- .../Register Management/IncLocalIns.cs | 31 +- .../Register Management/KillIns.cs | 25 +- .../Instructions/Register Management/Local.cs | 221 ++- .../Register Management/SetLocal0Ins.cs | 21 +- .../Register Management/SetLocal1Ins.cs | 21 +- .../Register Management/SetLocal2Ins.cs | 21 +- .../Register Management/SetLocal3Ins.cs | 21 +- .../Register Management/SetLocalIns.cs | 19 +- .../ABC/AVM2/Instructions/ReturnValueIns.cs | 27 +- Flazzy/ABC/AVM2/Instructions/ReturnVoidIns.cs | 13 +- .../ABC/AVM2/Instructions/SetPropertyIns.cs | 63 +- Flazzy/ABC/AVM2/Instructions/SetSlotIns.cs | 59 +- Flazzy/ABC/AVM2/Instructions/SetSuperIns.cs | 63 +- .../Stack Management/Primitive.cs | 101 +- .../Stack Management/PushByteIns.cs | 53 +- .../Stack Management/PushDoubleIns.cs | 73 +- .../Stack Management/PushFalseIns.cs | 23 +- .../Stack Management/PushIntIns.cs | 73 +- .../Stack Management/PushNaNIns.cs | 21 +- .../Stack Management/PushNullIns.cs | 21 +- .../Stack Management/PushShortIns.cs | 53 +- .../Stack Management/PushStringIns.cs | 83 +- .../Stack Management/PushTrueIns.cs | 21 +- .../Stack Management/PushUIntIns.cs | 73 +- Flazzy/ABC/AVM2/Instructions/SwapIns.cs | 41 +- Flazzy/ABC/AVM2/Instructions/ThrowIns.cs | 27 +- .../Type Conversion/CoerceAIns.cs | 37 +- .../Instructions/Type Conversion/CoerceIns.cs | 69 +- .../Type Conversion/CoerceSIns.cs | 43 +- .../Type Conversion/ConvertBIns.cs | 47 +- .../Type Conversion/ConvertDIns.cs | 43 +- .../Type Conversion/ConvertIIns.cs | 43 +- .../Type Conversion/ConvertOIns.cs | 37 +- .../Type Conversion/ConvertSIns.cs | 45 +- .../Type Conversion/ConvertUIns.cs | 43 +- Flazzy/ABC/AVM2/Instructions/TypeOfIns.cs | 37 +- Flazzy/ABC/Enums/ClassFlags.cs | 49 +- Flazzy/ABC/Enums/ConstantKind.cs | 27 +- Flazzy/ABC/Enums/MethodFlags.cs | 27 +- Flazzy/ABC/Enums/MultinameKind.cs | 29 +- Flazzy/ABC/Enums/NamespaceKind.cs | 21 +- Flazzy/ABC/Enums/TraitAttributes.cs | 19 +- Flazzy/ABC/Enums/TraitKind.cs | 21 +- Flazzy/ABC/IPoolConstant.cs | 9 +- Flazzy/ABC/Multinames/IMultiname.cs | 15 +- Flazzy/ABC/Multinames/IMultinameL.cs | 11 +- Flazzy/ABC/Multinames/IQName.cs | 15 +- Flazzy/ABC/Multinames/IRTQName.cs | 11 +- Flazzy/ABC/Traits/IClassTrait.cs | 11 +- Flazzy/ABC/Traits/IFunctionTrait.cs | 11 +- Flazzy/ABC/Traits/IMethodGSTrait.cs | 13 +- Flazzy/ABC/Traits/ISlotConstantTrait.cs | 19 +- Flazzy/CompressionKind.cs | 31 +- Flazzy/FlashItem.cs | 27 +- Flazzy/IO/Compression/ZLib.cs | 21 +- Flazzy/IO/FlashReader.cs | 417 +++-- Flazzy/IO/FlashWriter.cs | 399 +++-- Flazzy/Records/FrameRecord.cs | 43 +- Flazzy/Records/HeaderRecord.cs | 83 +- Flazzy/ShockwaveFlash.cs | 363 +++-- Flazzy/Tags/DefineBinaryDataTag.cs | 61 +- Flazzy/Tags/DefineBitsJPEG3.cs | 95 +- Flazzy/Tags/DefineBitsLosslessTag.cs | 131 +- Flazzy/Tags/DefineFontNameTag.cs | 59 +- Flazzy/Tags/DefineSoundTag.cs | 89 +- Flazzy/Tags/DoABCTag.cs | 65 +- Flazzy/Tags/EndTag.cs | 25 +- Flazzy/Tags/Enums/BitmapFormat.cs | 23 +- Flazzy/Tags/Enums/FlashEdition.cs | 21 +- Flazzy/Tags/Enums/FlashProduct.cs | 15 +- Flazzy/Tags/Enums/ImageFormat.cs | 13 +- Flazzy/Tags/Enums/TagKind.cs | 141 +- Flazzy/Tags/ExportAssetsTag.cs | 77 +- Flazzy/Tags/FileAttributesTag.cs | 85 +- Flazzy/Tags/FrameLabelTag.cs | 39 +- Flazzy/Tags/ImageTag.cs | 53 +- Flazzy/Tags/MetadataTag.cs | 33 +- Flazzy/Tags/ScriptLimitsTag.cs | 51 +- Flazzy/Tags/SetBackgroundColorTag.cs | 57 +- Flazzy/Tags/ShowFrameTag.cs | 25 +- Flazzy/Tags/SymbolClassTag.cs | 79 +- Flazzy/Tags/TagItem.cs | 43 +- Flazzy/Tags/UnknownTag.cs | 43 +- Flazzy/Tools/FlashCrypto.cs | 4 +- 212 files changed, 7431 insertions(+), 7639 deletions(-) diff --git a/Flazzy/ABC/ABCFile.cs b/Flazzy/ABC/ABCFile.cs index 0ebc73c..eaec65e 100644 --- a/Flazzy/ABC/ABCFile.cs +++ b/Flazzy/ABC/ABCFile.cs @@ -1,240 +1,239 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ABCFile : FlashItem, IDisposable { - public class ABCFile : FlashItem, IDisposable - { - private readonly FlashReader _input; - private readonly Dictionary> _classByQNameCache; - private readonly Dictionary _instanceByConstructorCache; + private readonly FlashReader _input; + private readonly Dictionary> _classByQNameCache; + private readonly Dictionary _instanceByConstructorCache; - public List Methods { get; } - public List Metadata { get; } - public List Instances { get; } - public List Classes { get; } - public List Scripts { get; } - public List MethodBodies { get; } + public List Methods { get; } + public List Metadata { get; } + public List Instances { get; } + public List Classes { get; } + public List Scripts { get; } + public List MethodBodies { get; } - public ASConstantPool Pool { get; } - public Version Version { get; set; } + public ASConstantPool Pool { get; } + public Version Version { get; set; } - protected override string DebuggerDisplay => "Version: " + Version; + protected override string DebuggerDisplay => "Version: " + Version; - public ABCFile() - { - _classByQNameCache = new Dictionary>(); - _instanceByConstructorCache = new Dictionary(); - - Methods = new List(); - Metadata = new List(); - Instances = new List(); - Classes = new List(); - Scripts = new List(); - MethodBodies = new List(); - } - public ABCFile(byte[] data) - : this(new FlashReader(data)) - { } - public ABCFile(FlashReader input) - : this() - { - _input = input; + public ABCFile() + { + _classByQNameCache = new Dictionary>(); + _instanceByConstructorCache = new Dictionary(); + + Methods = new List(); + Metadata = new List(); + Instances = new List(); + Classes = new List(); + Scripts = new List(); + MethodBodies = new List(); + } + public ABCFile(byte[] data) + : this(new FlashReader(data)) + { } + public ABCFile(FlashReader input) + : this() + { + _input = input; - ushort minor = input.ReadUInt16(); - ushort major = input.ReadUInt16(); - Version = new Version(major, minor); - Pool = new ASConstantPool(this, input); + ushort minor = input.ReadUInt16(); + ushort major = input.ReadUInt16(); + Version = new Version(major, minor); + Pool = new ASConstantPool(this, input); - PopulateList(Methods, ReadMethod); - PopulateList(Metadata, ReadMetadata); - PopulateList(Instances, ReadInstance); - _classByQNameCache.EnsureCapacity(Instances.Count); - _instanceByConstructorCache.EnsureCapacity(Instances.Count); + PopulateList(Methods, ReadMethod); + PopulateList(Metadata, ReadMetadata); + PopulateList(Instances, ReadInstance); + _classByQNameCache.EnsureCapacity(Instances.Count); + _instanceByConstructorCache.EnsureCapacity(Instances.Count); - PopulateList(Classes, ReadClass, Instances.Count); - PopulateList(Scripts, ReadScript); - PopulateList(MethodBodies, ReadMethodBody); + PopulateList(Classes, ReadClass, Instances.Count); + PopulateList(Scripts, ReadScript); + PopulateList(MethodBodies, ReadMethodBody); - _classByQNameCache.TrimExcess(); - _instanceByConstructorCache.TrimExcess(); - } + _classByQNameCache.TrimExcess(); + _instanceByConstructorCache.TrimExcess(); + } - public void ResetCache() + public void ResetCache() + { + _classByQNameCache.Clear(); + _instanceByConstructorCache.Clear(); + foreach (ASClass @class in Classes) { - _classByQNameCache.Clear(); - _instanceByConstructorCache.Clear(); - foreach (ASClass @class in Classes) - { - CacheByNaming(@class); - } - _classByQNameCache.TrimExcess(); - _instanceByConstructorCache.TrimExcess(); + CacheByNaming(@class); } - private void CacheByNaming(ASClass @class) + _classByQNameCache.TrimExcess(); + _instanceByConstructorCache.TrimExcess(); + } + private void CacheByNaming(ASClass @class) + { + if (!string.IsNullOrWhiteSpace(@class.Instance.Constructor.Name)) { - if (!string.IsNullOrWhiteSpace(@class.Instance.Constructor.Name)) - { - string prefix = null; - if (!string.IsNullOrWhiteSpace(@class.QName.Namespace.Name) && !@class.QName.Namespace.Name.StartsWith("_-")) - { - prefix = @class.QName.Namespace.Name + "."; - } - _instanceByConstructorCache.Add(prefix + @class.Instance.Constructor.Name, @class.Instance); - } - - if (!_classByQNameCache.TryGetValue(@class.QName, out List classes)) + string prefix = null; + if (!string.IsNullOrWhiteSpace(@class.QName.Namespace.Name) && !@class.QName.Namespace.Name.StartsWith("_-")) { - classes = new List(); - _classByQNameCache.Add(@class.QName, classes); + prefix = @class.QName.Namespace.Name + "."; } - classes.Add(@class); + _instanceByConstructorCache.Add(prefix + @class.Instance.Constructor.Name, @class.Instance); } - public int AddMethod(ASMethod method, bool recycle = true) + if (!_classByQNameCache.TryGetValue(@class.QName, out List classes)) { - return AddValue(Methods, method, recycle); + classes = new List(); + _classByQNameCache.Add(@class.QName, classes); } - public int AddMetadata(ASMetadata metadata, bool recycle = true) - { - return AddValue(Metadata, metadata, recycle); - } - public int AddClass(ASClass @class, ASInstance instance, bool recycle = true) - { - AddValue(Classes, @class, recycle); - return AddValue(Instances, instance, recycle); - } - public int AddScript(ASScript script, bool recycle = true) - { - return AddValue(Scripts, script, recycle); - } - public int AddMethodBody(ASMethodBody methodBody, bool recycle = true) + classes.Add(@class); + } + + public int AddMethod(ASMethod method, bool recycle = true) + { + return AddValue(Methods, method, recycle); + } + public int AddMetadata(ASMetadata metadata, bool recycle = true) + { + return AddValue(Metadata, metadata, recycle); + } + public int AddClass(ASClass @class, ASInstance instance, bool recycle = true) + { + AddValue(Classes, @class, recycle); + return AddValue(Instances, instance, recycle); + } + public int AddScript(ASScript script, bool recycle = true) + { + return AddValue(Scripts, script, recycle); + } + public int AddMethodBody(ASMethodBody methodBody, bool recycle = true) + { + if (methodBody.Method != null) { - if (methodBody.Method != null) - { - methodBody.Method.Body = methodBody; - } - return AddValue(MethodBodies, methodBody, recycle); + methodBody.Method.Body = methodBody; } - protected virtual int AddValue(List valueList, T value, bool recycle) + return AddValue(MethodBodies, methodBody, recycle); + } + protected virtual int AddValue(List valueList, T value, bool recycle) + { + int index = recycle ? valueList.IndexOf(value) : -1; + if (index == -1) { - int index = recycle ? valueList.IndexOf(value) : -1; - if (index == -1) - { - index = (valueList.Count); - valueList.Add(value); - } - return index; + index = (valueList.Count); + valueList.Add(value); } + return index; + } - public ASClass GetClass(ASMultiname multiname) => GetClasses(multiname).FirstOrDefault(); - public ASClass GetClass(string qualifiedName) => GetClass(GetMultiname(qualifiedName)); + public ASClass GetClass(ASMultiname multiname) => GetClasses(multiname).FirstOrDefault(); + public ASClass GetClass(string qualifiedName) => GetClass(GetMultiname(qualifiedName)); - public ASInstance GetInstance(ASMultiname multiname) => GetInstances(multiname).FirstOrDefault(); - public ASInstance GetInstance(string qualifiedName) => GetInstance(GetMultiname(qualifiedName)); + public ASInstance GetInstance(ASMultiname multiname) => GetInstances(multiname).FirstOrDefault(); + public ASInstance GetInstance(string qualifiedName) => GetInstance(GetMultiname(qualifiedName)); - public IEnumerable GetClasses(ASMultiname multiname) + public IEnumerable GetClasses(ASMultiname multiname) + { + if (multiname == null) { - if (multiname == null) - { - return Enumerable.Empty(); - } - return _classByQNameCache.GetValueOrDefault(multiname) ?? Enumerable.Empty(); + return Enumerable.Empty(); } - public IEnumerable GetClasses(string qualifiedName) => GetClasses(GetMultiname(qualifiedName)); + return _classByQNameCache.GetValueOrDefault(multiname) ?? Enumerable.Empty(); + } + public IEnumerable GetClasses(string qualifiedName) => GetClasses(GetMultiname(qualifiedName)); - public IEnumerable GetInstances(ASMultiname multiname) => GetClasses(multiname).Select(c => c.Instance); - public IEnumerable GetInstances(string qualifiedName) => GetInstances(GetMultiname(qualifiedName)); + public IEnumerable GetInstances(ASMultiname multiname) => GetClasses(multiname).Select(c => c.Instance); + public IEnumerable GetInstances(string qualifiedName) => GetInstances(GetMultiname(qualifiedName)); - public ASInstance GetInstanceByConstructor(string constructorName) => _instanceByConstructorCache.GetValueOrDefault(constructorName); + public ASInstance GetInstanceByConstructor(string constructorName) => _instanceByConstructorCache.GetValueOrDefault(constructorName); - private ASMethod ReadMethod(int index) => new(this, _input); - private ASMetadata ReadMetadata(int index) => new(this, _input); - private ASInstance ReadInstance(int index) => new(this, _input); - private ASClass ReadClass(int index) + private ASMethod ReadMethod(int index) => new(this, _input); + private ASMetadata ReadMetadata(int index) => new(this, _input); + private ASInstance ReadInstance(int index) => new(this, _input); + private ASClass ReadClass(int index) + { + var @class = new ASClass(this, _input) { - var @class = new ASClass(this, _input) - { - InstanceIndex = index - }; - CacheByNaming(@class); - return @class; - } - private ASScript ReadScript(int index) => new(this, _input); - private ASMethodBody ReadMethodBody(int index) => new(this, _input); + InstanceIndex = index + }; + CacheByNaming(@class); + return @class; + } + private ASScript ReadScript(int index) => new(this, _input); + private ASMethodBody ReadMethodBody(int index) => new(this, _input); - private ASMultiname GetMultiname(string qualifiedName) + private ASMultiname GetMultiname(string qualifiedName) + { + foreach (ASMultiname multiname in Pool.GetMultinames(qualifiedName)) { - foreach (ASMultiname multiname in Pool.GetMultinames(qualifiedName)) - { - if (multiname.Kind == MultinameKind.QName) return multiname; - } - return null; + if (multiname.Kind == MultinameKind.QName) return multiname; } - private void PopulateList(List list, Func reader, int count = -1) + return null; + } + private void PopulateList(List list, Func reader, int count = -1) + { + list.Capacity = count < 0 ? _input.ReadInt30() : count; + for (int i = 0; i < list.Capacity; i++) { - list.Capacity = count < 0 ? _input.ReadInt30() : count; - for (int i = 0; i < list.Capacity; i++) - { - T value = reader(i); - list.Add(value); - } + T value = reader(i); + list.Add(value); } + } - public override void WriteTo(FlashWriter output) - { - output.Write((ushort)Version.Minor); - output.Write((ushort)Version.Major); + public override void WriteTo(FlashWriter output) + { + output.Write((ushort)Version.Minor); + output.Write((ushort)Version.Major); - Pool.WriteTo(output); + Pool.WriteTo(output); - WriteTo(output, Methods); - WriteTo(output, Metadata); - WriteTo(output, Instances); - WriteTo(output, Classes, false); - WriteTo(output, Scripts); - WriteTo(output, MethodBodies); - } - private void WriteTo(FlashWriter output, List list, bool writeCount = true) - where T : FlashItem + WriteTo(output, Methods); + WriteTo(output, Metadata); + WriteTo(output, Instances); + WriteTo(output, Classes, false); + WriteTo(output, Scripts); + WriteTo(output, MethodBodies); + } + private void WriteTo(FlashWriter output, List list, bool writeCount = true) + where T : FlashItem + { + if (writeCount) { - if (writeCount) - { - output.WriteInt30(list.Count); - } - for (int i = 0; i < list.Count; i++) - { - FlashItem item = list[i]; - item.WriteTo(output); - } + output.WriteInt30(list.Count); } - - public void Dispose() + for (int i = 0; i < list.Count; i++) { - Dispose(true); + FlashItem item = list[i]; + item.WriteTo(output); } - protected virtual void Dispose(bool disposing) + } + + public void Dispose() + { + Dispose(true); + } + protected virtual void Dispose(bool disposing) + { + if (disposing) { - if (disposing) - { - _input.Dispose(); - _classByQNameCache.Clear(); - _instanceByConstructorCache.Clear(); - - Methods.Clear(); - Metadata.Clear(); - Instances.Clear(); - Classes.Clear(); - Scripts.Clear(); - MethodBodies.Clear(); - - Pool.Integers.Clear(); - Pool.UIntegers.Clear(); - Pool.Doubles.Clear(); - Pool.Strings.Clear(); - Pool.Namespaces.Clear(); - Pool.NamespaceSets.Clear(); - Pool.Multinames.Clear(); - } + _input.Dispose(); + _classByQNameCache.Clear(); + _instanceByConstructorCache.Clear(); + + Methods.Clear(); + Metadata.Clear(); + Instances.Clear(); + Classes.Clear(); + Scripts.Clear(); + MethodBodies.Clear(); + + Pool.Integers.Clear(); + Pool.UIntegers.Clear(); + Pool.Doubles.Clear(); + Pool.Strings.Clear(); + Pool.Namespaces.Clear(); + Pool.NamespaceSets.Clear(); + Pool.Multinames.Clear(); } } } \ No newline at end of file diff --git a/Flazzy/ABC/AS3Item.cs b/Flazzy/ABC/AS3Item.cs index fbb86bc..eab6d1f 100644 --- a/Flazzy/ABC/AS3Item.cs +++ b/Flazzy/ABC/AS3Item.cs @@ -1,17 +1,16 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public abstract class AS3Item : FlashItem { - public abstract class AS3Item : FlashItem - { - public ABCFile ABC { get; } + public ABCFile ABC { get; } - public AS3Item(ABCFile abc) - { - ABC = abc; - } + public AS3Item(ABCFile abc) + { + ABC = abc; + } - public virtual string ToAS3() - { - throw new NotSupportedException(); - } + public virtual string ToAS3() + { + throw new NotSupportedException(); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASClass.cs b/Flazzy/ABC/ASClass.cs index d680817..9b4409a 100644 --- a/Flazzy/ABC/ASClass.cs +++ b/Flazzy/ABC/ASClass.cs @@ -1,40 +1,39 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASClass : ASContainer { - public class ASClass : ASContainer - { - internal int InstanceIndex { get; set; } - public ASInstance Instance => ABC.Instances[InstanceIndex]; + internal int InstanceIndex { get; set; } + public ASInstance Instance => ABC.Instances[InstanceIndex]; - public int ConstructorIndex { get; set; } - public ASMethod Constructor => ABC.Methods[ConstructorIndex]; + public int ConstructorIndex { get; set; } + public ASMethod Constructor => ABC.Methods[ConstructorIndex]; - public override bool IsStatic => true; - public override ASMultiname QName => Instance.QName; - protected override string DebuggerDisplay => ToAS3(); + public override bool IsStatic => true; + public override ASMultiname QName => Instance.QName; + protected override string DebuggerDisplay => ToAS3(); - public ASClass(ABCFile abc) - : base(abc) - { } - public ASClass(ABCFile abc, FlashReader input) - : base(abc) - { - ConstructorIndex = input.ReadInt30(); - Constructor.IsConstructor = true; - Constructor.Container = this; + public ASClass(ABCFile abc) + : base(abc) + { } + public ASClass(ABCFile abc, FlashReader input) + : base(abc) + { + ConstructorIndex = input.ReadInt30(); + Constructor.IsConstructor = true; + Constructor.Container = this; - PopulateTraits(input); - } + PopulateTraits(input); + } - public override string ToAS3() - { - return Instance.ToAS3(); - } - public override void WriteTo(FlashWriter output) - { - output.WriteInt30(ConstructorIndex); - base.WriteTo(output); - } + public override string ToAS3() + { + return Instance.ToAS3(); + } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(ConstructorIndex); + base.WriteTo(output); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASConstantPool.cs b/Flazzy/ABC/ASConstantPool.cs index 27acaf9..77e901a 100644 --- a/Flazzy/ABC/ASConstantPool.cs +++ b/Flazzy/ABC/ASConstantPool.cs @@ -1,92 +1,92 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +/// +/// Represents a block of array-based entries that reflect the constants used by all the methods. +/// +public class ASConstantPool : FlashItem { - /// - /// Represents a block of array-based entries that reflect the constants used by all the methods. - /// - public class ASConstantPool : FlashItem - { - private readonly Dictionary _multinamesIndicesCache; - private readonly Dictionary> _multinamesByNameCache; + private readonly Dictionary _multinamesIndicesCache; + private readonly Dictionary> _multinamesByNameCache; - private readonly FlashReader _input; + private readonly FlashReader _input; - public ABCFile ABC { get; } + public ABCFile ABC { get; } - public List Integers { get; } - public List UIntegers { get; } - public List Doubles { get; } - public List Strings { get; } - public List Namespaces { get; } - public List NamespaceSets { get; } - public List Multinames { get; } + public List Integers { get; } + public List UIntegers { get; } + public List Doubles { get; } + public List Strings { get; } + public List Namespaces { get; } + public List NamespaceSets { get; } + public List Multinames { get; } - public ASConstantPool() - { - _multinamesIndicesCache = new Dictionary(); - _multinamesByNameCache = new Dictionary>(); - - Integers = new List(); - UIntegers = new List(); - Doubles = new List(); - Strings = new List(); - Namespaces = new List(); - NamespaceSets = new List(); - Multinames = new List(); - } - public ASConstantPool(ABCFile abc) - : this() - { - ABC = abc; - } - public ASConstantPool(ABCFile abc, FlashReader input) - : this(abc) - { - _input = input; - - PopulateList(Integers, input.ReadInt30, 0); - PopulateList(UIntegers, input.ReadUInt30, 0); - PopulateList(Doubles, input.ReadDouble, double.NaN); - PopulateList(Strings, input.ReadString, null); - PopulateList(Namespaces, ReadNamespace, null); - PopulateList(NamespaceSets, ReadNamespaceSet, null); - PopulateList(Multinames, ReadMultiname, null); - - _multinamesByNameCache.TrimExcess(); - _multinamesIndicesCache.TrimExcess(); - } + public ASConstantPool() + { + _multinamesIndicesCache = new Dictionary(); + _multinamesByNameCache = new Dictionary>(); + + Integers = new List(); + UIntegers = new List(); + Doubles = new List(); + Strings = new List(); + Namespaces = new List(); + NamespaceSets = new List(); + Multinames = new List(); + } + public ASConstantPool(ABCFile abc) + : this() + { + ABC = abc; + } + public ASConstantPool(ABCFile abc, FlashReader input) + : this(abc) + { + _input = input; + + PopulateList(Integers, input.ReadInt30, 0); + PopulateList(UIntegers, input.ReadUInt30, 0); + PopulateList(Doubles, input.ReadDouble, double.NaN); + PopulateList(Strings, input.ReadString, null); + PopulateList(Namespaces, ReadNamespace, null); + PopulateList(NamespaceSets, ReadNamespaceSet, null); + PopulateList(Multinames, ReadMultiname, null); + + _multinamesByNameCache.TrimExcess(); + _multinamesIndicesCache.TrimExcess(); + } - public object GetConstant(ConstantKind type, int index) + public object GetConstant(ConstantKind type, int index) + { + switch (type) { - switch (type) - { - case ConstantKind.True: return true; - case ConstantKind.False: return false; + case ConstantKind.True: return true; + case ConstantKind.False: return false; - case ConstantKind.Null: - case ConstantKind.Undefined: return null; + case ConstantKind.Null: + case ConstantKind.Undefined: return null; - case ConstantKind.String: return Strings[index]; - case ConstantKind.Double: return Doubles[index]; - case ConstantKind.Integer: return Integers[index]; - case ConstantKind.UInteger: return UIntegers[index]; + case ConstantKind.String: return Strings[index]; + case ConstantKind.Double: return Doubles[index]; + case ConstantKind.Integer: return Integers[index]; + case ConstantKind.UInteger: return UIntegers[index]; - case ConstantKind.Namespace: return Namespaces[index]; + case ConstantKind.Namespace: return Namespaces[index]; - default: return null; - } + default: return null; } + } - public int AddConstant(object value, bool recycle = true) + public int AddConstant(object value, bool recycle = true) + { + switch (Type.GetTypeCode(value.GetType())) { - switch (Type.GetTypeCode(value.GetType())) - { - case TypeCode.Int32: return AddConstant(Integers, (int)value, recycle); - case TypeCode.UInt32: return AddConstant(UIntegers, (uint)value, recycle); - case TypeCode.Double: return AddConstant(Doubles, (double)value, recycle); - case TypeCode.String: return AddConstant(Strings, (string)value, recycle); - default: + case TypeCode.Int32: return AddConstant(Integers, (int)value, recycle); + case TypeCode.UInt32: return AddConstant(UIntegers, (uint)value, recycle); + case TypeCode.Double: return AddConstant(Doubles, (double)value, recycle); + case TypeCode.String: return AddConstant(Strings, (string)value, recycle); + default: { return value switch { @@ -96,101 +96,100 @@ public int AddConstant(object value, bool recycle = true) _ => throw new ArgumentException("The provided value does not belong anywhere in the constant pool.", nameof(value)), }; } - } } - protected virtual int AddConstant(List constants, T value, bool recycle) + } + protected virtual int AddConstant(List constants, T value, bool recycle) + { + int index = (recycle ? constants.IndexOf(value, 1) : -1); + if (index == -1) { - int index = (recycle ? constants.IndexOf(value, 1) : -1); - if (index == -1) - { - constants.Add(value); - index = (constants.Count - 1); - } - return index; + constants.Add(value); + index = (constants.Count - 1); } + return index; + } - public int GetMultinameIndex(string name) - { - return GetMultinameIndices(name).FirstOrDefault(); - } - public ASMultiname GetMultiname(string name) - { - return GetMultinames(name).FirstOrDefault(); - } + public int GetMultinameIndex(string name) + { + return GetMultinameIndices(name).FirstOrDefault(); + } + public ASMultiname GetMultiname(string name) + { + return GetMultinames(name).FirstOrDefault(); + } - public IEnumerable GetMultinameIndices(string name) - { - foreach (ASMultiname multiname in GetMultinames(name)) - { - yield return _multinamesIndicesCache[multiname]; - } - } - public IEnumerable GetMultinames(string name) + public IEnumerable GetMultinameIndices(string name) + { + foreach (ASMultiname multiname in GetMultinames(name)) { - return _multinamesByNameCache.GetValueOrDefault(name) ?? Enumerable.Empty(); + yield return _multinamesIndicesCache[multiname]; } + } + public IEnumerable GetMultinames(string name) + { + return _multinamesByNameCache.GetValueOrDefault(name) ?? Enumerable.Empty(); + } - private ASMultiname ReadMultiname() + private ASMultiname ReadMultiname() + { + ASMultiname multiname = new(this, _input); + if (!string.IsNullOrWhiteSpace(multiname.Name)) { - ASMultiname multiname = new(this, _input); - if (!string.IsNullOrWhiteSpace(multiname.Name)) + if (!_multinamesByNameCache.TryGetValue(multiname.Name, out List multinames)) { - if (!_multinamesByNameCache.TryGetValue(multiname.Name, out List multinames)) - { - multinames = new List(); - _multinamesByNameCache.Add(multiname.Name, multinames); - } - multinames.Add(multiname); + multinames = new List(); + _multinamesByNameCache.Add(multiname.Name, multinames); } - _multinamesIndicesCache.Add(multiname, Multinames.Count); - return multiname; - } - private ASNamespace ReadNamespace() - { - return new ASNamespace(this, _input); + multinames.Add(multiname); } - private ASNamespaceSet ReadNamespaceSet() + _multinamesIndicesCache.Add(multiname, Multinames.Count); + return multiname; + } + private ASNamespace ReadNamespace() + { + return new ASNamespace(this, _input); + } + private ASNamespaceSet ReadNamespaceSet() + { + return new ASNamespaceSet(this, _input); + } + + private void PopulateList(List list, Func reader, T defaultValue) + { + list.Capacity = _input.ReadInt30(); + if (list.Equals(Multinames)) { - return new ASNamespaceSet(this, _input); + _multinamesByNameCache.EnsureCapacity(list.Capacity); + _multinamesIndicesCache.EnsureCapacity(list.Capacity); } - - private void PopulateList(List list, Func reader, T defaultValue) + if (list.Capacity > 0) { - list.Capacity = _input.ReadInt30(); - if (list.Equals(Multinames)) + list.Add(defaultValue); + for (int i = 1; i < list.Capacity; i++) { - _multinamesByNameCache.EnsureCapacity(list.Capacity); - _multinamesIndicesCache.EnsureCapacity(list.Capacity); - } - if (list.Capacity > 0) - { - list.Add(defaultValue); - for (int i = 1; i < list.Capacity; i++) - { - T value = reader(); - list.Add(value); - } + T value = reader(); + list.Add(value); } } + } - public override void WriteTo(FlashWriter output) - { - WriteTo(output, output.WriteInt30, Integers); - WriteTo(output, output.WriteUInt30, UIntegers); - WriteTo(output, output.Write, Doubles); - WriteTo(output, output.Write, Strings); - WriteTo(output, output.WriteItem, Namespaces); - WriteTo(output, output.WriteItem, NamespaceSets); - WriteTo(output, output.WriteItem, Multinames); - } - private void WriteTo(FlashWriter output, Action writer, List constants) + public override void WriteTo(FlashWriter output) + { + WriteTo(output, output.WriteInt30, Integers); + WriteTo(output, output.WriteUInt30, UIntegers); + WriteTo(output, output.Write, Doubles); + WriteTo(output, output.Write, Strings); + WriteTo(output, output.WriteItem, Namespaces); + WriteTo(output, output.WriteItem, NamespaceSets); + WriteTo(output, output.WriteItem, Multinames); + } + private void WriteTo(FlashWriter output, Action writer, List constants) + { + output.WriteInt30(constants.Count); + for (int i = 1; i < constants.Count; i++) { - output.WriteInt30(constants.Count); - for (int i = 1; i < constants.Count; i++) - { - T value = constants[i]; - writer(value); - } + T value = constants[i]; + writer(value); } } } \ No newline at end of file diff --git a/Flazzy/ABC/ASContainer.cs b/Flazzy/ABC/ASContainer.cs index 76aca49..7a79366 100644 --- a/Flazzy/ABC/ASContainer.cs +++ b/Flazzy/ABC/ASContainer.cs @@ -1,181 +1,180 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public abstract class ASContainer : AS3Item { - public abstract class ASContainer : AS3Item - { - public List Traits { get; } + public List Traits { get; } - public virtual bool IsStatic { get; } - public abstract ASMultiname QName { get; } - protected override string DebuggerDisplay + public virtual bool IsStatic { get; } + public abstract ASMultiname QName { get; } + protected override string DebuggerDisplay + { + get { - get - { - int methodCount = Traits.Count( - t => t.Kind == TraitKind.Method || - t.Kind == TraitKind.Getter || - t.Kind == TraitKind.Setter); + int methodCount = Traits.Count( + t => t.Kind == TraitKind.Method || + t.Kind == TraitKind.Getter || + t.Kind == TraitKind.Setter); - int slotCount = Traits.Count(t => t.Kind == TraitKind.Slot); - int constantCount = Traits.Count(t => t.Kind == TraitKind.Constant); + int slotCount = Traits.Count(t => t.Kind == TraitKind.Slot); + int constantCount = Traits.Count(t => t.Kind == TraitKind.Constant); - return $"{QName}, Traits: {Traits.Count}"; - } + return $"{QName}, Traits: {Traits.Count}"; } + } - public ASContainer(ABCFile abc) - : base(abc) - { - Traits = new List(); - } + public ASContainer(ABCFile abc) + : base(abc) + { + Traits = new List(); + } - public ASTrait AddMethod(ASMethod method, string qualifiedName) - { - int methodIndex = ABC.AddMethod(method); - int qNameIndex = AddPublicQualifiedName(qualifiedName); + public ASTrait AddMethod(ASMethod method, string qualifiedName) + { + int methodIndex = ABC.AddMethod(method); + int qNameIndex = AddPublicQualifiedName(qualifiedName); - var trait = new ASTrait(ABC) - { - Kind = TraitKind.Method, - QNameIndex = qNameIndex, - MethodIndex = methodIndex - }; - method.Trait = trait; - method.Container = this; + var trait = new ASTrait(ABC) + { + Kind = TraitKind.Method, + QNameIndex = qNameIndex, + MethodIndex = methodIndex + }; + method.Trait = trait; + method.Container = this; - Traits.Add(trait); - return trait; - } - public ASTrait AddSlot(string qualifiedName, string typeQualifiedName) + Traits.Add(trait); + return trait; + } + public ASTrait AddSlot(string qualifiedName, string typeQualifiedName) + { + var trait = new ASTrait(ABC) { - var trait = new ASTrait(ABC) - { - Kind = TraitKind.Slot, - QNameIndex = AddPublicQualifiedName(qualifiedName), - TypeIndex = ABC.Pool.GetMultinameIndex(typeQualifiedName) - }; + Kind = TraitKind.Slot, + QNameIndex = AddPublicQualifiedName(qualifiedName), + TypeIndex = ABC.Pool.GetMultinameIndex(typeQualifiedName) + }; - Traits.Add(trait); - return trait; - } + Traits.Add(trait); + return trait; + } - public IEnumerable GetMethods() - { - return GetTraits(TraitKind.Method, TraitKind.Getter, TraitKind.Setter).Select(t => t.Method); - } - public IEnumerable GetMethods(string qualifiedName) => GetMethods(qualifiedName, null, null); - public IEnumerable GetMethods(string qualifiedName, string returnTypeName) => GetMethods(qualifiedName, returnTypeName, null); - public IEnumerable GetMethods(string qualifiedName, string returnTypeName, int paramCount) => GetMethods(qualifiedName, returnTypeName, new string[paramCount]); - public IEnumerable GetMethods(string qualifiedName, string returnTypeName, string[] paramTypeNames) + public IEnumerable GetMethods() + { + return GetTraits(TraitKind.Method, TraitKind.Getter, TraitKind.Setter).Select(t => t.Method); + } + public IEnumerable GetMethods(string qualifiedName) => GetMethods(qualifiedName, null, null); + public IEnumerable GetMethods(string qualifiedName, string returnTypeName) => GetMethods(qualifiedName, returnTypeName, null); + public IEnumerable GetMethods(string qualifiedName, string returnTypeName, int paramCount) => GetMethods(qualifiedName, returnTypeName, new string[paramCount]); + public IEnumerable GetMethods(string qualifiedName, string returnTypeName, string[] paramTypeNames) + { + foreach (ASMethod method in GetMethods()) { - foreach (ASMethod method in GetMethods()) + if (qualifiedName != null && method.Trait.QName.Name != qualifiedName) continue; + if (returnTypeName != null && method.ReturnType?.Name != returnTypeName) continue; + if (paramTypeNames != null) { - if (qualifiedName != null && method.Trait.QName.Name != qualifiedName) continue; - if (returnTypeName != null && method.ReturnType?.Name != returnTypeName) continue; - if (paramTypeNames != null) - { - if (method.Parameters.Count != paramTypeNames.Length) continue; + if (method.Parameters.Count != paramTypeNames.Length) continue; - bool isContinuing = false; - for (int i = 0; i < paramTypeNames.Length; i++) + bool isContinuing = false; + for (int i = 0; i < paramTypeNames.Length; i++) + { + if (paramTypeNames[i] == null) continue; + if (method.Parameters[i].Type.Name != paramTypeNames[i]) { - if (paramTypeNames[i] == null) continue; - if (method.Parameters[i].Type.Name != paramTypeNames[i]) - { - isContinuing = true; - break; - } + isContinuing = true; + break; } - if (isContinuing) continue; } - yield return method; + if (isContinuing) continue; } + yield return method; } + } - public ASMethod GetMethod(string qualifiedName) => GetMethods(qualifiedName).FirstOrDefault(); - public ASMethod GetMethod(string qualifiedName, string returnTypeName) => GetMethods(qualifiedName, returnTypeName).FirstOrDefault(); - public ASMethod GetMethod(string qualifiedName, string returnTypeName, int paramCount) => GetMethods(qualifiedName, returnTypeName, paramCount).FirstOrDefault(); - public ASMethod GetMethod(string qualifiedName, string returnTypeName, string[] paramTypeNames) => GetMethods(qualifiedName, returnTypeName, paramTypeNames).FirstOrDefault(); + public ASMethod GetMethod(string qualifiedName) => GetMethods(qualifiedName).FirstOrDefault(); + public ASMethod GetMethod(string qualifiedName, string returnTypeName) => GetMethods(qualifiedName, returnTypeName).FirstOrDefault(); + public ASMethod GetMethod(string qualifiedName, string returnTypeName, int paramCount) => GetMethods(qualifiedName, returnTypeName, paramCount).FirstOrDefault(); + public ASMethod GetMethod(string qualifiedName, string returnTypeName, string[] paramTypeNames) => GetMethods(qualifiedName, returnTypeName, paramTypeNames).FirstOrDefault(); - public IEnumerable GetGetters() - { - return GetTraits(TraitKind.Getter); - } - public IEnumerable GetGetters(string returnTypeName) - { - return GetGetters() - .Where(g => g.Type.Name == returnTypeName); - } + public IEnumerable GetGetters() + { + return GetTraits(TraitKind.Getter); + } + public IEnumerable GetGetters(string returnTypeName) + { + return GetGetters() + .Where(g => g.Type.Name == returnTypeName); + } - public IEnumerable GetSlotTraits(string returnTypeName) - { - return GetTraits(TraitKind.Slot) - .Where(sct => (sct.Type?.Name ?? "*") == returnTypeName); - } - public IEnumerable GetConstantTraits(string returnTypeName) - { - return GetTraits(TraitKind.Constant) - .Where(sct => (sct.Type?.Name ?? "*") == returnTypeName); - } + public IEnumerable GetSlotTraits(string returnTypeName) + { + return GetTraits(TraitKind.Slot) + .Where(sct => (sct.Type?.Name ?? "*") == returnTypeName); + } + public IEnumerable GetConstantTraits(string returnTypeName) + { + return GetTraits(TraitKind.Constant) + .Where(sct => (sct.Type?.Name ?? "*") == returnTypeName); + } - public ASTrait GetSlot(string qualifiedName) - { - return GetTraits(TraitKind.Slot).FirstOrDefault(st => st.QName.Name == qualifiedName); - } - public ASTrait GetGetter(string qualifiedName) - { - return GetGetters().FirstOrDefault(g => g.QName.Name == qualifiedName); - } - public ASTrait GetConstant(string qualifiedName) - { - return GetTraits(TraitKind.Constant).FirstOrDefault(ct => ct.QName.Name == qualifiedName); - } + public ASTrait GetSlot(string qualifiedName) + { + return GetTraits(TraitKind.Slot).FirstOrDefault(st => st.QName.Name == qualifiedName); + } + public ASTrait GetGetter(string qualifiedName) + { + return GetGetters().FirstOrDefault(g => g.QName.Name == qualifiedName); + } + public ASTrait GetConstant(string qualifiedName) + { + return GetTraits(TraitKind.Constant).FirstOrDefault(ct => ct.QName.Name == qualifiedName); + } - public IEnumerable GetTraits(params TraitKind[] kinds) - { - return (kinds?.Length ?? 0) == 0 ? - Enumerable.Empty() : - Traits.Where(t => kinds.Contains(t.Kind)); - } + public IEnumerable GetTraits(params TraitKind[] kinds) + { + return (kinds?.Length ?? 0) == 0 ? + Enumerable.Empty() : + Traits.Where(t => kinds.Contains(t.Kind)); + } - private int AddPublicQualifiedName(string qualifiedName) + private int AddPublicQualifiedName(string qualifiedName) + { + var qName = new ASMultiname(ABC.Pool) { - var qName = new ASMultiname(ABC.Pool) - { - NameIndex = ABC.Pool.AddConstant(qualifiedName), - Kind = MultinameKind.QName, - NamespaceIndex = 1 // Public - }; - return ABC.Pool.AddConstant(qName); - } + NameIndex = ABC.Pool.AddConstant(qualifiedName), + Kind = MultinameKind.QName, + NamespaceIndex = 1 // Public + }; + return ABC.Pool.AddConstant(qName); + } - protected void PopulateTraits(FlashReader input) + protected void PopulateTraits(FlashReader input) + { + Traits.Capacity = input.ReadInt30(); + for (int i = 0; i < Traits.Capacity; i++) { - Traits.Capacity = input.ReadInt30(); - for (int i = 0; i < Traits.Capacity; i++) - { - var trait = new ASTrait(ABC, input); - trait.IsStatic = IsStatic; + var trait = new ASTrait(ABC, input); + trait.IsStatic = IsStatic; - if (trait.Kind == TraitKind.Method || - trait.Kind == TraitKind.Getter || - trait.Kind == TraitKind.Setter) - { - trait.Method.Container = this; - } - - Traits.Add(trait); + if (trait.Kind == TraitKind.Method || + trait.Kind == TraitKind.Getter || + trait.Kind == TraitKind.Setter) + { + trait.Method.Container = this; } + + Traits.Add(trait); } - public override void WriteTo(FlashWriter output) + } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(Traits.Count); + for (int i = 0; i < Traits.Count; i++) { - output.WriteInt30(Traits.Count); - for (int i = 0; i < Traits.Count; i++) - { - ASTrait trait = Traits[i]; - trait.WriteTo(output); - } + ASTrait trait = Traits[i]; + trait.WriteTo(output); } } } \ No newline at end of file diff --git a/Flazzy/ABC/ASException.cs b/Flazzy/ABC/ASException.cs index 64ec5cb..1c15bfd 100644 --- a/Flazzy/ABC/ASException.cs +++ b/Flazzy/ABC/ASException.cs @@ -1,39 +1,38 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASException : AS3Item { - public class ASException : AS3Item - { - public int To { get; set; } - public int From { get; set; } - public int Target { get; set; } + public int To { get; set; } + public int From { get; set; } + public int Target { get; set; } + + public int VariableNameIndex { get; set; } + public ASMultiname VariableName => ABC.Pool.Multinames[VariableNameIndex]; - public int VariableNameIndex { get; set; } - public ASMultiname VariableName => ABC.Pool.Multinames[VariableNameIndex]; + public int ExceptionTypeIndex { get; set; } + public ASMultiname ExceptionType => ABC.Pool.Multinames[ExceptionTypeIndex]; - public int ExceptionTypeIndex { get; set; } - public ASMultiname ExceptionType => ABC.Pool.Multinames[ExceptionTypeIndex]; + public ASException(ABCFile abc) + : base(abc) + { } + public ASException(ABCFile abc, FlashReader input) + : base(abc) + { + From = input.ReadInt30(); + To = input.ReadInt30(); + Target = input.ReadInt30(); + ExceptionTypeIndex = input.ReadInt30(); + VariableNameIndex = input.ReadInt30(); + } - public ASException(ABCFile abc) - : base(abc) - { } - public ASException(ABCFile abc, FlashReader input) - : base(abc) - { - From = input.ReadInt30(); - To = input.ReadInt30(); - Target = input.ReadInt30(); - ExceptionTypeIndex = input.ReadInt30(); - VariableNameIndex = input.ReadInt30(); - } - - public override void WriteTo(FlashWriter output) - { - output.WriteInt30(From); - output.WriteInt30(To); - output.WriteInt30(Target); - output.WriteInt30(ExceptionTypeIndex); - output.WriteInt30(VariableNameIndex); - } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(From); + output.WriteInt30(To); + output.WriteInt30(Target); + output.WriteInt30(ExceptionTypeIndex); + output.WriteInt30(VariableNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASInstance.cs b/Flazzy/ABC/ASInstance.cs index f5ac5e4..bc5285b 100644 --- a/Flazzy/ABC/ASInstance.cs +++ b/Flazzy/ABC/ASInstance.cs @@ -1,139 +1,138 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASInstance : ASContainer { - public class ASInstance : ASContainer - { - public ClassFlags Flags { get; set; } - public bool IsInterface => Flags.HasFlag(ClassFlags.Interface); + public ClassFlags Flags { get; set; } + public bool IsInterface => Flags.HasFlag(ClassFlags.Interface); - public int SuperIndex { get; set; } - public ASMultiname Super => ABC.Pool.Multinames[SuperIndex]; + public int SuperIndex { get; set; } + public ASMultiname Super => ABC.Pool.Multinames[SuperIndex]; - public int ConstructorIndex { get; set; } - public ASMethod Constructor => ABC.Methods[ConstructorIndex]; + public int ConstructorIndex { get; set; } + public ASMethod Constructor => ABC.Methods[ConstructorIndex]; - public int QNameIndex { get; set; } - public override ASMultiname QName => ABC.Pool.Multinames[QNameIndex]; + public int QNameIndex { get; set; } + public override ASMultiname QName => ABC.Pool.Multinames[QNameIndex]; - public int ProtectedNamespaceIndex { get; set; } - public ASNamespace ProtectedNamespace => ABC.Pool.Namespaces[ProtectedNamespaceIndex]; + public int ProtectedNamespaceIndex { get; set; } + public ASNamespace ProtectedNamespace => ABC.Pool.Namespaces[ProtectedNamespaceIndex]; - protected override string DebuggerDisplay => ToAS3(); + protected override string DebuggerDisplay => ToAS3(); - public List InterfaceIndices { get; } + public List InterfaceIndices { get; } - public ASInstance(ABCFile abc) - : base(abc) + public ASInstance(ABCFile abc) + : base(abc) + { + InterfaceIndices = new List(); + } + public ASInstance(ABCFile abc, FlashReader input) + : this(abc) + { + QNameIndex = input.ReadInt30(); + SuperIndex = input.ReadInt30(); + Flags = (ClassFlags)input.ReadByte(); + + if (Flags.HasFlag(ClassFlags.ProtectedNamespace)) { - InterfaceIndices = new List(); + ProtectedNamespaceIndex = input.ReadInt30(); } - public ASInstance(ABCFile abc, FlashReader input) - : this(abc) - { - QNameIndex = input.ReadInt30(); - SuperIndex = input.ReadInt30(); - Flags = (ClassFlags)input.ReadByte(); - if (Flags.HasFlag(ClassFlags.ProtectedNamespace)) - { - ProtectedNamespaceIndex = input.ReadInt30(); - } - - InterfaceIndices.Capacity = input.ReadInt30(); - for (int i = 0; i < InterfaceIndices.Capacity; i++) - { - int interfaceIndex = input.ReadInt30(); - InterfaceIndices.Add(interfaceIndex); - } + InterfaceIndices.Capacity = input.ReadInt30(); + for (int i = 0; i < InterfaceIndices.Capacity; i++) + { + int interfaceIndex = input.ReadInt30(); + InterfaceIndices.Add(interfaceIndex); + } - ConstructorIndex = input.ReadInt30(); - Constructor.IsConstructor = true; - Constructor.Container = this; + ConstructorIndex = input.ReadInt30(); + Constructor.IsConstructor = true; + Constructor.Container = this; - PopulateTraits(input); - } + PopulateTraits(input); + } - public IEnumerable GetInterfaces() + public IEnumerable GetInterfaces() + { + for (int i = 0; i < InterfaceIndices.Count; i++) { - for (int i = 0; i < InterfaceIndices.Count; i++) - { - int interfaceIndex = InterfaceIndices[i]; - ASMultiname @interface = ABC.Pool.Multinames[interfaceIndex]; - yield return @interface; - } + int interfaceIndex = InterfaceIndices[i]; + ASMultiname @interface = ABC.Pool.Multinames[interfaceIndex]; + yield return @interface; } - public bool ContainsInterface(string qualifiedName) + } + public bool ContainsInterface(string qualifiedName) + { + if (Super.Name != "Object") { - if (Super.Name != "Object") + ASInstance superInstance = ABC.GetInstance(Super); + if (superInstance.ContainsInterface(qualifiedName)) { - ASInstance superInstance = ABC.GetInstance(Super); - if (superInstance.ContainsInterface(qualifiedName)) - { - return true; - } - } - foreach (ASMultiname @interface in GetInterfaces()) - { - if (@interface.Name != qualifiedName) continue; return true; } - return false; } - - public override string ToAS3() + foreach (ASMultiname @interface in GetInterfaces()) { - string as3 = QName.Namespace.GetAS3Modifiers(); - bool isInterface = Flags.HasFlag(ClassFlags.Interface); + if (@interface.Name != qualifiedName) continue; + return true; + } + return false; + } - if (!string.IsNullOrWhiteSpace(as3)) as3 += " "; - if (Flags.HasFlag(ClassFlags.Final)) - { - as3 += "final "; - } + public override string ToAS3() + { + string as3 = QName.Namespace.GetAS3Modifiers(); + bool isInterface = Flags.HasFlag(ClassFlags.Interface); - if (Flags.HasFlag(ClassFlags.Interface)) - { - as3 += "interface "; - } - else as3 += "class "; + if (!string.IsNullOrWhiteSpace(as3)) as3 += " "; + if (Flags.HasFlag(ClassFlags.Final)) + { + as3 += "final "; + } - as3 += QName.Name; - if (!isInterface && ((Super?.Name ?? "Object") != "Object")) - { - as3 += $" extends {Super.Name}"; - } + if (Flags.HasFlag(ClassFlags.Interface)) + { + as3 += "interface "; + } + else as3 += "class "; - if (InterfaceIndices.Count > 0) - { - string interfacesAS3 = string.Join( - ", ", GetInterfaces().Select(i => i.Name)); + as3 += QName.Name; + if (!isInterface && ((Super?.Name ?? "Object") != "Object")) + { + as3 += $" extends {Super.Name}"; + } - as3 += (" implements " + interfacesAS3); - } + if (InterfaceIndices.Count > 0) + { + string interfacesAS3 = string.Join( + ", ", GetInterfaces().Select(i => i.Name)); - return as3; + as3 += (" implements " + interfacesAS3); } - public override void WriteTo(FlashWriter output) - { - output.WriteInt30(QNameIndex); - output.WriteInt30(SuperIndex); - output.Write((byte)Flags); - if (Flags.HasFlag(ClassFlags.ProtectedNamespace)) - { - output.WriteInt30(ProtectedNamespaceIndex); - } + return as3; + } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(QNameIndex); + output.WriteInt30(SuperIndex); + output.Write((byte)Flags); - output.WriteInt30(InterfaceIndices.Count); - for (int i = 0; i < InterfaceIndices.Count; i++) - { - int interfaceIndex = InterfaceIndices[i]; - output.WriteInt30(interfaceIndex); - } + if (Flags.HasFlag(ClassFlags.ProtectedNamespace)) + { + output.WriteInt30(ProtectedNamespaceIndex); + } - output.WriteInt30(ConstructorIndex); - base.WriteTo(output); + output.WriteInt30(InterfaceIndices.Count); + for (int i = 0; i < InterfaceIndices.Count; i++) + { + int interfaceIndex = InterfaceIndices[i]; + output.WriteInt30(interfaceIndex); } + + output.WriteInt30(ConstructorIndex); + base.WriteTo(output); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASMethod.cs b/Flazzy/ABC/ASMethod.cs index 023ceba..c7785d9 100644 --- a/Flazzy/ABC/ASMethod.cs +++ b/Flazzy/ABC/ASMethod.cs @@ -1,192 +1,192 @@ -using Flazzy.IO; +using System.Text; -using System.Text; +using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASMethod : AS3Item { - public class ASMethod : AS3Item - { - public int NameIndex { get; set; } - public string Name => ABC.Pool.Strings[NameIndex]; + public int NameIndex { get; set; } + public string Name => ABC.Pool.Strings[NameIndex]; - public int ReturnTypeIndex { get; set; } - public ASMultiname ReturnType => ABC.Pool.Multinames[ReturnTypeIndex]; + public int ReturnTypeIndex { get; set; } + public ASMultiname ReturnType => ABC.Pool.Multinames[ReturnTypeIndex]; - public MethodFlags Flags { get; set; } - public List Parameters { get; } + public MethodFlags Flags { get; set; } + public List Parameters { get; } - public ASTrait Trait { get; internal set; } - public ASMethodBody Body { get; internal set; } - public bool IsConstructor { get; internal set; } - public ASContainer Container { get; internal set; } - public bool IsAnonymous => Trait == null && !IsConstructor; + public ASTrait Trait { get; internal set; } + public ASMethodBody Body { get; internal set; } + public bool IsConstructor { get; internal set; } + public ASContainer Container { get; internal set; } + public bool IsAnonymous => Trait == null && !IsConstructor; - protected override string DebuggerDisplay => ToAS3(); + protected override string DebuggerDisplay => ToAS3(); - public ASMethod(ABCFile abc) - : base(abc) + public ASMethod(ABCFile abc) + : base(abc) + { + Parameters = new List(); + } + public ASMethod(ABCFile abc, FlashReader input) + : this(abc) + { + Parameters.Capacity = input.ReadInt30(); + ReturnTypeIndex = input.ReadInt30(); + + for (int i = 0; i < Parameters.Capacity; i++) { - Parameters = new List(); + var parameter = new ASParameter(this); + parameter.TypeIndex = input.ReadInt30(); + Parameters.Add(parameter); } - public ASMethod(ABCFile abc, FlashReader input) - : this(abc) - { - Parameters.Capacity = input.ReadInt30(); - ReturnTypeIndex = input.ReadInt30(); - for (int i = 0; i < Parameters.Capacity; i++) - { - var parameter = new ASParameter(this); - parameter.TypeIndex = input.ReadInt30(); - Parameters.Add(parameter); - } + NameIndex = input.ReadInt30(); + Flags = (MethodFlags)input.ReadByte(); - NameIndex = input.ReadInt30(); - Flags = (MethodFlags)input.ReadByte(); - - if (Flags.HasFlag(MethodFlags.HasOptional)) + if (Flags.HasFlag(MethodFlags.HasOptional)) + { + int optionalParamCount = input.ReadInt30(); + for (int i = Parameters.Count - optionalParamCount; + optionalParamCount > 0; + i++, optionalParamCount--) { - int optionalParamCount = input.ReadInt30(); - for (int i = Parameters.Count - optionalParamCount; - optionalParamCount > 0; - i++, optionalParamCount--) - { - ASParameter parameter = Parameters[i]; - parameter.IsOptional = true; - parameter.ValueIndex = input.ReadInt30(); - parameter.ValueKind = (ConstantKind)input.ReadByte(); - } + ASParameter parameter = Parameters[i]; + parameter.IsOptional = true; + parameter.ValueIndex = input.ReadInt30(); + parameter.ValueKind = (ConstantKind)input.ReadByte(); } + } - if (Flags.HasFlag(MethodFlags.HasParamNames)) + if (Flags.HasFlag(MethodFlags.HasParamNames)) + { + for (int i = 0; i < Parameters.Count; i++) { - for (int i = 0; i < Parameters.Count; i++) - { - ASParameter parameter = Parameters[i]; - parameter.NameIndex = input.ReadInt30(); - } + ASParameter parameter = Parameters[i]; + parameter.NameIndex = input.ReadInt30(); } } + } - public override string ToAS3() - { - var builder = new StringBuilder(); + public override string ToAS3() + { + var builder = new StringBuilder(); - ASMultiname qName = Trait?.QName ?? Container?.QName; - if (qName != null) + ASMultiname qName = Trait?.QName ?? Container?.QName; + if (qName != null) + { + if (Trait.Attributes.HasFlag(TraitAttributes.Override)) { - if(Trait.Attributes.HasFlag(TraitAttributes.Override)) - { - builder.Append("override "); - } - builder.Append(qName.Namespace.GetAS3Modifiers()); - if (builder.Length > 0) - { - builder.Append(' '); - } - if (!IsConstructor && Trait.IsStatic) - { - builder.Append("static "); - } - builder.Append("function "); - if(Trait.Kind == TraitKind.Getter) - { - builder.Append("get "); - } - if(Trait.Kind == TraitKind.Setter) - { - builder.Append("set "); - } - builder.Append(qName.Name); + builder.Append("override "); } - else if (IsAnonymous) builder.Append("function"); - - builder.Append('('); // Parameters Start - if (Parameters.Count > 0) + builder.Append(qName.Namespace.GetAS3Modifiers()); + if (builder.Length > 0) { - for (int i = 0; i < Parameters.Count; i++) - { - Parameters[i].Append(builder, i + 1); - builder.Append(", "); - } - builder.Length -= 2; + builder.Append(' '); } - - if (Flags.HasFlag(MethodFlags.NeedRest)) + if (!IsConstructor && Trait.IsStatic) { - builder.Append("... param"); - builder.Append(Parameters.Count + 1); + builder.Append("static "); } - builder.Append(')'); // Parameters End - if (ReturnType != null) + builder.Append("function "); + if (Trait.Kind == TraitKind.Getter) { - builder.Append(':'); - if(ReturnType.Kind == MultinameKind.TypeName) - { - builder.Append(ReturnType.QName.Name); - builder.Append(".<"); - builder.Append(string.Join(',', ReturnType.TypeIndices.Select(i => ABC.Pool.Multinames[i].Name))); - builder.Append('>'); - } else builder.Append(ReturnType.Name); + builder.Append("get "); + } + if (Trait.Kind == TraitKind.Setter) + { + builder.Append("set "); } - return builder.ToString(); + builder.Append(qName.Name); } + else if (IsAnonymous) builder.Append("function"); - public override void WriteTo(FlashWriter output) + builder.Append('('); // Parameters Start + if (Parameters.Count > 0) { - output.WriteInt30(Parameters.Count); - output.WriteInt30(ReturnTypeIndex); + for (int i = 0; i < Parameters.Count; i++) + { + Parameters[i].Append(builder, i + 1); + builder.Append(", "); + } + builder.Length -= 2; + } - int optionalParamCount = 0; - int optionalParamStartIndex = (Parameters.Count - 1); - if (Parameters.Count > 0) + if (Flags.HasFlag(MethodFlags.NeedRest)) + { + builder.Append("... param"); + builder.Append(Parameters.Count + 1); + } + builder.Append(')'); // Parameters End + if (ReturnType != null) + { + builder.Append(':'); + if (ReturnType.Kind == MultinameKind.TypeName) { - // This flag will be removed if at least a single parameter has no name assigned. - Flags |= MethodFlags.HasParamNames; - for (int i = 0; i < Parameters.Count; i++) - { - ASParameter parameter = Parameters[i]; - output.WriteInt30(parameter.TypeIndex); + builder.Append(ReturnType.QName.Name); + builder.Append(".<"); + builder.Append(string.Join(',', ReturnType.TypeIndices.Select(i => ABC.Pool.Multinames[i].Name))); + builder.Append('>'); + } + else builder.Append(ReturnType.Name); + } + return builder.ToString(); + } - // This flag should only be present when all parameters are assigned a Name. - if (string.IsNullOrWhiteSpace(parameter.Name)) - { - Flags &= ~MethodFlags.HasParamNames; - } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(Parameters.Count); + output.WriteInt30(ReturnTypeIndex); + + int optionalParamCount = 0; + int optionalParamStartIndex = (Parameters.Count - 1); + if (Parameters.Count > 0) + { + // This flag will be removed if at least a single parameter has no name assigned. + Flags |= MethodFlags.HasParamNames; + for (int i = 0; i < Parameters.Count; i++) + { + ASParameter parameter = Parameters[i]; + output.WriteInt30(parameter.TypeIndex); - // Just one optional parameter is enough to attain this flag. - if (parameter.IsOptional) + // This flag should only be present when all parameters are assigned a Name. + if (string.IsNullOrWhiteSpace(parameter.Name)) + { + Flags &= ~MethodFlags.HasParamNames; + } + + // Just one optional parameter is enough to attain this flag. + if (parameter.IsOptional) + { + if (i < optionalParamStartIndex) { - if (i < optionalParamStartIndex) - { - optionalParamStartIndex = i; - } - optionalParamCount++; - Flags |= MethodFlags.HasOptional; + optionalParamStartIndex = i; } + optionalParamCount++; + Flags |= MethodFlags.HasOptional; } } + } - output.WriteInt30(NameIndex); - output.Write((byte)Flags); - if (Flags.HasFlag(MethodFlags.HasOptional)) + output.WriteInt30(NameIndex); + output.Write((byte)Flags); + if (Flags.HasFlag(MethodFlags.HasOptional)) + { + output.WriteInt30(optionalParamCount); + for (int i = optionalParamStartIndex; i < Parameters.Count; i++) { - output.WriteInt30(optionalParamCount); - for (int i = optionalParamStartIndex; i < Parameters.Count; i++) - { - ASParameter parameter = Parameters[i]; - output.WriteInt30(parameter.ValueIndex); - output.Write((byte)parameter.ValueKind); - } + ASParameter parameter = Parameters[i]; + output.WriteInt30(parameter.ValueIndex); + output.Write((byte)parameter.ValueKind); } + } - if (Flags.HasFlag(MethodFlags.HasParamNames)) + if (Flags.HasFlag(MethodFlags.HasParamNames)) + { + for (int i = 0; i < Parameters.Count; i++) { - for (int i = 0; i < Parameters.Count; i++) - { - ASParameter parameter = Parameters[i]; - output.WriteInt30(parameter.NameIndex); - } + ASParameter parameter = Parameters[i]; + output.WriteInt30(parameter.NameIndex); } } } diff --git a/Flazzy/ABC/ASMethodBody.cs b/Flazzy/ABC/ASMethodBody.cs index fe49b28..4a94fae 100644 --- a/Flazzy/ABC/ASMethodBody.cs +++ b/Flazzy/ABC/ASMethodBody.cs @@ -1,75 +1,74 @@ -using Flazzy.IO; -using Flazzy.ABC.AVM2; +using Flazzy.ABC.AVM2; +using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASMethodBody : ASContainer { - public class ASMethodBody : ASContainer - { - public byte[] Code { get; set; } - public int MaxStack { get; set; } - public int LocalCount { get; set; } - public int MaxScopeDepth { get; set; } - public int InitialScopeDepth { get; set; } + public byte[] Code { get; set; } + public int MaxStack { get; set; } + public int LocalCount { get; set; } + public int MaxScopeDepth { get; set; } + public int InitialScopeDepth { get; set; } - public int MethodIndex { get; set; } - public ASMethod Method => ABC.Methods[MethodIndex]; + public int MethodIndex { get; set; } + public ASMethod Method => ABC.Methods[MethodIndex]; - public List Exceptions { get; } + public List Exceptions { get; } - public override ASMultiname QName => Method.Trait?.QName; - protected override string DebuggerDisplay => $"LocalCount: {LocalCount:n0}, MaxStack: {MaxStack:n0}"; + public override ASMultiname QName => Method.Trait?.QName; + protected override string DebuggerDisplay => $"LocalCount: {LocalCount:n0}, MaxStack: {MaxStack:n0}"; - public ASMethodBody(ABCFile abc) - : base(abc) - { - Exceptions = new List(); - } - public ASMethodBody(ABCFile abc, FlashReader input) - : this(abc) - { - MethodIndex = input.ReadInt30(); - Method.Body = this; - - MaxStack = input.ReadInt30(); - LocalCount = input.ReadInt30(); - InitialScopeDepth = input.ReadInt30(); - MaxScopeDepth = input.ReadInt30(); + public ASMethodBody(ABCFile abc) + : base(abc) + { + Exceptions = new List(); + } + public ASMethodBody(ABCFile abc, FlashReader input) + : this(abc) + { + MethodIndex = input.ReadInt30(); + Method.Body = this; - int codeLength = input.ReadInt30(); - Code = input.ReadBytes(codeLength); + MaxStack = input.ReadInt30(); + LocalCount = input.ReadInt30(); + InitialScopeDepth = input.ReadInt30(); + MaxScopeDepth = input.ReadInt30(); - Exceptions.Capacity = input.ReadInt30(); - for (int i = 0; i < Exceptions.Capacity; i++) - { - var exception = new ASException(abc, input); - Exceptions.Add(exception); - } - PopulateTraits(input); - } + int codeLength = input.ReadInt30(); + Code = input.ReadBytes(codeLength); - public ASCode ParseCode() + Exceptions.Capacity = input.ReadInt30(); + for (int i = 0; i < Exceptions.Capacity; i++) { - return new ASCode(ABC, this); + var exception = new ASException(abc, input); + Exceptions.Add(exception); } - - public override void WriteTo(FlashWriter output) - { - output.WriteInt30(MethodIndex); - output.WriteInt30(MaxStack); - output.WriteInt30(LocalCount); - output.WriteInt30(InitialScopeDepth); - output.WriteInt30(MaxScopeDepth); + PopulateTraits(input); + } - output.WriteInt30(Code.Length); - output.Write(Code); + public ASCode ParseCode() + { + return new ASCode(ABC, this); + } - output.WriteInt30(Exceptions.Count); - for (int i = 0; i < Exceptions.Count; i++) - { - ASException exception = Exceptions[i]; - exception.WriteTo(output); - } - base.WriteTo(output); + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(MethodIndex); + output.WriteInt30(MaxStack); + output.WriteInt30(LocalCount); + output.WriteInt30(InitialScopeDepth); + output.WriteInt30(MaxScopeDepth); + + output.WriteInt30(Code.Length); + output.Write(Code); + + output.WriteInt30(Exceptions.Count); + for (int i = 0; i < Exceptions.Count; i++) + { + ASException exception = Exceptions[i]; + exception.WriteTo(output); } + base.WriteTo(output); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASMultiname.cs b/Flazzy/ABC/ASMultiname.cs index 595b05c..fac40f0 100644 --- a/Flazzy/ABC/ASMultiname.cs +++ b/Flazzy/ABC/ASMultiname.cs @@ -78,52 +78,52 @@ public ASMultiname(ASConstantPool pool, FlashReader input) { case MultinameKind.QName: case MultinameKind.QNameA: - { - NamespaceIndex = input.ReadInt30(); - NameIndex = input.ReadInt30(); - break; - } + { + NamespaceIndex = input.ReadInt30(); + NameIndex = input.ReadInt30(); + break; + } case MultinameKind.RTQName: case MultinameKind.RTQNameA: - { - NameIndex = input.ReadInt30(); - break; - } + { + NameIndex = input.ReadInt30(); + break; + } case MultinameKind.RTQNameL: case MultinameKind.RTQNameLA: - { - /* No data. */ - break; - } + { + /* No data. */ + break; + } case MultinameKind.Multiname: case MultinameKind.MultinameA: - { - NameIndex = input.ReadInt30(); - NamespaceSetIndex = input.ReadInt30(); - break; - } + { + NameIndex = input.ReadInt30(); + NamespaceSetIndex = input.ReadInt30(); + break; + } case MultinameKind.MultinameL: case MultinameKind.MultinameLA: - { - NamespaceSetIndex = input.ReadInt30(); - break; - } + { + NamespaceSetIndex = input.ReadInt30(); + break; + } case MultinameKind.TypeName: - { - QNameIndex = input.ReadInt30(); - TypeIndices.Capacity = input.ReadInt30(); - for (int i = 0; i < TypeIndices.Capacity; i++) { - int typeIndex = input.ReadInt30(); - TypeIndices.Add(typeIndex); + QNameIndex = input.ReadInt30(); + TypeIndices.Capacity = input.ReadInt30(); + for (int i = 0; i < TypeIndices.Capacity; i++) + { + int typeIndex = input.ReadInt30(); + TypeIndices.Add(typeIndex); + } + break; } - break; - } } } @@ -141,52 +141,52 @@ public override void WriteTo(FlashWriter output) { case MultinameKind.QName: case MultinameKind.QNameA: - { - output.WriteInt30(NamespaceIndex); - output.WriteInt30(NameIndex); - break; - } + { + output.WriteInt30(NamespaceIndex); + output.WriteInt30(NameIndex); + break; + } case MultinameKind.RTQName: case MultinameKind.RTQNameA: - { - output.WriteInt30(NameIndex); - break; - } + { + output.WriteInt30(NameIndex); + break; + } case MultinameKind.RTQNameL: case MultinameKind.RTQNameLA: - { - /* No data. */ - break; - } + { + /* No data. */ + break; + } case MultinameKind.Multiname: case MultinameKind.MultinameA: - { - output.WriteInt30(NameIndex); - output.WriteInt30(NamespaceSetIndex); - break; - } + { + output.WriteInt30(NameIndex); + output.WriteInt30(NamespaceSetIndex); + break; + } case MultinameKind.MultinameL: case MultinameKind.MultinameLA: - { - output.WriteInt30(NamespaceSetIndex); - break; - } + { + output.WriteInt30(NamespaceSetIndex); + break; + } case MultinameKind.TypeName: - { - output.WriteInt30(QNameIndex); - output.WriteInt30(TypeIndices.Count); - for (int i = 0; i < TypeIndices.Count; i++) { - int typeIndex = TypeIndices[i]; - output.WriteInt30(typeIndex); + output.WriteInt30(QNameIndex); + output.WriteInt30(TypeIndices.Count); + for (int i = 0; i < TypeIndices.Count; i++) + { + int typeIndex = TypeIndices[i]; + output.WriteInt30(typeIndex); + } + break; } - break; - } } } diff --git a/Flazzy/ABC/ASNamespace.cs b/Flazzy/ABC/ASNamespace.cs index d76c44a..ef78d2b 100644 --- a/Flazzy/ABC/ASNamespace.cs +++ b/Flazzy/ABC/ASNamespace.cs @@ -1,86 +1,85 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +/// +/// Represents a namespace in the bytecode. +/// +public class ASNamespace : FlashItem, IEquatable, IPoolConstant { /// - /// Represents a namespace in the bytecode. + /// Gets or sets the index of the string in representing the namespace name. /// - public class ASNamespace : FlashItem, IEquatable, IPoolConstant - { - /// - /// Gets or sets the index of the string in representing the namespace name. - /// - public int NameIndex { get; set; } + public int NameIndex { get; set; } - public ASConstantPool Pool { get; init; } + public ASConstantPool Pool { get; init; } - /// - /// Gets the name of the namespace. - /// - public string Name => Pool.Strings[NameIndex]; + /// + /// Gets the name of the namespace. + /// + public string Name => Pool.Strings[NameIndex]; - /// - /// Gets or sets the kind of namespace this entry should be interpreted as by the loader. - /// - public NamespaceKind Kind { get; set; } + /// + /// Gets or sets the kind of namespace this entry should be interpreted as by the loader. + /// + public NamespaceKind Kind { get; set; } - protected override string DebuggerDisplay => $"{Kind}: \"{Name}\""; + protected override string DebuggerDisplay => $"{Kind}: \"{Name}\""; - public static bool operator ==(ASNamespace left, ASNamespace right) - { - return EqualityComparer.Default.Equals(left, right); - } - public static bool operator !=(ASNamespace left, ASNamespace right) - { - return !(left == right); - } + public static bool operator ==(ASNamespace left, ASNamespace right) + { + return EqualityComparer.Default.Equals(left, right); + } + public static bool operator !=(ASNamespace left, ASNamespace right) + { + return !(left == right); + } - public ASNamespace(ASConstantPool pool) - { - Pool = pool; - } - public ASNamespace(ASConstantPool pool, FlashReader input) - : this(pool) + public ASNamespace(ASConstantPool pool) + { + Pool = pool; + } + public ASNamespace(ASConstantPool pool, FlashReader input) + : this(pool) + { + Kind = (NamespaceKind)input.ReadByte(); + if (!Enum.IsDefined(typeof(NamespaceKind), Kind)) { - Kind = (NamespaceKind)input.ReadByte(); - if (!Enum.IsDefined(typeof(NamespaceKind), Kind)) - { - throw new InvalidCastException($"Invalid namespace kind for value {Kind:0x00}."); - } - NameIndex = input.ReadInt30(); + throw new InvalidCastException($"Invalid namespace kind for value {Kind:0x00}."); } + NameIndex = input.ReadInt30(); + } - public string GetAS3Modifiers() => Kind switch - { - NamespaceKind.Package => "public", - NamespaceKind.Private => "private", - NamespaceKind.Explicit => "explicit", - NamespaceKind.StaticProtected or NamespaceKind.Protected => "protected", - _ => string.Empty, - }; - public override void WriteTo(FlashWriter output) - { - output.Write((byte)Kind); - output.WriteInt30(NameIndex); - } + public string GetAS3Modifiers() => Kind switch + { + NamespaceKind.Package => "public", + NamespaceKind.Private => "private", + NamespaceKind.Explicit => "explicit", + NamespaceKind.StaticProtected or NamespaceKind.Protected => "protected", + _ => string.Empty, + }; + public override void WriteTo(FlashWriter output) + { + output.Write((byte)Kind); + output.WriteInt30(NameIndex); + } - public override int GetHashCode() - { - return HashCode.Combine(Name, Kind); - } - public bool Equals(ASNamespace other) - { - if (other == null) return false; - if (!ReferenceEquals(this, other)) - { - if (Name != other.Name) return false; - if (Kind != other.Kind) return false; - } - return true; - } - public override bool Equals(object obj) + public override int GetHashCode() + { + return HashCode.Combine(Name, Kind); + } + public bool Equals(ASNamespace other) + { + if (other == null) return false; + if (!ReferenceEquals(this, other)) { - return Equals(obj as ASNamespace); + if (Name != other.Name) return false; + if (Kind != other.Kind) return false; } + return true; + } + public override bool Equals(object obj) + { + return Equals(obj as ASNamespace); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASNamespaceSet.cs b/Flazzy/ABC/ASNamespaceSet.cs index f28029e..72e62b7 100644 --- a/Flazzy/ABC/ASNamespaceSet.cs +++ b/Flazzy/ABC/ASNamespaceSet.cs @@ -1,82 +1,81 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASNamespaceSet : FlashItem, IEquatable, IPoolConstant { - public class ASNamespaceSet : FlashItem, IEquatable, IPoolConstant - { - public ASConstantPool Pool { get; init; } - public List NamespaceIndices { get; } + public ASConstantPool Pool { get; init; } + public List NamespaceIndices { get; } - protected override string DebuggerDisplay => $"Namespaces: {NamespaceIndices.Count:n0}"; + protected override string DebuggerDisplay => $"Namespaces: {NamespaceIndices.Count:n0}"; - public static bool operator ==(ASNamespaceSet left, ASNamespaceSet right) - { - return EqualityComparer.Default.Equals(left, right); - } - public static bool operator !=(ASNamespaceSet left, ASNamespaceSet right) - { - return !(left == right); - } + public static bool operator ==(ASNamespaceSet left, ASNamespaceSet right) + { + return EqualityComparer.Default.Equals(left, right); + } + public static bool operator !=(ASNamespaceSet left, ASNamespaceSet right) + { + return !(left == right); + } - public ASNamespaceSet(ASConstantPool pool) - { - Pool = pool; - NamespaceIndices = new List(); - } - public ASNamespaceSet(ASConstantPool pool, FlashReader input) - : this(pool) + public ASNamespaceSet(ASConstantPool pool) + { + Pool = pool; + NamespaceIndices = new List(); + } + public ASNamespaceSet(ASConstantPool pool, FlashReader input) + : this(pool) + { + NamespaceIndices.Capacity = input.ReadInt30(); + for (int i = 0; i < NamespaceIndices.Capacity; i++) { - NamespaceIndices.Capacity = input.ReadInt30(); - for (int i = 0; i < NamespaceIndices.Capacity; i++) - { - int namespaceIndex = input.ReadInt30(); - NamespaceIndices.Add(namespaceIndex); - } + int namespaceIndex = input.ReadInt30(); + NamespaceIndices.Add(namespaceIndex); } + } - public override int GetHashCode() - { - var hash = new HashCode(); - foreach (ASNamespace @namespace in GetNamespaces()) - { - hash.Add(@namespace); - } - return hash.ToHashCode(); - } - public override bool Equals(object obj) + public override int GetHashCode() + { + var hash = new HashCode(); + foreach (ASNamespace @namespace in GetNamespaces()) { - return Equals(obj as ASNamespaceSet); + hash.Add(@namespace); } - public bool Equals(ASNamespaceSet other) + return hash.ToHashCode(); + } + public override bool Equals(object obj) + { + return Equals(obj as ASNamespaceSet); + } + public bool Equals(ASNamespaceSet other) + { + if (other == null) return false; + if (!ReferenceEquals(this, other)) { - if (other == null) return false; - if (!ReferenceEquals(this, other)) + if (NamespaceIndices.Count != other.NamespaceIndices.Count) return false; + for (int i = 0; i < NamespaceIndices.Count; i++) { - if (NamespaceIndices.Count != other.NamespaceIndices.Count) return false; - for (int i = 0; i < NamespaceIndices.Count; i++) - { - if (Pool.Namespaces[NamespaceIndices[i]] != other.Pool.Namespaces[NamespaceIndices[i]]) return false; - } + if (Pool.Namespaces[NamespaceIndices[i]] != other.Pool.Namespaces[NamespaceIndices[i]]) return false; } - return true; } + return true; + } - public IEnumerable GetNamespaces() + public IEnumerable GetNamespaces() + { + for (int i = 0; i < NamespaceIndices.Count; i++) { - for (int i = 0; i < NamespaceIndices.Count; i++) - { - yield return Pool.Namespaces[NamespaceIndices[i]]; - } + yield return Pool.Namespaces[NamespaceIndices[i]]; } - public override void WriteTo(FlashWriter output) + } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(NamespaceIndices.Count); + for (int i = 0; i < NamespaceIndices.Count; i++) { - output.WriteInt30(NamespaceIndices.Count); - for (int i = 0; i < NamespaceIndices.Count; i++) - { - int namespaceIndex = NamespaceIndices[i]; - output.WriteInt30(namespaceIndex); - } + int namespaceIndex = NamespaceIndices[i]; + output.WriteInt30(namespaceIndex); } - } + } \ No newline at end of file diff --git a/Flazzy/ABC/ASParameter.cs b/Flazzy/ABC/ASParameter.cs index c7113e1..fefc730 100644 --- a/Flazzy/ABC/ASParameter.cs +++ b/Flazzy/ABC/ASParameter.cs @@ -1,86 +1,85 @@ -using System.Text; -using System.Diagnostics; +using System.Diagnostics; +using System.Text; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +[DebuggerDisplay("{ToString(),nq}")] +public class ASParameter { - [DebuggerDisplay("{ToString(),nq}")] - public class ASParameter - { - private readonly ASMethod _method; + private readonly ASMethod _method; - public int ValueIndex { get; set; } - public object Value => _method.ABC.Pool.GetConstant(ValueKind, ValueIndex); + public int ValueIndex { get; set; } + public object Value => _method.ABC.Pool.GetConstant(ValueKind, ValueIndex); - public int NameIndex { get; set; } - public string Name => _method.ABC.Pool.Strings[NameIndex]; + public int NameIndex { get; set; } + public string Name => _method.ABC.Pool.Strings[NameIndex]; - public int TypeIndex { get; set; } - public ASMultiname Type => _method.ABC.Pool.Multinames[TypeIndex]; + public int TypeIndex { get; set; } + public ASMultiname Type => _method.ABC.Pool.Multinames[TypeIndex]; - public bool IsOptional { get; set; } - public ConstantKind ValueKind { get; set; } + public bool IsOptional { get; set; } + public ConstantKind ValueKind { get; set; } - public ASParameter(ASMethod method) - { - _method = method; - } + public ASParameter(ASMethod method) + { + _method = method; + } - public override string ToString() + public override string ToString() + { + var builder = new StringBuilder(); + Append(builder); + return builder.ToString(); + } + internal void Append(StringBuilder builder, int? index = null) + { + if (string.IsNullOrWhiteSpace(Name)) { - var builder = new StringBuilder(); - Append(builder); - return builder.ToString(); + builder.Append("param"); + builder.Append(index ?? _method.Parameters.IndexOf(this) + 1); } - internal void Append(StringBuilder builder, int? index = null) + else builder.Append(Name); + + builder.Append(':'); // Separate the parameter name, and its type. + if (Type?.Kind == MultinameKind.TypeName) { - if (string.IsNullOrWhiteSpace(Name)) - { - builder.Append("param"); - builder.Append(index ?? _method.Parameters.IndexOf(this) + 1); - } - else builder.Append(Name); + builder.Append(Type.QName.Name); + builder.Append(".<"); - builder.Append(':'); // Separate the parameter name, and its type. - if (Type?.Kind == MultinameKind.TypeName) + foreach (ASMultiname multiname in Type.GetTypes()) { - builder.Append(Type.QName.Name); - builder.Append(".<"); - - foreach (ASMultiname multiname in Type.GetTypes()) - { - builder.Append(multiname?.Name ?? "*"); - builder.Append(", "); - } - builder.Length -= 2; // Ignore the last two characters, in this case being ", ". - builder.Append('>'); + builder.Append(multiname?.Name ?? "*"); + builder.Append(", "); } - else builder.Append(Type?.Name ?? "*"); + builder.Length -= 2; // Ignore the last two characters, in this case being ", ". + builder.Append('>'); + } + else builder.Append(Type?.Name ?? "*"); - if (IsOptional) + if (IsOptional) + { + builder.Append(" = "); + switch (ValueKind) { - builder.Append(" = "); - switch (ValueKind) - { - case ConstantKind.String: + case ConstantKind.String: builder.Append('"'); builder.Append(Value); builder.Append('"'); break; - case ConstantKind.Null: + case ConstantKind.Null: builder.Append("null"); break; - case ConstantKind.True: + case ConstantKind.True: builder.Append("true"); break; - case ConstantKind.False: + case ConstantKind.False: builder.Append("false"); break; - default: builder.Append(Value); break; - } + default: builder.Append(Value); break; } } } diff --git a/Flazzy/ABC/ASScript.cs b/Flazzy/ABC/ASScript.cs index 2a6f2b6..b1ac30a 100644 --- a/Flazzy/ABC/ASScript.cs +++ b/Flazzy/ABC/ASScript.cs @@ -1,28 +1,27 @@ using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASScript : ASContainer // TODO: Check QName usages { - public class ASScript : ASContainer // TODO: Check QName usages - { - public int InitializerIndex { get; set; } - public ASMethod Initializer => ABC.Methods[InitializerIndex]; + public int InitializerIndex { get; set; } + public ASMethod Initializer => ABC.Methods[InitializerIndex]; - public override ASMultiname QName => Traits[0].QName; + public override ASMultiname QName => Traits[0].QName; - public ASScript(ABCFile abc) - : base(abc) - { } - public ASScript(ABCFile abc, FlashReader input) - : base(abc) - { - InitializerIndex = input.ReadInt30(); - PopulateTraits(input); - } + public ASScript(ABCFile abc) + : base(abc) + { } + public ASScript(ABCFile abc, FlashReader input) + : base(abc) + { + InitializerIndex = input.ReadInt30(); + PopulateTraits(input); + } - public override void WriteTo(FlashWriter output) - { - output.WriteInt30(InitializerIndex); - base.WriteTo(output); - } + public override void WriteTo(FlashWriter output) + { + output.WriteInt30(InitializerIndex); + base.WriteTo(output); } } \ No newline at end of file diff --git a/Flazzy/ABC/ASTrait.cs b/Flazzy/ABC/ASTrait.cs index a5b67e0..0c8079f 100644 --- a/Flazzy/ABC/ASTrait.cs +++ b/Flazzy/ABC/ASTrait.cs @@ -1,96 +1,97 @@ using System.Text; + using Flazzy.IO; -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public class ASTrait : AS3Item, IMethodGSTrait, ISlotConstantTrait, IClassTrait, IFunctionTrait { - public class ASTrait : AS3Item, IMethodGSTrait, ISlotConstantTrait, IClassTrait, IFunctionTrait - { - public int QNameIndex { get; set; } - public ASMultiname QName => ABC.Pool.Multinames[QNameIndex]; + public int QNameIndex { get; set; } + public ASMultiname QName => ABC.Pool.Multinames[QNameIndex]; - public ASMultiname Type + public ASMultiname Type + { + get { - get + if (Kind == TraitKind.Slot || + Kind == TraitKind.Constant) { - if (Kind == TraitKind.Slot || - Kind == TraitKind.Constant) - { - return ABC.Pool.Multinames[TypeIndex]; - } - return null; + return ABC.Pool.Multinames[TypeIndex]; } + return null; } - public int TypeIndex { get; set; } + } + public int TypeIndex { get; set; } - public ASMethod Method + public ASMethod Method + { + get { - get + if (Kind == TraitKind.Method || + Kind == TraitKind.Getter || + Kind == TraitKind.Setter) { - if (Kind == TraitKind.Method || - Kind == TraitKind.Getter || - Kind == TraitKind.Setter) - { - return ABC.Methods[MethodIndex]; - } - return null; + return ABC.Methods[MethodIndex]; } + return null; } - public int MethodIndex { get; set; } + } + public int MethodIndex { get; set; } - public ASMethod Function + public ASMethod Function + { + get { - get - { - if (Kind != TraitKind.Function) return null; - return ABC.Methods[FunctionIndex]; - } + if (Kind != TraitKind.Function) return null; + return ABC.Methods[FunctionIndex]; } - public int FunctionIndex { get; set; } + } + public int FunctionIndex { get; set; } - public ASClass Class + public ASClass Class + { + get { - get - { - if (Kind != TraitKind.Class) return null; - return ABC.Classes[ClassIndex]; - } + if (Kind != TraitKind.Class) return null; + return ABC.Classes[ClassIndex]; } - public int ClassIndex { get; set; } + } + public int ClassIndex { get; set; } - public int ValueIndex { get; set; } - public object Value => ABC.Pool.GetConstant(ValueKind, ValueIndex); + public int ValueIndex { get; set; } + public object Value => ABC.Pool.GetConstant(ValueKind, ValueIndex); - public ConstantKind ValueKind { get; set; } + public ConstantKind ValueKind { get; set; } - public int Id { get; set; } - public List MetadataIndices { get; } + public int Id { get; set; } + public List MetadataIndices { get; } - public bool IsStatic { get; internal set; } + public bool IsStatic { get; internal set; } - public TraitKind Kind { get; set; } - public TraitAttributes Attributes { get; set; } + public TraitKind Kind { get; set; } + public TraitAttributes Attributes { get; set; } - protected override string DebuggerDisplay => (Kind + ": " + QName.Name); + protected override string DebuggerDisplay => (Kind + ": " + QName.Name); - public ASTrait(ABCFile abc) - : base(abc) - { - MetadataIndices = new List(); - } - public ASTrait(ABCFile abc, FlashReader input) - : this(abc) - { - QNameIndex = input.ReadInt30(); + public ASTrait(ABCFile abc) + : base(abc) + { + MetadataIndices = new List(); + } + public ASTrait(ABCFile abc, FlashReader input) + : this(abc) + { + QNameIndex = input.ReadInt30(); - byte bitContainer = input.ReadByte(); - Kind = (TraitKind)(bitContainer & 0x0F); - Attributes = (TraitAttributes)(bitContainer >> 4); + byte bitContainer = input.ReadByte(); + Kind = (TraitKind)(bitContainer & 0x0F); + Attributes = (TraitAttributes)(bitContainer >> 4); - Id = input.ReadInt30(); - switch (Kind) - { - case TraitKind.Slot: - case TraitKind.Constant: + Id = input.ReadInt30(); + switch (Kind) + { + case TraitKind.Slot: + case TraitKind.Constant: { TypeIndex = input.ReadInt30(); ValueIndex = input.ReadInt30(); @@ -101,114 +102,114 @@ public ASTrait(ABCFile abc, FlashReader input) break; } - case TraitKind.Method: - case TraitKind.Getter: - case TraitKind.Setter: + case TraitKind.Method: + case TraitKind.Getter: + case TraitKind.Setter: { MethodIndex = input.ReadInt30(); Method.Trait = this; break; } - case TraitKind.Class: + case TraitKind.Class: { ClassIndex = input.ReadInt30(); break; } - case TraitKind.Function: + case TraitKind.Function: { FunctionIndex = input.ReadInt30(); break; } - } + } - if (Attributes.HasFlag(TraitAttributes.Metadata)) + if (Attributes.HasFlag(TraitAttributes.Metadata)) + { + MetadataIndices.Capacity = input.ReadInt30(); + for (int i = 0; i < MetadataIndices.Capacity; i++) { - MetadataIndices.Capacity = input.ReadInt30(); - for (int i = 0; i < MetadataIndices.Capacity; i++) - { - int metadatumIndex = input.ReadInt30(); - MetadataIndices.Add(metadatumIndex); - } + int metadatumIndex = input.ReadInt30(); + MetadataIndices.Add(metadatumIndex); } } + } - public IEnumerable GetMetadata() + public IEnumerable GetMetadata() + { + for (int i = 0; i < MetadataIndices.Count; i++) { - for (int i = 0; i < MetadataIndices.Count; i++) - { - int metadatumIndex = MetadataIndices[i]; - ASMetadata metadatum = ABC.Metadata[metadatumIndex]; - yield return metadatum; - } + int metadatumIndex = MetadataIndices[i]; + ASMetadata metadatum = ABC.Metadata[metadatumIndex]; + yield return metadatum; } + } - public override string ToAS3() + public override string ToAS3() + { + switch (Kind) { - switch(Kind) - { - case TraitKind.Constant: - case TraitKind.Slot: + case TraitKind.Constant: + case TraitKind.Slot: + { + StringBuilder builder = new(); + if (Attributes.HasFlag(TraitAttributes.Override)) { - StringBuilder builder = new(); - if(Attributes.HasFlag(TraitAttributes.Override)) - { - builder.Append("override "); - } - var modifiers = QName.Namespace.GetAS3Modifiers(); - if(!string.IsNullOrEmpty(modifiers)) - { - builder.Append(modifiers); - builder.Append(' '); - } - if (IsStatic) - { - builder.Append("static "); - } - builder.Append(Kind == TraitKind.Constant ? "const " : "var "); - builder.Append(QName.Name); - if(Type != null) + builder.Append("override "); + } + var modifiers = QName.Namespace.GetAS3Modifiers(); + if (!string.IsNullOrEmpty(modifiers)) + { + builder.Append(modifiers); + builder.Append(' '); + } + if (IsStatic) + { + builder.Append("static "); + } + builder.Append(Kind == TraitKind.Constant ? "const " : "var "); + builder.Append(QName.Name); + if (Type != null) + { + builder.Append(':'); + builder.Append(Type.Name ?? Type.QName.Name); + if (Type.Kind == MultinameKind.TypeName) { - builder.Append(':'); - builder.Append(Type.Name ?? Type.QName.Name); - if (Type.Kind == MultinameKind.TypeName) - { - builder.Append(".<"); - builder.Append(string.Join(',', Type.TypeIndices.Select(i => ABC.Pool.Multinames[i].Name))); - builder.Append('>'); - } + builder.Append(".<"); + builder.Append(string.Join(',', Type.TypeIndices.Select(i => ABC.Pool.Multinames[i].Name))); + builder.Append('>'); } - if (!string.IsNullOrEmpty(Value?.ToString())) + } + if (!string.IsNullOrEmpty(Value?.ToString())) + { + builder.Append(" = "); + if (ValueKind == ConstantKind.String) { - builder.Append(" = "); - if (ValueKind == ConstantKind.String) - { - builder.Append('"'); - builder.Append(Value.ToString()); - builder.Append('"'); - } - else builder.Append(Value.ToString().ToLower()); + builder.Append('"'); + builder.Append(Value.ToString()); + builder.Append('"'); } - builder.Append(';'); - return builder.ToString(); + else builder.Append(Value.ToString().ToLower()); } - } - return string.Empty; + builder.Append(';'); + return builder.ToString(); + } } + return string.Empty; + } - public override void WriteTo(FlashWriter output) - { - var bitContainer = (byte)( - ((byte)Attributes << 4) + (byte)Kind); + public override void WriteTo(FlashWriter output) + { + var bitContainer = (byte)( + ((byte)Attributes << 4) + (byte)Kind); - output.WriteInt30(QNameIndex); - output.Write(bitContainer); - output.WriteInt30(Id); - switch (Kind) - { - case TraitKind.Slot: - case TraitKind.Constant: + output.WriteInt30(QNameIndex); + output.Write(bitContainer); + output.WriteInt30(Id); + switch (Kind) + { + case TraitKind.Slot: + case TraitKind.Constant: { output.WriteInt30(TypeIndex); output.WriteInt30(ValueIndex); @@ -219,35 +220,34 @@ public override void WriteTo(FlashWriter output) break; } - case TraitKind.Method: - case TraitKind.Getter: - case TraitKind.Setter: + case TraitKind.Method: + case TraitKind.Getter: + case TraitKind.Setter: { output.WriteInt30(MethodIndex); break; } - case TraitKind.Class: + case TraitKind.Class: { output.WriteInt30(ClassIndex); break; } - case TraitKind.Function: + case TraitKind.Function: { output.WriteInt30(FunctionIndex); break; } - } + } - if (Attributes.HasFlag(TraitAttributes.Metadata)) + if (Attributes.HasFlag(TraitAttributes.Metadata)) + { + output.WriteInt30(MetadataIndices.Count); + for (int i = 0; i < MetadataIndices.Count; i++) { - output.WriteInt30(MetadataIndices.Count); - for (int i = 0; i < MetadataIndices.Count; i++) - { - int metadatumIndex = MetadataIndices[i]; - output.WriteInt30(metadatumIndex); - } + int metadatumIndex = MetadataIndices[i]; + output.WriteInt30(metadatumIndex); } } } diff --git a/Flazzy/ABC/AVM2/ASCode.cs b/Flazzy/ABC/AVM2/ASCode.cs index 5eda79c..db95031 100644 --- a/Flazzy/ABC/AVM2/ASCode.cs +++ b/Flazzy/ABC/AVM2/ASCode.cs @@ -1,568 +1,592 @@ -using System.Diagnostics; -using System.Collections; +using System.Collections; +using System.Diagnostics; -using Flazzy.IO; using Flazzy.ABC.AVM2.Instructions; +using Flazzy.IO; -namespace Flazzy.ABC.AVM2 +namespace Flazzy.ABC.AVM2; + +[DebuggerDisplay("Count = {Count}")] +public class ASCode : FlashItem, IList { - [DebuggerDisplay("Count = {Count}")] - public class ASCode : FlashItem, IList - { - private readonly ABCFile _abc; - private readonly ASMethodBody _body; + private readonly ABCFile _abc; + private readonly ASMethodBody _body; - private readonly List _instructions; - private readonly Dictionary _indices; - private readonly Dictionary> _opGroups; + private readonly List _instructions; + private readonly Dictionary _indices; + private readonly Dictionary> _opGroups; - public Dictionary JumpExits { get; } - public Dictionary SwitchExits { get; } + public Dictionary JumpExits { get; } + public Dictionary SwitchExits { get; } - public bool IsReadOnly => false; - public int Count => _instructions.Count; + public bool IsReadOnly => false; + public int Count => _instructions.Count; - public ASInstruction this[int index] + public ASInstruction this[int index] + { + get => _instructions[index]; + set { - get => _instructions[index]; - set - { - ASInstruction previous = _instructions[index]; + ASInstruction previous = _instructions[index]; - Jumper jumper = GetJumperEntry(previous); - if (jumper != null) - { - JumpExits[jumper] = value; - } - foreach (LookUpSwitchIns @switch in SwitchExits.Keys) + Jumper jumper = GetJumperEntry(previous); + if (jumper != null) + { + JumpExits[jumper] = value; + } + foreach (LookUpSwitchIns @switch in SwitchExits.Keys) + { + ASInstruction[] exits = SwitchExits[@switch]; + for (int i = 0; i < exits.Length; i++) { - ASInstruction[] exits = SwitchExits[@switch]; - for (int i = 0; i < exits.Length; i++) - { - ASInstruction exit = exits[i]; - if (previous != exit) continue; + ASInstruction exit = exits[i]; + if (previous != exit) continue; - exits[i] = value; - } + exits[i] = value; } + } - // Properly replaces the jump instruction with a new one. - if (Jumper.IsValid(previous.OP) && Jumper.IsValid(value.OP)) - { - jumper = (Jumper)value; - var previousJumper = (Jumper)previous; - - // Use the same offset of the previous jump instruction if the new jump instruction has the default offset '0'. - if (jumper.Offset == default) - { - jumper.Offset = previousJumper.Offset; - } + // Properly replaces the jump instruction with a new one. + if (Jumper.IsValid(previous.OP) && Jumper.IsValid(value.OP)) + { + jumper = (Jumper)value; + var previousJumper = (Jumper)previous; - // It is important to link the new jump instruction with an exit instruction, as this will re-determine the offset of the jump if a rebuild is required. - ASInstruction exit = JumpExits[previousJumper]; - JumpExits.Remove(previousJumper); - JumpExits.Add(jumper, exit); + // Use the same offset of the previous jump instruction if the new jump instruction has the default offset '0'. + if (jumper.Offset == default) + { + jumper.Offset = previousJumper.Offset; } - _indices.Remove(previous); - _indices.Add(value, index); - _instructions[index] = value; + // It is important to link the new jump instruction with an exit instruction, as this will re-determine the offset of the jump if a rebuild is required. + ASInstruction exit = JumpExits[previousJumper]; + JumpExits.Remove(previousJumper); + JumpExits.Add(jumper, exit); } + + _indices.Remove(previous); + _indices.Add(value, index); + _instructions[index] = value; } + } - public ASCode(ABCFile abc, ASMethodBody body) - { - _abc = abc; - _body = body; + public ASCode(ABCFile abc, ASMethodBody body) + { + _abc = abc; + _body = body; - _instructions = new List(); - _indices = new Dictionary(); - _opGroups = new Dictionary>(); + _instructions = new List(); + _indices = new Dictionary(); + _opGroups = new Dictionary>(); - JumpExits = new Dictionary(); - SwitchExits = new Dictionary(); + JumpExits = new Dictionary(); + SwitchExits = new Dictionary(); - LoadInstructions(); - } + LoadInstructions(); + } - public void Add(ASInstruction instruction) + public void Add(ASInstruction instruction) + { + Insert(_instructions.Count, instruction); + } + public bool Remove(ASInstruction instruction) + { + if (_indices.TryGetValue(instruction, out int index)) { - Insert(_instructions.Count, instruction); - } - public bool Remove(ASInstruction instruction) - { - if (_indices.TryGetValue(instruction, out int index)) - { - RemoveAt(index); - } - return index > -1; + RemoveAt(index); } + return index > -1; + } - public void RemoveAt(int index) - { - RemoveRange(index, 1); - } - public void Insert(int index, ASInstruction instruction) - { - InsertRange(index, new[] { instruction }); - } + public void RemoveAt(int index) + { + RemoveRange(index, 1); + } + public void Insert(int index, ASInstruction instruction) + { + InsertRange(index, new[] { instruction }); + } - public void RemoveRange(int index, int count) + public void RemoveRange(int index, int count) + { + if ((index + count) <= _instructions.Count) { - if ((index + count) <= _instructions.Count) + for (int i = 0; i < count; i++) { - for (int i = 0; i < count; i++) - { - ASInstruction instruction = _instructions[index]; - _indices.Remove(instruction); - _instructions.RemoveAt(index); + ASInstruction instruction = _instructions[index]; + _indices.Remove(instruction); + _instructions.RemoveAt(index); - List group = _opGroups[instruction.OP]; - if (group.Count == 1) - { - _opGroups.Remove(instruction.OP); - } - else group.Remove(instruction); + List group = _opGroups[instruction.OP]; + if (group.Count == 1) + { + _opGroups.Remove(instruction.OP); + } + else group.Remove(instruction); - Jumper entry = GetJumperEntry(instruction); - if (entry != null) + Jumper entry = GetJumperEntry(instruction); + if (entry != null) + { + if (index != _instructions.Count) { - if (index != _instructions.Count) - { - JumpExits[entry] = _instructions[index]; - } - else JumpExits[entry] = null; + JumpExits[entry] = _instructions[index]; } - foreach (LookUpSwitchIns @switch in SwitchExits.Keys) + else JumpExits[entry] = null; + } + foreach (LookUpSwitchIns @switch in SwitchExits.Keys) + { + ASInstruction[] exits = SwitchExits[@switch]; + for (int j = 0; j < exits.Length; j++) { - ASInstruction[] exits = SwitchExits[@switch]; - for (int j = 0; j < exits.Length; j++) - { - ASInstruction exit = exits[j]; - if (instruction != exit) continue; + ASInstruction exit = exits[j]; + if (instruction != exit) continue; - exits[j] = _instructions[index]; - } + exits[j] = _instructions[index]; } + } - if (Jumper.IsValid(instruction.OP)) - { - JumpExits.Remove((Jumper)instruction); - } - else if (instruction.OP == OPCode.LookUpSwitch) - { - SwitchExits.Remove((LookUpSwitchIns)instruction); - } + if (Jumper.IsValid(instruction.OP)) + { + JumpExits.Remove((Jumper)instruction); } - for (int i = index; i < _indices.Count; i++) + else if (instruction.OP == OPCode.LookUpSwitch) { - ASInstruction toPull = _instructions[i]; - _indices[toPull] -= count; + SwitchExits.Remove((LookUpSwitchIns)instruction); } } + for (int i = index; i < _indices.Count; i++) + { + ASInstruction toPull = _instructions[i]; + _indices[toPull] -= count; + } } - public void AddRange(IEnumerable collection) - { - InsertRange(_instructions.Count, collection); - } - public void InsertRange(int index, IEnumerable collection) + } + public void AddRange(IEnumerable collection) + { + InsertRange(_instructions.Count, collection); + } + public void InsertRange(int index, IEnumerable collection) + { + if (index <= _instructions.Count && collection.Any()) { - if (index <= _instructions.Count && collection.Any()) - { - var deadJumps = new Stack(JumpExits - .Where(je => je.Value == null) - .Select(je => je.Key)); + var deadJumps = new Stack(JumpExits + .Where(je => je.Value == null) + .Select(je => je.Key)); - int count = _instructions.Count; - if (index == _instructions.Count) - { - _instructions.AddRange(collection); - } - else _instructions.InsertRange(index, collection); - int collectionCount = (_instructions.Count - count); + int count = _instructions.Count; + if (index == _instructions.Count) + { + _instructions.AddRange(collection); + } + else _instructions.InsertRange(index, collection); + int collectionCount = (_instructions.Count - count); - while (deadJumps.Count > 0) - { - JumpExits[deadJumps.Pop()] = collection.First(); - } + while (deadJumps.Count > 0) + { + JumpExits[deadJumps.Pop()] = collection.First(); + } - for (int i = (index + collectionCount - 1); i >= index; i--) - { - ASInstruction instruction = _instructions[i]; - _indices.Add(instruction, i); + for (int i = (index + collectionCount - 1); i >= index; i--) + { + ASInstruction instruction = _instructions[i]; + _indices.Add(instruction, i); - if (!_opGroups.TryGetValue(instruction.OP, out List instructions)) - { - instructions = new List(); - _opGroups.Add(instruction.OP, instructions); - } - instructions.Add(instruction); - } - for (int i = (index + collectionCount); i < _instructions.Count; i++) + if (!_opGroups.TryGetValue(instruction.OP, out List instructions)) { - ASInstruction toPush = _instructions[i]; - _indices[toPush] += collectionCount; + instructions = new List(); + _opGroups.Add(instruction.OP, instructions); } + instructions.Add(instruction); } - } - - public void Clear() - { - _indices.Clear(); - _opGroups.Clear(); - _instructions.Clear(); - - JumpExits.Clear(); - SwitchExits.Clear(); - } - public bool Contains(OPCode op) - { - return _opGroups.ContainsKey(op); - } - public bool Contains(ASInstruction instruction) - { - if (_opGroups.TryGetValue(instruction.OP, out List group)) + for (int i = (index + collectionCount); i < _instructions.Count; i++) { - return group.Contains(instruction); + ASInstruction toPush = _instructions[i]; + _indices[toPush] += collectionCount; } - return false; } + } - public void CopyTo(ASInstruction[] array) - { - CopyTo(array, 0); - } - public void CopyTo(ASInstruction[] array, int arrayIndex) - { - CopyTo(0, array, arrayIndex, array.Length); - } - public void CopyTo(int index, ASInstruction[] array, int arrayIndex, int count) + public void Clear() + { + _indices.Clear(); + _opGroups.Clear(); + _instructions.Clear(); + + JumpExits.Clear(); + SwitchExits.Clear(); + } + public bool Contains(OPCode op) + { + return _opGroups.ContainsKey(op); + } + public bool Contains(ASInstruction instruction) + { + if (_opGroups.TryGetValue(instruction.OP, out List group)) { - _instructions.CopyTo(index, array, arrayIndex, count); + return group.Contains(instruction); } + return false; + } + + public void CopyTo(ASInstruction[] array) + { + CopyTo(array, 0); + } + public void CopyTo(ASInstruction[] array, int arrayIndex) + { + CopyTo(0, array, arrayIndex, array.Length); + } + public void CopyTo(int index, ASInstruction[] array, int arrayIndex, int count) + { + _instructions.CopyTo(index, array, arrayIndex, count); + } - public int IndexOf(OPCode op) + public int IndexOf(OPCode op) + { + if (_opGroups.ContainsKey(op)) { - if (_opGroups.ContainsKey(op)) - { - List instructions = _opGroups[op]; - return _indices[instructions[0]]; - } - return -1; + List instructions = _opGroups[op]; + return _indices[instructions[0]]; } - public int IndexOf(ASInstruction instruction) + return -1; + } + public int IndexOf(ASInstruction instruction) + { + if (_indices.ContainsKey(instruction)) { - if (_indices.ContainsKey(instruction)) - { - return _indices[instruction]; - } - return -1; + return _indices[instruction]; } - public bool StartsWith(params OPCode[] operations) + return -1; + } + public bool StartsWith(params OPCode[] operations) + { + for (int i = 0; i < operations.Length; i++) { - for (int i = 0; i < operations.Length; i++) + if (_instructions[i].OP != operations[i]) { - if (_instructions[i].OP != operations[i]) - { - return false; - } + return false; } - return (operations.Length > 0); } + return (operations.Length > 0); + } - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)_instructions).GetEnumerator(); - } - public IEnumerator GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)_instructions).GetEnumerator(); + } + public IEnumerator GetEnumerator() + { + return _instructions.GetEnumerator(); + } + + public void Deobfuscate() + { + var machine = new ASMachine(_body.LocalCount + _body.Method.Parameters.Count + 1); // Scope + Parameters + Function Locals + for (int i = 0; i <= _body.Method.Parameters.Count; i++) // Add the instance scope, and the method parameters to the register. { - return _instructions.GetEnumerator(); + machine.Registers.Add(i, null); } - public void Deobfuscate() + var cleaned = new List(_instructions.Count); + var valuePushers = new Stack(_body.MaxStack); + var localReferences = new Dictionary>(); + var localConversions = new Dictionary>(); + var swappedValues = new Dictionary(); + KeyValuePair[] jumpExits = JumpExits.ToArray(); + KeyValuePair[] switchExits = SwitchExits.ToArray(); + for (int i = 0; i < _instructions.Count; i++) { - var machine = new ASMachine(_body.LocalCount + _body.Method.Parameters.Count + 1); // Scope + Parameters + Function Locals - for (int i = 0; i <= _body.Method.Parameters.Count; i++) // Add the instance scope, and the method parameters to the register. + ASInstruction instruction = _instructions[i]; + if (Jumper.IsValid(instruction.OP)) { - machine.Registers.Add(i, null); + i += GetFinalJumpCount(machine, (Jumper)instruction, cleaned, localReferences, valuePushers); } - - var cleaned = new List(_instructions.Count); - var valuePushers = new Stack(_body.MaxStack); - var localReferences = new Dictionary>(); - var localConversions = new Dictionary>(); - var swappedValues = new Dictionary(); - KeyValuePair[] jumpExits = JumpExits.ToArray(); - KeyValuePair[] switchExits = SwitchExits.ToArray(); - for (int i = 0; i < _instructions.Count; i++) + else { - ASInstruction instruction = _instructions[i]; - if (Jumper.IsValid(instruction.OP)) + if (instruction.OP == OPCode.NewFunction && _instructions[i + 1].OP == OPCode.Pop) { - i += GetFinalJumpCount(machine, (Jumper)instruction, cleaned, localReferences, valuePushers); + i++; // This function is not utilized, based on the upcoming instruction; Skip them both. + continue; } - else + + if (instruction.OP == OPCode.Not) { - if (instruction.OP == OPCode.NewFunction && _instructions[i + 1].OP == OPCode.Pop) + ASInstruction previousIns = cleaned[^1]; + if (previousIns.OP == OPCode.PushTrue || previousIns.OP == OPCode.PushFalse) { - i++; // This function is not utilized, based on the upcoming instruction; Skip them both. - continue; - } + valuePushers.Pop(); + ASInstruction replacementIns = previousIns.OP == OPCode.PushTrue ? new PushFalseIns() : new PushTrueIns(); - if (instruction.OP == OPCode.Not) - { - ASInstruction previousIns = cleaned[^1]; - if (previousIns.OP == OPCode.PushTrue || previousIns.OP == OPCode.PushFalse) - { - valuePushers.Pop(); - ASInstruction replacementIns = previousIns.OP == OPCode.PushTrue ? new PushFalseIns() : new PushTrueIns(); + valuePushers.Push(replacementIns); + cleaned[^1] = replacementIns; - valuePushers.Push(replacementIns); - cleaned[^1] = replacementIns; - - machine.Values.Pop(); - replacementIns.Execute(machine); - continue; - } + machine.Values.Pop(); + replacementIns.Execute(machine); + continue; } - if (Local.IsGetLocal(instruction.OP)) + } + if (Local.IsGetLocal(instruction.OP)) + { + var local = (Local)instruction; + if (!machine.Registers.ContainsKey(local.Register)) { - var local = (Local)instruction; - if (!machine.Registers.ContainsKey(local.Register)) - { - instruction = new PushFalseIns(); - } + instruction = new PushFalseIns(); } + } + + instruction.Execute(machine); + #region Arithmetic Optimization + if (Computation.IsValid(instruction.OP)) + { + object result = machine.Values.Pop(); + ASInstruction rightPusher = valuePushers.Pop(); + ASInstruction leftPusher = valuePushers.Pop(); - instruction.Execute(machine); - #region Arithmetic Optimization - if (Computation.IsValid(instruction.OP)) + if (!IsRelyingOnLocals(leftPusher, localConversions) && !IsRelyingOnLocals(rightPusher, localConversions) && + !Local.IsValid(leftPusher.OP) && !Local.IsValid(rightPusher.OP) && result != null) { - object result = machine.Values.Pop(); - ASInstruction rightPusher = valuePushers.Pop(); - ASInstruction leftPusher = valuePushers.Pop(); + // Constant values found, push result instead of having it do the calculation everytime. + cleaned.Remove(leftPusher); + cleaned.Remove(rightPusher); + instruction = Primitive.Create(_abc, result); - if (!IsRelyingOnLocals(leftPusher, localConversions) && !IsRelyingOnLocals(rightPusher, localConversions) && - !Local.IsValid(leftPusher.OP) && !Local.IsValid(rightPusher.OP) && result != null) + foreach (KeyValuePair jumpExit in jumpExits) { - // Constant values found, push result instead of having it do the calculation everytime. - cleaned.Remove(leftPusher); - cleaned.Remove(rightPusher); - instruction = Primitive.Create(_abc, result); - - foreach (KeyValuePair jumpExit in jumpExits) + if (leftPusher == jumpExit.Value) { - if (leftPusher == jumpExit.Value) - { - JumpExits[jumpExit.Key] = instruction; - // Do not break, another jump instruction can share the same exit. - } + JumpExits[jumpExit.Key] = instruction; + // Do not break, another jump instruction can share the same exit. } - foreach (KeyValuePair switchExit in switchExits) + } + foreach (KeyValuePair switchExit in switchExits) + { + ASInstruction[] cases = switchExit.Value; + for (int j = 0; j < cases.Length; j++) { - ASInstruction[] cases = switchExit.Value; - for (int j = 0; j < cases.Length; j++) + ASInstruction exit = cases[j]; + if (leftPusher == exit) { - ASInstruction exit = cases[j]; - if (leftPusher == exit) - { - cases[j] = instruction; - } + cases[j] = instruction; } } - instruction.Execute(machine); - } - else - { - // Do not attempt to optimize when a local is being used, because these values can still change. - valuePushers.Push(leftPusher); - valuePushers.Push(rightPusher); - machine.Values.Push(result); } + instruction.Execute(machine); } - #endregion - cleaned.Add(instruction); - - ASInstruction[] swaps = null; - List references = null; - if (Local.IsValid(instruction.OP)) + else { - var local = (Local)instruction; - if (!localReferences.TryGetValue(local.Register, out references)) - { - references = new List(); - localReferences[local.Register] = references; - } - references.Add(instruction); + // Do not attempt to optimize when a local is being used, because these values can still change. + valuePushers.Push(leftPusher); + valuePushers.Push(rightPusher); + machine.Values.Push(result); } - else if (instruction.OP == OPCode.Swap) + } + #endregion + cleaned.Add(instruction); + + ASInstruction[] swaps = null; + List references = null; + if (Local.IsValid(instruction.OP)) + { + var local = (Local)instruction; + if (!localReferences.TryGetValue(local.Register, out references)) { - swaps = new ASInstruction[2]; - swappedValues[instruction] = swaps; + references = new List(); + localReferences[local.Register] = references; } + references.Add(instruction); + } + else if (instruction.OP == OPCode.Swap) + { + swaps = new ASInstruction[2]; + swappedValues[instruction] = swaps; + } - int popCount = instruction.GetPopCount(); - for (int j = 0; j < popCount; j++) + int popCount = instruction.GetPopCount(); + for (int j = 0; j < popCount; j++) + { + ASInstruction pusher = valuePushers.Pop(); + if (Local.IsValid(pusher.OP) && instruction.OP != OPCode.PushScope) { - ASInstruction pusher = valuePushers.Pop(); - if (Local.IsValid(pusher.OP) && instruction.OP != OPCode.PushScope) - { - if (!localConversions.TryGetValue(instruction, out List locals)) - { - locals = new List(); - localConversions.Add(instruction, locals); - } - locals.Add((Local)pusher); - } - - references?.Add(pusher); - if (swaps != null) + if (!localConversions.TryGetValue(instruction, out List locals)) { - swaps[j] = pusher; + locals = new List(); + localConversions.Add(instruction, locals); } + locals.Add((Local)pusher); } - int pushCount = instruction.GetPushCount(); - for (int j = 0; j < pushCount; j++) + + references?.Add(pusher); + if (swaps != null) { - valuePushers.Push(instruction); + swaps[j] = pusher; } } + int pushCount = instruction.GetPushCount(); + for (int j = 0; j < pushCount; j++) + { + valuePushers.Push(instruction); + } } + } - // Remove dead locals. - foreach (KeyValuePair> local in localReferences) - { - if (local.Key == 0) continue; // Scope - if (local.Key <= (_body.Method.Parameters.Count)) continue; // Register == Param #(Non-zero based) - List references = localReferences[local.Key]; + // Remove dead locals. + foreach (KeyValuePair> local in localReferences) + { + if (local.Key == 0) continue; // Scope + if (local.Key <= (_body.Method.Parameters.Count)) continue; // Register == Param #(Non-zero based) + List references = localReferences[local.Key]; - bool isNeeded = false; - foreach (ASInstruction reference in references) + bool isNeeded = false; + foreach (ASInstruction reference in references) + { + // This checks if the local is being referenced by something else that retrieves the value. + if (Local.IsValid(reference.OP) && !Local.IsSetLocal(reference.OP)) { - // This checks if the local is being referenced by something else that retrieves the value. - if (Local.IsValid(reference.OP) && !Local.IsSetLocal(reference.OP)) - { - isNeeded = true; - break; - } + isNeeded = true; + break; } - if (!isNeeded) + } + if (!isNeeded) + { + foreach (ASInstruction reference in references) { - foreach (ASInstruction reference in references) + if (reference.OP == OPCode.Swap) { - if (reference.OP == OPCode.Swap) + ASInstruction[] swaps = swappedValues[reference]; + foreach (ASInstruction swap in swaps) { - ASInstruction[] swaps = swappedValues[reference]; - foreach (ASInstruction swap in swaps) - { - cleaned.Remove(swap); - } + cleaned.Remove(swap); } - cleaned.Remove(reference); } + cleaned.Remove(reference); } } + } - switchExits = SwitchExits.ToArray(); - foreach (KeyValuePair switchExit in switchExits) + switchExits = SwitchExits.ToArray(); + foreach (KeyValuePair switchExit in switchExits) + { + foreach (ASInstruction exit in switchExit.Value) { - foreach (ASInstruction exit in switchExit.Value) + if (IndexOf(switchExit.Key) > IndexOf(exit)) continue; + if (cleaned.Contains(switchExit.Key) && !cleaned.Contains(exit)) { - if (IndexOf(switchExit.Key) > IndexOf(exit)) continue; - if (cleaned.Contains(switchExit.Key) && !cleaned.Contains(exit)) - { - // TODO: Handle missing switch cases. - } + // TODO: Handle missing switch cases. } } + } - jumpExits = JumpExits.ToArray(); // Global property could have been updated. - foreach (KeyValuePair jumpExit in jumpExits) - { - // This is not a forward jump instruction, since the exit appears before the jump. - if (IndexOf(jumpExit.Key) > IndexOf(jumpExit.Value)) continue; + jumpExits = JumpExits.ToArray(); // Global property could have been updated. + foreach (KeyValuePair jumpExit in jumpExits) + { + // This is not a forward jump instruction, since the exit appears before the jump. + if (IndexOf(jumpExit.Key) > IndexOf(jumpExit.Value)) continue; - // True if it still has the jump instruction, but the instruction needed to determine the final instruction to jump is not present. - if (cleaned.Contains(jumpExit.Key) && !cleaned.Contains(jumpExit.Value)) + // True if it still has the jump instruction, but the instruction needed to determine the final instruction to jump is not present. + if (cleaned.Contains(jumpExit.Key) && !cleaned.Contains(jumpExit.Value)) + { + // Start at the index of the instruction that should come after the final instruction to jump. + for (int j = (_indices[jumpExit.Value] + 1); j < _instructions.Count; j++) { - // Start at the index of the instruction that should come after the final instruction to jump. - for (int j = (_indices[jumpExit.Value] + 1); j < _instructions.Count; j++) + ASInstruction afterEnd = _instructions[j]; + int exitIndex = cleaned.IndexOf(afterEnd); + if (exitIndex != -1) // Does this instruction exist in the cleaned output?; Otherwise, get instruction that comes after it. { - ASInstruction afterEnd = _instructions[j]; - int exitIndex = cleaned.IndexOf(afterEnd); - if (exitIndex != -1) // Does this instruction exist in the cleaned output?; Otherwise, get instruction that comes after it. - { - JumpExits[jumpExit.Key] = cleaned[exitIndex]; - break; - } + JumpExits[jumpExit.Key] = cleaned[exitIndex]; + break; } } } - - _instructions.Clear(); - _instructions.AddRange(cleaned); - Recalibrate(); } - public bool IsBackwardsJump(Jumper jumper) + + _instructions.Clear(); + _instructions.AddRange(cleaned); + Recalibrate(); + } + public bool IsBackwardsJump(Jumper jumper) + { + return IndexOf(jumper) > IndexOf(JumpExits[jumper]); + } + public Jumper GetJumperEntry(ASInstruction exit) + { + foreach (KeyValuePair jumpExit in JumpExits) { - return IndexOf(jumper) > IndexOf(JumpExits[jumper]); + if (jumpExit.Value != exit) continue; + return jumpExit.Key; } - public Jumper GetJumperEntry(ASInstruction exit) + return null; + } + public ASInstruction[] GetJumpBlock(Jumper jumper) + { + int blockStart = (_indices[jumper] + 1); + int scopeEnd = _indices[JumpExits[jumper]]; + + var body = new ASInstruction[scopeEnd - blockStart]; + _instructions.CopyTo(blockStart, body, 0, body.Length); + + return body; + } + public LookUpSwitchIns GetSwitchEntry(ASInstruction exit) + { + foreach (KeyValuePair switchExit in SwitchExits) { - foreach (KeyValuePair jumpExit in JumpExits) - { - if (jumpExit.Value != exit) continue; - return jumpExit.Key; - } - return null; + if (!switchExit.Value.Contains(exit)) continue; + return switchExit.Key; } - public ASInstruction[] GetJumpBlock(Jumper jumper) - { - int blockStart = (_indices[jumper] + 1); - int scopeEnd = _indices[JumpExits[jumper]]; - - var body = new ASInstruction[scopeEnd - blockStart]; - _instructions.CopyTo(blockStart, body, 0, body.Length); + return null; + } - return body; + public IEnumerable GetOPGroup(OPCode op) + { + if (_opGroups.ContainsKey(op)) + { + return _opGroups[op]; } - public LookUpSwitchIns GetSwitchEntry(ASInstruction exit) + return Enumerable.Empty(); + } + public SortedDictionary> GetOPGroups() + { + var groups = new SortedDictionary>(); + foreach (OPCode op in _opGroups.Keys) { - foreach (KeyValuePair switchExit in SwitchExits) - { - if (!switchExit.Value.Contains(exit)) continue; - return switchExit.Key; - } - return null; + groups[op] = new List(); + groups[op].AddRange(_opGroups[op]); } + return groups; + } - public IEnumerable GetOPGroup(OPCode op) + private void Recalibrate() + { + _indices.Clear(); + _opGroups.Clear(); + for (int i = 0; i < _instructions.Count; i++) { - if (_opGroups.ContainsKey(op)) + ASInstruction instruction = _instructions[i]; + _indices.Add(instruction, i); + + if (!_opGroups.TryGetValue(instruction.OP, out List instructions)) { - return _opGroups[op]; + instructions = new List(); + _opGroups.Add(instruction.OP, instructions); } - return Enumerable.Empty(); + instructions.Add(instruction); } - public SortedDictionary> GetOPGroups() + } + private void LoadInstructions() + { + var marks = new Dictionary(); + var sharedExits = new Dictionary>(); + var switchCases = new Dictionary>(); + using (var input = new FlashReader(_body.Code)) { - var groups = new SortedDictionary>(); - foreach (OPCode op in _opGroups.Keys) + while (input.IsDataAvailable) { - groups[op] = new List(); - groups[op].AddRange(_opGroups[op]); - } - return groups; - } + long previousPosition = input.Position; + var instruction = ASInstruction.Create(_abc, input); + marks[previousPosition] = instruction; - private void Recalibrate() - { - _indices.Clear(); - _opGroups.Clear(); - for (int i = 0; i < _instructions.Count; i++) - { - ASInstruction instruction = _instructions[i]; - _indices.Add(instruction, i); + _indices.Add(instruction, _indices.Count); + _instructions.Add(instruction); if (!_opGroups.TryGetValue(instruction.OP, out List instructions)) { @@ -570,361 +594,336 @@ private void Recalibrate() _opGroups.Add(instruction.OP, instructions); } instructions.Add(instruction); - } - } - private void LoadInstructions() - { - var marks = new Dictionary(); - var sharedExits = new Dictionary>(); - var switchCases = new Dictionary>(); - using (var input = new FlashReader(_body.Code)) - { - while (input.IsDataAvailable) - { - long previousPosition = input.Position; - var instruction = ASInstruction.Create(_abc, input); - marks[previousPosition] = instruction; - - _indices.Add(instruction, _indices.Count); - _instructions.Add(instruction); - if (!_opGroups.TryGetValue(instruction.OP, out List instructions)) + if (sharedExits.TryGetValue(previousPosition, out List jumpers)) + { + // This is an exit position two or more jump instructions. + foreach (Jumper jumper in jumpers) { - instructions = new List(); - _opGroups.Add(instruction.OP, instructions); + JumpExits.Add(jumper, instruction); } - instructions.Add(instruction); + sharedExits.Remove(previousPosition); + } - if (sharedExits.TryGetValue(previousPosition, out List jumpers)) + if (switchCases.TryGetValue(previousPosition, out List<(LookUpSwitchIns, int)> caseExits)) + { + foreach ((LookUpSwitchIns owner, int index) in caseExits) { - // This is an exit position two or more jump instructions. - foreach (Jumper jumper in jumpers) - { - JumpExits.Add(jumper, instruction); - } - sharedExits.Remove(previousPosition); + SwitchExits[owner][index] = instruction; } + switchCases.Remove(previousPosition); + } - if (switchCases.TryGetValue(previousPosition, out List<(LookUpSwitchIns, int)> caseExits)) - { - foreach ((LookUpSwitchIns owner, int index) in caseExits) - { - SwitchExits[owner][index] = instruction; - } - switchCases.Remove(previousPosition); - } + if (instruction.OP == OPCode.LookUpSwitch) + { + var lookUpSwitchIns = (LookUpSwitchIns)instruction; + var offsets = new List(lookUpSwitchIns.CaseOffsets) { lookUpSwitchIns.DefaultOffset }; - if (instruction.OP == OPCode.LookUpSwitch) + var exits = new ASInstruction[offsets.Count]; + for (int i = 0; i < offsets.Count; i++) { - var lookUpSwitchIns = (LookUpSwitchIns)instruction; - var offsets = new List(lookUpSwitchIns.CaseOffsets) { lookUpSwitchIns.DefaultOffset }; - - var exits = new ASInstruction[offsets.Count]; - for (int i = 0; i < offsets.Count; i++) + long exitPosition = previousPosition + offsets[i]; + if (exitPosition <= input.Length) { - long exitPosition = previousPosition + offsets[i]; - if (exitPosition <= input.Length) + if (!switchCases.TryGetValue(exitPosition, out caseExits)) { - if (!switchCases.TryGetValue(exitPosition, out caseExits)) - { - caseExits = new List<(LookUpSwitchIns, int)>(); - switchCases.Add(exitPosition, caseExits); - } - caseExits.Add((lookUpSwitchIns, i)); + caseExits = new List<(LookUpSwitchIns, int)>(); + switchCases.Add(exitPosition, caseExits); } - else exits[i] = marks[exitPosition - uint.MaxValue - 1]; + caseExits.Add((lookUpSwitchIns, i)); } - SwitchExits.Add(lookUpSwitchIns, exits); + else exits[i] = marks[exitPosition - uint.MaxValue - 1]; } - else if (Jumper.IsValid(instruction.OP)) - { - var jumper = (Jumper)instruction; - if (jumper.Offset == 0) continue; + SwitchExits.Add(lookUpSwitchIns, exits); + } + else if (Jumper.IsValid(instruction.OP)) + { + var jumper = (Jumper)instruction; + if (jumper.Offset == 0) continue; - long exitPosition = (input.Position + jumper.Offset); - if (exitPosition == input.Length) - { - // Jump exit does not exist at this (non-existent)index, do not look for exit. - continue; - } - else if (exitPosition < input.Length) // Forward jump. + long exitPosition = (input.Position + jumper.Offset); + if (exitPosition == input.Length) + { + // Jump exit does not exist at this (non-existent)index, do not look for exit. + continue; + } + else if (exitPosition < input.Length) // Forward jump. + { + if (!sharedExits.TryGetValue(exitPosition, out jumpers)) { - if (!sharedExits.TryGetValue(exitPosition, out jumpers)) - { - jumpers = new List(); - sharedExits.Add(exitPosition, jumpers); - } - jumpers.Add(jumper); + jumpers = new List(); + sharedExits.Add(exitPosition, jumpers); } - else // Backwards jump. + jumpers.Add(jumper); + } + else // Backwards jump. + { + long markIndex = exitPosition - uint.MaxValue - 1; + if (marks[markIndex].OP == OPCode.Label) { - long markIndex = exitPosition - uint.MaxValue - 1; - if (marks[markIndex].OP == OPCode.Label) - { - var label = (LabelIns)marks[markIndex]; - JumpExits.Add(jumper, label); - } - // TODO: Check if not adding an impossible label is fine... + var label = (LabelIns)marks[markIndex]; + JumpExits.Add(jumper, label); } + // TODO: Check if not adding an impossible label is fine... } } } } - private void Rewrite(FlashWriter output, ASInstruction instruction, long position) - { - long currentPosition = output.Position; - output.Position = position; + } + private void Rewrite(FlashWriter output, ASInstruction instruction, long position) + { + long currentPosition = output.Position; + output.Position = position; - instruction.WriteTo(output); - output.Position = currentPosition; - } - private bool IsRelyingOnLocals(ASInstruction instruction, Dictionary> conversions) => conversions.GetValueOrDefault(instruction) != null; - private int GetFinalJumpCount(ASMachine machine, Jumper jumper, List cleaned, Dictionary> localReferences, Stack valuePushers) + instruction.WriteTo(output); + output.Position = currentPosition; + } + private bool IsRelyingOnLocals(ASInstruction instruction, Dictionary> conversions) => conversions.GetValueOrDefault(instruction) != null; + private int GetFinalJumpCount(ASMachine machine, Jumper jumper, List cleaned, Dictionary> localReferences, Stack valuePushers) + { + var magicCount = 0; + var locals = new List(); + var pushers = new List(); + bool? isJumping = jumper.RunCondition(machine); + + // Get the instructions that pushed the values the jump instruction used. + int popCount = jumper.GetPopCount(); + for (int i = 0; i < popCount; i++) { - var magicCount = 0; - var locals = new List(); - var pushers = new List(); - bool? isJumping = jumper.RunCondition(machine); - - // Get the instructions that pushed the values the jump instruction used. - int popCount = jumper.GetPopCount(); - for (int i = 0; i < popCount; i++) + ASInstruction pusher = valuePushers.Pop(); + if (!pushers.Contains(pusher)) { - ASInstruction pusher = valuePushers.Pop(); - if (!pushers.Contains(pusher)) + pushers.Add(pusher); + // Get the instructions that were pushed by a GetLocal/N. + // These are used to determine whether the jump should be kept, since a local register could change within the jump body. + if (Local.IsValid(pusher.OP)) { - pushers.Add(pusher); - // Get the instructions that were pushed by a GetLocal/N. - // These are used to determine whether the jump should be kept, since a local register could change within the jump body. - if (Local.IsValid(pusher.OP)) - { - locals.Add((Local)pusher); - } - else if (Primitive.IsValid(pusher.OP) || pusher.OP == OPCode.Dup) - { - magicCount++; - } + locals.Add((Local)pusher); + } + else if (Primitive.IsValid(pusher.OP) || pusher.OP == OPCode.Dup) + { + magicCount++; } } + } - // Output is not known, keep the instruction. - if (isJumping == null) - { - cleaned.Add(jumper); - return 0; - } + // Output is not known, keep the instruction. + if (isJumping == null) + { + cleaned.Add(jumper); + return 0; + } - if (pushers.Count != (magicCount + locals.Count)) - { - // One or more push instructions are wildcards, they have a 'history' of being modified. - // Keep this jump instruction, result could change. - cleaned.Add(jumper); - return 0; - } + if (pushers.Count != (magicCount + locals.Count)) + { + // One or more push instructions are wildcards, they have a 'history' of being modified. + // Keep this jump instruction, result could change. + cleaned.Add(jumper); + return 0; + } - // Gather information about the jump instruction, and it's 'block' of instructions that are being jumped over(if 'isJumping = true'). - bool isBackwardsJump = false; - IEnumerable block = null; - if (!JumpExits.TryGetValue(jumper, out ASInstruction exit)) - { - // This jump instruction should not be 'cleaned', keep it. - cleaned.Add(jumper); - return 0; - } + // Gather information about the jump instruction, and it's 'block' of instructions that are being jumped over(if 'isJumping = true'). + bool isBackwardsJump = false; + IEnumerable block = null; + if (!JumpExits.TryGetValue(jumper, out ASInstruction exit)) + { + // This jump instruction should not be 'cleaned', keep it. + cleaned.Add(jumper); + return 0; + } - if (IsBackwardsJump(jumper)) - { - isBackwardsJump = true; - block = cleaned - .Skip(cleaned.IndexOf(exit) + 1) - .TakeWhile(i => i != jumper); - } - else - { - block = jumper.Offset > 0 ? GetJumpBlock(jumper) : null; - } + if (IsBackwardsJump(jumper)) + { + isBackwardsJump = true; + block = cleaned + .Skip(cleaned.IndexOf(exit) + 1) + .TakeWhile(i => i != jumper); + } + else + { + block = jumper.Offset > 0 ? GetJumpBlock(jumper) : null; + } - if (isJumping == true && block != null) + if (isJumping == true && block != null) + { + if (isBackwardsJump) { - if (isBackwardsJump) + // Check if any of the locals used by the jump instruction is being set within the body. + // If the answer is yes, removing the jump instruction is a bad idea, since the output of the condition could change. + foreach (Local local in locals) { - // Check if any of the locals used by the jump instruction is being set within the body. - // If the answer is yes, removing the jump instruction is a bad idea, since the output of the condition could change. - foreach (Local local in locals) + foreach (ASInstruction instruction in block) { - foreach (ASInstruction instruction in block) - { - if (!Local.IsValid(instruction.OP)) continue; - if (Local.IsGetLocal(instruction.OP)) continue; - var bodyLocal = (Local)instruction; + if (!Local.IsValid(instruction.OP)) continue; + if (Local.IsGetLocal(instruction.OP)) continue; + var bodyLocal = (Local)instruction; - if (bodyLocal.Register == local.Register) - { - // Do not remove the jump instruction, condition result may change. - cleaned.Add(jumper); - return 0; - } + if (bodyLocal.Register == local.Register) + { + // Do not remove the jump instruction, condition result may change. + cleaned.Add(jumper); + return 0; } } } + } - foreach (KeyValuePair jumpExit in JumpExits) - { - if (jumpExit.Key == jumper) continue; + foreach (KeyValuePair jumpExit in JumpExits) + { + if (jumpExit.Key == jumper) continue; - bool hasEntry = block.Contains(jumpExit.Key); // Does a jump instruction begin somewhere in the block? - bool hasExit = block.Contains(jumpExit.Value); // Does the jump instruction end somewhere in the block? + bool hasEntry = block.Contains(jumpExit.Key); // Does a jump instruction begin somewhere in the block? + bool hasExit = block.Contains(jumpExit.Value); // Does the jump instruction end somewhere in the block? - ASInstruction afterLast = _instructions[_indices[block.Last()] + 1]; - bool isExitAfterLast = (jumpExit.Value == afterLast); // Does the exit of the jump that is in the block come after the final instruction of the current block? + ASInstruction afterLast = _instructions[_indices[block.Last()] + 1]; + bool isExitAfterLast = (jumpExit.Value == afterLast); // Does the exit of the jump that is in the block come after the final instruction of the current block? - if (hasEntry && !hasExit && !isExitAfterLast || - hasExit && !hasEntry) - { - // Keep the jump instruction, since it will corrupt the other jump instruction that is using it. - cleaned.Add(jumper); - return 0; - } + if (hasEntry && !hasExit && !isExitAfterLast || + hasExit && !hasEntry) + { + // Keep the jump instruction, since it will corrupt the other jump instruction that is using it. + cleaned.Add(jumper); + return 0; } - foreach (KeyValuePair switchExit in SwitchExits) + } + foreach (KeyValuePair switchExit in SwitchExits) + { + foreach (ASInstruction caseExit in switchExit.Value) { - foreach (ASInstruction caseExit in switchExit.Value) + if (block.Contains(caseExit)) { - if (block.Contains(caseExit)) - { - cleaned.Add(jumper); - return 0; - } + cleaned.Add(jumper); + return 0; } } } + } - foreach (Local local in locals) - { - List references = localReferences[local.Register]; - references.Remove(local); - } + foreach (Local local in locals) + { + List references = localReferences[local.Register]; + references.Remove(local); + } - // Remove the instructions that pushed values for the jump instruction that is to be removed. - foreach (ASInstruction pusher in pushers) - { - cleaned.Remove(pusher); - } + // Remove the instructions that pushed values for the jump instruction that is to be removed. + foreach (ASInstruction pusher in pushers) + { + cleaned.Remove(pusher); + } - if (isJumping == false || isBackwardsJump) - { - block = null; - } - JumpExits.Remove(jumper); - return (block?.Count() ?? 0); + if (isJumping == false || isBackwardsJump) + { + block = null; } + JumpExits.Remove(jumper); + return (block?.Count() ?? 0); + } - public override void WriteTo(FlashWriter output) + public override void WriteTo(FlashWriter output) + { + var marks = new Dictionary(); + var sharedExits = new Dictionary>(); + var switchCases = new Dictionary(); + foreach (ASInstruction instruction in _instructions) { - var marks = new Dictionary(); - var sharedExits = new Dictionary>(); - var switchCases = new Dictionary(); - foreach (ASInstruction instruction in _instructions) - { - long previousPosition = output.Position; - marks.Add(instruction, previousPosition); - instruction.WriteTo(output); + long previousPosition = output.Position; + marks.Add(instruction, previousPosition); + instruction.WriteTo(output); - if (sharedExits.TryGetValue(instruction, out List jumpers)) + if (sharedExits.TryGetValue(instruction, out List jumpers)) + { + foreach (ASInstruction jumper in jumpers) { - foreach (ASInstruction jumper in jumpers) - { - long position = marks[jumper]; - var fixedOffset = (uint)(previousPosition - (position + 4)); + long position = marks[jumper]; + var fixedOffset = (uint)(previousPosition - (position + 4)); - ((Jumper)jumper).Offset = fixedOffset; - Rewrite(output, jumper, position); - } - sharedExits.Remove(instruction); + ((Jumper)jumper).Offset = fixedOffset; + Rewrite(output, jumper, position); } + sharedExits.Remove(instruction); + } - if (switchCases.TryGetValue(instruction, out (LookUpSwitchIns owner, int index) caseExits)) + if (switchCases.TryGetValue(instruction, out (LookUpSwitchIns owner, int index) caseExits)) + { + long position = marks[caseExits.owner]; + var fixedOffset = (uint)(previousPosition - position); // Where the instruction starts. + int defaultIndex = caseExits.owner.CaseOffsets.IndexOf(caseExits.owner.DefaultOffset); + + if (caseExits.index == defaultIndex || caseExits.index == caseExits.owner.CaseOffsets.Count) + { + caseExits.owner.DefaultOffset = fixedOffset; + } + else { - long position = marks[caseExits.owner]; - var fixedOffset = (uint)(previousPosition - position); // Where the instruction starts. - int defaultIndex = caseExits.owner.CaseOffsets.IndexOf(caseExits.owner.DefaultOffset); + caseExits.owner.CaseOffsets[caseExits.index] = fixedOffset; + } + Rewrite(output, caseExits.owner, position); + } - if (caseExits.index == defaultIndex || caseExits.index == caseExits.owner.CaseOffsets.Count) + if (instruction.OP == OPCode.LookUpSwitch) + { + bool requiresRewrite = false; + var lookUpSwitch = (LookUpSwitchIns)instruction; + + ASInstruction[] cases = SwitchExits[lookUpSwitch]; + for (int i = 0; i < cases.Length; i++) + { + ASInstruction exit = cases[i]; + if (exit.OP != OPCode.Label) { - caseExits.owner.DefaultOffset = fixedOffset; + switchCases.Add(exit, (lookUpSwitch, i)); } - else + else if (exit.OP == OPCode.Label) { - caseExits.owner.CaseOffsets[caseExits.index] = fixedOffset; - } - Rewrite(output, caseExits.owner, position); - } - - if (instruction.OP == OPCode.LookUpSwitch) - { - bool requiresRewrite = false; - var lookUpSwitch = (LookUpSwitchIns)instruction; + requiresRewrite = true; + long exitPosition = marks[exit]; + long jumpCount = (previousPosition - (exitPosition + 1)); - ASInstruction[] cases = SwitchExits[lookUpSwitch]; - for (int i = 0; i < cases.Length; i++) - { - ASInstruction exit = cases[i]; - if (exit.OP != OPCode.Label) + uint fixedOffset = (uint)(uint.MaxValue - jumpCount); + if (i == (cases.Length - 1)) { - switchCases.Add(exit, (lookUpSwitch, i)); + lookUpSwitch.DefaultOffset = fixedOffset; } - else if (exit.OP == OPCode.Label) + else { - requiresRewrite = true; - long exitPosition = marks[exit]; - long jumpCount = (previousPosition - (exitPosition + 1)); - - uint fixedOffset = (uint)(uint.MaxValue - jumpCount); - if (i == (cases.Length - 1)) - { - lookUpSwitch.DefaultOffset = fixedOffset; - } - else - { - lookUpSwitch.CaseOffsets[i] = fixedOffset; - } + lookUpSwitch.CaseOffsets[i] = fixedOffset; } } - if (requiresRewrite) - { - Rewrite(output, lookUpSwitch, previousPosition); - } } - else if (Jumper.IsValid(instruction.OP)) + if (requiresRewrite) { - var jumper = (Jumper)instruction; - if (jumper.Offset == 0) continue; + Rewrite(output, lookUpSwitch, previousPosition); + } + } + else if (Jumper.IsValid(instruction.OP)) + { + var jumper = (Jumper)instruction; + if (jumper.Offset == 0) continue; - if (!JumpExits.TryGetValue(jumper, out ASInstruction exit)) - { - // An exit for this jump instruction could not be found, perhaps its' offset exceeds the index limit? - continue; - } - else if (exit.OP != OPCode.Label || !marks.ContainsKey(exit)) // Forward jumps can have a label for an exit, as long as it is located ahead. + if (!JumpExits.TryGetValue(jumper, out ASInstruction exit)) + { + // An exit for this jump instruction could not be found, perhaps its' offset exceeds the index limit? + continue; + } + else if (exit.OP != OPCode.Label || !marks.ContainsKey(exit)) // Forward jumps can have a label for an exit, as long as it is located ahead. + { + jumpers = null; + if (!sharedExits.TryGetValue(exit, out jumpers)) { - jumpers = null; - if (!sharedExits.TryGetValue(exit, out jumpers)) - { - jumpers = new List(); - sharedExits.Add(exit, jumpers); - } - jumpers.Add(jumper); + jumpers = new List(); + sharedExits.Add(exit, jumpers); } - else // Backward jumps must always have a label for an exit, and must be behind this instruction. - { - long exitPosition = marks[exit]; - long jumpCount = (output.Position - (exitPosition + 1)); + jumpers.Add(jumper); + } + else // Backward jumps must always have a label for an exit, and must be behind this instruction. + { + long exitPosition = marks[exit]; + long jumpCount = (output.Position - (exitPosition + 1)); - var fixedOffset = (uint)(uint.MaxValue - jumpCount); - jumper.Offset = fixedOffset; + var fixedOffset = (uint)(uint.MaxValue - jumpCount); + jumper.Offset = fixedOffset; - Rewrite(output, jumper, previousPosition); - } + Rewrite(output, jumper, previousPosition); } } } diff --git a/Flazzy/ABC/AVM2/ASMachine.cs b/Flazzy/ABC/AVM2/ASMachine.cs index 7ce5aa7..6cfb31a 100644 --- a/Flazzy/ABC/AVM2/ASMachine.cs +++ b/Flazzy/ABC/AVM2/ASMachine.cs @@ -1,16 +1,15 @@ -namespace Flazzy.ABC.AVM2 +namespace Flazzy.ABC.AVM2; + +public class ASMachine { - public class ASMachine - { - public Stack Values { get; } - public Stack Scopes { get; } - public Dictionary Registers { get; } + public Stack Values { get; } + public Stack Scopes { get; } + public Dictionary Registers { get; } - public ASMachine(int localCount) - { - Values = new Stack(); - Scopes = new Stack(); - Registers = new Dictionary(localCount); - } + public ASMachine(int localCount) + { + Values = new Stack(); + Scopes = new Stack(); + Registers = new Dictionary(localCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ASInstruction.cs b/Flazzy/ABC/AVM2/Instructions/ASInstruction.cs index ebfeef1..855f0a4 100644 --- a/Flazzy/ABC/AVM2/Instructions/ASInstruction.cs +++ b/Flazzy/ABC/AVM2/Instructions/ASInstruction.cs @@ -1,527 +1,526 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public abstract class ASInstruction : FlashItem, ICloneable { - public abstract class ASInstruction : FlashItem, ICloneable + public OPCode OP { get; } + protected ABCFile ABC { get; } + protected override string DebuggerDisplay => OP.ToString(); + + public ASInstruction(OPCode op) { - public OPCode OP { get; } - protected ABCFile ABC { get; } - protected override string DebuggerDisplay => OP.ToString(); + OP = op; + } + protected ASInstruction(OPCode op, ABCFile abc) + : this(op) + { + ABC = abc; + } - public ASInstruction(OPCode op) - { - OP = op; - } - protected ASInstruction(OPCode op, ABCFile abc) - : this(op) - { - ABC = abc; - } + public override void WriteTo(FlashWriter output) + { + output.Write((byte)OP); + WriteValuesTo(output); + } + protected virtual void WriteValuesTo(FlashWriter output) + { } - public override void WriteTo(FlashWriter output) - { - output.Write((byte)OP); - WriteValuesTo(output); - } - protected virtual void WriteValuesTo(FlashWriter output) - { } + public virtual int GetPopCount() + { + return 0; + } + public virtual int GetPushCount() + { + return 0; + } + public virtual void Execute(ASMachine machine) + { } - public virtual int GetPopCount() + protected int ResolveMultinamePops(ASMultiname multiname) + { + int popCount = 0; + if (multiname.IsNameNeeded) { - return 0; + popCount++; } - public virtual int GetPushCount() + if (multiname.IsNamespaceNeeded) { - return 0; + popCount++; } - public virtual void Execute(ASMachine machine) - { } - - protected int ResolveMultinamePops(ASMultiname multiname) + return popCount; + } + protected void ResolveMultiname(ASMachine machine, ASMultiname multiname) + { + if (multiname.IsNameNeeded) { - int popCount = 0; - if (multiname.IsNameNeeded) - { - popCount++; - } - if (multiname.IsNamespaceNeeded) - { - popCount++; - } - return popCount; + object name = machine.Values.Pop(); } - protected void ResolveMultiname(ASMachine machine, ASMultiname multiname) + if (multiname.IsNamespaceNeeded) { - if (multiname.IsNameNeeded) - { - object name = machine.Values.Pop(); - } - if (multiname.IsNamespaceNeeded) - { - object @namespace = machine.Values.Pop(); - } + object @namespace = machine.Values.Pop(); } + } - // TODO: Use source generator to add new items at compile time. - public static bool IsPropertyContainer(OPCode op) + // TODO: Use source generator to add new items at compile time. + public static bool IsPropertyContainer(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.CallPropVoid: - case OPCode.CallProperty: - case OPCode.ConstructProp: return true; - default: return false; - } + case OPCode.CallPropVoid: + case OPCode.CallProperty: + case OPCode.ConstructProp: return true; + default: return false; } - public static ASInstruction Create(ABCFile abc, FlashReader input) + } + public static ASInstruction Create(ABCFile abc, FlashReader input) + { + var op = (OPCode)input.ReadByte(); + switch (op) { - var op = (OPCode)input.ReadByte(); - switch (op) - { - #region Arithmetic - case OPCode.Add_i: + #region Arithmetic + case OPCode.Add_i: return new AddIIns(); - case OPCode.Add: + case OPCode.Add: return new AddIns(); - case OPCode.Decrement_i: + case OPCode.Decrement_i: return new DecrementIIns(); - case OPCode.Decrement: + case OPCode.Decrement: return new DecrementIns(); - case OPCode.Divide: + case OPCode.Divide: return new DivideIns(); - case OPCode.Equals: + case OPCode.Equals: return new EqualsIns(); - case OPCode.GreaterEquals: + case OPCode.GreaterEquals: return new GreaterEqualsIns(); - case OPCode.GreaterThan: + case OPCode.GreaterThan: return new GreaterThanIns(); - case OPCode.Increment_i: + case OPCode.Increment_i: return new IncrementIIns(); - case OPCode.Increment: + case OPCode.Increment: return new IncrementIns(); - case OPCode.In: + case OPCode.In: return new InIns(); - case OPCode.IsTypeLate: + case OPCode.IsTypeLate: return new IsTypeLateIns(); - case OPCode.LessEquals: + case OPCode.LessEquals: return new LessEqualsIns(); - case OPCode.LessThan: + case OPCode.LessThan: return new LessThanIns(); - case OPCode.Modulo: + case OPCode.Modulo: return new ModuloIns(); - case OPCode.Multiply_i: + case OPCode.Multiply_i: return new MultiplyIIns(); - case OPCode.Multiply: + case OPCode.Multiply: return new MultiplyIns(); - case OPCode.Negate_i: + case OPCode.Negate_i: return new NegateIIns(); - case OPCode.Negate: + case OPCode.Negate: return new NegateIns(); - case OPCode.StrictEquals: + case OPCode.StrictEquals: return new StrictEqualsIns(); - case OPCode.Subtract_i: + case OPCode.Subtract_i: return new SubtractIIns(); - case OPCode.Subtract: + case OPCode.Subtract: return new SubtractIns(); - #endregion + #endregion - #region Bit Manipulation - case OPCode.BitAnd: + #region Bit Manipulation + case OPCode.BitAnd: return new BitAndIns(); - case OPCode.BitNot: + case OPCode.BitNot: return new BitNotIns(); - case OPCode.BitOr: + case OPCode.BitOr: return new BitOrIns(); - case OPCode.BitXor: + case OPCode.BitXor: return new BitXorIns(); - case OPCode.LShift: + case OPCode.LShift: return new LShiftIns(); - case OPCode.RShift: + case OPCode.RShift: return new RShiftIns(); - case OPCode.URShift: + case OPCode.URShift: return new URShiftIns(); - #endregion + #endregion - #region Control Transfer - case OPCode.IfEq: + #region Control Transfer + case OPCode.IfEq: return new IfEqualIns(input); - case OPCode.IfFalse: + case OPCode.IfFalse: return new IfFalseIns(input); - case OPCode.IfGe: + case OPCode.IfGe: return new IfGreaterEqualIns(input); - case OPCode.IfGt: + case OPCode.IfGt: return new IfGreaterThanIns(input); - case OPCode.IfLe: + case OPCode.IfLe: return new IfLessEqualIns(input); - case OPCode.IfLt: + case OPCode.IfLt: return new IfLessThanIns(input); - case OPCode.IfNe: + case OPCode.IfNe: return new IfNotEqualIns(input); - case OPCode.IfNGe: + case OPCode.IfNGe: return new IfNotGreaterEqualIns(input); - case OPCode.IfNGt: + case OPCode.IfNGt: return new IfNotGreaterThanIns(input); - case OPCode.IfNLe: + case OPCode.IfNLe: return new IfNotLessEqualIns(input); - case OPCode.IfNLt: + case OPCode.IfNLt: return new IfNotLessThanIns(input); - case OPCode.IfStrictEq: + case OPCode.IfStrictEq: return new IfStrictEqualIns(input); - case OPCode.IfStrictNE: + case OPCode.IfStrictNE: return new IfStrictNotEqualIns(input); - case OPCode.IfTrue: + case OPCode.IfTrue: return new IfTrueIns(input); - case OPCode.Jump: + case OPCode.Jump: return new JumpIns(input); - #endregion + #endregion - #region Register Management - case OPCode.DecLocal_i: + #region Register Management + case OPCode.DecLocal_i: return new DecLocalIIns(input); - case OPCode.DecLocal: + case OPCode.DecLocal: return new DecLocalIns(input); - case OPCode.GetLocal_0: + case OPCode.GetLocal_0: return new GetLocal0Ins(); - case OPCode.GetLocal_1: + case OPCode.GetLocal_1: return new GetLocal1Ins(); - case OPCode.GetLocal_2: + case OPCode.GetLocal_2: return new GetLocal2Ins(); - case OPCode.GetLocal_3: + case OPCode.GetLocal_3: return new GetLocal3Ins(); - case OPCode.GetLocal: + case OPCode.GetLocal: return new GetLocalIns(input); - case OPCode.IncLocal_i: + case OPCode.IncLocal_i: return new IncLocalIIns(input); - case OPCode.IncLocal: + case OPCode.IncLocal: return new IncLocalIns(input); - case OPCode.Kill: + case OPCode.Kill: return new KillIns(input); - case OPCode.SetLocal_0: + case OPCode.SetLocal_0: return new SetLocal0Ins(); - case OPCode.SetLocal_1: + case OPCode.SetLocal_1: return new SetLocal1Ins(); - case OPCode.SetLocal_2: + case OPCode.SetLocal_2: return new SetLocal2Ins(); - case OPCode.SetLocal_3: + case OPCode.SetLocal_3: return new SetLocal3Ins(); - case OPCode.SetLocal: + case OPCode.SetLocal: return new SetLocalIns(input); - #endregion + #endregion - #region Stack Management - case OPCode.PushByte: + #region Stack Management + case OPCode.PushByte: return new PushByteIns(input); - case OPCode.PushDouble: + case OPCode.PushDouble: return new PushDoubleIns(abc, input); - case OPCode.PushFalse: + case OPCode.PushFalse: return new PushFalseIns(); - case OPCode.PushInt: + case OPCode.PushInt: return new PushIntIns(abc, input); - case OPCode.PushNan: + case OPCode.PushNan: return new PushNaNIns(); - case OPCode.PushNull: + case OPCode.PushNull: return new PushNullIns(); - case OPCode.PushShort: + case OPCode.PushShort: return new PushShortIns(input); - case OPCode.PushString: + case OPCode.PushString: return new PushStringIns(abc, input); - case OPCode.PushTrue: + case OPCode.PushTrue: return new PushTrueIns(); - case OPCode.PushUInt: + case OPCode.PushUInt: return new PushUIntIns(abc, input); - #endregion + #endregion - #region Type Conversion - case OPCode.Coerce_a: + #region Type Conversion + case OPCode.Coerce_a: return new CoerceAIns(); - case OPCode.Coerce: + case OPCode.Coerce: return new CoerceIns(abc, input); - case OPCode.Coerce_s: + case OPCode.Coerce_s: return new CoerceSIns(); - case OPCode.Convert_b: + case OPCode.Convert_b: return new ConvertBIns(); - case OPCode.Convert_d: + case OPCode.Convert_d: return new ConvertDIns(); - case OPCode.Convert_i: + case OPCode.Convert_i: return new ConvertIIns(); - case OPCode.Convert_o: + case OPCode.Convert_o: return new ConvertOIns(); - case OPCode.Convert_s: + case OPCode.Convert_s: return new ConvertSIns(); - case OPCode.Convert_u: + case OPCode.Convert_u: return new ConvertUIns(); - #endregion + #endregion - #region Miscellaneous - case OPCode.ApplyType: + #region Miscellaneous + case OPCode.ApplyType: return new ApplyTypeIns(input); - case OPCode.AsType: + case OPCode.AsType: return new AsTypeIns(abc, input); - case OPCode.AsTypeLate: + case OPCode.AsTypeLate: return new AsTypeLateIns(); - case OPCode.Call: + case OPCode.Call: return new CallIns(input); - case OPCode.CallMethod: + case OPCode.CallMethod: return new CallMethodIns(abc, input); - case OPCode.CallProperty: + case OPCode.CallProperty: return new CallPropertyIns(abc, input); - case OPCode.CallPropLex: + case OPCode.CallPropLex: return new CallPropLexIns(abc, input); - case OPCode.CallPropVoid: + case OPCode.CallPropVoid: return new CallPropVoidIns(abc, input); - case OPCode.CallStatic: + case OPCode.CallStatic: return new CallStaticIns(abc, input); - case OPCode.CallSuper: + case OPCode.CallSuper: return new CallSuperIns(abc, input); - case OPCode.CallSuperVoid: + case OPCode.CallSuperVoid: return new CallSuperVoidIns(abc, input); - case OPCode.CheckFilter: + case OPCode.CheckFilter: return new CheckFilterIns(); - case OPCode.Construct: + case OPCode.Construct: return new ConstructIns(input); - case OPCode.ConstructProp: + case OPCode.ConstructProp: return new ConstructPropIns(abc, input); - case OPCode.ConstructSuper: + case OPCode.ConstructSuper: return new ConstructSuperIns(input); - case OPCode.DebugFile: + case OPCode.DebugFile: return new DebugFileIns(abc, input); - case OPCode.Debug: + case OPCode.Debug: return new DebugIns(abc, input); - case OPCode.DebugLine: + case OPCode.DebugLine: return new DebugLineIns(input); - case OPCode.DeleteProperty: + case OPCode.DeleteProperty: return new DeletePropertyIns(abc, input); - case OPCode.Dup: + case OPCode.Dup: return new DupIns(); - case OPCode.Dxns: + case OPCode.Dxns: return new DxnsIns(abc, input); - case OPCode.DxnsLate: + case OPCode.DxnsLate: return new DxnsLateIns(); - case OPCode.Esc_XElem: + case OPCode.Esc_XElem: return new EscXElemIns(); - case OPCode.Esc_XAttr: + case OPCode.Esc_XAttr: return new EscXAttrIns(); - case OPCode.FindProperty: + case OPCode.FindProperty: return new FindPropertyIns(abc, input); - case OPCode.FindPropStrict: + case OPCode.FindPropStrict: return new FindPropStrictIns(abc, input); - case OPCode.GetDescendants: + case OPCode.GetDescendants: return new GetDescendantsIns(abc, input); - case OPCode.GetGlobalScope: + case OPCode.GetGlobalScope: return new GetGlobalScopeIns(); - case OPCode.GetLex: + case OPCode.GetLex: return new GetLexIns(abc, input); - case OPCode.GetProperty: + case OPCode.GetProperty: return new GetPropertyIns(abc, input); - case OPCode.GetScopeObject: + case OPCode.GetScopeObject: return new GetScopeObjectIns(input); - case OPCode.GetSlot: + case OPCode.GetSlot: return new GetSlotIns(input); - case OPCode.GetSuper: + case OPCode.GetSuper: return new GetSuperIns(abc, input); - case OPCode.HasNext2: + case OPCode.HasNext2: return new HasNext2Ins(input); - case OPCode.HasNext: + case OPCode.HasNext: return new HasNextIns(); - case OPCode.InitProperty: + case OPCode.InitProperty: return new InitPropertyIns(abc, input); - case OPCode.InstanceOf: + case OPCode.InstanceOf: return new InstanceOfIns(); - case OPCode.Label: + case OPCode.Label: return new LabelIns(); - case OPCode.LookUpSwitch: + case OPCode.LookUpSwitch: return new LookUpSwitchIns(input); - case OPCode.NewActivation: + case OPCode.NewActivation: return new NewActivationIns(); - case OPCode.NewArray: + case OPCode.NewArray: return new NewArrayIns(input); - case OPCode.NewCatch: + case OPCode.NewCatch: return new NewCatchIns(input); - case OPCode.NewClass: + case OPCode.NewClass: return new NewClassIns(abc, input); - case OPCode.NewFunction: + case OPCode.NewFunction: return new NewFunctionIns(abc, input); - case OPCode.NewObject: + case OPCode.NewObject: return new NewObjectIns(input); - case OPCode.NextName: + case OPCode.NextName: return new NextNameIns(); - case OPCode.NextValue: + case OPCode.NextValue: return new NextValueIns(); - case OPCode.Nop: + case OPCode.Nop: return new NopIns(); - case OPCode.Not: + case OPCode.Not: return new NotIns(); - case OPCode.Pop: + case OPCode.Pop: return new PopIns(); - case OPCode.PopScope: + case OPCode.PopScope: return new PopScopeIns(); - case OPCode.PushScope: + case OPCode.PushScope: return new PushScopeIns(); - case OPCode.PushUndefined: + case OPCode.PushUndefined: return new PushUndefinedIns(); - case OPCode.PushWith: + case OPCode.PushWith: return new PushWithIns(); - case OPCode.ReturnValue: + case OPCode.ReturnValue: return new ReturnValueIns(); - case OPCode.ReturnVoid: + case OPCode.ReturnVoid: return new ReturnVoidIns(); - case OPCode.SetProperty: + case OPCode.SetProperty: return new SetPropertyIns(abc, input); - case OPCode.SetSlot: + case OPCode.SetSlot: return new SetSlotIns(input); - case OPCode.SetSuper: + case OPCode.SetSuper: return new SetSuperIns(abc, input); - case OPCode.Swap: + case OPCode.Swap: return new SwapIns(); - case OPCode.Throw: + case OPCode.Throw: return new ThrowIns(); - case OPCode.TypeOf: + case OPCode.TypeOf: return new TypeOfIns(); #endregion - } - throw new Exception("Unhandled OPCode: " + op); } + throw new Exception("Unhandled OPCode: " + op); + } - object ICloneable.Clone() - { - return Clone(); - } - public ASInstruction Clone() - { - return (ASInstruction)MemberwiseClone(); - } + object ICloneable.Clone() + { + return Clone(); + } + public ASInstruction Clone() + { + return (ASInstruction)MemberwiseClone(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ApplyTypeIns.cs b/Flazzy/ABC/AVM2/Instructions/ApplyTypeIns.cs index 7dcf515..225e855 100644 --- a/Flazzy/ABC/AVM2/Instructions/ApplyTypeIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ApplyTypeIns.cs @@ -1,28 +1,27 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ApplyTypeIns : ASInstruction { - public class ApplyTypeIns : ASInstruction - { - public int ParamCount { get; set; } + public int ParamCount { get; set; } - public ApplyTypeIns() - : base(OPCode.ApplyType) - { } - public ApplyTypeIns(int paramCount) - : this() - { - ParamCount = paramCount; - } - public ApplyTypeIns(FlashReader input) - : this() - { - ParamCount = input.ReadInt30(); - } + public ApplyTypeIns() + : base(OPCode.ApplyType) + { } + public ApplyTypeIns(int paramCount) + : this() + { + ParamCount = paramCount; + } + public ApplyTypeIns(FlashReader input) + : this() + { + ParamCount = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ParamCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ParamCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIIns.cs index 13fc565..8f6c621 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class AddIIns : Computation { - public class AddIIns : Computation - { - public AddIIns() - : base(OPCode.Add_i) - { } + public AddIIns() + : base(OPCode.Add_i) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left + right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left + right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIns.cs index 685451d..6e581de 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/AddIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class AddIns : Computation { - public class AddIns : Computation - { - public AddIns() - : base(OPCode.Add) - { } + public AddIns() + : base(OPCode.Add) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left + right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left + right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/Computation.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/Computation.cs index 7790f90..4d3ecfe 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/Computation.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/Computation.cs @@ -1,56 +1,55 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public abstract class Computation : ASInstruction { - public abstract class Computation : ASInstruction + public Computation(OPCode op) + : base(op) + { } + + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() { - public Computation(OPCode op) - : base(op) - { } + return 1; + } + public override void Execute(ASMachine machine) + { + object right = machine.Values.Pop(); + object left = machine.Values.Pop(); - public override int GetPopCount() + object result = null; + if (left != null && right != null) { - return 2; + result = Execute(left, right); } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object right = machine.Values.Pop(); - object left = machine.Values.Pop(); - - object result = null; - if (left != null && right != null) - { - result = Execute(left, right); - } - machine.Values.Push(result); - } - protected abstract object Execute(object left, object right); + machine.Values.Push(result); + } + protected abstract object Execute(object left, object right); - public static bool IsValid(OPCode op) + public static bool IsValid(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.Add_i: - case OPCode.Add: - case OPCode.Divide: - case OPCode.Equals: - case OPCode.GreaterEquals: - case OPCode.GreaterThan: - case OPCode.LessEquals: - case OPCode.LessThan: - case OPCode.Modulo: - case OPCode.Multiply_i: - case OPCode.Multiply: - case OPCode.StrictEquals: - case OPCode.Subtract_i: - case OPCode.Subtract: + case OPCode.Add_i: + case OPCode.Add: + case OPCode.Divide: + case OPCode.Equals: + case OPCode.GreaterEquals: + case OPCode.GreaterThan: + case OPCode.LessEquals: + case OPCode.LessThan: + case OPCode.Modulo: + case OPCode.Multiply_i: + case OPCode.Multiply: + case OPCode.StrictEquals: + case OPCode.Subtract_i: + case OPCode.Subtract: return true; - default: + default: return false; - } } } -} +} \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIIns.cs index 87a093f..c23c3e8 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DecrementIIns : ASInstruction { - public class DecrementIIns : ASInstruction - { - public DecrementIIns() - : base(OPCode.Decrement_i) - { } + public DecrementIIns() + : base(OPCode.Decrement_i) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (Convert.ToInt32(value) - 1); - } - machine.Values.Push(result); + result = (Convert.ToInt32(value) - 1); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIns.cs index 0aa33dc..34b9999 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/DecrementIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DecrementIns : ASInstruction { - public class DecrementIns : ASInstruction - { - public DecrementIns() - : base(OPCode.Decrement) - { } + public DecrementIns() + : base(OPCode.Decrement) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (Convert.ToDouble(value) - 1); - } - machine.Values.Push(result); + result = (Convert.ToDouble(value) - 1); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/DivideIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/DivideIns.cs index 8fd8d58..b709608 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/DivideIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/DivideIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DivideIns : Computation { - public class DivideIns : Computation - { - public DivideIns() - : base(OPCode.Divide) - { } + public DivideIns() + : base(OPCode.Divide) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left / right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left / right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/EqualsIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/EqualsIns.cs index b990904..1ff5a97 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/EqualsIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/EqualsIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class EqualsIns : Computation { - public class EqualsIns : Computation - { - public EqualsIns() - : base(OPCode.Equals) - { } + public EqualsIns() + : base(OPCode.Equals) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left == right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left == right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterEqualsIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterEqualsIns.cs index 43652ba..80e451c 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterEqualsIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterEqualsIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GreaterEqualsIns : Computation { - public class GreaterEqualsIns : Computation - { - public GreaterEqualsIns() - : base(OPCode.GreaterEquals) - { } + public GreaterEqualsIns() + : base(OPCode.GreaterEquals) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left >= right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left >= right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterThanIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterThanIns.cs index e2fa7fc..3851c50 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterThanIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/GreaterThanIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GreaterThanIns : Computation { - public class GreaterThanIns : Computation - { - public GreaterThanIns() - : base(OPCode.GreaterThan) - { } + public GreaterThanIns() + : base(OPCode.GreaterThan) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left > right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left > right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/InIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/InIns.cs index 2682039..54a5757 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/InIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/InIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class InIns : ASInstruction { - public class InIns : ASInstruction - { - public InIns() - : base(OPCode.In) - { } + public InIns() + : base(OPCode.In) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object obj = machine.Values.Pop(); - object name = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object obj = machine.Values.Pop(); + object name = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIIns.cs index ec199d2..56065b4 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IncrementIIns : ASInstruction { - public class IncrementIIns : ASInstruction - { - public IncrementIIns() - : base(OPCode.Increment_i) - { } + public IncrementIIns() + : base(OPCode.Increment_i) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (Convert.ToInt32(value) + 1); - } - machine.Values.Push(result); + result = (Convert.ToInt32(value) + 1); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIns.cs index af7899d..c304e2c 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/IncrementIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IncrementIns : ASInstruction { - public class IncrementIns : ASInstruction - { - public IncrementIns() - : base(OPCode.Increment) - { } + public IncrementIns() + : base(OPCode.Increment) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (Convert.ToDouble(value) + 1); - } - machine.Values.Push(result); + result = (Convert.ToDouble(value) + 1); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/IsTypeLateIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/IsTypeLateIns.cs index 03d55b3..3c8b63c 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/IsTypeLateIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/IsTypeLateIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IsTypeLateIns : ASInstruction { - public class IsTypeLateIns : ASInstruction - { - public IsTypeLateIns() - : base(OPCode.IsTypeLate) - { } + public IsTypeLateIns() + : base(OPCode.IsTypeLate) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object type = machine.Values.Pop(); - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object type = machine.Values.Pop(); + object value = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessEqualsIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessEqualsIns.cs index 100da0f..6838ad7 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessEqualsIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessEqualsIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class LessEqualsIns : Computation { - public class LessEqualsIns : Computation - { - public LessEqualsIns() - : base(OPCode.LessEquals) - { } + public LessEqualsIns() + : base(OPCode.LessEquals) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left <= right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left <= right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessThanIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessThanIns.cs index 0a1a7e1..3e5e49f 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessThanIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/LessThanIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class LessThanIns : Computation { - public class LessThanIns : Computation - { - public LessThanIns() - : base(OPCode.LessThan) - { } + public LessThanIns() + : base(OPCode.LessThan) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left < right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left < right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/ModuloIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/ModuloIns.cs index d34d7df..92b6ca8 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/ModuloIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/ModuloIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ModuloIns : Computation { - public class ModuloIns : Computation - { - public ModuloIns() - : base(OPCode.Modulo) - { } + public ModuloIns() + : base(OPCode.Modulo) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left % right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left % right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIIns.cs index ad2d18a..a980013 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class MultiplyIIns : Computation { - public class MultiplyIIns : Computation - { - public MultiplyIIns() - : base(OPCode.Multiply_i) - { } + public MultiplyIIns() + : base(OPCode.Multiply_i) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left * right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left * right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIns.cs index 3a84e86..4e6f300 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/MultiplyIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class MultiplyIns : Computation { - public class MultiplyIns : Computation - { - public MultiplyIns() - : base(OPCode.Multiply) - { } + public MultiplyIns() + : base(OPCode.Multiply) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left * right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left * right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIIns.cs index a4f7372..0f19655 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NegateIIns : ASInstruction { - public class NegateIIns : ASInstruction - { - public NegateIIns() - : base(OPCode.Negate_i) - { } + public NegateIIns() + : base(OPCode.Negate_i) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (Convert.ToInt32(value) * -1); - } - machine.Values.Push(result); + result = (Convert.ToInt32(value) * -1); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIns.cs index 68cfc5f..8e13331 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/NegateIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NegateIns : ASInstruction { - public class NegateIns : ASInstruction - { - public NegateIns() - : base(OPCode.Negate) - { } + public NegateIns() + : base(OPCode.Negate) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (Convert.ToDouble(value) * -1); - } - machine.Values.Push(result); + result = (Convert.ToDouble(value) * -1); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/StrictEqualsIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/StrictEqualsIns.cs index be9242a..eb56356 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/StrictEqualsIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/StrictEqualsIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class StrictEqualsIns : Computation { - public class StrictEqualsIns : Computation - { - public StrictEqualsIns() - : base(OPCode.StrictEquals) - { } + public StrictEqualsIns() + : base(OPCode.StrictEquals) + { } - protected override object Execute(object left, object right) - { - var cLeft = (left as IComparable); - var cRight = (right as IComparable); - if (cLeft == null || cRight == null) return null; + protected override object Execute(object left, object right) + { + var cLeft = (left as IComparable); + var cRight = (right as IComparable); + if (cLeft == null || cRight == null) return null; - return (cLeft.CompareTo(cRight) == 0); - } + return (cLeft.CompareTo(cRight) == 0); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIIns.cs index e087b05..9bb59b8 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SubtractIIns : Computation { - public class SubtractIIns : Computation - { - public SubtractIIns() - : base(OPCode.Subtract_i) - { } + public SubtractIIns() + : base(OPCode.Subtract_i) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left - right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left - right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIns.cs b/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIns.cs index 7f26826..605d358 100644 --- a/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Arithmetic/SubtractIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SubtractIns : Computation { - public class SubtractIns : Computation - { - public SubtractIns() - : base(OPCode.Subtract) - { } + public SubtractIns() + : base(OPCode.Subtract) + { } - protected override object Execute(dynamic left, dynamic right) - { - return (left - right); - } + protected override object Execute(dynamic left, dynamic right) + { + return (left - right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/AsTypeIns.cs b/Flazzy/ABC/AVM2/Instructions/AsTypeIns.cs index 9c0ef04..825057a 100644 --- a/Flazzy/ABC/AVM2/Instructions/AsTypeIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/AsTypeIns.cs @@ -1,43 +1,42 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class AsTypeIns : ASInstruction { - public class AsTypeIns : ASInstruction - { - public int TypeNameIndex { get; set; } - public ASMultiname TypeName => ABC.Pool.Multinames[TypeNameIndex]; + public int TypeNameIndex { get; set; } + public ASMultiname TypeName => ABC.Pool.Multinames[TypeNameIndex]; - public AsTypeIns(ABCFile abc) - : base(OPCode.AsType, abc) - { } - public AsTypeIns(ABCFile abc, int typeNameIndex) - : this(abc) - { - TypeNameIndex = typeNameIndex; - } - public AsTypeIns(ABCFile abc, FlashReader input) - : this(abc) - { - TypeNameIndex = input.ReadInt30(); - } + public AsTypeIns(ABCFile abc) + : base(OPCode.AsType, abc) + { } + public AsTypeIns(ABCFile abc, int typeNameIndex) + : this(abc) + { + TypeNameIndex = typeNameIndex; + } + public AsTypeIns(ABCFile abc, FlashReader input) + : this(abc) + { + TypeNameIndex = input.ReadInt30(); + } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(TypeNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(TypeNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/AsTypeLateIns.cs b/Flazzy/ABC/AVM2/Instructions/AsTypeLateIns.cs index bcc3074..46bfc66 100644 --- a/Flazzy/ABC/AVM2/Instructions/AsTypeLateIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/AsTypeLateIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class AsTypeLateIns : ASInstruction { - public class AsTypeLateIns : ASInstruction - { - public AsTypeLateIns() - : base(OPCode.AsTypeLate) - { } + public AsTypeLateIns() + : base(OPCode.AsTypeLate) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object @class = machine.Values.Pop(); - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object @class = machine.Values.Pop(); + object value = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitAndIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitAndIns.cs index 45d39d9..f468374 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitAndIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitAndIns.cs @@ -1,31 +1,30 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class BitAndIns : ASInstruction { - public class BitAndIns : ASInstruction - { - public BitAndIns() - : base(OPCode.BitAnd) - { } + public BitAndIns() + : base(OPCode.BitAnd) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object right = machine.Values.Pop(); + object left = machine.Values.Pop(); + if (right != null && left != null) { - object result = null; - object right = machine.Values.Pop(); - object left = machine.Values.Pop(); - if (right != null && left != null) - { - var iLeft = (int)Convert.ToDouble(left); - var iRight = (int)Convert.ToDouble(right); - result = (iLeft & iRight); - } - machine.Values.Push(result); + var iLeft = (int)Convert.ToDouble(left); + var iRight = (int)Convert.ToDouble(right); + result = (iLeft & iRight); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitNotIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitNotIns.cs index d5bd133..ba990b0 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitNotIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitNotIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class BitNotIns : ASInstruction { - public class BitNotIns : ASInstruction - { - public BitNotIns() - : base(OPCode.BitNot) - { } + public BitNotIns() + : base(OPCode.BitNot) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = (~Convert.ToInt32(value)); - } - machine.Values.Push(result); + result = (~Convert.ToInt32(value)); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitOrIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitOrIns.cs index f8acc6a..5cc8e6f 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitOrIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitOrIns.cs @@ -1,31 +1,30 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class BitOrIns : ASInstruction { - public class BitOrIns : ASInstruction - { - public BitOrIns() - : base(OPCode.BitOr) - { } + public BitOrIns() + : base(OPCode.BitOr) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object right = machine.Values.Pop(); + object left = machine.Values.Pop(); + if (right != null && left != null) { - object result = null; - object right = machine.Values.Pop(); - object left = machine.Values.Pop(); - if (right != null && left != null) - { - int iLeft = Convert.ToInt32(left); - int iRight = Convert.ToInt32(right); - result = (iLeft | iRight); - } - machine.Values.Push(result); + int iLeft = Convert.ToInt32(left); + int iRight = Convert.ToInt32(right); + result = (iLeft | iRight); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitXorIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitXorIns.cs index acefd33..9ec567e 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitXorIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/BitXorIns.cs @@ -1,31 +1,30 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class BitXorIns : ASInstruction { - public class BitXorIns : ASInstruction - { - public BitXorIns() - : base(OPCode.BitXor) - { } + public BitXorIns() + : base(OPCode.BitXor) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object right = machine.Values.Pop(); + object left = machine.Values.Pop(); + if (right != null && left != null) { - object result = null; - object right = machine.Values.Pop(); - object left = machine.Values.Pop(); - if (right != null && left != null) - { - int iLeft = Convert.ToInt32(left); - int iRight = Convert.ToInt32(right); - result = (iLeft ^ iRight); - } - machine.Values.Push(result); + int iLeft = Convert.ToInt32(left); + int iRight = Convert.ToInt32(right); + result = (iLeft ^ iRight); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/LShiftIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/LShiftIns.cs index d67d311..262097e 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/LShiftIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/LShiftIns.cs @@ -1,31 +1,30 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class LShiftIns : ASInstruction { - public class LShiftIns : ASInstruction - { - public LShiftIns() - : base(OPCode.LShift) - { } + public LShiftIns() + : base(OPCode.LShift) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object right = machine.Values.Pop(); + object left = machine.Values.Pop(); + if (right != null && left != null) { - object result = null; - object right = machine.Values.Pop(); - object left = machine.Values.Pop(); - if (right != null && left != null) - { - int iLeft = Convert.ToInt32(left); - int iRight = (Convert.ToInt32(right) & 0x1F); - result = (iLeft << iRight); - } - machine.Values.Push(result); + int iLeft = Convert.ToInt32(left); + int iRight = (Convert.ToInt32(right) & 0x1F); + result = (iLeft << iRight); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/RShiftIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/RShiftIns.cs index cfdfdbf..725a4fe 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/RShiftIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/RShiftIns.cs @@ -1,31 +1,30 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class RShiftIns : ASInstruction { - public class RShiftIns : ASInstruction - { - public RShiftIns() - : base(OPCode.RShift) - { } + public RShiftIns() + : base(OPCode.RShift) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object right = machine.Values.Pop(); + object left = machine.Values.Pop(); + if (right != null && left != null) { - object result = null; - object right = machine.Values.Pop(); - object left = machine.Values.Pop(); - if (right != null && left != null) - { - int iLeft = Convert.ToInt32(left); - int iRight = (Convert.ToInt32(right) & 0x1F); - result = (iLeft >> iRight); - } - machine.Values.Push(result); + int iLeft = Convert.ToInt32(left); + int iRight = (Convert.ToInt32(right) & 0x1F); + result = (iLeft >> iRight); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/URShiftIns.cs b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/URShiftIns.cs index c0ebe14..ee8a147 100644 --- a/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/URShiftIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Bit Manipulation/URShiftIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class URShiftIns : ASInstruction { - public class URShiftIns : ASInstruction - { - public URShiftIns() - : base(OPCode.URShift) - { } + public URShiftIns() + : base(OPCode.URShift) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Pop(); - machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Pop(); + machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallIns.cs b/Flazzy/ABC/AVM2/Instructions/CallIns.cs index 1f90371..834cd5f 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallIns.cs @@ -1,47 +1,46 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallIns : ASInstruction { - public class CallIns : ASInstruction - { - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallIns() - : base(OPCode.Call) - { } - public CallIns(int argCount) - : this() - { - ArgCount = argCount; - } - public CallIns(FlashReader input) - : this() - { - ArgCount = input.ReadInt30(); - } + public CallIns() + : base(OPCode.Call) + { } + public CallIns(int argCount) + : this() + { + ArgCount = argCount; + } + public CallIns(FlashReader input) + : this() + { + ArgCount = input.ReadInt30(); + } - public override int GetPopCount() - { - return (ArgCount + 2); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + 2); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - object receiver = machine.Values.Pop(); - object function = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + object receiver = machine.Values.Pop(); + object function = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallMethodIns.cs b/Flazzy/ABC/AVM2/Instructions/CallMethodIns.cs index 7605101..44c3cfe 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallMethodIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallMethodIns.cs @@ -1,55 +1,54 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallMethodIns : ASInstruction { - public class CallMethodIns : ASInstruction - { - public int MethodIndex { get; set; } - public int ArgCount { get; set; } + public int MethodIndex { get; set; } + public int ArgCount { get; set; } - public CallMethodIns(ABCFile abc) - : base(OPCode.CallMethod, abc) - { } - public CallMethodIns(ABCFile abc, FlashReader input) - : this(abc) - { - MethodIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallMethodIns(ABCFile abc, int methodIndex) - : this(abc) - { - MethodIndex = methodIndex; - } - public CallMethodIns(ABCFile abc, int methodIndex, int argCount) - : this(abc) - { - MethodIndex = methodIndex; - ArgCount = argCount; - } + public CallMethodIns(ABCFile abc) + : base(OPCode.CallMethod, abc) + { } + public CallMethodIns(ABCFile abc, FlashReader input) + : this(abc) + { + MethodIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallMethodIns(ABCFile abc, int methodIndex) + : this(abc) + { + MethodIndex = methodIndex; + } + public CallMethodIns(ABCFile abc, int methodIndex, int argCount) + : this(abc) + { + MethodIndex = methodIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return ArgCount + 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return ArgCount + 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - machine.Values.Pop(); // Receiver - machine.Values.Push(null); + machine.Values.Pop(); } + machine.Values.Pop(); // Receiver + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(MethodIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(MethodIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallPropLexIns.cs b/Flazzy/ABC/AVM2/Instructions/CallPropLexIns.cs index 792663a..a00fb4b 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallPropLexIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallPropLexIns.cs @@ -1,58 +1,57 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallPropLexIns : ASInstruction { - public class CallPropLexIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallPropLexIns(ABCFile abc) - : base(OPCode.CallPropLex, abc) - { } - public CallPropLexIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallPropLexIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } - public CallPropLexIns(ABCFile abc, int propertyNameIndex, int argCount) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - ArgCount = argCount; - } + public CallPropLexIns(ABCFile abc) + : base(OPCode.CallPropLex, abc) + { } + public CallPropLexIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallPropLexIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } + public CallPropLexIns(ABCFile abc, int propertyNameIndex, int argCount) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return (ArgCount + ResolveMultinamePops(PropertyName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + ResolveMultinamePops(PropertyName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallPropVoidIns.cs b/Flazzy/ABC/AVM2/Instructions/CallPropVoidIns.cs index ab6ade9..43dfe15 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallPropVoidIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallPropVoidIns.cs @@ -1,54 +1,53 @@ -using Flazzy.IO; -using Flazzy.ABC.AVM2.Instructions.Containers; +using Flazzy.ABC.AVM2.Instructions.Containers; +using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallPropVoidIns : ASInstruction, IPropertyContainer { - public class CallPropVoidIns : ASInstruction, IPropertyContainer - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallPropVoidIns(ABCFile abc) - : base(OPCode.CallPropVoid, abc) - { } - public CallPropVoidIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallPropVoidIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } - public CallPropVoidIns(ABCFile abc, int propertyNameIndex, int argCount) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - ArgCount = argCount; - } + public CallPropVoidIns(ABCFile abc) + : base(OPCode.CallPropVoid, abc) + { } + public CallPropVoidIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallPropVoidIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } + public CallPropVoidIns(ABCFile abc, int propertyNameIndex, int argCount) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return (ArgCount + ResolveMultinamePops(PropertyName) + 1); - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + ResolveMultinamePops(PropertyName) + 1); + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); + machine.Values.Pop(); } + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallPropertyIns.cs b/Flazzy/ABC/AVM2/Instructions/CallPropertyIns.cs index 1a5c860..2e2d01e 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallPropertyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallPropertyIns.cs @@ -1,59 +1,58 @@ -using Flazzy.IO; -using Flazzy.ABC.AVM2.Instructions.Containers; +using Flazzy.ABC.AVM2.Instructions.Containers; +using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallPropertyIns : ASInstruction, IPropertyContainer { - public class CallPropertyIns : ASInstruction, IPropertyContainer - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallPropertyIns(ABCFile abc) - : base(OPCode.CallProperty, abc) - { } - public CallPropertyIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallPropertyIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } - public CallPropertyIns(ABCFile abc, int propertyNameIndex, int argCount) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - ArgCount = argCount; - } + public CallPropertyIns(ABCFile abc) + : base(OPCode.CallProperty, abc) + { } + public CallPropertyIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallPropertyIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } + public CallPropertyIns(ABCFile abc, int propertyNameIndex, int argCount) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return (ArgCount + ResolveMultinamePops(PropertyName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + ResolveMultinamePops(PropertyName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallStaticIns.cs b/Flazzy/ABC/AVM2/Instructions/CallStaticIns.cs index 9a75f66..1c48b15 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallStaticIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallStaticIns.cs @@ -1,57 +1,56 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallStaticIns : ASInstruction { - public class CallStaticIns : ASInstruction - { - public int MethodIndex { get; set; } - public ASMethod Method => ABC.Methods[MethodIndex]; + public int MethodIndex { get; set; } + public ASMethod Method => ABC.Methods[MethodIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallStaticIns(ABCFile abc) - : base(OPCode.CallStatic, abc) - { } - public CallStaticIns(ABCFile abc, FlashReader input) - : this(abc) - { - MethodIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallStaticIns(ABCFile abc, int methodIndex) - : this(abc) - { - MethodIndex = methodIndex; - } - public CallStaticIns(ABCFile abc, int methodIndex, int argCount) - : this(abc) - { - MethodIndex = methodIndex; - ArgCount = argCount; - } + public CallStaticIns(ABCFile abc) + : base(OPCode.CallStatic, abc) + { } + public CallStaticIns(ABCFile abc, FlashReader input) + : this(abc) + { + MethodIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallStaticIns(ABCFile abc, int methodIndex) + : this(abc) + { + MethodIndex = methodIndex; + } + public CallStaticIns(ABCFile abc, int methodIndex, int argCount) + : this(abc) + { + MethodIndex = methodIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return ArgCount + 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return ArgCount + 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - machine.Values.Pop(); // Receiver - machine.Values.Push(null); + machine.Values.Pop(); } + machine.Values.Pop(); // Receiver + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(MethodIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(MethodIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallSuperIns.cs b/Flazzy/ABC/AVM2/Instructions/CallSuperIns.cs index f325cdc..57a44b9 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallSuperIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallSuperIns.cs @@ -1,58 +1,57 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallSuperIns : ASInstruction { - public class CallSuperIns : ASInstruction - { - public int MethodNameIndex { get; set; } - public ASMultiname MethodName => ABC.Pool.Multinames[MethodNameIndex]; + public int MethodNameIndex { get; set; } + public ASMultiname MethodName => ABC.Pool.Multinames[MethodNameIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallSuperIns(ABCFile abc) - : base(OPCode.CallSuper, abc) - { } - public CallSuperIns(ABCFile abc, FlashReader input) - : this(abc) - { - MethodNameIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallSuperIns(ABCFile abc, int methodNameIndex) - : this(abc) - { - MethodNameIndex = methodNameIndex; - } - public CallSuperIns(ABCFile abc, int methodNameIndex, int argCount) - : this(abc) - { - MethodNameIndex = methodNameIndex; - ArgCount = argCount; - } + public CallSuperIns(ABCFile abc) + : base(OPCode.CallSuper, abc) + { } + public CallSuperIns(ABCFile abc, FlashReader input) + : this(abc) + { + MethodNameIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallSuperIns(ABCFile abc, int methodNameIndex) + : this(abc) + { + MethodNameIndex = methodNameIndex; + } + public CallSuperIns(ABCFile abc, int methodNameIndex, int argCount) + : this(abc) + { + MethodNameIndex = methodNameIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return (ArgCount + ResolveMultinamePops(MethodName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + ResolveMultinamePops(MethodName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - ResolveMultiname(machine, MethodName); - object receiver = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + ResolveMultiname(machine, MethodName); + object receiver = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(MethodNameIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(MethodNameIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CallSuperVoidIns.cs b/Flazzy/ABC/AVM2/Instructions/CallSuperVoidIns.cs index f69841a..eb865d1 100644 --- a/Flazzy/ABC/AVM2/Instructions/CallSuperVoidIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CallSuperVoidIns.cs @@ -1,58 +1,57 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CallSuperVoidIns : ASInstruction { - public class CallSuperVoidIns : ASInstruction - { - public int MethodNameIndex { get; set; } - public ASMultiname MethodName => ABC.Pool.Multinames[MethodNameIndex]; + public int MethodNameIndex { get; set; } + public ASMultiname MethodName => ABC.Pool.Multinames[MethodNameIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public CallSuperVoidIns(ABCFile abc) - : base(OPCode.CallSuperVoid, abc) - { } - public CallSuperVoidIns(ABCFile abc, FlashReader input) - : this(abc) - { - MethodNameIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public CallSuperVoidIns(ABCFile abc, int methodNameIndex) - : this(abc) - { - MethodNameIndex = methodNameIndex; - } - public CallSuperVoidIns(ABCFile abc, int methodNameIndex, int argCount) - : this(abc) - { - MethodNameIndex = methodNameIndex; - ArgCount = argCount; - } + public CallSuperVoidIns(ABCFile abc) + : base(OPCode.CallSuperVoid, abc) + { } + public CallSuperVoidIns(ABCFile abc, FlashReader input) + : this(abc) + { + MethodNameIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public CallSuperVoidIns(ABCFile abc, int methodNameIndex) + : this(abc) + { + MethodNameIndex = methodNameIndex; + } + public CallSuperVoidIns(ABCFile abc, int methodNameIndex, int argCount) + : this(abc) + { + MethodNameIndex = methodNameIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return (ArgCount + ResolveMultinamePops(MethodName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + ResolveMultinamePops(MethodName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - ResolveMultiname(machine, MethodName); - object receiver = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + ResolveMultiname(machine, MethodName); + object receiver = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(MethodNameIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(MethodNameIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/CheckFilterIns.cs b/Flazzy/ABC/AVM2/Instructions/CheckFilterIns.cs index 8903b79..8fe34fb 100644 --- a/Flazzy/ABC/AVM2/Instructions/CheckFilterIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/CheckFilterIns.cs @@ -1,23 +1,22 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CheckFilterIns : ASInstruction { - public class CheckFilterIns : ASInstruction - { - public CheckFilterIns() - : base(OPCode.CheckFilter) - { } + public CheckFilterIns() + : base(OPCode.CheckFilter) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ConstructIns.cs b/Flazzy/ABC/AVM2/Instructions/ConstructIns.cs index ba9fe5d..ddb5f24 100644 --- a/Flazzy/ABC/AVM2/Instructions/ConstructIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ConstructIns.cs @@ -1,46 +1,45 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConstructIns : ASInstruction { - public class ConstructIns : ASInstruction - { - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public ConstructIns() - : base(OPCode.Construct) - { } - public ConstructIns(int argCount) - : this() - { - ArgCount = argCount; - } - public ConstructIns(FlashReader input) - : this() - { - ArgCount = input.ReadInt30(); - } + public ConstructIns() + : base(OPCode.Construct) + { } + public ConstructIns(int argCount) + : this() + { + ArgCount = argCount; + } + public ConstructIns(FlashReader input) + : this() + { + ArgCount = input.ReadInt30(); + } - public override int GetPopCount() - { - return (ArgCount + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - object obj = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ConstructPropIns.cs b/Flazzy/ABC/AVM2/Instructions/ConstructPropIns.cs index 4ba8e61..9594792 100644 --- a/Flazzy/ABC/AVM2/Instructions/ConstructPropIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ConstructPropIns.cs @@ -1,59 +1,58 @@ -using Flazzy.IO; -using Flazzy.ABC.AVM2.Instructions.Containers; +using Flazzy.ABC.AVM2.Instructions.Containers; +using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConstructPropIns : ASInstruction, IPropertyContainer { - public class ConstructPropIns : ASInstruction, IPropertyContainer - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public ConstructPropIns(ABCFile abc) - : base(OPCode.ConstructProp, abc) - { } - public ConstructPropIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - ArgCount = input.ReadInt30(); - } - public ConstructPropIns(ABCFile abc, int propertyNameIndex) - :this(abc) - { - PropertyNameIndex = propertyNameIndex; - } - public ConstructPropIns(ABCFile abc, int propertyNameIndex, int argCount) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - ArgCount = argCount; - } + public ConstructPropIns(ABCFile abc) + : base(OPCode.ConstructProp, abc) + { } + public ConstructPropIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + ArgCount = input.ReadInt30(); + } + public ConstructPropIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } + public ConstructPropIns(ABCFile abc, int propertyNameIndex, int argCount) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + ArgCount = argCount; + } - public override int GetPopCount() - { - return (ArgCount + ResolveMultinamePops(PropertyName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + ResolveMultinamePops(PropertyName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - machine.Values.Push(null); + machine.Values.Pop(); } + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ConstructSuperIns.cs b/Flazzy/ABC/AVM2/Instructions/ConstructSuperIns.cs index 42b649b..d47b223 100644 --- a/Flazzy/ABC/AVM2/Instructions/ConstructSuperIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ConstructSuperIns.cs @@ -1,41 +1,40 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConstructSuperIns : ASInstruction { - public class ConstructSuperIns : ASInstruction - { - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public ConstructSuperIns() - : base(OPCode.ConstructSuper) - { } - public ConstructSuperIns(int argCount) - : this() - { - ArgCount = argCount; - } - public ConstructSuperIns(FlashReader input) - : this() - { - ArgCount = input.ReadInt30(); - } + public ConstructSuperIns() + : base(OPCode.ConstructSuper) + { } + public ConstructSuperIns(int argCount) + : this() + { + ArgCount = argCount; + } + public ConstructSuperIns(FlashReader input) + : this() + { + ArgCount = input.ReadInt30(); + } - public override int GetPopCount() - { - return (ArgCount + 1); - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount + 1); + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - machine.Values.Pop(); - } - object obj = machine.Values.Pop(); + machine.Values.Pop(); } + object obj = machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Containers/IPropertyContainer.cs b/Flazzy/ABC/AVM2/Instructions/Containers/IPropertyContainer.cs index da0730e..ebcb2e7 100644 --- a/Flazzy/ABC/AVM2/Instructions/Containers/IPropertyContainer.cs +++ b/Flazzy/ABC/AVM2/Instructions/Containers/IPropertyContainer.cs @@ -1,8 +1,7 @@ -namespace Flazzy.ABC.AVM2.Instructions.Containers +namespace Flazzy.ABC.AVM2.Instructions.Containers; + +public interface IPropertyContainer { - public interface IPropertyContainer - { - int PropertyNameIndex { get; set; } - ASMultiname PropertyName { get; } - } + int PropertyNameIndex { get; set; } + ASMultiname PropertyName { get; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfEqualIns.cs index fbb0138..b192098 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfEqualIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfEqualIns : Jumper { - public class IfEqualIns : Jumper - { - public IfEqualIns() - : base(OPCode.IfEq) - { } - public IfEqualIns(FlashReader input) - : base(OPCode.IfEq, input) - { } + public IfEqualIns() + : base(OPCode.IfEq) + { } + public IfEqualIns(FlashReader input) + : base(OPCode.IfEq, input) + { } - public override bool? RunCondition(ASMachine machine) - { - dynamic right = machine.Values.Pop(); - dynamic left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + dynamic right = machine.Values.Pop(); + dynamic left = machine.Values.Pop(); + if (left == null || right == null) return null; - return (left == right); - } + return (left == right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfFalseIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfFalseIns.cs index 78d8016..b5808f1 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfFalseIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfFalseIns.cs @@ -1,22 +1,21 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfFalseIns : Jumper { - public class IfFalseIns : Jumper - { - public IfFalseIns() - : base(OPCode.IfFalse) - { } - public IfFalseIns(FlashReader input) - : base(OPCode.IfFalse, input) - { } + public IfFalseIns() + : base(OPCode.IfFalse) + { } + public IfFalseIns(FlashReader input) + : base(OPCode.IfFalse, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var value = (machine.Values.Pop() as bool?); - if (value == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var value = (machine.Values.Pop() as bool?); + if (value == null) return null; - return (value == false); - } + return (value == false); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterEqualIns.cs index 0b733bf..48c0285 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterEqualIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfGreaterEqualIns : Jumper { - public class IfGreaterEqualIns : Jumper - { - public IfGreaterEqualIns() - : base(OPCode.IfGe) - { } - public IfGreaterEqualIns(FlashReader input) - : base(OPCode.IfGe, input) - { } + public IfGreaterEqualIns() + : base(OPCode.IfGe) + { } + public IfGreaterEqualIns(FlashReader input) + : base(OPCode.IfGe, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return (Convert.ToDouble(left) >= Convert.ToDouble(right)); - } + return (Convert.ToDouble(left) >= Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterThanIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterThanIns.cs index e8743b4..2ba091d 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterThanIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfGreaterThanIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfGreaterThanIns : Jumper { - public class IfGreaterThanIns : Jumper - { - public IfGreaterThanIns() - : base(OPCode.IfGt) - { } - public IfGreaterThanIns(FlashReader input) - : base(OPCode.IfGt, input) - { } + public IfGreaterThanIns() + : base(OPCode.IfGt) + { } + public IfGreaterThanIns(FlashReader input) + : base(OPCode.IfGt, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return (Convert.ToDouble(left) > Convert.ToDouble(right)); - } + return (Convert.ToDouble(left) > Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessEqualIns.cs index 9d7ca0b..c790e50 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessEqualIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfLessEqualIns : Jumper { - public class IfLessEqualIns : Jumper - { - public IfLessEqualIns() - : base(OPCode.IfLe) - { } - public IfLessEqualIns(FlashReader input) - : base(OPCode.IfLe, input) - { } + public IfLessEqualIns() + : base(OPCode.IfLe) + { } + public IfLessEqualIns(FlashReader input) + : base(OPCode.IfLe, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return (Convert.ToDouble(left) <= Convert.ToDouble(right)); - } + return (Convert.ToDouble(left) <= Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessThanIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessThanIns.cs index 3778937..7ba1499 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessThanIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfLessThanIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfLessThanIns : Jumper { - public class IfLessThanIns : Jumper - { - public IfLessThanIns() - : base(OPCode.IfLt) - { } - public IfLessThanIns(FlashReader input) - : base(OPCode.IfLt, input) - { } + public IfLessThanIns() + : base(OPCode.IfLt) + { } + public IfLessThanIns(FlashReader input) + : base(OPCode.IfLt, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return Convert.ToDouble(left) < Convert.ToDouble(right); - } + return Convert.ToDouble(left) < Convert.ToDouble(right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotEqualIns.cs index 208bde7..d3606ca 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotEqualIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfNotEqualIns : Jumper { - public class IfNotEqualIns : Jumper - { - public IfNotEqualIns() - : base(OPCode.IfNe) - { } - public IfNotEqualIns(FlashReader input) - : base(OPCode.IfNe, input) - { } + public IfNotEqualIns() + : base(OPCode.IfNe) + { } + public IfNotEqualIns(FlashReader input) + : base(OPCode.IfNe, input) + { } - public override bool? RunCondition(ASMachine machine) - { - dynamic right = machine.Values.Pop(); - dynamic left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + dynamic right = machine.Values.Pop(); + dynamic left = machine.Values.Pop(); + if (left == null || right == null) return null; - return (left != right); - } + return (left != right); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterEqualIns.cs index b3fb4e1..6d220cf 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterEqualIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfNotGreaterEqualIns : Jumper { - public class IfNotGreaterEqualIns : Jumper - { - public IfNotGreaterEqualIns() - : base(OPCode.IfNGe) - { } - public IfNotGreaterEqualIns(FlashReader input) - : base(OPCode.IfNGe, input) - { } + public IfNotGreaterEqualIns() + : base(OPCode.IfNGe) + { } + public IfNotGreaterEqualIns(FlashReader input) + : base(OPCode.IfNGe, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return !(Convert.ToDouble(left) >= Convert.ToDouble(right)); - } + return !(Convert.ToDouble(left) >= Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterThanIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterThanIns.cs index 3561f31..8038414 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterThanIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotGreaterThanIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfNotGreaterThanIns : Jumper { - public class IfNotGreaterThanIns : Jumper - { - public IfNotGreaterThanIns() - : base(OPCode.IfNGt) - { } - public IfNotGreaterThanIns(FlashReader input) - : base(OPCode.IfNGt, input) - { } + public IfNotGreaterThanIns() + : base(OPCode.IfNGt) + { } + public IfNotGreaterThanIns(FlashReader input) + : base(OPCode.IfNGt, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return !(Convert.ToDouble(left) > Convert.ToDouble(right)); - } + return !(Convert.ToDouble(left) > Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessEqualIns.cs index 33acf3b..1f88d28 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessEqualIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfNotLessEqualIns : Jumper { - public class IfNotLessEqualIns : Jumper - { - public IfNotLessEqualIns() - : base(OPCode.IfNLe) - { } - public IfNotLessEqualIns(FlashReader input) - : base(OPCode.IfNLe, input) - { } + public IfNotLessEqualIns() + : base(OPCode.IfNLe) + { } + public IfNotLessEqualIns(FlashReader input) + : base(OPCode.IfNLe, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return !(Convert.ToDouble(left) <= Convert.ToDouble(right)); - } + return !(Convert.ToDouble(left) <= Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessThanIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessThanIns.cs index 01bbab5..dc85fef 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessThanIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfNotLessThanIns.cs @@ -1,23 +1,22 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfNotLessThanIns : Jumper { - public class IfNotLessThanIns : Jumper - { - public IfNotLessThanIns() - : base(OPCode.IfNLt) - { } - public IfNotLessThanIns(FlashReader input) - : base(OPCode.IfNLt, input) - { } + public IfNotLessThanIns() + : base(OPCode.IfNLt) + { } + public IfNotLessThanIns(FlashReader input) + : base(OPCode.IfNLt, input) + { } - public override bool? RunCondition(ASMachine machine) - { - var right = machine.Values.Pop(); - var left = machine.Values.Pop(); - if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + var right = machine.Values.Pop(); + var left = machine.Values.Pop(); + if (left == null || right == null) return null; - return !(Convert.ToDouble(left) < Convert.ToDouble(right)); - } + return !(Convert.ToDouble(left) < Convert.ToDouble(right)); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictEqualIns.cs index 3e06ce5..c6c5531 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictEqualIns.cs @@ -1,24 +1,23 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfStrictEqualIns : Jumper { - public class IfStrictEqualIns : Jumper - { - public IfStrictEqualIns() - : base(OPCode.IfStrictEq) - { } - public IfStrictEqualIns(FlashReader input) - : base(OPCode.IfStrictEq, input) - { } + public IfStrictEqualIns() + : base(OPCode.IfStrictEq) + { } + public IfStrictEqualIns(FlashReader input) + : base(OPCode.IfStrictEq, input) + { } - public override bool? RunCondition(ASMachine machine) - { - //var right = (machine.Values.Pop() as IComparable); - //var left = (machine.Values.Pop() as IComparable); - //if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + //var right = (machine.Values.Pop() as IComparable); + //var left = (machine.Values.Pop() as IComparable); + //if (left == null || right == null) return null; - //return (left.CompareTo(right) == 0); - return null; - } + //return (left.CompareTo(right) == 0); + return null; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictNotEqualIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictNotEqualIns.cs index d1e6b08..31818c5 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictNotEqualIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfStrictNotEqualIns.cs @@ -1,24 +1,23 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfStrictNotEqualIns : Jumper { - public class IfStrictNotEqualIns : Jumper - { - public IfStrictNotEqualIns() - : base(OPCode.IfStrictNE) - { } - public IfStrictNotEqualIns(FlashReader input) - : base(OPCode.IfStrictNE, input) - { } + public IfStrictNotEqualIns() + : base(OPCode.IfStrictNE) + { } + public IfStrictNotEqualIns(FlashReader input) + : base(OPCode.IfStrictNE, input) + { } - public override bool? RunCondition(ASMachine machine) - { - //var right = (machine.Values.Pop() as IComparable); - //var left = (machine.Values.Pop() as IComparable); - //if (left == null || right == null) return null; + public override bool? RunCondition(ASMachine machine) + { + //var right = (machine.Values.Pop() as IComparable); + //var left = (machine.Values.Pop() as IComparable); + //if (left == null || right == null) return null; - //return !left.Equals(right); - return null; - } + //return !left.Equals(right); + return null; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfTrueIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfTrueIns.cs index 7493380..910d3f5 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfTrueIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/IfTrueIns.cs @@ -1,19 +1,18 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IfTrueIns : Jumper { - public class IfTrueIns : Jumper - { - public IfTrueIns() - : base(OPCode.IfTrue) - { } - public IfTrueIns(FlashReader input) - : base(OPCode.IfTrue, input) - { } + public IfTrueIns() + : base(OPCode.IfTrue) + { } + public IfTrueIns(FlashReader input) + : base(OPCode.IfTrue, input) + { } - public override bool? RunCondition(ASMachine machine) - { - return (machine.Values.Pop() as bool?); - } + public override bool? RunCondition(ASMachine machine) + { + return (machine.Values.Pop() as bool?); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/JumpIns.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/JumpIns.cs index 74efb34..8f6d0d9 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/JumpIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/JumpIns.cs @@ -1,19 +1,18 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class JumpIns : Jumper { - public class JumpIns : Jumper - { - public JumpIns() - : base(OPCode.Jump) - { } - public JumpIns(FlashReader input) - : base(OPCode.Jump, input) - { } + public JumpIns() + : base(OPCode.Jump) + { } + public JumpIns(FlashReader input) + : base(OPCode.Jump, input) + { } - public override bool? RunCondition(ASMachine machine) - { - return true; - } + public override bool? RunCondition(ASMachine machine) + { + return true; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Control Transfer/Jumper.cs b/Flazzy/ABC/AVM2/Instructions/Control Transfer/Jumper.cs index 78eb883..4ffc148 100644 --- a/Flazzy/ABC/AVM2/Instructions/Control Transfer/Jumper.cs +++ b/Flazzy/ABC/AVM2/Instructions/Control Transfer/Jumper.cs @@ -1,81 +1,80 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public abstract class Jumper : ASInstruction { - public abstract class Jumper : ASInstruction - { - public uint Offset { get; set; } + public uint Offset { get; set; } - public Jumper(OPCode op) - : base(op) - { } - public Jumper(OPCode op, uint offset) - : this(op) - { - Offset = offset; - } - public Jumper(OPCode op, FlashReader input) - : this(op) - { - Offset = input.ReadUInt24(); - } + public Jumper(OPCode op) + : base(op) + { } + public Jumper(OPCode op, uint offset) + : this(op) + { + Offset = offset; + } + public Jumper(OPCode op, FlashReader input) + : this(op) + { + Offset = input.ReadUInt24(); + } - public override int GetPopCount() + public override int GetPopCount() + { + switch (OP) { - switch (OP) - { - case OPCode.Jump: + case OPCode.Jump: return 0; - case OPCode.IfTrue: - case OPCode.IfFalse: + case OPCode.IfTrue: + case OPCode.IfFalse: return 1; - default: return 2; - } + default: return 2; } - public override int GetPushCount() - { - return 0; - } - public override void Execute(ASMachine machine) + } + public override int GetPushCount() + { + return 0; + } + public override void Execute(ASMachine machine) + { + int popCount = GetPopCount(); + for (int i = 0; i < popCount; i++) { - int popCount = GetPopCount(); - for (int i = 0; i < popCount; i++) - { - machine.Values.Pop(); - } + machine.Values.Pop(); } - public abstract bool? RunCondition(ASMachine machine); + } + public abstract bool? RunCondition(ASMachine machine); - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteUInt24(Offset); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteUInt24(Offset); + } - public static bool IsValid(OPCode op) + public static bool IsValid(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.IfEq: - case OPCode.IfGe: - case OPCode.IfGt: - case OPCode.IfLe: - case OPCode.IfLt: - case OPCode.Jump: - case OPCode.IfNe: - case OPCode.IfNGe: - case OPCode.IfNGt: - case OPCode.IfNLe: - case OPCode.IfNLt: - case OPCode.IfTrue: - case OPCode.IfFalse: - case OPCode.IfStrictEq: - case OPCode.IfStrictNE: + case OPCode.IfEq: + case OPCode.IfGe: + case OPCode.IfGt: + case OPCode.IfLe: + case OPCode.IfLt: + case OPCode.Jump: + case OPCode.IfNe: + case OPCode.IfNGe: + case OPCode.IfNGt: + case OPCode.IfNLe: + case OPCode.IfNLt: + case OPCode.IfTrue: + case OPCode.IfFalse: + case OPCode.IfStrictEq: + case OPCode.IfStrictNE: return true; - default: return false; - } + default: return false; } } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DebugFileIns.cs b/Flazzy/ABC/AVM2/Instructions/DebugFileIns.cs index ef2739a..5ccde02 100644 --- a/Flazzy/ABC/AVM2/Instructions/DebugFileIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DebugFileIns.cs @@ -1,29 +1,28 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DebugFileIns : ASInstruction { - public class DebugFileIns : ASInstruction - { - public int FileNameIndex { get; set; } - public string FileName => ABC.Pool.Strings[FileNameIndex]; + public int FileNameIndex { get; set; } + public string FileName => ABC.Pool.Strings[FileNameIndex]; - public DebugFileIns(ABCFile abc) - : base(OPCode.DebugFile, abc) - { } - public DebugFileIns(ABCFile abc, FlashReader input) - : this(abc) - { - FileNameIndex = input.ReadInt30(); - } - public DebugFileIns(ABCFile abc, int fileNameIndex) - : this(abc) - { - FileNameIndex = fileNameIndex; - } + public DebugFileIns(ABCFile abc) + : base(OPCode.DebugFile, abc) + { } + public DebugFileIns(ABCFile abc, FlashReader input) + : this(abc) + { + FileNameIndex = input.ReadInt30(); + } + public DebugFileIns(ABCFile abc, int fileNameIndex) + : this(abc) + { + FileNameIndex = fileNameIndex; + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(FileNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(FileNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DebugIns.cs b/Flazzy/ABC/AVM2/Instructions/DebugIns.cs index 2efec6b..f1d739e 100644 --- a/Flazzy/ABC/AVM2/Instructions/DebugIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DebugIns.cs @@ -1,41 +1,40 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DebugIns : ASInstruction { - public class DebugIns : ASInstruction - { - public int NameIndex { get; set; } - public string Name => ABC.Pool.Strings[NameIndex]; + public int NameIndex { get; set; } + public string Name => ABC.Pool.Strings[NameIndex]; - public int Extra { get; set; } - public byte DebugType { get; set; } - public byte RegisterIndex { get; set; } + public int Extra { get; set; } + public byte DebugType { get; set; } + public byte RegisterIndex { get; set; } - public DebugIns(ABCFile abc) - : base(OPCode.Debug, abc) - { } - public DebugIns(ABCFile abc, FlashReader input) - : this(abc) - { - DebugType = input.ReadByte(); - NameIndex = input.ReadInt30(); - RegisterIndex = input.ReadByte(); - Extra = input.ReadInt30(); - } - public DebugIns(ABCFile abc, int nameIndex, byte debugType, byte registerIndex) - : this(abc) - { - NameIndex = nameIndex; - DebugType = debugType; - RegisterIndex = registerIndex; - } + public DebugIns(ABCFile abc) + : base(OPCode.Debug, abc) + { } + public DebugIns(ABCFile abc, FlashReader input) + : this(abc) + { + DebugType = input.ReadByte(); + NameIndex = input.ReadInt30(); + RegisterIndex = input.ReadByte(); + Extra = input.ReadInt30(); + } + public DebugIns(ABCFile abc, int nameIndex, byte debugType, byte registerIndex) + : this(abc) + { + NameIndex = nameIndex; + DebugType = debugType; + RegisterIndex = registerIndex; + } - protected override void WriteValuesTo(FlashWriter output) - { - output.Write(DebugType); - output.WriteInt30(NameIndex); - output.Write(RegisterIndex); - output.WriteInt30(Extra); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.Write(DebugType); + output.WriteInt30(NameIndex); + output.Write(RegisterIndex); + output.WriteInt30(Extra); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DebugLineIns.cs b/Flazzy/ABC/AVM2/Instructions/DebugLineIns.cs index fd01103..8f5cc39 100644 --- a/Flazzy/ABC/AVM2/Instructions/DebugLineIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DebugLineIns.cs @@ -1,28 +1,27 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DebugLineIns : ASInstruction { - public class DebugLineIns : ASInstruction - { - public int LineNumber { get; set; } + public int LineNumber { get; set; } - public DebugLineIns() - : base(OPCode.DebugLine) - { } - public DebugLineIns(int lineNumber) - : this() - { - LineNumber = lineNumber; - } - public DebugLineIns(FlashReader input) - : this() - { - LineNumber = input.ReadInt30(); - } + public DebugLineIns() + : base(OPCode.DebugLine) + { } + public DebugLineIns(int lineNumber) + : this() + { + LineNumber = lineNumber; + } + public DebugLineIns(FlashReader input) + : this() + { + LineNumber = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(LineNumber); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(LineNumber); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DeletePropertyIns.cs b/Flazzy/ABC/AVM2/Instructions/DeletePropertyIns.cs index bbbefa0..802b9dd 100644 --- a/Flazzy/ABC/AVM2/Instructions/DeletePropertyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DeletePropertyIns.cs @@ -1,44 +1,43 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DeletePropertyIns : ASInstruction { - public class DeletePropertyIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public DeletePropertyIns(ABCFile abc) - : base(OPCode.DeleteProperty, abc) - { } - public DeletePropertyIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public DeletePropertyIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public DeletePropertyIns(ABCFile abc) + : base(OPCode.DeleteProperty, abc) + { } + public DeletePropertyIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public DeletePropertyIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return (ResolveMultinamePops(PropertyName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return (ResolveMultinamePops(PropertyName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DupIns.cs b/Flazzy/ABC/AVM2/Instructions/DupIns.cs index c6cdd4a..c34fb0c 100644 --- a/Flazzy/ABC/AVM2/Instructions/DupIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DupIns.cs @@ -1,19 +1,18 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DupIns : ASInstruction { - public class DupIns : ASInstruction - { - public DupIns() - : base(OPCode.Dup) - { } + public DupIns() + : base(OPCode.Dup) + { } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Peek(); - machine.Values.Push(value); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Peek(); + machine.Values.Push(value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DxnsIns.cs b/Flazzy/ABC/AVM2/Instructions/DxnsIns.cs index 6949586..6f61b8c 100644 --- a/Flazzy/ABC/AVM2/Instructions/DxnsIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DxnsIns.cs @@ -1,19 +1,18 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DxnsIns : ASInstruction { - public class DxnsIns : ASInstruction - { - public int UriIndex { get; set; } - public string Uri => ABC.Pool.Strings[UriIndex]; + public int UriIndex { get; set; } + public string Uri => ABC.Pool.Strings[UriIndex]; - public DxnsIns(ABCFile abc) - : base(OPCode.Dxns, abc) - { } - public DxnsIns(ABCFile abc, FlashReader input) - : this(abc) - { - UriIndex = input.ReadInt30(); - } + public DxnsIns(ABCFile abc) + : base(OPCode.Dxns, abc) + { } + public DxnsIns(ABCFile abc, FlashReader input) + : this(abc) + { + UriIndex = input.ReadInt30(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/DxnsLateIns.cs b/Flazzy/ABC/AVM2/Instructions/DxnsLateIns.cs index 0ba6f8d..b6692e7 100644 --- a/Flazzy/ABC/AVM2/Instructions/DxnsLateIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/DxnsLateIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DxnsLateIns : ASInstruction { - public class DxnsLateIns : ASInstruction - { - public DxnsLateIns() - : base(OPCode.DxnsLate) - { } + public DxnsLateIns() + : base(OPCode.DxnsLate) + { } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Enums/OPCode.cs b/Flazzy/ABC/AVM2/Instructions/Enums/OPCode.cs index 1aad4c1..47f4e58 100644 --- a/Flazzy/ABC/AVM2/Instructions/Enums/OPCode.cs +++ b/Flazzy/ABC/AVM2/Instructions/Enums/OPCode.cs @@ -1,582 +1,581 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public enum OPCode { - public enum OPCode - { - /// - /// Add two values. - /// - Add = 0xa0, - /// - /// Add two integer values. - /// - Add_i = 0xc5, - /// - /// Apply type/generic parameters. - /// - ApplyType = 0x53, - /// - /// Return the same value, or null if not of the specified type. - /// - AsType = 0x86, - /// - /// Return the same value, or null if not of the specified type. - /// - AsTypeLate = 0x87, - /// - /// Bitwise AND(&). - /// - BitAnd = 0xa8, - /// - /// Bitwise NOT(~). - /// - BitNot = 0x97, - /// - /// Bitwise OR(|). - /// - BitOr = 0xa9, - /// - /// Bitwise exclusive OR(^). - /// - BitXor = 0xaa, - /// - /// Call a closure. - /// - Call = 0x41, - /// - /// Call a method identified by index in the object’s method table. - /// - CallMethod = 0x43, - /// - /// Call a property. - /// - CallProperty = 0x46, - /// - /// Call a property. - /// - CallPropLex = 0x4c, - /// - /// Call a property, discarding the return value. - /// - CallPropVoid = 0x4f, - /// - /// Call a method identified by index in the property. - /// - CallStatic = 0x44, - /// - /// Call a method on a base class. - /// - CallSuper = 0x45, - /// - /// Call a method on a base class, discarding the return value. - /// - CallSuperVoid = 0x4e, - /// - /// Check to make sure an object can have a filter operation performed on it. - /// - CheckFilter = 0x78, - /// - /// Coerce a value to a specified type. - /// - Coerce = 0x80, - /// - /// Coerce a value to the any type(*). - /// - Coerce_a = 0x82, - /// - /// Coerce a value to a string. - /// - Coerce_s = 0x85, - /// - /// Construct an instance. - /// - Construct = 0x42, - /// - /// Construct a property. - /// - ConstructProp = 0x4a, - /// - /// Construct an instance of the base class. - /// - ConstructSuper = 0x49, - /// - /// Convert a value to a bool. - /// - Convert_b = 0x76, - /// - /// Convert a value to an integer. - /// - Convert_i = 0x73, - /// - /// Convert a value to a double. - /// - Convert_d = 0x75, - /// - /// Convert a value to an object. - /// - Convert_o = 0x77, - /// - /// Convert a value to an unsigned integer. - /// - Convert_u = 0x74, - /// - /// Convert a value to a string. - /// - Convert_s = 0x70, - /// - /// Debugging info. - /// - Debug = 0xef, - /// - /// Debugging line number info. - /// - DebugFile = 0xf1, - /// - /// Debugging line number info. - /// - DebugLine = 0xf0, - /// - /// Decrement a local register value. - /// - DecLocal = 0x94, - /// - /// Decrement a local register value. - /// - DecLocal_i = 0xc3, - /// - /// Decrement a value. - /// - Decrement = 0x93, - /// - /// Decrement an integer value. - /// - Decrement_i = 0xc1, - /// - /// Delete a property. - /// - DeleteProperty = 0x6a, - /// - /// Divide two values. - /// - Divide = 0xa3, - /// - /// Duplicates the top value on the stack. - /// - Dup = 0x2a, - /// - /// Sets the default XML namespace. - /// - Dxns = 0x06, - /// - /// Sets the default XML namespace with a value determined at runtime. - /// - DxnsLate = 0x07, - /// - /// Compare two values. - /// - Equals = 0xab, - /// - /// Escape an xml attribute. - /// - Esc_XAttr = 0x72, - /// - /// Escape an xml element. - /// - Esc_XElem = 0x71, - /// - /// Search the scope stack for a property. - /// - FindProperty = 0x5e, - /// - /// Find a property. - /// - FindPropStrict = 0x5d, - /// - /// Get descendants. - /// - GetDescendants = 0x59, - /// - /// Gets the global scope. - /// - GetGlobalScope = 0x64, - /// - /// Get the value of a slot on the global scope. - /// - GetGlobalSlot = 0x6e, - /// - /// Find and get a property. - /// - GetLex = 0x60, - /// - /// Get a local register. - /// - GetLocal = 0x62, - /// - /// Get local register 0. - /// - GetLocal_0 = 0xd0, - /// - /// Get local register 1. - /// - GetLocal_1 = 0xd1, - /// - /// Get local register 2. - /// - GetLocal_2 = 0xd2, - /// - /// Get local register 3. - /// - GetLocal_3 = 0xd3, - /// - /// Get a property. - /// - GetProperty = 0x66, - /// - /// Get a scope object. - /// - GetScopeObject = 0x65, - /// - /// Get the value of a slot. - /// - GetSlot = 0x6c, - /// - /// Gets a property from a base class. - /// - GetSuper = 0x04, - /// - /// Determine if one value is greater than or equal to another. - /// - GreaterEquals = 0xb0, - /// - /// Determine if one value is greater than another. - /// - GreaterThan = 0xaf, - /// - /// Determine if the given object has any more properties. - /// - HasNext = 0x1f, - /// - /// Determine if the given object has any more properties. - /// - HasNext2 = 0x32, - /// - /// Branch if the first value is equal to the second value. - /// - IfEq = 0x13, - /// - /// Branch if false. - /// - IfFalse = 0x12, - /// - /// Branch if the first value is greater than or equal to the second value. - /// - IfGe = 0x18, - /// - /// Branch if the first value is greater than the second value. - /// - IfGt = 0x17, - /// - /// Branch if the first value is less than or equal to the second value. - /// - IfLe = 0x16, - /// - /// Branch if the first value is less than the second value. - /// - IfLt = 0x15, - /// - /// Branch if the first value is not greater than or equal to the second value. - /// - IfNGe = 0x0f, - /// - /// Branch if the first value is not greater than the second value. - /// - IfNGt = 0x0e, - /// - /// Branch if the first value is not less than or equal to the second value. - /// - IfNLe = 0x0d, - /// - /// Branch if the first value is not less than the second value. - /// - IfNLt = 0x0c, - /// - /// Branch if the first value is not equal to the second value. - /// - IfNe = 0x14, - /// - /// Branch if the first value is equal to the second value. - /// - IfStrictEq = 0x19, - /// - /// Branch if the first value is not equal to the second value. - /// - IfStrictNE = 0x1a, - /// - /// Branch if true. - /// - IfTrue = 0x11, - /// - /// Determine whether an object has a named property. - /// - In = 0xb4, - /// - /// Increment a local register value. - /// - IncLocal = 0x92, - /// - /// Increment a local register value. - /// - IncLocal_i = 0xc2, - /// - /// Increment a value. - /// - Increment = 0x91, - /// - /// Increment an integer value. - /// - Increment_i = 0xc0, - /// - /// Initialize a property. - /// - InitProperty = 0x68, - /// - /// Check the prototype chain of an object for the existence of a type. - /// - InstanceOf = 0xb1, - /// - /// Checks whether an object is of a certain type. - /// - IsType = 0xb2, - /// - /// Checks whether an object is of a certain type. - /// - IsTypeLate = 0xb3, - /// - /// Unconditional branch. - /// - Jump = 0x10, - /// - /// Kills a local register. - /// - Kill = 0x08, - /// - /// Do nothing. - /// - Label = 0x09, - /// - /// Determine if one value is less than or equal to another. - /// - LessEquals = 0xae, - /// - /// Determine of one value is less than another. - /// - LessThan = 0xad, - /// - /// Jump to different locations based on an index. - /// - LookUpSwitch = 0x1b, - /// - /// Bitwise left shift. - /// - LShift = 0xa5, - /// - /// Perform modulo division on two values. - /// - Modulo = 0xa4, - /// - /// Multiply two values. - /// - Multiply = 0xa2, - /// - /// Multiply two integer values. - /// - Multiply_i = 0xc7, - /// - /// Negate a value. - /// - Negate = 0x90, - /// - /// Negate an integer value. - /// - Negate_i = 0xc4, - /// - /// Create a new activation object. - /// - NewActivation = 0x57, - /// - /// Create a new array. - /// - NewArray = 0x56, - /// - /// Create a new catch scope. - /// - NewCatch = 0x5a, - /// - /// Create a new class. - /// - NewClass = 0x58, - /// - /// Create a new function object. - /// - NewFunction = 0x40, - /// - /// Create a new object. - /// - NewObject = 0x55, - /// - /// Get the name of the next property when iterating over an object. - /// - NextName = 0x1e, - /// - /// Get the name of the next property when iterating over an object. - /// - NextValue = 0x23, - /// - /// Do nothing. - /// - Nop = 0x02, - /// - /// Boolean negation. - /// - Not = 0x96, - /// - /// Pop the top value from the stack. - /// - Pop = 0x29, - /// - /// Pop a scope off of the scope stack. - /// - PopScope = 0x1d, - /// - /// Push a byte value. - /// - PushByte = 0x24, - /// - /// Push a double value onto the stack. - /// - PushDouble = 0x2f, - /// - /// Push false. - /// - PushFalse = 0x27, - /// - /// Push an int value onto the stack. - /// - PushInt = 0x2d, - /// - /// Push a namespace. - /// - PushNamespace = 0x31, - /// - /// Push NaN(Not A Number). - /// - PushNan = 0x28, - /// - /// Push null. - /// - PushNull = 0x20, - /// - /// Push an object onto the scope stack. - /// - PushScope = 0x30, - /// - /// Push a short value. - /// - PushShort = 0x25, - /// - /// Push a string value onto the stack. - /// - PushString = 0x2c, - /// - /// Push true. - /// - PushTrue = 0x26, - /// - /// Push an unsigned int value onto the stack. - /// - PushUInt = 0x2e, - /// - /// Push undefined. - /// - PushUndefined = 0x21, - /// - /// Push a with scope onto the scope stack. - /// - PushWith = 0x1c, - /// - /// Return a value from a method. - /// - ReturnValue = 0x48, - /// - /// Return from a method. - /// - ReturnVoid = 0x47, - /// - /// Signed bitwise right shift. - /// - RShift = 0xa6, - /// - /// Set a local register. - /// - SetLocal = 0x63, - /// - /// Set local register 0. - /// - SetLocal_0 = 0xd4, - /// - /// Set local register 1. - /// - SetLocal_1 = 0xd5, - /// - /// Set local register 2. - /// - SetLocal_2 = 0xd6, - /// - /// Set local register 3. - /// - SetLocal_3 = 0xd7, - /// - /// Set the value of a slot on the global scope. - /// - SetGlobalSlot = 0x6f, - /// - /// Set a property. - /// - SetProperty = 0x61, - /// - /// Set the value of a slot. - /// - SetSlot = 0x6d, - /// - /// Sets a property in a base class. - /// - SetSuper = 0x05, - /// - /// Compare two values strictly. - /// - StrictEquals = 0xac, - /// - /// Subtract one value from another. - /// - Subtract = 0xa1, - /// - /// Subtract an integer value from another integer value. - /// - Subtract_i = 0xc6, - /// - /// Swap the top two operands on the stack. - /// - Swap = 0x2b, - /// - /// Throws an exception. - /// - Throw = 0x03, - /// - /// Get the type name of a value. - /// - TypeOf = 0x95, - /// - /// Unsigned bitwise right shift. - /// - URShift = 0xa7 - } + /// + /// Add two values. + /// + Add = 0xa0, + /// + /// Add two integer values. + /// + Add_i = 0xc5, + /// + /// Apply type/generic parameters. + /// + ApplyType = 0x53, + /// + /// Return the same value, or null if not of the specified type. + /// + AsType = 0x86, + /// + /// Return the same value, or null if not of the specified type. + /// + AsTypeLate = 0x87, + /// + /// Bitwise AND(&). + /// + BitAnd = 0xa8, + /// + /// Bitwise NOT(~). + /// + BitNot = 0x97, + /// + /// Bitwise OR(|). + /// + BitOr = 0xa9, + /// + /// Bitwise exclusive OR(^). + /// + BitXor = 0xaa, + /// + /// Call a closure. + /// + Call = 0x41, + /// + /// Call a method identified by index in the object’s method table. + /// + CallMethod = 0x43, + /// + /// Call a property. + /// + CallProperty = 0x46, + /// + /// Call a property. + /// + CallPropLex = 0x4c, + /// + /// Call a property, discarding the return value. + /// + CallPropVoid = 0x4f, + /// + /// Call a method identified by index in the property. + /// + CallStatic = 0x44, + /// + /// Call a method on a base class. + /// + CallSuper = 0x45, + /// + /// Call a method on a base class, discarding the return value. + /// + CallSuperVoid = 0x4e, + /// + /// Check to make sure an object can have a filter operation performed on it. + /// + CheckFilter = 0x78, + /// + /// Coerce a value to a specified type. + /// + Coerce = 0x80, + /// + /// Coerce a value to the any type(*). + /// + Coerce_a = 0x82, + /// + /// Coerce a value to a string. + /// + Coerce_s = 0x85, + /// + /// Construct an instance. + /// + Construct = 0x42, + /// + /// Construct a property. + /// + ConstructProp = 0x4a, + /// + /// Construct an instance of the base class. + /// + ConstructSuper = 0x49, + /// + /// Convert a value to a bool. + /// + Convert_b = 0x76, + /// + /// Convert a value to an integer. + /// + Convert_i = 0x73, + /// + /// Convert a value to a double. + /// + Convert_d = 0x75, + /// + /// Convert a value to an object. + /// + Convert_o = 0x77, + /// + /// Convert a value to an unsigned integer. + /// + Convert_u = 0x74, + /// + /// Convert a value to a string. + /// + Convert_s = 0x70, + /// + /// Debugging info. + /// + Debug = 0xef, + /// + /// Debugging line number info. + /// + DebugFile = 0xf1, + /// + /// Debugging line number info. + /// + DebugLine = 0xf0, + /// + /// Decrement a local register value. + /// + DecLocal = 0x94, + /// + /// Decrement a local register value. + /// + DecLocal_i = 0xc3, + /// + /// Decrement a value. + /// + Decrement = 0x93, + /// + /// Decrement an integer value. + /// + Decrement_i = 0xc1, + /// + /// Delete a property. + /// + DeleteProperty = 0x6a, + /// + /// Divide two values. + /// + Divide = 0xa3, + /// + /// Duplicates the top value on the stack. + /// + Dup = 0x2a, + /// + /// Sets the default XML namespace. + /// + Dxns = 0x06, + /// + /// Sets the default XML namespace with a value determined at runtime. + /// + DxnsLate = 0x07, + /// + /// Compare two values. + /// + Equals = 0xab, + /// + /// Escape an xml attribute. + /// + Esc_XAttr = 0x72, + /// + /// Escape an xml element. + /// + Esc_XElem = 0x71, + /// + /// Search the scope stack for a property. + /// + FindProperty = 0x5e, + /// + /// Find a property. + /// + FindPropStrict = 0x5d, + /// + /// Get descendants. + /// + GetDescendants = 0x59, + /// + /// Gets the global scope. + /// + GetGlobalScope = 0x64, + /// + /// Get the value of a slot on the global scope. + /// + GetGlobalSlot = 0x6e, + /// + /// Find and get a property. + /// + GetLex = 0x60, + /// + /// Get a local register. + /// + GetLocal = 0x62, + /// + /// Get local register 0. + /// + GetLocal_0 = 0xd0, + /// + /// Get local register 1. + /// + GetLocal_1 = 0xd1, + /// + /// Get local register 2. + /// + GetLocal_2 = 0xd2, + /// + /// Get local register 3. + /// + GetLocal_3 = 0xd3, + /// + /// Get a property. + /// + GetProperty = 0x66, + /// + /// Get a scope object. + /// + GetScopeObject = 0x65, + /// + /// Get the value of a slot. + /// + GetSlot = 0x6c, + /// + /// Gets a property from a base class. + /// + GetSuper = 0x04, + /// + /// Determine if one value is greater than or equal to another. + /// + GreaterEquals = 0xb0, + /// + /// Determine if one value is greater than another. + /// + GreaterThan = 0xaf, + /// + /// Determine if the given object has any more properties. + /// + HasNext = 0x1f, + /// + /// Determine if the given object has any more properties. + /// + HasNext2 = 0x32, + /// + /// Branch if the first value is equal to the second value. + /// + IfEq = 0x13, + /// + /// Branch if false. + /// + IfFalse = 0x12, + /// + /// Branch if the first value is greater than or equal to the second value. + /// + IfGe = 0x18, + /// + /// Branch if the first value is greater than the second value. + /// + IfGt = 0x17, + /// + /// Branch if the first value is less than or equal to the second value. + /// + IfLe = 0x16, + /// + /// Branch if the first value is less than the second value. + /// + IfLt = 0x15, + /// + /// Branch if the first value is not greater than or equal to the second value. + /// + IfNGe = 0x0f, + /// + /// Branch if the first value is not greater than the second value. + /// + IfNGt = 0x0e, + /// + /// Branch if the first value is not less than or equal to the second value. + /// + IfNLe = 0x0d, + /// + /// Branch if the first value is not less than the second value. + /// + IfNLt = 0x0c, + /// + /// Branch if the first value is not equal to the second value. + /// + IfNe = 0x14, + /// + /// Branch if the first value is equal to the second value. + /// + IfStrictEq = 0x19, + /// + /// Branch if the first value is not equal to the second value. + /// + IfStrictNE = 0x1a, + /// + /// Branch if true. + /// + IfTrue = 0x11, + /// + /// Determine whether an object has a named property. + /// + In = 0xb4, + /// + /// Increment a local register value. + /// + IncLocal = 0x92, + /// + /// Increment a local register value. + /// + IncLocal_i = 0xc2, + /// + /// Increment a value. + /// + Increment = 0x91, + /// + /// Increment an integer value. + /// + Increment_i = 0xc0, + /// + /// Initialize a property. + /// + InitProperty = 0x68, + /// + /// Check the prototype chain of an object for the existence of a type. + /// + InstanceOf = 0xb1, + /// + /// Checks whether an object is of a certain type. + /// + IsType = 0xb2, + /// + /// Checks whether an object is of a certain type. + /// + IsTypeLate = 0xb3, + /// + /// Unconditional branch. + /// + Jump = 0x10, + /// + /// Kills a local register. + /// + Kill = 0x08, + /// + /// Do nothing. + /// + Label = 0x09, + /// + /// Determine if one value is less than or equal to another. + /// + LessEquals = 0xae, + /// + /// Determine of one value is less than another. + /// + LessThan = 0xad, + /// + /// Jump to different locations based on an index. + /// + LookUpSwitch = 0x1b, + /// + /// Bitwise left shift. + /// + LShift = 0xa5, + /// + /// Perform modulo division on two values. + /// + Modulo = 0xa4, + /// + /// Multiply two values. + /// + Multiply = 0xa2, + /// + /// Multiply two integer values. + /// + Multiply_i = 0xc7, + /// + /// Negate a value. + /// + Negate = 0x90, + /// + /// Negate an integer value. + /// + Negate_i = 0xc4, + /// + /// Create a new activation object. + /// + NewActivation = 0x57, + /// + /// Create a new array. + /// + NewArray = 0x56, + /// + /// Create a new catch scope. + /// + NewCatch = 0x5a, + /// + /// Create a new class. + /// + NewClass = 0x58, + /// + /// Create a new function object. + /// + NewFunction = 0x40, + /// + /// Create a new object. + /// + NewObject = 0x55, + /// + /// Get the name of the next property when iterating over an object. + /// + NextName = 0x1e, + /// + /// Get the name of the next property when iterating over an object. + /// + NextValue = 0x23, + /// + /// Do nothing. + /// + Nop = 0x02, + /// + /// Boolean negation. + /// + Not = 0x96, + /// + /// Pop the top value from the stack. + /// + Pop = 0x29, + /// + /// Pop a scope off of the scope stack. + /// + PopScope = 0x1d, + /// + /// Push a byte value. + /// + PushByte = 0x24, + /// + /// Push a double value onto the stack. + /// + PushDouble = 0x2f, + /// + /// Push false. + /// + PushFalse = 0x27, + /// + /// Push an int value onto the stack. + /// + PushInt = 0x2d, + /// + /// Push a namespace. + /// + PushNamespace = 0x31, + /// + /// Push NaN(Not A Number). + /// + PushNan = 0x28, + /// + /// Push null. + /// + PushNull = 0x20, + /// + /// Push an object onto the scope stack. + /// + PushScope = 0x30, + /// + /// Push a short value. + /// + PushShort = 0x25, + /// + /// Push a string value onto the stack. + /// + PushString = 0x2c, + /// + /// Push true. + /// + PushTrue = 0x26, + /// + /// Push an unsigned int value onto the stack. + /// + PushUInt = 0x2e, + /// + /// Push undefined. + /// + PushUndefined = 0x21, + /// + /// Push a with scope onto the scope stack. + /// + PushWith = 0x1c, + /// + /// Return a value from a method. + /// + ReturnValue = 0x48, + /// + /// Return from a method. + /// + ReturnVoid = 0x47, + /// + /// Signed bitwise right shift. + /// + RShift = 0xa6, + /// + /// Set a local register. + /// + SetLocal = 0x63, + /// + /// Set local register 0. + /// + SetLocal_0 = 0xd4, + /// + /// Set local register 1. + /// + SetLocal_1 = 0xd5, + /// + /// Set local register 2. + /// + SetLocal_2 = 0xd6, + /// + /// Set local register 3. + /// + SetLocal_3 = 0xd7, + /// + /// Set the value of a slot on the global scope. + /// + SetGlobalSlot = 0x6f, + /// + /// Set a property. + /// + SetProperty = 0x61, + /// + /// Set the value of a slot. + /// + SetSlot = 0x6d, + /// + /// Sets a property in a base class. + /// + SetSuper = 0x05, + /// + /// Compare two values strictly. + /// + StrictEquals = 0xac, + /// + /// Subtract one value from another. + /// + Subtract = 0xa1, + /// + /// Subtract an integer value from another integer value. + /// + Subtract_i = 0xc6, + /// + /// Swap the top two operands on the stack. + /// + Swap = 0x2b, + /// + /// Throws an exception. + /// + Throw = 0x03, + /// + /// Get the type name of a value. + /// + TypeOf = 0x95, + /// + /// Unsigned bitwise right shift. + /// + URShift = 0xa7 } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/EscXAttrIns.cs b/Flazzy/ABC/AVM2/Instructions/EscXAttrIns.cs index 6c95d7a..1ded94d 100644 --- a/Flazzy/ABC/AVM2/Instructions/EscXAttrIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/EscXAttrIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class EscXAttrIns : ASInstruction { - public class EscXAttrIns : ASInstruction - { - public EscXAttrIns() - : base(OPCode.Esc_XAttr) - { } + public EscXAttrIns() + : base(OPCode.Esc_XAttr) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = Convert.ToString(value); - } - machine.Values.Push(result); + result = Convert.ToString(value); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/EscXElemIns.cs b/Flazzy/ABC/AVM2/Instructions/EscXElemIns.cs index dabac46..f7e3511 100644 --- a/Flazzy/ABC/AVM2/Instructions/EscXElemIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/EscXElemIns.cs @@ -1,23 +1,22 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class EscXElemIns : ASInstruction { - public class EscXElemIns : ASInstruction - { - public EscXElemIns() - : base(OPCode.Esc_XElem) - { } + public EscXElemIns() + : base(OPCode.Esc_XElem) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(value.ToString()); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(value.ToString()); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/FindPropStrictIns.cs b/Flazzy/ABC/AVM2/Instructions/FindPropStrictIns.cs index 44c23be..3e61325 100644 --- a/Flazzy/ABC/AVM2/Instructions/FindPropStrictIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/FindPropStrictIns.cs @@ -1,43 +1,42 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class FindPropStrictIns : ASInstruction { - public class FindPropStrictIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public FindPropStrictIns(ABCFile abc) - : base(OPCode.FindPropStrict, abc) - { } - public FindPropStrictIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public FindPropStrictIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public FindPropStrictIns(ABCFile abc) + : base(OPCode.FindPropStrict, abc) + { } + public FindPropStrictIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public FindPropStrictIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return ResolveMultinamePops(PropertyName); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - ResolveMultiname(machine, PropertyName); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return ResolveMultinamePops(PropertyName); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + ResolveMultiname(machine, PropertyName); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/FindPropertyIns.cs b/Flazzy/ABC/AVM2/Instructions/FindPropertyIns.cs index 17b451a..98b7ede 100644 --- a/Flazzy/ABC/AVM2/Instructions/FindPropertyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/FindPropertyIns.cs @@ -1,43 +1,42 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class FindPropertyIns : ASInstruction { - public class FindPropertyIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public FindPropertyIns(ABCFile abc) - : base(OPCode.FindProperty, abc) - { } - public FindPropertyIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public FindPropertyIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public FindPropertyIns(ABCFile abc) + : base(OPCode.FindProperty, abc) + { } + public FindPropertyIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public FindPropertyIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return ResolveMultinamePops(PropertyName); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - ResolveMultiname(machine, PropertyName); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return ResolveMultinamePops(PropertyName); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + ResolveMultiname(machine, PropertyName); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetDescendantsIns.cs b/Flazzy/ABC/AVM2/Instructions/GetDescendantsIns.cs index f89d158..a096e8b 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetDescendantsIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetDescendantsIns.cs @@ -1,44 +1,43 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetDescendantsIns : ASInstruction { - public class GetDescendantsIns : ASInstruction - { - public int DescendantIndex { get; set; } - public ASMultiname Descendant => ABC.Pool.Multinames[DescendantIndex]; + public int DescendantIndex { get; set; } + public ASMultiname Descendant => ABC.Pool.Multinames[DescendantIndex]; - public GetDescendantsIns(ABCFile abc) - : base(OPCode.GetDescendants, abc) - { } - public GetDescendantsIns(ABCFile abc, FlashReader input) - : this(abc) - { - DescendantIndex = input.ReadInt30(); - } - public GetDescendantsIns(ABCFile abc, int descendantIndex) - : this(abc) - { - DescendantIndex = descendantIndex; - } + public GetDescendantsIns(ABCFile abc) + : base(OPCode.GetDescendants, abc) + { } + public GetDescendantsIns(ABCFile abc, FlashReader input) + : this(abc) + { + DescendantIndex = input.ReadInt30(); + } + public GetDescendantsIns(ABCFile abc, int descendantIndex) + : this(abc) + { + DescendantIndex = descendantIndex; + } - public override int GetPopCount() - { - return (ResolveMultinamePops(Descendant) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - ResolveMultiname(machine, Descendant); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return (ResolveMultinamePops(Descendant) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + ResolveMultiname(machine, Descendant); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(DescendantIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(DescendantIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetGlobalScopeIns.cs b/Flazzy/ABC/AVM2/Instructions/GetGlobalScopeIns.cs index 7237d07..8d6106a 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetGlobalScopeIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetGlobalScopeIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetGlobalScopeIns : ASInstruction { - public class GetGlobalScopeIns : ASInstruction - { - public GetGlobalScopeIns() - : base(OPCode.GetGlobalScope) - { } + public GetGlobalScopeIns() + : base(OPCode.GetGlobalScope) + { } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetLexIns.cs b/Flazzy/ABC/AVM2/Instructions/GetLexIns.cs index 8192237..decb786 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetLexIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetLexIns.cs @@ -1,38 +1,37 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetLexIns : ASInstruction { - public class GetLexIns : ASInstruction - { - public int TypeNameIndex { get; set; } - public ASMultiname TypeName => ABC.Pool.Multinames[TypeNameIndex]; + public int TypeNameIndex { get; set; } + public ASMultiname TypeName => ABC.Pool.Multinames[TypeNameIndex]; - public GetLexIns(ABCFile abc) - : base(OPCode.GetLex, abc) - { } - public GetLexIns(ABCFile abc, FlashReader input) - : this(abc) - { - TypeNameIndex = input.ReadInt30(); - } - public GetLexIns(ABCFile abc, int typeNameIndex) - : this(abc) - { - TypeNameIndex = typeNameIndex; - } + public GetLexIns(ABCFile abc) + : base(OPCode.GetLex, abc) + { } + public GetLexIns(ABCFile abc, FlashReader input) + : this(abc) + { + TypeNameIndex = input.ReadInt30(); + } + public GetLexIns(ABCFile abc, int typeNameIndex) + : this(abc) + { + TypeNameIndex = typeNameIndex; + } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(TypeNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(TypeNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetPropertyIns.cs b/Flazzy/ABC/AVM2/Instructions/GetPropertyIns.cs index 15022f8..d74b8fd 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetPropertyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetPropertyIns.cs @@ -1,44 +1,43 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetPropertyIns : ASInstruction { - public class GetPropertyIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public GetPropertyIns(ABCFile abc) - : base(OPCode.GetProperty, abc) - { } - public GetPropertyIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public GetPropertyIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public GetPropertyIns(ABCFile abc) + : base(OPCode.GetProperty, abc) + { } + public GetPropertyIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public GetPropertyIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return (ResolveMultinamePops(PropertyName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return (ResolveMultinamePops(PropertyName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetScopeObjectIns.cs b/Flazzy/ABC/AVM2/Instructions/GetScopeObjectIns.cs index 90d5070..73479b5 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetScopeObjectIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetScopeObjectIns.cs @@ -1,37 +1,36 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetScopeObjectIns : ASInstruction { - public class GetScopeObjectIns : ASInstruction - { - public byte ScopeIndex { get; set; } + public byte ScopeIndex { get; set; } - public GetScopeObjectIns() - : base(OPCode.GetScopeObject) - { } - public GetScopeObjectIns(byte scopeIndex) - : this() - { - ScopeIndex = scopeIndex; - } - public GetScopeObjectIns(FlashReader input) - : this() - { - ScopeIndex = input.ReadByte(); - } + public GetScopeObjectIns() + : base(OPCode.GetScopeObject) + { } + public GetScopeObjectIns(byte scopeIndex) + : this() + { + ScopeIndex = scopeIndex; + } + public GetScopeObjectIns(FlashReader input) + : this() + { + ScopeIndex = input.ReadByte(); + } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.Write(ScopeIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.Write(ScopeIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetSlotIns.cs b/Flazzy/ABC/AVM2/Instructions/GetSlotIns.cs index 5763a7c..eef8169 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetSlotIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetSlotIns.cs @@ -1,42 +1,41 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetSlotIns : ASInstruction { - public class GetSlotIns : ASInstruction - { - public int SlotIndex { get; set; } + public int SlotIndex { get; set; } - public GetSlotIns() - : base(OPCode.GetSlot) - { } - public GetSlotIns(int slotIndex) - : this() - { - SlotIndex = slotIndex; - } - public GetSlotIns(FlashReader input) - : this() - { - SlotIndex = input.ReadInt30(); - } + public GetSlotIns() + : base(OPCode.GetSlot) + { } + public GetSlotIns(int slotIndex) + : this() + { + SlotIndex = slotIndex; + } + public GetSlotIns(FlashReader input) + : this() + { + SlotIndex = input.ReadInt30(); + } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(SlotIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(SlotIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/GetSuperIns.cs b/Flazzy/ABC/AVM2/Instructions/GetSuperIns.cs index 420b766..2f3a124 100644 --- a/Flazzy/ABC/AVM2/Instructions/GetSuperIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/GetSuperIns.cs @@ -1,44 +1,43 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetSuperIns : ASInstruction { - public class GetSuperIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public GetSuperIns(ABCFile abc) - : base(OPCode.GetSuper, abc) - { } - public GetSuperIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public GetSuperIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public GetSuperIns(ABCFile abc) + : base(OPCode.GetSuper, abc) + { } + public GetSuperIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public GetSuperIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return (ResolveMultinamePops(PropertyName) + 1); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return (ResolveMultinamePops(PropertyName) + 1); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/HasNext2Ins.cs b/Flazzy/ABC/AVM2/Instructions/HasNext2Ins.cs index 5fe1ecf..1b0852e 100644 --- a/Flazzy/ABC/AVM2/Instructions/HasNext2Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/HasNext2Ins.cs @@ -1,41 +1,40 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class HasNext2Ins : ASInstruction { - public class HasNext2Ins : ASInstruction - { - public int ObjectIndex { get; set; } - public int RegisterIndex { get; set; } + public int ObjectIndex { get; set; } + public int RegisterIndex { get; set; } - public HasNext2Ins() - : base(OPCode.HasNext2) - { } - public HasNext2Ins(FlashReader input) - : this() - { - ObjectIndex = input.ReadInt30(); - RegisterIndex = input.ReadInt30(); - } - public HasNext2Ins(int objectIndex, int registerIndex) - : this() - { - ObjectIndex = objectIndex; - RegisterIndex = registerIndex; - } + public HasNext2Ins() + : base(OPCode.HasNext2) + { } + public HasNext2Ins(FlashReader input) + : this() + { + ObjectIndex = input.ReadInt30(); + RegisterIndex = input.ReadInt30(); + } + public HasNext2Ins(int objectIndex, int registerIndex) + : this() + { + ObjectIndex = objectIndex; + RegisterIndex = registerIndex; + } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ObjectIndex); - output.WriteInt30(RegisterIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ObjectIndex); + output.WriteInt30(RegisterIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/HasNextIns.cs b/Flazzy/ABC/AVM2/Instructions/HasNextIns.cs index a09a818..760b1ec 100644 --- a/Flazzy/ABC/AVM2/Instructions/HasNextIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/HasNextIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class HasNextIns : ASInstruction { - public class HasNextIns : ASInstruction - { - public HasNextIns() - : base(OPCode.HasNext) - { } + public HasNextIns() + : base(OPCode.HasNext) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object curIndex = machine.Values.Pop(); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object curIndex = machine.Values.Pop(); + object obj = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/InitPropertyIns.cs b/Flazzy/ABC/AVM2/Instructions/InitPropertyIns.cs index 9833322..992490c 100644 --- a/Flazzy/ABC/AVM2/Instructions/InitPropertyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/InitPropertyIns.cs @@ -1,40 +1,39 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class InitPropertyIns : ASInstruction { - public class InitPropertyIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public InitPropertyIns(ABCFile abc) - : base(OPCode.InitProperty, abc) - { } - public InitPropertyIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public InitPropertyIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public InitPropertyIns(ABCFile abc) + : base(OPCode.InitProperty, abc) + { } + public InitPropertyIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public InitPropertyIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return (1 + ResolveMultinamePops(PropertyName) + 1); - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - } + public override int GetPopCount() + { + return (1 + ResolveMultinamePops(PropertyName) + 1); + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/InstanceOfIns.cs b/Flazzy/ABC/AVM2/Instructions/InstanceOfIns.cs index b923081..d1c89b8 100644 --- a/Flazzy/ABC/AVM2/Instructions/InstanceOfIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/InstanceOfIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class InstanceOfIns : ASInstruction { - public class InstanceOfIns : ASInstruction - { - public InstanceOfIns() - : base(OPCode.InstanceOf) - { } + public InstanceOfIns() + : base(OPCode.InstanceOf) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object type = machine.Values.Pop(); - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object type = machine.Values.Pop(); + object value = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/LabelIns.cs b/Flazzy/ABC/AVM2/Instructions/LabelIns.cs index 4d9f235..417d892 100644 --- a/Flazzy/ABC/AVM2/Instructions/LabelIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/LabelIns.cs @@ -1,9 +1,8 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class LabelIns : ASInstruction { - public class LabelIns : ASInstruction - { - public LabelIns() - : base(OPCode.Label) - { } - } + public LabelIns() + : base(OPCode.Label) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/LookUpSwitchIns.cs b/Flazzy/ABC/AVM2/Instructions/LookUpSwitchIns.cs index 4c021fb..ab2021b 100644 --- a/Flazzy/ABC/AVM2/Instructions/LookUpSwitchIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/LookUpSwitchIns.cs @@ -1,54 +1,53 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class LookUpSwitchIns : ASInstruction { - public class LookUpSwitchIns : ASInstruction - { - public List CaseOffsets { get; } - public uint DefaultOffset { get; set; } + public List CaseOffsets { get; } + public uint DefaultOffset { get; set; } - public LookUpSwitchIns() - : base(OPCode.LookUpSwitch) - { - CaseOffsets = new List(); - } - public LookUpSwitchIns(FlashReader input) - : this() + public LookUpSwitchIns() + : base(OPCode.LookUpSwitch) + { + CaseOffsets = new List(); + } + public LookUpSwitchIns(FlashReader input) + : this() + { + DefaultOffset = input.ReadUInt24(); + CaseOffsets.Capacity = (input.ReadInt30() + 1); + for (int i = 0; i < CaseOffsets.Capacity; i++) { - DefaultOffset = input.ReadUInt24(); - CaseOffsets.Capacity = (input.ReadInt30() + 1); - for (int i = 0; i < CaseOffsets.Capacity; i++) - { - CaseOffsets.Add(input.ReadUInt24()); - } + CaseOffsets.Add(input.ReadUInt24()); } - public LookUpSwitchIns(uint defaultOffset, params uint[] caseOffsets) - : this() - { - DefaultOffset = defaultOffset; + } + public LookUpSwitchIns(uint defaultOffset, params uint[] caseOffsets) + : this() + { + DefaultOffset = defaultOffset; - CaseOffsets.AddRange(caseOffsets); - CaseOffsets.Add(DefaultOffset); - } + CaseOffsets.AddRange(caseOffsets); + CaseOffsets.Add(DefaultOffset); + } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Pop(); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteUInt24(DefaultOffset); + output.WriteInt30(CaseOffsets.Count - 1); + for (int i = 0; i < CaseOffsets.Count; i++) { - output.WriteUInt24(DefaultOffset); - output.WriteInt30(CaseOffsets.Count - 1); - for (int i = 0; i < CaseOffsets.Count; i++) - { - uint offset = CaseOffsets[i]; - output.WriteUInt24(offset); - } + uint offset = CaseOffsets[i]; + output.WriteUInt24(offset); } } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NewActivationIns.cs b/Flazzy/ABC/AVM2/Instructions/NewActivationIns.cs index a9710db..3fe856a 100644 --- a/Flazzy/ABC/AVM2/Instructions/NewActivationIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NewActivationIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NewActivationIns : ASInstruction { - public class NewActivationIns : ASInstruction - { - public NewActivationIns() - : base(OPCode.NewActivation) - { } + public NewActivationIns() + : base(OPCode.NewActivation) + { } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NewArrayIns.cs b/Flazzy/ABC/AVM2/Instructions/NewArrayIns.cs index b38e673..11ef92c 100644 --- a/Flazzy/ABC/AVM2/Instructions/NewArrayIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NewArrayIns.cs @@ -1,46 +1,45 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NewArrayIns : ASInstruction { - public class NewArrayIns : ASInstruction - { - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public NewArrayIns() - : base(OPCode.NewArray) - { } - public NewArrayIns(int argCount) - : this() - { - ArgCount = argCount; - } - public NewArrayIns(FlashReader input) - : this() - { - ArgCount = input.ReadInt30(); - } + public NewArrayIns() + : base(OPCode.NewArray) + { } + public NewArrayIns(int argCount) + : this() + { + ArgCount = argCount; + } + public NewArrayIns(FlashReader input) + : this() + { + ArgCount = input.ReadInt30(); + } - public override int GetPopCount() - { - return ArgCount; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return ArgCount; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + var newarray = new object[ArgCount]; + for (int i = ArgCount - 1; i >= 0; i--) { - var newarray = new object[ArgCount]; - for (int i = ArgCount - 1; i >= 0; i--) - { - newarray[i] = machine.Values.Pop(); - } - machine.Values.Push(newarray); + newarray[i] = machine.Values.Pop(); } + machine.Values.Push(newarray); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NewCatchIns.cs b/Flazzy/ABC/AVM2/Instructions/NewCatchIns.cs index bbbef41..ef78203 100644 --- a/Flazzy/ABC/AVM2/Instructions/NewCatchIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NewCatchIns.cs @@ -1,37 +1,36 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NewCatchIns : ASInstruction { - public class NewCatchIns : ASInstruction - { - public int ExceptionIndex { get; set; } + public int ExceptionIndex { get; set; } - public NewCatchIns() - : base(OPCode.NewCatch) - { } - public NewCatchIns(FlashReader input) - : this() - { - ExceptionIndex = input.ReadInt30(); - } - public NewCatchIns(int exceptionIndex) - : this() - { - ExceptionIndex = exceptionIndex; - } + public NewCatchIns() + : base(OPCode.NewCatch) + { } + public NewCatchIns(FlashReader input) + : this() + { + ExceptionIndex = input.ReadInt30(); + } + public NewCatchIns(int exceptionIndex) + : this() + { + ExceptionIndex = exceptionIndex; + } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ExceptionIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ExceptionIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NewClassIns.cs b/Flazzy/ABC/AVM2/Instructions/NewClassIns.cs index a2f22a9..e6860f1 100644 --- a/Flazzy/ABC/AVM2/Instructions/NewClassIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NewClassIns.cs @@ -1,43 +1,42 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NewClassIns : ASInstruction { - public class NewClassIns : ASInstruction - { - public int ClassIndex { get; set; } - public ASClass Class => ABC.Classes[ClassIndex]; + public int ClassIndex { get; set; } + public ASClass Class => ABC.Classes[ClassIndex]; - public NewClassIns(ABCFile abc) - : base(OPCode.NewClass, abc) - { } - public NewClassIns(ABCFile abc, int classIndex) - : this(abc) - { - ClassIndex = classIndex; - } - public NewClassIns(ABCFile abc, FlashReader input) - : this(abc) - { - ClassIndex = input.ReadInt30(); - } + public NewClassIns(ABCFile abc) + : base(OPCode.NewClass, abc) + { } + public NewClassIns(ABCFile abc, int classIndex) + : this(abc) + { + ClassIndex = classIndex; + } + public NewClassIns(ABCFile abc, FlashReader input) + : this(abc) + { + ClassIndex = input.ReadInt30(); + } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object baseType = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object baseType = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ClassIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ClassIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NewFunctionIns.cs b/Flazzy/ABC/AVM2/Instructions/NewFunctionIns.cs index 9ff6b18..70f3d74 100644 --- a/Flazzy/ABC/AVM2/Instructions/NewFunctionIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NewFunctionIns.cs @@ -1,38 +1,37 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NewFunctionIns : ASInstruction { - public class NewFunctionIns : ASInstruction - { - public int MethodIndex { get; set; } - public ASMethod Method => ABC.Methods[MethodIndex]; + public int MethodIndex { get; set; } + public ASMethod Method => ABC.Methods[MethodIndex]; - public NewFunctionIns(ABCFile abc) - : base(OPCode.NewFunction, abc) - { } - public NewFunctionIns(ABCFile abc, int methodIndex) - : this(abc) - { - MethodIndex = methodIndex; - } - public NewFunctionIns(ABCFile abc, FlashReader input) - : this(abc) - { - MethodIndex = input.ReadInt30(); - } + public NewFunctionIns(ABCFile abc) + : base(OPCode.NewFunction, abc) + { } + public NewFunctionIns(ABCFile abc, int methodIndex) + : this(abc) + { + MethodIndex = methodIndex; + } + public NewFunctionIns(ABCFile abc, FlashReader input) + : this(abc) + { + MethodIndex = input.ReadInt30(); + } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(MethodIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(MethodIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NewObjectIns.cs b/Flazzy/ABC/AVM2/Instructions/NewObjectIns.cs index 991fe18..781f8c5 100644 --- a/Flazzy/ABC/AVM2/Instructions/NewObjectIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NewObjectIns.cs @@ -1,46 +1,45 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NewObjectIns : ASInstruction { - public class NewObjectIns : ASInstruction - { - public int ArgCount { get; set; } + public int ArgCount { get; set; } - public NewObjectIns() - : base(OPCode.NewObject) - { } - public NewObjectIns(int argCount) - : this() - { - ArgCount = argCount; - } - public NewObjectIns(FlashReader input) - : this() - { - ArgCount = input.ReadInt30(); - } + public NewObjectIns() + : base(OPCode.NewObject) + { } + public NewObjectIns(int argCount) + : this() + { + ArgCount = argCount; + } + public NewObjectIns(FlashReader input) + : this() + { + ArgCount = input.ReadInt30(); + } - public override int GetPopCount() - { - return (ArgCount * 2); - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return (ArgCount * 2); + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + for (int i = 0; i < ArgCount; i++) { - for (int i = 0; i < ArgCount; i++) - { - object value = machine.Values.Pop(); - object name = machine.Values.Pop(); - } - machine.Values.Push(null); + object value = machine.Values.Pop(); + object name = machine.Values.Pop(); } + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ArgCount); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ArgCount); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NextNameIns.cs b/Flazzy/ABC/AVM2/Instructions/NextNameIns.cs index 2e9eeb1..f66e878 100644 --- a/Flazzy/ABC/AVM2/Instructions/NextNameIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NextNameIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NextNameIns : ASInstruction { - public class NextNameIns : ASInstruction - { - public NextNameIns() - : base(OPCode.NextName) - { } + public NextNameIns() + : base(OPCode.NextName) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object index = machine.Values.Pop(); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object index = machine.Values.Pop(); + object obj = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NextValueIns.cs b/Flazzy/ABC/AVM2/Instructions/NextValueIns.cs index dbb11c9..a300fc0 100644 --- a/Flazzy/ABC/AVM2/Instructions/NextValueIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NextValueIns.cs @@ -1,24 +1,23 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NextValueIns : ASInstruction { - public class NextValueIns : ASInstruction - { - public NextValueIns() - : base(OPCode.NextValue) - { } + public NextValueIns() + : base(OPCode.NextValue) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object index = machine.Values.Pop(); - object obj = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object index = machine.Values.Pop(); + object obj = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NopIns.cs b/Flazzy/ABC/AVM2/Instructions/NopIns.cs index 30fef11..52139ba 100644 --- a/Flazzy/ABC/AVM2/Instructions/NopIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NopIns.cs @@ -1,9 +1,8 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NopIns : ASInstruction { - public class NopIns : ASInstruction - { - public NopIns() - : base(OPCode.Nop) - { } - } + public NopIns() + : base(OPCode.Nop) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/NotIns.cs b/Flazzy/ABC/AVM2/Instructions/NotIns.cs index f9a1125..5ca6dd5 100644 --- a/Flazzy/ABC/AVM2/Instructions/NotIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/NotIns.cs @@ -1,31 +1,30 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class NotIns : ASInstruction { - public class NotIns : ASInstruction - { - public NotIns() - : base(OPCode.Not) - { } + public NotIns() + : base(OPCode.Not) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + if (value != null) { - object value = machine.Values.Pop(); - if (value != null) + if (value is string) { - if (value is string) - { - value = !string.IsNullOrEmpty((string)value); - } - else value = !Convert.ToBoolean(value); + value = !string.IsNullOrEmpty((string)value); } - machine.Values.Push(value); + else value = !Convert.ToBoolean(value); } + machine.Values.Push(value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/PopIns.cs b/Flazzy/ABC/AVM2/Instructions/PopIns.cs index 423d91a..f8e29f1 100644 --- a/Flazzy/ABC/AVM2/Instructions/PopIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/PopIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PopIns : ASInstruction { - public class PopIns : ASInstruction - { - public PopIns() - : base(OPCode.Pop) - { } + public PopIns() + : base(OPCode.Pop) + { } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Pop(); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Pop(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/PopScopeIns.cs b/Flazzy/ABC/AVM2/Instructions/PopScopeIns.cs index c3f6d80..eb921d5 100644 --- a/Flazzy/ABC/AVM2/Instructions/PopScopeIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/PopScopeIns.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PopScopeIns : ASInstruction { - public class PopScopeIns : ASInstruction - { - public PopScopeIns() - : base(OPCode.PopScope) - { } + public PopScopeIns() + : base(OPCode.PopScope) + { } - public override void Execute(ASMachine machine) - { - machine.Scopes.Pop(); - } + public override void Execute(ASMachine machine) + { + machine.Scopes.Pop(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/PushScopeIns.cs b/Flazzy/ABC/AVM2/Instructions/PushScopeIns.cs index dc442d4..5bd7e9c 100644 --- a/Flazzy/ABC/AVM2/Instructions/PushScopeIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/PushScopeIns.cs @@ -1,19 +1,18 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushScopeIns : ASInstruction { - public class PushScopeIns : ASInstruction - { - public PushScopeIns() - : base(OPCode.PushScope) - { } + public PushScopeIns() + : base(OPCode.PushScope) + { } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Scopes.Push(value); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Scopes.Push(value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/PushUndefinedIns.cs b/Flazzy/ABC/AVM2/Instructions/PushUndefinedIns.cs index 170c081..53cc3ed 100644 --- a/Flazzy/ABC/AVM2/Instructions/PushUndefinedIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/PushUndefinedIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushUndefinedIns : ASInstruction { - public class PushUndefinedIns : ASInstruction - { - public PushUndefinedIns() - : base(OPCode.PushUndefined) - { } + public PushUndefinedIns() + : base(OPCode.PushUndefined) + { } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(null); - } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/PushWithIns.cs b/Flazzy/ABC/AVM2/Instructions/PushWithIns.cs index 6f97793..3775759 100644 --- a/Flazzy/ABC/AVM2/Instructions/PushWithIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/PushWithIns.cs @@ -1,19 +1,18 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushWithIns : ASInstruction { - public class PushWithIns : ASInstruction - { - public PushWithIns() - : base(OPCode.PushWith) - { } + public PushWithIns() + : base(OPCode.PushWith) + { } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object scopeObj = machine.Values.Pop(); - machine.Scopes.Push(scopeObj); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object scopeObj = machine.Values.Pop(); + machine.Scopes.Push(scopeObj); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIIns.cs index 92ab1ee..7ab71fc 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIIns.cs @@ -1,24 +1,23 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DecLocalIIns : Local { - public class DecLocalIIns : Local - { - public DecLocalIIns(int register) - : base(OPCode.DecLocal_i, register) - { } - public DecLocalIIns(FlashReader input) - : base(OPCode.DecLocal_i, input) - { } + public DecLocalIIns(int register) + : base(OPCode.DecLocal_i, register) + { } + public DecLocalIIns(FlashReader input) + : base(OPCode.DecLocal_i, input) + { } - public override void Execute(ASMachine machine) + public override void Execute(ASMachine machine) + { + object value = machine.Registers[Register]; + if (value != null) { - object value = machine.Registers[Register]; - if (value != null) - { - value = (Convert.ToInt32(value) - 1); - } - machine.Registers[Register] = value; + value = (Convert.ToInt32(value) - 1); } + machine.Registers[Register] = value; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIns.cs index 348114a..df46529 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/DecLocalIns.cs @@ -1,24 +1,23 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class DecLocalIns : Local { - public class DecLocalIns : Local - { - public DecLocalIns(int register) - : base(OPCode.DecLocal, register) - { } - public DecLocalIns(FlashReader input) - : base(OPCode.DecLocal, input) - { } + public DecLocalIns(int register) + : base(OPCode.DecLocal, register) + { } + public DecLocalIns(FlashReader input) + : base(OPCode.DecLocal, input) + { } - public override void Execute(ASMachine machine) + public override void Execute(ASMachine machine) + { + object value = machine.Registers[Register]; + if (value != null) { - object value = machine.Registers[Register]; - if (value != null) - { - value = (Convert.ToDouble(value) - 1); - } - machine.Registers[Register] = value; + value = (Convert.ToDouble(value) - 1); } + machine.Registers[Register] = value; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal0Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal0Ins.cs index 71421d2..fdc29d9 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal0Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal0Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetLocal0Ins : Local { - public class GetLocal0Ins : Local + public override int Register { - public override int Register - { - get => 0; - set => throw new NotSupportedException(); - } - - public GetLocal0Ins() - : base(OPCode.GetLocal_0) - { } + get => 0; + set => throw new NotSupportedException(); } + + public GetLocal0Ins() + : base(OPCode.GetLocal_0) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal1Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal1Ins.cs index 9416667..bc5f801 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal1Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal1Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetLocal1Ins : Local { - public class GetLocal1Ins : Local + public override int Register { - public override int Register - { - get => 1; - set => throw new NotSupportedException(); - } - - public GetLocal1Ins() - : base(OPCode.GetLocal_1) - { } + get => 1; + set => throw new NotSupportedException(); } + + public GetLocal1Ins() + : base(OPCode.GetLocal_1) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal2Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal2Ins.cs index 76542ff..da6a3be 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal2Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal2Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetLocal2Ins : Local { - public class GetLocal2Ins : Local + public override int Register { - public override int Register - { - get => 2; - set => throw new NotSupportedException(); - } - - public GetLocal2Ins() - : base(OPCode.GetLocal_2) - { } + get => 2; + set => throw new NotSupportedException(); } + + public GetLocal2Ins() + : base(OPCode.GetLocal_2) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal3Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal3Ins.cs index 5a910ca..bf939cf 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal3Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocal3Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetLocal3Ins : Local { - public class GetLocal3Ins : Local + public override int Register { - public override int Register - { - get => 3; - set => throw new NotSupportedException(); - } - - public GetLocal3Ins() - : base(OPCode.GetLocal_3) - { } + get => 3; + set => throw new NotSupportedException(); } + + public GetLocal3Ins() + : base(OPCode.GetLocal_3) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocalIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocalIns.cs index 8780cc5..13d11b9 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocalIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/GetLocalIns.cs @@ -1,14 +1,13 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class GetLocalIns : Local { - public class GetLocalIns : Local - { - public GetLocalIns(int register) - : base(OPCode.GetLocal, register) - { } - public GetLocalIns(FlashReader input) - : base(OPCode.GetLocal, input) - { } - } + public GetLocalIns(int register) + : base(OPCode.GetLocal, register) + { } + public GetLocalIns(FlashReader input) + : base(OPCode.GetLocal, input) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIIns.cs index 0301224..2cd8607 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIIns.cs @@ -1,24 +1,23 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IncLocalIIns : Local { - public class IncLocalIIns : Local - { - public IncLocalIIns(int register) - : base(OPCode.IncLocal_i, register) - { } - public IncLocalIIns(FlashReader input) - : base(OPCode.IncLocal_i, input) - { } + public IncLocalIIns(int register) + : base(OPCode.IncLocal_i, register) + { } + public IncLocalIIns(FlashReader input) + : base(OPCode.IncLocal_i, input) + { } - public override void Execute(ASMachine machine) + public override void Execute(ASMachine machine) + { + object value = machine.Registers[Register]; + if (value != null) { - object value = machine.Registers[Register]; - if (value != null) - { - value = (Convert.ToInt32(value) + 1); - } - machine.Registers[Register] = value; + value = (Convert.ToInt32(value) + 1); } + machine.Registers[Register] = value; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIns.cs index 1ba3e65..41bb9db 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/IncLocalIns.cs @@ -1,24 +1,23 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class IncLocalIns : Local { - public class IncLocalIns : Local - { - public IncLocalIns(int register) - : base(OPCode.IncLocal, register) - { } - public IncLocalIns(FlashReader input) - : base(OPCode.IncLocal, input) - { } + public IncLocalIns(int register) + : base(OPCode.IncLocal, register) + { } + public IncLocalIns(FlashReader input) + : base(OPCode.IncLocal, input) + { } - public override void Execute(ASMachine machine) + public override void Execute(ASMachine machine) + { + object value = machine.Registers[Register]; + if (value != null) { - object value = machine.Registers[Register]; - if (value != null) - { - value = (Convert.ToDouble(value) + 1); - } - machine.Registers[Register] = value; + value = (Convert.ToDouble(value) + 1); } + machine.Registers[Register] = value; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/KillIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/KillIns.cs index 9f10ca2..c02369c 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/KillIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/KillIns.cs @@ -1,19 +1,18 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class KillIns : Local { - public class KillIns : Local - { - public KillIns(int register) - : base(OPCode.Kill, register) - { } - public KillIns(FlashReader input) - : base(OPCode.Kill, input) - { } + public KillIns(int register) + : base(OPCode.Kill, register) + { } + public KillIns(FlashReader input) + : base(OPCode.Kill, input) + { } - public override void Execute(ASMachine machine) - { - machine.Registers[Register] = null; - } + public override void Execute(ASMachine machine) + { + machine.Registers[Register] = null; } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/Local.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/Local.cs index e330023..596a668 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/Local.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/Local.cs @@ -1,146 +1,145 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public abstract class Local : ASInstruction { - public abstract class Local : ASInstruction + public virtual int Register { get; set; } + + public Local(OPCode op) + : base(op) + { } + public Local(OPCode op, int register) + : this(op) { - public virtual int Register { get; set; } + Register = register; + } + public Local(OPCode op, FlashReader input) + : this(op) + { + Register = input.ReadInt30(); + } - public Local(OPCode op) - : base(op) - { } - public Local(OPCode op, int register) - : this(op) + public override int GetPopCount() + { + return (IsSetLocal(OP) ? 1 : 0); + } + public override int GetPushCount() + { + return (IsGetLocal(OP) ? 1 : 0); + } + public override void Execute(ASMachine machine) + { + if (IsSetLocal(OP)) { - Register = register; + machine.Registers[Register] = machine.Values.Pop(); } - public Local(OPCode op, FlashReader input) - : this(op) + else if (IsGetLocal(OP)) { - Register = input.ReadInt30(); + object value = machine.Registers[Register]; + machine.Values.Push(value); } + } - public override int GetPopCount() - { - return (IsSetLocal(OP) ? 1 : 0); - } - public override int GetPushCount() - { - return (IsGetLocal(OP) ? 1 : 0); - } - public override void Execute(ASMachine machine) + protected override void WriteValuesTo(FlashWriter output) + { + switch (OP) { - if (IsSetLocal(OP)) - { - machine.Registers[Register] = machine.Values.Pop(); - } - else if (IsGetLocal(OP)) - { - object value = machine.Registers[Register]; - machine.Values.Push(value); - } - } + case OPCode.SetLocal_0: + case OPCode.SetLocal_1: + case OPCode.SetLocal_2: + case OPCode.SetLocal_3: - protected override void WriteValuesTo(FlashWriter output) - { - switch (OP) - { - case OPCode.SetLocal_0: - case OPCode.SetLocal_1: - case OPCode.SetLocal_2: - case OPCode.SetLocal_3: - - case OPCode.GetLocal_0: - case OPCode.GetLocal_1: - case OPCode.GetLocal_2: - case OPCode.GetLocal_3: return; - - default: + case OPCode.GetLocal_0: + case OPCode.GetLocal_1: + case OPCode.GetLocal_2: + case OPCode.GetLocal_3: return; + + default: output.WriteInt30(Register); break; - } } + } - public static bool IsValid(OPCode op) + public static bool IsValid(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.Kill: - - case OPCode.DecLocal: - case OPCode.DecLocal_i: - - case OPCode.IncLocal: - case OPCode.IncLocal_i: - - case OPCode.GetLocal: - case OPCode.GetLocal_0: - case OPCode.GetLocal_1: - case OPCode.GetLocal_2: - case OPCode.GetLocal_3: - - case OPCode.SetLocal: - case OPCode.SetLocal_0: - case OPCode.SetLocal_1: - case OPCode.SetLocal_2: - case OPCode.SetLocal_3: + case OPCode.Kill: + + case OPCode.DecLocal: + case OPCode.DecLocal_i: + + case OPCode.IncLocal: + case OPCode.IncLocal_i: + + case OPCode.GetLocal: + case OPCode.GetLocal_0: + case OPCode.GetLocal_1: + case OPCode.GetLocal_2: + case OPCode.GetLocal_3: + + case OPCode.SetLocal: + case OPCode.SetLocal_0: + case OPCode.SetLocal_1: + case OPCode.SetLocal_2: + case OPCode.SetLocal_3: return true; - default: return false; - } + default: return false; } - public static bool IsGetLocal(OPCode op) + } + public static bool IsGetLocal(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.GetLocal: - case OPCode.GetLocal_0: - case OPCode.GetLocal_1: - case OPCode.GetLocal_2: - case OPCode.GetLocal_3: + case OPCode.GetLocal: + case OPCode.GetLocal_0: + case OPCode.GetLocal_1: + case OPCode.GetLocal_2: + case OPCode.GetLocal_3: return true; - default: return false; - } + default: return false; } - public static bool IsSetLocal(OPCode op) + } + public static bool IsSetLocal(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.SetLocal: - case OPCode.SetLocal_0: - case OPCode.SetLocal_1: - case OPCode.SetLocal_2: - case OPCode.SetLocal_3: + case OPCode.SetLocal: + case OPCode.SetLocal_0: + case OPCode.SetLocal_1: + case OPCode.SetLocal_2: + case OPCode.SetLocal_3: return true; - default: return false; - } + default: return false; } + } - public static Local CreateSet(int register) + public static Local CreateSet(int register) + { + switch (register) { - switch (register) - { - case 0: return new SetLocal0Ins(); - case 1: return new SetLocal1Ins(); - case 2: return new SetLocal2Ins(); - case 3: return new SetLocal3Ins(); - - default: return new SetLocalIns(register); - } + case 0: return new SetLocal0Ins(); + case 1: return new SetLocal1Ins(); + case 2: return new SetLocal2Ins(); + case 3: return new SetLocal3Ins(); + + default: return new SetLocalIns(register); } - public static Local CreateGet(int register) + } + public static Local CreateGet(int register) + { + switch (register) { - switch (register) - { - case 0: return new GetLocal0Ins(); - case 1: return new GetLocal1Ins(); - case 2: return new GetLocal2Ins(); - case 3: return new GetLocal3Ins(); - - default: return new GetLocalIns(register); - } + case 0: return new GetLocal0Ins(); + case 1: return new GetLocal1Ins(); + case 2: return new GetLocal2Ins(); + case 3: return new GetLocal3Ins(); + + default: return new GetLocalIns(register); } } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal0Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal0Ins.cs index 5e5b806..4f76469 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal0Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal0Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetLocal0Ins : Local { - public class SetLocal0Ins : Local + public override int Register { - public override int Register - { - get => 0; - set => throw new NotSupportedException(); - } - - public SetLocal0Ins() - : base(OPCode.SetLocal_0) - { } + get => 0; + set => throw new NotSupportedException(); } + + public SetLocal0Ins() + : base(OPCode.SetLocal_0) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal1Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal1Ins.cs index 149673f..6950203 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal1Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal1Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetLocal1Ins : Local { - public class SetLocal1Ins : Local + public override int Register { - public override int Register - { - get => 1; - set => throw new NotSupportedException(); - } - - public SetLocal1Ins() - : base(OPCode.SetLocal_1) - { } + get => 1; + set => throw new NotSupportedException(); } + + public SetLocal1Ins() + : base(OPCode.SetLocal_1) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal2Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal2Ins.cs index 1b8c39b..e4bf9ad 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal2Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal2Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetLocal2Ins : Local { - public class SetLocal2Ins : Local + public override int Register { - public override int Register - { - get => 2; - set => throw new NotSupportedException(); - } - - public SetLocal2Ins() - : base(OPCode.SetLocal_2) - { } + get => 2; + set => throw new NotSupportedException(); } + + public SetLocal2Ins() + : base(OPCode.SetLocal_2) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal3Ins.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal3Ins.cs index fcc6f3f..e7df691 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal3Ins.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocal3Ins.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetLocal3Ins : Local { - public class SetLocal3Ins : Local + public override int Register { - public override int Register - { - get => 3; - set => throw new NotSupportedException(); - } - - public SetLocal3Ins() - : base(OPCode.SetLocal_3) - { } + get => 3; + set => throw new NotSupportedException(); } + + public SetLocal3Ins() + : base(OPCode.SetLocal_3) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocalIns.cs b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocalIns.cs index 5d19c0b..0361691 100644 --- a/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocalIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Register Management/SetLocalIns.cs @@ -1,14 +1,13 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetLocalIns : Local { - public class SetLocalIns : Local - { - public SetLocalIns(int register) - : base(OPCode.SetLocal, register) - { } - public SetLocalIns(FlashReader input) - : base(OPCode.SetLocal, input) - { } - } + public SetLocalIns(int register) + : base(OPCode.SetLocal, register) + { } + public SetLocalIns(FlashReader input) + : base(OPCode.SetLocal, input) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ReturnValueIns.cs b/Flazzy/ABC/AVM2/Instructions/ReturnValueIns.cs index 77669a6..b291a50 100644 --- a/Flazzy/ABC/AVM2/Instructions/ReturnValueIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ReturnValueIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ReturnValueIns : ASInstruction { - public class ReturnValueIns : ASInstruction - { - public ReturnValueIns() - : base(OPCode.ReturnValue) - { } + public ReturnValueIns() + : base(OPCode.ReturnValue) + { } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Pop(); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Pop(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ReturnVoidIns.cs b/Flazzy/ABC/AVM2/Instructions/ReturnVoidIns.cs index daf1dec..048e88a 100644 --- a/Flazzy/ABC/AVM2/Instructions/ReturnVoidIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ReturnVoidIns.cs @@ -1,9 +1,8 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ReturnVoidIns : ASInstruction { - public class ReturnVoidIns : ASInstruction - { - public ReturnVoidIns() - : base(OPCode.ReturnVoid) - { } - } + public ReturnVoidIns() + : base(OPCode.ReturnVoid) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/SetPropertyIns.cs b/Flazzy/ABC/AVM2/Instructions/SetPropertyIns.cs index 9d83a14..18cfcb2 100644 --- a/Flazzy/ABC/AVM2/Instructions/SetPropertyIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/SetPropertyIns.cs @@ -1,40 +1,39 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetPropertyIns : ASInstruction { - public class SetPropertyIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public SetPropertyIns(ABCFile abc) - : base(OPCode.SetProperty, abc) - { } - public SetPropertyIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public SetPropertyIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public SetPropertyIns(ABCFile abc) + : base(OPCode.SetProperty, abc) + { } + public SetPropertyIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public SetPropertyIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return (2 + ResolveMultinamePops(PropertyName)); - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - } + public override int GetPopCount() + { + return (2 + ResolveMultinamePops(PropertyName)); + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/SetSlotIns.cs b/Flazzy/ABC/AVM2/Instructions/SetSlotIns.cs index 6cf6d75..2373f75 100644 --- a/Flazzy/ABC/AVM2/Instructions/SetSlotIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/SetSlotIns.cs @@ -1,38 +1,37 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetSlotIns : ASInstruction { - public class SetSlotIns : ASInstruction - { - public int SlotIndex { get; set; } + public int SlotIndex { get; set; } - public SetSlotIns() - : base(OPCode.SetSlot) - { } - public SetSlotIns(int slotIndex) - : this() - { - SlotIndex = slotIndex; - } - public SetSlotIns(FlashReader input) - : this() - { - SlotIndex = input.ReadInt30(); - } + public SetSlotIns() + : base(OPCode.SetSlot) + { } + public SetSlotIns(int slotIndex) + : this() + { + SlotIndex = slotIndex; + } + public SetSlotIns(FlashReader input) + : this() + { + SlotIndex = input.ReadInt30(); + } - public override int GetPopCount() - { - return 2; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - object obj = machine.Values.Pop(); - } + public override int GetPopCount() + { + return 2; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + object obj = machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(SlotIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(SlotIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/SetSuperIns.cs b/Flazzy/ABC/AVM2/Instructions/SetSuperIns.cs index daa574c..f73e7f3 100644 --- a/Flazzy/ABC/AVM2/Instructions/SetSuperIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/SetSuperIns.cs @@ -1,40 +1,39 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SetSuperIns : ASInstruction { - public class SetSuperIns : ASInstruction - { - public int PropertyNameIndex { get; set; } - public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; + public int PropertyNameIndex { get; set; } + public ASMultiname PropertyName => ABC.Pool.Multinames[PropertyNameIndex]; - public SetSuperIns(ABCFile abc) - : base(OPCode.SetSuper, abc) - { } - public SetSuperIns(ABCFile abc, FlashReader input) - : this(abc) - { - PropertyNameIndex = input.ReadInt30(); - } - public SetSuperIns(ABCFile abc, int propertyNameIndex) - : this(abc) - { - PropertyNameIndex = propertyNameIndex; - } + public SetSuperIns(ABCFile abc) + : base(OPCode.SetSuper, abc) + { } + public SetSuperIns(ABCFile abc, FlashReader input) + : this(abc) + { + PropertyNameIndex = input.ReadInt30(); + } + public SetSuperIns(ABCFile abc, int propertyNameIndex) + : this(abc) + { + PropertyNameIndex = propertyNameIndex; + } - public override int GetPopCount() - { - return (2 + ResolveMultinamePops(PropertyName)); - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - ResolveMultiname(machine, PropertyName); - object obj = machine.Values.Pop(); - } + public override int GetPopCount() + { + return (2 + ResolveMultinamePops(PropertyName)); + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + ResolveMultiname(machine, PropertyName); + object obj = machine.Values.Pop(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(PropertyNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(PropertyNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/Primitive.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/Primitive.cs index 24633a0..700a2cf 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/Primitive.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/Primitive.cs @@ -1,71 +1,71 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public abstract class Primitive : ASInstruction { - public abstract class Primitive : ASInstruction - { - public virtual object Value { get; set; } + public virtual object Value { get; set; } - public Primitive(OPCode op) - : base(op) - { } - public Primitive(OPCode op, ABCFile abc) - : base(op, abc) - { } + public Primitive(OPCode op) + : base(op) + { } + public Primitive(OPCode op, ABCFile abc) + : base(op, abc) + { } - public override int GetPopCount() - { - return 0; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - machine.Values.Push(Value); - } + public override int GetPopCount() + { + return 0; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + machine.Values.Push(Value); + } - public static bool IsValid(OPCode op) + public static bool IsValid(OPCode op) + { + switch (op) { - switch (op) - { - case OPCode.PushByte: - case OPCode.PushDouble: - case OPCode.PushFalse: - case OPCode.PushInt: - case OPCode.PushNan: - case OPCode.PushNull: - case OPCode.PushShort: - case OPCode.PushString: - case OPCode.PushTrue: - case OPCode.PushUInt: + case OPCode.PushByte: + case OPCode.PushDouble: + case OPCode.PushFalse: + case OPCode.PushInt: + case OPCode.PushNan: + case OPCode.PushNull: + case OPCode.PushShort: + case OPCode.PushString: + case OPCode.PushTrue: + case OPCode.PushUInt: return true; - default: + default: return false; - } } - public static Primitive Create(ABCFile abc, object value) + } + public static Primitive Create(ABCFile abc, object value) + { + var typeCode = Type.GetTypeCode(value.GetType()); + switch (typeCode) { - var typeCode = Type.GetTypeCode(value.GetType()); - switch (typeCode) - { - case TypeCode.Byte: - case TypeCode.Int32: + case TypeCode.Byte: + case TypeCode.Int32: return new PushIntIns(abc, (int)value); - case TypeCode.Int16: + case TypeCode.Int16: return new PushShortIns((int)value); - case TypeCode.UInt32: + case TypeCode.UInt32: return new PushUIntIns(abc, (uint)value); - case TypeCode.Double: + case TypeCode.Double: return new PushDoubleIns(abc, (double)value); - case TypeCode.String: + case TypeCode.String: return new PushStringIns(abc, (string)value); - case TypeCode.Boolean: + case TypeCode.Boolean: { var result = (bool)value; if (result) @@ -75,12 +75,11 @@ public static Primitive Create(ABCFile abc, object value) else return new PushFalseIns(); } - case TypeCode.Empty: + case TypeCode.Empty: return new PushNullIns(); - default: + default: return new PushNaNIns(); - } } } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushByteIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushByteIns.cs index 8faf4e9..303f253 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushByteIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushByteIns.cs @@ -1,37 +1,36 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushByteIns : Primitive { - public class PushByteIns : Primitive + private byte _value; + new public byte Value { - private byte _value; - new public byte Value + get => _value; + set { - get => _value; - set - { - _value = value; - base.Value = value; - } + _value = value; + base.Value = value; } + } - public PushByteIns() - : base(OPCode.PushByte) - { } - public PushByteIns(byte value) - : this() - { - Value = value; - } - public PushByteIns(FlashReader input) - : this() - { - Value = input.ReadByte(); - } + public PushByteIns() + : base(OPCode.PushByte) + { } + public PushByteIns(byte value) + : this() + { + Value = value; + } + public PushByteIns(FlashReader input) + : this() + { + Value = input.ReadByte(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.Write(Value); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.Write(Value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushDoubleIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushDoubleIns.cs index fbddda8..7cd0ded 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushDoubleIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushDoubleIns.cs @@ -1,52 +1,51 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushDoubleIns : Primitive { - public class PushDoubleIns : Primitive + private double _value; + new public double Value { - private double _value; - new public double Value + get => _value; + set { - get => _value; - set - { - _value = value; - _valueIndex = ABC.Pool.AddConstant(value); + _value = value; + _valueIndex = ABC.Pool.AddConstant(value); - base.Value = value; - } + base.Value = value; } + } - private int _valueIndex; - public int ValueIndex + private int _valueIndex; + public int ValueIndex + { + get => _valueIndex; + set { - get => _valueIndex; - set - { - _valueIndex = value; - _value = ABC.Pool.Doubles[value]; + _valueIndex = value; + _value = ABC.Pool.Doubles[value]; - base.Value = _value; - } + base.Value = _value; } + } - public PushDoubleIns(ABCFile abc) - : base(OPCode.PushDouble, abc) - { } - public PushDoubleIns(ABCFile abc, double value) - : this(abc) - { - Value = value; - } - public PushDoubleIns(ABCFile abc, FlashReader input) - : this(abc) - { - ValueIndex = input.ReadInt30(); - } + public PushDoubleIns(ABCFile abc) + : base(OPCode.PushDouble, abc) + { } + public PushDoubleIns(ABCFile abc, double value) + : this(abc) + { + Value = value; + } + public PushDoubleIns(ABCFile abc, FlashReader input) + : this(abc) + { + ValueIndex = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ValueIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ValueIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushFalseIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushFalseIns.cs index 47cc2bc..5517797 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushFalseIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushFalseIns.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushFalseIns : Primitive { - public class PushFalseIns : Primitive + public override object Value { - public override object Value - { - get => false; - set => throw new NotSupportedException(); - } - - public PushFalseIns() - : base(OPCode.PushFalse) - { } + get => false; + set => throw new NotSupportedException(); } -} + + public PushFalseIns() + : base(OPCode.PushFalse) + { } +} \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushIntIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushIntIns.cs index 60d9918..36a09c6 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushIntIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushIntIns.cs @@ -1,52 +1,51 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushIntIns : Primitive { - public class PushIntIns : Primitive + private int _value; + new public int Value { - private int _value; - new public int Value + get => _value; + set { - get => _value; - set - { - _value = value; - _valueIndex = ABC.Pool.AddConstant(value); + _value = value; + _valueIndex = ABC.Pool.AddConstant(value); - base.Value = value; - } + base.Value = value; } + } - private int _valueIndex; - public int ValueIndex + private int _valueIndex; + public int ValueIndex + { + get => _valueIndex; + set { - get => _valueIndex; - set - { - _valueIndex = value; - _value = ABC.Pool.Integers[value]; + _valueIndex = value; + _value = ABC.Pool.Integers[value]; - base.Value = _value; - } + base.Value = _value; } + } - public PushIntIns(ABCFile abc) - : base(OPCode.PushInt, abc) - { } - public PushIntIns(ABCFile abc, int value) - : this(abc) - { - Value = value; - } - public PushIntIns(ABCFile abc, FlashReader input) - : this(abc) - { - ValueIndex = input.ReadInt30(); - } + public PushIntIns(ABCFile abc) + : base(OPCode.PushInt, abc) + { } + public PushIntIns(ABCFile abc, int value) + : this(abc) + { + Value = value; + } + public PushIntIns(ABCFile abc, FlashReader input) + : this(abc) + { + ValueIndex = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ValueIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ValueIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNaNIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNaNIns.cs index bea89e7..3ad7894 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNaNIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNaNIns.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushNaNIns : Primitive { - public class PushNaNIns : Primitive + public override object Value { - public override object Value - { - get => double.NaN; - set => throw new NotSupportedException(); - } - - public PushNaNIns() - : base(OPCode.PushNan) - { } + get => double.NaN; + set => throw new NotSupportedException(); } + + public PushNaNIns() + : base(OPCode.PushNan) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNullIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNullIns.cs index fff35f5..5c27d31 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNullIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushNullIns.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushNullIns : Primitive { - public class PushNullIns : Primitive + public override object Value { - public override object Value - { - get => null; - set => throw new NotSupportedException(); - } - - public PushNullIns() - : base(OPCode.PushNull) - { } + get => null; + set => throw new NotSupportedException(); } + + public PushNullIns() + : base(OPCode.PushNull) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushShortIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushShortIns.cs index 0e37e09..05aa8ff 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushShortIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushShortIns.cs @@ -1,37 +1,36 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushShortIns : Primitive { - public class PushShortIns : Primitive + private int _value; + new public int Value { - private int _value; - new public int Value + get => _value; + set { - get => _value; - set - { - _value = value; - base.Value = value; - } + _value = value; + base.Value = value; } + } - public PushShortIns() - : base(OPCode.PushShort) - { } - public PushShortIns(int value) - : this() - { - Value = value; - } - public PushShortIns(FlashReader input) - : this() - { - Value = input.ReadInt30(); - } + public PushShortIns() + : base(OPCode.PushShort) + { } + public PushShortIns(int value) + : this() + { + Value = value; + } + public PushShortIns(FlashReader input) + : this() + { + Value = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(Value); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(Value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushStringIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushStringIns.cs index e2d3544..a29ed20 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushStringIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushStringIns.cs @@ -1,57 +1,56 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushStringIns : Primitive { - public class PushStringIns : Primitive + private string _value; + new public string Value { - private string _value; - new public string Value + get => _value; + set { - get => _value; - set - { - _value = value; - _valueIndex = ABC.Pool.AddConstant(value); + _value = value; + _valueIndex = ABC.Pool.AddConstant(value); - base.Value = value; - } + base.Value = value; } + } - private int _valueIndex; - public int ValueIndex + private int _valueIndex; + public int ValueIndex + { + get => _valueIndex; + set { - get => _valueIndex; - set - { - _valueIndex = value; - _value = ABC.Pool.Strings[value]; + _valueIndex = value; + _value = ABC.Pool.Strings[value]; - base.Value = _value; - } + base.Value = _value; } + } - public PushStringIns(ABCFile abc) - : base(OPCode.PushString, abc) - { } - public PushStringIns(ABCFile abc, string value) - : this(abc) - { - Value = value; - } - public PushStringIns(ABCFile abc, int valueIndex) - : this(abc) - { - ValueIndex = valueIndex; - } - public PushStringIns(ABCFile abc, FlashReader input) - : this(abc) - { - ValueIndex = input.ReadInt30(); - } + public PushStringIns(ABCFile abc) + : base(OPCode.PushString, abc) + { } + public PushStringIns(ABCFile abc, string value) + : this(abc) + { + Value = value; + } + public PushStringIns(ABCFile abc, int valueIndex) + : this(abc) + { + ValueIndex = valueIndex; + } + public PushStringIns(ABCFile abc, FlashReader input) + : this(abc) + { + ValueIndex = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ValueIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ValueIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushTrueIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushTrueIns.cs index 7f1e488..44cb622 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushTrueIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushTrueIns.cs @@ -1,15 +1,14 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushTrueIns : Primitive { - public class PushTrueIns : Primitive + public override object Value { - public override object Value - { - get => true; - set => throw new NotSupportedException(); - } - - public PushTrueIns() - : base(OPCode.PushTrue) - { } + get => true; + set => throw new NotSupportedException(); } + + public PushTrueIns() + : base(OPCode.PushTrue) + { } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushUIntIns.cs b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushUIntIns.cs index 434b1f6..0be01a6 100644 --- a/Flazzy/ABC/AVM2/Instructions/Stack Management/PushUIntIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Stack Management/PushUIntIns.cs @@ -1,52 +1,51 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class PushUIntIns : Primitive { - public class PushUIntIns : Primitive + private uint _value; + new public uint Value { - private uint _value; - new public uint Value + get => _value; + set { - get => _value; - set - { - _value = value; - _valueIndex = ABC.Pool.AddConstant(value); + _value = value; + _valueIndex = ABC.Pool.AddConstant(value); - base.Value = value; - } + base.Value = value; } + } - private int _valueIndex; - public int ValueIndex + private int _valueIndex; + public int ValueIndex + { + get => _valueIndex; + set { - get => _valueIndex; - set - { - _valueIndex = value; - _value = ABC.Pool.UIntegers[value]; + _valueIndex = value; + _value = ABC.Pool.UIntegers[value]; - base.Value = _value; - } + base.Value = _value; } + } - public PushUIntIns(ABCFile abc) - : base(OPCode.PushUInt, abc) - { } - public PushUIntIns(ABCFile abc, uint value) - : this(abc) - { - Value = value; - } - public PushUIntIns(ABCFile abc, FlashReader input) - : this(abc) - { - ValueIndex = input.ReadInt30(); - } + public PushUIntIns(ABCFile abc) + : base(OPCode.PushUInt, abc) + { } + public PushUIntIns(ABCFile abc, uint value) + : this(abc) + { + Value = value; + } + public PushUIntIns(ABCFile abc, FlashReader input) + : this(abc) + { + ValueIndex = input.ReadInt30(); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(ValueIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(ValueIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/SwapIns.cs b/Flazzy/ABC/AVM2/Instructions/SwapIns.cs index d7e318a..544d2d8 100644 --- a/Flazzy/ABC/AVM2/Instructions/SwapIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/SwapIns.cs @@ -1,26 +1,25 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class SwapIns : ASInstruction { - public class SwapIns : ASInstruction - { - public SwapIns() - : base(OPCode.Swap) - { } + public SwapIns() + : base(OPCode.Swap) + { } - public override int GetPopCount() - { - return 2; - } - public override int GetPushCount() - { - return 2; - } - public override void Execute(ASMachine machine) - { - object value2 = machine.Values.Pop(); - object value1 = machine.Values.Pop(); + public override int GetPopCount() + { + return 2; + } + public override int GetPushCount() + { + return 2; + } + public override void Execute(ASMachine machine) + { + object value2 = machine.Values.Pop(); + object value1 = machine.Values.Pop(); - machine.Values.Push(value2); - machine.Values.Push(value1); - } + machine.Values.Push(value2); + machine.Values.Push(value1); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/ThrowIns.cs b/Flazzy/ABC/AVM2/Instructions/ThrowIns.cs index 78d2e71..428908b 100644 --- a/Flazzy/ABC/AVM2/Instructions/ThrowIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/ThrowIns.cs @@ -1,18 +1,17 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ThrowIns : ASInstruction { - public class ThrowIns : ASInstruction - { - public ThrowIns() - : base(OPCode.Throw) - { } + public ThrowIns() + : base(OPCode.Throw) + { } - public override int GetPopCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - } + public override int GetPopCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceAIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceAIns.cs index 0ec181f..7ed6b30 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceAIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceAIns.cs @@ -1,23 +1,22 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CoerceAIns : ASInstruction { - public class CoerceAIns : ASInstruction - { - public CoerceAIns() - : base(OPCode.Coerce_a) - { } + public CoerceAIns() + : base(OPCode.Coerce_a) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(value); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceIns.cs index aae7c77..3fbabc1 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceIns.cs @@ -1,43 +1,42 @@ using Flazzy.IO; -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CoerceIns : ASInstruction { - public class CoerceIns : ASInstruction - { - public int TypeNameIndex { get; set; } - public ASMultiname TypeName => ABC.Pool.Multinames[TypeNameIndex]; + public int TypeNameIndex { get; set; } + public ASMultiname TypeName => ABC.Pool.Multinames[TypeNameIndex]; - public CoerceIns(ABCFile abc) - : base(OPCode.Coerce, abc) - { } - public CoerceIns(ABCFile abc, int typeNameIndex) - : this(abc) - { - TypeNameIndex = typeNameIndex; - } - public CoerceIns(ABCFile abc, FlashReader input) - : this(abc) - { - TypeNameIndex = input.ReadInt30(); - } + public CoerceIns(ABCFile abc) + : base(OPCode.Coerce, abc) + { } + public CoerceIns(ABCFile abc, int typeNameIndex) + : this(abc) + { + TypeNameIndex = typeNameIndex; + } + public CoerceIns(ABCFile abc, FlashReader input) + : this(abc) + { + TypeNameIndex = input.ReadInt30(); + } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(null); + } - protected override void WriteValuesTo(FlashWriter output) - { - output.WriteInt30(TypeNameIndex); - } + protected override void WriteValuesTo(FlashWriter output) + { + output.WriteInt30(TypeNameIndex); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceSIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceSIns.cs index 9b8378a..c9fa4c6 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceSIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/CoerceSIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class CoerceSIns : ASInstruction { - public class CoerceSIns : ASInstruction - { - public CoerceSIns() - : base(OPCode.Coerce_s) - { } + public CoerceSIns() + : base(OPCode.Coerce_s) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + string result = null; + object value = machine.Values.Pop(); + if (value != null) { - string result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = Convert.ToString(value); - } - machine.Values.Push(result); + result = Convert.ToString(value); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertBIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertBIns.cs index d234443..0d45b56 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertBIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertBIns.cs @@ -1,32 +1,31 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConvertBIns : ASInstruction { - public class ConvertBIns : ASInstruction - { - public ConvertBIns() - : base(OPCode.Convert_b) - { } + public ConvertBIns() + : base(OPCode.Convert_b) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) + if (value is string) { - if (value is string) - { - result = string.IsNullOrEmpty((string)value); - } - else result = Convert.ToBoolean(value); + result = string.IsNullOrEmpty((string)value); } - machine.Values.Push(result); + else result = Convert.ToBoolean(value); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertDIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertDIns.cs index 656c9f0..a6a561a 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertDIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertDIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConvertDIns : ASInstruction { - public class ConvertDIns : ASInstruction - { - public ConvertDIns() - : base(OPCode.Convert_d) - { } + public ConvertDIns() + : base(OPCode.Convert_d) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = Convert.ToDouble(value); - } - machine.Values.Push(result); + result = Convert.ToDouble(value); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertIIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertIIns.cs index 9406a26..47a308a 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertIIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertIIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConvertIIns : ASInstruction { - public class ConvertIIns : ASInstruction - { - public ConvertIIns() - : base(OPCode.Convert_i) - { } + public ConvertIIns() + : base(OPCode.Convert_i) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = Convert.ToInt32(value); - } - machine.Values.Push(result); + result = Convert.ToInt32(value); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertOIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertOIns.cs index 2e2cb99..c6e47c1 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertOIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertOIns.cs @@ -1,23 +1,22 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConvertOIns : ASInstruction { - public class ConvertOIns : ASInstruction - { - public ConvertOIns() - : base(OPCode.Convert_o) - { } + public ConvertOIns() + : base(OPCode.Convert_o) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(value); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(value); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertSIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertSIns.cs index e27b971..227a5d0 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertSIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertSIns.cs @@ -1,29 +1,28 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConvertSIns : ASInstruction { - public class ConvertSIns : ASInstruction - { - public ConvertSIns() - : base(OPCode.Convert_s) - { } + public ConvertSIns() + : base(OPCode.Convert_s) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + object value = machine.Values.Pop(); + if (value != null) { - object result = null; - object value = machine.Values.Pop(); - if (value != null) - { - result = Convert.ToString(value); - } - else result = "null"; - machine.Values.Push(result); + result = Convert.ToString(value); } + else result = "null"; + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertUIns.cs b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertUIns.cs index 9790db0..64d0456 100644 --- a/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertUIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/Type Conversion/ConvertUIns.cs @@ -1,28 +1,27 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class ConvertUIns : ASInstruction { - public class ConvertUIns : ASInstruction - { - public ConvertUIns() - : base(OPCode.Convert_u) - { } + public ConvertUIns() + : base(OPCode.Convert_u) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object result = null; + dynamic value = machine.Values.Pop(); + if (value != null) { - object result = null; - dynamic value = machine.Values.Pop(); - if (value != null) - { - result = (uint)Convert.ToDouble(value); - } - machine.Values.Push(result); + result = (uint)Convert.ToDouble(value); } + machine.Values.Push(result); } } \ No newline at end of file diff --git a/Flazzy/ABC/AVM2/Instructions/TypeOfIns.cs b/Flazzy/ABC/AVM2/Instructions/TypeOfIns.cs index caedcdb..abea401 100644 --- a/Flazzy/ABC/AVM2/Instructions/TypeOfIns.cs +++ b/Flazzy/ABC/AVM2/Instructions/TypeOfIns.cs @@ -1,23 +1,22 @@ -namespace Flazzy.ABC.AVM2.Instructions +namespace Flazzy.ABC.AVM2.Instructions; + +public class TypeOfIns : ASInstruction { - public class TypeOfIns : ASInstruction - { - public TypeOfIns() - : base(OPCode.TypeOf) - { } + public TypeOfIns() + : base(OPCode.TypeOf) + { } - public override int GetPopCount() - { - return 1; - } - public override int GetPushCount() - { - return 1; - } - public override void Execute(ASMachine machine) - { - object value = machine.Values.Pop(); - machine.Values.Push(null); - } + public override int GetPopCount() + { + return 1; + } + public override int GetPushCount() + { + return 1; + } + public override void Execute(ASMachine machine) + { + object value = machine.Values.Pop(); + machine.Values.Push(null); } } \ No newline at end of file diff --git a/Flazzy/ABC/Enums/ClassFlags.cs b/Flazzy/ABC/Enums/ClassFlags.cs index 38d1a3f..5ce3752 100644 --- a/Flazzy/ABC/Enums/ClassFlags.cs +++ b/Flazzy/ABC/Enums/ClassFlags.cs @@ -1,27 +1,26 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +[Flags] +public enum ClassFlags { - [Flags] - public enum ClassFlags - { - /// - /// Represents no flags for this class. - /// - None = 0x00, - /// - /// Represents a sealed class where properties can't be dynamically added to instances of the class. - /// - Sealed = 0x01, - /// - /// Represents a class that can't be used as a base class for any other class. - /// - Final = 0x02, - /// - /// Represents a class that is of interface type - /// - Interface = 0x04, - /// - /// Represents a class that uses its' protected namespace meaning the property is present. - /// - ProtectedNamespace = 0x08 - } + /// + /// Represents no flags for this class. + /// + None = 0x00, + /// + /// Represents a sealed class where properties can't be dynamically added to instances of the class. + /// + Sealed = 0x01, + /// + /// Represents a class that can't be used as a base class for any other class. + /// + Final = 0x02, + /// + /// Represents a class that is of interface type + /// + Interface = 0x04, + /// + /// Represents a class that uses its' protected namespace meaning the property is present. + /// + ProtectedNamespace = 0x08 } \ No newline at end of file diff --git a/Flazzy/ABC/Enums/ConstantKind.cs b/Flazzy/ABC/Enums/ConstantKind.cs index e41d80e..92b8967 100644 --- a/Flazzy/ABC/Enums/ConstantKind.cs +++ b/Flazzy/ABC/Enums/ConstantKind.cs @@ -1,19 +1,18 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public enum ConstantKind { - public enum ConstantKind - { - Null = 0x0C, - Undefined = 0x00, + Null = 0x0C, + Undefined = 0x00, - String = 0x01, - Double = 0x06, - Integer = 0x03, - UInteger = 0x04, + String = 0x01, + Double = 0x06, + Integer = 0x03, + UInteger = 0x04, - True = 0x0B, - False = 0x0A, + True = 0x0B, + False = 0x0A, - Namespace = 0x08, - Multiname = 0x09 - } + Namespace = 0x08, + Multiname = 0x09 } \ No newline at end of file diff --git a/Flazzy/ABC/Enums/MethodFlags.cs b/Flazzy/ABC/Enums/MethodFlags.cs index 39077fb..f048769 100644 --- a/Flazzy/ABC/Enums/MethodFlags.cs +++ b/Flazzy/ABC/Enums/MethodFlags.cs @@ -1,16 +1,15 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +[Flags] +public enum MethodFlags { - [Flags] - public enum MethodFlags - { - None = 0, - NeedArguments = 1, - NeedActivation = 2, - NeedRest = 4, - HasOptional = 8, - IgnoreRest = 16, - Explicit = 32, - SetDxns = 64, - HasParamNames = 128 - } + None = 0, + NeedArguments = 1, + NeedActivation = 2, + NeedRest = 4, + HasOptional = 8, + IgnoreRest = 16, + Explicit = 32, + SetDxns = 64, + HasParamNames = 128 } \ No newline at end of file diff --git a/Flazzy/ABC/Enums/MultinameKind.cs b/Flazzy/ABC/Enums/MultinameKind.cs index a80f5d7..e473f48 100644 --- a/Flazzy/ABC/Enums/MultinameKind.cs +++ b/Flazzy/ABC/Enums/MultinameKind.cs @@ -1,20 +1,19 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public enum MultinameKind { - public enum MultinameKind - { - QName = 0x07, - QNameA = 0x0D, + QName = 0x07, + QNameA = 0x0D, - RTQName = 0x0F, - RTQNameA = 0x10, - RTQNameL = 0x11, - RTQNameLA = 0X12, + RTQName = 0x0F, + RTQNameA = 0x10, + RTQNameL = 0x11, + RTQNameLA = 0X12, - Multiname = 0x09, - MultinameA = 0x0E, - MultinameL = 0x1B, - MultinameLA = 0x1C, + Multiname = 0x09, + MultinameA = 0x0E, + MultinameL = 0x1B, + MultinameLA = 0x1C, - TypeName = 0x1D - } + TypeName = 0x1D } \ No newline at end of file diff --git a/Flazzy/ABC/Enums/NamespaceKind.cs b/Flazzy/ABC/Enums/NamespaceKind.cs index 0c532a2..8de2d71 100644 --- a/Flazzy/ABC/Enums/NamespaceKind.cs +++ b/Flazzy/ABC/Enums/NamespaceKind.cs @@ -1,13 +1,12 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public enum NamespaceKind { - public enum NamespaceKind - { - Namespace = 0x08, - Package = 0x16, - PackageInternal = 0x17, - Protected = 0x18, - Explicit = 0x19, - StaticProtected = 0x1A, - Private = 0x05 - } + Namespace = 0x08, + Package = 0x16, + PackageInternal = 0x17, + Protected = 0x18, + Explicit = 0x19, + StaticProtected = 0x1A, + Private = 0x05 } \ No newline at end of file diff --git a/Flazzy/ABC/Enums/TraitAttributes.cs b/Flazzy/ABC/Enums/TraitAttributes.cs index 9976140..3a8d735 100644 --- a/Flazzy/ABC/Enums/TraitAttributes.cs +++ b/Flazzy/ABC/Enums/TraitAttributes.cs @@ -1,11 +1,10 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +[Flags] +public enum TraitAttributes { - [Flags] - public enum TraitAttributes - { - None = 0x00, - Final = 0x01, - Override = 0x02, - Metadata = 0x04 - } -} + None = 0x00, + Final = 0x01, + Override = 0x02, + Metadata = 0x04 +} \ No newline at end of file diff --git a/Flazzy/ABC/Enums/TraitKind.cs b/Flazzy/ABC/Enums/TraitKind.cs index 203c955..42d3d70 100644 --- a/Flazzy/ABC/Enums/TraitKind.cs +++ b/Flazzy/ABC/Enums/TraitKind.cs @@ -1,13 +1,12 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public enum TraitKind { - public enum TraitKind - { - Slot = 0, - Method = 1, - Getter = 2, - Setter = 3, - Class = 4, - Function = 5, - Constant = 6 - } + Slot = 0, + Method = 1, + Getter = 2, + Setter = 3, + Class = 4, + Function = 5, + Constant = 6 } \ No newline at end of file diff --git a/Flazzy/ABC/IPoolConstant.cs b/Flazzy/ABC/IPoolConstant.cs index b638f3c..2f02fe1 100644 --- a/Flazzy/ABC/IPoolConstant.cs +++ b/Flazzy/ABC/IPoolConstant.cs @@ -1,7 +1,6 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IPoolConstant { - public interface IPoolConstant - { - public ASConstantPool Pool { get; init; } - } + public ASConstantPool Pool { get; init; } } \ No newline at end of file diff --git a/Flazzy/ABC/Multinames/IMultiname.cs b/Flazzy/ABC/Multinames/IMultiname.cs index 7b90e49..dfa0e24 100644 --- a/Flazzy/ABC/Multinames/IMultiname.cs +++ b/Flazzy/ABC/Multinames/IMultiname.cs @@ -1,11 +1,10 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IMultiname { - public interface IMultiname - { - string Name { get; } - int NameIndex { get; set; } + string Name { get; } + int NameIndex { get; set; } - ASNamespaceSet NamespaceSet { get; } - int NamespaceSetIndex { get; set; } - } + ASNamespaceSet NamespaceSet { get; } + int NamespaceSetIndex { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Multinames/IMultinameL.cs b/Flazzy/ABC/Multinames/IMultinameL.cs index c20b6c9..75edcfb 100644 --- a/Flazzy/ABC/Multinames/IMultinameL.cs +++ b/Flazzy/ABC/Multinames/IMultinameL.cs @@ -1,8 +1,7 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IMultinameL { - public interface IMultinameL - { - ASNamespaceSet NamespaceSet { get; } - int NamespaceSetIndex { get; set; } - } + ASNamespaceSet NamespaceSet { get; } + int NamespaceSetIndex { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Multinames/IQName.cs b/Flazzy/ABC/Multinames/IQName.cs index 4f7e715..79e0341 100644 --- a/Flazzy/ABC/Multinames/IQName.cs +++ b/Flazzy/ABC/Multinames/IQName.cs @@ -1,11 +1,10 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IQName { - public interface IQName - { - string Name { get; } - int NameIndex { get; set; } + string Name { get; } + int NameIndex { get; set; } - ASNamespace Namespace { get; } - int NamespaceIndex { get; set; } - } + ASNamespace Namespace { get; } + int NamespaceIndex { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Multinames/IRTQName.cs b/Flazzy/ABC/Multinames/IRTQName.cs index d8a054b..0fbcd42 100644 --- a/Flazzy/ABC/Multinames/IRTQName.cs +++ b/Flazzy/ABC/Multinames/IRTQName.cs @@ -1,8 +1,7 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IRTQName { - public interface IRTQName - { - string Name { get; } - int NameIndex { get; set; } - } + string Name { get; } + int NameIndex { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Traits/IClassTrait.cs b/Flazzy/ABC/Traits/IClassTrait.cs index f9a64be..2dd8d8e 100644 --- a/Flazzy/ABC/Traits/IClassTrait.cs +++ b/Flazzy/ABC/Traits/IClassTrait.cs @@ -1,8 +1,7 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IClassTrait { - public interface IClassTrait - { - ASClass Class { get; } - int ClassIndex { get; set; } - } + ASClass Class { get; } + int ClassIndex { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Traits/IFunctionTrait.cs b/Flazzy/ABC/Traits/IFunctionTrait.cs index 0c1ea5f..a265b76 100644 --- a/Flazzy/ABC/Traits/IFunctionTrait.cs +++ b/Flazzy/ABC/Traits/IFunctionTrait.cs @@ -1,8 +1,7 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IFunctionTrait { - public interface IFunctionTrait - { - ASMethod Function { get; } - int FunctionIndex { get; set; } - } + ASMethod Function { get; } + int FunctionIndex { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Traits/IMethodGSTrait.cs b/Flazzy/ABC/Traits/IMethodGSTrait.cs index 31269b1..53ce0c5 100644 --- a/Flazzy/ABC/Traits/IMethodGSTrait.cs +++ b/Flazzy/ABC/Traits/IMethodGSTrait.cs @@ -1,10 +1,9 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface IMethodGSTrait { - public interface IMethodGSTrait - { - ASMethod Method { get; } - int MethodIndex { get; set; } + ASMethod Method { get; } + int MethodIndex { get; set; } - int Id { get; set; } - } + int Id { get; set; } } \ No newline at end of file diff --git a/Flazzy/ABC/Traits/ISlotConstantTrait.cs b/Flazzy/ABC/Traits/ISlotConstantTrait.cs index 284aa2c..7c0c53d 100644 --- a/Flazzy/ABC/Traits/ISlotConstantTrait.cs +++ b/Flazzy/ABC/Traits/ISlotConstantTrait.cs @@ -1,14 +1,13 @@ -namespace Flazzy.ABC +namespace Flazzy.ABC; + +public interface ISlotConstantTrait { - public interface ISlotConstantTrait - { - ASMultiname Type { get; } - int TypeIndex { get; set; } + ASMultiname Type { get; } + int TypeIndex { get; set; } - object Value { get; } - int ValueIndex { get; set; } - ConstantKind ValueKind { get; set; } + object Value { get; } + int ValueIndex { get; set; } + ConstantKind ValueKind { get; set; } - int Id { get; set; } - } + int Id { get; set; } } \ No newline at end of file diff --git a/Flazzy/CompressionKind.cs b/Flazzy/CompressionKind.cs index bf4151d..f5be638 100644 --- a/Flazzy/CompressionKind.cs +++ b/Flazzy/CompressionKind.cs @@ -1,18 +1,17 @@ -namespace Flazzy +namespace Flazzy; + +public enum CompressionKind { - public enum CompressionKind - { - /// - /// Represents no compression. - /// - None = 0x46, - /// - /// Represents ZLib compression. (SWF +6) - /// - ZLib = 0x43, - /// - /// Represents LZMA compression. (SWF +13) - /// - LZMA = 0x5A - } + /// + /// Represents no compression. + /// + None = 0x46, + /// + /// Represents ZLib compression. (SWF +6) + /// + ZLib = 0x43, + /// + /// Represents LZMA compression. (SWF +13) + /// + LZMA = 0x5A } \ No newline at end of file diff --git a/Flazzy/FlashItem.cs b/Flazzy/FlashItem.cs index 72b9c7c..3984511 100644 --- a/Flazzy/FlashItem.cs +++ b/Flazzy/FlashItem.cs @@ -2,23 +2,22 @@ using Flazzy.IO; -namespace Flazzy +namespace Flazzy; + +[DebuggerDisplay("{DebuggerDisplay,nq}")] +public abstract class FlashItem { - [DebuggerDisplay("{DebuggerDisplay,nq}")] - public abstract class FlashItem - { - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - protected virtual string DebuggerDisplay => "{" + ToString() + "}"; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + protected virtual string DebuggerDisplay => "{" + ToString() + "}"; - public byte[] ToArray() + public byte[] ToArray() + { + using (var outputMem = new MemoryStream()) + using (var output = new FlashWriter(outputMem)) { - using (var outputMem = new MemoryStream()) - using (var output = new FlashWriter(outputMem)) - { - WriteTo(output); - return outputMem.ToArray(); - } + WriteTo(output); + return outputMem.ToArray(); } - public abstract void WriteTo(FlashWriter output); } + public abstract void WriteTo(FlashWriter output); } \ No newline at end of file diff --git a/Flazzy/IO/Compression/ZLib.cs b/Flazzy/IO/Compression/ZLib.cs index 8677b94..2f8e61f 100644 --- a/Flazzy/IO/Compression/ZLib.cs +++ b/Flazzy/IO/Compression/ZLib.cs @@ -1,16 +1,15 @@ using System.IO.Compression; -namespace Flazzy.IO.Compression +namespace Flazzy.IO.Compression; + +public static class ZLib { - public static class ZLib + public static FlashWriter WrapCompressor(Stream stream, bool leaveOpen) + { + return new FlashWriter(new ZLibStream(stream, CompressionMode.Compress, leaveOpen)); + } + public static FlashReader WrapDecompressor(Stream stream) { - public static FlashWriter WrapCompressor(Stream stream, bool leaveOpen) - { - return new FlashWriter(new ZLibStream(stream, CompressionMode.Compress, leaveOpen)); - } - public static FlashReader WrapDecompressor(Stream stream) - { - return new FlashReader(new ZLibStream(stream, CompressionMode.Decompress)); - } + return new FlashReader(new ZLibStream(stream, CompressionMode.Decompress)); } -} +} \ No newline at end of file diff --git a/Flazzy/IO/FlashReader.cs b/Flazzy/IO/FlashReader.cs index 2960a15..78fcaa2 100644 --- a/Flazzy/IO/FlashReader.cs +++ b/Flazzy/IO/FlashReader.cs @@ -1,245 +1,244 @@ using System.Text; -namespace Flazzy.IO +namespace Flazzy.IO; + +public class FlashReader : BinaryReader { - public class FlashReader : BinaryReader + private readonly bool _leaveOpen; + + public long Position + { + get => BaseStream.Position; + set => BaseStream.Position = value; + } + public long Length => BaseStream.Length; + public bool IsDisposed { get; private set; } + public bool IsDataAvailable => Position < Length; + + protected int BitPosition { get; set; } + protected byte BitContainer { get; set; } + + public FlashReader(byte[] data) + : this(new MemoryStream(data)) + { } + public FlashReader(Stream input) + : this(input, new UTF8Encoding(false, true), false) + { } + public FlashReader(Stream input, bool leaveOpen) + : this(input, new UTF8Encoding(false, true), leaveOpen) + { } + public FlashReader(Stream input, Encoding encoding) + : this(input, encoding, false) + { } + public FlashReader(Stream output, Encoding encoding, bool leaveOpen) + : base(output, encoding) + { + _leaveOpen = leaveOpen; + } + + public uint ReadUInt24() { - private readonly bool _leaveOpen; + var value = (uint)(ReadByte() + + (ReadByte() << 8) + (ReadByte() << 16)); - public long Position + if ((value >> 23) == 1) + value |= 0xff000000; + + return value; + } + + public int ReadInt30() + { + int result = ReadByte(); + if ((result & 0x00000080) == 0) { - get => BaseStream.Position; - set => BaseStream.Position = value; + return result; } - public long Length => BaseStream.Length; - public bool IsDisposed { get; private set; } - public bool IsDataAvailable => Position < Length; - - protected int BitPosition { get; set; } - protected byte BitContainer { get; set; } - - public FlashReader(byte[] data) - : this(new MemoryStream(data)) - { } - public FlashReader(Stream input) - : this(input, new UTF8Encoding(false, true), false) - { } - public FlashReader(Stream input, bool leaveOpen) - : this(input, new UTF8Encoding(false, true), leaveOpen) - { } - public FlashReader(Stream input, Encoding encoding) - : this(input, encoding, false) - { } - public FlashReader(Stream output, Encoding encoding, bool leaveOpen) - : base(output, encoding) + result = (result & 0x0000007f) | (ReadByte()) << 7; + if ((result & 0x00004000) == 0) { - _leaveOpen = leaveOpen; + return result; } - - public uint ReadUInt24() + result = (result & 0x00003fff) | (ReadByte()) << 14; + if ((result & 0x00200000) == 0) { - var value = (uint)(ReadByte() + - (ReadByte() << 8) + (ReadByte() << 16)); - - if ((value >> 23) == 1) - value |= 0xff000000; - - return value; + return result; + } + result = (result & 0x001fffff) | (ReadByte()) << 21; + if ((result & 0x10000000) == 0) + { + return result; } + return (result & 0x0fffffff) | (ReadByte()) << 28; + } + public uint ReadUInt30() + { + return (uint)ReadInt30(); + } - public int ReadInt30() + public int ReadUB(int bitCount) + { + int result = 0; + if (bitCount > 0) { - int result = ReadByte(); - if ((result & 0x00000080) == 0) + if (BitPosition == 0) { - return result; + BitContainer = ReadByte(); } - result = (result & 0x0000007f) | (ReadByte()) << 7; - if ((result & 0x00004000) == 0) + for (int i = 0; i < bitCount; i++) { - return result; - } - result = (result & 0x00003fff) | (ReadByte()) << 14; - if ((result & 0x00200000) == 0) - { - return result; - } - result = (result & 0x001fffff) | (ReadByte()) << 21; - if ((result & 0x10000000) == 0) - { - return result; - } - return (result & 0x0fffffff) | (ReadByte()) << 28; - } - public uint ReadUInt30() - { - return (uint)ReadInt30(); - } + int bit = ((BitContainer >> (7 - BitPosition)) & 1); + result += (bit << ((bitCount - 1) - i)); - public int ReadUB(int bitCount) - { - int result = 0; - if (bitCount > 0) - { - if (BitPosition == 0) + if (++BitPosition == 8) { - BitContainer = ReadByte(); - } - for (int i = 0; i < bitCount; i++) - { - int bit = ((BitContainer >> (7 - BitPosition)) & 1); - result += (bit << ((bitCount - 1) - i)); - - if (++BitPosition == 8) + BitPosition = 0; + if (i != (bitCount - 1)) { - BitPosition = 0; - if (i != (bitCount - 1)) - { - BitContainer = ReadByte(); - } + BitContainer = ReadByte(); } } } - return result; } - public int ReadSB(int bitCount) - { - int result = ReadUB(bitCount); - int shift = (32 - bitCount); + return result; + } + public int ReadSB(int bitCount) + { + int result = ReadUB(bitCount); + int shift = (32 - bitCount); - return ((result << shift) >> shift); - } + return ((result << shift) >> shift); + } - public string ReadNullString() - { - char currentChar = '\0'; - string value = string.Empty; - while ((currentChar = ReadChar()) != '\0') - { - value += currentChar; - } - return value; - } - public string ReadString(int length) + public string ReadNullString() + { + char currentChar = '\0'; + string value = string.Empty; + while ((currentChar = ReadChar()) != '\0') { - char[] characters = ReadChars(length); - return new string(characters); + value += currentChar; } + return value; + } + public string ReadString(int length) + { + char[] characters = ReadChars(length); + return new string(characters); + } - #region Read Overrides - public override int Read() - { - Align(); - return base.Read(); - } - public override int Read(byte[] buffer, int index, int count) - { - Align(); - return base.Read(buffer, index, count); - } - public override int Read(char[] buffer, int index, int count) - { - Align(); - return base.Read(buffer, index, count); - } - public override bool ReadBoolean() - { - Align(); - return base.ReadBoolean(); - } - public override byte ReadByte() - { - Align(); - return base.ReadByte(); - } - public override byte[] ReadBytes(int count) - { - Align(); - return base.ReadBytes(count); - } - public override char ReadChar() - { - Align(); - return base.ReadChar(); - } - public override char[] ReadChars(int count) - { - Align(); - return base.ReadChars(count); - } - public override decimal ReadDecimal() - { - Align(); - return base.ReadDecimal(); - } - public override double ReadDouble() - { - Align(); - return base.ReadDouble(); - } - public override short ReadInt16() - { - Align(); - return base.ReadInt16(); - } - public override int ReadInt32() - { - Align(); - return base.ReadInt32(); - } - public override long ReadInt64() - { - Align(); - return base.ReadInt64(); - } - public override sbyte ReadSByte() - { - Align(); - return base.ReadSByte(); - } - public override float ReadSingle() - { - Align(); - return base.ReadSingle(); - } - public override string ReadString() - { - Align(); - return base.ReadString(); - } - public override ushort ReadUInt16() - { - Align(); - return base.ReadUInt16(); - } - public override uint ReadUInt32() - { - Align(); - return base.ReadUInt32(); - } - public override ulong ReadUInt64() - { - Align(); - return base.ReadUInt64(); - } - #endregion + #region Read Overrides + public override int Read() + { + Align(); + return base.Read(); + } + public override int Read(byte[] buffer, int index, int count) + { + Align(); + return base.Read(buffer, index, count); + } + public override int Read(char[] buffer, int index, int count) + { + Align(); + return base.Read(buffer, index, count); + } + public override bool ReadBoolean() + { + Align(); + return base.ReadBoolean(); + } + public override byte ReadByte() + { + Align(); + return base.ReadByte(); + } + public override byte[] ReadBytes(int count) + { + Align(); + return base.ReadBytes(count); + } + public override char ReadChar() + { + Align(); + return base.ReadChar(); + } + public override char[] ReadChars(int count) + { + Align(); + return base.ReadChars(count); + } + public override decimal ReadDecimal() + { + Align(); + return base.ReadDecimal(); + } + public override double ReadDouble() + { + Align(); + return base.ReadDouble(); + } + public override short ReadInt16() + { + Align(); + return base.ReadInt16(); + } + public override int ReadInt32() + { + Align(); + return base.ReadInt32(); + } + public override long ReadInt64() + { + Align(); + return base.ReadInt64(); + } + public override sbyte ReadSByte() + { + Align(); + return base.ReadSByte(); + } + public override float ReadSingle() + { + Align(); + return base.ReadSingle(); + } + public override string ReadString() + { + Align(); + return base.ReadString(); + } + public override ushort ReadUInt16() + { + Align(); + return base.ReadUInt16(); + } + public override uint ReadUInt32() + { + Align(); + return base.ReadUInt32(); + } + public override ulong ReadUInt64() + { + Align(); + return base.ReadUInt64(); + } + #endregion - public void Align() + public void Align() + { + if (BitPosition > 0) { - if (BitPosition > 0) - { - BitPosition = 0; - BitContainer = 0; - } + BitPosition = 0; + BitContainer = 0; } + } - protected override void Dispose(bool disposing) + protected override void Dispose(bool disposing) + { + base.Dispose(!_leaveOpen); + if (disposing) { - base.Dispose(!_leaveOpen); - if (disposing) - { - IsDisposed = true; - } + IsDisposed = true; } } } \ No newline at end of file diff --git a/Flazzy/IO/FlashWriter.cs b/Flazzy/IO/FlashWriter.cs index ae3b11d..cf570d9 100644 --- a/Flazzy/IO/FlashWriter.cs +++ b/Flazzy/IO/FlashWriter.cs @@ -1,235 +1,234 @@ using System.Text; -namespace Flazzy.IO +namespace Flazzy.IO; + +public class FlashWriter : BinaryWriter { - public class FlashWriter : BinaryWriter - { - private readonly bool _leaveOpen; + private readonly bool _leaveOpen; - public long Position - { - get => BaseStream.Position; - set => BaseStream.Position = value; - } - public long Length => BaseStream.Length; + public long Position + { + get => BaseStream.Position; + set => BaseStream.Position = value; + } + public long Length => BaseStream.Length; - protected int BitPosition { get; set; } - protected int BitContainer { get; set; } + protected int BitPosition { get; set; } + protected int BitContainer { get; set; } - public FlashWriter() - : this(0) - { } - public FlashWriter(byte[] data) - : this(data.Length) - { - Write(data, 0, data.Length); - } - public FlashWriter(int capacity) - : this(new MemoryStream(capacity)) - { } - - public FlashWriter(Stream output) - : this(output, new UTF8Encoding(false, true), false) - { } - public FlashWriter(Stream output, bool leaveOpen) - : this(output, new UTF8Encoding(false, true), leaveOpen) - { } - public FlashWriter(Stream output, Encoding encoding) - : this(output, encoding, false) - { } - public FlashWriter(Stream output, Encoding encoding, bool leaveOpen) - : base(output, encoding) - { - _leaveOpen = leaveOpen; - } + public FlashWriter() + : this(0) + { } + public FlashWriter(byte[] data) + : this(data.Length) + { + Write(data, 0, data.Length); + } + public FlashWriter(int capacity) + : this(new MemoryStream(capacity)) + { } + + public FlashWriter(Stream output) + : this(output, new UTF8Encoding(false, true), false) + { } + public FlashWriter(Stream output, bool leaveOpen) + : this(output, new UTF8Encoding(false, true), leaveOpen) + { } + public FlashWriter(Stream output, Encoding encoding) + : this(output, encoding, false) + { } + public FlashWriter(Stream output, Encoding encoding, bool leaveOpen) + : base(output, encoding) + { + _leaveOpen = leaveOpen; + } - public void WriteItem(FlashItem item) - { - item.WriteTo(this); - } + public void WriteItem(FlashItem item) + { + item.WriteTo(this); + } - public void WriteInt30(int value) - { - Align(); - Write7BitEncodedInt(value); - } - public void WriteUInt24(uint value) - { - Align(); + public void WriteInt30(int value) + { + Align(); + Write7BitEncodedInt(value); + } + public void WriteUInt24(uint value) + { + Align(); - var byteValue = (byte)(value & 0xff); - Write(byteValue); + var byteValue = (byte)(value & 0xff); + Write(byteValue); - value >>= 8; + value >>= 8; - byteValue = (byte)(value & 0xff); - Write(byteValue); + byteValue = (byte)(value & 0xff); + Write(byteValue); - value >>= 8; + value >>= 8; - byteValue = (byte)(value & 0xff); - Write(byteValue); - } - public void WriteUInt30(uint value) - { - Align(); - Write7BitEncodedInt((int)value); - } - public void WriteBits(int maxBits, long value) + byteValue = (byte)(value & 0xff); + Write(byteValue); + } + public void WriteUInt30(uint value) + { + Align(); + Write7BitEncodedInt((int)value); + } + public void WriteBits(int maxBits, long value) + { + for (int i = 0; i < maxBits; i++) { - for (int i = 0; i < maxBits; i++) - { - int bit = (int)((value >> ((maxBits - 1) - i)) & 1); + int bit = (int)((value >> ((maxBits - 1) - i)) & 1); - BitContainer += (bit * (1 << (7 - BitPosition))); - if (++BitPosition == 8) - { - base.Write((byte)BitContainer); + BitContainer += (bit * (1 << (7 - BitPosition))); + if (++BitPosition == 8) + { + base.Write((byte)BitContainer); - BitPosition = 0; - BitContainer = 0; - } + BitPosition = 0; + BitContainer = 0; } } + } - public void WriteNullString(string value) + public void WriteNullString(string value) + { + Write(value.ToCharArray()); + Write('\0'); + } + public void Write(string value, bool excludeLength) + { + if (excludeLength) { Write(value.ToCharArray()); - Write('\0'); } - public void Write(string value, bool excludeLength) + else { - if (excludeLength) - { - Write(value.ToCharArray()); - } - else - { - Write(value); - } + Write(value); } + } - #region Write Overrides - public override void Write(bool value) - { - Align(); - base.Write(value); - } - public override void Write(byte value) - { - Align(); - base.Write(value); - } - public override void Write(byte[] buffer) - { - Align(); - base.Write(buffer); - } - public override void Write(byte[] buffer, int index, int count) - { - Align(); - base.Write(buffer, index, count); - } - public override void Write(char ch) - { - Align(); - base.Write(ch); - } - public override void Write(char[] chars) - { - Align(); - base.Write(chars); - } - public override void Write(char[] chars, int index, int count) - { - Align(); - base.Write(chars, index, count); - } - public override void Write(decimal value) - { - Align(); - base.Write(value); - } - public override void Write(double value) - { - Align(); - base.Write(value); - } - public override void Write(float value) - { - Align(); - base.Write(value); - } - public override void Write(int value) - { - Align(); - base.Write(value); - } - public override void Write(long value) - { - Align(); - base.Write(value); - } - public override void Write(sbyte value) - { - Align(); - base.Write(value); - } - public override void Write(short value) - { - Align(); - base.Write(value); - } - public override void Write(string value) - { - Align(); - base.Write(value); - } - public override void Write(uint value) - { - Align(); - base.Write(value); - } - public override void Write(ulong value) - { - Align(); - base.Write(value); - } - public override void Write(ushort value) - { - Align(); - base.Write(value); - } - #endregion + #region Write Overrides + public override void Write(bool value) + { + Align(); + base.Write(value); + } + public override void Write(byte value) + { + Align(); + base.Write(value); + } + public override void Write(byte[] buffer) + { + Align(); + base.Write(buffer); + } + public override void Write(byte[] buffer, int index, int count) + { + Align(); + base.Write(buffer, index, count); + } + public override void Write(char ch) + { + Align(); + base.Write(ch); + } + public override void Write(char[] chars) + { + Align(); + base.Write(chars); + } + public override void Write(char[] chars, int index, int count) + { + Align(); + base.Write(chars, index, count); + } + public override void Write(decimal value) + { + Align(); + base.Write(value); + } + public override void Write(double value) + { + Align(); + base.Write(value); + } + public override void Write(float value) + { + Align(); + base.Write(value); + } + public override void Write(int value) + { + Align(); + base.Write(value); + } + public override void Write(long value) + { + Align(); + base.Write(value); + } + public override void Write(sbyte value) + { + Align(); + base.Write(value); + } + public override void Write(short value) + { + Align(); + base.Write(value); + } + public override void Write(string value) + { + Align(); + base.Write(value); + } + public override void Write(uint value) + { + Align(); + base.Write(value); + } + public override void Write(ulong value) + { + Align(); + base.Write(value); + } + public override void Write(ushort value) + { + Align(); + base.Write(value); + } + #endregion - protected void Align() + protected void Align() + { + if (BitPosition > 0) { - if (BitPosition > 0) - { - base.Write((byte)BitContainer); + base.Write((byte)BitContainer); - BitPosition = 0; - BitContainer = 0; - } - } - public override void Flush() - { - Align(); - base.Flush(); + BitPosition = 0; + BitContainer = 0; } + } + public override void Flush() + { + Align(); + base.Flush(); + } - protected override void Dispose(bool disposing) + protected override void Dispose(bool disposing) + { + if (disposing) { - if (disposing) + if (_leaveOpen) + { + OutStream.Flush(); + } + else { - if (_leaveOpen) - { - OutStream.Flush(); - } - else - { - OutStream.Dispose(); - } + OutStream.Dispose(); } } } diff --git a/Flazzy/Records/FrameRecord.cs b/Flazzy/Records/FrameRecord.cs index d25c212..413d6f5 100644 --- a/Flazzy/Records/FrameRecord.cs +++ b/Flazzy/Records/FrameRecord.cs @@ -1,29 +1,28 @@ using Flazzy.IO; -namespace Flazzy.Records +namespace Flazzy.Records; + +public class FrameRecord : FlashItem { - public class FrameRecord : FlashItem - { - public ushort Rate { get; set; } - public ushort Count { get; set; } - public RectangleRecord Area { get; set; } + public ushort Rate { get; set; } + public ushort Count { get; set; } + public RectangleRecord Area { get; set; } - public FrameRecord() - { - Area = new RectangleRecord(); - } - public FrameRecord(FlashReader input) - { - Area = new RectangleRecord(input); - Rate = (ushort)(input.ReadUInt16() >> 8); - Count = input.ReadUInt16(); - } + public FrameRecord() + { + Area = new RectangleRecord(); + } + public FrameRecord(FlashReader input) + { + Area = new RectangleRecord(input); + Rate = (ushort)(input.ReadUInt16() >> 8); + Count = input.ReadUInt16(); + } - public override void WriteTo(FlashWriter output) - { - Area.WriteTo(output); - output.Write((ushort)(Rate << 8)); - output.Write(Count); - } + public override void WriteTo(FlashWriter output) + { + Area.WriteTo(output); + output.Write((ushort)(Rate << 8)); + output.Write(Count); } } \ No newline at end of file diff --git a/Flazzy/Records/HeaderRecord.cs b/Flazzy/Records/HeaderRecord.cs index dc45b03..29e4da6 100644 --- a/Flazzy/Records/HeaderRecord.cs +++ b/Flazzy/Records/HeaderRecord.cs @@ -1,29 +1,29 @@ using Flazzy.IO; using Flazzy.Tags; -namespace Flazzy.Records +namespace Flazzy.Records; + +public class HeaderRecord : FlashItem { - public class HeaderRecord : FlashItem - { - private const int MAX_SHORT_LENGTH = 62; + private const int MAX_SHORT_LENGTH = 62; - private bool _isLongTag; - public bool IsLongTag + private readonly bool _isLongTag; + public bool IsLongTag + { + get { - get + switch (Kind) { - switch (Kind) - { - case TagKind.DefineBits: + case TagKind.DefineBits: - case TagKind.DefineBitsJPEG2: - case TagKind.DefineBitsJPEG3: - case TagKind.DefineBitsJPEG4: + case TagKind.DefineBitsJPEG2: + case TagKind.DefineBitsJPEG3: + case TagKind.DefineBitsJPEG4: - case TagKind.DefineBitsLossless: - case TagKind.DefineBitsLossless2: + case TagKind.DefineBitsLossless: + case TagKind.DefineBitsLossless2: - case TagKind.SoundStreamBlock: + case TagKind.SoundStreamBlock: { /* * These tags are required to write their length amount in the long format, @@ -32,45 +32,44 @@ public bool IsLongTag return true; } - default: + default: { return (_isLongTag || (Length > MAX_SHORT_LENGTH)); } - } } } + } - public int Length { get; set; } - public TagKind Kind { get; set; } + public int Length { get; set; } + public TagKind Kind { get; set; } - public HeaderRecord(TagKind kind) + public HeaderRecord(TagKind kind) + { + Kind = kind; + } + public HeaderRecord(FlashReader input) + { + ushort header = header = input.ReadUInt16(); + Kind = (TagKind)(header >> 6); + + Length = (header & 63); + if (Length > MAX_SHORT_LENGTH) { - Kind = kind; + Length = input.ReadInt32(); + _isLongTag = (Length <= MAX_SHORT_LENGTH); } - public HeaderRecord(FlashReader input) - { - ushort header = header = input.ReadUInt16(); - Kind = (TagKind)(header >> 6); + } - Length = (header & 63); - if (Length > MAX_SHORT_LENGTH) - { - Length = input.ReadInt32(); - _isLongTag = (Length <= MAX_SHORT_LENGTH); - } - } + public override void WriteTo(FlashWriter output) + { + var header = ((uint)Kind << 6); + header |= (IsLongTag ? 63 : (uint)Length); - public override void WriteTo(FlashWriter output) + output.Write((ushort)header); + if (IsLongTag) { - var header = ((uint)Kind << 6); - header |= (IsLongTag ? 63 : (uint)Length); - - output.Write((ushort)header); - if (IsLongTag) - { - output.Write(Length); - } + output.Write(Length); } } } \ No newline at end of file diff --git a/Flazzy/ShockwaveFlash.cs b/Flazzy/ShockwaveFlash.cs index 010adb0..98cff23 100644 --- a/Flazzy/ShockwaveFlash.cs +++ b/Flazzy/ShockwaveFlash.cs @@ -1,215 +1,214 @@ using Flazzy.IO; -using Flazzy.Tags; -using Flazzy.Records; using Flazzy.IO.Compression; +using Flazzy.Records; +using Flazzy.Tags; -namespace Flazzy -{ - public class ShockwaveFlash : IDisposable - { - private readonly FlashReader _input; - - public List Tags { get; } - public CompressionKind Compression { get; } - public string Signature => ((char)Compression + "WS"); - - public byte Version { get; set; } - public uint FileLength { get; set; } - public FrameRecord Frame { get; set; } - - public ShockwaveFlash() - : this(true) - { } - public ShockwaveFlash(string path) - : this(File.OpenRead(path)) - { } - public ShockwaveFlash(byte[] data) - : this(new MemoryStream(data)) - { } - public ShockwaveFlash(Stream input) - : this(input, false) - { } - public ShockwaveFlash(Stream input, bool leaveOpen) - : this(new FlashReader(input, leaveOpen)) - { } - - protected ShockwaveFlash(FlashReader input) - : this(false) - { - Compression = (CompressionKind)input.ReadString(3)[0]; - Version = input.ReadByte(); - FileLength = input.ReadUInt32(); +namespace Flazzy; - if (Compression == CompressionKind.LZMA) - { - throw new NotSupportedException("LZMA compression is not supported."); - } +public class ShockwaveFlash : IDisposable +{ + private readonly FlashReader _input; + + public List Tags { get; } + public CompressionKind Compression { get; } + public string Signature => ((char)Compression + "WS"); + + public byte Version { get; set; } + public uint FileLength { get; set; } + public FrameRecord Frame { get; set; } + + public ShockwaveFlash() + : this(true) + { } + public ShockwaveFlash(string path) + : this(File.OpenRead(path)) + { } + public ShockwaveFlash(byte[] data) + : this(new MemoryStream(data)) + { } + public ShockwaveFlash(Stream input) + : this(input, false) + { } + public ShockwaveFlash(Stream input, bool leaveOpen) + : this(new FlashReader(input, leaveOpen)) + { } + + protected ShockwaveFlash(FlashReader input) + : this(false) + { + Compression = (CompressionKind)input.ReadString(3)[0]; + Version = input.ReadByte(); + FileLength = input.ReadUInt32(); - _input = (Compression == CompressionKind.ZLib) ? - ZLib.WrapDecompressor(input.BaseStream) : input; - Frame = new FrameRecord(_input); - } - protected ShockwaveFlash(bool isCreatingTemplate) + if (Compression == CompressionKind.LZMA) { - Tags = new List(); - if (isCreatingTemplate) - { - Frame = new FrameRecord(); - Frame.Area = new RectangleRecord(); - Compression = CompressionKind.ZLib; - } + throw new NotSupportedException("LZMA compression is not supported."); } - public void Disassemble() + _input = (Compression == CompressionKind.ZLib) ? + ZLib.WrapDecompressor(input.BaseStream) : input; + Frame = new FrameRecord(_input); + } + protected ShockwaveFlash(bool isCreatingTemplate) + { + Tags = new List(); + if (isCreatingTemplate) { - Disassemble(null); - } - public virtual void Disassemble(Action callback) - { - if (_input.IsDisposed) - { - throw new ObjectDisposedException(nameof(_input), "Input stream has already been disposed, or disassembly of the file has already occured."); - } - long position = (8 + Frame.Area.GetByteSize() + 4); - while (position != FileLength) - { - var header = new HeaderRecord(_input); - position += (header.IsLongTag ? 6 : 2); - long offset = (header.Length + position); - - TagItem tag = ReadTag(header, _input); - position += tag.GetBodySize(); - - if (position != offset) - { - throw new IOException($"Expected position value '{offset}', instead got '{position}'."); - } - callback?.Invoke(tag); - Tags.Add(tag); - - if (tag.Kind == TagKind.End) break; - } - _input.Dispose(); + Frame = new FrameRecord(); + Frame.Area = new RectangleRecord(); + Compression = CompressionKind.ZLib; } + } - public void Assemble(FlashWriter output) + public void Disassemble() + { + Disassemble(null); + } + public virtual void Disassemble(Action callback) + { + if (_input.IsDisposed) { - Assemble(output, Compression, null); + throw new ObjectDisposedException(nameof(_input), "Input stream has already been disposed, or disassembly of the file has already occured."); } - public void Assemble(FlashWriter output, Action callback) + long position = (8 + Frame.Area.GetByteSize() + 4); + while (position != FileLength) { - Assemble(output, Compression, callback); - } + var header = new HeaderRecord(_input); + position += (header.IsLongTag ? 6 : 2); + long offset = (header.Length + position); - public void Assemble(FlashWriter output, CompressionKind compression) - { - Assemble(output, compression, null); - } - public virtual void Assemble(FlashWriter output, CompressionKind compression, Action callback) - { - output.Write(((char)compression) + "WS", true); - output.Write(Version); - output.Write(uint.MinValue); + TagItem tag = ReadTag(header, _input); + position += tag.GetBodySize(); - if (compression == CompressionKind.LZMA) - { - throw new NotSupportedException("LZMA compression is not supported."); - } - int fileLength = 8; - - FlashWriter compressor = compression == CompressionKind.ZLib ? - ZLib.WrapCompressor(output.BaseStream, true) : null; - - /* Body Start */ - Frame.WriteTo(compressor ?? output); - fileLength += (Frame.Area.GetByteSize() + 4); - for (int i = 0; i < Tags.Count; i++) + if (position != offset) { - TagItem tag = Tags[i]; - callback?.Invoke(tag); - WriteTag(tag, compressor ?? output); - - fileLength += tag.Header.Length; - fileLength += (tag.Header.IsLongTag ? 6 : 2); + throw new IOException($"Expected position value '{offset}', instead got '{position}'."); } - compressor?.Dispose(); - /* Body End */ + callback?.Invoke(tag); + Tags.Add(tag); - output.Position = 4; - output.Write((uint)fileLength); - output.Position = output.Length; + if (tag.Kind == TagKind.End) break; } + _input.Dispose(); + } - public void CopyTo(Stream output) - { - CopyTo(output, Compression, null); - } - public void CopyTo(Stream output, Action callback) - { - CopyTo(output, Compression, callback); - } + public void Assemble(FlashWriter output) + { + Assemble(output, Compression, null); + } + public void Assemble(FlashWriter output, Action callback) + { + Assemble(output, Compression, callback); + } - public void CopyTo(Stream output, CompressionKind compression) - { - CopyTo(output, compression, null); - } - public void CopyTo(Stream output, CompressionKind compression, Action callback) - { - using var fOutput = new FlashWriter(output, true); - Assemble(fOutput, compression, callback); - } + public void Assemble(FlashWriter output, CompressionKind compression) + { + Assemble(output, compression, null); + } + public virtual void Assemble(FlashWriter output, CompressionKind compression, Action callback) + { + output.Write(((char)compression) + "WS", true); + output.Write(Version); + output.Write(uint.MinValue); - public byte[] ToArray() - { - return ToArray(Compression); - } - public byte[] ToArray(CompressionKind compression) + if (compression == CompressionKind.LZMA) { - using var output = new MemoryStream((int)FileLength); - CopyTo(output, compression, null); - return output.ToArray(); + throw new NotSupportedException("LZMA compression is not supported."); } + int fileLength = 8; - protected virtual void WriteTag(TagItem tag, FlashWriter output) - { - tag.WriteTo(output); - } - protected virtual TagItem ReadTag(HeaderRecord header, FlashReader input) - { - return header.Kind switch - { - TagKind.DefineBinaryData => new DefineBinaryDataTag(header, input), - TagKind.DefineBitsJPEG3 => new DefineBitsJPEG3(header, input), - TagKind.DefineBitsLossless or TagKind.DefineBitsLossless2 => new DefineBitsLosslessTag(header, input), - TagKind.DefineFontName => new DefineFontNameTag(header, input), - TagKind.DefineSound => new DefineSoundTag(header, input), - TagKind.DoABC => new DoABCTag(header, input), - TagKind.End => new EndTag(header), - TagKind.ExportAssets => new ExportAssetsTag(header, input), - TagKind.FileAttributes => new FileAttributesTag(header, input), - TagKind.FrameLabel => new FrameLabelTag(header, input), - TagKind.Metadata => new MetadataTag(header, input), - TagKind.ProductInfo => new ProductInfoTag(header, input), - TagKind.ScriptLimits => new ScriptLimitsTag(header, input), - TagKind.SetBackgroundColor => new SetBackgroundColorTag(header, input), - TagKind.ShowFrame => new ShowFrameTag(header), - TagKind.SymbolClass => new SymbolClassTag(header, input), - - _ => new UnknownTag(header, input), - }; - } + FlashWriter compressor = compression == CompressionKind.ZLib ? + ZLib.WrapCompressor(output.BaseStream, true) : null; - public void Dispose() + /* Body Start */ + Frame.WriteTo(compressor ?? output); + fileLength += (Frame.Area.GetByteSize() + 4); + for (int i = 0; i < Tags.Count; i++) { - Dispose(true); + TagItem tag = Tags[i]; + callback?.Invoke(tag); + WriteTag(tag, compressor ?? output); + + fileLength += tag.Header.Length; + fileLength += (tag.Header.IsLongTag ? 6 : 2); } - protected virtual void Dispose(bool disposing) + compressor?.Dispose(); + /* Body End */ + + output.Position = 4; + output.Write((uint)fileLength); + output.Position = output.Length; + } + + public void CopyTo(Stream output) + { + CopyTo(output, Compression, null); + } + public void CopyTo(Stream output, Action callback) + { + CopyTo(output, Compression, callback); + } + + public void CopyTo(Stream output, CompressionKind compression) + { + CopyTo(output, compression, null); + } + public void CopyTo(Stream output, CompressionKind compression, Action callback) + { + using var fOutput = new FlashWriter(output, true); + Assemble(fOutput, compression, callback); + } + + public byte[] ToArray() + { + return ToArray(Compression); + } + public byte[] ToArray(CompressionKind compression) + { + using var output = new MemoryStream((int)FileLength); + CopyTo(output, compression, null); + return output.ToArray(); + } + + protected virtual void WriteTag(TagItem tag, FlashWriter output) + { + tag.WriteTo(output); + } + protected virtual TagItem ReadTag(HeaderRecord header, FlashReader input) + { + return header.Kind switch + { + TagKind.DefineBinaryData => new DefineBinaryDataTag(header, input), + TagKind.DefineBitsJPEG3 => new DefineBitsJPEG3(header, input), + TagKind.DefineBitsLossless or TagKind.DefineBitsLossless2 => new DefineBitsLosslessTag(header, input), + TagKind.DefineFontName => new DefineFontNameTag(header, input), + TagKind.DefineSound => new DefineSoundTag(header, input), + TagKind.DoABC => new DoABCTag(header, input), + TagKind.End => new EndTag(header), + TagKind.ExportAssets => new ExportAssetsTag(header, input), + TagKind.FileAttributes => new FileAttributesTag(header, input), + TagKind.FrameLabel => new FrameLabelTag(header, input), + TagKind.Metadata => new MetadataTag(header, input), + TagKind.ProductInfo => new ProductInfoTag(header, input), + TagKind.ScriptLimits => new ScriptLimitsTag(header, input), + TagKind.SetBackgroundColor => new SetBackgroundColorTag(header, input), + TagKind.ShowFrame => new ShowFrameTag(header), + TagKind.SymbolClass => new SymbolClassTag(header, input), + + _ => new UnknownTag(header, input), + }; + } + + public void Dispose() + { + Dispose(true); + } + protected virtual void Dispose(bool disposing) + { + if (disposing) { - if (disposing) - { - Tags.Clear(); - _input.Dispose(); - } + Tags.Clear(); + _input.Dispose(); } } } \ No newline at end of file diff --git a/Flazzy/Tags/DefineBinaryDataTag.cs b/Flazzy/Tags/DefineBinaryDataTag.cs index 86b2008..6682069 100644 --- a/Flazzy/Tags/DefineBinaryDataTag.cs +++ b/Flazzy/Tags/DefineBinaryDataTag.cs @@ -1,40 +1,39 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class DefineBinaryDataTag : TagItem { - public class DefineBinaryDataTag : TagItem - { - public ushort Id { get; set; } - public byte[] Data { get; set; } + public ushort Id { get; set; } + public byte[] Data { get; set; } - public DefineBinaryDataTag() - : base(TagKind.DefineBinaryData) - { - Data = new byte[0]; - } - public DefineBinaryDataTag(HeaderRecord header, FlashReader input) - : base(header) - { - Id = input.ReadUInt16(); - input.ReadUInt32(); // Reserved | Must equal '0'. - Data = input.ReadBytes(header.Length - 6); - } + public DefineBinaryDataTag() + : base(TagKind.DefineBinaryData) + { + Data = new byte[0]; + } + public DefineBinaryDataTag(HeaderRecord header, FlashReader input) + : base(header) + { + Id = input.ReadUInt16(); + input.ReadUInt32(); // Reserved | Must equal '0'. + Data = input.ReadBytes(header.Length - 6); + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(ushort); - size += sizeof(uint); - size += Data.Length; - return size; - } + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += sizeof(uint); + size += Data.Length; + return size; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(Id); - output.Write(0); // Reserved | Must equal '0'. - output.Write(Data); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(Id); + output.Write(0); // Reserved | Must equal '0'. + output.Write(Data); } } \ No newline at end of file diff --git a/Flazzy/Tags/DefineBitsJPEG3.cs b/Flazzy/Tags/DefineBitsJPEG3.cs index 808c825..4b22201 100644 --- a/Flazzy/Tags/DefineBitsJPEG3.cs +++ b/Flazzy/Tags/DefineBitsJPEG3.cs @@ -3,62 +3,61 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags -{ - public class DefineBitsJPEG3 : ImageTag - { - public ushort Id { get; set; } - public byte[] Data { get; set; } - public byte[] AlphaData { get; set; } +namespace Flazzy.Tags; - public DefineBitsJPEG3() - : base(TagKind.DefineBitsJPEG3) - { } - public DefineBitsJPEG3(HeaderRecord header, FlashReader input) - : base(header) - { - Id = input.ReadUInt16(); +public class DefineBitsJPEG3 : ImageTag +{ + public ushort Id { get; set; } + public byte[] Data { get; set; } + public byte[] AlphaData { get; set; } - int alphaDataOffset = input.ReadInt32(); - Data = input.ReadBytes(alphaDataOffset); + public DefineBitsJPEG3() + : base(TagKind.DefineBitsJPEG3) + { } + public DefineBitsJPEG3(HeaderRecord header, FlashReader input) + : base(header) + { + Id = input.ReadUInt16(); - Format = GetFormat(Data); - if (Format == ImageFormat.JPEG) - { - int partialLength = (2 + 4 + alphaDataOffset); - AlphaData = input.ReadBytes(Header.Length - partialLength); - } - else - { - // Minimum Compressed Empty Data Length - AlphaData = input.ReadBytes(8); - } - } + int alphaDataOffset = input.ReadInt32(); + Data = input.ReadBytes(alphaDataOffset); - public override Color[,] GetARGBMap() + Format = GetFormat(Data); + if (Format == ImageFormat.JPEG) { - throw new NotSupportedException(); + int partialLength = (2 + 4 + alphaDataOffset); + AlphaData = input.ReadBytes(Header.Length - partialLength); } - public override void SetARGBMap(Color[,] map) + else { - throw new NotSupportedException(); + // Minimum Compressed Empty Data Length + AlphaData = input.ReadBytes(8); } + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(ushort); - size += sizeof(uint); - size += Data.Length; - size += AlphaData.Length; - return size; - } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(Id); - output.Write((uint)Data.Length); - output.Write(Data); - output.Write(AlphaData); - } + public override Color[,] GetARGBMap() + { + throw new NotSupportedException(); + } + public override void SetARGBMap(Color[,] map) + { + throw new NotSupportedException(); + } + + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += sizeof(uint); + size += Data.Length; + size += AlphaData.Length; + return size; + } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(Id); + output.Write((uint)Data.Length); + output.Write(Data); + output.Write(AlphaData); } } \ No newline at end of file diff --git a/Flazzy/Tags/DefineBitsLosslessTag.cs b/Flazzy/Tags/DefineBitsLosslessTag.cs index e90f14a..47297da 100644 --- a/Flazzy/Tags/DefineBitsLosslessTag.cs +++ b/Flazzy/Tags/DefineBitsLosslessTag.cs @@ -1,89 +1,88 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class DefineBitsLosslessTag : TagItem { - public class DefineBitsLosslessTag : TagItem - { - public ushort Id { get; set; } + public ushort Id { get; set; } - public ushort Width { get; set; } - public ushort Height { get; set; } - public byte ColorTableSize { get; } - public BitmapFormat Format { get; set; } - public byte[] CompressedData { get; set; } + public ushort Width { get; set; } + public ushort Height { get; set; } + public byte ColorTableSize { get; } + public BitmapFormat Format { get; set; } + public byte[] CompressedData { get; set; } - public int Version => Kind == TagKind.DefineBitsLossless ? 1 : 2; + public int Version => Kind == TagKind.DefineBitsLossless ? 1 : 2; - public DefineBitsLosslessTag(byte version) - : base(version == 1 ? TagKind.DefineBitsLossless : TagKind.DefineBitsLossless2) - { - CompressedData = Array.Empty(); - } - public DefineBitsLosslessTag(HeaderRecord header, FlashReader input) - : base(header) + public DefineBitsLosslessTag(byte version) + : base(version == 1 ? TagKind.DefineBitsLossless : TagKind.DefineBitsLossless2) + { + CompressedData = Array.Empty(); + } + public DefineBitsLosslessTag(HeaderRecord header, FlashReader input) + : base(header) + { + Id = input.ReadUInt16(); + Format = input.ReadByte() switch { - Id = input.ReadUInt16(); - Format = input.ReadByte() switch - { - 3 => BitmapFormat.ColorMap8, - 4 when Version == 1 => BitmapFormat.Rgb15, - 5 => BitmapFormat.Rgb32, + 3 => BitmapFormat.ColorMap8, + 4 when Version == 1 => BitmapFormat.Rgb15, + 5 => BitmapFormat.Rgb32, - _ => throw new InvalidDataException("Invalid bitmap format.") - }; + _ => throw new InvalidDataException("Invalid bitmap format.") + }; - Width = input.ReadUInt16(); - Height = input.ReadUInt16(); + Width = input.ReadUInt16(); + Height = input.ReadUInt16(); - if (Format == BitmapFormat.ColorMap8) - ColorTableSize = input.ReadByte(); + if (Format == BitmapFormat.ColorMap8) + ColorTableSize = input.ReadByte(); - CompressedData = input.ReadBytes(header.Length - GetHeaderSize()); - } + CompressedData = input.ReadBytes(header.Length - GetHeaderSize()); + } - private int GetHeaderSize() + private int GetHeaderSize() + { + int size = 0; + size += sizeof(ushort); + size += sizeof(byte); + size += sizeof(ushort); + size += sizeof(ushort); + if (Format == BitmapFormat.ColorMap8) { - int size = 0; - size += sizeof(ushort); size += sizeof(byte); - size += sizeof(ushort); - size += sizeof(ushort); - if (Format == BitmapFormat.ColorMap8) - { - size += sizeof(byte); - } - return size; } + return size; + } - public override int GetBodySize() - { - int size = 0; - size += GetHeaderSize(); - size += CompressedData.Length; - return size; - } - protected override void WriteBodyTo(FlashWriter output) + public override int GetBodySize() + { + int size = 0; + size += GetHeaderSize(); + size += CompressedData.Length; + return size; + } + protected override void WriteBodyTo(FlashWriter output) + { + byte format = Format switch { - byte format = Format switch - { - BitmapFormat.ColorMap8 => 3, - BitmapFormat.Rgb15 when Version == 1 => 4, - BitmapFormat.Rgb32 => 5, + BitmapFormat.ColorMap8 => 3, + BitmapFormat.Rgb15 when Version == 1 => 4, + BitmapFormat.Rgb32 => 5, - BitmapFormat.Rgb15 when Version == 2 => throw new Exception($"{BitmapFormat.Rgb15} is only supported on {nameof(DefineBitsLosslessTag)} version 1."), - _ => throw new InvalidDataException("Invalid bitmap format.") - }; + BitmapFormat.Rgb15 when Version == 2 => throw new Exception($"{BitmapFormat.Rgb15} is only supported on {nameof(DefineBitsLosslessTag)} version 1."), + _ => throw new InvalidDataException("Invalid bitmap format.") + }; - output.Write(Id); - output.Write(format); - output.Write(Width); - output.Write(Height); - if (Format == BitmapFormat.ColorMap8) - { - output.Write(ColorTableSize); - } - output.Write(CompressedData); + output.Write(Id); + output.Write(format); + output.Write(Width); + output.Write(Height); + if (Format == BitmapFormat.ColorMap8) + { + output.Write(ColorTableSize); } + output.Write(CompressedData); } } \ No newline at end of file diff --git a/Flazzy/Tags/DefineFontNameTag.cs b/Flazzy/Tags/DefineFontNameTag.cs index 29ae88a..273b955 100644 --- a/Flazzy/Tags/DefineFontNameTag.cs +++ b/Flazzy/Tags/DefineFontNameTag.cs @@ -3,39 +3,38 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class DefineFontNameTag : TagItem { - public class DefineFontNameTag : TagItem - { - public ushort Id { get; set; } - public string Name { get; set; } - public string Copyright { get; set; } + public ushort Id { get; set; } + public string Name { get; set; } + public string Copyright { get; set; } - public DefineFontNameTag() - : base(TagKind.DefineFontName) - { } - public DefineFontNameTag(HeaderRecord header, FlashReader input) - : base(header) - { - Id = input.ReadUInt16(); - Name = input.ReadNullString(); - Copyright = input.ReadNullString(); - } + public DefineFontNameTag() + : base(TagKind.DefineFontName) + { } + public DefineFontNameTag(HeaderRecord header, FlashReader input) + : base(header) + { + Id = input.ReadUInt16(); + Name = input.ReadNullString(); + Copyright = input.ReadNullString(); + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(ushort); - size += (Encoding.UTF8.GetByteCount(Name) + 1); - size += (Encoding.UTF8.GetByteCount(Copyright) + 1); - return size; - } + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += (Encoding.UTF8.GetByteCount(Name) + 1); + size += (Encoding.UTF8.GetByteCount(Copyright) + 1); + return size; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(Id); - output.WriteNullString(Name); - output.WriteNullString(Copyright); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(Id); + output.WriteNullString(Name); + output.WriteNullString(Copyright); } } \ No newline at end of file diff --git a/Flazzy/Tags/DefineSoundTag.cs b/Flazzy/Tags/DefineSoundTag.cs index 030555e..d58bd2a 100644 --- a/Flazzy/Tags/DefineSoundTag.cs +++ b/Flazzy/Tags/DefineSoundTag.cs @@ -1,54 +1,53 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class DefineSoundTag : TagItem { - public class DefineSoundTag : TagItem - { - public int Rate { get; set; } - public int Size { get; set; } - public ushort Id { get; set; } - public int Format { get; set; } - public int SoundType { get; set; } - public byte[] SoundData { get; set; } - public uint SoundSampleCount { get; set; } + public int Rate { get; set; } + public int Size { get; set; } + public ushort Id { get; set; } + public int Format { get; set; } + public int SoundType { get; set; } + public byte[] SoundData { get; set; } + public uint SoundSampleCount { get; set; } - public DefineSoundTag() - : base(TagKind.DefineSound) - { - SoundData = new byte[0]; - } - public DefineSoundTag(HeaderRecord header, FlashReader input) - : base(header) - { - Id = input.ReadUInt16(); - Format = input.ReadUB(4); - Rate = input.ReadUB(2); - Size = input.ReadUB(1); - SoundType = input.ReadUB(1); - SoundSampleCount = input.ReadUInt32(); - SoundData = input.ReadBytes(header.Length - 7); - } + public DefineSoundTag() + : base(TagKind.DefineSound) + { + SoundData = new byte[0]; + } + public DefineSoundTag(HeaderRecord header, FlashReader input) + : base(header) + { + Id = input.ReadUInt16(); + Format = input.ReadUB(4); + Rate = input.ReadUB(2); + Size = input.ReadUB(1); + SoundType = input.ReadUB(1); + SoundSampleCount = input.ReadUInt32(); + SoundData = input.ReadBytes(header.Length - 7); + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(ushort); - size += sizeof(byte); - size += sizeof(uint); - size += SoundData.Length; - return size; - } + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += sizeof(byte); + size += sizeof(uint); + size += SoundData.Length; + return size; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(Id); - output.WriteBits(4, Format); - output.WriteBits(2, Rate); - output.WriteBits(1, Size); - output.WriteBits(1, SoundType); - output.Write(SoundSampleCount); - output.Write(SoundData); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(Id); + output.WriteBits(4, Format); + output.WriteBits(2, Rate); + output.WriteBits(1, Size); + output.WriteBits(1, SoundType); + output.Write(SoundSampleCount); + output.Write(SoundData); } } \ No newline at end of file diff --git a/Flazzy/Tags/DoABCTag.cs b/Flazzy/Tags/DoABCTag.cs index e4c0096..205b04c 100644 --- a/Flazzy/Tags/DoABCTag.cs +++ b/Flazzy/Tags/DoABCTag.cs @@ -3,43 +3,42 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class DoABCTag : TagItem { - public class DoABCTag : TagItem - { - public uint Flags { get; set; } - public string Name { get; set; } - public byte[] ABCData { get; set; } + public uint Flags { get; set; } + public string Name { get; set; } + public byte[] ABCData { get; set; } - public DoABCTag() - : base(TagKind.DoABC) - { - ABCData = new byte[0]; - } - public DoABCTag(HeaderRecord header, FlashReader input) - : base(header) - { - Flags = input.ReadUInt32(); - Name = input.ReadNullString(); + public DoABCTag() + : base(TagKind.DoABC) + { + ABCData = new byte[0]; + } + public DoABCTag(HeaderRecord header, FlashReader input) + : base(header) + { + Flags = input.ReadUInt32(); + Name = input.ReadNullString(); - int partialLength = (Encoding.UTF8.GetByteCount(Name) + 5); - ABCData = input.ReadBytes(header.Length - partialLength); - } + int partialLength = (Encoding.UTF8.GetByteCount(Name) + 5); + ABCData = input.ReadBytes(header.Length - partialLength); + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(uint); - size += (Encoding.UTF8.GetByteCount(Name) + 1); - size += ABCData.Length; - return size; - } + public override int GetBodySize() + { + int size = 0; + size += sizeof(uint); + size += (Encoding.UTF8.GetByteCount(Name) + 1); + size += ABCData.Length; + return size; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(Flags); - output.WriteNullString(Name); - output.Write(ABCData); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(Flags); + output.WriteNullString(Name); + output.Write(ABCData); } } \ No newline at end of file diff --git a/Flazzy/Tags/EndTag.cs b/Flazzy/Tags/EndTag.cs index 81a0a83..dbe613a 100644 --- a/Flazzy/Tags/EndTag.cs +++ b/Flazzy/Tags/EndTag.cs @@ -1,19 +1,18 @@ using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class EndTag : TagItem { - public class EndTag : TagItem - { - public EndTag() - : base(TagKind.End) - { } - public EndTag(HeaderRecord header) - : base(header) - { } + public EndTag() + : base(TagKind.End) + { } + public EndTag(HeaderRecord header) + : base(header) + { } - public override int GetBodySize() - { - return 0; - } + public override int GetBodySize() + { + return 0; } } \ No newline at end of file diff --git a/Flazzy/Tags/Enums/BitmapFormat.cs b/Flazzy/Tags/Enums/BitmapFormat.cs index be030e1..1f65ee6 100644 --- a/Flazzy/Tags/Enums/BitmapFormat.cs +++ b/Flazzy/Tags/Enums/BitmapFormat.cs @@ -1,15 +1,14 @@ -namespace Flazzy.Tags +namespace Flazzy.Tags; + +/// +/// Represents the possible bitmap data formats for +/// +public enum BitmapFormat { /// - /// Represents the possible bitmap data formats for + /// Represents a 8-bit bitmap with a color map. /// - public enum BitmapFormat - { - /// - /// Represents a 8-bit bitmap with a color map. - /// - ColorMap8, - Rgb15, - Rgb32 - } -} + ColorMap8, + Rgb15, + Rgb32 +} \ No newline at end of file diff --git a/Flazzy/Tags/Enums/FlashEdition.cs b/Flazzy/Tags/Enums/FlashEdition.cs index 9b2ca37..d23a692 100644 --- a/Flazzy/Tags/Enums/FlashEdition.cs +++ b/Flazzy/Tags/Enums/FlashEdition.cs @@ -1,13 +1,12 @@ -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public enum FlashEdition { - public enum FlashEdition - { - Developer = 0, - FullCommercial = 1, - NonCommercial = 2, - Educational = 3, - NotForResale = 4, - Trial = 5, - None = 6 - } + Developer = 0, + FullCommercial = 1, + NonCommercial = 2, + Educational = 3, + NotForResale = 4, + Trial = 5, + None = 6 } \ No newline at end of file diff --git a/Flazzy/Tags/Enums/FlashProduct.cs b/Flazzy/Tags/Enums/FlashProduct.cs index 5d308aa..b867dc5 100644 --- a/Flazzy/Tags/Enums/FlashProduct.cs +++ b/Flazzy/Tags/Enums/FlashProduct.cs @@ -1,10 +1,9 @@ -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public enum FlashProduct { - public enum FlashProduct - { - Unknown = 0, - MacromediaFlexJ2EE = 1, - MacromediaFlexNET = 2, - AdobeFlex = 3 - } + Unknown = 0, + MacromediaFlexJ2EE = 1, + MacromediaFlexNET = 2, + AdobeFlex = 3 } \ No newline at end of file diff --git a/Flazzy/Tags/Enums/ImageFormat.cs b/Flazzy/Tags/Enums/ImageFormat.cs index f26d6b5..06b5baa 100644 --- a/Flazzy/Tags/Enums/ImageFormat.cs +++ b/Flazzy/Tags/Enums/ImageFormat.cs @@ -1,9 +1,8 @@ -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public enum ImageFormat : long { - public enum ImageFormat : long - { - PNG = 0, // 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A - JPEG = 1, // 0xFF, 0xD8 | OR | 0xFF, 0xD9, 0xFF, 0xD8 - GIF98a = 2 // 0x47 0x49 0x46 0x38 0x39 0x61 - } + PNG = 0, // 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A + JPEG = 1, // 0xFF, 0xD8 | OR | 0xFF, 0xD9, 0xFF, 0xD8 + GIF98a = 2 // 0x47 0x49 0x46 0x38 0x39 0x61 } \ No newline at end of file diff --git a/Flazzy/Tags/Enums/TagKind.cs b/Flazzy/Tags/Enums/TagKind.cs index ae33ae5..3c81a38 100644 --- a/Flazzy/Tags/Enums/TagKind.cs +++ b/Flazzy/Tags/Enums/TagKind.cs @@ -1,97 +1,96 @@ -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public enum TagKind { - public enum TagKind - { - End = 0, - ShowFrame = 1, + End = 0, + ShowFrame = 1, - DefineShape = 2, - DefineShape2 = 22, - DefineShape3 = 32, - DefineShape4 = 83, + DefineShape = 2, + DefineShape2 = 22, + DefineShape3 = 32, + DefineShape4 = 83, - PlaceObject = 4, - PlaceObject2 = 26, - PlaceObject3 = 70, + PlaceObject = 4, + PlaceObject2 = 26, + PlaceObject3 = 70, - RemoveObject = 5, - RemoveObject2 = 28, + RemoveObject = 5, + RemoveObject2 = 28, - DefineBits = 6, + DefineBits = 6, - DefineButton = 7, - DefineButton2 = 34, + DefineButton = 7, + DefineButton2 = 34, - JPEGTables = 8, - SetBackgroundColor = 9, + JPEGTables = 8, + SetBackgroundColor = 9, - DefineFont = 10, - DefineFont2 = 48, - DefineFont3 = 75, - DefineFont4 = 91, + DefineFont = 10, + DefineFont2 = 48, + DefineFont3 = 75, + DefineFont4 = 91, - DefineText = 11, - DefineText2 = 33, + DefineText = 11, + DefineText2 = 33, - DoAction = 12, + DoAction = 12, - DefineFontInfo = 13, - DefineFontInfo2 = 62, + DefineFontInfo = 13, + DefineFontInfo2 = 62, - DefineSound = 14, + DefineSound = 14, - StartSound = 15, - StartSound2 = 89, + StartSound = 15, + StartSound2 = 89, - DefineButtonSound = 17, + DefineButtonSound = 17, - SoundStreamHead = 18, - SoundStreamHead2 = 45, + SoundStreamHead = 18, + SoundStreamHead2 = 45, - SoundStreamBlock = 19, + SoundStreamBlock = 19, - DefineBitsLossless = 20, - DefineBitsLossless2 = 36, + DefineBitsLossless = 20, + DefineBitsLossless2 = 36, - DefineBitsJPEG2 = 21, - DefineBitsJPEG3 = 35, - DefineBitsJPEG4 = 90, + DefineBitsJPEG2 = 21, + DefineBitsJPEG3 = 35, + DefineBitsJPEG4 = 90, - DefineButtonCxform = 23, - Protect = 24, - DefineEditText = 37, - DefineSprite = 39, - ProductInfo = 41, - FrameLabel = 43, + DefineButtonCxform = 23, + Protect = 24, + DefineEditText = 37, + DefineSprite = 39, + ProductInfo = 41, + FrameLabel = 43, - DefineMorphShape = 46, - DefineMorphShape2 = 84, + DefineMorphShape = 46, + DefineMorphShape2 = 84, - ExportAssets = 56, + ExportAssets = 56, - ImportAssets = 57, - ImportAssets2 = 71, + ImportAssets = 57, + ImportAssets2 = 71, - EnableDebugger = 58, - EnableDebugger2 = 64, + EnableDebugger = 58, + EnableDebugger2 = 64, - DoInitAction = 59, - DefineVideoStream = 60, - VideoFrame = 61, - ScriptLimits = 65, - SetTabIndex = 66, - FileAttributes = 69, - DefineFontAlignZones = 73, - CSMTextSettings = 74, - SymbolClass = 76, - Metadata = 77, - DefineScalingGrid = 78, - DoABC = 82, - DefineSceneAndFrameLabelData = 86, - DefineBinaryData = 87, - DefineFontName = 88, - EnableTelemetry = 93, + DoInitAction = 59, + DefineVideoStream = 60, + VideoFrame = 61, + ScriptLimits = 65, + SetTabIndex = 66, + FileAttributes = 69, + DefineFontAlignZones = 73, + CSMTextSettings = 74, + SymbolClass = 76, + Metadata = 77, + DefineScalingGrid = 78, + DoABC = 82, + DefineSceneAndFrameLabelData = 86, + DefineBinaryData = 87, + DefineFontName = 88, + EnableTelemetry = 93, - Unknown = 255 - } + Unknown = 255 } \ No newline at end of file diff --git a/Flazzy/Tags/ExportAssetsTag.cs b/Flazzy/Tags/ExportAssetsTag.cs index 34a7a2f..3ba5e41 100644 --- a/Flazzy/Tags/ExportAssetsTag.cs +++ b/Flazzy/Tags/ExportAssetsTag.cs @@ -3,55 +3,54 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class ExportAssetsTag : TagItem { - public class ExportAssetsTag : TagItem + public List Ids { get; } + public List Names { get; } + + public ExportAssetsTag() + : base(TagKind.ExportAssets) + { + Ids = new List(); + Names = new List(); + } + public ExportAssetsTag(HeaderRecord header, FlashReader input) + : base(header) { - public List Ids { get; } - public List Names { get; } + ushort assetCount = input.ReadUInt16(); - public ExportAssetsTag() - : base(TagKind.ExportAssets) - { - Ids = new List(); - Names = new List(); - } - public ExportAssetsTag(HeaderRecord header, FlashReader input) - : base(header) + Ids = new List(assetCount); + Names = new List(assetCount); + for (int i = 0; i < assetCount; i++) { - ushort assetCount = input.ReadUInt16(); - - Ids = new List(assetCount); - Names = new List(assetCount); - for (int i = 0; i < assetCount; i++) - { - Ids.Add(input.ReadUInt16()); - Names.Add(input.ReadNullString()); - } + Ids.Add(input.ReadUInt16()); + Names.Add(input.ReadNullString()); } + } - public override int GetBodySize() + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += (sizeof(ushort) * Ids.Count); + foreach (string name in Names) { - int size = 0; - size += sizeof(ushort); - size += (sizeof(ushort) * Ids.Count); - foreach (string name in Names) - { - size += (Encoding.UTF8.GetByteCount(name) + 1); - } - return size; + size += (Encoding.UTF8.GetByteCount(name) + 1); } + return size; + } + + protected override void WriteBodyTo(FlashWriter output) + { + int assetCount = Math.Min(Ids.Count, Names.Count); + output.Write((ushort)assetCount); - protected override void WriteBodyTo(FlashWriter output) + for (int i = 0; i < assetCount; i++) { - int assetCount = Math.Min(Ids.Count, Names.Count); - output.Write((ushort)assetCount); - - for (int i = 0; i < assetCount; i++) - { - output.Write(Ids[i]); - output.WriteNullString(Names[i]); - } + output.Write(Ids[i]); + output.WriteNullString(Names[i]); } } } \ No newline at end of file diff --git a/Flazzy/Tags/FileAttributesTag.cs b/Flazzy/Tags/FileAttributesTag.cs index 38c0252..397ffa3 100644 --- a/Flazzy/Tags/FileAttributesTag.cs +++ b/Flazzy/Tags/FileAttributesTag.cs @@ -1,54 +1,53 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class FileAttributesTag : TagItem { - public class FileAttributesTag : TagItem - { - public bool UseDirectBlit { get; set; } - public bool UseGPU { get; set; } - public bool HasMetadata { get; set; } - public bool ActionScript3 { get; set; } - public bool NoCrossDomainCache { get; set; } - public bool UseNetwork { get; set; } + public bool UseDirectBlit { get; set; } + public bool UseGPU { get; set; } + public bool HasMetadata { get; set; } + public bool ActionScript3 { get; set; } + public bool NoCrossDomainCache { get; set; } + public bool UseNetwork { get; set; } - public FileAttributesTag() - : base(TagKind.FileAttributes) - { } - public FileAttributesTag(HeaderRecord header, FlashReader input) - : base(header) - { - input.Align(); + public FileAttributesTag() + : base(TagKind.FileAttributes) + { } + public FileAttributesTag(HeaderRecord header, FlashReader input) + : base(header) + { + input.Align(); - input.ReadUB(1); // Reserved | Must equal '0'. - UseDirectBlit = (input.ReadUB(1) == 1); - UseGPU = (input.ReadUB(1) == 1); - HasMetadata = (input.ReadUB(1) == 1); - ActionScript3 = (input.ReadUB(1) == 1); - NoCrossDomainCache = (input.ReadUB(1) == 1); - input.ReadUB(1); // Reserved | Must equal '0'. - UseNetwork = (input.ReadUB(1) == 1); - input.ReadUB(24); // Reserved | Must equal '0'. - } + input.ReadUB(1); // Reserved | Must equal '0'. + UseDirectBlit = (input.ReadUB(1) == 1); + UseGPU = (input.ReadUB(1) == 1); + HasMetadata = (input.ReadUB(1) == 1); + ActionScript3 = (input.ReadUB(1) == 1); + NoCrossDomainCache = (input.ReadUB(1) == 1); + input.ReadUB(1); // Reserved | Must equal '0'. + UseNetwork = (input.ReadUB(1) == 1); + input.ReadUB(24); // Reserved | Must equal '0'. + } - public override int GetBodySize() - { - return sizeof(int); // 32 Bits - } + public override int GetBodySize() + { + return sizeof(int); // 32 Bits + } - protected override void WriteBodyTo(FlashWriter output) - { - output.WriteBits(1, 0); // Reserved | Must equal '0'. - output.WriteBits(1, (UseDirectBlit ? 1 : 0)); - output.WriteBits(1, (UseGPU ? 1 : 0)); - output.WriteBits(1, (HasMetadata ? 1 : 0)); - output.WriteBits(1, (ActionScript3 ? 1 : 0)); - output.WriteBits(1, (NoCrossDomainCache ? 1 : 0)); - output.WriteBits(1, 0); // Reserved | Must equal '0'. - output.WriteBits(1, (UseNetwork ? 1 : 0)); - output.WriteBits(24, 0); // Reserved | Must equal '0'. + protected override void WriteBodyTo(FlashWriter output) + { + output.WriteBits(1, 0); // Reserved | Must equal '0'. + output.WriteBits(1, (UseDirectBlit ? 1 : 0)); + output.WriteBits(1, (UseGPU ? 1 : 0)); + output.WriteBits(1, (HasMetadata ? 1 : 0)); + output.WriteBits(1, (ActionScript3 ? 1 : 0)); + output.WriteBits(1, (NoCrossDomainCache ? 1 : 0)); + output.WriteBits(1, 0); // Reserved | Must equal '0'. + output.WriteBits(1, (UseNetwork ? 1 : 0)); + output.WriteBits(24, 0); // Reserved | Must equal '0'. - output.Flush(); - } + output.Flush(); } } \ No newline at end of file diff --git a/Flazzy/Tags/FrameLabelTag.cs b/Flazzy/Tags/FrameLabelTag.cs index 4782269..c22e2a7 100644 --- a/Flazzy/Tags/FrameLabelTag.cs +++ b/Flazzy/Tags/FrameLabelTag.cs @@ -3,29 +3,28 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class FrameLabelTag : TagItem { - public class FrameLabelTag : TagItem - { - public string Name { get; set; } + public string Name { get; set; } - public FrameLabelTag() - : base(TagKind.FrameLabel) - { } - public FrameLabelTag(HeaderRecord header, FlashReader input) - : base(header) - { - Name = input.ReadNullString(); - } + public FrameLabelTag() + : base(TagKind.FrameLabel) + { } + public FrameLabelTag(HeaderRecord header, FlashReader input) + : base(header) + { + Name = input.ReadNullString(); + } - public override int GetBodySize() - { - return (Encoding.UTF8.GetByteCount(Name) + 1); - } + public override int GetBodySize() + { + return (Encoding.UTF8.GetByteCount(Name) + 1); + } - protected override void WriteBodyTo(FlashWriter output) - { - output.WriteNullString(Name); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.WriteNullString(Name); } } \ No newline at end of file diff --git a/Flazzy/Tags/ImageTag.cs b/Flazzy/Tags/ImageTag.cs index 41b4e9f..9b4db68 100644 --- a/Flazzy/Tags/ImageTag.cs +++ b/Flazzy/Tags/ImageTag.cs @@ -2,37 +2,36 @@ using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public abstract class ImageTag : TagItem { - public abstract class ImageTag : TagItem - { - public ImageFormat Format { get; protected set; } + public ImageFormat Format { get; protected set; } - public ImageTag(TagKind kind) - : base(kind) - { } - public ImageTag(HeaderRecord header) - : base(header) - { } + public ImageTag(TagKind kind) + : base(kind) + { } + public ImageTag(HeaderRecord header) + : base(header) + { } - protected ImageFormat GetFormat(byte[] data) + protected ImageFormat GetFormat(byte[] data) + { + if (BitConverter.ToInt32(data, 0) == -654321153 || BitConverter.ToInt16(data, 0) == -9985) { - if (BitConverter.ToInt32(data, 0) == -654321153 || BitConverter.ToInt16(data, 0) == -9985) - { - return ImageFormat.JPEG; - } - else if (BitConverter.ToInt64(data, 0) == 727905341920923785) - { - return ImageFormat.PNG; - } - else if (BitConverter.ToInt32(data, 0) == 944130375 && BitConverter.ToInt16(data, 4) == 24889) - { - return ImageFormat.GIF98a; - } - throw new ArgumentException("Provided data contains an unknown image format."); + return ImageFormat.JPEG; } - - public abstract Color[,] GetARGBMap(); - public abstract void SetARGBMap(Color[,] map); + else if (BitConverter.ToInt64(data, 0) == 727905341920923785) + { + return ImageFormat.PNG; + } + else if (BitConverter.ToInt32(data, 0) == 944130375 && BitConverter.ToInt16(data, 4) == 24889) + { + return ImageFormat.GIF98a; + } + throw new ArgumentException("Provided data contains an unknown image format."); } + + public abstract Color[,] GetARGBMap(); + public abstract void SetARGBMap(Color[,] map); } \ No newline at end of file diff --git a/Flazzy/Tags/MetadataTag.cs b/Flazzy/Tags/MetadataTag.cs index a4bca2c..480ee55 100644 --- a/Flazzy/Tags/MetadataTag.cs +++ b/Flazzy/Tags/MetadataTag.cs @@ -3,25 +3,24 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class MetadataTag : TagItem { - public class MetadataTag : TagItem - { - public string Metadata { get; set; } + public string Metadata { get; set; } - public MetadataTag() - : base(TagKind.Metadata) - { } - public MetadataTag(HeaderRecord header, FlashReader input) - : base(header) - { - Metadata = input.ReadNullString(); - } + public MetadataTag() + : base(TagKind.Metadata) + { } + public MetadataTag(HeaderRecord header, FlashReader input) + : base(header) + { + Metadata = input.ReadNullString(); + } - public override int GetBodySize() => (Encoding.UTF8.GetByteCount(Metadata) + 1); - protected override void WriteBodyTo(FlashWriter output) - { - output.WriteNullString(Metadata); - } + public override int GetBodySize() => (Encoding.UTF8.GetByteCount(Metadata) + 1); + protected override void WriteBodyTo(FlashWriter output) + { + output.WriteNullString(Metadata); } } \ No newline at end of file diff --git a/Flazzy/Tags/ScriptLimitsTag.cs b/Flazzy/Tags/ScriptLimitsTag.cs index 44df99f..f2af3fa 100644 --- a/Flazzy/Tags/ScriptLimitsTag.cs +++ b/Flazzy/Tags/ScriptLimitsTag.cs @@ -1,35 +1,34 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class ScriptLimitsTag : TagItem { - public class ScriptLimitsTag : TagItem - { - public ushort MaxRecursionDepth { get; set; } - public ushort ScriptTimeoutSeconds { get; set; } + public ushort MaxRecursionDepth { get; set; } + public ushort ScriptTimeoutSeconds { get; set; } - public ScriptLimitsTag() - : base(TagKind.ScriptLimits) - { } - public ScriptLimitsTag(HeaderRecord header, FlashReader input) - : base(header) - { - MaxRecursionDepth = input.ReadUInt16(); - ScriptTimeoutSeconds = input.ReadUInt16(); - } + public ScriptLimitsTag() + : base(TagKind.ScriptLimits) + { } + public ScriptLimitsTag(HeaderRecord header, FlashReader input) + : base(header) + { + MaxRecursionDepth = input.ReadUInt16(); + ScriptTimeoutSeconds = input.ReadUInt16(); + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(ushort); - size += sizeof(ushort); - return size; - } + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += sizeof(ushort); + return size; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(MaxRecursionDepth); - output.Write(ScriptTimeoutSeconds); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(MaxRecursionDepth); + output.Write(ScriptTimeoutSeconds); } } \ No newline at end of file diff --git a/Flazzy/Tags/SetBackgroundColorTag.cs b/Flazzy/Tags/SetBackgroundColorTag.cs index d7880e2..d4cb776 100644 --- a/Flazzy/Tags/SetBackgroundColorTag.cs +++ b/Flazzy/Tags/SetBackgroundColorTag.cs @@ -3,38 +3,37 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class SetBackgroundColorTag : TagItem { - public class SetBackgroundColorTag : TagItem - { - public Color BackgroundColor { get; set; } + public Color BackgroundColor { get; set; } - public SetBackgroundColorTag() - : base(TagKind.SetBackgroundColor) - { } - public SetBackgroundColorTag(HeaderRecord header, FlashReader input) - : base(header) - { - byte r = input.ReadByte(); - byte g = input.ReadByte(); - byte b = input.ReadByte(); - BackgroundColor = Color.FromArgb(r, g, b); - } + public SetBackgroundColorTag() + : base(TagKind.SetBackgroundColor) + { } + public SetBackgroundColorTag(HeaderRecord header, FlashReader input) + : base(header) + { + byte r = input.ReadByte(); + byte g = input.ReadByte(); + byte b = input.ReadByte(); + BackgroundColor = Color.FromArgb(r, g, b); + } - public override int GetBodySize() - { - int size = 0; - size += sizeof(byte); - size += sizeof(byte); - size += sizeof(byte); - return size; - } + public override int GetBodySize() + { + int size = 0; + size += sizeof(byte); + size += sizeof(byte); + size += sizeof(byte); + return size; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(BackgroundColor.R); - output.Write(BackgroundColor.G); - output.Write(BackgroundColor.B); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(BackgroundColor.R); + output.Write(BackgroundColor.G); + output.Write(BackgroundColor.B); } } \ No newline at end of file diff --git a/Flazzy/Tags/ShowFrameTag.cs b/Flazzy/Tags/ShowFrameTag.cs index 44fc779..b7446bc 100644 --- a/Flazzy/Tags/ShowFrameTag.cs +++ b/Flazzy/Tags/ShowFrameTag.cs @@ -1,19 +1,18 @@ using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class ShowFrameTag : TagItem { - public class ShowFrameTag : TagItem - { - public ShowFrameTag() - : base(TagKind.ShowFrame) - { } - public ShowFrameTag(HeaderRecord header) - : base(header) - { } + public ShowFrameTag() + : base(TagKind.ShowFrame) + { } + public ShowFrameTag(HeaderRecord header) + : base(header) + { } - public override int GetBodySize() - { - return 0; - } + public override int GetBodySize() + { + return 0; } } \ No newline at end of file diff --git a/Flazzy/Tags/SymbolClassTag.cs b/Flazzy/Tags/SymbolClassTag.cs index aa70cdf..8e167a2 100644 --- a/Flazzy/Tags/SymbolClassTag.cs +++ b/Flazzy/Tags/SymbolClassTag.cs @@ -3,56 +3,55 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class SymbolClassTag : TagItem { - public class SymbolClassTag : TagItem - { - public List Ids { get; } - public List Names { get; } + public List Ids { get; } + public List Names { get; } - public SymbolClassTag() - : base(TagKind.SymbolClass) - { - Ids = new List(); - Names = new List(); - } - public SymbolClassTag(HeaderRecord header, FlashReader input) - : base(header) - { - ushort symbolCount = input.ReadUInt16(); + public SymbolClassTag() + : base(TagKind.SymbolClass) + { + Ids = new List(); + Names = new List(); + } + public SymbolClassTag(HeaderRecord header, FlashReader input) + : base(header) + { + ushort symbolCount = input.ReadUInt16(); - Ids = new List(symbolCount); - Names = new List(symbolCount); + Ids = new List(symbolCount); + Names = new List(symbolCount); - for (int i = 0; i < symbolCount; i++) - { - Ids.Add(input.ReadUInt16()); - Names.Add(input.ReadNullString()); - } + for (int i = 0; i < symbolCount; i++) + { + Ids.Add(input.ReadUInt16()); + Names.Add(input.ReadNullString()); } + } - public override int GetBodySize() + public override int GetBodySize() + { + int size = 0; + size += sizeof(ushort); + size += (sizeof(ushort) * Ids.Count); + foreach (string name in Names) { - int size = 0; - size += sizeof(ushort); - size += (sizeof(ushort) * Ids.Count); - foreach (string name in Names) - { - size += (Encoding.UTF8.GetByteCount(name) + 1); - } - return size; + size += (Encoding.UTF8.GetByteCount(name) + 1); } + return size; + } + + protected override void WriteBodyTo(FlashWriter output) + { + int symbolCount = Math.Min(Ids.Count, Names.Count); + output.Write((ushort)symbolCount); - protected override void WriteBodyTo(FlashWriter output) + for (int i = 0; i < symbolCount; i++) { - int symbolCount = Math.Min(Ids.Count, Names.Count); - output.Write((ushort)symbolCount); - - for (int i = 0; i < symbolCount; i++) - { - output.Write(Ids[i]); - output.WriteNullString(Names[i]); - } + output.Write(Ids[i]); + output.WriteNullString(Names[i]); } } } \ No newline at end of file diff --git a/Flazzy/Tags/TagItem.cs b/Flazzy/Tags/TagItem.cs index 479c1bc..f31a648 100644 --- a/Flazzy/Tags/TagItem.cs +++ b/Flazzy/Tags/TagItem.cs @@ -1,32 +1,31 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public abstract class TagItem : FlashItem { - public abstract class TagItem : FlashItem - { - public TagKind Kind => Header.Kind; - public HeaderRecord Header { get; } + public TagKind Kind => Header.Kind; + public HeaderRecord Header { get; } - protected override string DebuggerDisplay => Kind.ToString(); + protected override string DebuggerDisplay => Kind.ToString(); - public TagItem(TagKind kind) - : this(new HeaderRecord(kind)) - { } - public TagItem(HeaderRecord header) - { - Header = header; - } + public TagItem(TagKind kind) + : this(new HeaderRecord(kind)) + { } + public TagItem(HeaderRecord header) + { + Header = header; + } - public abstract int GetBodySize(); + public abstract int GetBodySize(); - public override void WriteTo(FlashWriter output) - { - Header.Length = GetBodySize(); - Header.WriteTo(output); - WriteBodyTo(output); - } - protected virtual void WriteBodyTo(FlashWriter output) - { } + public override void WriteTo(FlashWriter output) + { + Header.Length = GetBodySize(); + Header.WriteTo(output); + WriteBodyTo(output); } + protected virtual void WriteBodyTo(FlashWriter output) + { } } \ No newline at end of file diff --git a/Flazzy/Tags/UnknownTag.cs b/Flazzy/Tags/UnknownTag.cs index f6aee9e..ed5045c 100644 --- a/Flazzy/Tags/UnknownTag.cs +++ b/Flazzy/Tags/UnknownTag.cs @@ -1,31 +1,30 @@ using Flazzy.IO; using Flazzy.Records; -namespace Flazzy.Tags +namespace Flazzy.Tags; + +public class UnknownTag : TagItem { - public class UnknownTag : TagItem - { - public byte[] Data { get; set; } + public byte[] Data { get; set; } - public UnknownTag(TagKind kind) - : base(kind) - { - Data = new byte[0]; - } - public UnknownTag(HeaderRecord header, FlashReader input) - : base(header) - { - Data = input.ReadBytes(header.Length); - } + public UnknownTag(TagKind kind) + : base(kind) + { + Data = new byte[0]; + } + public UnknownTag(HeaderRecord header, FlashReader input) + : base(header) + { + Data = input.ReadBytes(header.Length); + } - public override int GetBodySize() - { - return Data.Length; - } + public override int GetBodySize() + { + return Data.Length; + } - protected override void WriteBodyTo(FlashWriter output) - { - output.Write(Data); - } + protected override void WriteBodyTo(FlashWriter output) + { + output.Write(Data); } } \ No newline at end of file diff --git a/Flazzy/Tools/FlashCrypto.cs b/Flazzy/Tools/FlashCrypto.cs index 27916aa..f9999e6 100644 --- a/Flazzy/Tools/FlashCrypto.cs +++ b/Flazzy/Tools/FlashCrypto.cs @@ -1,6 +1,6 @@ -using System.Text; +using System.Runtime.InteropServices; using System.Security.Cryptography; -using System.Runtime.InteropServices; +using System.Text; namespace Flazzy.Tools;