[英]Passing 0x20, 0x00, 0x0d, 0x0a bytes to strcmp()
I'm trying to do a challenge where there's a strange strcmp. 我正在尝试在有奇怪的strcmp的地方进行挑战。 It is the following: 内容如下:
if(strcmp(argv[1],"\x00")) return 0;
if(strcmp(argv[2],"\x20\x0a\x0d")) return 0;
I've tried to pass the arguments through Python but the bytes aren't read in the correct way. 我试图通过Python传递参数,但未以正确的方式读取字节。 This is what I tried: 这是我尝试的:
./program $(python -c 'import sys;sys.stdout.write("\x00 \x20\x0a\x0d")')
I also tried to use their repr
but that didn't work too. 我也尝试使用他们的repr
但那也没有用。 They are currently being evaluated for what every byte actually represents: how do I "pass them as they are" correctly? 目前正在评估它们的每个字节实际代表什么:如何正确“按原样传递它们”?
If you don't want the backslash escapes to be evaluated, you need to escape them. 如果您不希望对反斜杠转义进行评估,则需要对它们进行转义。
This: 这个:
if(strcmp(argv[1], "\\x20\\x0a\\x0d")) return 0;
compares against the literal string "\\x20\\x0a\\x0d"
, which has 12 characters. 与文字字符串"\\x20\\x0a\\x0d"
进行比较,该字符串包含12个字符。
From a command-line perspective, the first argument should be an empty string (typically written as ""
in most shells), and the second should be the tree-character string " \\n\\r"
in Python notation. 从命令行角度来看,第一个参数应该是一个空字符串(在大多数shell中通常写为""
),第二个参数应该是Python表示法中的树字符字符串" \\n\\r"
。
Not sure what Python has to do with things here, from eg bash you should be able to do: 不知道Python与这里的事情有什么关系,例如bash,您应该能够做到:
$ ./program "" $'\n\r'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.