I have a Python program which connects to an iPhone and pulls off the my_app.app but it also explores the .app folder to find the binary name as sometimes they can be different. my_app.app doesn't mean the binary is called my_app. Frustrating.
So I grab the binary name, and then my program that used to work, suddenly stops working, it seems when pulling the binary name from iPhone back to Mac, it inserts an ESC character, or ASCII char 27 at the start and end of the binary string. I thought I could fix this with str[1:-1]
but I'm still having problems.
Is there a way in Python to strip this out, or to convert it, or replace it to a proper character so it can be removed?
example: once I have pulled the binary file from the iPhone I want to run file
on it, however the presence of the ESC char at the end, means the shell cannot find the file.
EDIT: Added some code for further troubleshooting in case it isn't the ESC char
#grabbing the binary name
binName = dlg.actListBox.GetStringSelection()
binName = binName.replace('\x27', '')
binName = binName[1:-1]
#trying to run file
cmd = "file " + appBinPath + "/" + binName
p = subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE)
stdout = p.communicate()[0]
self.progressBox.AppendText(stdout)
#output I get in program is:
/Users/p/Documents/ios/output/myapp/myapp_decrypt/Payload/myapp.app/myapp: cannot open `/Users/p/Documents/ios/output/myapp/myapp_decrypt/Payload/myapp.app/myapp' (No such file or directory)
However if I copy the path above, and type file [path]
into a terminal and press Enter, I first receive a terminal beep tone (I'm guessing due to the ASCII 27 char) but on the second press the file
command works perfect, so that path is certainly correct.
#manual file cmd with same path as used by program
file /Users/p/Documents/ios/output/myapp/myapp_decrypt/Payload/myapp.app/myapp
/Users/p/Documents/ios/output/myapp/myapp_decrypt/Payload/myapp.app/myapp: Mach-O 64-bit executable
SOLVED: Using the repr()
function outlined below in the comments allowed us to see what was in the string. Comment from PM2Ring that ESC is \x1b
and a standard .replace()
solved this