

The encode() function represents data in an alternative form. We used the join() function to join the elements of byte_list as char. It takes an iterable object as an argument and returns a single string formed from the elements of the iterable object separated by a separator character(s). The join() function in Python is a built-in method that combines multiple strings into one string.

Next, we used the open() function to open a file for reading, or writing is a built-in function in Python. We used the with keyword to wrap the code block of writing the byte_array to the bytes_array.txt file.

It handles errors and exceptions without disrupting the flow of the program. To successfully write the byte_array to the file, we used Python’s try-except control flow statement.

Similarly, we can run the same command on the object file to disassemble the code: $ objdump -d test.oĤ: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)Īs we can see above, unlike the binary file, the object file shows only the main section.īy default, it shows the disassembly in ATT mnemonic.We used the bytearray() function to convert the byte_list to the byte_array. In order to ensure this is the disassembly, we may modify the C program, compile it and run the objdump command on it again to see the changes. We see the add instruction to add 20 (0x14) to the variable i at the memory address 605. Here we can see the relevant main section after stripping off others. Since we have used the -d flag, it’ll print all the executable sections. Using the -d option, we can see the assembly code for the binary: $ objdump -d testĥfe: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)Ī binary file contains a lot of sections in ELF format with address and metadata for properly loading the executable when it is launched.
