]> localhost Git - pldh.git/commitdiff
Update README main
authormisomosi <[email protected]>
Tue, 7 May 2024 06:09:53 +0000 (02:09 -0400)
committermisomosi <[email protected]>
Tue, 7 May 2024 06:09:53 +0000 (02:09 -0400)
README.md
pld.h

index f11cef54f5b25526957410761f540442151e2d5e..59131fa5a760ec6619b24638ca7a1903b87bba6e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,57 @@
 # pld.h
 Functions and logging generally useful for preloads
 
+## Why Make This Header?
+
+I do a lot of preloads in general to debug and mess with applications.
+That makes it useful to have a quick and dirty header file I can just
+include in a single file in order to easily fetch loaded modules
+and get their respective functions.
+
+## Usage
+
+You can just include the header file in your preload main source file.
+All the functions in the header are static so keep that in mind when
+your preload spans multiple files.
+
+The following macros are defined to load libraries and symbols
+
+```
+PLD(name)
+* Use the library with this name when loading functions
+
+PLDH
+* PLD(name) defines a function with this name
+* You can use this macro to redefine the preloaded library if preloading multiple libraries
+
+PFNALTFIND(name, alt)
+* Use the type signature of the variable called "name", but use the string "alt" to look it up
+* This is useful for ordinals in Windows or typecasting in general
+
+PFNFIND(name)
+* Use both the string name and type signature of the variable called "name"
+* Equivalent to PFNALTFIND(name, #name)
+
+PFNALT(h, name, alt)
+* Like PFNALTFIND, but cache the result in a new static variable named via "h"
+
+PFN(h, name)
+* Like PFNFIND but cache the result in a new static variable named via "h"
+```
+
+Usages are in the ``examples`` directory
+
+## Why Use This Header?
+
+* Type signatures don't need to be typed out when hooking functions.
+* Saves boilerplate needed to load the libraries/functions while checking the return values.
+* Works with the Following Compilers
+  - MSVC
+  - GCC
+  - Clang
+  - TCC
+* Works with C and C++
+* Comes with logging using only ``write`` on POSIX or ``WriteFile`` on Windows by default
+  - Logging can be overridden to be another function or not even present, see ``write.c`` in ``examples``
+  - Not essential but it helps diagnose silly things like spelling errors very quickly.
 
diff --git a/pld.h b/pld.h
index a0eff069e57848cb17ce966558010b7abcfd1d29..03eadf5815f81cf92b1df353845920e909c1b14d 100644 (file)
--- a/pld.h
+++ b/pld.h
@@ -213,7 +213,7 @@ static PLD_LibHandle PLD_Private_dlopen_wrapper(const char *name)
 #define PFNALTFIND(name, alt) ((PLDTYPEOF(&name))PLD_Private_dlsym_wrapper(PLDH(), alt))\r
 #define PFNFIND(name) PFNALTFIND(name, #name)\r
 \r
-// Lazily load functions\r
+// Cache functions that are loaded\r
 #define PFNALT(h, name, alt)  \\r
        static PLDTYPEOF(&name) h = NULL; \\r
        if (h == NULL) h = PFNALTFIND(name, alt)\r