Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/dllinject/libloader.h
Views: 11766
1/*2* libloader.h -- misc. defines for libloader3* Jarkko Turkulainen <jt[at]klake.org>4*5*/6789#include <stdio.h>10#include <windows.h>111213/* NTSTATUS values */1415#define STATUS_SUCCESS 0x0000000016#define STATUS_IMAGE_NOT_AT_BASE 0x40000003171819/* Time values */20#define HIGH_TIME 0x01C422FA21#define LOW_TIME_1 0x7E275CE022#define LOW_TIME_2 0x8E275CE023242526/* Some defines ripped off from DDK */2728typedef struct _FILE_BASIC_INFORMATION {29LARGE_INTEGER CreationTime;30LARGE_INTEGER LastAccessTime;31LARGE_INTEGER LastWriteTime;32LARGE_INTEGER ChangeTime;33ULONG FileAttributes;34} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;3536typedef enum _SECTION_INFORMATION_CLASS {37SectionBasicInformation,38SectionImageInformation39} SECTION_INFORMATION_CLASS;4041typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;4243typedef LONG NTSTATUS;44#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)4546typedef struct _IO_STATUS_BLOCK {47NTSTATUS Status;48ULONG Information;49} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;5051typedef struct _UNICODE_STRING {52USHORT Length;53USHORT MaximumLength;54#ifdef MIDL_PASS55[size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;56#else57PWSTR Buffer;58#endif59} UNICODE_STRING;60typedef UNICODE_STRING *PUNICODE_STRING;6162typedef struct _ANSI_STRING {63USHORT Length;64USHORT MaximumLength;65PWSTR Buffer;66} ANSI_STRING, *PANSI_STRING, STRING, *PSTRING;6768typedef enum _SECTION_INHERIT {69ViewShare = 1,70ViewUnmap = 271} SECTION_INHERIT;7273typedef struct _OBJECT_ATTRIBUTES {74ULONG Length;75HANDLE RootDirectory;76PUNICODE_STRING ObjectName;77ULONG Attributes;78PVOID SecurityDescriptor;79PVOID SecurityQualityOfService;80} OBJECT_ATTRIBUTES;81typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;828384/* Funtion definitions */8586/* kernel32 */87typedef VOID (WINAPI *f_ExitProcess)(UINT);88typedef DWORD (WINAPI *f_LoadLibrary)(LPCTSTR);89typedef FARPROC (WINAPI *f_GetProcAddress)(HMODULE, LPCTSTR);90typedef LPVOID (WINAPI *f_VirtualAlloc)(LPVOID, SIZE_T, DWORD, DWORD);91typedef BOOL (WINAPI *f_VirtualFree)(LPVOID, SIZE_T, DWORD);92typedef DWORD (WINAPI *f_VirtualQuery)(LPCVOID, PMEMORY_BASIC_INFORMATION, SIZE_T);93typedef BOOL (WINAPI *f_VirtualProtect)(LPVOID, SIZE_T, DWORD, PDWORD);94typedef BOOL (WINAPI *f_FlushInstructionCache)(HANDLE, LPCVOID, SIZE_T);95typedef BOOL (WINAPI *f_WriteProcessMemory)(HANDLE, LPVOID, LPCVOID, SIZE_T, SIZE_T *);9697/* ntdll */98typedef NTSTATUS (NTAPI *f_NtOpenSection)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);99typedef NTSTATUS (NTAPI *f_NtQueryAttributesFile)(POBJECT_ATTRIBUTES, PFILE_BASIC_INFORMATION);100typedef void (NTAPI *f_NtOpenFile)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES,101PIO_STATUS_BLOCK, ULONG ShareAccess, ULONG);102typedef NTSTATUS (NTAPI *f_NtCreateSection)(PHANDLE, ULONG, POBJECT_ATTRIBUTES, PLARGE_INTEGER,103ULONG, ULONG, HANDLE);104typedef NTSTATUS (NTAPI *f_NtMapViewOfSection)(HANDLE, HANDLE, PVOID *, ULONG, ULONG,105PLARGE_INTEGER, PULONG, SECTION_INHERIT, ULONG, ULONG);106107108/* ws2_32 */109typedef int (WINAPI *f_recv)(SOCKET, char *, int, int);110111112113/* Funtion hashes */114115/* kernel32 */116#define HASH_LoadLibraryA 0xec0e4e8e117#define HASH_GetProcAddress 0x7c0dfcaa118#define HASH_ExitProcess 0x73e2d87e119#define HASH_VirtualAlloc 0x91afca54120#define HASH_VirtualFree 0x030633ac121#define HASH_VirtualQuery 0xa3c8c8aa122#define HASH_VirtualProtect 0x7946c61b123#define HASH_FlushInstructionCache 0x53120980124#define HASH_WriteProcessMemory 0xd83d6aa1125126/* ntdll */127#define HASH_NtOpenSection 0x92b5dd95128#define HASH_NtQueryAttributesFile 0x494a7890129#define HASH_NtOpenFile 0x852974b8130#define HASH_NtCreateSection 0x5bb29bcb131#define HASH_NtMapViewOfSection 0xd5159b94132133/* ws2_32 */134#define HASH_recv 0xe71819b6135#define HASH_getpeername 0x95066ef2136137138139typedef struct _SHELLCODE_CTX {140141/* File descriptor */142SOCKET sd;143/* Library name */144char libname[256];145int liblen;146/* Global offset */147DWORD offset;148/* Allocated memory sections */149DWORD file_address;150DWORD mapped_address;151152/* Hook stub functions */153unsigned char s_NtOpenSection[10];154unsigned char s_NtQueryAttributesFile[10];155unsigned char s_NtOpenFile[10];156unsigned char s_NtCreateSection[10];157unsigned char s_NtMapViewOfSection[10];158/* Hooked functions */159DWORD NtOpenSection;160DWORD NtQueryAttributesFile;161DWORD NtOpenFile;162DWORD NtCreateSection;163DWORD NtMapViewOfSection;164165/* function pointers, kernel32 */166f_LoadLibrary LoadLibrary;167f_GetProcAddress GetProcAddress;168f_ExitProcess ExitProcess;169f_VirtualAlloc VirtualAlloc;170f_VirtualFree VirtualFree;171f_VirtualQuery VirtualQuery;172f_VirtualProtect VirtualProtect;173f_FlushInstructionCache FlushInstructionCache;174f_WriteProcessMemory WriteProcessMemory;175/* function pointers, ntdll */176f_NtOpenSection p_NtOpenSection;177f_NtQueryAttributesFile p_NtQueryAttributesFile;178f_NtOpenFile p_NtOpenFile;179f_NtCreateSection p_NtCreateSection;180f_NtMapViewOfSection p_NtMapViewOfSection;181/* function pointers, ws2_32 */182f_recv recv;183184185} SHELLCODE_CTX;186187188189190