Skip to content

Commit a4986bd

Browse files
committed
Merge branch 'release/1.0.5'
2 parents bb81d7c + 9e23d2c commit a4986bd

6 files changed

Lines changed: 51 additions & 19 deletions

File tree

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ DROIDGROUND_BASE_PATH= # If you want to host the webapp on a subpath
22
DROIDGROUND_APP_PACKAGE_NAME=com.droidground.hiddenactivity
33
DROIDGROUND_ADB_HOST=localhost
44
DROIDGROUND_ADB_PORT=5037
5+
DROIDGROUND_ADB_SERIAL= # Optional device serial to connect to. If unspecified, the first connected device is used.
56
DROIDGROUND_DEVICE_TYPE=usb # Either "usb" or "network" are accepted values. Invalid values fallback to "usb"
67
DROIDGROUND_DEVICE_HOST=192.168.1.202 # The address or host name of the device. This field is only evaluated if "DROIDGROUND_DEVICE_TYPE" is set to "network"
78
DROIDGROUND_DEVICE_PORT=1234 # The port of the device. This field is only evaluated if "DROIDGROUND_DEVICE_TYPE" is set to "network"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The `.env.sample` file in the root directory is a good starting point. This is t
8686
| `DROIDGROUND_APP_PACKAGE_NAME` | Package name of target app | - |
8787
| `DROIDGROUND_ADB_HOST` | ADB host | `localhost` |
8888
| `DROIDGROUND_ADB_PORT` | ADB port | `5037` |
89+
| `DROIDGROUND_ADB_SERIAL` | Optional ADB device serial to connect to | - |
8990
| `DROIDGROUND_DEVICE_TYPE` | `usb` or `network` | `usb` |
9091
| `DROIDGROUND_DEVICE_HOST` | IP of Android device (`adb`) (network mode only) | - |
9192
| `DROIDGROUND_DEVICE_PORT` | port of Android device (`adb`) (network mode only) | - |

package-lock.json

Lines changed: 16 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "droidground",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"type": "module",
55
"author": "Angelo Delicato",
66
"scripts": {

src/server/manager.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export class ManagerSingleton {
5151
private constructor() {
5252
// private constructor prevents direct instantiation
5353
const port: any = process.env.DROIDGROUND_ADB_PORT ?? "";
54+
const serialEnv: any = process.env.DROIDGROUND_ADB_SERIAL ?? "";
55+
const adbSerial = serialEnv.trim().length === 0 ? undefined : serialEnv.trim();
5456
const exploitAppDuration: any = process.env.DROIDGROUND_EXPLOIT_APP_DURATION ?? "";
5557
const exploitAppmaxSizeEnv: any = process.env.DROIDGROUND_EXPLOIT_APP_MAX_SIZE ?? "";
5658
const exploitAppMaxSize: number =
@@ -77,6 +79,7 @@ export class ManagerSingleton {
7779
adb: {
7880
host: process.env.DROIDGROUND_ADB_HOST ?? "localhost",
7981
port: isNaN(port) || port.trim().length === 0 ? 5037 : parseInt(port),
82+
serial: adbSerial,
8083
},
8184
features: {
8285
basePath: process.env.DROIDGROUND_BASE_PATH ?? "",
@@ -147,6 +150,15 @@ export class ManagerSingleton {
147150
return;
148151
}
149152

153+
const requestedSerial = this.config.adb.serial;
154+
if (requestedSerial) {
155+
const addedSerials = _devices.map(device => device.serial);
156+
if (!addedSerials.includes(requestedSerial)) {
157+
Logger.debug(`Ignoring added devices because serial '${requestedSerial}' was not included.`);
158+
return;
159+
}
160+
}
161+
150162
await this.setupAdb();
151163
await this.setCtf();
152164

@@ -204,9 +216,21 @@ export class ManagerSingleton {
204216
throw new Error("No device connected");
205217
}
206218

207-
Logger.debug("Listing devices (and using the first one)");
208-
Logger.debug(devices);
209-
const device = devices[0];
219+
const serial = this.config.adb.serial;
220+
let device: AdbServerClient.Device | undefined;
221+
if (serial) {
222+
Logger.debug(`Looking for device with serial '${serial}'`);
223+
device = devices.find(d => d.serial === serial);
224+
if (!device) {
225+
Logger.error(`ADB device with serial '${serial}' not found`);
226+
Logger.debug(`Connected devices: ${JSON.stringify(devices)}`);
227+
throw new Error(`ADB device with serial '${serial}' not found`);
228+
}
229+
} else {
230+
Logger.debug("Listing devices (and using the first one)");
231+
Logger.debug(devices);
232+
device = devices[0];
233+
}
210234

211235
this.device = device;
212236

@@ -337,7 +361,8 @@ export class ManagerSingleton {
337361
}
338362

339363
Logger.info("Running setup.sh script...");
340-
const scriptOutput = execFileSync(setupScript, {
364+
const setupArgs = this.config.adb.serial ? [this.config.adb.serial] : [];
365+
const scriptOutput = execFileSync(setupScript, setupArgs, {
341366
cwd: process.env.DROIDGROUND_INIT_SCRIPTS_FOLDER,
342367
stdio: "pipe",
343368
encoding: "utf-8",
@@ -366,7 +391,8 @@ export class ManagerSingleton {
366391
const initDFolder = process.env.DROIDGROUND_INIT_SCRIPTS_FOLDER ?? "/init.d";
367392
const resetScript = path.resolve(initDFolder, "reset.sh");
368393
if (safeFileExists(resetScript)) {
369-
const scriptOutput = execFileSync(resetScript, {
394+
const resetArgs = this.config.adb.serial ? [this.config.adb.serial] : [];
395+
const scriptOutput = execFileSync(resetScript, resetArgs, {
370396
cwd: process.env.DROIDGROUND_INIT_SCRIPTS_FOLDER,
371397
stdio: "pipe",
372398
encoding: "utf-8",

src/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface DroidGroundConfig {
3636
adb: {
3737
host: string;
3838
port: number;
39+
serial?: string;
3940
};
4041
features: DroidGroundFeatures;
4142
teams: DroidGroundTeam[];

0 commit comments

Comments
 (0)