예제 #1
0
 protected override void WriteValuesTo(FlashWriter output)
 {
     output.Write(DebugType);
     output.WriteInt30(NameIndex);
     output.Write(RegisterIndex);
     output.WriteInt30(Extra);
 }
예제 #2
0
파일: Program.cs 프로젝트: torylayne/Tanji
        private static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Settings = LoadSettings();
            if (args.Length > 0 && args[0].EndsWith(".swf"))
            {
                var clientInfo = new FileInfo(Path.GetFullPath(args[0]));
                using (var game = new HGame(clientInfo.FullName))
                {
                    game.Disassemble();
                    game.DisableHostChecks();
                    game.InjectKeyShouter(4001);
                    game.InjectEndPointShouter(4000);
                    game.InjectEndPoint("127.0.0.1", (int)Settings["ConnectionListenPort"]);

                    string moddedClientPath = Path.Combine(clientInfo.DirectoryName, "MOD_" + clientInfo.Name);
                    using (var fileOutput = File.Open(moddedClientPath, FileMode.Create))
                        using (var output = new FlashWriter(fileOutput))
                        {
                            game.Assemble(output, CompressionKind.ZLIB);
                        }
                    MessageBox.Show($"File has been modified/re-assembled successfully at '{moddedClientPath}'.", "Tanji - Alert!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                return;
            }

            Eavesdropper.Certifier = new CertificateManager("Tanji", "Tanji Certificate Authority");
            Eavesdropper.Overrides.AddRange(((string)Settings["ProxyOverrides"]).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));

            Application.Run(new MainFrm());
        }
예제 #3
0
파일: HGame.cs 프로젝트: Simonvdh/Tanji
 protected void ReplaceNextOperation(FlashReader inCode, FlashWriter outCode, ASMethod method, OPCode oldOP, object[] oldValues, OPCode newOP, object[] newValues)
 {
     while (inCode.IsDataAvailable)
     {
         OPCode   op     = inCode.ReadOP();
         object[] values = inCode.ReadValues(op);
         if (op != oldOP)
         {
             outCode.WriteOP(op, values);
             continue;
         }
         if (oldValues != null && (oldValues.Length == values.Length))
         {
             bool valuesMatch = true;
             for (int i = 0; i < oldValues.Length; i++)
             {
                 if (oldValues[i] != null &&
                     !oldValues[i].Equals(values[i]))
                 {
                     valuesMatch = false;
                     break;
                 }
             }
             if (!valuesMatch)
             {
                 outCode.WriteOP(op, values);
                 continue;
             }
         }
         outCode.WriteOP(newOP, newValues);
         WriteLog($"Replaced operation '{oldOP}[{string.Join(", ", oldValues)}]' with '{newOP}[{string.Join(", ", newValues)}]' in method '{method}'.");
         break;
     }
 }
예제 #4
0
        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);

                    // 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)
                        {
                            optionalParamStartIndex = i;
                        }

                        optionalParamCount++;
                        Flags |= 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++)
                {
                    ASParameter parameter = Parameters[i];
                    output.WriteInt30(parameter.ValueIndex);
                    output.Write((byte)parameter.ValueKind);
                }
            }

            if (Flags.HasFlag(MethodFlags.HasParamNames))
            {
                for (int i = 0; i < Parameters.Count; i++)
                {
                    ASParameter parameter = Parameters[i];
                    output.WriteInt30(parameter.NameIndex);
                }
            }
        }
예제 #5
0
 public byte[] ToByteArray()
 {
     using (var multinameL = new FlashWriter())
     {
         multinameL.Write7BitEncodedInt(NamespaceSetIndex);
         return(multinameL.ToArray());
     }
 }
예제 #6
0
 public byte[] ToByteArray()
 {
     using (var rtqName = new FlashWriter())
     {
         rtqName.Write7BitEncodedInt(ObjNameIndex);
         return(rtqName.ToArray());
     }
 }
예제 #7
0
 public override void WriteTo(FlashWriter output)
 {
     output.WriteInt30(From);
     output.WriteInt30(To);
     output.WriteInt30(Target);
     output.WriteInt30(ExceptionTypeIndex);
     output.WriteInt30(VariableNameIndex);
 }
예제 #8
0
 public byte[] ToByteArray()
 {
     using (var asMultiname = new FlashWriter())
     {
         asMultiname.Write((byte)MultinameType);
         asMultiname.Write(Data.ToByteArray());
         return(asMultiname.ToArray());
     }
 }
 public byte[] ToByteArray()
 {
     using (var trait = new FlashWriter())
     {
         trait.Write7BitEncodedInt(DispId);
         trait.Write7BitEncodedInt(MethodIndex);
         return(trait.ToArray());
     }
 }
예제 #10
0
 public byte[] ToArray()
 {
     using (var outputMem = new MemoryStream())
         using (var output = new FlashWriter(outputMem))
         {
             WriteTo(output);
             return(outputMem.ToArray());
         }
 }
예제 #11
0
        private void Rewrite(FlashWriter output, ASInstruction instruction, long position)
        {
            long currentPosition = output.Position;

            output.Position = position;

            instruction.WriteTo(output);
            output.Position = currentPosition;
        }
예제 #12
0
 public byte[] ToArray()
 {
     using (var memOutput = new MemoryStream(_initialLength))
         using (var output = new FlashWriter(memOutput))
         {
             WriteTo(output);
             return(memOutput.ToArray());
         }
 }
예제 #13
0
 public override void WriteTo(FlashWriter output)
 {
     output.WriteInt30(Traits.Count);
     for (int i = 0; i < Traits.Count; i++)
     {
         ASTrait trait = Traits[i];
         trait.WriteTo(output);
     }
 }
예제 #14
0
 public override void WriteTo(FlashWriter output)
 {
     output.WriteInt30(NamespaceIndices.Count);
     for (int i = 0; i < NamespaceIndices.Count; i++)
     {
         int namespaceIndex = NamespaceIndices[i];
         output.WriteInt30(namespaceIndex);
     }
 }
예제 #15
0
 public byte[] ToByteArray()
 {
     using (var trait = new FlashWriter())
     {
         trait.Write7BitEncodedInt(SlotId);
         trait.Write7BitEncodedInt(FunctionIndex);
         return(trait.ToArray());
     }
 }
예제 #16
0
 protected override void WriteTag(TagItem tag, FlashWriter output)
 {
     if (tag.Kind == TagKind.DoABC)
     {
         DoABCTag doABCTag = (DoABCTag)tag;
         doABCTag.ABCData = _abcFileTags[doABCTag].ToArray();
     }
     base.WriteTag(tag, output);
 }
예제 #17
0
 private void WriteTo <T>(FlashWriter output, Action <T> writer, List <T> constants)
 {
     output.WriteInt30(constants.Count);
     for (int i = 1; i < constants.Count; i++)
     {
         T value = constants[i];
         writer(value);
     }
 }
예제 #18
0
 public byte[] ToByteArray()
 {
     using (var asNamespace = new FlashWriter())
     {
         asNamespace.Write((byte)NamespaceType);
         asNamespace.Write7BitEncodedInt(ObjNameIndex);
         return(asNamespace.ToArray());
     }
 }
예제 #19
0
파일: HGame.cs 프로젝트: makinit/Tanji
        /// <summary>
        /// Injects the specified public RSA keys into the bytecode that handles the verification of the received primes.
        /// </summary>
        /// <param name="exponent">The public exponent.</param>
        /// <param name="modulus">The public modulus.</param>
        public void ReplaceRSAKeys(int exponent, string modulus)
        {
            ABCFile    abc = ABCFiles[2];
            ASInstance habboCommDemoInstance = abc.FindFirstInstanceByName("HabboCommunicationDemo");

            IEnumerable <MethodGetterSetterTrait> mgsTraits =
                habboCommDemoInstance.FindMethodGetterSetterTraits();

            ASMethod method          = null;
            int      rsaKeyTypeIndex = abc.Constants.IndexOfMultiname("RSAKey");

            foreach (MethodGetterSetterTrait mgsTrait in mgsTraits)
            {
                if (mgsTrait.Method.ReturnType.Name != "void")
                {
                    continue;
                }
                if (mgsTrait.Method.Parameters.Count != 1)
                {
                    continue;
                }

                if (ContainsOperation(mgsTrait.Method, OPCode.GetLex, rsaKeyTypeIndex))
                {
                    method = mgsTrait.Method;
                    WriteLog($"Found reference to 'RSAKey' in method '{method}'.");
                    break;
                }
            }

            using (var outCode = new FlashWriter())
                using (var inCode = new FlashReader(method.Body.Bytecode))
                {
                    int modulusStringIndex     = abc.Constants.AddString(modulus);
                    int exponentStringIndex    = abc.Constants.AddString(exponent.ToString("x")); // Turn the number to hex, remeber guys, (65537= 10001(hex))
                    int keyObfuscatorTypeIndex = abc.Constants.IndexOfMultiname("KeyObfuscator");

                    // Replace the first 'GetLex[KeyObfuscator]' operation with 'PushString[modulus]'.
                    ReplaceNextOperation(inCode, outCode, method,
                                         OPCode.GetLex, new object[] { keyObfuscatorTypeIndex },
                                         OPCode.PushString, new object[] { modulusStringIndex });

                    // Ignore these operations, do not write.
                    inCode.ReadValuesUntil(OPCode.CallProperty);

                    // Replace the second 'GetLex[KeyObfuscator]' operation with 'PushString[exponent]'.
                    ReplaceNextOperation(inCode, outCode, method,
                                         OPCode.GetLex, new object[] { keyObfuscatorTypeIndex },
                                         OPCode.PushString, new object[] { exponentStringIndex });

                    // Ignore these operations, do not write.
                    inCode.ReadValuesUntil(OPCode.CallProperty);

                    CopyBytecode(inCode, outCode);
                    method.Body.Bytecode = outCode.ToArray();
                }
        }
예제 #20
0
 public byte[] ToArray(CompressionKind compression)
 {
     using (var outputMem = new MemoryStream((int)FileLength))
         using (var output = new FlashWriter(outputMem))
         {
             Assemble(output, compression);
             return(outputMem.ToArray());
         }
 }
예제 #21
0
        protected override void WriteBodyTo(FlashWriter output)
        {
            output.Write((ushort)Entries.Count);

            foreach (var pair in Entries)
            {
                output.Write(pair.Item1);
                output.WriteNullString(pair.Item2);
            }
        }
예제 #22
0
 public override void WriteTo(FlashWriter output)
 {
     output.WriteInt30(NameIndex);
     output.WriteInt30(Items.Count);
     for (int i = 0; i < Items.Count; i++)
     {
         ASItemInfo item = Items[i];
         item.WriteTo(output);
     }
 }
예제 #23
0
 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);
 }
예제 #24
0
 protected override void WriteValuesTo(FlashWriter output)
 {
     output.WriteUInt24(DefaultOffset);
     output.WriteInt30(CaseOffsets.Count - 1);
     for (int i = 0; i < CaseOffsets.Count; i++)
     {
         uint offset = CaseOffsets[i];
         output.WriteUInt24(offset);
     }
 }
예제 #25
0
        protected override void WriteTag(TagItem tag, FlashWriter output)
        {
            if (tag.Kind == TagKind.DoABC)
            {
                var abcTag = (DoABCTag)tag;
                abcTag.ABCData = AbcTagFiles[abcTag].ToArray();
            }

            base.WriteTag(tag, output);
        }
예제 #26
0
 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);
 }
예제 #27
0
        protected override byte[] OnConstruct()
        {
            using (var tag = new FlashWriter(4))
            {
                tag.Write(MaxRecursionDepth);
                tag.Write(ScriptTimeoutSeconds);

                return(tag.ToArray());
            }
        }
예제 #28
0
        public override void WriteTo(FlashWriter output)
        {
            output.Write((byte)Kind);
            switch (Kind)
            {
            case MultinameKind.QName:
            case MultinameKind.QNameA:
            {
                output.WriteInt30(NamespaceIndex);
                output.WriteInt30(NameIndex);
                break;
            }

            case MultinameKind.RTQName:
            case MultinameKind.RTQNameA:
            {
                output.WriteInt30(NameIndex);
                break;
            }

            case MultinameKind.RTQNameL:
            case MultinameKind.RTQNameLA:
            {
                /* No data. */
                break;
            }

            case MultinameKind.Multiname:
            case MultinameKind.MultinameA:
            {
                output.WriteInt30(NameIndex);
                output.WriteInt30(NamespaceSetIndex);
                break;
            }

            case MultinameKind.MultinameL:
            case MultinameKind.MultinameLA:
            {
                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);
                }
                break;
            }
            }
        }
예제 #29
0
        protected override byte[] OnConstruct()
        {
            using (var tag = new FlashWriter())
            {
                tag.Write(Flags);
                tag.WriteNullTerminatedString(Name);
                tag.Write(ABC.ToByteArray());

                return(tag.ToArray());
            }
        }
예제 #30
0
파일: HGame.cs 프로젝트: makinit/Tanji
        protected void ReplaceNextOperation(ASMethod method, OPCode oldOP, object[] oldValues, OPCode newOP, object[] newValues)
        {
            using (var outCode = new FlashWriter())
                using (var inCode = new FlashReader(method.Body.Bytecode))
                {
                    ReplaceNextOperation(inCode, outCode, method, oldOP, oldValues, newOP, newValues);

                    CopyBytecode(inCode, outCode);
                    method.Body.Bytecode = outCode.ToArray();
                }
        }