Binary 如何在没有uudecode、base64或x/y/z/modem的情况下通过串行端口传输二进制文件?

Binary 如何在没有uudecode、base64或x/y/z/modem的情况下通过串行端口传输二进制文件?,binary,port,transfer,Binary,Port,Transfer,我正在尝试通过一个小型嵌入式设备上的串行端口传输二进制文件,该设备没有uudecode、base64或x/y/z/modem UTIL 我为far所做的尝试是: $ sudo picocom -l -r -b 921600 --send-cmd "ascii-xfr -snv" /dev/ttyS0 # cat > libdebug.so $ cat libdebug.so | sudo tee /dev/ttyS0 但这会挂起我的设备。实际上,我能做的就是以ascii模式上传我自己的

我正在尝试通过一个小型嵌入式设备上的串行端口传输二进制文件,该设备没有uudecode、base64或x/y/z/modem UTIL

我为far所做的尝试是:

$ sudo picocom -l -r -b 921600 --send-cmd "ascii-xfr -snv" /dev/ttyS0
# cat > libdebug.so

$ cat libdebug.so | sudo tee /dev/ttyS0

但这会挂起我的设备。

实际上,我能做的就是以ascii模式上传我自己的uudecode.sh,然后我可以用它来解码我自己的二进制文件

以下是适用于ksh的脚本:

#!/bin/ksh

# uudecode in POSIX bourne shell
#
# *EXCRUCIATINGLY* SLOW!!!
#
# Taken from a reply to a blog post here:
# http://www.weeklywhinge.com/?p=108
#
# Copyright (c) 2015, Rafael Kitover <rkitover@gmail.com>
# Modified in 2018, Philippe Bouchard <philippeb8@gmail.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bs=0
while read -r t ; do
    if [ "$bs" -eq 1 ] ; then
        if [ "a$t" = "aend" ] ; then
            bs=2
        else
            set $(printf "%d " "'$(echo $t | cut -c1)" "'$(echo $t | cut -c2)" "'$(echo $t | cut -c3)" "'$(echo $t | cut -c4)" "'$(echo $t | cut -c5)" "'$(echo $t | cut -c6)" "'$(echo $t | cut -c7)" "'$(echo $t | cut -c8)" "'$(echo $t | cut -c9)" "'$(echo $t | cut -c10)" "'$(echo $t | cut -c11)" "'$(echo $t | cut -c12)" "'$(echo $t | cut -c13)" "'$(echo $t | cut -c14)" "'$(echo $t | cut -c15)" "'$(echo $t | cut -c16)" "'$(echo $t | cut -c17)" "'$(echo $t | cut -c18)" "'$(echo $t | cut -c19)" "'$(echo $t | cut -c20)" "'$(echo $t | cut -c21)" "'$(echo $t | cut -c22)" "'$(echo $t | cut -c23)" "'$(echo $t | cut -c24)" "'$(echo $t | cut -c25)" "'$(echo $t | cut -c26)" "'$(echo $t | cut -c27)" "'$(echo $t | cut -c28)" "'$(echo $t | cut -c29)" "'$(echo $t | cut -c30)" "'$(echo $t | cut -c31)" "'$(echo $t | cut -c32)" "'$(echo $t | cut -c33)" "'$(echo $t | cut -c34)" "'$(echo $t | cut -c35)" "'$(echo $t | cut -c36)" "'$(echo $t | cut -c37)" "'$(echo $t | cut -c38)" "'$(echo $t | cut -c39)" "'$(echo $t | cut -c40)" "'$(echo $t | cut -c41)" "'$(echo $t | cut -c42)" "'$(echo $t | cut -c43)" "'$(echo $t | cut -c44)" "'$(echo $t | cut -c45)" "'$(echo $t | cut -c46)" "'$(echo $t | cut -c47)" "'$(echo $t | cut -c48)" "'$(echo $t | cut -c49)" "'$(echo $t | cut -c50)" "'$(echo $t | cut -c51)" "'$(echo $t | cut -c52)" "'$(echo $t | cut -c53)" "'$(echo $t | cut -c54)" "'$(echo $t | cut -c55)" "'$(echo $t | cut -c56)" "'$(echo $t | cut -c57)" "'$(echo $t | cut -c58)" "'$(echo $t | cut -c59)" "'$(echo $t | cut -c60)" "'$(echo $t | cut -c61)")
            l=$(($1 -32 & 63 ))
            shift
            while [ $l -gt 0 ] ; do
                i0=$(($1 -32 & 63))
                shift
                i1=$(($1 -32 & 63))
                shift
                i2=$(($1 -32 & 63))
                shift
                i3=$(($1 -32 & 63))
                shift
                if [ $l -gt 2 ] ; then
                    echo -ne "\0$(($i0 >> 4))$(($i0 >> 1 & 7))$(($i0 << 2 & 4 | $i1 >> 4))\0$(($i1 >> 2 & 3))$(($i1 << 1 & 6 | $i2 >> 5))$(($i2 >> 2 & 7))\0$(($i2 & 3))$(($i3 >> 3 & 7))$(($i3 & 7))"
                    true
                elif [ $l -eq 2 ] ; then
                    echo -ne "\0$(($i0 >> 4))$(($i0 >> 1 & 7))$(($i0 << 2 & 4 | $i1 >> 4))\0$(($i1 >> 2 & 3))$(($i1 << 1 & 6 | $i2 >> 5))$(($i2 >> 2 & 7))"
                    true
                else
                    echo -ne "\0$(($i0 >> 4))$(($i0 >> 1 & 7))$(($i0 << 2 & 4 | $i1 >> 4))"
                    true
                fi
                l=$(($l-3))
            done
        fi
    elif [ $(echo $t | cut -c1-5) = "begin" ]; then
        bs=1
    fi
done
#/bin/ksh
#POSIX bourne shell中的uudecode
#
#*极度缓慢!!!
#
#摘自对以下博客帖子的回复:
# http://www.weeklywhinge.com/?p=108
#
#版权所有(c)2015,Rafael Kitover
#Philippe Bouchard于2018年修改
#
#以源代码和二进制形式重新分发和使用,带或不带
#如果满足以下条件,则允许进行修改:
#*源代码的重新分发必须保留上述版权
#请注意,此条件列表和以下免责声明。
#*二进制形式的重新分发必须复制上述版权
#请注意,此条件列表和中的以下免责声明
#随分发提供的文件和/或其他材料。
#
#本软件由版权所有者“原样”和任何
#明示或默示保证,包括但不限于
#针对特定用途的适销性和适用性的保证如下:
#否认。在任何情况下,版权持有人均不对任何
#直接、间接、附带、特殊、惩戒性或后果性损害
#(包括但不限于采购替代货物或服务;
#使用、数据或利润的损失;或业务中断),无论是何种原因造成的;以及
#任何责任理论,无论是合同责任、严格责任还是侵权责任
#(包括疏忽或其他)以任何方式因使用本文件而产生
#软件,即使已告知此类损坏的可能性。
bs=0
而read-rt;做
如果[“$bs”-等式1];然后
如果[“a$t”=“aend”];然后
bs=2
其他的
(回音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音切切切-c3-c3-c3)3)“““““””(回音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音音“$(回声$t |切-c13)””$(回音$t及切切切—c16)“元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元元“$(echo$t | cut-c26)”“$(echo$t | cut-c27)”“““”””””““““”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””(回声(回声(回声(回声(回声(回声(回声t(回声(回声(回声(回声t(回声t)切切切切切切切切9)“$(echo$t | cut-c40)”“$(echo$t | cut-c41)(回音$t