No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LibraryLoader.h 2.7KB

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