我如何迭代所有 ASCII 以将它们用作变量?

How do i iterate all ASCII to use them as variable?

我有一个二进制文件 "crackme",我想尝试将所有 ASCII 字符作为参数,这是我目前所做的。

 #!/bin/bash                                                                                                                                                                                   

for ((i=32;i<127;i++))
do
    c="\$(printf %03o "$i")";
    echo $c;
    ./crackme $c;
done

执行的命令是“./crackme \65”,显然我正在尝试执行“./crackme A”。

不漂亮,但这个有效:

for ((i=32;i<127;i++))
do
    printf -v c '\x%x' "$i"
    ./crackme "$(echo -e $c)"
done

为了后代,几个有用的函数:

# 65 -> A
chr() { printf "\x$(printf "%x" "")"; }
# A -> 65
ord() { printf "%d" "'"; }

ord printf 命令的奇数最后一个参数是documented:

Arguments to non-string format specifiers are treated as C language constants, except that a leading plus or minus sign is allowed, and if the leading character is a single or double quote, the value is the ASCII value of the following character.

然后

for ((i = 32; i < 127; i++)); do
    ./crackme "$(chr $i)"
done