简体   繁体   English

将0x20、0x00、0x0d,0x0a字节传递给strcmp()

[英]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.

相关问题 带字节的串行通信(0x00 问题) - Serial communication with bytes (0x00 problem) 编码错误:输入转换因输入错误而失败,使用Flask和BeautifulSoup时字节为0x9D 0x29 0x2E 0x20 - encoding error : input conversion failed due to input error, bytes 0x9D 0x29 0x2E 0x20 when using Flask and BeautifulSoup Python-如果位和0x20 == 0x20 - Python - Confused by if statement if bits&0x20==0x20 Python 将十六进制值从 0x00 转换为 0x0 - Python convert hex value from 0x00 to 0x0 <read-write buffer ptr 0x00, size 855 at 0x00>蟒蛇 - <read-write buffer ptr 0x00, size 855 at 0x00> python 打印“ \\ x09”,打印0x20,如何将0x09打印到STDOUT? - Print “\x09”, print 0x20, how to print 0x09 to STDOUT? 编写转义字节字符的字符串,即“ \\ x00 \\ x20 \\…”,就好像它们是字节一样 - Write string of escaped byte characters, ie '\x00\x20\…', as if they were bytes Django URL arg不能包含NUL(0x00)字符 - Django url arg cannot contain NUL (0x00) characters how to store bytes like b'PK\x03\x04\x14\x00\x08\x08\x08\x009bwR\x00\x00\x00\x00\x00\x00\x00 to dataframe or csv in python - how to store bytes like b'PK\x03\x04\x14\x00\x08\x08\x08\x009bwR\x00\x00\x00\x00\x00\x00\x00 to dataframe or csv in python 如何通过 python 使 16 位到 8 位像 0x0300 到 0x03 和 0x00? - how to make 16bit to 8bit like that 0x0300 to 0x03 and 0x00 by python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM