Esempio n. 1
0
        public static CObject processStreamObject(Stream ins)
        {
            BinaryReader dis = new BinaryReader(ins);

            int code1 = dis.readUnsignedLeb128_X();

#if (PLOG)
            log("code1:" + code1, 0);
#endif
            CObject root = new CObject(code1, new byte[0], code1, null);
            root.type = code1;
            if (code1 == 8)
            {
                return(root);
            }
            bool r;
            int  i = 0;
            do
            {
                BitResult result = Parser.readCodeAndExtract(dis, 0);
                if (result == null)
                {
                    throw new Exception("Unable to process result, class code:" + code1 + ":" + result);
                }
#if (PLOG)
                log("do member " + (++i) + ": with code:" + result, 0);
#endif
                r = Parser.handleCode(root, dis, result.code, result.data, 1);
            } while (r);
            return(root);
        }
Esempio n. 2
0
        public override object convert(CObject obj)
        {
            if (obj.data == null)
            {
                return("");
            }

            return(Util.bytesToHexString(obj.data));
        }
 public override object convert(CObject obj)
 {
     if (obj.data.Length == 1)
     {
         return(long.Parse("" + getDIS(obj).ReadBoolean()));
     }
     else
     {
         return(getDIS(obj).ReadInt64());
     }
 }
Esempio n. 4
0
        public Quaternion readQuat()
        {
            CObject cObject = this;

            if (cObject.members.Count != 4)
            {
                throw new Exception("Not arrary of 4 was ary of :" + cObject.members.Count);
            }
            CFloatConvertor conv = CFloatConvertor.inst;
            float           a    = (float)conv.convert(cObject.members[0]);
            float           b    = (float)conv.convert(cObject.members[1]);
            float           c    = (float)conv.convert(cObject.members[2]);
            float           d    = (float)conv.convert(cObject.members[3]);

            return(new Quaternion(a, b, c, d));
        }
Esempio n. 5
0
        public bool getBoolMember(int i, bool defValue)
        {
            if (!hasMember(i))
            {
                return(defValue);
            }
            CObject member = getMember(i);
            object  o      = member.convert();

            if (o is bool)
            {
                return((bool)o);
            }

            return((bool)CBooleanConvertor.inst.convert(getMember(i)));
        }
Esempio n. 6
0
        internal string getStringMember(int i)
        {
            CObject member = getMember(i);

            if (member == null)
            {
                return("");
            }
            object o = member.convert();

            if (o is string)
            {
                return((string)o);
            }
            return((string)CStringConvertor.inst.convert(getMember(i)));
        }
Esempio n. 7
0
        public Dictionary <int, CObject> asDict()
        {
            if (type != 12)
            {
                throw new Exception("datatype[" + type + "] is not dictionary type 12:" + this);
            }
            Dictionary <int, CObject> dict = new Dictionary <int, CObject>();

            for (int i = 0; i < members.Count; i += 2)
            {
                int     a = getIntMember(i);
                CObject b = getMember(i + 1);
                dict[a] = b;
            }
            return(dict);
        }
Esempio n. 8
0
        public int getIntMember(int i)
        {
            CObject member = getMember(i);
            object  o      = member.convert();

            if (o is int)
            {
                return((int)o);
            }
            if (o is long)
            {
                return((int)((long)o));
            }


            return((int)CIntConvertor.inst.convert(getMember(i)));
        }
Esempio n. 9
0
        internal float getFloatMember(int i, float defaultVal)
        {
            CObject member = getMember(i);

            if (member == null)
            {
                return(defaultVal);
            }
            object o = member.convert();

            if (o is float)
            {
                return((float)o);
            }

            return((float)CFloatConvertor.inst.convert(getMember(i)));
        }
Esempio n. 10
0
        public Vector3 readVec3()
        {
            CObject cObject = this;

            if (cObject.members.Count != 3)
            {
                throw new Exception("Not arrary of 3 was ary of :" + cObject.members.Count);
            }
            CFloatConvertor conv = CFloatConvertor.inst;

            try
            {
                return(new Vector3((float)conv.convert(cObject.members[0]), (float)conv.convert(cObject.members[1]),
                                   (float)conv.convert(cObject.members[2])));
            }
            catch (Exception e)
            {
                return(new Vector3());
            }
        }
Esempio n. 11
0
 public override object convert(CObject obj)
 {
     return(getDIS(obj).readSignedVarLong(null));
 }
Esempio n. 12
0
        public static bool handleCode(CObject parent, BinaryReader dis, int datacode, int extradata, int indent)
        {
            //parent.index = codedata;
            switch (datacode)
            {
            case 0:
#if (PLOG)
                log("handleCode:" + datacode + ", possibly boolean 0", indent);
#endif
                parent.addMember(new CObject(0, new byte[] { 0x0 }, extradata, CBooleanConvertor.inst));
                return(true);

            case 1:
#if (PLOG)
                log("handleCode:" + datacode + ", possibly boolean 1", indent);
#endif
                if (parent.type == 127)
                {
                    parent.addMember(new CObject(1, new byte[] { 0x1 }, extradata, CLongConvertor.inst));
                }
                else
                {
                    parent.addMember(new CObject(1, new byte[] { 0x1 }, extradata, CBooleanConvertor.inst));
                }
                return(true);

            case 2:
            {
                // Variable length encoded long
                MemoryStream bos = new MemoryStream(20);
                long         x   = dis.readUnsignedVarLong(bos);
                parent.addMember(new CObject(2, bos, extradata, CUnsignedVarLongConvertor.inst));
#if (PLOG)
                log("handleCode:" + datacode + ", unsigned long: " + x, indent);
#endif
                return(true);
            }

            case 3:
            {
                // Variable length encoded long
                MemoryStream bos = new MemoryStream(20);
                long         x   = dis.readSignedVarLong(bos);
                parent.addMember(new CObject(3, bos, extradata, CSignedVarLongConvertor.inst));
#if (PLOG)
                log("handleCode:" + datacode + ", signed long: " + x, indent);
#endif
                return(true);
            }

            case 4:
            {
                // 4 bytes, int maybe?
#if (PLOG)
                log("handleCode:" + datacode + ", int?", indent);
#endif
                parent.addMember(new CObject(4, dis.ReadBytes(4), extradata, ClassDefaults.getConv(parent.type, 4)));
                return(true);
            }

            case 5:
                // 8 bytes, double maybe?

#if (PLOG)
                log("handleCode:" + datacode + ", long?", indent);
#endif
                byte[] d = dis.ReadBytes(8);

                if ((parent.type == 4086))
                {
                    parent.addMember(new CObject(5, d, extradata, CFileTimeConvertor.inst));
                    //parent.addMember(readFileTime(diss));
                }
                else
                {
                    parent.addMember(new CObject(5, d, extradata, CDoubleConvertor.inst));
                }
                return(true);

            case 6:
#if (PLOG)
                log("handleCode:" + datacode + ", string/data?", indent);
#endif
                // string or data
                int    strLength = dis.readUnsignedLeb128_X();
                byte[] data      = dis.ReadBytes(strLength);
                //String newString = ASCIIEncoding.ASCII.GetString(data);


                parent.addMember(new CObject(6, data, extradata, CStringConvertor.inst));

                return(true);

            case 10:
            case 9:
            {
                CObject obj = new CObject(datacode, new byte[0], extradata, null);
                parent.addMember(obj);
                obj.parent = parent;

                if (datacode == 10)
                {
                    // NEW OBJECT
                    int objclass = dis.readUnsignedLeb128_X();
                    //obj.addMember(value);

                    obj.type = objclass;
                    if (objclass > 0xFFFF || objclass == 0)
                    {
                        loge("bad value code 10", indent);
                        return(false);
                    }
                }
#if (PLOG)
                log("handleCode:" + datacode + ", array: " + obj.type, indent + 1);
#endif
                // array?
                BitResult rr;
                int       x = 0;
                do
                {
                    rr = readCodeAndExtract(dis, indent + 2);
                    if (rr == null)
                    {
                        loge("WARN: rr null for code [" + datacode + "][" + x + "], assume it is a boolean", indent);
                        // KLUDGE - Treat as a boolean
                        rr = new BitResult(0, 0);
                        //break;
                    }
                    if (rr.code == 8)
                    {
#if (PLOG)
                        log("end object, read [" + x + "], objects", indent + 1);
#endif
                        return(true);
                    }
#if (PLOG)
                    log("handle code[" + rr.code + "]", indent + 1);
#endif
                    x++;
                } while (handleCode(obj, dis, rr.code, rr.data, indent + 2));
                loge("overun while code [" + datacode + "]:" + rr, indent + 1);

                return(false);
            }

            case 11:
            {
                // array?
#if (PLOG)
                log("handlecode:" + datacode + ", get data", indent + 1);
#endif
                BitResult r = readCodeAndExtract(dis, indent + 1);
                if (r == null)
                {
                    loge("bad bitresult code 11", indent + 1);
                    return(false);
                }
#if (PLOG)
                log("bitresult:" + r, indent + 1);
#endif
                int count = r.data;
                if (count == 0)
                {
                    return(true);
                }
                int     i   = 0;
                CObject obj = new CObject(datacode, new byte[0], count, null);
                obj.hintCapacity(count);
                obj.index = extradata;
                parent.addMember(obj);

                int codeOfChildren = r.code;
#if (PLOG)
                log("array size: " + count + " of type[" + codeOfChildren + "]", indent + 1);
#endif
                while (handleCode(obj, dis, codeOfChildren, i, indent + 2))
                {
#if (PLOG)
                    log("code 11: handled  item[" + i + " of " + count + "], childcode[" + codeOfChildren + "]",
                        indent + 1);
#endif
                    if (++i >= count)
                    {
                        return(true);
                    }
                }
                loge("overun while code 11 [i == " + i + ", count=" + count, indent + 1);

                return(false);
            }

            case 12:
            {
#if (PLOG)
                log("handleCode:" + datacode + ", array3?", indent);
#endif
                int[] result = readCodeThenReadTwice(dis, indent + 1);

                int count = result[2];
                if (count == 0)
                {
                    return(true);
                }
                int     i   = 0;
                int     ii  = 0;
                CObject obj = new CObject(datacode, new byte[0], count, null);
                obj.index = extradata;
                parent.addMember(obj);
                while (handleCode(obj, dis, result[0], ii++, indent + 1) && handleCode(obj, dis, result[1], ii++, indent + 1))
                {
                    if (++i >= count)
                    {
                        return(true);
                    }
                }
                loge("overun while code 12", indent + 1);
                return(false);
            }

            case 8:
#if (PLOG)
                log("handleCode:" + datacode + ", end of object", indent);
#endif
                // END OF OBJECT
                return(false);

            default:
                loge("unk code:" + datacode, indent);
                break;
            }

            loge("exit case", indent);
            return(false);
        }
Esempio n. 13
0
 public override object convert(CObject obj)
 {
     return(Encoding.ASCII.GetString(obj.data));
 }
 public override object convert(CObject obj)
 {
     return(readFileTime(getDIS(obj)));
 }
 public override object convert(CObject obj)
 {
     return(getDIS(obj).ReadDouble());
 }
Esempio n. 16
0
 public void addMember(CObject newObj)
 {
     members.Add(newObj);
     newObj.parent = this;
 }
 public BinaryReader getDIS(CObject obj)
 {
     return(getLEDIS(obj.data));
 }
Esempio n. 18
0
 public override object convert(CObject obj)
 {
     return(getDIS(obj).ReadBoolean());
 }
 public abstract object convert(CObject obj);
Esempio n. 20
0
 public override object convert(CObject obj)
 {
     return("");
 }