Пример #1
0
        public IEnumerable <ClrDataMethod> EnumerateMethodInstancesByAddress(ClrDataAddress addr)
        {
            InitDelegate(ref _startEnum, VTable.StartEnumMethodInstancesByAddress);
            InitDelegate(ref _enum, VTable.EnumMethodInstanceByAddress);
            InitDelegate(ref _endEnum, VTable.EndEnumMethodInstancesByAddress);

            List <ClrDataMethod> result = new List <ClrDataMethod>(1);

            if (!_startEnum(Self, addr, IntPtr.Zero, out ClrDataAddress handle))
            {
                return(result);
            }

            try
            {
                while (_enum(Self, ref handle, out IntPtr method))
                {
                    result.Add(new ClrDataMethod(_library, method));
                }
            }
            finally
            {
                _endEnum(Self, handle);
            }

            return(result);
        }
Пример #2
0
        public HResult ReadVirtual(IntPtr _, ClrDataAddress cda, IntPtr buffer, int bytesRequested, out int bytesRead)
        {
            ulong       address = cda;
            Span <byte> span    = new Span <byte>(buffer.ToPointer(), bytesRequested);

            if (address == MagicCallbackConstant && _callbackContext > 0)
            {
                // See comment in RuntimeBuilder.FlushDac
                _callback?.Invoke();
                bytesRead = 0;
                return(HResult.E_FAIL);
            }

            if (_dataReader.Read(address, span, out int read))
            {
                bytesRead = read;
                return(HResult.S_OK);
            }

            bytesRead = 0;
            ModuleInfo?info = GetModule(address);

            if (info != null)
            {
                string?filePath = null;
                if (!string.IsNullOrEmpty(info.FileName))
                {
                    if (info.FileName !.EndsWith(".so", StringComparison.OrdinalIgnoreCase))
                    {
                        // TODO
                        Debug.WriteLine($"TODO: Implement reading from module '{info.FileName}'");
                        return(HResult.E_NOTIMPL);
                    }

                    filePath = _dataTarget.BinaryLocator?.FindBinary(info.FileName !, info.IndexTimeStamp, info.IndexFileSize, true);
                }

                if (filePath is null)
                {
                    bytesRead = 0;
                    return(HResult.E_FAIL);
                }

                // We do not put a using statement here to prevent needing to load/unload the binary over and over.
                PEImage?peimage = _dataTarget.LoadPEImage(filePath);
                if (peimage != null)
                {
                    lock (peimage)
                    {
                        DebugOnly.Assert(peimage.IsValid);
                        int rva = checked ((int)(address - info.ImageBase));
                        bytesRead = peimage.Read(rva, span);
                        return(HResult.S_OK);
                    }
                }
            }

            return(HResult.E_FAIL);
        }
Пример #3
0
 public HResult SetTLSValue(IntPtr self, uint threadID, uint index, ClrDataAddress value)
 {
     return(HResult.E_FAIL);
 }
Пример #4
0
 public HResult WriteVirtual(IntPtr self, ClrDataAddress address, IntPtr buffer, uint bytesRequested, out uint bytesWritten)
 {
     // This gets used by MemoryBarrier() calls in the dac, which really shouldn't matter what we do here.
     bytesWritten = bytesRequested;
     return(HResult.S_OK);
 }
Пример #5
0
 public HResult GetAssemblyLoadContext(ClrDataAddress methodTable, out ClrDataAddress assemblyLoadContext)
 {
     InitDelegate(ref _getAssemblyLoadContext, VTable.GetAssemblyLoadContext);
     return(_getAssemblyLoadContext(Self, methodTable, out assemblyLoadContext));
 }