问题
In a Linux console when a C program asks for a string (i.e. username) how can I insert non-printable chars?
I search something better thenprintf '\x48\x83\xc4\x50\x48\xbf\x3d...etc' | ./myProgram.bin
or./myProgram.bin < dataFile
I prefer to type chars when needed but I don't know how to write non-printable ones.
Thank you
回答1:
It worked using xclip (printf '\x48\x83...' | xclip) to copy the string to clipboard.
Then, when the program asks for the string, I used SHIFT+CTRL+V to paste the string.
It generally works, except for certain characters (\x08, ...) that the input function (gets, ...) can ignore or use as control character.
回答2:
Non printable characters have decimal value from 0 to 31. You can print them this way:
void main() {
int i;
char c;
for(i=0;i<32;i++) {
c=i;
cout<<c<<" ";
}
getch();
}
Same way, you can read the characters in terms of their integer values....However, putting them alongwith printable characters in one string, would be another uphill task.
来源:https://stackoverflow.com/questions/18945448/input-string-with-non-printable-chars