Mango是一种DSL,其语法与Objective-C非常相似,Mango也是iOS应用程序修补程序SDK

网友投稿 1768 2022-10-19

Mango是一种DSL,其语法与Objective-C非常相似,Mango也是iOS应用程序修补程序SDK

Mango是一种DSL,其语法与Objective-C非常相似,Mango也是iOS应用程序修补程序SDK

MangoFix中文资料集合

MangoFix 学习讨论QQ群:766215773

Mango

MangoFix is a DSL which syntax is very similar to Objective-C,MangoFix is also an iOS App hotfix SDK. You can use MangoFix method replace any Objective-C method.

Example

#import "AppDelegate.h"#import @implementation AppDelegate- (BOOL)encryptPlainScirptToDocument{ NSError *outErr = nil; BOOL writeResult = NO; NSURL *scriptUrl = [[NSBundle mainBundle] URLForResource:@"demo" withExtension:@"mg"]; NSString *planScriptString = [NSString stringWithContentsOfURL:scriptUrl encoding:NSUTF8StringEncoding error:&outErr]; if (outErr) goto err; { NSURL *publicKeyUrl = [[NSBundle mainBundle] URLForResource:@"public_key.txt" withExtension:nil]; NSString *publicKey = [NSString stringWithContentsOfURL:publicKeyUrl encoding:NSUTF8StringEncoding error:&outErr]; if (outErr) goto err; NSString *encryptedScriptString = [MFRSA encryptString:planScriptString publicKey:publicKey]; NSString * encryptedPath= [(NSString *)[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"encrypted_demo.mg"]; NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:encryptedPath]) { [fileManager createFileAtPath:encryptedPath contents:nil attributes:nil]; } writeResult = [encryptedScriptString writeToFile:encryptedPath atomically:YES encoding:NSUTF8StringEncoding error:&outErr]; }err: if (outErr) NSLog(@"%@",outErr); return writeResult;}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { BOOL writeResult = [self encryptPlainScirptToDocument]; if (!writeResult) { return NO; } NSURL *privateKeyUrl = [[NSBundle mainBundle] URLForResource:@"private_key.txt" withExtension:nil]; NSString *privateKey = [NSString stringWithContentsOfURL:privateKeyUrl encoding:NSUTF8StringEncoding error:nil]; MFContext *context = [[MFContext alloc] initWithRASPrivateKey:privateKey]; NSString * encryptedPath= [(NSString *)[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"encrypted_demo.mg"]; NSURL *scriptUrl = [NSURL fileURLWithPath:encryptedPath]; [context evalMangoScriptWithURL:scriptUrl]; return YES;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:[self genView]];}- (UIView *)genView{ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 150, 200)]; return view;}@end

class ViewController:UIViewController{- (UIView *)genView{ UIView *view = UIView.alloc().initWithFrame:(CGRectMake(50, 100, 150, 200)); view.backgroundColor = UIColor.redColor(); return view;}}

Installation

CocoaPods

Add pod 'MangoFix' to your Podfile.

Run pod install or pod update.Import

Usage

Objective-C

#import exec Mango Script by [context evalMangoScriptWithSourceString:@""];

MFContext *context = [[MFContext alloc] init];// exec mango file from network[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://xxx/demo.mg"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSString *script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];    [context evalMangoScriptWithSourceString:script];}]; // exec local mango fileNSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mg"];NSString *script = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil];[context evalMangoScriptWithSourceString:script];

Mango

Quick start

Mango Type usage

Mango support type as fllow:

void

equivalent to Objective-C `void`.

BOOL

equivalent to Objective-C `BOOL`.

uint

equivalent to Objective-C `unsigned char`、`unsigned short`、`unsigned int`、`unsigned long`、`unsigned long long`、`NSUInteger`.

int

equivalent to Objective-C `char`、`short`、`int`、`long`、`long long`、`NSInteger`.

double

equivalent to Objective-C `double`、`float`、`CGFloat`.

id

equivalent to Objective-C `id`.

OCClassName *

NSString *str = @"";

Block

Block blokc = ^id(id arg){};

Class

Class clazz = NSString.class();

struct

struct CGRect rect;// must add struct keyword before structure variables defined.

Pointer

Pointer ptr; // C pointer.

CFunction

CFunction ptr = CFunction("c function name"); // CFunction.

Ohter

For more information on MangFix usage, see the MangoFix project unit test.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Attribute(特性)
下一篇:oracle 12c 13姨
相关文章

 发表评论

暂时没有评论,来抢沙发吧~