-
Notifications
You must be signed in to change notification settings - Fork 9
Add job objects support #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
Brovan/Core/Emulation/OS/Windows/Process/NtAssignProcessToJobObject.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using static Brovan.Core.Helpers.BinaryHelpers; | ||
|
|
||
| namespace Brovan.Core.Emulation.OS.Windows | ||
| { | ||
| internal class NtAssignProcessToJobObject : IWinSyscall | ||
| { | ||
| public NTSTATUS Handle(BinaryEmulator Instance) | ||
| { | ||
| if (Instance._binary.Architecture == BinaryArchitecture.x64) | ||
| { | ||
| ulong JobHandle = Instance.WinHelper.GetArg64(0); | ||
| ulong ProcessHandle = Instance.WinHelper.GetArg64(1); | ||
| return Instance.WinHelper.AssignProcessToJobHandle(JobHandle, ProcessHandle); | ||
| } | ||
|
|
||
| uint SP = Instance.ReadRegister32(Registers.UC_X86_REG_ESP); | ||
| uint JobHandle32 = Instance.ReadMemoryUInt(SP + 4); | ||
| uint ProcessHandle32 = Instance.ReadMemoryUInt(SP + 8); | ||
| return Instance.WinHelper.AssignProcessToJobHandle(JobHandle32, ProcessHandle32); | ||
| } | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
Brovan/Core/Emulation/OS/Windows/Process/NtCreateJobObject.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| using static Brovan.Core.Helpers.BinaryHelpers; | ||
|
|
||
| namespace Brovan.Core.Emulation.OS.Windows | ||
| { | ||
| internal class NtCreateJobObject : IWinSyscall | ||
| { | ||
| public NTSTATUS Handle(BinaryEmulator Instance) | ||
| { | ||
| if (Instance._binary.Architecture == BinaryArchitecture.x64) | ||
| { | ||
| ulong JobHandlePtr = Instance.WinHelper.GetArg64(0); | ||
| ulong DesiredAccess = (uint)Instance.WinHelper.GetArg64(1); | ||
| ulong ObjectAttributesPtr = Instance.WinHelper.GetArg64(2); | ||
|
|
||
| if (JobHandlePtr == 0) | ||
| return NTSTATUS.STATUS_INVALID_PARAMETER; | ||
|
|
||
| if (!Instance.IsRegionMapped(JobHandlePtr, 8)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| string Name = string.Empty; | ||
| if (ObjectAttributesPtr != 0) | ||
| { | ||
| if (!Instance.IsRegionMapped(ObjectAttributesPtr, 0x30)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| if (!StructSerializer.ParseStruct(Instance, ObjectAttributesPtr, out OBJECT_ATTRIBUTES64 ObjectAttrs)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| if (ObjectAttrs.ObjectName != 0 && !Instance.WinHelper.TryReadUnicodeString64(ObjectAttrs.ObjectName, out Name, out NTSTATUS NameStatus)) | ||
| return NameStatus; | ||
| } | ||
|
|
||
| WinHandle Handle = Instance.WinHelper.CreateJobHandle(Name, (AccessMask)(uint)DesiredAccess); | ||
| if (!Instance._emulator.WriteMemory(JobHandlePtr, Handle.Handle)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| return NTSTATUS.STATUS_SUCCESS; | ||
| } | ||
|
|
||
| uint SP = Instance.ReadRegister32(Registers.UC_X86_REG_ESP); | ||
| uint JobHandlePtr32 = Instance.ReadMemoryUInt(SP + 4); | ||
| uint DesiredAccess32 = Instance.ReadMemoryUInt(SP + 8); | ||
| uint ObjectAttributesPtr32 = Instance.ReadMemoryUInt(SP + 12); | ||
|
|
||
| if (JobHandlePtr32 == 0) | ||
| return NTSTATUS.STATUS_INVALID_PARAMETER; | ||
|
|
||
| if (!Instance.IsRegionMapped(JobHandlePtr32, 4)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| string Name32 = string.Empty; | ||
| if (ObjectAttributesPtr32 != 0) | ||
| { | ||
| if (!Instance.IsRegionMapped(ObjectAttributesPtr32, 0x18)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| uint ObjectNamePtr32 = Instance.ReadMemoryUInt(ObjectAttributesPtr32 + 0x08); | ||
| if (ObjectNamePtr32 != 0 && !Instance.WinHelper.TryReadUnicodeString32(ObjectNamePtr32, out Name32, out NTSTATUS NameStatus32)) | ||
| return NameStatus32; | ||
| } | ||
|
|
||
| WinHandle Handle32 = Instance.WinHelper.CreateJobHandle(Name32, (AccessMask)DesiredAccess32); | ||
| if (!Instance._emulator.WriteMemory(JobHandlePtr32, (uint)Handle32.Handle)) | ||
| return NTSTATUS.STATUS_ACCESS_VIOLATION; | ||
|
|
||
| return NTSTATUS.STATUS_SUCCESS; | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
Brovan/Core/Emulation/OS/Windows/Process/NtIsProcessInJob.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using System.Reflection.Metadata; | ||
| using static Brovan.Core.Helpers.BinaryHelpers; | ||
|
|
||
| namespace Brovan.Core.Emulation.OS.Windows | ||
| { | ||
| internal class NtIsProcessInJob : IWinSyscall | ||
| { | ||
| public NTSTATUS Handle(BinaryEmulator Instance) | ||
| { | ||
| if (Instance._binary.Architecture == BinaryArchitecture.x64) | ||
| { | ||
| ulong ProcessHandle = Instance.WinHelper.GetArg64(0); | ||
| ulong JobHandle = Instance.WinHelper.GetArg64(1); | ||
| if (!Instance.WinHelper.HandleExists(JobHandle)) | ||
| return NTSTATUS.STATUS_INVALID_HANDLE; | ||
| bool IsInJob = Instance.WinHelper.IsProcessInJob(ProcessHandle, JobHandle); | ||
| return IsInJob ? NTSTATUS.STATUS_PROCESS_IN_JOB : NTSTATUS.STATUS_SUCCESS; | ||
| } | ||
|
|
||
| uint SP = Instance.ReadRegister32(Registers.UC_X86_REG_ESP); | ||
| uint ProcessHandle32 = Instance.ReadMemoryUInt(SP + 4); | ||
| uint JobHandle32 = Instance.ReadMemoryUInt(SP + 8); | ||
| bool IsInJob32 = Instance.WinHelper.IsProcessInJob(ProcessHandle32, JobHandle32); | ||
| if (!Instance.WinHelper.HandleExists(JobHandle32)) | ||
| return NTSTATUS.STATUS_INVALID_HANDLE; | ||
| return IsInJob32 ? NTSTATUS.STATUS_PROCESS_IN_JOB : NTSTATUS.STATUS_SUCCESS; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.