Skip to content

Commit

Permalink
Updated KnownDllsResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
daem0nc0re committed Feb 16, 2024
1 parent 13abd5b commit c12e5ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions SyscallResolvers/KnownDllsResolver/Interop/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static extern NTSTATUS NtMapViewOfSection(

[DllImport("ntdll.dll")]
public static extern NTSTATUS NtOpenSection(
ref IntPtr SectionHandle,
out IntPtr SectionHandle,
ACCESS_MASK DesiredAccess,
ref OBJECT_ATTRIBUTES ObjectAttributes);
in OBJECT_ATTRIBUTES ObjectAttributes);

[DllImport("ntdll.dll")]
public static extern NTSTATUS NtUnmapViewOfSection(
Expand Down
18 changes: 10 additions & 8 deletions SyscallResolvers/KnownDllsResolver/Library/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public static int ResolveSyscallNumber(string syscallName)
int nSyscallNumber = -1;
var hSection = IntPtr.Zero;
var objectPath = @"\KnownDlls\ntdll.dll";
var objectAttributes = new OBJECT_ATTRIBUTES(
objectPath,
OBJECT_ATTRIBUTES_FLAGS.OBJ_CASE_INSENSITIVE);

if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
{
Expand All @@ -33,10 +30,15 @@ public static int ResolveSyscallNumber(string syscallName)

Console.WriteLine("[>] Trying to get section handle to {0}.", objectPath);

ntstatus = NativeMethods.NtOpenSection(
ref hSection,
ACCESS_MASK.SECTION_MAP_READ,
ref objectAttributes);
using (var objectAttributes = new OBJECT_ATTRIBUTES(
objectPath,
OBJECT_ATTRIBUTES_FLAGS.OBJ_CASE_INSENSITIVE))
{
ntstatus = NativeMethods.NtOpenSection(
out hSection,
ACCESS_MASK.SECTION_MAP_READ,
in objectAttributes);
}

if (ntstatus != Win32Consts.STATUS_SUCCESS)
{
Expand Down Expand Up @@ -78,7 +80,7 @@ public static int ResolveSyscallNumber(string syscallName)

foreach (var entry in syscallTable)
{
if (entry.Key.IndexOf(syscallName, StringComparison.OrdinalIgnoreCase) >= 0)
if (entry.Key.IndexOf(syscallName, StringComparison.OrdinalIgnoreCase) == 0)
{
syscallName = entry.Key;
nSyscallNumber = entry.Value;
Expand Down

0 comments on commit c12e5ae

Please sign in to comment.