在研究了如何使用Powershell创建zip文件后,我发现了以下非常有用的链接,该链接描述了如何使用Powershell创建一个zip文件,其中包含以下脚本:
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
Run Code Online (Sandbox Code Playgroud)
这就像一个魅力,问题是我根本不明白它是如何工作的.我能否详细说明这是做什么的?
我在codeproject上找到了一些允许用户模拟的示例代码.
此代码通过导入以下非托管Win32 API函数来工作:
[DllImport("advapi32.dll", SetLastError = true)]
private static extern int LogonUser(
string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int DuplicateToken(IntPtr hToken,int impersonationLevel,ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool CloseHandle(IntPtr handle);
Run Code Online (Sandbox Code Playgroud)
这些函数用于模拟目标用户,然后执行某些操作,然后还原模拟上下文.冒充用户是这样实现的:
if ( LogonUser(userName, domainName, password, LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT, ref token ) != 0 )
{
if …Run Code Online (Sandbox Code Playgroud)