Exemple #1
0
        public static void DumpOpUntilError(byte[] code)
        {
            uint i = 0;
            uint n = (uint)code.Length;
            uint j = 0;

            while (i < n)
            {
                AVM2Command command = null;

                uint index = i;

                try
                {
                    command = Translator.ToCommand(code[i++]);
                }
                catch (Exception)
                {
                    Console.WriteLine("[-] Error occured at index {0}", index);
                    break;
                }

                i += command.ReadParameters(code, i);

                Console.WriteLine("[i] [0x{1:x4},{1:D4},#{2:D4}]: {0}", command.StringRepresentation, index, j++);
            }
        }
Exemple #2
0
        public AVM2Command Clone()
        {
            AVM2Command clone = new AVM2Command(_stringRepresentation, _inlineName, _opCode, _parameterCount, _types);

            clone._parameters = (ArrayList)_parameters.Clone();

            return(clone);
        }
Exemple #3
0
 protected uint GetUInt(AVM2Command cmd, int paramIndex)
 {
     return ((U32)_abc.ConstantPool.UIntTable[(int)((U30)cmd.Parameters[paramIndex]).Value]).Value;
 }
Exemple #4
0
 protected StringInfo GetString(AVM2Command cmd, int paramIndex)
 {
     return (StringInfo)(_abc.ConstantPool.StringTable[(int)((U30)cmd.Parameters[paramIndex]).Value]);
 }
Exemple #5
0
 protected NamespaceInfo GetNamespace(AVM2Command cmd, int paramIndex)
 {
     return (NamespaceInfo)(_abc.ConstantPool.NamespaceTable[(int)((U30)cmd.Parameters[paramIndex]).Value]);
 }
Exemple #6
0
 protected MultinameInfo GetMultiname(AVM2Command cmd, int paramIndex)
 {
     return (MultinameInfo)(_abc.ConstantPool.MultinameTable[(int)((U30)cmd.Parameters[paramIndex]).Value]);
 }
Exemple #7
0
 protected MethodInfo GetMethod(AVM2Command cmd, int paramIndex)
 {
     return (MethodInfo)_abc.Methods[(int)((U30)cmd.Parameters[paramIndex]).Value];
 }
Exemple #8
0
 protected double GetDouble(AVM2Command cmd, int paramIndex)
 {
     return (double)_abc.ConstantPool.DoubleTable[(int)((U30)cmd.Parameters[paramIndex]).Value];
 }
Exemple #9
0
        protected void FormatCommand(uint address, AVM2Command cmd)
        {
            string output = "";

            //output += String.Format("{0:X4}\t", address);

            //output += String.Format("{0}\t", address);

            if (((byte)Op.Label == cmd.OpCode) || _labels.IsMarked(address))
            {
                output += String.Format("\r\n.label{0}:\r\n", _labels.GetLabelAt(address).id);
            }

            output += "\t" + cmd.StringRepresentation + "\t\t";

            if (cmd.StringRepresentation.Length < 8)
                output += "\t";

            int n = cmd.Parameters.Count;
            int m = n - 1;

            switch (cmd.OpCode)
            {
                // Param 1: U30 -> Multiname
                case (byte)Op.AsType:
                case (byte)Op.Coerce:
                case (byte)Op.DeleteProperty:
                case (byte)Op.FindProperty:
                case (byte)Op.FindPropertyStrict:
                case (byte)Op.GetDescendants:
                case (byte)Op.GetLex:

                case (byte)Op.GetSuper:
                case (byte)Op.InitProperty:
                case (byte)Op.IsType:
                case (byte)Op.SetProperty:
                    output += NameUtil.ResolveMultiname(_abc, GetMultiname(cmd, 0));
                    break;

                case (byte)Op.GetProperty:
                    output += NameUtil.ResolveMultiname(_abc, GetMultiname(cmd, 0));
                    break;

                // Param 1: U30 -> Multiname
                // Param 2: Param count
                case (byte)Op.CallProperty:
                case (byte)Op.CallPropertyLex:
                case (byte)Op.CallPropertyVoid:
                case (byte)Op.CallSuper:
                case (byte)Op.CallSuperVoid:
                case (byte)Op.ConstructProperty:
                    output += NameUtil.ResolveMultiname(_abc, GetMultiname(cmd, 0));
                    output += ", " + ((U30)cmd.Parameters[1]).Value.ToString();
                    break;

                // Param 1: U30 -> MethodInfo
                // Param 2: Param count
                case (byte)Op.CallStatic:
                    output += ((StringInfo)(_abc.ConstantPool.StringTable[(int)GetMethod(cmd, 0).Name.Value])).ToString();
                    output += ", " + ((U30)cmd.Parameters[1]).Value.ToString();
                    break;

                // Param 1: U30 -> InstanceInfo
                case (byte)Op.NewClass:
                    InstanceInfo ii = (InstanceInfo)_abc.Instances[(int)((U30)cmd.Parameters[0]).Value];
                    output += NameUtil.ResolveClass(_abc, ii);
                    break;

                // Param 1: ?
                case (byte)Op.PushNamespace:
                    output += GetNamespace(cmd, 0);
                    break;

                // Param 1: U30 -> DoubleTable
                case (byte)Op.PushDouble:
                    //TODO fix this and do not use replace...
                    output += GetDouble(cmd, 0).ToString().Replace(',', '.');
                    break;

                // Param 1: U30 -> IntTable
                case (byte)Op.PushInt:
                    output += GetInt(cmd, 0);
                    break;

                // Param 1: U30 -> UIntTable
                case (byte)Op.PushUInt:
                    output += GetUInt(cmd, 0);
                    break;

                // Param 1: U30 -> StringTable
                case (byte)Op.DebugFile:
                case (byte)Op.PushString:
                    output += '"' + GetString(cmd, 0).ToString() + '"';
                    break;

                // Param 1: ?
                case (byte)Op.NewFunction:
                    output += ((U30)cmd.Parameters[0]).Value + " ;call to anonymous method " + ((U30)cmd.Parameters[0]).Value;
                    break;

                // Param 1: S24 -> Jump Offset
                case (byte)Op.IfEqual:
                case (byte)Op.IfFalse:
                case (byte)Op.IfGreaterEqual:
                case (byte)Op.IfGreaterThan:
                case (byte)Op.IfLessEqual:
                case (byte)Op.IfLowerThan:
                case (byte)Op.IfNotEqual:
                case (byte)Op.IfNotGreaterEqual:
                case (byte)Op.IfNotGreaterThan:
                case (byte)Op.IfNotLowerEqual:
                case (byte)Op.IfNotLowerThan:
                case (byte)Op.IfStrictEqual:
                case (byte)Op.IfStrictNotEqual:
                case (byte)Op.IfTrue:
                case (byte)Op.Jump:
                    S24 offset = (S24)cmd.Parameters[0];
                    // addr + (1byte opcode) + (offset byte length) + (offset value)
                    output += String.Format(".label{0}", _labels.GetLabelAt((uint)(address + 1 + offset.Length + offset.Value)).id) + "\r\n";
                    break;
                case (byte)Op.LookupSwitch:
                    S24 defaultLabel = (S24)cmd.Parameters[0];
                    U30 count = (U30)cmd.Parameters[1];

                    output += String.Format(".label{0}", _labels.GetLabelAt((uint)(address + defaultLabel.Value)).id) + ", ";

                    for (int i = 0, o = (int)count.Value+1; i < o; ++i)
                    {
                        S24 offsetLabel = (S24)cmd.Parameters[2 + i];

                        output += String.Format(".label{0}", _labels.GetLabelAt((uint)(address + offsetLabel.Value)).id);

                        if (i != o - 1)
                        {
                            output += ", ";
                        }
                    }

                    output += "\r\n";

                    break;

                default:
                    for (int i = 0; i < n; ++i)
                    {
                        object t = cmd.Parameters[i];

                        if (t is byte) { output += String.Format("{0}", (byte)t); }
                        else if (t is S24) { output += String.Format("{0}", ((S24)t).Value); }
                        else if (t is U30) { output += String.Format("{0}", ((U30)t).Value); }
                        else if (t is U32) { output += String.Format("{0}", ((U32)t).Value); }

                        if (i != m)
                            output += ", ";
                    }
                    break;
            }

            output += "\r\n";

            _output.Add(output);
        }
Exemple #10
0
        public AVM2Command Clone()
        {
            AVM2Command clone = new AVM2Command(_stringRepresentation, _inlineName, _opCode, _parameterCount, _types);
            clone._parameters = (ArrayList)_parameters.Clone();

            return clone;
        }
Exemple #11
0
        protected void FormatCommand(uint address, AVM2Command cmd)
        {
            string output = "";

            output += String.Format("{0:X4}\t", address);
            output += cmd.StringRepresentation + "\t\t";

            if (cmd.StringRepresentation.Length < 8)
                output += "\t";

            int n = cmd.Parameters.Count;
            int m = n - 1;

            for (int i = 0; i < n; ++i)
            {
                object t = cmd.Parameters[i];

                if (t is byte) { output += String.Format("{0}", (byte)t); }
                else if (t is S24) { output += String.Format("{0}", ((S24)t).Value); }
                else if (t is U30) { output += String.Format("{0}", ((U30)t).Value); }
                else if (t is U32) { output += String.Format("{0}", ((U30)t).Value); }

                if (i != m)
                    output += ", ";
            }

            output += "\r\n";

            _output.Add(output);
        }