【发布时间】:2018-08-28 13:58:39
【问题描述】:
我正在尝试从我的网站为平板电脑获取 RGB 值。平板电脑只接受 SICP 命令。 目前我正在使用 netcat 建立这样的连接:
$cmd = 'echo -n -e "\x09\x01\x00\xf3\x01\xff\x80\x00'.$checksum.'" | nc '.$ip.' '.$port;
shell_exec($cmd);
echo $cmd;
这适用于平板电脑,但我仍然无法为 3 个 RGB 值创建变量,因为我的校验和计算器需要六进制格式。 我可以在 PHP("hexstrcomp") 中创建六进制数组,其中最后 4 个值是 RGB 和校验和。
$hexshowndec = array("09","01","00","f3", "01", "ff", "80", "00", "00");
$hexstrcomp = array("\x09","\x01","\x00","\xf3","\x01","\xff","\x80","\x00","\x00");
for ($i = 0; $i < 8; $i++) // 8 for message length before checksum
{
$byte = $hexstrcomp[$i];
$hexstrcomp[8] = $hexstrcomp[8] ^ ord($byte);
echo "Current checksum: " . sprintf("%02x", $hexstrcomp[8]) . "<br>"; // 0x23
}
echo "Checksum: " . sprintf("%02x", $hexstrcomp[8]);
$cmd = 'echo -n -e "\x' . $hexshowndec[0]
. '\x' . $hexshowndec[1]
. '\x' . $hexshowndec[2]
. '\x' . $hexshowndec[3]
. '\x' . $hexshowndec[4]
. '\x' . $hexshowndec[5]
. '\x' . $hexshowndec[6]
. '\x' . $hexshowndec[7]
. '\x' . sprintf("%02x", $hexstrcomp[8])
. '" | nc '.$ip.' '.$port;
shell_exec($cmd);
echo "<p>Orange!</p>";
例如,如何更改 hexstrcomp[5] 的值,以便我仍然可以成功使用我的校验和?尝试以下导致校验和失败:
$hexshowndec[6] = sprintf("%02x", $hexstrcomp[6]); //gets this done
$hexstrcomp[6] = "\x00"; // works, but need variable for 00 part
$hexstrcomp[6] = "\x{$hexshowndec[6]}"; // fails
$hexstrcomp[6] = "\x" . $hexshowndec[6]; // fails
【问题讨论】:
标签: php arrays hex rgb checksum