建议你要么使用苹果提供的正规方法,要么使用逆向+tweak开发,
@Ouroboros hi,Ouroboros ,看见你的代码,然后尝试了一下,createVPN(@“10.3.2.3”,@“administrator”,@“aasss!”,@“PPTP”); 程序得到执行了,但是在设置里面没有看见我设置的vpn,请教一下是什么原因呢?
你调用了函数, 程序当然得到了执行, 但我怎么知道是什么原因…
hook VPNConnectionStore, 注意看类中的方法
哥们,我也遇到这个问题,不知道你解决了没?
我在 hook VPNConnectionStore的时候出现了 hook 不到的问题,请问你有遇到吗
前辈 你们解决了吗 这个问题
你好,我按照你的代码写了个tweak,hook的Preference,打开Preference的时候可以成功创建VPN,然后我接着调用connect那段代码就是连接不上,但是当我手动点击设置–通用–vpn,再进行连接可以连接上了,请问这可能是什么原因呢?
张总,我改了下你的代码,改成打开所有app都会去连接VPN,出现的问题是,第一次打开某app连接不上,再打开一个app又连接上了,请问这可能是什么原因呢?
谁知道你改成啥样了?
下面这是我改过的,在成功保存VPN配置后,休眠10s,调用connectVPN()进行连接。
void createVPN(NSString* server, NSString* username, NSString* password, NSString* SharedSecret, NSString* type)
{
NSBundle* vpn = [NSBundle bundleWithPath:@"/System/Library/PreferenceBundles/VPNPreferences.bundle"];
if ([vpn load] == NO)
{
NSLog(@"load vpn failed");
return;
}
VPNConnectionStore* vpnStore;
VPNSetupListController* vpnSetup;
vpnStore = [objc_getClass("VPNConnectionStore") sharedInstance];
NSLog(@"createVPN vpnStore description:%@",[vpnStore description]);
for (NEConfiguration* cfg in [vpnStore configurations])
{
NSString* uuid = [[cfg identifier] UUIDString];
if ([vpnStore respondsToSelector:@selector(deleteVPNWithServiceID:)])
{
[vpnStore deleteVPNWithServiceID:uuid];
}
else if ([vpnStore respondsToSelector:@selector(deleteVPNWithServiceID:withGrade:)])
{
[vpnStore deleteVPNWithServiceID:uuid withGrade:nil];
}
else
{
NSLog(@"can't delete vpn");
return;
}
}
sleep(2);
vpnSetup = [[objc_getClass("VPNSetupListController") alloc] init];
[vpnSetup setDisplayName:@"displayName" forSpecifier:nil];
[vpnSetup setVPNType:(__bridge CFStringRef)type forSpecifier:nil];
[vpnSetup setServer:server forSpecifier:nil];
[vpnSetup setUsername:username forSpecifier:nil];
[vpnSetup setPassword:password forSpecifier:nil];
[vpnSetup setSharedSecret:SharedSecret forSpecifier:nil];
[vpnSetup setSendAllTraffic:[NSNumber numberWithBool:YES] forSpecifier:nil];
[vpnSetup setPPTPEncryptionLevel:@1 forSpecifier:nil];
if ([vpnSetup respondsToSelector:@selector(saveConfigurationSettings)])
{
NSLog(@"saveConfigurationSettings");
[vpnSetup saveConfigurationSettings];
sleep(10);
connectVPN(YES); // try to connect VPN
}
else if ([vpnSetup respondsToSelector:@selector(_saveConfigurationSettings)])
{
NSLog(@"_saveConfigurationSettings");
[vpnSetup saveConfigurationSettings];
}
else
{
NSLog(@"can't saveConfigurationSettings");
return;
}
sleep(2);
}
void connectVPN(BOOL connect)
{
VPNConnectionStore* vpnStore;
VPNConnection* vpn;
dispatch_semaphore_t semaphore;
NSNotificationCenter* center;
id changeObserver;
vpnStore = [objc_getClass("VPNConnectionStore") sharedInstance];
NSLog(@"connectVPN vpnStore description:%@",[vpnStore description]);
vpn = [vpnStore currentConnectionWithGrade:[vpnStore currentOnlyConnectionGrade]];
if (vpn == nil)
{
NSLog(@"NotConnected");
// return VPNStatus::NotConnected;
}
NSLog(@"vpn = %@", vpn);
NSLog(@"session_status = %d, status = %llu, statusText = %@", [vpn session_status], [vpn status], [vpn statusText]);
if (connect == NO && [vpn status] == 1){
// return VPNStatus::NotConnected;
}
semaphore = dispatch_semaphore_create(0);
center = [NSNotificationCenter defaultCenter];
changeObserver = [center
addObserverForName:@"VPNConnectionStatusChanged"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* note) {
NSString* name;
VPNConnection* vpn;
// NSDictionary* userInfo;
name = [note name];
vpn = [note object];
// userInfo = [note userInfo];
NSLog(@"name = %@", name);
NSLog(@"object = %@", vpn);
// DbgLog(@"userInfo = %@", userInfo);
NSLog(@"session_status = %d, status = %llu, statusText = %@", [vpn session_status], [vpn status], [vpn statusText]);
switch ([vpn status])
{
case 2:
case 5:
break;
default:
dispatch_semaphore_signal(semaphore);
}
}
];
connect ? [vpn connect] : [vpn disconnect];
const int64_t tenSeconds = 15ll * 1000 * 1000 * 1000;
if (dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, tenSeconds)) != 0)
{
NSLog(@"connectVPN timeout");
[vpn disconnect];
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, tenSeconds));
}
[center removeObserver:changeObserver];
NSLog(@"connectVPN done");
NSLog(@"status = %llu", [vpn status]);
// return VPNStatus::fromStatus([vpn status]);
}
大佬 这个直接不能用么,没达到预期效果啊。。。
这是两年前的代码,你不会自己逆向新版iOS吗
我知道,我用的9.0.2的系统,没试成功,难道是我操作的问题么,直接把里面的包跟plist放到了越狱设备对应的文件夹里面