Created
March 16, 2018 10:04
-
-
Save juner/ac13d1340d127723e99e6e99e1134406 to your computer and use it in GitHub Desktop.
DirectShowのFilter情報をレジストリから取得するテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.Win32; | |
namespace ExampleProject | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
ReadMp4SplitterFilters(); | |
} | |
catch(Exception e) | |
{ | |
Console.WriteLine(e); | |
} | |
Console.ReadLine(); | |
} | |
/// <summary> | |
/// MP4スプリッターのfilterが入っているか確認する | |
/// </summary> | |
static void ReadMp4SplitterFilters() | |
{ | |
var DirectShowCLSID = new Guid("{083863f1-70de-11d0-bd40-00a0c911ce86}"); | |
var TargetFilters = new HashSet<Guid>() { new Guid("{3ccc052e-bdee-408a-bea7-90914ef2964b}"), new Guid("{61f47056-e400-43d3-af1e-ab7dffd4c4ad}") }; | |
var MP4_Splitter_Filters = Category.GetFilters(DirectShowCLSID).Where(c => TargetFilters.Contains(c.CLSID)).ToArray(); | |
if (TargetFilters.Count == MP4_Splitter_Filters.Length) | |
Console.WriteLine("Has MP4_Splitter Filters"); | |
else | |
Console.WriteLine("Has not MP4_Splitter Filters"); | |
foreach (var filter in MP4_Splitter_Filters) | |
Console.WriteLine($" {filter}"); | |
} | |
/// <summary> | |
/// DirectShowの<see cref="Category.Filter"/>を<see cref="Category"/>を取得せずに取得する | |
/// </summary> | |
static void ReadDirectShowFilterPattern2() | |
{ | |
var DirectShowCLSID = new Guid("{083863f1-70de-11d0-bd40-00a0c911ce86}"); | |
foreach (var filter in Category.GetFilters(DirectShowCLSID)) | |
Console.WriteLine($" {filter}"); | |
} | |
/// <summary> | |
/// DirectShowの<see cref="Category.Filter"/>を取得する | |
/// </summary> | |
static void ReadDirectShowFilterPattern1() | |
{ | |
var DirectShowCLSID = new Guid("{083863f1-70de-11d0-bd40-00a0c911ce86}"); | |
var DirectShow = Category.GetCategory(DirectShowCLSID); | |
foreach (var filter in DirectShow.GetFilters()) | |
Console.WriteLine($" {filter}"); | |
} | |
/// <summary> | |
/// 全ての<see cref="Category"/>とその<see cref="Category.Filter"/>を取得する | |
/// </summary> | |
static void ReadAllFilter() | |
{ | |
foreach (var category in Category.GetCategories()) | |
{ | |
Console.WriteLine($"{category}"); | |
foreach (var filter in category.GetFilters()) | |
Console.WriteLine($" {filter}"); | |
} | |
} | |
/// <summary> | |
/// カテゴリ | |
/// </summary> | |
public class Category | |
{ | |
/// <summary> | |
/// カテゴリ名 | |
/// </summary> | |
public string FriendlyName { get; set; } | |
/// <summary> | |
/// 固有のID | |
/// </summary> | |
public Guid CLSID { get; private set; } | |
private Category(Guid CLSID, string FriendlyName) | |
{ | |
this.FriendlyName = FriendlyName; | |
this.CLSID = CLSID; | |
} | |
public override string ToString() => | |
$"{nameof(Category)} {{" | |
+ $" {nameof(FriendlyName)}: {FriendlyName}" | |
+ $", {nameof(CLSID)}: {CLSID:B}" | |
+ $"}}"; | |
/// <summary> | |
/// カテゴリ一覧を取得する | |
/// </summary> | |
/// <returns></returns> | |
public static IEnumerable<Category> GetCategories() | |
{ | |
using (var Instance = Registry.ClassesRoot.OpenSubKey(@"CLSID\{DA4E3DA0-D07D-11d0-BD50-00A0C911CE86}\Instance", false)) | |
foreach (var subKeyName in Instance?.GetSubKeyNames() ?? Enumerable.Empty<string>()) | |
using (var subKey = Instance.OpenSubKey(subKeyName, false)) | |
{ | |
var FriendlyName = subKey.GetValue(nameof(Category.FriendlyName)) as string; | |
var CLSID = subKey.GetValue(nameof(Category.CLSID)) as string; | |
yield return new Category(Guid.Parse(CLSID), FriendlyName); | |
} | |
} | |
/// <summary> | |
/// カテゴリを取得する | |
/// </summary> | |
/// <param name="CLSID"></param> | |
/// <returns></returns> | |
public static Category GetCategory(Guid CLSID) | |
{ | |
using (var category = Registry.ClassesRoot.OpenSubKey($@"CLSID\{{DA4E3DA0-D07D-11d0-BD50-00A0C911CE86}}\Instance\{CLSID:B}", false)) | |
{ | |
if (category == null) | |
return null; | |
var FriendlyName = category.GetValue(nameof(Category.FriendlyName)) as string; | |
var _CLSID = category.GetValue(nameof(Category.CLSID)) as string; | |
return new Category(Guid.Parse(_CLSID), FriendlyName); | |
} | |
} | |
public IEnumerable<Filter> GetFilters() => GetFilters(CLSID); | |
public static IEnumerable<Filter> GetFilters(Guid CategoryCLSI) | |
{ | |
using (var Instance = Registry.ClassesRoot.OpenSubKey($@"CLSID\{CategoryCLSI:B}\Instance", false)) | |
foreach (var subKeyName in Instance?.GetSubKeyNames() ?? Enumerable.Empty<string>()) | |
using (var subKey = Instance.OpenSubKey(subKeyName, false)) | |
{ | |
var FilterData = subKey.GetValue(nameof(Filter.FilterData)) as byte[]; | |
var FriendlyName = subKey.GetValue(nameof(Filter.FriendlyName)) as string; | |
var CLSID = subKey.GetValue(nameof(Filter.CLSID)) as string; | |
yield return new Filter(Guid.Parse(CLSID), FriendlyName, FilterData); | |
} | |
} | |
/// <summary> | |
/// フィルタ | |
/// </summary> | |
public class Filter | |
{ | |
public byte[] FilterData { get; set; } | |
public string FriendlyName { get; set; } | |
public Guid CLSID { get; private set; } | |
internal Filter(Guid CLSID, string FriendlyName, byte[] FilterData) | |
{ | |
this.CLSID = CLSID; | |
this.FriendlyName = FriendlyName; | |
this.FilterData = FilterData; | |
SetDatas(); | |
} | |
/// <summary> | |
/// dll,ax等のファイル名 | |
/// </summary> | |
public string FileNameOfTheDLL { get; set; } | |
/// <summary> | |
/// スレッドモデル | |
/// </summary> | |
public string ThreadingModel { get; set; } | |
/// <summary> | |
/// 追加情報の取得 | |
/// </summary> | |
private void SetDatas() | |
{ | |
using (var Filter = Registry.ClassesRoot.OpenSubKey($@"CLSID\{CLSID:B}", false)) | |
{ | |
if (Filter == null) | |
return; | |
var FriendlyName = Filter.GetValue(null) as string; | |
using (var InprocServer32 = Filter.OpenSubKey("InprocServer32", false)) | |
{ | |
FileNameOfTheDLL = InprocServer32.GetValue(null) as string; | |
ThreadingModel = InprocServer32.GetValue(nameof(ThreadingModel)) as string; | |
} | |
} | |
} | |
public override string ToString() => | |
$"{nameof(Filter)} {{" | |
+ $" {nameof(FriendlyName)}: {FriendlyName}" | |
+ $", {nameof(CLSID)}: {CLSID:B}" | |
+ $", {nameof(FileNameOfTheDLL)}: {FileNameOfTheDLL}" | |
+ $", {nameof(ThreadingModel)}: {ThreadingModel}" | |
+ $", {nameof(FilterData)}: [{string.Join(",", FilterData?.Select(b => $"{b:X2}") ?? Enumerable.Empty<string>())}]" | |
+ $"}}"; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment