User:Nicolas17/MobileMail/MessageViewController/previewActionForSwipeAction:withMessage:forSwipe:

From iPhone Development Wiki
Jump to: navigation, search
-(UIPreviewAction*)_previewActionForSwipeAction:(unsigned long long)action withMessage:(id)message forSwipe:(BOOL)swipe;

This method in MessageViewController creates a UIPreviewAction object (action shown in the 3D Touch "peek" view). It's called by leadingPreviewAction and trailingPreviewAction to get the actions on the sides of the peek, and by _previewActionsForSwipeActions:excludingSwipeActions: for the actions at the bottom.

Reverse engineering info

I'm starting to decompile this method and will put the pseudocode in this page.

This method contains two jump tables (at least in arm64), presumably compiled from switch statements, which Hopper doesn't handle automatically even in the disassembly, and it will be a bit of a pain to figure them out manually.

Decompiled code

This is what I have so far decompiling this method.

-(UIPreviewAction*)_previewActionForSwipeAction: (unsigned long long)action
                                    withMessage: (id)message
                                       forSwipe: (BOOL)swipe
{
    x20 = swipe
    x21 = message
    x19 = action
    x22 = self

    x25 = [self presentingViewController];
    if (x25 == 0) {
        x25 = [[UIApplication] sharedApplication] sceneController];
    }

    w28 = 0xc2000000 // from "movz w28, #0xc200, lsl #16"; I don't know if that's correct
    if (action > 5) goto L1; // if (action > 5)

/* TODO; involves jumptable
000000010009bd34         movz       x0, #0x0
000000010009bd38         adr        x9, #0x10009c384
000000010009bd3c         nop        
000000010009bd40         ldrsw      x10, [x9, x19, lsl #2]
000000010009bd44         add        x9, x10, x9
000000010009bd48         br         x9
*/

    L1: // 0x10009bd4c
    if (action > 6) goto L2; // if (action > 6)

    //0x10009bd54
    x23 = [[NSBundle mainBundle] localizedStringForKey: @"PREVIEW_SWIPE_ARCHIVE" value:"" table:"Main-OrbHW"];

    // This is initializing a block_literal struct
    w24 = 0;
    var_110 = _NSConcreteStackBlock; //64-bit
    var_118 = w28; // 32-bit
    var_11c = 0x00000000; // 32-bit, wzr
    var_120 = 0x10009c82c; // 64-bit
    var_128 = 0x1001fe1e0; // 64-bit
    var_148 = w20; // 8-bit
    var_130 = x22; // both 64-bit; these come from a STP that I'm not sure about
    var_138 = x21;
    var_140 = x25;
    x27 = &var_110;
    w26 = 0x2; // orr w26, wzr, #0x2
    goto jump_A_124;

    L2: // 0x10009bdd8
}