The string "/bin/cat flag.txt" is not present in the binary, so the method used in "split" won't work here.
We are given a function print_file and our task is to call print_file("flag.txt"). There is no "flag.txt" string in the binary either, so we have to input this string and store it somewhere, for example, the .bss segment.
As the instruction suggests, we should look for a gadget mov [reg], reg:
The idea is:
Store the string "flag" in ebp.
Store the address of bss in edi.
Use the gadget mov dword ptr [edi], ebp ; ret to pass the string flag to the .bss segment.
Repeat step 1 to 3 to pass the string ".txt" to bss + 4.
Again, the 64-bit case is even simpler. The idea is the same, except we can pass the string "flag.txt" in one round because we are dealing with 64-bit registers.