Beispiel #1
0
        public void ReadDataRefContents(DataRef field)
        {
            if (field.Length < 0)
            {
                return;
            }

            bool opened = OpenReader();

            if (_reader == null)
            {
                return;
            }

            try
            {
                // Calculate the base offset to read from
                long oldBaseOffset = BaseOffset;
                long dataOffset    = field.DataAddress;
                if (_type == LoadType.File)
                {
                    dataOffset = (uint)_cache.MetaArea.PointerToOffset(dataOffset);
                }

                _reader.SeekTo(dataOffset);

                switch (field.Format)
                {
                default:
                    byte[] data = _reader.ReadBlock(field.Length);
                    field.Value = FunctionHelpers.BytesToHexString(data);
                    break;

                case "utf16":
                    field.Value = _reader.ReadUTF16(field.Length);
                    break;

                case "asciiz":
                    field.Value = _reader.ReadAscii(field.Length);
                    break;
                }

                BaseOffset = oldBaseOffset;
            }
            finally
            {
                if (opened)
                {
                    CloseReader();
                }
            }
        }
Beispiel #2
0
        public void VisitDataRef(DataRef field)
        {
            SeekToOffset(field.Offset);
            StructureValueCollection values = StructureReader.ReadStructure(_reader, _dataRefLayout);

            var  length  = (int)values.GetInteger("size");
            uint pointer = values.GetInteger("pointer");

            if (length > 0)
            {
                if (_cache.GetType() == typeof(Blamite.Blam.FourthGen.FourthGenCacheFile))
                {
                    pointer = HeaderOffset + (pointer & 0xFFFFFFF);
                }

                field.DataAddress = pointer;
                field.Length      = length;

                // Go to position
                if (_type == LoadType.Memory)
                {
                    _reader.SeekTo(pointer);
                }
                else
                {
                    _reader.SeekTo(_cache.MetaArea.PointerToOffset(pointer));
                }

                switch (field.Format)
                {
                default:
                    byte[] data = _reader.ReadBlock(field.Length);
                    field.Value = FunctionHelpers.BytesToHexString(data);
                    break;

                case "unicode":
                    field.Value = _reader.ReadUTF16(field.Length);
                    break;

                case "asciiz":
                    field.Value = _reader.ReadAscii(field.Length);
                    break;
                }
            }
            else
            {
                field.DataAddress = 0;
                field.Length      = 0;
                field.Value       = "";
            }
        }
Beispiel #3
0
        public void VisitDataRef(DataRef field)
        {
            SeekToOffset(field.Offset);
            StructureValueCollection values = StructureReader.ReadStructure(_reader, _dataRefLayout);

            var  length  = (int)values.GetInteger("size");
            uint pointer = (uint)values.GetInteger("pointer");

            long expanded = _cache.PointerExpander.Expand(pointer);

            if (length > 0 && _cache.MetaArea.ContainsBlockPointer(expanded, length))
            {
                field.DataAddress = expanded;
                field.Length      = length;

                // Go to position
                if (_type == LoadType.Memory)
                {
                    _reader.SeekTo(expanded);
                }
                else
                {
                    _reader.SeekTo(_cache.MetaArea.PointerToOffset(expanded));
                }

                switch (field.Format)
                {
                default:
                    byte[] data = _reader.ReadBlock(field.Length);
                    field.Value = FunctionHelpers.BytesToHexString(data);
                    break;

                case "unicode":
                    field.Value = _reader.ReadUTF16(field.Length);
                    break;

                case "asciiz":
                    field.Value = _reader.ReadAscii(field.Length);
                    break;
                }
            }
            else
            {
                field.DataAddress = 0;
                field.Length      = 0;
                field.Value       = "";
            }
        }
Beispiel #4
0
 public void VisitRawData(RawData field)
 {
     SeekToOffset(field.Offset);
     field.DataAddress = field.FieldAddress;
     field.Value       = FunctionHelpers.BytesToHexString(_reader.ReadBlock(field.Length));
 }