Skip to content

Use non-nightly with unsafe extern "system" fn #37

Answered by Roms1383
Roms1383 asked this question in Q&A
Discussion options

You must be logged in to vote

(most likely) library is loaded in different position: libraries get loaded dynamically at runtime and don't have the same address every time. You have to use OS functions at runtime to get the start address of the library and add the offset to the function.

indeed I'm on Windows and needed:

  • GetModuleHandleW to get base address at runtime and cast its result as a usize
  • add function relative address as a usize too which turns out being 0x1419130 instead

    0x141419130 takes into account base 0x14000... (found in e.g. IDA: the very beginning of binary)

  • use RawDetour to avoid relying on nightly
  • I also thought function was unsafe extern "system" fn(u64, u64) -> bool while it's actually uns…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@Roms1383
Comment options

Comment options

You must be logged in to vote
1 reply
@Roms1383
Comment options

Answer selected by Roms1383
Comment options

You must be logged in to vote
1 reply
@Roms1383
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants