LibraryLoader.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #include "il2cpp-pinvoke-support.h"
  4. #include "utils/StringView.h"
  5. #include <string>
  6. #include "Baselib.h"
  7. #include "Cpp/Baselib_DynamicLibrary.h"
  8. #if !RUNTIME_TINY
  9. #include "Cpp/ReentrantLock.h"
  10. #include <vector>
  11. #include <string>
  12. #endif
  13. namespace il2cpp
  14. {
  15. namespace os
  16. {
  17. struct HardcodedPInvokeDependencyFunction
  18. {
  19. const char* functionName;
  20. Il2CppMethodPointer functionPointer;
  21. size_t functionNameLen;
  22. };
  23. struct HardcodedPInvokeDependencyLibrary
  24. {
  25. const Il2CppNativeChar* libraryName;
  26. size_t functionCount;
  27. const HardcodedPInvokeDependencyFunction* functions;
  28. };
  29. #define HARDCODED_DEPENDENCY_LIBRARY(libraryName, libraryFunctions) { libraryName, sizeof(libraryFunctions) / sizeof(HardcodedPInvokeDependencyFunction), libraryFunctions }
  30. #define HARDCODED_DEPENDENCY_FUNCTION(function) { #function, reinterpret_cast<Il2CppMethodPointer>(function), IL2CPP_ARRAY_SIZE(#function)-1 }
  31. class LibraryLoader
  32. {
  33. public:
  34. static Il2CppMethodPointer GetHardcodedPInvokeDependencyFunctionPointer(const il2cpp::utils::StringView<Il2CppNativeChar>& nativeDynamicLibrary, const il2cpp::utils::StringView<char>& entryPoint, Il2CppCharSet charSet);
  35. static Baselib_DynamicLibrary_Handle LoadDynamicLibrary(const utils::StringView<Il2CppNativeChar> nativeDynamicLibrary, std::string& detailedError);
  36. static Il2CppMethodPointer GetFunctionPointer(Baselib_DynamicLibrary_Handle handle, const PInvokeArguments& pinvokeArgs, std::string& detailedError);
  37. static Il2CppMethodPointer GetFunctionPointer(Baselib_DynamicLibrary_Handle handle, const char* functionName, std::string& detailedError);
  38. static void CleanupLoadedLibraries();
  39. static bool CloseLoadedLibrary(Baselib_DynamicLibrary_Handle handle);
  40. static void SetFindPluginCallback(Il2CppSetFindPlugInCallback method);
  41. static Baselib_DynamicLibrary_Handle TryOpeningLibrary(const Il2CppNativeChar* libraryName, std::string& detailedError);
  42. private:
  43. static Baselib_DynamicLibrary_Handle ProbeForLibrary(const Il2CppNativeChar* libraryName, const size_t libraryNameLength, std::string& detailedError);
  44. // needsClosing defaults to true, only set it to false when needed
  45. static Baselib_DynamicLibrary_Handle OpenProgramHandle(Baselib_ErrorState& errorState, bool& needsClosing);
  46. static const HardcodedPInvokeDependencyLibrary* HardcodedPInvokeDependencies;
  47. static const size_t HardcodedPInvokeDependenciesCount;
  48. static bool EntryNameMatches(const il2cpp::utils::StringView<char>& hardcodedEntryPoint, const il2cpp::utils::StringView<char>& entryPoint);
  49. };
  50. } /* namespace os */
  51. } /* namespace il2cpp*/