* fixed EnvironmentBlock.GetLength

* fixed CreateExtended, CSR notification is now optional; starting simple programs works!

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2010 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
wj32
2009-09-30 11:43:58 +00:00
parent 4e8aa8c6c4
commit 5fd079df21
3 changed files with 53 additions and 48 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ namespace ProcessHacker.Native
// Modify the process parameters pointer in the PEB.
processHandle.WriteMemory(
peb.Increment(Peb.ProcessParametersOffset),
newProcessParameters,
&newProcessParameters,
IntPtr.Size
);
}
@@ -57,7 +57,7 @@ namespace ProcessHacker.Native.Objects
public unsafe int GetLength()
{
byte* ptr = (byte*)_environment;
short* ptr = (short*)_environment;
while (*ptr != 0)
while (*ptr++ != 0)
@@ -148,6 +148,7 @@ namespace ProcessHacker.Native.Objects
fileName,
parentProcess,
creationFlags,
true,
inheritHandles,
EnvironmentBlock.GetCurrent(),
currentDirectory,
@@ -161,6 +162,7 @@ namespace ProcessHacker.Native.Objects
string fileName,
ProcessHandle parentProcess,
ProcessCreationFlags creationFlags,
bool notifyCsr,
bool inheritHandles,
EnvironmentBlock environment,
string currentDirectory,
@@ -236,60 +238,63 @@ namespace ProcessHacker.Native.Objects
// Notify CSR.
BaseCreateProcessMsg processMsg = new BaseCreateProcessMsg();
processMsg.ProcessHandle = phandle;
processMsg.ThreadHandle = thandle;
processMsg.ClientId = clientId;
processMsg.CreationFlags = creationFlags;
if ((creationFlags & (ProcessCreationFlags.DebugProcess |
ProcessCreationFlags.DebugOnlyThisProcess)) != 0)
if (notifyCsr)
{
NtStatus status;
BaseCreateProcessMsg processMsg = new BaseCreateProcessMsg();
status = Win32.DbgUiConnectToDbg();
processMsg.ProcessHandle = phandle;
processMsg.ThreadHandle = thandle;
processMsg.ClientId = clientId;
processMsg.CreationFlags = creationFlags;
if (status >= NtStatus.Error)
if ((creationFlags & (ProcessCreationFlags.DebugProcess |
ProcessCreationFlags.DebugOnlyThisProcess)) != 0)
{
phandle.Terminate(status);
Win32.ThrowLastError(status);
NtStatus status;
status = Win32.DbgUiConnectToDbg();
if (status >= NtStatus.Error)
{
phandle.Terminate(status);
Win32.ThrowLastError(status);
}
processMsg.DebuggerClientId = ThreadHandle.GetCurrentCid();
}
processMsg.DebuggerClientId = ThreadHandle.GetCurrentCid();
}
// If this is a GUI program, set the 1 and 2 bits to turn the
// hourglass cursor on.
if (imageInfo.ImageSubsystem == 2)
processMsg.ProcessHandle = processMsg.ProcessHandle.Or((1 | 2).ToIntPtr());
// We still have to honor the startup info settings, though.
if ((startupInfo.Flags & StartupFlags.ForceOnFeedback) ==
StartupFlags.ForceOnFeedback)
processMsg.ProcessHandle = processMsg.ProcessHandle.Or((1).ToIntPtr());
if ((startupInfo.Flags & StartupFlags.ForceOffFeedback) ==
StartupFlags.ForceOffFeedback)
processMsg.ProcessHandle = processMsg.ProcessHandle.And((1).ToIntPtr().Not());
// If this is a GUI program, set the 1 and 2 bits to turn the
// hourglass cursor on.
if (imageInfo.ImageSubsystem == 2)
processMsg.ProcessHandle = processMsg.ProcessHandle.Or((1 | 2).ToIntPtr());
// We still have to honor the startup info settings, though.
if ((startupInfo.Flags & StartupFlags.ForceOnFeedback) ==
StartupFlags.ForceOnFeedback)
processMsg.ProcessHandle = processMsg.ProcessHandle.Or((1).ToIntPtr());
if ((startupInfo.Flags & StartupFlags.ForceOffFeedback) ==
StartupFlags.ForceOffFeedback)
processMsg.ProcessHandle = processMsg.ProcessHandle.And((1).ToIntPtr().Not());
using (var data = new MemoryAlloc(
CsrApiMsg.ApiMessageDataOffset + Marshal.SizeOf(typeof(BaseCreateProcessMsg))
))
{
data.WriteStruct<BaseCreateProcessMsg>(CsrApiMsg.ApiMessageDataOffset, 0, processMsg);
Win32.CsrClientCallServer(
data,
IntPtr.Zero,
Win32.CsrMakeApiNumber(Win32.BaseSrvServerDllIndex, (int)BaseSrvApiNumber.BasepCreateProcess),
Marshal.SizeOf(typeof(BaseCreateProcessMsg))
);
NtStatus status = (NtStatus)data.ReadStruct<CsrApiMsg>().ReturnValue;
if (status >= NtStatus.Error)
using (var data = new MemoryAlloc(
CsrApiMsg.ApiMessageDataOffset + Marshal.SizeOf(typeof(BaseCreateProcessMsg))
))
{
phandle.Terminate(status);
Win32.ThrowLastError(status);
data.WriteStruct<BaseCreateProcessMsg>(CsrApiMsg.ApiMessageDataOffset, 0, processMsg);
Win32.CsrClientCallServer(
data,
IntPtr.Zero,
Win32.CsrMakeApiNumber(Win32.BaseSrvServerDllIndex, (int)BaseSrvApiNumber.BasepCreateProcess),
Marshal.SizeOf(typeof(BaseCreateProcessMsg))
);
NtStatus status = (NtStatus)data.ReadStruct<CsrApiMsg>().ReturnValue;
if (status >= NtStatus.Error)
{
phandle.Terminate(status);
Win32.ThrowLastError(status);
}
}
}