Esempio n. 1
0
 /// <summary>
 /// Read memory out of the target process.
 /// </summary>
 /// <param name="memoryService">memory service instance</param>
 /// <param name="address">The address of memory to read</param>
 /// <param name="buffer">The buffer to read memory into</param>
 /// <param name="bytesRequested">The number of bytes to read</param>
 /// <param name="bytesRead">The number of bytes actually read out of the target process</param>
 /// <returns>true if any bytes were read at all, false if the read failed (and no bytes were read)</returns>
 public static bool ReadMemory(this IMemoryService memoryService, ulong address, IntPtr buffer, int bytesRequested, out int bytesRead)
 {
     unsafe
     {
         return(memoryService.ReadMemory(address, new Span <byte>(buffer.ToPointer(), bytesRequested), out bytesRead));
     }
 }
Esempio n. 2
0
        internal CorDebugDataTargetWrapper(IServiceProvider services)
        {
            Debug.Assert(services != null);
            _target                = services.GetService <ITarget>();
            _symbolService         = services.GetService <ISymbolService>();
            _memoryService         = services.GetService <IMemoryService>();
            _threadService         = services.GetService <IThreadService>();
            _threadUnwindService   = services.GetService <IThreadUnwindService>();
            _ignoreAddressBitsMask = _memoryService.SignExtensionMask();

            VTableBuilder builder = AddInterface(IID_ICorDebugDataTarget, validate: false);

            builder.AddMethod(new GetPlatformDelegate(GetPlatform));
            builder.AddMethod(new ReadVirtualDelegate(ReadVirtual));
            builder.AddMethod(new GetThreadContextDelegate(GetThreadContext));
            ICorDebugDataTarget = builder.Complete();

            builder = AddInterface(IID_ICorDebugDataTarget4, validate: false);
            builder.AddMethod(new VirtualUnwindDelegate(VirtualUnwind));
            builder.Complete();

            builder = AddInterface(IID_ICorDebugMutableDataTarget, validate: false);
            builder.AddMethod(new WriteVirtualDelegate(WriteVirtual));
            builder.AddMethod(new SetThreadContextDelegate((self, threadId, contextSize, context) => HResult.E_NOTIMPL));
            builder.AddMethod(new ContinueStatusChangeDelegate((self, continueStatus) => HResult.E_NOTIMPL));
            builder.Complete();

            builder = AddInterface(IID_ICorDebugMetaDataLocator, validate: false);
            builder.AddMethod(new GetMetaDataDelegate(GetMetaData));
            builder.Complete();

            AddRef();
        }
 /// <summary>
 /// Memory service constructor
 /// </summary>
 /// <param name="target">target instance</param>
 /// <param name="memoryService">memory service to wrap</param>
 public MetadataMappingMemoryService(ITarget target, IMemoryService memoryService)
 {
     _target        = target;
     _memoryService = memoryService;
     target.OnFlushEvent.Register(Flush);
     target.DisposeOnDestroy(SymbolService?.OnChangeEvent.Register(Flush));
 }
 public ModeSelectViewModel(INavService navService, IMemoryService memService,
                            IDataExchangeService exchangeService, IAlertMessageService alertService) : base(navService)
 {
     this.memService      = memService;
     this.exchangeService = exchangeService;
     this.alertService    = alertService;
 }
Esempio n. 5
0
        /// <summary>
        /// Create an instance of the hosting class
        /// </summary>
        /// <param name="target">target instance</param>
        public SOSHost(ITarget target)
        {
            Target                 = target;
            ConsoleService         = target.Services.GetService <IConsoleService>();
            ModuleService          = target.Services.GetService <IModuleService>();
            ThreadService          = target.Services.GetService <IThreadService>();
            MemoryService          = target.Services.GetService <IMemoryService>();
            _ignoreAddressBitsMask = MemoryService.SignExtensionMask();

            string rid = InstallHelper.GetRid();

            SOSPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), rid);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var debugClient = new DebugClient(this);
                _interface = debugClient.IDebugClient;
            }
            else
            {
                var lldbServices = new LLDBServices(this);
                _interface = lldbServices.ILLDBServices;
            }
            _hostWrapper = new HostWrapper(target.Host);
            _hostWrapper.AddServiceWrapper(SymbolServiceWrapper.IID_ISymbolService, () => new SymbolServiceWrapper(target.Host));
        }
Esempio n. 6
0
 public MemoryController(IMapper mapper, IConfiguration configuration,
                         IMemoryService memoryService, ICommentService commentService, IAccountService accountService) : base(mapper, configuration)
 {
     _memoryService  = memoryService;
     _commentService = commentService;
     _accountService = accountService;
 }
Esempio n. 7
0
        public SymbolServiceWrapper(ISymbolService symbolService, IMemoryService memoryService)
        {
            Debug.Assert(symbolService != null);
            Debug.Assert(memoryService != null);
            _symbolService = symbolService;
            _memoryService = memoryService;
            Debug.Assert(_symbolService != null);

            VTableBuilder builder = AddInterface(IID_ISymbolService, validate: false);

            builder.AddMethod(new IsSymbolStoreEnabledDelegate((IntPtr self) => _symbolService.IsSymbolStoreEnabled));
            builder.AddMethod(new InitializeSymbolStoreDelegate(InitializeSymbolStore));
            builder.AddMethod(new ParseSymbolPathDelegate(ParseSymbolPath));
            builder.AddMethod(new DisplaySymbolStoreDelegate(DisplaySymbolStore));
            builder.AddMethod(new DisableSymbolStoreDelegate((IntPtr self) => _symbolService.DisableSymbolStore()));
            builder.AddMethod(new LoadNativeSymbolsDelegate(LoadNativeSymbols));
            builder.AddMethod(new LoadNativeSymbolsFromIndexDelegate(LoadNativeSymbolsFromIndex));
            builder.AddMethod(new LoadSymbolsForModuleDelegate(LoadSymbolsForModule));
            builder.AddMethod(new DisposeDelegate(Dispose));
            builder.AddMethod(new ResolveSequencePointDelegate(ResolveSequencePoint));
            builder.AddMethod(new GetLocalVariableNameDelegate(GetLocalVariableName));
            builder.AddMethod(new GetLineByILOffsetDelegate(GetLineByILOffset));
            builder.AddMethod(new GetExpressionValueDelegate(GetExpressionValue));
            builder.AddMethod(new GetMetadataLocatorDelegate(GetMetadataLocator));
            builder.AddMethod(new GetICorDebugMetadataLocatorDelegate(GetICorDebugMetadataLocator));
            builder.Complete();

            AddRef();
        }
 /// <summary>
 /// Create a stream for the address range.
 /// </summary>
 /// <param name="memoryService">memory service instance</param>
 /// <param name="address">address to read</param>
 /// <param name="size">size of stream</param>
 /// <returns>memory range Stream</returns>
 public static Stream CreateMemoryStream(this IMemoryService memoryService, ulong address, ulong size)
 {
     Debug.Assert(address != 0);
     Debug.Assert(size != 0);
     Debug.Assert((address & ~memoryService.SignExtensionMask()) == 0);
     return(new TargetStream(memoryService, address, size));
 }
        /// <summary>
        /// Creates a key generator for the runtime module pointed to by the address/size.
        /// </summary>
        /// <param name="memoryService">memory service instance</param>
        /// <param name="config">Target configuration: Windows, Linux or OSX</param>
        /// <param name="moduleFilePath">module path</param>
        /// <param name="address">module base address</param>
        /// <param name="size">module size</param>
        /// <returns>KeyGenerator or null if error</returns>
        public static KeyGenerator GetKeyGenerator(this IMemoryService memoryService, OSPlatform config, string moduleFilePath, ulong address, ulong size)
        {
            Stream       stream    = memoryService.CreateMemoryStream(address, size);
            KeyGenerator generator = null;

            if (config == OSPlatform.Linux)
            {
                var elfFile = new ELFFile(new StreamAddressSpace(stream), 0, true);
                generator = new ELFFileKeyGenerator(Tracer.Instance, elfFile, moduleFilePath);
            }
            else if (config == OSPlatform.OSX)
            {
                var machOFile = new MachOFile(new StreamAddressSpace(stream), 0, true);
                generator = new MachOFileKeyGenerator(Tracer.Instance, machOFile, moduleFilePath);
            }
            else if (config == OSPlatform.Windows)
            {
                var peFile = new PEFile(new StreamAddressSpace(stream), true);
                generator = new PEFileKeyGenerator(Tracer.Instance, peFile, moduleFilePath);
            }
            else
            {
                Trace.TraceError("GetKeyGenerator: unsupported platform {0}", config);
            }
            return(generator);
        }
 /// <summary>
 /// Memory service constructor
 /// </summary>
 /// <param name="target"></param>
 /// <param name="memoryService">memory service to wrap</param>
 internal PEImageMappingMemoryService(ITarget target, IMemoryService memoryService)
 {
     _memoryService = memoryService;
     _moduleService = target.Services.GetService <IModuleService>();
     _memoryCache   = new MemoryCache(ReadMemoryFromModule);
     target.OnFlushEvent.Register(_memoryCache.FlushCache);
 }
Esempio n. 11
0
        /// <summary>
        /// Create an instance of the hosting class. Has the lifetime of the target. Depends on the
        /// context service for the current thread and runtime.
        /// </summary>
        /// <param name="services">service provider</param>
        public SOSHost(IServiceProvider services)
        {
            Services      = services;
            Target        = services.GetService <ITarget>() ?? throw new DiagnosticsException("No target");
            TargetWrapper = new TargetWrapper(services);
            Target.DisposeOnDestroy(this);
            ConsoleService = services.GetService <IConsoleService>();
            ModuleService  = services.GetService <IModuleService>();
            ThreadService  = services.GetService <IThreadService>();
            MemoryService  = services.GetService <IMemoryService>();
            TargetWrapper.ServiceWrapper.AddServiceWrapper(SymbolServiceWrapper.IID_ISymbolService, () => new SymbolServiceWrapper(services.GetService <ISymbolService>(), MemoryService));
            _ignoreAddressBitsMask = MemoryService.SignExtensionMask();
            _sosLibrary            = services.GetService <SOSLibrary>();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var debugClient = new DebugClient(this);
                _interface = debugClient.IDebugClient;
            }
            else
            {
                var lldbServices = new LLDBServices(this);
                _interface = lldbServices.ILLDBServices;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryWorker{TMemory, TMemoryStatus}"/> class.
 /// </summary>
 /// <param name="memoryService">The application layer MemoryService.</param>
 /// <param name="configuration">The IConfiguration instance.</param>
 /// <param name="logger">The NLog logger instance.</param>
 public MemoryWorker(
     IMemoryService <TMemory, TMemoryStatus> memoryService,
     IConfiguration configuration,
     ILogger logger)
     : base(memoryService, configuration, logger)
 {
 }
Esempio n. 13
0
 public MainEditorViewModel(IMemoryService memoryService, ILogger logger, IFolderBrowserDialog folderBrowserDialog)
 {
     _memoryService       = memoryService;
     _logger              = logger;
     _folderBrowserDialog = folderBrowserDialog;
     _logger.LogCreate(this);
 }
Esempio n. 14
0
        public DataTargetWrapper(IServiceProvider services, IRuntime runtime)
        {
            Debug.Assert(services != null);
            Debug.Assert(runtime != null);
            _services              = services;
            _runtimeBaseAddress    = runtime.RuntimeModule.ImageBase;
            _symbolService         = services.GetService <ISymbolService>();
            _memoryService         = services.GetService <IMemoryService>();
            _threadService         = services.GetService <IThreadService>();
            _threadUnwindService   = services.GetService <IThreadUnwindService>();
            _moduleService         = services.GetService <IModuleService>();
            _remoteMemoryService   = services.GetService <IRemoteMemoryService>();
            _ignoreAddressBitsMask = _memoryService.SignExtensionMask();

            VTableBuilder builder = AddInterface(IID_ICLRDataTarget, false);

            AddDataTarget(builder);
            IDataTarget = builder.Complete();

            builder = AddInterface(IID_ICLRDataTarget2, false);
            AddDataTarget2(builder);
            builder.Complete();

            builder = AddInterface(IID_ICLRDataTarget4, validate: false);
            builder.AddMethod(new VirtualUnwindDelegate(VirtualUnwind));
            builder.Complete();

            builder = AddInterface(IID_ICLRMetadataLocator, false);
            builder.AddMethod(new GetMetadataDelegate(GetMetadata));
            builder.Complete();

            builder = AddInterface(IID_ICLRRuntimeLocator, false);
            builder.AddMethod(new GetRuntimeBaseDelegate(GetRuntimeBase));
            builder.Complete();
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryType{TMemory, TMemoryStatus}"/> class.
        /// </summary>
        /// <param name="memoryService">The application layer MemoryService.</param>
        /// <param name="logger">The NLog logger instance.</param>
        public MemoryType(IMemoryService <TMemory, TMemoryStatus> memoryService, ILogger logger)
        {
            this.Field(x => x.Total);

            this.Field <MemoryStatusType <TMemoryStatus> >()
            .Name("Status")
            .ResolveAsync(async context =>
            {
                logger.Debug("Memory status field");

                return(await memoryService.GetLastStatusAsync());
            });

            this.Connection <MemoryStatusType <TMemoryStatus> >()
            .Name("Statuses")
            .Bidirectional()
            .ResolveAsync(async context =>
            {
                logger.Debug("Memory statuses connection");

                var pagingInput = context.GetPagingInput();
                var statuses    = await memoryService.GetStatusesAsync(pagingInput);

                return(statuses.ToConnection());
            });
        }
Esempio n. 16
0
        /// <summary>
        /// ctor().
        /// </summary>
        public MemoryView()
        {
            InitializeComponent();

            _memory = DependencyService.Get <IMemoryService>();

            RefreshScreen();
        }
 public TargetStream(IMemoryService memoryService, ulong address, ulong size)
     : base()
 {
     _memoryService = memoryService;
     _address       = address;
     Length         = (long)size;
     Position       = 0;
 }
Esempio n. 18
0
 public static MemoryInfo getInfo()
 {
     if (_arquivo == null)
     {
         _arquivo = DependencyService.Get <IMemoryService>();
     }
     return(_arquivo.getInfo());
 }
Esempio n. 19
0
 public MainPageDetailViewModel()
 {
     RunRealmCommand  = new Command(async() => await RunRealmTest());
     _dialogService   = DependencyService.Get <IDialogService>();
     _memoryService   = DependencyService.Get <IMemoryService>();
     _benchmarkRunner = new BenchmarkRunner();
     UpdateMemoryInfo();
 }
Esempio n. 20
0
 public TestBase(
     [Import] ILoggingService loggingService,
     [Import] IObjectManager objectManager,
     [Import] IMemoryService memoryService)
 {
     this.loggingService = loggingService;
     this.objectManager  = objectManager;
     this.memoryService  = memoryService;
 }
 /// <summary>
 /// The PE and ELF image mapping memory service. This service assumes that the managed PE
 /// assemblies are in the module service's list. This is true for dbgeng, dotnet-dump but not
 /// true for lldb (only native modules are provided).
 /// </summary>
 /// <param name="target">target instance</param>
 /// <param name="memoryService">memory service to wrap</param>
 internal ImageMappingMemoryService(ITarget target, IMemoryService memoryService)
 {
     _memoryService       = memoryService;
     _moduleService       = target.Services.GetService <IModuleService>();
     _memoryCache         = new MemoryCache(ReadMemoryFromModule);
     _recursionProtection = new HashSet <ulong>();
     target.OnFlushEvent.Register(_memoryCache.FlushCache);
     target.DisposeOnDestroy(target.Services.GetService <ISymbolService>()?.OnChangeEvent.Register(_memoryCache.FlushCache));
 }
Esempio n. 22
0
 public ApplicationService(IMemoryService memory, ISourceFileModel <ILineOfCode> srcModel, OperationHelpers operationHelpers, BitOperations bitOperations, ByteOperations byteOperations, LiteralControlOperations literalControlOperations)
 {
     this._memory              = memory;
     this._srcModel            = srcModel;
     _bitOperations            = bitOperations;
     _byteOperations           = byteOperations;
     _literalControlOperations = literalControlOperations;
     _operationHelpers         = operationHelpers;
 }
Esempio n. 23
0
        public MainController(MainViewModel viewModel, IMemoryService memoryService,
                              IDiagnosticsService diagnosticsService,
                              IEnumerable <IWorkspaceDescriptor> workspaceDescriptors)
            : base(viewModel)
        {
            _logger = LogManager.GetCurrentClassLogger();
            _logger.Debug("Main controller starting...");

            _workspaceDescriptors = workspaceDescriptors;

            var availableWorkspaces = _workspaceDescriptors.OrderBy(x => x.Position)
                                      .Select(x => x.Name)
                                      .ToList();

            foreach (var availableWorkspace in availableWorkspaces)
            {
                _logger.Debug("Available workspace - '{0}'", availableWorkspace);
            }

            availableWorkspaces.Insert(0, string.Empty);

            ViewModel.AddAvailableWorkspaces(availableWorkspaces);

            _disposable = new CompositeDisposable
            {
                ViewModel.AddWorkspaceStream
                .Subscribe(CreateWorkspace),

                ViewModel.RemoveWorkspaceStream
                .Do(RemoveWorkspace)
                .Delay(TimeSpan.FromMilliseconds(DisposeDelay))
                .Do(DeleteWorkspace)
                .Subscribe(),

                memoryService.MemoryInMegaBytes
                .DistinctUntilChanged()
                .Throttle(TimeSpan.FromSeconds(1))
                .Subscribe(UpdateUsedMemory),

                diagnosticsService.PerformanceCounters(1000)
                .Subscribe(x =>
                {
                    Debug.WriteLine("PrivateWorkingSetMemory = " +
                                    decimal.Round(Convert.ToDecimal(x.PrivateWorkingSetMemory) / (1024 * 1000), 2));
                    Debug.WriteLine("TotalAvailableMemoryMb = " + x.TotalAvailableMemoryMb);
                }),

                diagnosticsService.LoadedAssembly
                .Subscribe(x => Debug.WriteLine("Assembly = " + x.FullName))
            };

            for (var i = 0; i < 200; i++)
            {
                _logger.Debug("Log Item = " + i);
            }
        }
Esempio n. 24
0
 public TargetStream(IMemoryService memoryService, ulong address, ulong size)
     : base()
 {
     Debug.Assert(address != 0);
     Debug.Assert(size != 0);
     _memoryService = memoryService;
     _address       = address;
     Length         = (long)size;
     Position       = 0;
 }
Esempio n. 25
0
 public AccountManager(IUnitOfWork unitOfWork, IPasswordHasher <User> passwordHasher,
                       ITokenProvider tokenProvider, IEmailSender emailSender,
                       IBackgroundTaskQueue queue, IMemoryService memoryService, IConfiguration configuration) : base(unitOfWork, configuration)
 {
     _passwordHasher = passwordHasher;
     _tokenProvider  = tokenProvider;
     _emailSender    = emailSender;
     _queue          = queue;
     _memoryService  = memoryService;
 }
Esempio n. 26
0
        /// <summary>
        /// Memory service constructor
        /// </summary>
        /// <param name="target"></param>
        /// <param name="memoryService">memory service to wrap</param>
        internal PEImageMappingMemoryService(ITarget target, IMemoryService memoryService)
        {
            _memoryService = memoryService;
            _moduleService = target.Services.GetService <IModuleService>();
            _memoryCache   = new MemoryCache(ReadMemoryFromModule);

            target.OnFlushEvent += (object sender, EventArgs e) => {
                _memoryCache.FlushCache();
            };
        }
Esempio n. 27
0
        public static string GetMemoryStatus()
        {
            string         res = "";
            IMemoryService ims = DependencyService.Get <IMemoryService>();

            if (ims != null)
            {
                res = ims.GetInfo().ToString();
            }
            return(res);
        }
Esempio n. 28
0
 public TestBase(
     [Import] ILoggerService logger,
     [Import] IMemoryService memory,
     [Import] INavigationService navigation,
     [Import] IObjectManagerService objectManager)
 {
     this.logger        = logger;
     this.memory        = memory;
     this.navigation    = navigation;
     this.objectManager = objectManager;
 }
 public RememberWhenApplicationService(
     IParameterManagementService parameterManagementService,
     IEnvironmentManagementService environmentService,
     IMemoryService memoryService,
     IEmailService emailService,
     ITextMessageService textMessageService)
 {
     _environmentService         = environmentService;
     _parameterManagementService = parameterManagementService;
     _memoryService      = memoryService;
     _emailService       = emailService;
     _textMessageService = textMessageService;
 }
Esempio n. 30
0
        public MemoriesViewModel(IMemoryService memoryService, IPhotoService photoService)
        {
            _memoryService = memoryService;
            _photoService  = photoService;

            MemoryList = new ObservableCollection <Memory>(memoryService.GetAll());

            foreach (var memory in MemoryList)
            {
                memory.Photo = photoService.Get(memory.PhotoId);
            }

            SubscribeToMessages();
        }