Skip to content

Instantly share code, notes, and snippets.



Last active Oct 11, 2020
What would you like to do?
timeBeginPeriod inject
-- 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")
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 ="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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment