{"version":3,"file":"bundle.min.js","sources":["lib/Helpers.js","lib/transport/WebUsbTransport.js","lib/message/MessageHeader.js","lib/message/Message.js","lib/message/MessageChannel.js","lib/AdbConnectionInformation.js","lib/SyncFrame.js","lib/Stream.js","lib/Shell.js","lib/AdbClient.js","main.js"],"sourcesContent":["/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nexport function toHex8(num) {\n return paddit(num.toString(16), 2, '0');\n}\nexport function toHex16(num) {\n return paddit(num.toString(16), 4, '0');\n}\nexport function toHex32(num) {\n return paddit(num.toString(16), 8, '0');\n}\nexport function hexdump(view, prefix = '') {\n const decoder = new TextDecoder();\n for (let i = 0; i < view.byteLength; i += 16) {\n const max = (view.byteLength - i) > 16 ? 16 : (view.byteLength - i);\n let row = prefix + toHex16(i) + ' ';\n let j;\n for (j = 0; j < max; j++) {\n row += ' ' + toHex8(view.getUint8(i + j));\n }\n for (; j < 16; j++) {\n row += ' ';\n }\n row += ' | ' + decoder.decode(new DataView(view.buffer, i, max));\n console.log(row);\n }\n}\nexport function privateKeyDump(key) {\n return __awaiter(this, void 0, void 0, function* () {\n if (!key.privateKey.extractable) {\n console.log('cannot dump the private key, it\\'s not extractable');\n return;\n }\n const privkey = yield crypto.subtle.exportKey('pkcs8', key.privateKey);\n console.log(`-----BEGIN PRIVATE KEY-----\\n${toB64(privkey)}\\n-----END PRIVATE KEY-----`);\n });\n}\nexport function publicKeyDump(key) {\n return __awaiter(this, void 0, void 0, function* () {\n if (!key.publicKey.extractable) {\n console.log('cannot dump the public key, it\\'s not extractable');\n return;\n }\n const pubKey = yield crypto.subtle.exportKey('spki', key.publicKey);\n console.log(`-----BEGIN PUBLIC KEY-----\\n${toB64(pubKey)}'\\n-----END PUBLIC KEY-----`);\n });\n}\nexport function toB64(buffer) {\n return btoa(new Uint8Array(buffer).reduce((s, b) => s + String.fromCharCode(b), ''));\n}\nexport function encodeCmd(cmd) {\n const encoder = new TextEncoder();\n const buffer = encoder.encode(cmd).buffer;\n const view = new DataView(buffer);\n return view.getUint32(0, true);\n}\nexport function decodeCmd(cmd) {\n const decoder = new TextDecoder();\n const buffer = new ArrayBuffer(4);\n const view = new DataView(buffer);\n view.setUint32(0, cmd, true);\n return decoder.decode(buffer);\n}\nfunction paddit(text, width, padding) {\n const padlen = width - text.length;\n let padded = '';\n for (let i = 0; i < padlen; i++) {\n padded += padding;\n }\n return padded + text;\n}\n//# sourceMappingURL=Helpers.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { hexdump } from '../Helpers';\nconst ADB_DEVICE = { classCode: 255, subclassCode: 66, protocolCode: 1 };\nconst FASTBOOT_DEVICE = { classCode: 255, subclassCode: 66, protocolCode: 3 };\nconst DEVICE_FILTERS = [ADB_DEVICE, FASTBOOT_DEVICE];\n/**\n * An implementation of {@link Transport} using WebUSB as the tranport layer.\n */\nexport default class WebUsbTransport {\n constructor(device, match, endpointIn, endpointOut, options, log = console.log) {\n this.device = device;\n this.match = match;\n this.endpointIn = endpointIn;\n this.endpointOut = endpointOut;\n this.options = options;\n this.log = log;\n }\n /**\n * Releases the interface and closes the connection to the WebUSB device\n */\n close() {\n return __awaiter(this, void 0, void 0, function* () {\n yield this.device.releaseInterface(this.match.intf.interfaceNumber);\n yield this.device.close();\n });\n }\n /**\n * Sends data to the USB device\n *\n * @param {ArrayBuffer} data the data to be sent to the interface\n */\n write(data) {\n return __awaiter(this, void 0, void 0, function* () {\n if (this.options.dump) {\n hexdump(new DataView(data), '' + this.endpointOut + '==> ');\n }\n yield this.device.transferOut(this.endpointOut, data);\n });\n }\n /**\n * Receives data from the USB device\n *\n * @param {number} len the length of date to be read\n * @returns {Promise 20) {\n const magic = data.getUint32(20, true);\n if ((cmd ^ magic) !== -1) {\n throw new Error('magic mismatch');\n }\n }\n return new MessageHeader(decodeCmd(cmd), arg0, arg1, len, checksum);\n }\n}\n//# sourceMappingURL=MessageHeader.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport MessageHeader from './MessageHeader';\nimport { toB64 } from '../Helpers';\nexport default class Message {\n constructor(header, data) {\n this.header = header;\n this.data = data;\n }\n dataAsString() {\n if (!this.data) {\n return null;\n }\n const textDecoder = new TextDecoder();\n return textDecoder.decode(this.data);\n }\n static newMessage(cmd, arg0, arg1, useChecksum, data) {\n let checksum = 0;\n let byteLength = 0;\n if (data) {\n byteLength = data.byteLength;\n if (useChecksum) {\n checksum = Message.checksum(data);\n }\n }\n const header = new MessageHeader(cmd, arg0, arg1, byteLength, checksum);\n return new Message(header, data);\n }\n static open(localId, remoteId, service, useChecksum) {\n const encoder = new TextEncoder();\n const data = new DataView(encoder.encode('' + service + '\\0').buffer);\n return Message.newMessage('OPEN', localId, remoteId, useChecksum, data);\n }\n static cnxn(version, maxPayload, banner, useChecksum) {\n const encoder = new TextEncoder();\n const data = new DataView(encoder.encode(banner).buffer);\n return Message.newMessage('CNXN', version, maxPayload, useChecksum, data);\n }\n static authSignature(signedToken, useChecksum) {\n return Message.newMessage('AUTH', 2, 0, useChecksum, signedToken);\n }\n static authPublicKey(publicKey, useChecksum) {\n const textEncoder = new TextEncoder();\n const data = textEncoder.encode(toB64(publicKey.buffer) + '\\0');\n return Message.newMessage('AUTH', 3, 0, useChecksum, new DataView(data.buffer));\n }\n static checksum(dataView) {\n let sum = 0;\n for (let i = 0; i < dataView.byteLength; i++) {\n sum += dataView.getUint8(i);\n }\n return sum & 0xffffffff;\n }\n}\n//# sourceMappingURL=Message.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport Message from './Message';\nimport MessageHeader from './MessageHeader';\nexport default class MessageChannel {\n constructor(transport, options, listener) {\n this.transport = transport;\n this.options = options;\n this.listener = listener;\n this.active = true;\n this.readLoop();\n }\n readLoop() {\n return __awaiter(this, void 0, void 0, function* () {\n let message;\n do {\n message = yield this.read();\n if (this.options.debug) {\n console.log('<<<', message);\n }\n this.listener.newMessage(message);\n } while (this.active);\n });\n }\n readHeader() {\n return __awaiter(this, void 0, void 0, function* () {\n const response = yield this.transport.read(24);\n return MessageHeader.parse(response, this.options.useChecksum);\n });\n }\n read() {\n return __awaiter(this, void 0, void 0, function* () {\n const header = yield this.readHeader();\n let receivedData;\n switch (header.cmd) {\n default: {\n if (header.length > 0) {\n receivedData = yield this.transport.read(header.length);\n }\n }\n }\n const message = new Message(header, receivedData);\n return message;\n });\n }\n close() {\n this.active = false;\n }\n write(m) {\n return __awaiter(this, void 0, void 0, function* () {\n if (this.options.debug) {\n console.log('>>>', m);\n }\n const data = m.header.toDataView();\n yield this.transport.write(data.buffer);\n if (m.data) {\n yield this.transport.write(m.data.buffer);\n }\n });\n }\n}\n//# sourceMappingURL=MessageChannel.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nconst PRODUCT_NAME_KEY = 'ro.product.name';\nconst PRODUCT_MODEL_KEY = 'ro.product.model';\nconst PRODUCT_DEVICE_KEY = 'ro.product.device';\nconst FEATURES_KEY = 'features';\nconst DEFAULT_PRODUCT_VALUE = '';\nexport default class AdbConnectionInformation {\n constructor(productName, productDevice, productModel, features) {\n this.productName = productName;\n this.productDevice = productDevice;\n this.productModel = productModel;\n this.features = features;\n }\n static fromDataView(input) {\n const textDecoder = new TextDecoder();\n const decodedInput = textDecoder.decode(input);\n return AdbConnectionInformation.fromString(decodedInput);\n }\n /**\n * Creates an AdbConnectionInformation from a Connection string\n * @param input the string sent as data from a Connection response\n */\n static fromString(input) {\n const start = input.indexOf('::');\n const properties = input.substring(start + 2).split(';');\n let productName = DEFAULT_PRODUCT_VALUE;\n let productDevice = DEFAULT_PRODUCT_VALUE;\n let productModel = DEFAULT_PRODUCT_VALUE;\n let features = [];\n for (const property of properties) {\n if (property.startsWith(PRODUCT_NAME_KEY)) {\n productName = property.substring(PRODUCT_NAME_KEY.length + 1);\n continue;\n }\n if (property.startsWith(PRODUCT_MODEL_KEY)) {\n productModel = property.substring(PRODUCT_MODEL_KEY.length + 1);\n continue;\n }\n if (property.startsWith(PRODUCT_DEVICE_KEY)) {\n productDevice = property.substring(PRODUCT_DEVICE_KEY.length + 1);\n continue;\n }\n if (property.startsWith(FEATURES_KEY)) {\n features = property.substring(FEATURES_KEY.length + 1).split(',');\n }\n }\n return new AdbConnectionInformation(productName, productDevice, productModel, features);\n }\n}\n//# sourceMappingURL=AdbConnectionInformation.js.map","/**\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { encodeCmd, decodeCmd } from './Helpers';\nexport default class SyncFrame {\n constructor(cmd, byteLength) {\n this.cmd = cmd;\n this.byteLength = byteLength;\n }\n toDataView() {\n const data = new ArrayBuffer(8);\n const cmd = encodeCmd(this.cmd);\n const view = new DataView(data);\n view.setUint32(0, cmd, true);\n view.setUint32(4, this.byteLength, true);\n return view;\n }\n static fromDataView(dataView) {\n const cmd = decodeCmd(dataView.getUint32(0, true));\n const byteLength = dataView.getUint32(4, true);\n return new SyncFrame(cmd, byteLength);\n }\n}\n//# sourceMappingURL=SyncFrame.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport Message from './message/Message';\nimport { toHex32 } from './Helpers';\nimport SyncFrame from './SyncFrame';\nexport default class Stream {\n constructor(client, service, localId, remoteId, options) {\n this.client = client;\n this.service = service;\n this.localId = localId;\n this.remoteId = remoteId;\n this.options = options;\n this.awaitMessage = null;\n }\n close() {\n return __awaiter(this, void 0, void 0, function* () {\n yield this.write('CLSE');\n if (this.options.debug) {\n console.log(`Closed stream ${this.service}`);\n console.log(` local_id: 0x${toHex32(this.localId)}`);\n console.log(` remote_id: 0x${toHex32(this.remoteId)}`);\n }\n this.client.unregisterStream(this);\n });\n }\n consumeMessage(msg) {\n if (msg.header.arg0 === 0 || msg.header.arg0 !== this.remoteId ||\n msg.header.arg1 === 0 || msg.header.arg1 !== this.localId) {\n return false;\n }\n if (this.awaitMessage) {\n this.awaitMessage(msg);\n this.awaitMessage = null;\n }\n return true;\n }\n write(cmd, data) {\n return __awaiter(this, void 0, void 0, function* () {\n const message = this.newMessage(cmd, data);\n yield this.client.sendMessage(message);\n });\n }\n read() {\n return __awaiter(this, void 0, void 0, function* () {\n return new Promise(resolve => {\n this.awaitMessage = resolve;\n });\n });\n }\n /**\n *\n * Retrieves a file from device to a local file. The remote path is the path to\n * the file that will be returned. Just as for the SEND sync request the file\n * received is split up into chunks. The sync response id is \"DATA\" and length is\n * the chunk size. After follows chunk size number of bytes. This is repeated\n * until the file is transferred. Each chunk will not be larger than 64k.\n * When the file is transferred a sync response \"DONE\" is retrieved where the\n * length can be ignored.\n *\n * @param {string} remotePath path to the file to be pulled from the device\n * @returns {Promise} a Blog with the file contents.\n */\n pull(remotePath) {\n return __awaiter(this, void 0, void 0, function* () {\n const encoder = new TextEncoder();\n const encodedFilename = encoder.encode(remotePath);\n // Sends RECV with filename length.\n const recvFrame = new SyncFrame('RECV', encodedFilename.byteLength);\n const wrteRecvMessage = this.newMessage('WRTE', recvFrame.toDataView());\n yield this.client.sendMessage(wrteRecvMessage);\n const wrteRecvResponse = yield this.read();\n if (wrteRecvResponse.header.cmd !== 'OKAY') {\n throw new Error('WRTE/RECV failed: ' + wrteRecvResponse);\n }\n // 17. We send the path of the file we want again sdcard/someFile.txt\n const wrteFilenameMessage = this.newMessage('WRTE', new DataView(encodedFilename.buffer));\n yield this.client.sendMessage(wrteFilenameMessage);\n // 18. Device sends us OKAY\n const wrteFilenameResponse = yield this.read();\n if (wrteFilenameResponse.header.cmd !== 'OKAY') {\n throw new Error('WRTE/filename failed: ' + wrteFilenameResponse);\n }\n const okayMessage = this.newMessage('OKAY');\n let fileDataMessage = yield this.read();\n yield this.client.sendMessage(okayMessage);\n let syncFrame = SyncFrame.fromDataView(new DataView(fileDataMessage.data.buffer.slice(0, 8)));\n let buffer = new Uint8Array(fileDataMessage.data.buffer.slice(8));\n const chunks = [];\n while (syncFrame.cmd !== 'DONE') {\n while (syncFrame.byteLength >= buffer.byteLength) {\n fileDataMessage = yield this.read();\n yield this.client.sendMessage(okayMessage);\n // Join both arrays\n const newLength = buffer.byteLength + fileDataMessage.data.byteLength;\n const newBuffer = new Uint8Array(newLength);\n newBuffer.set(buffer, 0);\n newBuffer.set(new Uint8Array(fileDataMessage.data.buffer), buffer.byteLength);\n buffer = newBuffer;\n }\n chunks.push(buffer.slice(0, syncFrame.byteLength).buffer);\n buffer = buffer.slice(syncFrame.byteLength);\n syncFrame = SyncFrame.fromDataView(new DataView(buffer.slice(0, 8).buffer));\n buffer = buffer.slice(8);\n }\n return new Blob(chunks);\n });\n }\n newMessage(cmd, data) {\n return Message.newMessage(cmd, this.localId, this.remoteId, this.options.useChecksum, data);\n }\n static open(device, service, options) {\n return __awaiter(this, void 0, void 0, function* () {\n const localId = Stream.nextId++;\n let remoteId = 0;\n const m = Message.open(localId, remoteId, service, options.useChecksum);\n yield device.sendMessage(m);\n let response;\n do {\n response = yield device.awaitMessage();\n } while (response.header.arg1 !== localId);\n if (response.header.cmd !== 'OKAY') {\n throw new Error('OPEN Failed');\n }\n remoteId = response.header.arg0;\n if (options.debug) {\n console.log(`Opened stream ${service}`);\n console.log(` local_id: 0x${toHex32(localId)}`);\n console.log(` remote_id: 0x${toHex32(remoteId)}`);\n }\n const stream = new Stream(device, service, localId, remoteId, options);\n device.registerStream(stream);\n return stream;\n });\n }\n}\nStream.nextId = 1;\n//# sourceMappingURL=Stream.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nexport default class Shell {\n constructor(stream, callbackFunction) {\n this.stream = stream;\n this.callbackFunction = callbackFunction;\n this.textDecoder = new TextDecoder();\n this.textEncoder = new TextEncoder();\n this.messageListener = [];\n this.closed = false;\n this.loopRead();\n }\n loopRead() {\n return __awaiter(this, void 0, void 0, function* () {\n try {\n let message;\n do {\n message = yield this.stream.read();\n if (message.header.cmd === 'WRTE') {\n this.stream.write('OKAY');\n const data = this.textDecoder.decode(message.data);\n if (this.callbackFunction) {\n this.callbackFunction(data);\n }\n }\n // Resolve Messages waiting for this event\n for (const listener of this.messageListener) {\n listener(message);\n }\n } while (!this.closed);\n }\n catch (e) {\n console.error('loopRead crashed', e);\n }\n this.stream.client.unregisterStream(this.stream);\n });\n }\n waitForMessage(cmd) {\n return new Promise(resolve => {\n const callback = (message) => {\n if (message.header.cmd === cmd) {\n const pos = this.messageListener.indexOf(callback);\n this.messageListener.splice(pos, 1);\n resolve(message);\n }\n };\n this.messageListener.push(callback);\n });\n }\n write(command) {\n return __awaiter(this, void 0, void 0, function* () {\n const data = this.textEncoder.encode(command);\n yield this.stream.write('WRTE', new DataView(data.buffer));\n yield this.waitForMessage('OKAY');\n });\n }\n close() {\n return __awaiter(this, void 0, void 0, function* () {\n this.closed = true;\n yield this.write('CLSE');\n });\n }\n}\n//# sourceMappingURL=Shell.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport Message from './message/Message';\nimport MessageChannel from './message/MessageChannel';\nimport { privateKeyDump } from './Helpers';\nimport AdbConnectionInformation from './AdbConnectionInformation';\nimport Stream from './Stream';\nimport Shell from './Shell';\nconst VERSION = 0x01000000;\nconst VERSION_NO_CHECKSUM = 0x01000001;\nconst MAX_PAYLOAD = 256 * 1024;\nconst MACHINE_BANNER = 'host::\\0';\nexport default class AdbClient {\n /**\n * Creates a new AdbClient\n *\n * @param {Transport} transport the transport layer.\n */\n constructor(transport, options, keyStore) {\n this.transport = transport;\n this.options = options;\n this.keyStore = keyStore;\n this.messageCallback = null;\n this.openStreams = new Set();\n this.messageChannel = new MessageChannel(transport, options, this);\n }\n registerStream(stream) {\n this.openStreams.add(stream);\n console.log(this.openStreams);\n }\n unregisterStream(stream) {\n this.openStreams.delete(stream);\n console.log(this.openStreams);\n }\n newMessage(msg) {\n // Check if this message matches one of the open streams.\n for (const stream of this.openStreams) {\n if (stream.consumeMessage(msg)) {\n return;\n }\n }\n if (this.messageCallback) {\n this.messageCallback(msg);\n }\n }\n awaitMessage() {\n return __awaiter(this, void 0, void 0, function* () {\n return new Promise((resolve) => {\n this.messageCallback = resolve;\n });\n });\n }\n connect() {\n return __awaiter(this, void 0, void 0, function* () {\n const version = this.options.useChecksum ? VERSION : VERSION_NO_CHECKSUM;\n const cnxn = Message.cnxn(version, MAX_PAYLOAD, MACHINE_BANNER, this.options.useChecksum);\n yield this.sendMessage(cnxn); // Send the Message\n // Response to connect must be CNXN or AUTH. Ignore different responses until the right one\n // arrives.\n let response;\n do {\n response = yield this.awaitMessage();\n } while (response.header.cmd !== 'CNXN' && response.header.cmd !== 'AUTH');\n // Server connected\n if (response.header.cmd === 'CNXN') {\n if (!response.data) {\n throw new Error('Connection doesn\\'t have data');\n }\n return AdbConnectionInformation.fromDataView(response.data);\n }\n // Server asked to authenticate\n response = yield this.doAuth(response);\n if (!response.data) {\n throw new Error('Connection doesn\\'t have data');\n }\n return AdbConnectionInformation.fromDataView(response.data);\n });\n }\n disconnect() {\n return __awaiter(this, void 0, void 0, function* () {\n this.messageChannel.close();\n });\n }\n shell(command) {\n return __awaiter(this, void 0, void 0, function* () {\n const stream = yield Stream.open(this, `shell:${command}`, this.options);\n const response = yield stream.read();\n yield stream.close();\n return response.dataAsString() || '';\n });\n }\n interactiveShell(callback) {\n return __awaiter(this, void 0, void 0, function* () {\n const stream = yield Stream.open(this, 'shell:', this.options);\n return new Shell(stream, callback);\n });\n }\n sync() {\n return __awaiter(this, void 0, void 0, function* () {\n return yield Stream.open(this, 'sync:', this.options);\n });\n }\n pull(filename) {\n return __awaiter(this, void 0, void 0, function* () {\n const syncStream = yield this.sync();\n const result = yield syncStream.pull(filename);\n yield syncStream.close();\n return result;\n });\n }\n doAuth(authResponse) {\n return __awaiter(this, void 0, void 0, function* () {\n if (authResponse.header.cmd !== 'AUTH') {\n throw new Error('Not an AUTH response');\n }\n if (authResponse.header.arg0 !== 1) {\n throw new Error(`\n Invalid AUTH parameter. Expected 1 and received ${authResponse.header.arg0}`);\n }\n if (!authResponse.data) {\n throw new Error('AUTH message doens\\'t contain data');\n }\n let token = authResponse.data.buffer;\n // Try signing with one of the stored keys\n const keys = yield this.keyStore.loadKeys();\n for (const key of keys) {\n const signed = yield crypto.subtle.sign('RSASSA-PKCS1-v1_5', key.privateKey, token);\n const signatureMessage = Message.authSignature(new DataView(signed), this.options.useChecksum);\n yield this.sendMessage(signatureMessage);\n const signatureResponse = yield this.awaitMessage();\n if (signatureResponse.header.cmd === 'CNXN') {\n return signatureResponse;\n }\n console.log('Received message ', signatureResponse, 'from phone');\n }\n // None of they saved Keys is usable. Create new key\n const key = yield AdbClient.generateKey(this.options.dump, this.options.keySize);\n yield this.keyStore.saveKey(key);\n const exportedKey = new DataView(yield crypto.subtle.exportKey('spki', key.publicKey));\n const keyMessage = Message.authPublicKey(exportedKey, this.options.useChecksum);\n yield this.sendMessage(keyMessage);\n console.log('Accept Key on Device');\n const keyResponse = yield this.awaitMessage();\n if (keyResponse.header.cmd !== 'CNXN') {\n console.error('AUTH failed. Phone didn\\'t accept key', keyResponse);\n throw new Error('AUTH failed. Phone didn\\'t accept key');\n }\n return keyResponse;\n });\n }\n sendMessage(m) {\n return __awaiter(this, void 0, void 0, function* () {\n yield this.messageChannel.write(m);\n });\n }\n static generateKey(dump, keySize) {\n return __awaiter(this, void 0, void 0, function* () {\n const extractable = dump;\n const key = yield crypto.subtle.generateKey({\n name: 'RSASSA-PKCS1-v1_5',\n modulusLength: keySize,\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\n hash: { name: 'SHA-1' }\n }, extractable, ['sign', 'verify']);\n if (dump) {\n yield privateKeyDump(key);\n }\n return key;\n });\n }\n}\n//# sourceMappingURL=AdbClient.js.map","/*\n * Copyright 2020 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport WebUsbTransport from './lib/transport/WebUsbTransport';\nimport AdbClient from './lib/AdbClient';\nimport Stream from './lib/Stream';\nlet transport;\nlet adbClient;\nconst connectButton = document.querySelector('#connect');\nconst disconnectButton = document.querySelector('#disconnect');\nconst startButton = document.querySelector('#start');\nconst stopButton = document.querySelector('#stop');\nconst screenshotButton = document.querySelector('#screencapture');\nconst video = document.querySelector('#video');\nconst screenshot = document.querySelector('#screenshot');\nconst download = document.querySelector('#download');\nconst status = document.querySelector('#status');\nconst options = {\n debug: true,\n useChecksum: false,\n dump: false,\n keySize: 2048,\n};\nclass MyKeyStore {\n constructor() {\n this.keys = [];\n }\n loadKeys() {\n return __awaiter(this, void 0, void 0, function* () {\n return this.keys;\n });\n }\n saveKey(key) {\n return __awaiter(this, void 0, void 0, function* () {\n this.keys.push(key);\n console.log('Saving Key' + key);\n });\n }\n}\nconst keyStore = new MyKeyStore();\nconnectButton.addEventListener('click', (_) => __awaiter(void 0, void 0, void 0, function* () {\n try {\n transport = yield WebUsbTransport.open(options);\n adbClient = new AdbClient(transport, options, keyStore);\n status.textContent = 'Accept prompt on device';\n const adbConnectionInformation = yield adbClient.connect();\n status.textContent = 'Connected and ready';\n console.log('Connected: ', adbConnectionInformation);\n connectButton.classList.toggle('hidden');\n disconnectButton.classList.toggle('hidden');\n }\n catch (e) {\n console.error('Connection Failed: ', e);\n status.textContent = 'Failed to connect to a device';\n }\n}));\ndisconnectButton.addEventListener('click', (_) => __awaiter(void 0, void 0, void 0, function* () {\n try {\n if (adbClient) {\n try {\n yield adbClient.disconnect();\n }\n catch (e) {\n console.log('Error disconnecting ADB Client: ', e);\n }\n adbClient = null;\n }\n if (transport) {\n yield transport.close();\n transport = null;\n }\n connectButton.classList.toggle('hidden');\n disconnectButton.classList.toggle('hidden');\n status.textContent = 'Connect to a device to start';\n }\n catch (e) {\n console.error('Disconnecting Failed: ', e);\n }\n}));\nconst RECORD_FILE_NAME = '/sdcard/webadb-record-2.mp4';\nlet shell = null;\nstartButton.addEventListener('click', () => __awaiter(void 0, void 0, void 0, function* () {\n shell = yield Stream.open(adbClient, `shell:screenrecord ${RECORD_FILE_NAME}`, options);\n status.textContent = 'Recording...';\n stopButton.classList.toggle('hidden');\n startButton.classList.toggle('hidden');\n}));\nstopButton.addEventListener('click', () => __awaiter(void 0, void 0, void 0, function* () {\n // await shell!.write(String.fromCharCode(3) + '\\n'); // CTRL+C\n status.textContent = 'Finishing Recording...';\n yield shell.close();\n status.textContent = 'Pulling video...';\n // Trying to load the file straight away results in a broken file.\n // Waiting for a couple of seconds fixes it. Maybe send STAT before\n // attempting download.\n setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {\n console.log('Starting ADB Pull');\n const result = yield adbClient.pull(RECORD_FILE_NAME);\n const videoSrc = window.URL.createObjectURL(result);\n video.src = videoSrc;\n download.href = videoSrc;\n download.download = 'recording.mp4';\n stopButton.classList.toggle('hidden');\n startButton.classList.toggle('hidden');\n screenshot.classList.add('hidden');\n video.classList.remove('hidden');\n download.classList.remove('hidden');\n status.textContent = 'Done! Connected and ready';\n }), 2000);\n}));\nscreenshotButton.addEventListener('click', () => __awaiter(void 0, void 0, void 0, function* () {\n status.textContent = 'Generating Screenshot...';\n yield adbClient.shell('screencap -p /sdcard/screenshot.png');\n status.textContent = 'Pulling image...';\n setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {\n console.log('Starting ADB Pull');\n const result = yield adbClient.pull('/sdcard/screenshot.png');\n const imageSrc = window.URL.createObjectURL(result);\n screenshot.src = imageSrc;\n download.href = imageSrc;\n download.download = 'screenshot.png';\n download.classList.remove('hidden');\n screenshot.classList.remove('hidden');\n video.classList.add('hidden');\n status.textContent = 'Done! Connected and ready';\n }), 2000);\n}));\n//# sourceMappingURL=main.js.map"],"names":["__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","toHex8","num","paddit","toString","toHex32","toB64","buffer","btoa","Uint8Array","reduce","s","b","String","fromCharCode","encodeCmd","cmd","TextEncoder","encode","DataView","getUint32","decodeCmd","decoder","TextDecoder","ArrayBuffer","setUint32","decode","text","width","padding","padlen","length","padded","i","ADB_DEVICE","classCode","subclassCode","protocolCode","FASTBOOT_DEVICE","DEVICE_FILTERS","WebUsbTransport","[object Object]","device","match","endpointIn","endpointOut","options","log","console","this","releaseInterface","intf","interfaceNumber","close","data","dump","view","prefix","byteLength","max","j","row","getUint8","hexdump","transferOut","len","response","transferIn","Error","findMatch","navigator","usb","requestDevice","filters","open","selectConfiguration","conf","configurationValue","claimInterface","getEndpointNum","alternate","endpoints","transport","debug","filter","configuration","configurations","interfaces","alternates","interfaceClass","interfaceSubclass","interfaceProtocol","dir","type","ep","direction","endpointNumber","MessageHeader","arg0","arg1","checksum","rawCmd","magic","useChecksum","Message","header","localId","remoteId","service","encoder","newMessage","version","maxPayload","banner","signedToken","publicKey","dataView","sum","MessageChannel","listener","active","readLoop","message","read","parse","readHeader","receivedData","m","toDataView","write","AdbConnectionInformation","productName","productDevice","productModel","features","input","decodedInput","fromString","start","indexOf","properties","substring","split","property","startsWith","SyncFrame","Stream","client","awaitMessage","unregisterStream","msg","sendMessage","remotePath","encodedFilename","recvFrame","wrteRecvMessage","wrteRecvResponse","wrteFilenameMessage","wrteFilenameResponse","okayMessage","fileDataMessage","syncFrame","fromDataView","slice","chunks","newLength","newBuffer","set","push","Blob","nextId","stream","registerStream","Shell","callbackFunction","textDecoder","textEncoder","messageListener","closed","loopRead","error","callback","pos","splice","command","waitForMessage","AdbClient","keyStore","messageCallback","openStreams","Set","messageChannel","add","delete","consumeMessage","cnxn","doAuth","dataAsString","filename","syncStream","sync","pull","authResponse","token","keys","loadKeys","key","signed","crypto","subtle","sign","privateKey","signatureMessage","authSignature","signatureResponse","generateKey","keySize","saveKey","exportedKey","exportKey","keyMessage","authPublicKey","keyResponse","extractable","name","modulusLength","publicExponent","hash","privkey","privateKeyDump","adbClient","connectButton","document","querySelector","disconnectButton","startButton","stopButton","screenshotButton","video","screenshot","download","status","addEventListener","_","textContent","adbConnectionInformation","connect","classList","toggle","disconnect","shell","setTimeout","videoSrc","window","URL","createObjectURL","src","href","remove","imageSrc"],"mappings":"yBAeA,IAAIA,EAAwC,SAAUC,EAASC,EAAYC,EAAGC,GAE1E,OAAO,IAAKD,IAAMA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,IAAW,MAAOG,GAAKL,EAAOK,IACpF,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,IAAW,MAAOG,GAAKL,EAAOK,IACvF,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,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