Last active
October 11, 2020 13:59
-
-
Save MikuAuahDark/0f44f955e40e6c113b14bd94b2a2638f to your computer and use it in GitHub Desktop.
timeBeginPeriod inject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This code injects call to "timeBeginPeriod" to specified PID | |
-- Note that it's inadvisable to set the timer resolution | |
-- as it can affect battery life and your electricity bills. | |
-- Attribution to MikuAuahDark (me) is appreciated, but you can | |
-- use part or all of this code without my permission. | |
local ffi = require("ffi") | |
ffi.cdef[[ | |
int __stdcall timeBeginPeriod(uint32_t); | |
void* __stdcall CreateRemoteThread(void*, void*, size_t, void*, void*, uint32_t, uint32_t*); | |
void* __stdcall OpenProcess(uint32_t, int, uint32_t); | |
int __stdcall CloseHandle(void *handle); | |
]] | |
local pid = assert(tonumber((...)), "need PID to inject") | |
local resolution = tonumber((select(2, ...))) or 1 | |
-- 0x2 + 0x40 + 0x8 + 0x20 + 0x10 | |
local handle = ffi.C.OpenProcess(0x7A, false, pid) | |
assert(handle ~= nil, "Unable to open process") | |
local tid = ffi.new("uint32_t[1]") | |
local thread = ffi.C.CreateRemoteThread(handle, nil, 0, ffi.C.timeBeginPeriod, ffi.cast("void*", resolution), 0, tid) | |
if thread ~= nil then | |
print("tid = "..tid[0]) | |
end | |
ffi.C.CloseHandle(handle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment