Skip to content

How to hook a C function? #1523

Answered by cq674350529
fripSide asked this question in Q&A
Dec 25, 2024 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Hi, I tried with the minimal example you provided, and it worked.

def qiling_test():
    def my_hook(ql):
        print("Function hooked!")
    
    rootfs_path = "/home/xxx/workspace/git/qiling/examples/rootfs/x8664_linux"
    bin_path = "/home/xxx/main_elf"

    ql = Qiling([bin_path, "123"], rootfs_path, console=False, verbose=QL_VERBOSE.DISABLED)

    # image_base = ql.loader.load_address
    image_base = ql.loader.images[0].base
    ql.hook_address(my_hook, image_base + 0x118C)    # the first instruction address of main()

    ql.run()

The output is as follows.

~$ python3 qiling_demo.py 
Function hooked!
ret: 1

Q: What addresses should I pass to hook_address, the offset shown in IDA…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@fripSide
Comment options

@cq674350529
Comment options

@fripSide
Comment options

@fripSide
Comment options

@cq674350529
Comment options

Answer selected by fripSide
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy