我将学习如何在C#中处理作为服务器端的HTTPS流量,并且在第一步中我遇到了一些麻烦.
这是一些代码(http://pastebin.com/C4ZYrS8Q):
class Program
{
static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None) return true;
Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
return false;
}
static void Main()
{
var tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080);
tcpListener.Start();
var clientAccept = tcpListener.AcceptTcpClient();
Thread.Sleep(1000);
if (clientAccept.Available > 0)
{
var sslStream = new SslStream(clientAccept.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
var certificate = new X509Certificate("path\server.pfx", "password");
sslStream.AuthenticateAsServer(certificate);
}
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
不要争辩!:)这只是测试代码,我只想在C#中实现SSL处理的一些基本步骤.
所以......问题发生在这一行:
sslStream.AuthenticateAsServer(certificate);
Run Code Online (Sandbox Code Playgroud)

从俄语翻译为: - SSL服务器模式必须使用具有相应私钥的证书.
我想,我的X509证书不正确,但再次检查:
makecert.exe …Run Code Online (Sandbox Code Playgroud) 如何在windbg中找出哪个主题是我的事件句柄的所有者:
我在跑
!handle 00003aec f
Run Code Online (Sandbox Code Playgroud)
得到
Handle 00003aec
Type Event
Attributes 0
GrantedAccess 0x1f0003:
Delete,ReadControl,WriteDac,WriteOwner,Synch
QueryState,ModifyState
HandleCount 2
PointerCount 4
Name <none>
No object specific information available
Run Code Online (Sandbox Code Playgroud)
回来了,因为没有名字,我还没弄明白如何让主人出来证明我的线程正在等待哪个线程
[编辑]我必须对转储工作,因为原始进程需要在用户计算机上重新启动,因此无法调试实时会话
到目前为止我发现的关于这个主题的最好的讨论是在这个博客上,但不幸的是我们最终使用了不同的锁方法(我最终使用WaitForMultipleObjectsEx,描述是针对WaitForSingleObject),他似乎可以访问实时进程
我的线程的堆栈跟踪(被阻塞的东西以及我正在寻找当前所有者的那个)是:
0:045> k9
ChildEBP RetAddr
1130e050 7c90e9ab ntdll!KiFastSystemCallRet
1130e054 7c8094e2 ntdll!ZwWaitForMultipleObjects+0xc
1130e0f0 79ed98fd kernel32!WaitForMultipleObjectsEx+0x12c
1130e158 79ed9889 mscorwks!WaitForMultipleObjectsEx_SO_TOLERANT+0x6f
1130e178 79ed9808 mscorwks!Thread::DoAppropriateAptStateWait+0x3c
1130e1fc 79ed96c4 mscorwks!Thread::DoAppropriateWaitWorker+0x13c
1130e24c 79ed9a62 mscorwks!Thread::DoAppropriateWait+0x40
1130e2a8 79e78944 mscorwks!CLREvent::WaitEx+0xf7
1130e2bc 7a162d84 mscorwks!CLREvent::Wait+0x17
1130e33c 7a02fd94 mscorwks!CRWLock::RWWaitForSingleObject+0x6d
1130e364 79ebd3af mscorwks!CRWLock::StaticAcquireWriterLock+0x12e
1130e410 00f24557 mscorwks!CRWLock::StaticAcquireWriterLockPublic+0xc9
Run Code Online (Sandbox Code Playgroud) 我想写/删除文件,但有时如果该文件被另一个程序使用,我会崩溃.如何检查文件是否由其他进程打开,或者我可以打开它进行写入?
如何获取使用给定文件名和互斥锁名称的进程的PID?(不是通过自定义内核驱动程序,而是在用户模式下的C#中.)
这个"简单"问题似乎充满了侧面问题.
例如.新进程是否打开了多个窗口; 它有闪屏吗?
有一个简单的方法吗?(我正在开始一个新的Notepad ++实例)
...
std::tstring tstrNotepad_exe = tstrProgramFiles + _T("\\Notepad++\\notepad++.exe");
SHELLEXECUTEINFO SEI={0};
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.hwnd = hWndMe; // This app's window handle
sei.lpVerb = _T("open");
sei.lpFile = tstrNotepad_exe.c_str();
sei.lpParameters = _T(" -multiInst -noPlugins -nosession -notabbar ";
sei.lpDirectory = NULL;
sei.nShow = SW_SHOW;
sei.hInstApp = NULL;
if( ShellExecuteEx(&sei) )
{ // I have sei.hProcess, but how best to utilize it from here?
}
...
Run Code Online (Sandbox Code Playgroud) 我一直在阅读IntPtr,并已阅读它用于表示句柄.这究竟是什么意思?我确信这是一个简单的解释,但是灯泡现在还没有打开..
在.NET进程的生命周期中,a的句柄是否System.Windows.Forms.Form可以说Application.Run(form)实际使用的主表单更改了它的值,即如果在不同的进程中使用句柄的值,例如IntPtr handle = User32.FindWindow(null, "Name"),是否存在该句柄可能的情况是否被.NET运行时失效?
编辑
我需要知道的把手,因为我想用SendMessage和WM_COPYDATA等以IPC.
正如我在上一个问题的答案中所建议的那样,我使用ProcessExplorer来分析我的应用程序用来查找句柄泄漏的句柄列表.
泄漏的句柄属于Section类型.
什么是截面句柄,它在哪里使用以及什么可能导致截面手柄泄漏?
我没有在我的代码中使用内存映射文件.
不幸的是,Chrome没有纯静音打印(Firefox不是一个选项),因此当您添加--kiosk-printing时,Chrome中会有一些恼人的~1秒闪屏.我有一个想法,如果我们添加这个参数:--disable-print-preview到Chrome和系统打印对话框出现是否有任何工具可以在后台运行并单击打印按钮为你这么快,你不会看到它?
我有2个应用程序,program.exe和updater.exe,都是用Delphi5编写的.程序在没有admin-rights(并且没有manifest)的情况下运行,updater有一个带有"requireAdministrator"的清单,因为他必须能够在Program-Folder中写入以更新program.exe.
问题是启动更新程序,让他等到程序关闭.我在网上找到了不同的方式,但都没有用(大多数情况下,第一个应用程序启动第二个应用程序并等待第二个应用程序的结束,在我的情况下,第二个应用程序应该等待第一个应用程序的结束).
更新程序应该等待,这很容易
updater.exe
{$R manifest.res}
label.caption:='Wait for program.exe closing';
repeat
sleep(1000);
until File is not open
ProgramHandle := Read Handle from File
WaitForSingleObject(ProgramHandle,INFINITE);
label.caption:='program.exe CLOSED';
Do updates
Run Code Online (Sandbox Code Playgroud)
方法1
使用CreateProcess启动更新程序:
program.exe
FillChar(siInfo, SizeOf(siInfo), 0);
siInfo.cb := SizeOf(siInfo);
saProcessAttributes.nLength := SizeOf(saProcessAttributes);
saProcessAttributes.lpSecurityDescriptor := nil;
saProcessAttributes.bInheritHandle := TRUE;
saThreadAttributes.nLength := SizeOf(saThreadAttributes);
saThreadAttributes.lpSecurityDescriptor := nil;
saThreadAttributes.bInheritHandle := True;
if CreateProcess(nil,
PChar('updater.exe'),
@saProcessAttributes,
@saThreadAttributes,
TRUE, NORMAL_PRIORITY_CLASS, nil,
PChar(ExtractFilePath(Application.ExeName)),
siInfo, piInfo) then
begin
DuplicateHandle(GetCurrentProcess, GetCurrentProcess,
piInfo.hProcess, @MyHandle,
PROCESS_QUERY_INFORMATION, TRUE,
DUPLICATE_SAME_ACCESS) then
Write MyHandle in a …Run Code Online (Sandbox Code Playgroud) delphi createprocess handle waitforsingleobject shellexecuteex