예제 #1
0
        public override GetValueResult GetValue(string fileName, int fieldIndex, int unitIndex,
                                                int maxLen, GetValueFlags flags, out string fieldValue, out ContentFieldType fieldType)
        {
            _getAborted = false;
            fieldType   = ContentFieldType.NoMoreFields;
            fieldValue  = null;

            if (string.IsNullOrEmpty(fileName))
            {
                return(GetValueResult.FieldEmpty);
            }

            if (fieldIndex < 0 || fieldIndex > FieldCount - 1)
            {
                return(GetValueResult.NoSuchField);
            }

            var field = Fields[fieldIndex];

            if (null == field)
            {
                return(GetValueResult.NoSuchField);
            }

            fieldType = field.ContentType;

            var res = field.GetValue(fileName, flags, ref _getAborted);

            fieldValue = res.Value;

            return(res.Result);
        }
예제 #2
0
 private static string IncludeObjectId(DkmClrValue value, string valueStr, GetValueFlags flags)
 {
     Debug.Assert(valueStr != null);
     return((flags & GetValueFlags.IncludeObjectId) == 0 ?
            valueStr :
            value.IncludeObjectId(valueStr));
 }
예제 #3
0
        public override ValueResult GetValue(string fileName, GetValueFlags flags, ref bool getAborted)
        {
            if (Directory.Exists(fileName))
            {
                if ((flags & GetValueFlags.DelayIfSlow) != 0)
                {
                    return(ValueResult.OnDemand("?"));
                }

                try
                {
                    long size = GetDirectorySize(fileName, ref getAborted);
                    return(ValueResult.Success(GetSizeValue(size)));
                } catch (IOException)
                {
                    // Directory changed, stop long operation
                    return(ValueResult.FieldEmpty());
                }
            }

            if (File.Exists(fileName))
            {
                var info = new FileInfo(fileName);
                return(ValueResult.Success(GetSizeValue(info.Length)));
            }

            return(new ValueResult {
                Result = GetValueResult.FileError, Value = string.Empty
            });
        }
예제 #4
0
        public static int GetValueW([MarshalAs(UnmanagedType.LPWStr)] string fileName,
                                    int fieldIndex, int unitIndex, IntPtr fieldValue, int maxLen, int flags)
        {
            GetValueResult   result;
            ContentFieldType fieldType = ContentFieldType.NoMoreFields;
            GetValueFlags    gvFlags   = (GetValueFlags)flags;

            callSignature = String.Format("ContentGetValue '{0}' ({1}/{2}/{3})",
                                          fileName, fieldIndex, unitIndex, gvFlags.ToString());
            try {
                string fieldValueStr;
                // TODO: add - comments where .NET plugin interface differs from TC
                result = Plugin.GetValue(fileName, fieldIndex, unitIndex,
                                         maxLen, gvFlags, out fieldValueStr, out fieldType);
                if (result == GetValueResult.Success ||
                    result == GetValueResult.Delayed ||
                    result == GetValueResult.OnDemand)
                {
                    ContentFieldType resultType =
                        result == GetValueResult.Success ? fieldType : ContentFieldType.WideString;
                    (new ContentValue(fieldValueStr, resultType)).CopyTo(fieldValue);
                }

                // !!! may produce much trace info !!!
                TraceCall(TraceLevel.Verbose, String.Format("{0} - {1}", result.ToString(), fieldValueStr));
            } catch (Exception ex) {
                ProcessException(ex);
                result = GetValueResult.NoSuchField;
            }
            return(result == GetValueResult.Success ? (int)fieldType : (int)result);
        }
예제 #5
0
        public override ValueResult GetValue(string fileName, GetValueFlags flags, ref bool getAborted)
        {
            if (Directory.Exists(fileName))
            {
                return(ValueResult.Success("Folder"));
            }

            if (File.Exists(fileName))
            {
                var info = new FileInfo(fileName);

                string fileType;
                switch (info.Extension.ToLower())
                {
                case ".exe":
                case ".dll":
                case ".sys":
                case ".com":
                    fileType = "Program";
                    break;

                case ".zip":
                case ".rar":
                case ".cab":
                case ".7z":
                    fileType = "Archive";
                    break;

                case ".bmp":
                case ".jpg":
                case ".png":
                case ".gif":
                    fileType = "Image";
                    break;

                case ".mp3":
                case ".avi":
                case ".wav":
                    fileType = "Multimedia";
                    break;

                case ".htm":
                case ".html":
                    fileType = "Web Page";
                    break;

                default:
                    fileType = "File";
                    break;
                }
                return(ValueResult.Success(fileType));
            }

            return(new ValueResult {
                Result = GetValueResult.FileError, Value = string.Empty
            });
        }
예제 #6
0
        public override ValueResult GetValue(string fileName, GetValueFlags flags, ref bool getAborted)
        {
            if (Directory.Exists(fileName))
            {
                var    info       = new DirectoryInfo(fileName);
                string timeString = info.CreationTime.ToString("G");
                return(ValueResult.Success(timeString));
            }

            if (File.Exists(fileName))
            {
                var    info       = new FileInfo(fileName);
                string timeString = info.CreationTime.ToString("G");
                return(ValueResult.Success(timeString));
            }

            return(ValueResult.FileError());
        }
예제 #7
0
        internal string GetValueString(DkmClrValue value, ObjectDisplayOptions options, GetValueFlags flags)
        {
            if (value.IsError())
            {
                return((string)value.HostObjectValue);
            }

            if (UsesHexadecimalNumbers(value))
            {
                options |= ObjectDisplayOptions.UseHexadecimalNumbers;
            }

            var lmrType = value.Type.GetLmrType();

            if (IsPredefinedType(lmrType) && !lmrType.IsObject())
            {
                if (lmrType.IsString())
                {
                    var stringValue = (string)value.HostObjectValue;
                    if (stringValue == null)
                    {
                        return(_nullString);
                    }
                    return(IncludeObjectId(
                               value,
                               FormatString(stringValue, options),
                               flags));
                }
                else if (lmrType.IsCharacter())
                {
                    return(IncludeObjectId(
                               value,
                               FormatLiteral((char)value.HostObjectValue, options | ObjectDisplayOptions.IncludeCodePoints),
                               flags));
                }
                else
                {
                    return(IncludeObjectId(
                               value,
                               FormatPrimitive(value, options & ~ObjectDisplayOptions.UseQuotes),
                               flags));
                }
            }
            else if (value.IsNull && !lmrType.IsPointer)
            {
                return(_nullString);
            }
            else if (lmrType.IsEnum)
            {
                return(IncludeObjectId(
                           value,
                           GetEnumDisplayString(lmrType, value, options, (flags & GetValueFlags.IncludeTypeName) != 0),
                           flags));
            }
            else if (lmrType.IsArray)
            {
                return(IncludeObjectId(
                           value,
                           GetArrayDisplayString(lmrType, value.ArrayDimensions, value.ArrayLowerBounds, options),
                           flags));
            }
            else if (lmrType.IsPointer)
            {
                // NOTE: the HostObjectValue will have a size corresponding to the process bitness
                // and FormatPrimitive will adjust accordingly.
                var tmp = FormatPrimitive(value, ObjectDisplayOptions.UseHexadecimalNumbers); // Always in hex.
                Debug.Assert(tmp != null);
                return(tmp);
            }
            else if (lmrType.IsNullable())
            {
                var nullableValue = value.GetNullableValue();
                // It should be impossible to nest nullables, so this recursion should introduce only a single extra stack frame.
                return(nullableValue == null
                    ? _nullString
                    : GetValueString(nullableValue, ObjectDisplayOptions.None, GetValueFlags.IncludeTypeName));
            }

            // "value.EvaluateToString()" will check "Call string-conversion function on objects in variables windows"
            // (Tools > Options setting) and call "value.ToString()" if appropriate.
            return(IncludeObjectId(
                       value,
                       string.Format(_defaultFormat, value.EvaluateToString() ?? value.InspectionContext.GetTypeName(value.Type)),
                       flags));
        }
예제 #8
0
        public override ValueResult GetValue(string fileName, GetValueFlags flags, ref bool getAborted)
        {
            var info = new FileInfo(fileName);

            return(ValueResult.Success(ReplaceDates(info.Name)));
        }
 private static string IncludeObjectId(DkmClrValue value, string valueStr, GetValueFlags flags)
 {
     Debug.Assert(valueStr != null);
     return (flags & GetValueFlags.IncludeObjectId) == 0 ?
         valueStr :
         value.IncludeObjectId(valueStr);
 }
        internal string GetValueString(DkmClrValue value, DkmInspectionContext inspectionContext, ObjectDisplayOptions options, GetValueFlags flags)
        {
            if (value.IsError())
            {
                return (string)value.HostObjectValue;
            }

            if (UsesHexadecimalNumbers(inspectionContext))
            {
                options |= ObjectDisplayOptions.UseHexadecimalNumbers;
            }

            var lmrType = value.Type.GetLmrType();
            if (IsPredefinedType(lmrType) && !lmrType.IsObject())
            {
                if (lmrType.IsString())
                {
                    var stringValue = (string)value.HostObjectValue;
                    if (stringValue == null)
                    {
                        return _nullString;
                    }
                    return IncludeObjectId(
                        value,
                        FormatString(stringValue, options),
                        flags);
                }
                else if (lmrType.IsCharacter())
                {
                    return IncludeObjectId(
                        value,
                        FormatLiteral((char)value.HostObjectValue, options | ObjectDisplayOptions.IncludeCodePoints),
                        flags);
                }
                else
                {
                    return IncludeObjectId(
                        value,
                        FormatPrimitive(value, options & ~ObjectDisplayOptions.UseQuotes, inspectionContext),
                        flags);
                }
            }
            else if (value.IsNull && !lmrType.IsPointer)
            {
                return _nullString;
            }
            else if (lmrType.IsEnum)
            {
                return IncludeObjectId(
                    value,
                    GetEnumDisplayString(lmrType, value, options, (flags & GetValueFlags.IncludeTypeName) != 0, inspectionContext),
                    flags);
            }
            else if (lmrType.IsArray)
            {
                return IncludeObjectId(
                    value,
                    GetArrayDisplayString(lmrType, value.ArrayDimensions, value.ArrayLowerBounds, options),
                    flags);
            }
            else if (lmrType.IsPointer)
            {
                // NOTE: the HostObjectValue will have a size corresponding to the process bitness
                // and FormatPrimitive will adjust accordingly.
                var tmp = FormatPrimitive(value, ObjectDisplayOptions.UseHexadecimalNumbers, inspectionContext); // Always in hex.
                Debug.Assert(tmp != null);
                return tmp;
            }
            else if (lmrType.IsNullable())
            {
                var nullableValue = value.GetNullableValue(inspectionContext);
                // It should be impossible to nest nullables, so this recursion should introduce only a single extra stack frame.
                return nullableValue == null
                    ? _nullString
                    : GetValueString(nullableValue, inspectionContext, ObjectDisplayOptions.None, GetValueFlags.IncludeTypeName);
            }

            // "value.EvaluateToString()" will check "Call string-conversion function on objects in variables windows"
            // (Tools > Options setting) and call "value.ToString()" if appropriate.
            return IncludeObjectId(
                value,
                string.Format(_defaultFormat, value.EvaluateToString(inspectionContext) ?? inspectionContext.GetTypeName(value.Type, CustomTypeInfo: null, FormatSpecifiers: NoFormatSpecifiers)),
                flags);
        }
예제 #11
0
        private string GetValueString(
            DkmClrValue value,
            DkmInspectionContext inspectionContext,
            ObjectDisplayOptions options,
            GetValueFlags flags
            )
        {
            if (value.IsError())
            {
                return((string)value.HostObjectValue);
            }

            if (UsesHexadecimalNumbers(inspectionContext))
            {
                options |= ObjectDisplayOptions.UseHexadecimalNumbers;
            }

            var lmrType = value.Type.GetLmrType();

            if (IsPredefinedType(lmrType) && !lmrType.IsObject())
            {
                if (lmrType.IsString())
                {
                    var stringValue = (string)value.HostObjectValue;
                    if (stringValue == null)
                    {
                        return(_nullString);
                    }
                    return(IncludeObjectId(value, FormatString(stringValue, options), flags));
                }
                else if (lmrType.IsCharacter())
                {
                    // check if HostObjectValue is null, since any of these types might actually be a synthetic value as well.
                    if (value.HostObjectValue == null)
                    {
                        return(_hostValueNotFoundString);
                    }

                    return(IncludeObjectId(
                               value,
                               FormatLiteral(
                                   (char)value.HostObjectValue,
                                   options | ObjectDisplayOptions.IncludeCodePoints
                                   ),
                               flags
                               ));
                }
                else
                {
                    return(IncludeObjectId(
                               value,
                               FormatPrimitive(
                                   value,
                                   options
                                   & ~(
                                       ObjectDisplayOptions.UseQuotes
                                       | ObjectDisplayOptions.EscapeNonPrintableCharacters
                                       ),
                                   inspectionContext
                                   ),
                               flags
                               ));
                }
            }
            else if (value.IsNull && !lmrType.IsPointer)
            {
                return(_nullString);
            }
            else if (lmrType.IsEnum)
            {
                return(IncludeObjectId(
                           value,
                           GetEnumDisplayString(
                               lmrType,
                               value,
                               options,
                               (flags & GetValueFlags.IncludeTypeName) != 0,
                               inspectionContext
                               ),
                           flags
                           ));
            }
            else if (lmrType.IsArray)
            {
                return(IncludeObjectId(
                           value,
                           GetArrayDisplayString(
                               value.Type.AppDomain,
                               lmrType,
                               value.ArrayDimensions,
                               value.ArrayLowerBounds,
                               options
                               ),
                           flags
                           ));
            }
            else if (lmrType.IsPointer)
            {
                // NOTE: the HostObjectValue will have a size corresponding to the process bitness
                // and FormatPrimitive will adjust accordingly.
                var tmp = FormatPrimitive(
                    value,
                    ObjectDisplayOptions.UseHexadecimalNumbers,
                    inspectionContext
                    ); // Always in hex.
                Debug.Assert(tmp != null);
                return(tmp);
            }
            else if (lmrType.IsNullable())
            {
                var nullableValue = value.GetNullableValue(inspectionContext);
                // It should be impossible to nest nullables, so this recursion should introduce only a single extra stack frame.
                return(nullableValue == null
                  ? _nullString
                  : GetValueString(
                           nullableValue,
                           inspectionContext,
                           ObjectDisplayOptions.None,
                           GetValueFlags.IncludeTypeName
                           ));
            }
            else if (lmrType.IsIntPtr())
            {
                // check if HostObjectValue is null, since any of these types might actually be a synthetic value as well.
                if (value.HostObjectValue == null)
                {
                    return(_hostValueNotFoundString);
                }

                if (IntPtr.Size == 8)
                {
                    var intPtr = ((IntPtr)value.HostObjectValue).ToInt64();
                    return(FormatPrimitiveObject(
                               intPtr,
                               ObjectDisplayOptions.UseHexadecimalNumbers
                               ));
                }
                else
                {
                    var intPtr = ((IntPtr)value.HostObjectValue).ToInt32();
                    return(FormatPrimitiveObject(
                               intPtr,
                               ObjectDisplayOptions.UseHexadecimalNumbers
                               ));
                }
            }
            else if (lmrType.IsUIntPtr())
            {
                // check if HostObjectValue is null, since any of these types might actually be a synthetic value as well.
                if (value.HostObjectValue == null)
                {
                    return(_hostValueNotFoundString);
                }

                if (UIntPtr.Size == 8)
                {
                    var uIntPtr = ((UIntPtr)value.HostObjectValue).ToUInt64();
                    return(FormatPrimitiveObject(
                               uIntPtr,
                               ObjectDisplayOptions.UseHexadecimalNumbers
                               ));
                }
                else
                {
                    var uIntPtr = ((UIntPtr)value.HostObjectValue).ToUInt32();
                    return(FormatPrimitiveObject(
                               uIntPtr,
                               ObjectDisplayOptions.UseHexadecimalNumbers
                               ));
                }
            }
            else
            {
                int cardinality;
                if (lmrType.IsTupleCompatible(out cardinality) && (cardinality > 1))
                {
                    var values = ArrayBuilder <string> .GetInstance();

                    if (value.TryGetTupleFieldValues(cardinality, values, inspectionContext))
                    {
                        return(IncludeObjectId(
                                   value,
                                   GetTupleExpression(values.ToArrayAndFree()),
                                   flags
                                   ));
                    }
                    values.Free();
                }
            }

            // "value.EvaluateToString()" will check "Call string-conversion function on objects in variables windows"
            // (Tools > Options setting) and call "value.ToString()" if appropriate.
            return(IncludeObjectId(
                       value,
                       string.Format(
                           _defaultFormat,
                           value.EvaluateToString(inspectionContext)
                           ?? inspectionContext.GetTypeName(
                               value.Type,
                               CustomTypeInfo: null,
                               FormatSpecifiers: NoFormatSpecifiers
                               )
                           ),
                       flags
                       ));
        }
예제 #12
0
 public abstract ValueResult GetValue(string fileName, GetValueFlags flags, ref bool getAborted);
예제 #13
0
        public override GetValueResult GetValue(string fileName, int fieldIndex, int unitIndex,
                                                int maxLen, GetValueFlags flags, out string fieldValue, out ContentFieldType fieldType)
        {
            GetValueResult result = GetValueResult.FieldEmpty;

            fieldType  = ContentFieldType.NoMoreFields;
            fieldValue = null;
            if (String.IsNullOrEmpty(fileName))
            {
                return(result);
            }
            if (Directory.Exists(fileName))
            {
                DirectoryInfo info      = new DirectoryInfo(fileName);
                string        createdDT = info.CreationTime.ToString("G");
                switch (fieldIndex)
                {
                case FileTypeIdx:
                    fieldValue = "Folder";
                    fieldType  = ContentFieldType.WideString;
                    break;

                case Size32Idx:
                    if ((flags & GetValueFlags.DelayIfSlow) != 0)
                    {
                        fieldValue = "?";
                        result     = GetValueResult.OnDemand;
                    }
                    else
                    {
                        try {
                            long size = GetDirectorySize(fileName);
                            fieldType  = ContentFieldType.NumericFloating;
                            fieldValue = GetSizeValue(size);
                        } catch (IOException) {
                            // Directory changed, stop long operation
                            result = GetValueResult.FieldEmpty;
                        }
                    }
                    break;

                case CreateDateTimeIdx:
                    fieldValue = createdDT;
                    fieldType  = ContentFieldType.DateTime;
                    break;

                case CreateDateIdx:
                    fieldValue = createdDT;
                    fieldType  = ContentFieldType.Date;
                    break;

                case CreateTimeIdx:
                    fieldValue = createdDT;
                    fieldType  = ContentFieldType.Time;
                    break;

                default:
                    result = GetValueResult.NoSuchField;
                    break;
                }
            }
            else if (File.Exists(fileName))
            {
                FileInfo info      = new FileInfo(fileName);
                string   createdDT = info.CreationTime.ToString("G");
                switch (fieldIndex)
                {
                case FileTypeIdx:
                    string fileType = String.Empty;
                    switch (info.Extension.ToLower())
                    {
                    case ".exe":
                    case ".dll":
                    case ".sys":
                    case ".com":
                        fileType = "Program";
                        break;

                    case ".zip":
                    case ".rar":
                    case ".cab":
                    case ".7z":
                        fileType = "Archive";
                        break;

                    case ".bmp":
                    case ".jpg":
                    case ".png":
                    case ".gif":
                        fileType = "Это Image";
                        break;

                    case ".mp3":
                    case ".avi":
                    case ".wav":
                        fileType = "Multimedia";
                        break;

                    case ".htm":
                    case ".html":
                        fileType = "Web Page";
                        break;

                    default:
                        fileType = "File";
                        break;
                    }
                    if (!String.IsNullOrEmpty(fileType))
                    {
                        fieldValue = fileType;
                        fieldType  = ContentFieldType.WideString;
                    }
                    break;

                case Size32Idx:
                    long size = info.Length;
                    fieldType  = ContentFieldType.NumericFloating;
                    fieldValue = GetSizeValue(size);
                    break;

                case CreateDateTimeIdx:
                    fieldValue = createdDT;
                    fieldType  = ContentFieldType.DateTime;
                    break;

                case CreateDateIdx:
                    fieldValue = createdDT;
                    fieldType  = ContentFieldType.Date;
                    break;

                case CreateTimeIdx:
                    fieldValue = createdDT;
                    fieldType  = ContentFieldType.Time;
                    break;

                default:
                    result = GetValueResult.NoSuchField;
                    break;
                }
            }
            else
            {
                result = GetValueResult.FileError;
            }
            if (!fieldType.Equals(ContentFieldType.NoMoreFields))
            {
                result = GetValueResult.Success;
            }
            return(result);
        }
예제 #14
0
 public virtual GetValueResult GetValue(string fileName, int fieldIndex, int unitIndex,
                                        int maxLen, GetValueFlags flags, out string fieldValue, out ContentFieldType fieldType)
 {
     throw new MethodNotSupportedException("GetValue", true);
 }