public void GetActiveConsoleId() { // This, of course, won't necessarily be true if remotely connected to a full Terminal Server // or as an administrator to a Windows server via Remote Desktop for Administration. RemoteDesktopMethods.GetActiveConsoleSessionId().Should().Be( RemoteDesktopMethods.ProcessIdToSessionId(ProcessMethods.GetCurrentProcessId())); }
public void OpenCurrentProcess() { using (SafeProcessHandle handle = ProcessMethods.OpenProcess(ProcessMethods.GetCurrentProcessId(), ProcessAccessRights.QueryLimitedInfomration)) { handle.IsInvalid.Should().BeFalse(); } }
public void Process(ProcessMethods method) { switch (method) { case ProcessMethods.DeleteDuplicateAbstracts: DeleteDuplicateAbstracts(); break; case ProcessMethods.NormalizeKeywords: NormalizeKeywords(); break; case ProcessMethods.AllMethods: DeleteDuplicateAbstracts(); GoogleApiAnalyses(); break; case ProcessMethods.GoogleApiAnalyses: GoogleApiAnalyses(); break; default: break; } }
public void GetCurrentProcessIdViaFakeHandle() { uint id = ProcessMethods.GetCurrentProcessId(); var handle = ProcessMethods.GetCurrentProcess(); ProcessMethods.GetProcessId(handle).Should().Be(id); }
public VxAceModule(BaseDebug baseDebug, IServiceProvider serviceProvider, ProcessMethods processMethods, Action updatables, int precision = 33) : base(baseDebug, serviceProvider, processMethods, "RGSS301.dll", updatables, precision) { if (updatables is null) { InitUpdatables(); } }
/// <summary> /// OffsetLoader for loading offsets based on defined/undefined types. /// You can define type that has been (dumped / set up) by config/class file. /// </summary> /// <param name="debug">debug</param> /// <param name="processMethods">Methods for accessing process</param> /// <param name="plugin">Defined plugin suited for set engine</param> /// <param name="precision">Async precision.</param> /// <param name="objName">Has to be defined literal name of config file if type is dynamic.</param> /// <param name="props">Props of expando obj. Fields & methods</param> public OffsetLoader(BaseDebug debug, ProcessMethods processMethods, PluginBase plugin, int precision = 33, string objName = "", IEnumerable <string> props = null) : base(debug, processMethods._gameProcess, precision) { _plugin = plugin; if (objName == "") { Type = (T)Activator.CreateInstance(typeof(T)); if (Type.Equals(default))
public void SetEnvironmentVariable_EqualsNotValidPastFirstCharacter(string name) { // Anything past the first character in the name isn't allowed to be an equals character. // If this does change we'd need to change the logic in GetEnvironmentVariables(). Action action = () => ProcessMethods.SetEnvironmentVariable(name, "invalid"); action.ShouldThrow <ArgumentException>(); }
public void BasicGetSetEnvironmentVariable(string prefix) { string name = prefix + System.IO.Path.GetRandomFileName(); ProcessMethods.SetEnvironmentVariable(name, "BasicGetSetEnvironmentVariable"); ProcessMethods.GetEnvironmentVariable(name).Should().Be("BasicGetSetEnvironmentVariable"); ProcessMethods.SetEnvironmentVariable(name, null); ProcessMethods.GetEnvironmentVariable(name).Should().BeNull(); }
public void GetCurrentProcessIdViaRealHandle() { uint id = ProcessMethods.GetCurrentProcessId(); using (var handle = ProcessMethods.OpenProcess(id, ProcessAccessRights.QueryLimitedInfomration)) { ProcessMethods.GetProcessId(handle).Should().Be(id); } }
/// <summary> /// Opens a process token. /// </summary> public static AccessToken OpenProcessToken(AccessTokenRights desiredAccess) { if (!Imports.OpenProcessToken(ProcessMethods.GetCurrentProcess(), desiredAccess, out var processToken)) { throw Errors.GetIoExceptionForLastError(desiredAccess.ToString()); } return(processToken); }
public void GetProcessMemoryInfo_Basic() { var info = ProcessMethods.GetProcessMemoryInfo(); // PagefileUsage is 0 on Win7, otherwise it is equal to PrivateUsage if (info.PagefileUsage.ToUInt64() != 0) { info.PagefileUsage.ToUInt64().Should().Be(info.PrivateUsage.ToUInt64()); } }
/// <summary> /// Opens a process token. /// </summary> public static SafeTokenHandle OpenProcessToken(TokenRights desiredAccess) { SafeTokenHandle processToken; if (!Direct.OpenProcessToken(ProcessMethods.GetCurrentProcess(), desiredAccess, out processToken)) { throw ErrorHelper.GetIoExceptionForLastError(desiredAccess.ToString()); } return(processToken); }
unsafe static void FillListBox(WindowHandle hwndList) { foreach (var name in ProcessMethods.GetEnvironmentVariables().Keys) { if (name[0] != '=') // Skip variable names beginning with '=' { fixed(char *buffer = name) hwndList.SendMessage(ListBoxMessage.AddString, 0, buffer); } } }
public void ValidateKnownRelativeBehaviors(string value, string expected) { // TODO: Need to modify to work with actually present drives and skip if there // isn't more than one. // Set the current directory to D: and the hidden env for C:'s last current directory ProcessMethods.SetEnvironmentVariable(@"=C:", @"C:\Users"); using (new TempCurrentDirectory(@"E:\")) { FileMethods.GetFullPathName(value).Should().Be(expected); } }
/// <summary> /// Gets info for the given module in the given process. /// </summary> /// <param name="process">The process for the given module or null for the current process.</param> /// <remarks>External process handles must be opened with PROCESS_QUERY_INFORMATION|PROCESS_VM_READ</remarks> public unsafe static MODULEINFO GetModuleInfo(ModuleInstance module, SafeProcessHandle process = null) { if (process == null) { process = ProcessMethods.GetCurrentProcess(); } if (!Imports.K32GetModuleInformation(process, module, out var info, (uint)sizeof(MODULEINFO))) { throw Errors.GetIoExceptionForLastError(); } return(info); }
unsafe static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.Create: SIZE baseUnits = Windows.GetDialogBaseUnits(); // Create listbox and static text windows. hwndList = Windows.CreateWindow("listbox", null, WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ListBoxStyles.Standard, ExtendedWindowStyles.None, baseUnits.cx, baseUnits.cy * 3, baseUnits.cx * 64 + Windows.GetSystemMetrics(SystemMetric.CXVSCROLL), baseUnits.cy * 20, window, (IntPtr)ID_LIST, ((CREATESTRUCT *)lParam)->hInstance, IntPtr.Zero); hwndText = Windows.CreateWindow("static", null, WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Left, ExtendedWindowStyles.None, baseUnits.cx, baseUnits.cy, Windows.GetSystemMetrics(SystemMetric.CYSCREEN), baseUnits.cy, window, (IntPtr)ID_TEXT, ((CREATESTRUCT *)lParam)->hInstance, IntPtr.Zero); FillListBox(hwndList); return(0); case WindowMessage.SetFocus: hwndList.SetFocus(); return(0); case WindowMessage.Command: if (wParam.LowWord == ID_LIST && (wParam.HighWord == (ushort)ListBoxNotification.SelectionChange)) { // Get current selection. uint iIndex = hwndList.SendMessage(ListBoxMessage.GetCurrentSelection, 0, 0); int iLength = hwndList.SendMessage(ListBoxMessage.GetTextLength, iIndex, 0) + 1; char *nameBuffer = stackalloc char[iLength]; int result = hwndList.SendMessage(ListBoxMessage.GetText, iIndex, nameBuffer); // Get environment string. string value = ProcessMethods.GetEnvironmentVariable(new string(nameBuffer, 0, result)); // Show it in window. hwndText.SetWindowText(value); } return(0); case WindowMessage.Destroy: Windows.PostQuitMessage(0); return(0); } return(Windows.DefaultWindowProcedure(window, message, wParam, lParam)); }
public void ListEnvironmentVariables_Basic(string prefix) { string name = prefix + System.IO.Path.GetRandomFileName(); ProcessMethods.SetEnvironmentVariable(name, "test"); ProcessMethods.GetEnvironmentVariable(name).Should().Be("test"); var variables = ProcessMethods.GetEnvironmentVariables(); variables.Should().ContainKey(name); variables[name].Should().Be("test"); ProcessMethods.SetEnvironmentVariable(name, null); ProcessMethods.GetEnvironmentVariable(name).Should().BeNull(); variables = ProcessMethods.GetEnvironmentVariables(); variables.Should().NotContainKey(name); }
/// <summary> /// Gets info for the given module in the given process. /// </summary> /// <param name="process">The process for the given module or null for the current process.</param> /// <remarks>External process handles must be opened with PROCESS_QUERY_INFORMATION|PROCESS_VM_READ</remarks> public static MODULEINFO GetModuleInfo(SafeModuleHandle module, SafeProcessHandle process = null) { if (process == null) { process = ProcessMethods.GetCurrentProcess(); } MODULEINFO info; if (!Direct.K32GetModuleInformation(process, module, out info, (uint)Marshal.SizeOf <MODULEINFO>())) { throw ErrorHelper.GetIoExceptionForLastError(); } return(info); }
public void SetEnvironmentVariable_SetNullStringThrows() { Action action = () => ProcessMethods.SetEnvironmentVariable(null, "invalid"); action.ShouldThrow <ArgumentNullException>(); }
public void GetCurrentProcess() { ProcessHandle handle = ProcessMethods.GetCurrentProcess(); handle.HANDLE.Should().Be(new IntPtr(-1)); }
/// <summary> /// Gets the module handles for the given process. /// </summary> /// <remarks>External process handles must be opened with PROCESS_QUERY_INFORMATION|PROCESS_VM_READ</remarks> /// <param name="process">The process to get modules for or null for the current process.</param> public unsafe static IEnumerable <ModuleInstance> GetProcessModules(SafeProcessHandle process = null) { if (process == null) process = ProcessMethods.GetCurrentProcess(); }
private bool PublishProject() { try { string[] scriptFiles = Directory.GetFiles(_projectPath, "*.json", SearchOption.AllDirectories); List <ManifestContentFiles> manifestFiles = new List <ManifestContentFiles>(); foreach (string file in scriptFiles) { ManifestContentFiles manifestFile = new ManifestContentFiles { Include = file.Replace(_projectPath, "") }; manifestFiles.Add(manifestFile); } ManifestMetadata metadata = new ManifestMetadata() { Id = _projectId.ToString(), Title = _projectName, Authors = txtAuthorName.Text.Trim(), Version = txtVersion.Text.Trim(), Description = txtDescription.Text.Trim(), RequireLicenseAcceptance = false, DependencySets = new List <ManifestDependencySet>() { new ManifestDependencySet() { Dependencies = new List <ManifestDependency>() { new ManifestDependency() { Id = "OpenBots.Studio", Version = new Version(Application.ProductVersion).ToString() } } } }, ContentFiles = manifestFiles, }; PackageBuilder builder = new PackageBuilder(); builder.PopulateFiles(_projectPath, new[] { new ManifestFile() { Source = "**" } }); builder.Populate(metadata); if (!Directory.Exists(txtLocation.Text)) { Directory.CreateDirectory(txtLocation.Text); } string nugetFilePath = Path.Combine(txtLocation.Text.Trim(), $"{_projectName}_{txtVersion.Text.Trim()}.nupkg"); using (FileStream stream = File.Open(nugetFilePath, FileMode.OpenOrCreate)) builder.Save(stream); NotificationMessage = $"'{_projectName}' published successfully"; try { lblError.Text = $"Publishing {_projectName} to the server..."; var client = AuthMethods.GetAuthToken(); ProcessMethods.UploadProcess(client, _projectName, nugetFilePath); } catch (Exception) { NotificationMessage = $"'{_projectName}' was published locally. To publish to an OpenBots Server please install and connect the OpenBots Agent."; } return(true); } catch (Exception ex) { lblError.Text = ex.Message; return(false); } }
public void GetEnvironmentVariable_GetNullStringThrows() { Action action = () => ProcessMethods.GetEnvironmentVariable(null); action.ShouldThrow <ArgumentNullException>(); }
public void GetCurrentProcessId() { uint id = ProcessMethods.GetCurrentProcessId(); id.Should().NotBe(0); }
public void SetEnvironmentVariable_SetEmptyStringNotValid() { Action action = () => ProcessMethods.SetEnvironmentVariable("", "invalid"); action.ShouldThrow <ArgumentException>(); }