public Result <string> GetLinkTarget() { var type = NtdllHelper.GetObjectType(Name); if (type != "SymbolicLink") { return(Result <string> .Failed("Not a symbolic link")); } var objectAttributes = new OBJECT_ATTRIBUTES(Name, 0); var status = Ntdll.NtOpenSymbolicLinkObject( out var linkHandle, ACCESS_MASK.GENERIC_READ, ref objectAttributes); if (status < 0) { return(Result <string> .Failed("Open file failed with status " + status)); } using (linkHandle) { var targetBuffer = new UNICODE_STRING(new string(' ', 512)); status = Ntdll.NtQuerySymbolicLinkObject( linkHandle, ref targetBuffer, out var len); return(status < 0 ? Result <string> .Failed("Query link failed with status " + status) : Result <string> .Succeeded(targetBuffer.ToString())); } }
public void GetObjectType_IsDirectory() { // test global namespace root Assert.Equal("Directory", NtdllHelper.GetObjectType(@"\")); // test ? on end of directory name Assert.Equal("Directory", NtdllHelper.GetObjectType(@"\GLOBAL??")); }
private static void Main(string[] args) { // default to root object namespace var objectName = @"\"; if (args.Length > 0) { objectName = args[0]; } var type = NtdllHelper.GetObjectType(objectName); WriteLine($"Object type {type}: {objectName}"); switch (type) { case "Directory": ListDirectoryContents(objectName); break; } }
public void GetObjectType_DoesNotExist() { Assert.Null(NtdllHelper.GetObjectType(@"\BlahFooBar")); }
public void GetObjectType_IsNotDirectory() { Assert.Equal("Device", NtdllHelper.GetObjectType(@"\clfs")); // test C: symlink - tricky for parsing C: name Assert.Equal("SymbolicLink", NtdllHelper.GetObjectType(@"\GLOBAL??\C:")); }