-
-
Notifications
You must be signed in to change notification settings - Fork 99
fix: undetected games when ran with administrator #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
farhannz
wants to merge
5
commits into
OpenAsar:main
Choose a base branch
from
farhannz:win32_games_detector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8bde751
initial commit for windows game detector
farhannz 85f999f
Update win32.js
farhannz 63f8832
fix null imagename
farhannz cd14338
Merge branch 'OpenAsar:main' into win32_games_detector
farhannz 0f22e14
Merge branch 'OpenAsar:main' into win32_games_detector
farhannz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 file contains hidden or 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 file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,88 @@ | ||||||||||||||||
| import { exec } from 'child_process'; | ||||||||||||||||
|
|
||||||||||||||||
| export const getProcesses = () => new Promise(res => exec(`wmic process get ProcessID,ExecutablePath /format:csv`, (e, out) => { | ||||||||||||||||
| res(out.toString().split('\r\n').slice(2).map(x => { | ||||||||||||||||
| const parsed = x.trim().split(',').slice(1).reverse(); | ||||||||||||||||
| return [ parseInt(parsed[0]) || parsed[0], parsed[1] ]; | ||||||||||||||||
| }).filter(x => x[1])); | ||||||||||||||||
| })); | ||||||||||||||||
| import koffi from 'koffi'; | ||||||||||||||||
|
|
||||||||||||||||
| // Load Windows API | ||||||||||||||||
| const psapi = koffi.load('psapi.dll'); | ||||||||||||||||
| const kernel32 = koffi.load('kernel32.dll'); | ||||||||||||||||
| const ntdll = koffi.load('ntdll.dll'); | ||||||||||||||||
|
|
||||||||||||||||
| // Define Alias | ||||||||||||||||
| const DWORD = koffi.alias('DWORD', 'uint32_t'); | ||||||||||||||||
| const BOOL = koffi.alias('BOOL', 'int32_t'); | ||||||||||||||||
| const HANDLE = koffi.pointer('HANDLE', koffi.opaque()) | ||||||||||||||||
|
|
||||||||||||||||
| const UNICODE_STRING = koffi.struct('UNICODE_STRING', { | ||||||||||||||||
| Length: 'uint16', | ||||||||||||||||
| MaximumLength: 'uint16', | ||||||||||||||||
| Buffer: HANDLE | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| const SYSTEM_PROCESS_ID_INFORMATION = koffi.struct('SYSTEM_PROCESS_ID_INFORMATION', { | ||||||||||||||||
| ProcessId: HANDLE, | ||||||||||||||||
| ImageName: UNICODE_STRING | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| const EnumProcesses = psapi.func('BOOL __stdcall EnumProcesses(_Out_ DWORD *lpidProcess, DWORD cb, _Out_ DWORD *lpcbNeeded)') | ||||||||||||||||
| const GetLastError = kernel32.func('DWORD GetLastError()') | ||||||||||||||||
| const NtQuerySystemInformation = ntdll.func('NtQuerySystemInformation', 'int32', ['int32', 'SYSTEM_PROCESS_ID_INFORMATION*', 'uint32', HANDLE]); | ||||||||||||||||
|
|
||||||||||||||||
| const SystemProcessIdInformation = 88; // SYSTEM_INFORMATION_CLASS enum value for SystemProcessIdInformation | ||||||||||||||||
|
|
||||||||||||||||
| const STATUS_INFO_LENGTH_MISMATCH = 0xC0000004; | ||||||||||||||||
| const NT_SUCCESS = (status) => status >= 0; | ||||||||||||||||
| const NT_ERROR = (status) => status < 0; | ||||||||||||||||
|
|
||||||||||||||||
| // Using undocumented function NtQuerySystemInformation() | ||||||||||||||||
| // to circumvent limited privilege of wmic or gwmi | ||||||||||||||||
| // when querying executable path of a process | ||||||||||||||||
| const getProcessImageName = (pid) => { | ||||||||||||||||
| let bufferSize = 1024; | ||||||||||||||||
| let buffer = Buffer.alloc(bufferSize); | ||||||||||||||||
|
|
||||||||||||||||
| while (true) { | ||||||||||||||||
| const info = { | ||||||||||||||||
| ProcessId: pid, | ||||||||||||||||
| ImageName: { | ||||||||||||||||
| Length: 0, | ||||||||||||||||
| MaximumLength: buffer.length, | ||||||||||||||||
| Buffer: buffer | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| const result = NtQuerySystemInformation(SystemProcessIdInformation, info, 24, null); | ||||||||||||||||
|
|
||||||||||||||||
| if (NT_ERROR(result) && result !== STATUS_INFO_LENGTH_MISMATCH) { | ||||||||||||||||
| console.error(`NtQuerySystemInformation() failed with pid = ${pid}, error = ${result}`); | ||||||||||||||||
| return null; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if (NT_SUCCESS(result)) { | ||||||||||||||||
| return buffer.subarray(0, buffer.length).toString('utf16le'); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Just to prevent infinite loops |
||||||||||||||||
| bufferSize *= 2; | ||||||||||||||||
| if (bufferSize > 0xffff) bufferSize = 0xffff; | ||||||||||||||||
| buffer = Buffer.alloc(bufferSize); | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| export const getProcesses = () => new Promise(res => { | ||||||||||||||||
| const processIds = new Uint32Array(1024); | ||||||||||||||||
| const bytesNeeded = new Uint32Array(1); | ||||||||||||||||
| let out = [] | ||||||||||||||||
|
|
||||||||||||||||
| const success = EnumProcesses(processIds, processIds.byteLength, bytesNeeded) | ||||||||||||||||
| if (!success) { | ||||||||||||||||
| console.log(GetLastError()) | ||||||||||||||||
| } else { | ||||||||||||||||
| const numProcesses = bytesNeeded[0] / 4; // Divide by 4 because DWORD is 4 bytes | ||||||||||||||||
| for(let i = 0; i < numProcesses; ++i) { | ||||||||||||||||
| if (processIds[i]) { | ||||||||||||||||
| let imageName = getProcessImageName(processIds[i]) | ||||||||||||||||
| if( imageName != null ){ | ||||||||||||||||
| out.push([processIds, imageName]) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| res(out) | ||||||||||||||||
| }); | ||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's officially undocumented but you could put this here, it has some good information