private void RefreshProcessList(string filter, bool hideUnrestricted) { using (var processes = new DisposableList <NtProcess>(NtProcess.GetProcesses(ProcessAccessRights.QueryInformation))) { processes.Sort((a, b) => a.ProcessId - b.ProcessId); IEnumerable <NtProcess> filtered = processes.Where(p => GetToken(p) != null); if (!String.IsNullOrWhiteSpace(filter)) { filter = filter.ToLower(); filtered = filtered.Where(p => p.FullPath.ToLower().Contains(filter)); } if (hideUnrestricted) { filtered = filtered.Where(p => IsRestrictedToken(p)); } ClearTree(treeViewProcesses); ClearList(listViewThreads); foreach (NtProcess entry in filtered) { AddProcessNode(entry); AddThreads(entry); } listViewThreads.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewThreads.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } }
/// <summary> /// Overridden ProcessRecord method. /// </summary> protected override void ProcessRecord() { if (ThreadId == -1 && ProcessId == -1) { IEnumerable <NtThread> threads = NtThread.GetThreads(Access); if (FilterScript == null) { WriteObject(threads); } else { using (var ths = new DisposableList <NtThread>(threads)) { WriteObject(ths.Where(t => ArbitraryFilter(t, FilterScript)).Select(t => t.Duplicate()).ToArray()); } } } else if (ProcessId != -1) { using (NtProcess process = NtProcess.Open(ProcessId, ProcessAccessRights.MaximumAllowed)) { WriteObject(process.GetThreads()); } } else { WriteObject(NtThread.Open(ThreadId, Access)); } }
private IEnumerable <ListViewItem> CreateThreads(NtProcess query_process, NtToken process_token) { List <ListViewItem> ret = new List <ListViewItem>(); using (var threads = new DisposableList <NtThread>(query_process.GetThreads(ThreadAccessRights.MaximumAllowed))) { foreach (NtThread thread in threads.Where(t => t.IsAccessGranted(ThreadAccessRights.QueryLimitedInformation))) { using (var result = NtToken.OpenThreadToken(thread, true, TokenAccessRights.MaximumAllowed, false)) { if (!result.IsSuccess) { continue; } var token = result.Result; ListViewItem item = new ListViewItem($"{query_process.ProcessId} - {query_process.Name}"); item.SubItems.Add(thread.ThreadId.ToString()); item.SubItems.Add(token.User.ToString()); item.SubItems.Add(token.ImpersonationLevel.ToString()); item.Tag = new ThreadTokenEntry(query_process, process_token, thread.ThreadId, thread.Description, token, thread.GetSecurityDescriptor(SecurityInformation.AllBasic, false).GetResultOrDefault()); ret.Add(item); } } } return(ret); }
private void RefreshProcessList(string filter, bool hideUnrestricted, bool showDeadProcesses) { bool filter_name = !string.IsNullOrWhiteSpace(filter); ClearList(listViewProcesses); ClearList(listViewThreads); using (var list = new DisposableList <NtProcess>(NtProcess.GetProcesses(ProcessAccessRights.MaximumAllowed))) { List <NtProcess> processes = list.Where(p => !p.IsDeleting || showDeadProcesses) .Where(p => p.IsAccessGranted(ProcessAccessRights.QueryLimitedInformation)).ToList(); processes.Sort((a, b) => a.ProcessId - b.ProcessId); using (var tokens = new DisposableList <NtToken>(processes.Select(p => GetToken(p)))) { List <ListViewItem> procs = new List <ListViewItem>(); List <ListViewItem> threads = new List <ListViewItem>(); Debug.Assert(processes.Count == tokens.Count); for (int i = 0; i < processes.Count; ++i) { NtProcess p = processes[i]; NtToken t = tokens[i]; if (t == null || !t.IsAccessGranted(TokenAccessRights.Query)) { continue; } if (filter_name) { if (!p.FullPath.ToLower().Contains(filter.ToLower())) { continue; } } if (hideUnrestricted) { if (!IsRestrictedToken(t)) { continue; } } procs.Add(CreateProcessNode(p, t)); threads.AddRange(CreateThreads(p, t)); } listViewProcesses.Items.AddRange(procs.ToArray()); listViewThreads.Items.AddRange(threads.ToArray()); ResizeColumns(listViewProcesses); ResizeColumns(listViewThreads); } } }
/// <summary> /// Overridden ProcessRecord method. /// </summary> protected override void ProcessRecord() { if (InfoOnly) { if (ProcessId != -1) { WriteObject(QueryThreadInformation(ProcessId), true); } else { WriteObject(QueryThreadInformation(), true); } } else if (Current) { WriteObject(GetCurrentThread(Access, PseudoHandle)); } else if (ThreadId == -1 && ProcessId == -1) { IEnumerable <NtThread> threads = NtThread.GetThreads(Access, FromSystem); if (FilterScript == null) { WriteObject(threads, true); } else { using (var ths = new DisposableList <NtThread>(threads)) { WriteObject(ths.Where(t => ArbitraryFilter(t, FilterScript)).Select(t => t.Duplicate()).ToArray(), true); } } } else if (ProcessId != -1) { using (NtProcess process = NtProcess.Open(ProcessId, ProcessAccessRights.MaximumAllowed)) { WriteObject(process.GetThreads(), true); } } else { WriteObject(NtThread.Open(ThreadId, Access)); } }
private void RefreshProcessList(string filter, bool hideUnrestricted) { using (var processes = new DisposableList <NtProcess>(NtProcess.GetProcesses(ProcessAccessRights.QueryLimitedInformation))) { processes.Sort((a, b) => a.ProcessId - b.ProcessId); IEnumerable <NtProcess> filtered = processes.Where(p => GetToken(p) != null); if (!String.IsNullOrWhiteSpace(filter)) { filter = filter.ToLower(); filtered = filtered.Where(p => p.FullPath.ToLower().Contains(filter)); } if (hideUnrestricted) { filtered = filtered.Where(p => IsRestrictedToken(p)); } ClearList(listViewProcesses); ClearList(listViewThreads); List <ListViewItem> procs = new List <ListViewItem>(); List <ListViewItem> threads = new List <ListViewItem>(); foreach (NtProcess entry in filtered) { ListViewItem proc = CreateProcessNode(entry); if (proc != null) { procs.Add(proc); } threads.AddRange(CreateThreads(entry)); } listViewProcesses.Items.AddRange(procs.ToArray()); listViewThreads.Items.AddRange(threads.ToArray()); ResizeColumns(listViewProcesses); ResizeColumns(listViewThreads); } }
private void RefreshProcessList(string filter, bool hideUnrestricted) { using (var processes = new DisposableList<NtProcess>(NtProcess.GetProcesses(ProcessAccessRights.QueryInformation))) { processes.Sort((a, b) => a.ProcessId- b.ProcessId); IEnumerable<NtProcess> filtered = processes.Where(p => GetToken(p) != null); if (!String.IsNullOrWhiteSpace(filter)) { filter = filter.ToLower(); filtered = filtered.Where(p => p.FullPath.ToLower().Contains(filter)); } if (hideUnrestricted) { filtered = filtered.Where(p => IsRestrictedToken(p)); } ClearTree(treeViewProcesses); ClearList(listViewThreads); foreach (NtProcess entry in filtered) { AddProcessNode(entry); AddThreads(entry); } listViewThreads.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listViewThreads.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } }
static Texture CreateTextureFromImage(string path, string textureName, TextureSettings textureSettings, bool isDecalsWad) { // Load the main texture image, and any available mipmap images: using (var images = new DisposableList <Image <Rgba32> >(GetMipmapFilePaths(path).Prepend(path) .Select(imagePath => File.Exists(imagePath) ? ImageReading.ReadImage(imagePath) : null))) { // Verify image sizes: if (images[0].Width % 16 != 0 || images[0].Height % 16 != 0) { throw new InvalidDataException($"Texture '{path}' width or height is not a multiple of 16."); } for (int i = 1; i < images.Count; i++) { if (images[i] != null && (images[i].Width != images[0].Width >> i || images[i].Height != images[0].Height >> i)) { throw new InvalidDataException($"Mipmap {i} for texture '{path}' width or height does not match texture size."); } } if (isDecalsWad) { return(CreateDecalTexture(textureName, images.ToArray(), textureSettings)); } var filename = Path.GetFileName(path); var isTransparentTexture = filename.StartsWith("{"); var isAnimatedTexture = AnimatedTextureNameRegex.IsMatch(filename); var isWaterTexture = filename.StartsWith("!"); // Create a suitable palette, taking special texture types into account: var transparencyThreshold = isTransparentTexture ? Clamp(textureSettings.TransparencyThreshold ?? 128, 0, 255) : 0; Func <Rgba32, bool> isTransparentPredicate = null; if (textureSettings.TransparencyColor != null) { var transparencyColor = textureSettings.TransparencyColor.Value; isTransparentPredicate = color => color.A < transparencyThreshold || (color.R == transparencyColor.R && color.G == transparencyColor.G && color.B == transparencyColor.B); } else { isTransparentPredicate = color => color.A < transparencyThreshold; } var colorHistogram = ColorQuantization.GetColorHistogram(images.Where(image => image != null), isTransparentPredicate); var maxColors = 256 - (isTransparentTexture ? 1 : 0) - (isWaterTexture ? 2 : 0); var colorClusters = ColorQuantization.GetColorClusters(colorHistogram, maxColors); // Always make sure we've got a 256-color palette (some tools can't handle smaller palettes): if (colorClusters.Length < maxColors) { colorClusters = colorClusters .Concat(Enumerable .Range(0, maxColors - colorClusters.Length) .Select(i => (new Rgba32(), new[] { new Rgba32() }))) .ToArray(); } // Make palette adjustments for special textures: if (isWaterTexture) { var fogColor = textureSettings.WaterFogColor ?? ColorQuantization.GetAverageColor(colorHistogram); var fogIntensity = new Rgba32((byte)Clamp(textureSettings.WaterFogColor?.A ?? (int)((1f - GetBrightness(fogColor)) * 255), 0, 255), 0, 0); colorClusters = colorClusters.Take(3) .Append((fogColor, new[] { fogColor })) // Slot 3: water fog color .Append((fogIntensity, new[] { fogIntensity })) // Slot 4: fog intensity (stored in red channel) .Concat(colorClusters.Skip(3)) .ToArray(); } if (isTransparentTexture) { var colorKey = new Rgba32(0, 0, 255); colorClusters = colorClusters .Append((colorKey, new[] { colorKey })) // Slot 255: used for transparent pixels .ToArray(); } // Create the actual palette, and a color index lookup cache: var palette = colorClusters .Select(cluster => cluster.Item1) .ToArray(); var colorIndexMappingCache = new Dictionary <Rgba32, int>(); for (int i = 0; i < colorClusters.Length; i++) { (_, var colors) = colorClusters[i]; foreach (var color in colors) { colorIndexMappingCache[color] = i; } } // Create any missing mipmaps: for (int i = 1; i < images.Count; i++) { if (images[i] == null) { images[i] = images[0].Clone(context => context.Resize(images[0].Width >> i, images[0].Height >> i)); } } // Create texture data: var textureData = images .Select(image => CreateTextureData(image, palette, colorIndexMappingCache, textureSettings, isTransparentPredicate, disableDithering: isAnimatedTexture)) .ToArray(); return(Texture.CreateMipmapTexture( name: textureName, width: images[0].Width, height: images[0].Height, imageData: textureData[0], palette: palette, mipmap1Data: textureData[1], mipmap2Data: textureData[2], mipmap3Data: textureData[3])); } }
/// <summary> /// Overridden ProcessRecord method. /// </summary> protected override void ProcessRecord() { if (ThreadId == -1 && ProcessId == -1) { IEnumerable<NtThread> threads = NtThread.GetThreads(Access); if (FilterScript == null) { WriteObject(threads); } else { using (var ths = new DisposableList<NtThread>(threads)) { WriteObject(ths.Where(t => ArbitraryFilter(t, FilterScript)).Select(t => t.Duplicate()).ToArray()); } } } else if (ProcessId != -1) { using (NtProcess process = NtProcess.Open(ProcessId, ProcessAccessRights.MaximumAllowed)) { WriteObject(process.GetThreads()); } } else { WriteObject(NtThread.Open(ThreadId, Access)); } }
/// <summary> /// Overridden ProcessRecord method. /// </summary> protected override void ProcessRecord() { switch (ParameterSetName) { case "infoonly": { if (ProcessId != -1) { WriteObject(QueryThreadInformation(ProcessId), true); } else { WriteObject(QueryThreadInformation(), true); } } break; case "current": WriteObject(GetCurrentThread(Access, PseudoHandle)); break; case "all": { IEnumerable <NtThread> threads = NtThread.GetThreads(Access, FromSystem); if (FilterScript == null) { WriteObject(threads, true); } else { using (var ths = new DisposableList <NtThread>(threads)) { WriteObject(ths.Where(t => ArbitraryFilter(t, FilterScript)).Select(t => t.Duplicate()).ToArray(), true); } } } break; case "pid": { using (NtProcess process = NtProcess.Open(ProcessId, ProcessAccessRights.MaximumAllowed)) { WriteObject(process.GetThreads(), true); } } break; case "tid": { if (ProcessId != -1) { WriteObject(NtThread.Open(ProcessId, ThreadId, Access)); } else { WriteObject(NtThread.Open(ThreadId, Access)); } } break; } }