jmpews / Dobby

a lightweight, multi-platform, multi-architecture hook framework.
Apache License 2.0
3.89k stars 796 forks source link

NearMemoryAllocator::allocateNearBlock always print error log #202

Open LinzerLee opened 1 year ago

LinzerLee commented 1 year ago

Environment: RedHat 7.5 (x64)

I am using the lastest commit. When I call DobbyHook function, it always faild and print error log.

[!] [/home/Dobby/source/MemoryAllocator/NearMemoryAllocator.cc:198:allocateNearBlock][near memory allocator] allocate near block failed (0x8, 0x400e10, 0x80000000)
[!] [/home/Dobby/source/TrampolineBridge/Trampoline/x64/trampoline_x64.cc:22:allocate_indirect_stub]Not found near forward stub

In NearMemoryAllocator::allocateNearBlockFromDefaultAllocator and NearMemoryAllocator::allocateNearBlockFromUnusedRegion and method

min_valid_addr = pos - search_range;  // if pos < search_range, and min_valid_addr will be a large value,this maybe a bug
max_valid_addr = pos + search_range;

Modify according to the following example, it run normal:

min_valid_addr = pos >= search_range ? (pos - search_range) : 0;
gxosty commented 1 year ago

Got the same issue. Following @LinzerLee 's example solved the problem