Skip to content

Commit aa7ec1f

Browse files
committed
feat: adds getProcessCommandLine
1 parent 0317262 commit aa7ec1f

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ LeagueClientUx process. If you wish to await until a client is found, you can us
8585
| unsafe | `false` | If you do not wish to authenticate safely using a self-signed certificate you can authorize while ignoring any certificate rejections. To authenticate this way, set unsafe to `true`. The custom certificate option will take precedence over this, meaning this option is meaningless if a custom certificate is provided. |
8686
| useDeprecatedWmic | `false` | Use deprecated Windows WMIC command line over Get-CimInstance. Does nothing if the system is not running on Windows. |
8787
| windowsShell | `powershell` | Set the Windows shell to use. Either powershell or cmd. |
88+
| getProcessCommandLine | `undefined` | Set custom function to get LeagueClientUx process information. |
8889

8990
```js
9091
import { authenticate } from 'league-connect'

src/authentication.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export interface AuthenticationOptions {
7878
* Default: 'powershell'
7979
*/
8080
windowsShell?: 'cmd' | 'powershell'
81+
/**
82+
* Set getProcessCommandLine custom function to get LeagueClientUx process information.
83+
*
84+
* Default: undefined
85+
*/
86+
getProcessCommandLine?: (processName: string) => string
8187
/**
8288
* Debug mode. Prints error information to console.
8389
* @internal
@@ -128,26 +134,46 @@ export class ClientElevatedPermsError extends Error {
128134
* @throws ClientElevatedPermsError If the League Client is running as administrator and the script is not (Windows only)
129135
*/
130136
export async function authenticate(options?: AuthenticationOptions): Promise<Credentials> {
131-
async function tryAuthenticate() {
137+
async function getProcessCommandLine(executionOptions: { shell: string; } | { shell?: undefined; }) {
132138
const name = options?.name ?? DEFAULT_NAME
133-
const portRegex = /--app-port=([0-9]+)(?= *"| --)/
134-
const passwordRegex = /--remoting-auth-token=(.+?)(?= *"| --)/
135-
const pidRegex = /--app-pid=([0-9]+)(?= *"| --)/
136139
const isWindows = process.platform === 'win32'
137140

138141
let command: string
142+
139143
if (!isWindows) {
140144
command = `ps x -o args | grep '${name}'`
141-
} else if (isWindows && options?.useDeprecatedWmic === true) {
145+
146+
const { stdout: rawStdout } = await exec(command, {})
147+
148+
return rawStdout
149+
}
150+
151+
if (typeof options?.getProcessCommandLine === 'function') {
152+
return options.getProcessCommandLine(`${name}.exe`)
153+
}
154+
155+
if (options?.useDeprecatedWmic) {
142156
command = `wmic process where caption='${name}.exe' get commandline`
143157
} else {
144158
command = `Get-CimInstance -Query "SELECT * from Win32_Process WHERE name LIKE '${name}.exe'" | Select-Object -ExpandProperty CommandLine`
145159
}
146160

161+
const { stdout: rawStdout } = await exec(command, executionOptions)
162+
163+
return rawStdout
164+
}
165+
166+
async function tryAuthenticate() {
167+
const name = options?.name ?? DEFAULT_NAME
168+
const portRegex = /--app-port=([0-9]+)(?= *"| --)/
169+
const passwordRegex = /--remoting-auth-token=(.+?)(?= *"| --)/
170+
const pidRegex = /--app-pid=([0-9]+)(?= *"| --)/
171+
const isWindows = process.platform === 'win32'
172+
147173
const executionOptions = isWindows ? { shell: options?.windowsShell ?? ('powershell' as string) } : {}
148174

149175
try {
150-
const { stdout: rawStdout } = await exec(command, executionOptions)
176+
const rawStdout = await getProcessCommandLine(executionOptions)
151177
// TODO: investigate regression with calling .replace on rawStdout
152178
// Remove newlines from stdout
153179
const stdout = rawStdout.replace(/\n|\r/g, '')

src/tests/authentication.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ describe('authenticating to the api', () => {
6565

6666
expect(credentials?.certificate).toBeUndefined()
6767
})
68+
69+
test('authentication using get-command-line detection mode', async () => {
70+
const credentials = await authenticate({
71+
getProcessCommandLine: () => `C:/Riot Games/LeagueClientUx.exe" "--remoting-auth-token=CUSTOM_TOKEN" "--app-port=57730" "--app-pid=28900"`
72+
})
73+
74+
expect(credentials).toBeDefined()
75+
expect(credentials?.certificate).toBeDefined()
76+
})
6877
})

0 commit comments

Comments
 (0)