-
-
Notifications
You must be signed in to change notification settings - Fork 256
Fix/#215 #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Fix/#215 #216
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cfdcdb8
Fix #215 & Disassembler test
acidicoala bfc5540
Fix #215 for general case
acidicoala 414a413
Fix asmjit warning
acidicoala b81d905
Ignore routine reading SP in `followJmp`
acidicoala 9c4b655
Remove duplicate size check
acidicoala 7118280
Refactored routine size check
acidicoala 593a349
Updated log message
acidicoala dd312de
Updated log message
acidicoala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,76 +1,76 @@ | ||
| #ifndef POLYHOOK_2_0_ILCALLBACK_HPP | ||
| #define POLYHOOK_2_0_ILCALLBACK_HPP | ||
| #pragma warning(push, 0) | ||
| #include <asmjit/asmjit.h> | ||
| #pragma warning( pop ) | ||
| #pragma warning( disable : 4200) | ||
| #include "polyhook2/PolyHookOs.hpp" | ||
| #include "polyhook2/ErrorLog.hpp" | ||
| #include "polyhook2/Enums.hpp" | ||
| #include "polyhook2/MemAccessor.hpp" | ||
| namespace PLH { | ||
| class ILCallback : public MemAccessor { | ||
| public: | ||
| struct Parameters { | ||
| template<typename T> | ||
| void setArg(const uint8_t idx, const T val) const { | ||
| *(T*)getArgPtr(idx) = val; | ||
| } | ||
| template<typename T> | ||
| T getArg(const uint8_t idx) const { | ||
| return *(T*)getArgPtr(idx); | ||
| } | ||
| // asm depends on this specific type | ||
| // we the ILCallback allocates stack space that is set to point here | ||
| volatile uint64_t m_arguments; | ||
| private: | ||
| // must be char* for aliasing rules to work when reading back out | ||
| char* getArgPtr(const uint8_t idx) const { | ||
| return ((char*)&m_arguments) + sizeof(uint64_t) * idx; | ||
| } | ||
| }; | ||
| struct ReturnValue { | ||
| unsigned char* getRetPtr() const { | ||
| return (unsigned char*)&m_retVal; | ||
| } | ||
| uint64_t m_retVal; | ||
| }; | ||
| typedef void(*tUserCallback)(const Parameters* params, const uint8_t count, const ReturnValue* ret); | ||
| ILCallback(); | ||
| ~ILCallback(); | ||
| /* Construct a callback given the raw signature at runtime. 'Callback' param is the C stub to transfer to, | ||
| where parameters can be modified through a structure which is written back to the parameter slots depending | ||
| on calling convention.*/ | ||
| uint64_t getJitFunc(const asmjit::FuncSignature& sig, const asmjit::Arch arch, const tUserCallback callback); | ||
| /* Construct a callback given the typedef as a string. Types are any valid C/C++ data type (basic types), and pointers to | ||
| anything are just a uintptr_t. Calling convention is defaulted to whatever is typical for the compiler you use, you can override with | ||
| stdcall, fastcall, or cdecl (cdecl is default on x86). On x64 those map to the same thing.*/ | ||
| uint64_t getJitFunc(const std::string& retType, const std::vector<std::string>& paramTypes, const asmjit::Arch arch, const tUserCallback callback, std::string callConv = ""); | ||
| uint64_t* getTrampolineHolder(); | ||
| private: | ||
| // does a given type fit in a general purpose register (i.e. is it integer type) | ||
| bool isGeneralReg(const asmjit::TypeId typeId) const; | ||
| // float, double, simd128 | ||
| bool isXmmReg(const asmjit::TypeId typeId) const; | ||
| asmjit::CallConvId getCallConv(const std::string& conv); | ||
| asmjit::TypeId getTypeId(const std::string& type); | ||
| uint64_t m_callbackBuf; | ||
| asmjit::x86::Mem argsStack; | ||
| // ptr to trampoline allocated by hook, we hold this so user doesn't need to. | ||
| uint64_t m_trampolinePtr; | ||
| }; | ||
| } | ||
| #endif // POLYHOOK_2_0_ILCALLBACK_HPP | ||
| #ifndef POLYHOOK_2_0_ILCALLBACK_HPP | ||
| #define POLYHOOK_2_0_ILCALLBACK_HPP | ||
|
|
||
| #pragma warning(push, 0) | ||
| #include <asmjit/x86.h> | ||
| #pragma warning( pop ) | ||
|
|
||
| #pragma warning( disable : 4200) | ||
| #include "polyhook2/PolyHookOs.hpp" | ||
| #include "polyhook2/ErrorLog.hpp" | ||
| #include "polyhook2/Enums.hpp" | ||
| #include "polyhook2/MemAccessor.hpp" | ||
|
|
||
| namespace PLH { | ||
| class ILCallback : public MemAccessor { | ||
| public: | ||
| struct Parameters { | ||
| template<typename T> | ||
| void setArg(const uint8_t idx, const T val) const { | ||
| *(T*)getArgPtr(idx) = val; | ||
| } | ||
|
|
||
| template<typename T> | ||
| T getArg(const uint8_t idx) const { | ||
| return *(T*)getArgPtr(idx); | ||
| } | ||
|
|
||
| // asm depends on this specific type | ||
| // we the ILCallback allocates stack space that is set to point here | ||
| volatile uint64_t m_arguments; | ||
| private: | ||
| // must be char* for aliasing rules to work when reading back out | ||
| char* getArgPtr(const uint8_t idx) const { | ||
| return ((char*)&m_arguments) + sizeof(uint64_t) * idx; | ||
| } | ||
| }; | ||
|
|
||
| struct ReturnValue { | ||
| unsigned char* getRetPtr() const { | ||
| return (unsigned char*)&m_retVal; | ||
| } | ||
| uint64_t m_retVal; | ||
| }; | ||
|
|
||
| typedef void(*tUserCallback)(const Parameters* params, const uint8_t count, const ReturnValue* ret); | ||
|
|
||
| ILCallback(); | ||
| ~ILCallback(); | ||
|
|
||
| /* Construct a callback given the raw signature at runtime. 'Callback' param is the C stub to transfer to, | ||
| where parameters can be modified through a structure which is written back to the parameter slots depending | ||
| on calling convention.*/ | ||
| uint64_t getJitFunc(const asmjit::FuncSignature& sig, const asmjit::Arch arch, const tUserCallback callback); | ||
|
|
||
| /* Construct a callback given the typedef as a string. Types are any valid C/C++ data type (basic types), and pointers to | ||
| anything are just a uintptr_t. Calling convention is defaulted to whatever is typical for the compiler you use, you can override with | ||
| stdcall, fastcall, or cdecl (cdecl is default on x86). On x64 those map to the same thing.*/ | ||
| uint64_t getJitFunc(const std::string& retType, const std::vector<std::string>& paramTypes, const asmjit::Arch arch, const tUserCallback callback, std::string callConv = ""); | ||
| uint64_t* getTrampolineHolder(); | ||
| private: | ||
| // does a given type fit in a general purpose register (i.e. is it integer type) | ||
| bool isGeneralReg(const asmjit::TypeId typeId) const; | ||
| // float, double, simd128 | ||
| bool isXmmReg(const asmjit::TypeId typeId) const; | ||
|
|
||
| asmjit::CallConvId getCallConv(const std::string& conv); | ||
| asmjit::TypeId getTypeId(const std::string& type); | ||
|
|
||
| uint64_t m_callbackBuf; | ||
| asmjit::x86::Mem argsStack; | ||
|
|
||
| // ptr to trampoline allocated by hook, we hold this so user doesn't need to. | ||
| uint64_t m_trampolinePtr; | ||
| }; | ||
| } | ||
| #endif // POLYHOOK_2_0_ILCALLBACK_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.