Comments (8)
signature scanning would be best approach. thank you, i am closing this issue.
from libmem.
I am not sure what do you mean by hooking methods in compile time, but there is an API for hooking vtables. There are no classes, because it is compatible with C, and there is no C++ specific version, only C/C++.
To hook a VMT:
lm_vmt_t some_object_vmt;
LM_VmtNew(*(lm_address_t **)some_object_addr, &some_object_vmt);
LM_VmtHook(&some_object_vmt, 0, hk_some_function); /* hook function of index 0 from some_object's VMT */
/* freeing the VMT */
LM_VmtFree(&some_object_vmt);
from libmem.
I am not sure what do you mean by hooking methods in compile time, but there is an API for hooking vtables. There are no classes, because it is compatible with C, and there is no C++ specific version, only C/C++. To hook a VMT:
lm_vmt_t some_object_vmt; LM_VmtNew(*(lm_address_t **)some_object_addr, &some_object_vmt); LM_VmtHook(&some_object_vmt, 0, hk_some_function); /* hook function of index 0 from some_object's VMT */ /* freeing the VMT */ LM_VmtFree(&some_object_vmt);
I didnt meant hooking in compile time (:, its about the get address of virtual method in compile time. So basically, if the index changed because of the main code refactored, test case will be healthy as not needed to change.
from libmem.
You can get the address of the function using LM_VmtGetOriginal
:
lm_vmt_t some_object_vmt;
lm_address_t orig_addr;
/* ... */
orig_addr = LM_VmtGetOriginal(&some_object_vmt, 5); /* get original function address at index 5 */
Also, if the index changed because of the main code refactored
- not sure what this means either, the index should never change, unless the class itself has changed (e.g they added a new virtual function before the one you're accessing) or at least that's my understanding of it.
from libmem.
You can get the address of the function using
LM_VmtGetOriginal
:lm_vmt_t some_object_vmt; lm_address_t orig_addr; /* ... */ orig_addr = LM_VmtGetOriginal(&some_object_vmt, 5); /* get original function address at index 5 */Also,
if the index changed because of the main code refactored
- not sure what this means either, the index should never change, unless the class itself has changed (e.g they added a new virtual function before the one you're accessing) or at least that's my understanding of it.
exactly you got correct.whenever they ( actually we since im not hacking some one else's memory :) ) added new virtual function, the test case shouldnt also need refactoring. so in the compile time, we can create a helper class to solve actual index of function ( or address )
from libmem.
If you want to get an index from the function address + object, I don't think C++ allows you to get the address of a virtual function. But assuming you got the address, should be something like this (untested):
lm_size_t get_function_index(lm_vmt_t *vmt, lm_address_t func_addr)
{
lm_size_t i;
lm_address_t addr = LM_ADDRESS_BAD;
for (;; ++i) {
addr = LM_VmtGetOriginal(vmt, i);
if (addr == func_addr)
break;
}
return i;
}
from libmem.
Yes, we can find the function index by bruteforcing checks by a loop if it is equals to address; but in the test cases you should write your code as easy to understand and you are right we are not able to get address of virtual method, but i bet compiler solving it at the compiling time and packs to code in that way. So, somehow we can get address or index at compiling time too. So it could be like this:
int index = lm_smth(Foo.Vmethod);
from libmem.
Yes, we can find the function index by bruteforcing checks by a loop if it is equals to address; but in the test cases you should write your code as easy to understand and you are right we are not able to get address of virtual method, but i bet compiler solving it at the compiling time and packs to code in that way. So, somehow we can get address or index at compiling time too. So it could be like this:
int index = lm_smth(Foo.Vmethod);
Again, if you have the function address, you can use the get_function_index
function I provided. Thing is, C++ itself does not allow you to get the address of a virtual method at compile time. So this functionality would not be possible.
Also, the code in the tests are just to make sure libmem works, the examples for users to read have their own folder (although it is lacking some more examples right now).
Best way is probably to just hardcode your indices and avoid changing them, or using signature scanning to find the function address, and then using the get_function_index
method to find the index.
from libmem.
Related Issues (20)
- Don't assume BSD == FreeBSD
- Declare all `LM_*` preprocessor definitions on build system instead of on source code HOT 2
- crates.io documentation link 404 HOT 2
- New internal layout HOT 3
- Investigate crash on Ubuntu and other glibc Linux distros HOT 1
- Remove LIEF HOT 1
- Fix GitHub Action getting stuck when assertion fails in Unit Test (Windows)
- Add table in README containing supported platforms, languages, etc HOT 1
- Remove injector library HOT 1
- Don't stop unit tests on first failure
- Consider using WMI to get the boot time on Windows
- Consider better typedef for lm_bool_t HOT 1
- Check if libkvm is actually necessary on FreeBSD HOT 1
- Test if `owner_pid` from `lm_thread_t` matches the actual process ID in Unit tests HOT 1
- Fix crash in `winutils.c` when attempting to convert strings with `NULL`
- Test `LM_EnumSymbols` for external processes
- Consider adding function to retrieve page size (and rewrite code that retrieves page size)
- Clean up files
- Do better cross compiling (remove `LIBMEM_ARCH` option)
- Remove mounting procfs in FreeBSD on README HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libmem.