Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Convert unsigned char array to argv

+6 votes
asked Aug 17, 2023 by winapiadmin (210 points)
edited Oct 13, 2023 by winapiadmin

I have a array:

    unsigned char byte[122] = {
0x40, 0x16, 0x98, 0x00, 0xC0, 0x00, 0x98, 0x00, 0xEE, 0xFE, 0xEE, 0xFE,
0xEE, 0xFE, 0xEE, 0xFE, 0xEE, 0xFE, 0xEE, 0xFE, 0xEE, 0xFE, 0xEE, 0xFE,
0xEE, 0xFE, 0xEE, 0xFE, 0xEE, 0xFE, 0xEE, 0xFE, 0xD2, 0x6A, 0x3F, 0x29,
0xF0, 0x87, 0x00, 0x1B, 0x22, 0x43, 0x3A, 0x5C, 0x55, 0x73, 0x65, 0x72,
0x73, 0x5C, 0x61, 0x73, 0x64, 0x66, 0x73, 0x5C, 0x4F, 0x6E, 0x65, 0x44,
0x72, 0x69, 0x76, 0x65, 0x5C, 0x44, 0x65, 0x73, 0x6B, 0x74, 0x6F, 0x70,
0x5C, 0x64, 0x75, 0x6D, 0x70, 0x65, 0x72, 0x5C, 0x44, 0x55, 0x4D, 0x50,
0x42, 0x49, 0x4E, 0x2E, 0x45, 0x58, 0x45, 0x22, 0x00, 0xAB, 0xAB, 0xAB,
0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xAB, 0xFE, 0xFE, 0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xB7, 0x6A, 0x3C, 0x4F, 0xFF, 0x87, 0x00,
0x00, 0x38

How can I store to a single array, for example, like the argv parameter?

1 Answer

+1 vote
answered Aug 18, 2023 by Peter Minarik (82,920 points)
edited Aug 21, 2023 by Peter Minarik

I do not understand your question.

Would you like to store the variable byte in argv or you would like to read argv and store it in variable byte?

It seems like you're asking for the first, but it makes no sense as the value of argv comes from the operating system, whatever the caller of the program provided because you never call the main() function manually.

If you want to pass in data from the operating system to your program, you can provide it as arguments, e.g.: MyProgram.exe ARGUMENT1 ARGUMENT2 ARGUMENT3 etc, assuming your program is compiled to MyProgram.exe.

However, since your input bytes interpreted as character string contain non-printable characters, those you cannot really enter from the command line (especially the 0x00).

This could be circumvented if you'd create a batch file and launch your program from there. E.g.: launcher.bat could have the following content:


where SPECIAL_ARGUMENTS contains the byte sequence and characters. You will need a binary editor though to add the special 0x00 and similar characters in the SPECIAL_ARGUMENTS part between the quotes.


Visual Studio has a built-in binary editor for instance or you can look for your preferred one online.

commented Aug 21, 2023 by winapiadmin (210 points)
It's reversed engineered from DUMPBIN.EXE 6.0. That's why it causes the problem, it has passed to spawnvp().
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.