1

我正在尝试按照 George Georgovassilis 在此处所做的操作从 Axis 嵌入式 Linux 产品中控制 Kasa Smartplug:https ://blog.georgovassilis.com/2016/05/07/controlling-the-tp-link-hs100- wi-fi-smart-plug/ 我已经设法从 Axis 盒子打开和关闭插头,但我在尝试查询 Smartplug 的开/关状态时遇到了困难,因为我没有 od(或 hd , hexdump 或 xxd) 并且 Smartplug 输出是二进制的。执行此操作的 George 代码片段是:

decode(){
    code=171
    input_num=`od $ODOPTS`
    IFS=' ' read -r -a array <<< "$input_num"
    args_for_printf=""
    for element in "${array[@]}"
    do
        output=$(( $element ^ $code ))
        args_for_printf="$args_for_printf\x$(printf %x $output)"
        code=$element
    done
    printf "$args_for_printf"
 }

有没有办法我可以使用基本的 shell 命令而不是使用 od 来做到这一点?Axis 盒子说它是 crisv32 上的 Linux 2.6.29,我大约 30 年前曾经使用 Unix,所以我很挣扎......

4

2 回答 2

2

没有 od 或 hd 的 Linux shell 中的八进制转储

看起来很简单awk。从这个答案中借用代码并从这个答案中拆分出来很简单:

awk -v ORS='' -v OFS='' 'BEGIN{ for(n=0;n<256;n++)ord[sprintf("%c",n)]=n }  
    { split($0, chars, "");
    chars[length($0)+1]=RS; # add the newline to output. One could check if RS is empty.
    # and print
    for (i=1;i<=length($0)+1;++i) printf("%o\n", ord[chars[i]]) }'
于 2020-12-20T17:33:10.737 回答
0

我最终设法解决了这个问题:我不知道如何仅使用目标机器上可用的 shell 命令来复制 od,所以我创建了一个非常简单的 C 程序来从二进制文件中读取每个字节并将其打印为一个可读的字符。这包括复制奇怪的 XOR,这似乎与基本加密有关(可能)。然后我使用 sed 提取了我需要的值。在我的 Lubuntu 机器上为目标 CRIS 架构交叉编译这个 C 对于一个简单的程序来说并不太难。一旦我将模型代码简化为我自己的最小可重现示例,一切都会变得容易得多。谢谢大家。

于 2021-01-07T14:33:56.390 回答