SymProcSleuth is a C implementation of the SymProcAddress
function, which is an alternative to the GetProcAddress
function for retrieving the address of a function within a module. This implementation is based on the original C++ code from the SymProcAddress repository by MzHmO. Special thanks to MzHmO for the original C++ implementation of SymProcAddress
, which served as the basis for SymProcSleuth.
The C version of the code, SymProcSleuth, introduces several differences and enhancements compared to the original C++ implementation:
- Language: The code has been translated from C++ to pure C, making it more portable and compatible with a wider range of systems and compilers.
- Struct-based Module Information: Instead of using C++-specific features like
std::map
, the C version utilizes a customModuleInfo
struct to store information about each processed module, including the module handle and a dynamically allocated array of function entries. - Dynamic Memory Allocation: The C version employs dynamic memory allocation using
malloc
,realloc
, andfree
to manage the storage of module information and function entries. This allows for flexibility in handling multiple modules and functions. - Callback Function: The
EnumSymbolsCallback
function is implemented as a regular C function instead of a lambda function. It is used as a callback for theSymEnumSymbols
function to process the enumerated symbols. - Multiple Module Enumeration: SymProcSleuth has been enhanced to handle multiple enumerations of the same module efficiently. It maintains a list of processed modules and checks if a module has already been processed before enumerating its symbols, avoiding duplicate entries.
- Error Handling: The C version includes proper error handling, setting the last error to
ERROR_PROC_NOT_FOUND
when a function is not found within a module. - Memory Management: SymProcSleuth provides a
FreeSymbols
function to free the dynamically allocated memory used for storing module information and function entries. This ensures proper cleanup and prevents memory leaks.
To compile the SymProcSleuth code, follow these steps:
-
Open a Visual Studio Developer Command Prompt.
-
Navigate to the directory containing the
SymProcSleuth.c
file. -
Run the following command to compile the code:
cl /EHsc SymProcSleuth.c /link dbghelp.lib
This command compiles the
SymProcSleuth.c
file with exception handling enabled (/EHsc
) and links against thedbghelp.lib
library.
-
Open a command prompt.
-
Navigate to the directory containing the
SymProcSleuth.c
file. -
Run the following command to compile the code:
gcc -o SymProcSleuth.exe SymProcSleuth.c -ldbghelp
This command compiles the
SymProcSleuth.c
file and links against thedbghelp
library, generating an executable namedSymProcSleuth.exe
.
Make sure you have the necessary compiler (Visual Studio or MinGW) installed and properly configured on your system. Additionally, ensure that the dbghelp.lib
library is available in your system's library search path.
After successful compilation, you can run the resulting executable (SymProcSleuth.exe
) to test the functionality of the SymProcAddress
function.
This code is released under the MIT License.
References:
https://github.com/MzHmO/SymProcAddress/blob/main/SymProcAddress/main.cpp