Skip to content

Commit 00789ec

Browse files
committed
tests: add detour code test
1 parent 05b0e05 commit 00789ec

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/test-detour-code.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local lunatest = require("tests.lunatest.lunatest")
2+
local rps = require("RPS")
3+
4+
local test_detour_code = {}
5+
6+
function test_detour_code.test_detourCode()
7+
local func1_code = { 0xB8, 0x02, 0x00, 0x00, 0x00, 0xBA, 0x03, 0x00, 0x00, 0x00, 0x0F, 0xAF, 0xC2, 0xC3 }
8+
local func1_address = rps.allocateCode(#func1_code)
9+
rps.writeCode(func1_address, func1_code)
10+
11+
local func1 = rps.exposeCode(func1_address, 0, 0) -- this call with 3 arguments
12+
13+
lunatest.assert_equal(6, func1())
14+
15+
rps.detourCode(function(registers)
16+
registers.EAX = 100
17+
return registers
18+
end, func1_address + 5, 5)
19+
20+
lunatest.assert_equal(300, func1())
21+
22+
end
23+
24+
return test_detour_code

0 commit comments

Comments
 (0)