Skip to content

Instantly share code, notes, and snippets.

@taozuhong
Created September 10, 2023 02:16
Show Gist options
  • Save taozuhong/79e43b23a3d0017a67415a5148252757 to your computer and use it in GitHub Desktop.
Save taozuhong/79e43b23a3d0017a67415a5148252757 to your computer and use it in GitHub Desktop.
Windows.vapi
/*
* Copyright(C) 2019-present taozuhong(https://github.com/taozuhong)
* Important:
* These functions are a part of the Kangaroo tool suite;
* Copyright Tao Zuhong. 2019-2023 All rights reserved.
*
* Author: Tao Zuhong
* Created: 9.10.2023
*/
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "windows.h")]
namespace Windows {
public void* _get_osfhandle(int fd);
public int _dup(int fd);
public int _dup2(int fd1, int fd2);
public int _close(int fd);
public int waitpid(int pid);
public void exit(int rc);
public ulong WaitForSingleObject(void* hHandle, ulong dwMilliseconds);
public int CloseHandle(void* hObject);
public uint GetLastError();
public uint FormatMessage(uint dwFlags, string lpSource, uint dwMessageId, uint dwLanguageId, uint8[] lpBuffer, va_list Arguments);
public void* WSACreateEvent();
public int WSAEventSelect(int socket, void* hEventObject, long lNetworkEvents);
public bool WSAResetEvent(void* hEventObject);
public struct FILETIME {
public uint dwLowDateTime;
public uint dwHighDateTime;
}
public uint CREATE_NO_WINDOW;
public uint DETACHED_PROCESS;
public uint CREATE_NEW_CONSOLE;
public uint INFINITE;
public uint NORMAL_PRIORITY_CLASS;
[CCode (cname = "SECURITY_ATTRIBUTES", has_type_id = false)]
public struct SecurityAttributes {
public uint nLength;
public void* lpSecurityDescriptor;
public int bInheritHandle;
}
[CCode (cname = "STARTUPINFOA", has_type_id = false)]
public struct StartupInfo {
public ulong cb;
public void* lpReserved;
public void* lpDesktop;
public void* lpTitle;
public ulong dwX;
public ulong dwY;
public ulong dwXSize;
public ulong dwYSize;
public ulong dwXCountChars;
public ulong dwYCountChars;
public ulong dwFillAttribute;
public ulong dwFlags;
public ushort wShowWindow;
public ushort cbReserved2;
public void* lpReserved2;
public void* hStdInput;
public void* hStdOutput;
public void* hStdError;
}
[CCode (cname = "PROCESS_INFORMATION", has_type_id = false)]
public struct ProcessInformation {
public void* hProcess;
public void* hThread;
public ulong dwProcessId;
public ulong dwThreadId;
}
[CCode (cname = "CreateProcessA")]
public int CreateProcess(
string? lpApplicationName,
string? lpCommandLine,
SecurityAttributes* lpProcessAttributes,
SecurityAttributes* lpThreadAttributes,
int bInheritHandles,
ulong dwCreationFlags,
void* lpEnvironment,
void* lpCurrentDirectory,
StartupInfo* lpStartupInfo,
ProcessInformation* lpProcessInformation
);
[CCode (cname = "SHELLEXECUTEINFOA", destroy_function = "", has_type_id = false)]
public struct ShellExecuteInfo {
public ulong cbSize;
public ulong fMask;
public void* hwnd;
public string lpVerb;
public string lpFile;
public string lpParameters;
public string lpDirectory;
public int nShow;
public void* hInstApp;
public void* lpIDList;
public string lpClass;
public void* hkeyClass;
public ulong dwHotKey;
[CCode (cname = "DUMMYUNIONNAME.hIcon")]
public void* hIcon;
[CCode (cname = "DUMMYUNIONNAME.hMonitor")]
public void* hMonitor;
public void* hProcess;
}
[CCode (cname = "unsigned long", cprefix = "COINIT_", has_type_id = false)]
public enum COINIT {
APARTMENTTHREADED,
MULTITHREADED,
DISABLE_OLE1DDE,
SPEED_OVER_MEMORY
}
[CCode (cname = "CoInitializeEx")]
public void* CoInitializeEx(
void* pvReserved,
ulong dwCoInit
);
[CCode (cname = "ShellExecuteExA")]
public int ShellExecuteEx(
ShellExecuteInfo* pExecInfo
);
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "windows.h,wincred.h")]
namespace Credential {
[CCode (cprefix = "CRED_TYPE_")]
public enum CredentialType
{
GENERIC = 1,
DOMAIN_PASSWORD,
DOMAIN_CERTIFICATE,
DOMAIN_VISIBLE_PASSWORD,
GENERIC_CERTIFICATE,
DOMAIN_EXTENDED,
MAXIMUM,
MAXIMUM_EX = MAXIMUM + 1000,
}
public struct ATTRIBUTEA {
string Keyword;
uint Flags;
uint ValueSize;
uint8[] Value;
}
[CCode (cname = "struct _CREDENTIALA", has_type_id = false, has_destroy_function = false)]
[Compact]
public struct CREDENTIALA
{
public uint Flags;
public CredentialType Type;
public string TargetName;
public string Comment;
public FILETIME LastWritten;
// public uint CredentialBlobSize;
[CCode (array_length_cname = "CredentialBlobSize", array_length_pos = "4.1")]
public uint8[] CredentialBlob;
public uint Persist;
public uint AttributeCount;
public void* Attributes;
public string TargetAlias;
public string UserName;
}
public int CredReadA(string target, CredentialType type, int reservedFlag, out void* pCredential);
public int CredWriteA(ref CREDENTIALA userCredential, uint32 flags);
public int CredDeleteA(string TargetName, CredentialType Type, uint Flags);
public int CredEnumerateA(string filter, int flag, out int count, out void** pCredentials);
public int CredFree(void* cred);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment