Ejemplo n.º 1
0
        public void Get <T>(long structRVA, ref T destination, PtrType ptrType = PtrType.VA)
        {
            long structPtr = Resolve(structRVA, ptrType);

            Seek(structPtr, SeekOrigin.Begin);

            Get(this, ref destination);
        }
Ejemplo n.º 2
0
        //public string GetASCIIStr(int size = -1)
        //{
        //    if (size == -1)
        //        size = Get<ushort>();

        //    if (size == 0)
        //        return string.Empty;

        //    // Read in a byte array
        //    byte[] bytes = Reader.ReadBytes(size);

        //    byte zero = Reader.ReadByte();

        //    return Encoding.ASCII.GetString(bytes);
        //}


        //public string GetStr(int size = -1, Encoding encoding = null)
        //{
        //    if (encoding == null)
        //        encoding = Encoding.ASCII;

        //    if (size == -1)
        //        size = Get<ushort>();

        //    // Read in a byte array
        //    byte[] bytes = Reader.ReadBytes(size + 1);

        //    return encoding.GetString(bytes);
        //}

        public string GetStr(
            long ptr,
            PtrType ptrType,
            int size            = -1,
            Encoding encoding   = null,
            bool nullTerminated = false)
        {
            Seek(Resolve(ptr, ptrType), SeekOrigin.Begin);

            return(GetStr(size, encoding, nullTerminated));
        }
Ejemplo n.º 3
0
        public T[] GetArrayOf <T>(long ptr, int count, PtrType ptrType = PtrType.VA)
        {
            if (ptr == 0)
            {
                return(new T[0]);
            }

            Seek(Resolve(ptr, ptrType), SeekOrigin.Begin);

            return(GetArrayOf <T>(count));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts template types to Object type (useful for inline methods and template specialization types)
        /// </summary>
        /// <param name="type"></param>
        /// <param name="newType"></param>
        /// <returns>Returns if the type is actually changed or not</returns>
        public static bool TryPatchTemplateToObjectType(AstType type, out AstType newType)
        {
            newType = (AstType)type.Clone();
            string name = "";
            if (type is SimpleType)
            {
                SimpleType st = type as SimpleType;
                name = st.Identifier;
                if (Cache.GetTemplateTypes().Contains(name))
                {
                    newType = new SimpleType("Object");
                    return true;
                }
                else
                {
                    if (st.TypeArguments.Any())
                    {
                        List<AstType> args = new List<AstType>();
                        bool converted = false;
                        foreach (AstType t in st.TypeArguments)
                        {
                            AstType discard;
                            if (TryPatchTemplateToObjectType(t, out discard))
                            {
                                converted = true;
                                args.Add(new SimpleType("Object"));
                            }
                            else
                                args.Add((AstType)t.Clone());
                        }

                        SimpleType nType = (SimpleType)st.Clone();
                        nType.TypeArguments.Clear();
                        nType.TypeArguments.AddRange(args.ToArray());
                        newType = nType;
                        return converted;
                    }
                }
            }
            if (type is PtrType)
            {
                if ((type as PtrType).Target is SimpleType)
                {
                    SimpleType pst = (type as PtrType).Target as SimpleType;
                    AstType tmp;
                    bool converted = TryPatchTemplateToObjectType(pst, out tmp);
                    newType = new PtrType(tmp);
                    return converted;
                }
            }

            return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads in a block from a file and converts it to the struct
        /// type specified by the template parameter
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="structRVA"></param>
        /// <returns></returns>
        public T Get <T>(long structRVA, PtrType ptrType = PtrType.VA)
        {
            long structPtr = Resolve(structRVA, ptrType);

            return(FromBinaryReaderFromPtr <T>(this, structPtr));
        }
Ejemplo n.º 6
0
 public Guid VGetGuid(long structRVA, PtrType ptrType = PtrType.VA)
 {
     return(RGetGuid(Resolve(structRVA, ptrType)));
 }
Ejemplo n.º 7
0
 public abstract long Resolve(long virtAddress, PtrType ptrType = PtrType.VA);
Ejemplo n.º 8
0
        public string VGetStr(long structRVA, Encoding encoding = null, PtrType ptrType = PtrType.VA)
        {
            var ptr = Resolve(structRVA, ptrType);

            return(RGetStr(ptr, encoding ?? Encoding.ASCII));
        }