Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions src/extension/android/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ export class AdbHelper {
}

public async apiVersion(deviceId: string): Promise<AndroidAPILevel> {
const output = await this.executeQuery(deviceId, "shell getprop ro.build.version.sdk");
const output = await this.executeQuery(deviceId, ["shell", "getprop", "ro.build.version.sdk"]);
return parseInt(output, 10);
}

public reverseAdb(deviceId: string, port: number): Promise<void> {
return this.execute(deviceId, `reverse tcp:${port} tcp:${port}`);
return this.execute(deviceId, ["reverse", `tcp:${port}`, `tcp:${port}`]);
}

public showDevMenu(deviceId?: string): Promise<void> {
Expand Down Expand Up @@ -237,7 +237,7 @@ export class AdbHelper {
);
const isExist = fs.existsSync(localPropertiesSdkPath);
if (isExist) {
return `"${localPropertiesSdkPath}"`;
return localPropertiesSdkPath;
}
if (logger) {
logger.warning(
Expand All @@ -253,15 +253,24 @@ export class AdbHelper {
}

public executeShellCommand(deviceId: string, command: string): Promise<string> {
return this.executeQuery(deviceId, `shell "${command}"`);
return this.childProcess.execFileToString(this.adbExecutable, [
"-s",
deviceId,
"shell",
command,
]);
}

public installApplicationToEmulator(appPath: string): Promise<string> {
return this.childProcess.execToString(`adb install ${appPath}`);
return this.childProcess.execFileToString("adb", ["install", appPath]);
}

public executeQuery(deviceId: string, command: string): Promise<string> {
return this.childProcess.execToString(this.generateCommandForTarget(deviceId, command));
public executeQuery(deviceId: string, args: string[]): Promise<string> {
return this.childProcess.execFileToString(this.adbExecutable, [
"-s",
deviceId,
...args,
]);
}

private parseConnectedTargets(input: string): IDebuggableMobileTarget[] {
Expand All @@ -283,12 +292,9 @@ export class AdbHelper {
return !!id.match(AdbHelper.AndroidSDKEmulatorPattern);
}

private execute(deviceId: string, command: string): Promise<void> {
return this.commandExecutor.execute(this.generateCommandForTarget(deviceId, command));
}

private generateCommandForTarget(deviceId: string, adbCommand: string): string {
return `${this.adbExecutable} -s "${deviceId}" ${adbCommand}`;
private execute(deviceId: string, args: string[]): Promise<void> {
const command = `${this.adbExecutable} -s "${deviceId}" ${args.join(" ")}`;
return this.commandExecutor.execute(command);
}

private getSdkLocationFromLocalPropertiesFile(
Expand Down
11 changes: 7 additions & 4 deletions src/extension/android/androidContainerUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async function _pushFile(
try {
const pushRes = await adbHelper.executeQuery(
deviceId,
`push ${sourceFilepath} ${tmpFilePath}`,
["push", sourceFilepath, tmpFilePath],
);
logger?.debug(pushRes);
const command = `cp "${tmpFilePath}" "${destFilepath}" && chmod 644 "${destFilepath}"`;
Expand Down Expand Up @@ -135,10 +135,13 @@ function validateAppName(app: string): Promise<string> {
}

function validateFilePath(filePath: string): Promise<string> {
if (!filePath.match(/'/)) {
return Promise.resolve(filePath);
if (!/^[A-Za-z0-9._\/-]+$/.test(filePath)) {
return Promise.reject(new Error(`Disallowed filepath characters: ${filePath}`));
}
return Promise.reject(new Error(`Disallowed escaping filepath: ${filePath}`));
if (filePath.includes("..")) {
return Promise.reject(new Error(`Path traversal not allowed: ${filePath}`));
}
return Promise.resolve(filePath);
}

function validateFileContent(content: string): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion src/extension/android/androidPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class AndroidPlatform extends GeneralMobilePlatform {
// For physical devices, get model name
const modelResult = await this.adbHelper.executeQuery(
targetId,
"shell getprop ro.product.model",
["shell", "getprop", "ro.product.model"],
);
const model = modelResult.trim();
if (model) {
Expand Down
1 change: 1 addition & 0 deletions src/extension/networkInspector/networkInspectorServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class NetworkInspectorServer {
: this.untrustedRequestHandler,
transport: new RSocketTCPServer({
port: port,
host: "127.0.0.1",
serverFactory: serverFactory,
}),
});
Expand Down