memorypatch

19/08/2019 - 04:00 pm
#import <map>
#import "extends/UISwitch+Block.h"
#import "libraries/KittyMemory/MemoryPatch.hpp"




#define ARM64_RET_TRUE "\x20\x00\x80\xd2\xc0\x03\x5f\xd6"
#define ARM64_REPLACE_HIGH_VALUE "\xe0\xff\x9f\x52\xc0\x03\x5f\xd6"


// map variable to handle patches
static std::map <std::string, MemoryPatch> _patchesMap;
static void createPatchesMap()
{
  /* NULL for base executable */
  /* addresses are zero because this is just an example */

  _patchesMap["Minimap"] = MemoryPatch(NULL, /*address*/0x101741ED8, ARM64_RET_TRUE, 8); //for example canShow function
  
}






// simple label with toggle
static UISwitch *createToggle(CGPoint point, NSString *name) {

   CGRect rect = CGRectMake(point.x, point.y, 210.f, 30.f);

   UILabel *label = [[UILabel alloc] initWithFrame:rect];
   label.text = name;
   label.textAlignment = NSTextAlignmentLeft;
   label.adjustsFontSizeToFitWidth = YES;
   label.numberOfLines = 0;
   label.textColor = [UIColor whiteColor];
   label.backgroundColor = [UIColor clearColor];


   currTag++;

   UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(CGRectGetMaxX(rect) + 5.f, rect.origin.y, 32.5f, 30.f)];
   sw.onTintColor = [UIColor redColor]; // toggle on state color
   sw.tag = currTag;

   currTag++;

   return sw;
}



// Hooking app load up to initialize patches
%hook UnityAppController

-(void)DidBecomeActive:(id){
     // create & initialize patches map
     createPatchesMap();

     // loop through patches map and add toggle for each patch
     for (auto &it : _patchesMap)
     {
       NSString *patch_name = [NSString stringWithUTF8String:it.first.c_str()];
      [createToggle(CGPointMake(x, y), patch_name) handleControlEvent:^(UISwitch *sw){
	if([sw isOn]){ // toggle is on
             it.second.Modify();
           } else { // off
             it.second.Restore();
           }
	}];

       y += 35.f; // spacing for next toggle
     }

   });
}