Created
December 15, 2018 06:08
-
-
Save EionRobb/560c6d72f0f52449b7cbc08f0f6d28a6 to your computer and use it in GitHub Desktop.
Quick hack to send a broadcast message to Google Home devices connected to an account
This file contains 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
<?php | |
if (!isset($_GET['text'])) { | |
header('HTTP/1.1 404 Not Found'); | |
exit; | |
} | |
$refresh_token = ''; | |
$access_token = ''; | |
$http = array( | |
'content' => 'refresh_token=' . $refresh_token . '&'. | |
'client_id=665279033229-p2offua1jokn23nl5hetk3gdjnl4djte.apps.googleusercontent.com&'. | |
'client_secret=DG37mUkYwZRB25hB598bfI7o&'. | |
'grant_type=refresh_token', | |
'method' => 'POST', | |
'header' => "content-type: application/x-www-form-urlencoded\r\nConnection: close", | |
//'proxy' => 'tcp://127.0.0.1:8888', | |
); | |
$ssl = array( | |
'verify_peer' => false, | |
); | |
$token_context = stream_context_create(array('http' => $http, 'ssl' => $ssl)); | |
$token = file_get_contents('https://accounts.google.com/o/oauth2/token', false, $token_context); | |
$token_info = json_decode($token, true); | |
$url = 'https://embeddedassistant.googleapis.com/google.assistant.embedded.v1alpha2.EmbeddedAssistant/Assist'; | |
$access_token = $token_info['access_token']; | |
$timeout = 60; | |
$command = 'broadcast ' . preg_replace('@[^a-z ]@', '', strtolower($_GET['text'])); | |
$len = strlen($command); | |
//hack up the protobuf | |
$postdata = "\x00\x00\x00\x00".chr(60+$len)."\x0A".chr(58+$len)."2".chr($len).$command."\x12\x08\x08\x01\x10\xc0\xbb\x01\x18d\x1a\x07\x12\x05en-US\"#\x0A\x10sample_device_id\x1a\x0fsample_model_id"; | |
$opts = array(); | |
$opts['http'] = array(); | |
$opts['http']['method'] = "POST"; | |
$opts['http']['header'] = "Authorization: Bearer " . $access_token . "\r\n" . | |
"Content-Type: application/grpc\r\n" . | |
"Connection: close"; | |
$opts['http']['timeout'] = $timeout; | |
$opts['http']['content'] = $postdata; | |
$opts['ssl'] = array(); | |
$opts['ssl']['verify_peer'] = false; | |
$context = stream_context_create($opts); | |
$response = file_get_contents($url, false, $context); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment