Domanda

Using a python script, I want to print out the following hex output :

hex_values = \
"\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd" + \
"\x80\x5b\x5e\x52\x68\x02\x00\x1a\x0a\x6a\x10\x51\x50\x89" + \
"\x80\x43\xb0\x66\xcd\x80\x93\x59\x6a\x3f\x58\xcd\x80\x49" + \
"\x50\x53\x89\xe1\xb0\x0b\xcd\x80"

with print hex_values.

This ends out outputting:

./test
1���SCSj���f̀[^Rh
jQP��C�f̀�Yj?X̀IPS���

which is expected. However, when I feed this output into a compiled C file with something like

./compiled_c_here $(test)

The compiled C file will error complaining that there are in fact too many arguments being fed in. This is because the python script outputs a hex sequence that has spaces between the ASCII characrers which causes the executable to believe this is 2 inputs instead of one long hex string.

Note: The compiled C file will behave correctly if the hex output has no spaces (However, I believe I can't just ignore the spaces as they represent some of the ASCII sequence).

The compiled C file is largely a black box to me and I want to be able to preserve the hex output such that it would behave the same way as if received ASCII characters represented the initial hex values.

What is a good way to print the hex values from the initial python script such that they can be interpreted as a single hex string without modifying the compiled C file.

È stato utile?

Soluzione

Enclose the data in quotes

./compiled_c_here "$(test)"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top