MacOS Mach-O executable fails to save at WriteToFile

Issues related to VMProtect
liamxx
Posts: 3
Joined: Thu Feb 01, 2018 7:13 am

MacOS Mach-O executable fails to save at WriteToFile

Postby liamxx » Thu Feb 01, 2018 7:46 am

I am attempting to protect a Mach-O executable VMProtect, but when it gets to the "saving startup code" stage it will fail with the output file disappearing at any arbitrary point in the process. I have attempted to fix this by testing a variety of settings with no luck. Currently, I have every protection setting turned to off (debugger, packing, etc.) but am still receiving the WriteToFile runtime error (it will successfully compile with no protected functions or strings, though). I am using VMProtect Professional v 3.1.2 build 830.

I am willing to share my program through private means. Thanks in advance.

liamxx
Posts: 3
Joined: Thu Feb 01, 2018 7:13 am

Re: MacOS Mach-O executable fails to save at WriteToFile

Postby liamxx » Thu Feb 01, 2018 9:35 am

After careful investigation, I have discovered that my application will ONLY compile if all optimizations (-O2, in my case) and loader paths are not changed. Before I protect my application, I use install_name_tool to fix the loader paths to some libraries and -O2 to increase performance and decrease size, so I'd much rather prefer to be able to do both.

Admin
Site Admin
Posts: 1438
Joined: Mon Aug 21, 2006 8:19 pm
Location: Russia, E-burg
Contact:

Re: MacOS Mach-O executable fails to save at WriteToFile

Postby Admin » Thu Feb 01, 2018 9:50 am

"Runtime error at WriteToFile" means that your binary has no enough space in the Mach-O header for adding a new segment.

liamxx
Posts: 3
Joined: Thu Feb 01, 2018 7:13 am

Re: MacOS Mach-O executable fails to save at WriteToFile

Postby liamxx » Thu Feb 01, 2018 11:42 pm

After dissecting a working executable and the broken one, I can see what you mean:
Image

Optimizations definitely delete most of the free space in the header. It was only until I removed the -O2 flag for my program (replacing it with -O1 which only optimizes speed) that it was able to compile with enough free space in the header. It would be quite nice if VMProtect could allocate more header space automatically, but other than that my problem is solved.

Admin
Site Admin
Posts: 1438
Joined: Mon Aug 21, 2006 8:19 pm
Location: Russia, E-burg
Contact:

Re: MacOS Mach-O executable fails to save at WriteToFile

Postby Admin » Fri Feb 02, 2018 3:48 am

VMProtect uses all free space between Mach-O header and the first section (in your case it's the "__text") for storing of new segments and sections. Please notice that the "__text" can't be moved in other part of file because this trick will "kill" all references between "__text" and other sections. Only compiler without size optimization can do it.