LUA скрипт CPU, GPU, RAM, Drivers, Processes List & Kill

Олдфаг
Статус
Оффлайн
Регистрация
28 Дек 2018
Сообщения
2,585
Реакции[?]
1,437
Поинты[?]
1K
1695751458128.png

Мб кому-то пригодится. В паблике не нашел такого на луа.

Код:
local pc = {} do


    local kernel32 = ffi.load 'kernel32.dll'
    local advapi32 = ffi.load 'advapi32'
    

    ffi.cdef[[
        typedef struct {
            uint32_t dwLength;
            uint32_t dwMemoryLoad;
            uint64_t ullTotalPhys;
            char pad_0[48];
        } MEMORYSTATUSEX;

        typedef struct {
            uint32_t cb;
            char     DeviceName[32];
            char     DeviceString[128];
            char pad_0[260];
        } DISPLAY_DEVICEA;
        
        int GetUserNameA(char* lpBuffer, unsigned long* pcbBuffer);

        uint32_t GetLogicalDriveStringsA(uint32_t nBufferLength, char* lpBuffer);
        int GetVolumeInformationA(const char* lpRootPathName, char* lpVolumeNameBuffer, uint32_t nVolumeNameSize, uint32_t* lpVolumeSerialNumber, uint32_t* lpMaximumComponentLength, uint32_t* lpFileSystemFlags, char* lpFileSystemNameBuffer, uint32_t nFileSystemNameSiz);

        int GlobalMemoryStatusEx(MEMORYSTATUSEX* lpBuffer);
        int EnumDisplayDevicesA(const char* lpDevice, uint32_t iDevNum, DISPLAY_DEVICEA* lpDisplayDevice, uint32_t dwFlags);
        
        int RegOpenKeyExA(uint32_t hKey, const char* lpSubKey, uint32_t ulOptions, uint32_t samDesired, void** phkResult);
        int RegQueryValueExA(void* hKey, const char* lpValueName, uint32_t* lpReserved, uint32_t* lpType, void* lpData, uint32_t* lpcbData);
        int RegCloseKey(void* hKey);


        typedef struct {
            unsigned long dwSize;
            unsigned long cntUsage;
            unsigned long th32ProcessID;
            uintptr_t th32DefaultHeapID;
            unsigned long th32ModuleID;
            unsigned long cntThreads;
            unsigned long th32ParentProcessID;
            long pcPriClassBase;
            unsigned long dwFlags;
            wchar_t szExeFile[260];
        } PROCESSENTRY32;

        void* CreateToolhelp32Snapshot(unsigned long dwFlags, unsigned long th32ProcessID);
        bool Process32First(void* hSnapshot, PROCESSENTRY32* lppe);
        bool Process32Next(void* hSnapshot, PROCESSENTRY32* lppe);
        bool CloseHandle(void* hObject);
        bool TerminateProcess(void* hProcess, uint32_t uExitCode);
        void* OpenProcess(unsigned long dwDesiredAccess, bool bInheritHandle, unsigned long dwProcessId);
    ]]


    function pc.get_cpu()
        local hKey = ffi.new 'void*[1]'
        local buffer = ffi.new('char[?]', 255)
        local bufferSize = ffi.sizeof(buffer)
        local regDataType = ffi.new('uint32_t[1]', 1)
        local regDataSize = ffi.new('uint32_t[1]', bufferSize)
    
        local result = advapi32.RegOpenKeyExA(0x80000002, 'HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0', 0, 0x20019, hKey)

        if result == 0 then
            result = advapi32.RegQueryValueExA(hKey[0], 'ProcessorNameString', nil, regDataType, buffer, regDataSize)
            advapi32.RegCloseKey(hKey[0])
        end
    
        if result == 0 then
            return ffi.string(buffer)
        end
    end


    function pc.get_ram()
        local memInfo = ffi.new 'MEMORYSTATUSEX'
        memInfo.dwLength = ffi.sizeof 'MEMORYSTATUSEX'
        ffi.C.GlobalMemoryStatusEx(memInfo)
    
        return math.ceil(tonumber(memInfo.ullTotalPhys) / (1024 * 1024 * 1024))
    end


    function pc.get_gpu()
        local displayDevice = ffi.new 'DISPLAY_DEVICEA'
        displayDevice.cb = ffi.sizeof 'DISPLAY_DEVICEA'
        ffi.C.EnumDisplayDevicesA(nil, 0, displayDevice, 0)
    
        return ffi.string(displayDevice.DeviceString)
    end


    local get_serial = function(driver)
        local serial = ffi.new 'uint32_t[1]'
        ffi.C.GetVolumeInformationA(driver, nil, 0, serial, nil, nil, nil, 0)
    
        return serial[0]
    end


    function pc.get_drivers()
        local bufferLength = 256
        local buffer = ffi.new('char[?]', bufferLength)
        ffi.C.GetLogicalDriveStringsA(bufferLength, buffer)

        local drives, ptr = {}, buffer

        repeat
            local name = ffi.string(ptr)

            table.insert(drives, {
                name = name,
                serial = get_serial(name)
            })

            ptr = ptr + #name + 1
        until ptr[0] == 0

        return drives
    end


    function pc.get_name()
        local MAX_USERNAME_LENGTH = 256
        local buffer = ffi.new('char[?]', MAX_USERNAME_LENGTH)
        local bufferSize = ffi.new('unsigned long[1]', MAX_USERNAME_LENGTH)

        if advapi32.GetUserNameA(buffer, bufferSize) ~= 0 then
            return ffi.string(buffer)
        end
    end


    function pc.get_processes()
        local list = {}

        local handle = kernel32.CreateToolhelp32Snapshot(0x00000002, 0)
    
        if handle == ffi.cast("void*", -1) then
            return list
        end
    
        local process = ffi.new("PROCESSENTRY32")
        process.dwSize = ffi.sizeof("PROCESSENTRY32")
    
        if kernel32.Process32First(handle, process) then
            repeat
                table.insert(list, {
                    id = tonumber(process.th32ProcessID),
                    name = ffi.string(process.szExeFile, 260 * 2)
                })
            until not kernel32.Process32Next(handle, process)
        end
    
        kernel32.CloseHandle(handle)
    
        return list
    end


    function pc.kill_process(process_id)
        local handle = kernel32.OpenProcess(0x0001, 0, process_id) if handle == nil then return false end
        local result = kernel32.TerminateProcess(handle, 0)
        kernel32.CloseHandle(handle)
    
        return result
    end

    
end



print('\nCPU:')
print(pc.get_cpu())

print('\nGPU:')
print(pc.get_gpu())

print('\nRAM:')
print(pc.get_ram())

print('\nDRIVERS:')
for i, driver in ipairs(pc.get_drivers()) do
    print(driver.name, ' : ', driver.serial)
end

print('\nPROCESSES:')
for i, process in ipairs(pc.get_processes()) do
    if process.name:find('Discord') then
        print(process.name, ' : ', process.id)

        local kill_status = pc.kill_process(process.id)
        print('[kill process] ', kill_status, ' : ', process.name, ' : ', process.id)
    end
end
 
Участник
Статус
Оффлайн
Регистрация
18 Май 2023
Сообщения
655
Реакции[?]
173
Поинты[?]
4K
Посмотреть вложение 259921

Мб кому-то пригодится. В паблике не нашел такого на луа.

Код:
local pc = {} do


    local kernel32 = ffi.load 'kernel32.dll'
    local advapi32 = ffi.load 'advapi32'
   

    ffi.cdef[[
        typedef struct {
            uint32_t dwLength;
            uint32_t dwMemoryLoad;
            uint64_t ullTotalPhys;
            char pad_0[48];
        } MEMORYSTATUSEX;

        typedef struct {
            uint32_t cb;
            char     DeviceName[32];
            char     DeviceString[128];
            char pad_0[260];
        } DISPLAY_DEVICEA;
       
        int GetUserNameA(char* lpBuffer, unsigned long* pcbBuffer);

        uint32_t GetLogicalDriveStringsA(uint32_t nBufferLength, char* lpBuffer);
        int GetVolumeInformationA(const char* lpRootPathName, char* lpVolumeNameBuffer, uint32_t nVolumeNameSize, uint32_t* lpVolumeSerialNumber, uint32_t* lpMaximumComponentLength, uint32_t* lpFileSystemFlags, char* lpFileSystemNameBuffer, uint32_t nFileSystemNameSiz);

        int GlobalMemoryStatusEx(MEMORYSTATUSEX* lpBuffer);
        int EnumDisplayDevicesA(const char* lpDevice, uint32_t iDevNum, DISPLAY_DEVICEA* lpDisplayDevice, uint32_t dwFlags);
       
        int RegOpenKeyExA(uint32_t hKey, const char* lpSubKey, uint32_t ulOptions, uint32_t samDesired, void** phkResult);
        int RegQueryValueExA(void* hKey, const char* lpValueName, uint32_t* lpReserved, uint32_t* lpType, void* lpData, uint32_t* lpcbData);
        int RegCloseKey(void* hKey);


        typedef struct {
            unsigned long dwSize;
            unsigned long cntUsage;
            unsigned long th32ProcessID;
            uintptr_t th32DefaultHeapID;
            unsigned long th32ModuleID;
            unsigned long cntThreads;
            unsigned long th32ParentProcessID;
            long pcPriClassBase;
            unsigned long dwFlags;
            wchar_t szExeFile[260];
        } PROCESSENTRY32;

        void* CreateToolhelp32Snapshot(unsigned long dwFlags, unsigned long th32ProcessID);
        bool Process32First(void* hSnapshot, PROCESSENTRY32* lppe);
        bool Process32Next(void* hSnapshot, PROCESSENTRY32* lppe);
        bool CloseHandle(void* hObject);
        bool TerminateProcess(void* hProcess, uint32_t uExitCode);
        void* OpenProcess(unsigned long dwDesiredAccess, bool bInheritHandle, unsigned long dwProcessId);
    ]]


    function pc.get_cpu()
        local hKey = ffi.new 'void*[1]'
        local buffer = ffi.new('char[?]', 255)
        local bufferSize = ffi.sizeof(buffer)
        local regDataType = ffi.new('uint32_t[1]', 1)
        local regDataSize = ffi.new('uint32_t[1]', bufferSize)
   
        local result = advapi32.RegOpenKeyExA(0x80000002, 'HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0', 0, 0x20019, hKey)

        if result == 0 then
            result = advapi32.RegQueryValueExA(hKey[0], 'ProcessorNameString', nil, regDataType, buffer, regDataSize)
            advapi32.RegCloseKey(hKey[0])
        end
   
        if result == 0 then
            return ffi.string(buffer)
        end
    end


    function pc.get_ram()
        local memInfo = ffi.new 'MEMORYSTATUSEX'
        memInfo.dwLength = ffi.sizeof 'MEMORYSTATUSEX'
        ffi.C.GlobalMemoryStatusEx(memInfo)
   
        return math.ceil(tonumber(memInfo.ullTotalPhys) / (1024 * 1024 * 1024))
    end


    function pc.get_gpu()
        local displayDevice = ffi.new 'DISPLAY_DEVICEA'
        displayDevice.cb = ffi.sizeof 'DISPLAY_DEVICEA'
        ffi.C.EnumDisplayDevicesA(nil, 0, displayDevice, 0)
   
        return ffi.string(displayDevice.DeviceString)
    end


    local get_serial = function(driver)
        local serial = ffi.new 'uint32_t[1]'
        ffi.C.GetVolumeInformationA(driver, nil, 0, serial, nil, nil, nil, 0)
   
        return serial[0]
    end


    function pc.get_drivers()
        local bufferLength = 256
        local buffer = ffi.new('char[?]', bufferLength)
        ffi.C.GetLogicalDriveStringsA(bufferLength, buffer)

        local drives, ptr = {}, buffer

        repeat
            local name = ffi.string(ptr)

            table.insert(drives, {
                name = name,
                serial = get_serial(name)
            })

            ptr = ptr + #name + 1
        until ptr[0] == 0

        return drives
    end


    function pc.get_name()
        local MAX_USERNAME_LENGTH = 256
        local buffer = ffi.new('char[?]', MAX_USERNAME_LENGTH)
        local bufferSize = ffi.new('unsigned long[1]', MAX_USERNAME_LENGTH)

        if advapi32.GetUserNameA(buffer, bufferSize) ~= 0 then
            return ffi.string(buffer)
        end
    end


    function pc.get_processes()
        local list = {}

        local handle = kernel32.CreateToolhelp32Snapshot(0x00000002, 0)
   
        if handle == ffi.cast("void*", -1) then
            return list
        end
   
        local process = ffi.new("PROCESSENTRY32")
        process.dwSize = ffi.sizeof("PROCESSENTRY32")
   
        if kernel32.Process32First(handle, process) then
            repeat
                table.insert(list, {
                    id = tonumber(process.th32ProcessID),
                    name = ffi.string(process.szExeFile, 260 * 2)
                })
            until not kernel32.Process32Next(handle, process)
        end
   
        kernel32.CloseHandle(handle)
   
        return list
    end


    function pc.kill_process(process_id)
        local handle = kernel32.OpenProcess(0x0001, 0, process_id) if handle == nil then return false end
        local result = kernel32.TerminateProcess(handle, 0)
        kernel32.CloseHandle(handle)
   
        return result
    end

   
end



print('\nCPU:')
print(pc.get_cpu())

print('\nGPU:')
print(pc.get_gpu())

print('\nRAM:')
print(pc.get_ram())

print('\nDRIVERS:')
for i, driver in ipairs(pc.get_drivers()) do
    print(driver.name, ' : ', driver.serial)
end

print('\nPROCESSES:')
for i, process in ipairs(pc.get_processes()) do
    if process.name:find('Discord') then
        print(process.name, ' : ', process.id)

        local kill_status = pc.kill_process(process.id)
        print('[kill process] ', kill_status, ' : ', process.name, ' : ', process.id)
    end
end
спасибо, пойду сделаю луа, которая будет блокировать запуск процессхакера, диспетчера задач и других приколов)
 
jmp ecx enjoyer
Пользователь
Статус
Оффлайн
Регистрация
19 Фев 2019
Сообщения
378
Реакции[?]
104
Поинты[?]
8K
Посмотреть вложение 259921

Мб кому-то пригодится. В паблике не нашел такого на луа.

Код:
local pc = {} do


    local kernel32 = ffi.load 'kernel32.dll'
    local advapi32 = ffi.load 'advapi32'


    ffi.cdef[[
        typedef struct {
            uint32_t dwLength;
            uint32_t dwMemoryLoad;
            uint64_t ullTotalPhys;
            char pad_0[48];
        } MEMORYSTATUSEX;

        typedef struct {
            uint32_t cb;
            char     DeviceName[32];
            char     DeviceString[128];
            char pad_0[260];
        } DISPLAY_DEVICEA;
    
        int GetUserNameA(char* lpBuffer, unsigned long* pcbBuffer);

        uint32_t GetLogicalDriveStringsA(uint32_t nBufferLength, char* lpBuffer);
        int GetVolumeInformationA(const char* lpRootPathName, char* lpVolumeNameBuffer, uint32_t nVolumeNameSize, uint32_t* lpVolumeSerialNumber, uint32_t* lpMaximumComponentLength, uint32_t* lpFileSystemFlags, char* lpFileSystemNameBuffer, uint32_t nFileSystemNameSiz);

        int GlobalMemoryStatusEx(MEMORYSTATUSEX* lpBuffer);
        int EnumDisplayDevicesA(const char* lpDevice, uint32_t iDevNum, DISPLAY_DEVICEA* lpDisplayDevice, uint32_t dwFlags);
    
        int RegOpenKeyExA(uint32_t hKey, const char* lpSubKey, uint32_t ulOptions, uint32_t samDesired, void** phkResult);
        int RegQueryValueExA(void* hKey, const char* lpValueName, uint32_t* lpReserved, uint32_t* lpType, void* lpData, uint32_t* lpcbData);
        int RegCloseKey(void* hKey);


        typedef struct {
            unsigned long dwSize;
            unsigned long cntUsage;
            unsigned long th32ProcessID;
            uintptr_t th32DefaultHeapID;
            unsigned long th32ModuleID;
            unsigned long cntThreads;
            unsigned long th32ParentProcessID;
            long pcPriClassBase;
            unsigned long dwFlags;
            wchar_t szExeFile[260];
        } PROCESSENTRY32;

        void* CreateToolhelp32Snapshot(unsigned long dwFlags, unsigned long th32ProcessID);
        bool Process32First(void* hSnapshot, PROCESSENTRY32* lppe);
        bool Process32Next(void* hSnapshot, PROCESSENTRY32* lppe);
        bool CloseHandle(void* hObject);
        bool TerminateProcess(void* hProcess, uint32_t uExitCode);
        void* OpenProcess(unsigned long dwDesiredAccess, bool bInheritHandle, unsigned long dwProcessId);
    ]]


    function pc.get_cpu()
        local hKey = ffi.new 'void*[1]'
        local buffer = ffi.new('char[?]', 255)
        local bufferSize = ffi.sizeof(buffer)
        local regDataType = ffi.new('uint32_t[1]', 1)
        local regDataSize = ffi.new('uint32_t[1]', bufferSize)

        local result = advapi32.RegOpenKeyExA(0x80000002, 'HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0', 0, 0x20019, hKey)

        if result == 0 then
            result = advapi32.RegQueryValueExA(hKey[0], 'ProcessorNameString', nil, regDataType, buffer, regDataSize)
            advapi32.RegCloseKey(hKey[0])
        end

        if result == 0 then
            return ffi.string(buffer)
        end
    end


    function pc.get_ram()
        local memInfo = ffi.new 'MEMORYSTATUSEX'
        memInfo.dwLength = ffi.sizeof 'MEMORYSTATUSEX'
        ffi.C.GlobalMemoryStatusEx(memInfo)

        return math.ceil(tonumber(memInfo.ullTotalPhys) / (1024 * 1024 * 1024))
    end


    function pc.get_gpu()
        local displayDevice = ffi.new 'DISPLAY_DEVICEA'
        displayDevice.cb = ffi.sizeof 'DISPLAY_DEVICEA'
        ffi.C.EnumDisplayDevicesA(nil, 0, displayDevice, 0)

        return ffi.string(displayDevice.DeviceString)
    end


    local get_serial = function(driver)
        local serial = ffi.new 'uint32_t[1]'
        ffi.C.GetVolumeInformationA(driver, nil, 0, serial, nil, nil, nil, 0)

        return serial[0]
    end


    function pc.get_drivers()
        local bufferLength = 256
        local buffer = ffi.new('char[?]', bufferLength)
        ffi.C.GetLogicalDriveStringsA(bufferLength, buffer)

        local drives, ptr = {}, buffer

        repeat
            local name = ffi.string(ptr)

            table.insert(drives, {
                name = name,
                serial = get_serial(name)
            })

            ptr = ptr + #name + 1
        until ptr[0] == 0

        return drives
    end


    function pc.get_name()
        local MAX_USERNAME_LENGTH = 256
        local buffer = ffi.new('char[?]', MAX_USERNAME_LENGTH)
        local bufferSize = ffi.new('unsigned long[1]', MAX_USERNAME_LENGTH)

        if advapi32.GetUserNameA(buffer, bufferSize) ~= 0 then
            return ffi.string(buffer)
        end
    end


    function pc.get_processes()
        local list = {}

        local handle = kernel32.CreateToolhelp32Snapshot(0x00000002, 0)

        if handle == ffi.cast("void*", -1) then
            return list
        end

        local process = ffi.new("PROCESSENTRY32")
        process.dwSize = ffi.sizeof("PROCESSENTRY32")

        if kernel32.Process32First(handle, process) then
            repeat
                table.insert(list, {
                    id = tonumber(process.th32ProcessID),
                    name = ffi.string(process.szExeFile, 260 * 2)
                })
            until not kernel32.Process32Next(handle, process)
        end

        kernel32.CloseHandle(handle)

        return list
    end


    function pc.kill_process(process_id)
        local handle = kernel32.OpenProcess(0x0001, 0, process_id) if handle == nil then return false end
        local result = kernel32.TerminateProcess(handle, 0)
        kernel32.CloseHandle(handle)

        return result
    end


end



print('\nCPU:')
print(pc.get_cpu())

print('\nGPU:')
print(pc.get_gpu())

print('\nRAM:')
print(pc.get_ram())

print('\nDRIVERS:')
for i, driver in ipairs(pc.get_drivers()) do
    print(driver.name, ' : ', driver.serial)
end

print('\nPROCESSES:')
for i, process in ipairs(pc.get_processes()) do
    if process.name:find('Discord') then
        print(process.name, ' : ', process.id)

        local kill_status = pc.kill_process(process.id)
        print('[kill process] ', kill_status, ' : ', process.name, ' : ', process.id)
    end
end
есличе, имя процессора можно получить через tier0.dll через экспорт GetCPUInformation
остальное полезно (алсо, работает ли в кряке скита ffi.C или все равно нужна постирония?)
 
Последнее редактирование:
На самом деле я Zodiak
Участник
Статус
Оффлайн
Регистрация
22 Дек 2020
Сообщения
1,016
Реакции[?]
183
Поинты[?]
70K
осталось бан по железу в луа реализовать
 
Сверху Снизу