コード例 #1
0
 public byte[] ToByteArray()
 {
     using (var trait = new FlashWriter())
     {
         trait.Write7BitEncodedInt(SlotId);
         trait.Write7BitEncodedInt(FunctionIndex);
         return(trait.ToArray());
     }
 }
コード例 #2
0
ファイル: QName.cs プロジェクト: proxymoron/Sulakore
 public byte[] ToByteArray()
 {
     using (var qName = new FlashWriter())
     {
         qName.Write7BitEncodedInt(NamespaceIndex);
         qName.Write7BitEncodedInt(ObjNameIndex);
         return(qName.ToArray());
     }
 }
コード例 #3
0
 public byte[] ToByteArray()
 {
     using (var trait = new FlashWriter())
     {
         trait.Write7BitEncodedInt(DispId);
         trait.Write7BitEncodedInt(MethodIndex);
         return(trait.ToArray());
     }
 }
コード例 #4
0
 public byte[] ToByteArray()
 {
     using (var multiname = new FlashWriter())
     {
         multiname.Write7BitEncodedInt(ObjNameIndex);
         multiname.Write7BitEncodedInt(NamespaceSetIndex);
         return(multiname.ToArray());
     }
 }
コード例 #5
0
ファイル: ASException.cs プロジェクト: proxymoron/Sulakore
 public byte[] ToByteArray()
 {
     using (var asException = new FlashWriter())
     {
         asException.Write7BitEncodedInt(From);
         asException.Write7BitEncodedInt(To);
         asException.Write7BitEncodedInt(Target);
         asException.Write7BitEncodedInt(ExceptionTypeIndex);
         asException.Write7BitEncodedInt(VariableNameIndex);
         return(asException.ToArray());
     }
 }
コード例 #6
0
        public byte[] ToByteArray()
        {
            using (var asNamespaceSet = new FlashWriter())
            {
                asNamespaceSet.Write7BitEncodedInt(NamespaceIndices.Count);

                foreach (int namespaceIndex in NamespaceIndices)
                {
                    asNamespaceSet.Write7BitEncodedInt(namespaceIndex);
                }

                return(asNamespaceSet.ToArray());
            }
        }
コード例 #7
0
ファイル: ASInstance.cs プロジェクト: proxymoron/Sulakore
        public byte[] ToByteArray()
        {
            using (var asInstance = new FlashWriter())
            {
                asInstance.Write7BitEncodedInt(TypeIndex);
                asInstance.Write7BitEncodedInt(SuperTypeIndex);
                asInstance.Write7BitEncodedInt((byte)ClassInfo);

                if ((ClassInfo & ClassFlags.ProtectedNamespace) != 0)
                {
                    asInstance.Write7BitEncodedInt(ProtectedNamespaceIndex);
                }

                asInstance.Write7BitEncodedInt(InterfaceIndices.Count);
                foreach (int index in InterfaceIndices)
                {
                    asInstance.Write7BitEncodedInt(index);
                }

                asInstance.Write7BitEncodedInt(ConstructorIndex);
                asInstance.Write7BitEncodedInt(Traits.Count);

                foreach (ASTrait trait in Traits)
                {
                    asInstance.Write(trait.ToByteArray());
                }

                return(asInstance.ToArray());
            }
        }
コード例 #8
0
 public byte[] ToByteArray()
 {
     using (var asMetadata = new FlashWriter())
     {
         asMetadata.Write7BitEncodedInt(ObjNameIndex);
         asMetadata.Write7BitEncodedInt(Elements.Count);
         foreach (Tuple <int, int> element in Elements)
         {
             asMetadata.Write7BitEncodedInt(element.Item1);
             asMetadata.Write7BitEncodedInt(element.Item2);
         }
         return(asMetadata.ToArray());
     }
 }
コード例 #9
0
        public byte[] ToByteArray()
        {
            using (var asMethodBody = new FlashWriter())
            {
                asMethodBody.Write7BitEncodedInt(MethodIndex);
                asMethodBody.Write7BitEncodedInt(MaxStack);
                asMethodBody.Write7BitEncodedInt(LocalCount);
                asMethodBody.Write7BitEncodedInt(InitialScopeDepth);
                asMethodBody.Write7BitEncodedInt(MaxScopeDepth);

                asMethodBody.Write7BitEncodedInt(Bytecode.Length);
                asMethodBody.Write(Bytecode);

                asMethodBody.Write7BitEncodedInt(Exceptions.Count);
                foreach (ASException exception in Exceptions)
                {
                    asMethodBody.Write(exception.ToByteArray());
                }

                asMethodBody.Write7BitEncodedInt(Traits.Count);
                foreach (ASTrait trait in Traits)
                {
                    asMethodBody.Write(trait.ToByteArray());
                }

                return(asMethodBody.ToArray());
            }
        }
コード例 #10
0
ファイル: ASClass.cs プロジェクト: proxymoron/Sulakore
        public byte[] ToByteArray()
        {
            using (var asClass = new FlashWriter())
            {
                asClass.Write7BitEncodedInt(ConstructorIndex);
                asClass.Write7BitEncodedInt(Traits.Count);

                foreach (ASTrait trait in Traits)
                {
                    asClass.Write(trait.ToByteArray());
                }

                return(asClass.ToArray());
            }
        }
コード例 #11
0
        public byte[] ToByteArray()
        {
            using (var asScript = new FlashWriter())
            {
                asScript.Write7BitEncodedInt(FunctionIndex);
                asScript.Write7BitEncodedInt(Traits.Count);

                foreach (ASTrait trait in Traits)
                {
                    asScript.Write(trait.ToByteArray());
                }

                return(asScript.ToArray());
            }
        }
コード例 #12
0
ファイル: Typename.cs プロジェクト: proxymoron/Sulakore
        public byte[] ToByteArray()
        {
            using (var typename = new FlashWriter())
            {
                typename.Write7BitEncodedInt(TypeIndex);
                typename.Write7BitEncodedInt(ParameterTypeIndices.Count);

                foreach (int multinameParameterIndex in ParameterTypeIndices)
                {
                    typename.Write7BitEncodedInt(multinameParameterIndex);
                }

                return(typename.ToArray());
            }
        }
コード例 #13
0
        public byte[] ToByteArray()
        {
            using (var trait = new FlashWriter())
            {
                trait.Write7BitEncodedInt(SlotId);
                trait.Write7BitEncodedInt(TypeIndex);
                trait.Write7BitEncodedInt(ValueIndex);

                if (ValueIndex != 0)
                {
                    trait.Write((byte)ValueType);
                }

                return(trait.ToArray());
            }
        }
コード例 #14
0
ファイル: ABCFile.cs プロジェクト: proxymoron/Sulakore
        public byte[] ToByteArray()
        {
            using (var abcFile = new FlashWriter())
            {
                abcFile.Write(MinorVersion);
                abcFile.Write(MajorVersion);
                abcFile.Write(Constants.ToByteArray());

                abcFile.Write7BitEncodedInt(Methods.Count);
                foreach (ASMethod methodInfo in Methods)
                {
                    abcFile.Write(methodInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(Metadata.Count);
                foreach (ASMetadata metadataInfo in Metadata)
                {
                    abcFile.Write(metadataInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(Instances.Count);
                foreach (ASInstance instanceInfo in Instances)
                {
                    abcFile.Write(instanceInfo.ToByteArray());
                }

                foreach (ASClass classInfo in Classes)
                {
                    abcFile.Write(classInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(Scripts.Count);
                foreach (ASScript scriptInfo in Scripts)
                {
                    abcFile.Write(scriptInfo.ToByteArray());
                }

                abcFile.Write7BitEncodedInt(MethodBodies.Count);
                foreach (ASMethodBody methodBodyInfo in MethodBodies)
                {
                    abcFile.Write(methodBodyInfo.ToByteArray());
                }

                return(abcFile.ToArray());
            }
        }
コード例 #15
0
ファイル: ASNamespace.cs プロジェクト: proxymoron/Sulakore
 public byte[] ToByteArray()
 {
     using (var asNamespace = new FlashWriter())
     {
         asNamespace.Write((byte)NamespaceType);
         asNamespace.Write7BitEncodedInt(ObjNameIndex);
         return(asNamespace.ToArray());
     }
 }
コード例 #16
0
        public byte[] ToByteArray()
        {
            using (var asConstants = new FlashWriter())
            {
                asConstants.Write7BitEncodedInt(_integers.Count);
                for (int i = 1; i < _integers.Count; i++)
                {
                    asConstants.Write7BitEncodedInt(_integers[i]);
                }

                asConstants.Write7BitEncodedInt(_uintegers.Count);
                for (int i = 1; i < _uintegers.Count; i++)
                {
                    asConstants.Write7BitEncodedInt((int)_uintegers[i]);
                }

                asConstants.Write7BitEncodedInt(_doubles.Count);
                for (int i = 1; i < _doubles.Count; i++)
                {
                    asConstants.Write(_doubles[i]);
                }

                asConstants.Write7BitEncodedInt(_strings.Count);
                for (int i = 1; i < _strings.Count; i++)
                {
                    asConstants.Write(_strings[i]);
                }

                asConstants.Write7BitEncodedInt(_namespaces.Count);
                for (int i = 1; i < _namespaces.Count; i++)
                {
                    asConstants.Write(_namespaces[i].ToByteArray());
                }

                asConstants.Write7BitEncodedInt(_namespaceSets.Count);
                for (int i = 1; i < _namespaceSets.Count; i++)
                {
                    asConstants.Write(_namespaceSets[i].ToByteArray());
                }

                asConstants.Write7BitEncodedInt(_multinames.Count);
                for (int i = 1; i < _multinames.Count; i++)
                {
                    asConstants.Write(_multinames[i].ToByteArray());
                }

                return(asConstants.ToArray());
            }
        }
コード例 #17
0
        public byte[] ToByteArray()
        {
            using (var asTrait = new FlashWriter())
            {
                var trueKind = (byte)((
                                          (byte)Attributes << 4) + (byte)TraitType);

                asTrait.Write7BitEncodedInt(TypeIndex);
                asTrait.Write(trueKind);
                asTrait.Write(Data.ToByteArray());

                if ((Attributes & TraitAttributes.Metadata) != 0)
                {
                    asTrait.Write7BitEncodedInt(MetadataIndices.Count);

                    foreach (int index in MetadataIndices)
                    {
                        asTrait.Write7BitEncodedInt(index);
                    }
                }
                return(asTrait.ToArray());
            }
        }
コード例 #18
0
        public byte[] ToByteArray()
        {
            using (var asMethod = new FlashWriter())
            {
                asMethod.Write7BitEncodedInt(Parameters.Count);
                asMethod.Write7BitEncodedInt(ReturnTypeIndex);

                foreach (ASParameter parameter in Parameters)
                {
                    asMethod.Write7BitEncodedInt(parameter.TypeIndex);
                }

                asMethod.Write7BitEncodedInt(NameIndex);
                asMethod.Write7BitEncodedInt((byte)MethodInfo);

                if ((MethodInfo & MethodFlags.HasOptional) != 0)
                {
                    int    optionalParamCount = 0;
                    byte[] optionalParamData  = null;
                    using (var opParam = new FlashWriter())
                    {
                        for (int i = 0; i < Parameters.Count; i++)
                        {
                            if (!Parameters[i].IsOptional)
                            {
                                continue;
                            }

                            optionalParamCount++;
                            opParam.Write7BitEncodedInt(Parameters[i].ValueIndex);
                            opParam.Write((byte)Parameters[i].ValueType);
                        }
                        optionalParamData = opParam.ToArray();
                    }

                    asMethod.Write7BitEncodedInt(optionalParamCount);
                    asMethod.Write(optionalParamData);
                }

                if ((MethodInfo & MethodFlags.HasParamNames) != 0)
                {
                    foreach (ASParameter parameter in Parameters)
                    {
                        asMethod.Write7BitEncodedInt(parameter.ObjNameIndex);
                    }
                }
                return(asMethod.ToArray());
            }
        }
コード例 #19
0
        protected void RemoveHostSuffix(ABCFile abc, ASMethod connectMethod)
        {
            using (var inCode = new FlashReader(connectMethod.Body.Bytecode))
                using (var outCode = new FlashWriter(inCode.Length))
                {
                    int ifNeCount = 0;
                    while (inCode.Position != inCode.Length)
                    {
                        OPCode op = inCode.ReadOP();
                        outCode.WriteOP(op);
                        if (op == OPCode.IfNe && ++ifNeCount == 2)
                        {
                            var iFNeJumpCount = (int)inCode.ReadS24();
                            outCode.WriteS24(iFNeJumpCount + 6);
                            continue;
                        }
                        else if (op != OPCode.PushInt)
                        {
                            continue;
                        }

                        int pushIntIndex = inCode.Read7BitEncodedInt();
                        int integerValue = abc.Constants.Integers[pushIntIndex];
                        switch (integerValue)
                        {
                        case 65244:
                        case 65185:
                        case 65191:
                        case 65189:
                        case 65188:
                        case 65174:
                        case 65238:
                        case 65184:
                        case 65171:
                        case 65172:
                        {
                            pushIntIndex = abc.Constants.AddInteger(65290);
                            break;
                        }
                        }
                        outCode.Write7BitEncodedInt(pushIntIndex);
                    }
                    connectMethod.Body.Bytecode = outCode.ToArray();
                }
            RemoveDeadFalseConditions(connectMethod.Body);
        }
コード例 #20
0
        public bool DisableExpirationDateCheck()
        {
            ABCFile    abc           = ABCFiles[2];
            ASInstance windowContext = abc.FindInstanceByName("WindowContext");

            if (windowContext == null)
            {
                return(false);
            }

            using (var inCode = new FlashReader(windowContext.Constructor.Body.Bytecode))
                using (var outCode = new FlashWriter())
                {
                    int setLocal11Itterations = 0;
                    while (inCode.Position != inCode.Length)
                    {
                        OPCode op = inCode.ReadOP();
                        outCode.WriteOP(op);
                        if (op != OPCode.SetLocal)
                        {
                            continue;
                        }

                        int setLocalIndex = inCode.Read7BitEncodedInt();
                        outCode.Write7BitEncodedInt(setLocalIndex);
                        if (setLocalIndex != 11 || (++setLocal11Itterations != 2))
                        {
                            continue;
                        }

                        outCode.WriteOP(OPCode.ReturnVoid);
                        outCode.Write(inCode.ToArray(), inCode.Position,
                                      inCode.Length - inCode.Position);

                        windowContext.Constructor.Body.Bytecode = outCode.ToArray();
                        return(true);
                    }
                }
            return(false);
        }
コード例 #21
0
        public bool ReplaceRSA(int exponent, string modulus)
        {
            ABCFile abc          = ABCFiles[2];
            int     modulusIndex = abc.Constants.AddString(modulus);

            int exponentIndex = abc.Constants
                                .AddString(exponent.ToString("x"));

            int        rsaStart  = 0;
            ASInstance commClass = abc.FindInstanceByName("HabboCommunicationDemo");
            ASMethod   verifier  = FindVerifyMethod(commClass, abc, out rsaStart);

            using (var inCode = new FlashReader(verifier.Body.Bytecode))
                using (var outCode = new FlashWriter(inCode.Length))
                {
                    bool searchingKeys = true;
                    inCode.Position = rsaStart;
                    outCode.Write(inCode.ToArray(), 0, rsaStart);

                    while (inCode.Position != inCode.Length)
                    {
                        byte codeByte = inCode.ReadByte();
                        outCode.Write(codeByte);

                        if (!searchingKeys)
                        {
                            outCode.Write(inCode.ToArray(),
                                          inCode.Position, inCode.Length - inCode.Position);

                            break;
                        }
                        switch ((OPCode)codeByte)
                        {
                        case OPCode.GetLex:
                        {
                            outCode.Position--;
                            outCode.WriteOP(OPCode.PushString);

                            int         typeIndex = inCode.Read7BitEncodedInt();
                            ASMultiname type      = abc.Constants.Multinames[typeIndex];

                            inCode.ReadOP();
                            inCode.Read7BitEncodedInt();
                            inCode.Read7BitEncodedInt();

                            if (modulusIndex > 0)
                            {
                                outCode.Write7BitEncodedInt(modulusIndex);
                                modulusIndex = -1;
                            }
                            else if (searchingKeys)
                            {
                                outCode.Write7BitEncodedInt(exponentIndex);
                                searchingKeys = false;
                            }
                            break;
                        }

                        case OPCode.PushString:
                        {
                            int    stringIndex = inCode.Read7BitEncodedInt();
                            string value       = abc.Constants.Strings[stringIndex];

                            if (string.IsNullOrWhiteSpace(Modulus))
                            {
                                Modulus = value;
                                outCode.Write7BitEncodedInt(modulusIndex);
                            }
                            else if (string.IsNullOrWhiteSpace(Exponent))
                            {
                                Exponent = value;
                                outCode.Write7BitEncodedInt(exponentIndex);

                                searchingKeys = false;
                            }
                            break;
                        }

                        default: continue;
                        }
                    }

                    verifier.Body.Bytecode = outCode.ToArray();
                    if (!searchingKeys)
                    {
                        return(true);
                    }
                }
            return(false);
        }
コード例 #22
0
        public bool BypassRemoteHostCheck()
        {
            ABCFile    abc         = ABCFiles[2];
            ASInstance commManager = abc.FindInstanceByName("HabboCommunicationManager");

            if (commManager == null)
            {
                return(false);
            }

            // The "host" value is always the first slot, for now.
            string hostValueSlotName = commManager.FindTraits <SlotConstantTrait>(TraitType.Slot)
                                       .Where(t => t.Type.ObjName == "String").ToArray()[0].ObjName;

            ASMethod initComponent = commManager.FindMethod("initComponent", "void").Method;

            if (initComponent == null)
            {
                return(false);
            }

            using (var inCode = new FlashReader(initComponent.Body.Bytecode))
                using (var outCode = new FlashWriter(inCode.Length))
                {
                    int hostSlotIndex = abc.Constants.IndexOfMultiname(hostValueSlotName);
                    while (inCode.Position != inCode.Length)
                    {
                        OPCode op = inCode.ReadOP();
                        outCode.WriteOP(op);
                        if (op != OPCode.GetLocal_0)
                        {
                            continue;
                        }

                        op = inCode.ReadOP();
                        outCode.WriteOP(op);
                        if (op != OPCode.CallPropVoid)
                        {
                            continue;
                        }

                        int callPropVoidIndex = inCode.Read7BitEncodedInt();
                        outCode.Write7BitEncodedInt(callPropVoidIndex);

                        int callPropVoidArgCount = inCode.Read7BitEncodedInt();
                        outCode.Write7BitEncodedInt(callPropVoidArgCount);

                        if (callPropVoidArgCount != 0)
                        {
                            continue;
                        }

                        int getPropertyNameIndex = abc.Constants
                                                   .IndexOfMultiname("getProperty");

                        outCode.WriteOP(OPCode.GetLocal_0);
                        outCode.WriteOP(OPCode.FindPropStrict);
                        outCode.Write7BitEncodedInt(getPropertyNameIndex);

                        outCode.WriteOP(OPCode.PushString);
                        outCode.Write7BitEncodedInt(abc.Constants.AddString("connection.info.host"));

                        outCode.WriteOP(OPCode.CallProperty);
                        outCode.Write7BitEncodedInt(getPropertyNameIndex);
                        outCode.Write7BitEncodedInt(1);

                        outCode.WriteOP(OPCode.InitProperty);
                        outCode.Write7BitEncodedInt(hostSlotIndex);

                        outCode.Write(inCode.ToArray(),
                                      inCode.Position, inCode.Length - inCode.Position);

                        do
                        {
                            op = inCode.ReadOP();
                        }while (op != OPCode.CallPropVoid);

                        callPropVoidIndex = inCode.Read7BitEncodedInt();
                        ASMultiname callPropVoidName = abc.Constants.Multinames[callPropVoidIndex];
                        ASMethod    connectMethod    = commManager.FindMethod(callPropVoidName.ObjName, "void").Method;
                        RemoveHostSuffix(abc, connectMethod);

                        initComponent.Body.Bytecode = outCode.ToArray();
                        return(true);
                    }
                }
            return(false);
        }