From ee00258ef3a5a2cfb1d74e1253c8062f103ec99a Mon Sep 17 00:00:00 2001 From: zc <2650838+Wack0@users.noreply.github.com> Date: Tue, 28 Mar 2023 17:45:20 +0100 Subject: [PATCH] examples: add C examples --- examples/DllImportExample.c | 52 +++++++++++++++++++++++++++++++++++++ examples/Format.c | 47 +++++++++++++++++++++++++++++++++ examples/HelloWorld.c | 43 ++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 examples/DllImportExample.c create mode 100644 examples/Format.c create mode 100644 examples/HelloWorld.c diff --git a/examples/DllImportExample.c b/examples/DllImportExample.c new file mode 100644 index 0000000..0ac5bea --- /dev/null +++ b/examples/DllImportExample.c @@ -0,0 +1,52 @@ +// Define the primitives/builtins. +typedef char s8; +typedef unsigned char u8; +typedef short s16; +typedef unsigned short u16; +typedef int s32; +typedef unsigned int u32; +typedef __int64 s64; +typedef unsigned __int64 u64; + +typedef __String PSTR; +typedef unsigned __String PWSTR; + +typedef u8 BYTE; +typedef u16 WORD; +typedef u32 DWORD; +typedef u64 QWORD; +typedef u8 BOOLEAN; + +typedef u32 NTSTATUS; +typedef s32 HRESULT; + +typedef void * PVOID; +typedef u32 IntPtr; + +typedef PVOID __attribute(__open) ArrOfConst[]; // array of const + +enum { + false = 0, + true = 1 +}; + +enum { + MB_OK = 0, + mbInformation = 0 +}; + +enum { + STATUS_UNSUCCESSFUL = 0xC0000001 +}; + +// Define imported external functions. +// Displays a message box. +static s32 __attribute(__internal) MsgBox(PWSTR Text, s32 Type, s32 Buttons); +// Ends the calling process and all its threads. +static void __attribute(__dll("kernelbase.dll", "ExitProcess")) __attribute(__stdcall) ExitProcess(u32 uExitCode); + +BOOLEAN InitializeUninstall() { + MsgBox(L"Hello IFPS world! Let's call ExitProcess()!", MB_OK, mbInformation); + ExitProcess(STATUS_UNSUCCESSFUL); + return false; +} \ No newline at end of file diff --git a/examples/Format.c b/examples/Format.c new file mode 100644 index 0000000..3486cfb --- /dev/null +++ b/examples/Format.c @@ -0,0 +1,47 @@ +// Define the primitives/builtins. +typedef char s8; +typedef unsigned char u8; +typedef short s16; +typedef unsigned short u16; +typedef int s32; +typedef unsigned int u32; +typedef __int64 s64; +typedef unsigned __int64 u64; + +typedef __String PSTR; +typedef unsigned __String PWSTR; + +typedef u8 BYTE; +typedef u16 WORD; +typedef u32 DWORD; +typedef u64 QWORD; +typedef u8 BOOLEAN; + +typedef u32 NTSTATUS; +typedef s32 HRESULT; + +typedef void * PVOID; +typedef u32 IntPtr; + +typedef PVOID __attribute(__open) ArrOfConst[]; // array of const + +enum { + false = 0, + true = 1 +}; + +enum { + MB_OK = 0, + mbInformation = 0 +}; + +// Define imported external functions. +// Formats the series of arguments in the open array Args. (basically equivalent to sprintf) +static PWSTR __attribute(__internal) Format(PWSTR Format, ArrOfConst Args); +// Displays a message box. +static s32 __attribute(__internal) MsgBox(PWSTR Text, s32 Type, s32 Buttons); + +BOOLEAN InitializeUninstall() { + MsgBox(Format(L"Hello %s %d", { L"world", 1337 }), MB_OK, mbInformation); + return false; +} \ No newline at end of file diff --git a/examples/HelloWorld.c b/examples/HelloWorld.c new file mode 100644 index 0000000..802f8c8 --- /dev/null +++ b/examples/HelloWorld.c @@ -0,0 +1,43 @@ +// Define the primitives/builtins. +typedef char s8; +typedef unsigned char u8; +typedef short s16; +typedef unsigned short u16; +typedef int s32; +typedef unsigned int u32; +typedef __int64 s64; +typedef unsigned __int64 u64; + +typedef __String PSTR; +typedef unsigned __String PWSTR; + +typedef u8 BYTE; +typedef u16 WORD; +typedef u32 DWORD; +typedef u64 QWORD; +typedef u8 BOOLEAN; + +typedef u32 NTSTATUS; +typedef s32 HRESULT; + +typedef void * PVOID; +typedef u32 IntPtr; + +enum { + false = 0, + true = 1 +}; + +enum { + MB_OK = 0, + mbInformation = 0 +}; + +// Define imported external functions. +// Displays a message box. +static s32 __attribute(__internal) MsgBox(PWSTR Text, s32 Type, s32 Buttons); + +BOOLEAN InitializeUninstall() { + MsgBox(L"Hello IFPS world!", MB_OK, mbInformation); + return false; +} \ No newline at end of file