private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { var process = ViewModel.ApplicationViewModel.SelectedProcess; if (!process.HasExited) { var injector = new ApplicationInjector(ViewModel.ApplicationViewModel.SelectedProcess); injector.Inject(); // Exit page. ViewModel.ApplicationViewModel.ChangeApplicationPage(Enum.ApplicationSubPage.ReloadedProcess); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddControllers(options => { options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer())); }); services.AddMvc().AddFluentValidation(); services.AddCors(); services.AddDbContext <ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddScoped <DbContext, ApplicationContext>(); services.AddLocalization(options => options.ResourcesPath = "Resources"); ApplicationInjector.RegisterServices(services); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Version = "v1", Title = "Ewave Livraria API", Description = "Ewave Livraria" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "Bearer", Name = "Bearer", In = ParameterLocation.Header }, new List <string>() } }); }); }
/* Implementation */ private void ProcessWatcherOnOnNewProcess(Process newProcess) { try { string fullPath = newProcess.GetExecutablePath(); var config = _configService.Items.FirstOrDefault(x => string.Equals(ApplicationConfig.GetAbsoluteAppLocation(x), fullPath, StringComparison.OrdinalIgnoreCase)); if (config != null && config.Config.AutoInject) { var appInjector = new ApplicationInjector(newProcess); appInjector.Inject(); } } catch (Exception) { // Ignored } }
/// <summary> /// Starts the application, injecting Reloaded into it. /// </summary> public void Start() { // Start up the process Native.STARTUPINFO startupInfo = new Native.STARTUPINFO(); Native.SECURITY_ATTRIBUTES lpProcessAttributes = new Native.SECURITY_ATTRIBUTES(); Native.SECURITY_ATTRIBUTES lpThreadAttributes = new Native.SECURITY_ATTRIBUTES(); Native.PROCESS_INFORMATION processInformation = new Native.PROCESS_INFORMATION(); if (_arguments == null) { _arguments = ""; } bool success = Native.CreateProcessW(null, $"\"{_location}\" {_arguments}", ref lpProcessAttributes, ref lpThreadAttributes, false, Native.ProcessCreationFlags.CREATE_SUSPENDED, IntPtr.Zero, Path.GetDirectoryName(_location) !, ref startupInfo, ref processInformation); if (!success) { string windowsErrorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message; throw new ArgumentException($"{Resources.ErrorFailedToStartProcess.Get()} {windowsErrorMessage}"); } // DLL Injection var process = Process.GetProcessById((int)processInformation.dwProcessId); var injector = new ApplicationInjector(process); try { injector.Inject(); } catch (Exception) { Native.ResumeThread(processInformation.hThread); throw; } Native.ResumeThread(processInformation.hThread); }