Skip to content

Instantly share code, notes, and snippets.

@adon90
Created July 23, 2018 09:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adon90/2dceb8e6597d1e5daee29a84111d9279 to your computer and use it in GitHub Desktop.
Save adon90/2dceb8e6597d1e5daee29a84111d9279 to your computer and use it in GitHub Desktop.
"@
Add-Type -TypeDefinition @"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class GetAddress
{
[DllImport("kernel32", SetLastError=true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary(
[MarshalAs(UnmanagedType.LPStr)]string lpFileName);
[DllImport("kernel32", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true)]
public static extern IntPtr GetProcAddress(
IntPtr hModule,
string procName);
}
"@
$library = [GetAddress]::LoadLibrary("c:\windows\system32\kernel32")
$address = [GetAddress]::GetProcAddress($library, "WinExec")
"0x$("{0:X16}" -f $address.ToInt64())"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment