title: libMobileGestalt.dylib crashed when Hooking MGCopyAnswer for ARM64
body: <p>When I try to hook MGCopyAnswer, I get a crash. I'm trying this on a jailbroken iPhone 5s in iOS 8.3, arm64 binaries.</p>
  
  <pre><code>#import &lt;substrate.h&gt;
  
  extern "C" CFTypeRef MGCopyAnswer(CFStringRef);
  MSHook(CFTypeRef, MGCopyAnswer, CFStringRef key)
  {
    return _MGCopyAnswer(key);
  }
  
  %ctor
  {
    NSString *appID = [[NSBundle mainBundle] bundleIdentifier];
    if ( appID &amp;&amp; [appID isEqualToString:@"com.test.test"])   {
      MSHookFunction(MGCopyAnswer, MSHake(MGCopyAnswer));
    }
  }
  </code></pre>
  
  <p>Makefile:</p>
  
  <pre><code>ARCHS = armv7 armv7s arm64
  TARGET = iphone:latest:8.0
  test2_FRAMEWORKS = UIKit
  
  include theos/makefiles/common.mk
  
  TWEAK_NAME = test2
  test2_FILES = Tweak.xm
  test2_LIBRARIES = MobileGestalt
  
  include $(THEOS_MAKE_PATH)/tweak.mk
  
  after-install::
    install.exec "killall -9 SpringBoard"
  </code></pre>
  
  <p>Crash log:</p>
  
  <pre><code>Version: 1.44 (1.4)
  Code Type: ARM-64 (Native)
  Parent Process: launchd [1]
  
  Date/Time:           2016-04-25 01:09:31.810 +0800
  Launch Time:         2016-04-25 01:09:31.564 +0800
  OS Version:          iOS 8.3 (12F70)
  Report Version:      105
  
  Exception Type:  EXC_BAD_INSTRUCTION (SIGILL)
  Exception Codes: 0x0000000000000001, 0x000000000068fe68
  Triggered by Thread:  0
  
  Thread 0 name:  Dispatch queue: com.apple.main-thread
  Thread 0 Crashed:
  0   libMobileGestalt.dylib          0x0000000195af7e84 0x195af4000 + 16004
  1   libMobileGestalt.dylib          0x0000000195af82bc MGGetBoolAnswer + 32
  2   AppSupport                      0x000000018b020594 __CPIsInternalDevice_block_invoke + 16
  3   libdispatch.dylib               0x0000000196c99950 _dispatch_client_callout + 12
  4   libdispatch.dylib               0x0000000196c9a828 dispatch_once_f + 92
  5   AppSupport                      0x000000018b02057c CPIsInternalDevice + 60
  6   UIKit                           0x0000000189b58750 ___UIApplicationUsesAlternateUI_block_invoke + 12
  7   libdispatch.dylib               0x0000000196c99950 _dispatch_client_callout + 12
  8   libdispatch.dylib               0x0000000196c9a828 dispatch_once_f + 92
  9   UIKit                           0x0000000189923750 UIApplicationInitialize + 1872
  10  UIKit                           0x0000000189922b1c UIApplicationMain + 320
  
  MGCopyAnswer:
  -&gt;  0x193a7fe84 &lt;+0&gt;:  .long  0x002d7c28                ; unknown opcode
      0x193a7fe88 &lt;+4&gt;:  .long  0x00000001                ; unknown opcode
      0x193a7fe8c &lt;+8&gt;:  stp    x20, x19, [sp, #32]
      0x193a7fe90 &lt;+12&gt;: stp    x29, x30, [sp, #48]
      0x193a7fe94 &lt;+16&gt;: add    x29, sp, #48
      0x193a7fe98 &lt;+20&gt;: sub    sp, sp, #48
      0x193a7fe9c &lt;+24&gt;: mov    x19, x1
      0x193a7fea0 &lt;+28&gt;: mov    x22, x0
      0x193a7fea4 &lt;+32&gt;: movz   w0, #0
      0x193a7fea8 &lt;+36&gt;: bl     0x193a7f564               ; ___lldb_unnamed_function54$$libMobileGestalt.dylib
      0x193a7feac &lt;+40&gt;: orr    w1, wzr, #0x1
      0x193a7feb0 &lt;+44&gt;: mov    x0, x22
      0x193a7feb4 &lt;+48&gt;: bl     0x193a7f5fc               ; ___lldb_unnamed_function56$$libMobileGestalt.dylib
      0x193a7feb8 &lt;+52&gt;: mov    x21, x0
      0x193a7febc &lt;+56&gt;: movz   w20, #0
      0x193a7fec0 &lt;+60&gt;: cbz    x21, 0x193a7fefc          ; &lt;+120&gt;
      0x193a7fec4 &lt;+64&gt;: ldr    w20, [x21, #148]
      0x193a7fec8 &lt;+68&gt;: mov    x0, x21
  orig_MGCopyAnswer
      0x104234000: movz   x1, #0
      0x104234004: stp    x24, x23, [sp, #-64]!
      0x104234008: stp    x22, x21, [sp, #16]
      0x10423400c: ldr    x16, #8
      0x104234010: br     x16
      0x104234014: .long  0x93a7fe8c                
      0x104234018: .long  0x00000001                ; unknown opcode
  </code></pre>
  
  <p>What am I doing wrong?</p>