I wanna install a ipa on a jailbreak i-device.I get this code bellow on google. Here is the code
#import "dlfcn.h"
typedef int (*MobileInstallationInstall)(NSString *path, NSDictionary *dict, void *na, NSString *path2_equal_path_maybe_no_use);
void *lib = dlopen("/System/Library/PrivateFrameworks/MobileInstallation.framework/MobileInstallation", RTLD_LOCAL);
if (lib)
{
MobileInstallationInstall pMobileInstallationInstall = (MobileInstallationInstall)dlsym(lib, "MobileInstallationInstall");
if (pMobileInstallationInstall)
{
int ret = pMobileInstallationInstall(path, [NSDictionary dictionaryWithObject:#"User" forKey:#"ApplicationType"], nil, path);
dlclose(lib);
return ret;
}
}
return -1;
But that's not enough.I wanna get the install progress.Just like download progress. Unfortunately,I get nothing on google.any ideas?
you have to specify a callback function on the third parameter of MobileInstallationInstall
void MobileInstallationCallback(CFDictionaryRef information){
NSLog(#"%#",information);
}
int ret = pMobileInstallationInstall(path, [NSDictionary dictionaryWithObject:#"User" forKey:#"ApplicationType"], & MobileInstallationCallback, path);
all the informations will be sent to MobileInstallationCallback via the parameter information
Related
I want to hook "React Native" RCTLog logs method _RCTLogJavaScriptInternal , The source codes is:
void _RCTLogJavaScriptInternal(RCTLogLevel level, NSString *message)
{
RCTLogFunction logFunction = RCTGetLocalLogFunction();
BOOL log = RCT_DEBUG || (logFunction != nil);
if (log && level >= RCTGetLogThreshold()) {
if (logFunction) {
logFunction(level, RCTLogSourceJavaScript, nil, nil, message);
}
}
}
RCTLogFunction RCTDefaultLogFunction =
^(RCTLogLevel level,
RCTLogSource source,
__unused NSString *fileName,
__unused NSNumber *lineNumber,
NSString *message) {
os_log_with_type(RCTLogForLogSource(source), RCTLogTypeForLogLevel(level), "%{public}s", message.UTF8String);
};
So if I just hook Apple's os_log_with_type, I will get the RCTLog logs.
This is my codes, but not working. Please help me. Thanks!!!!
#import <os/log.h>
#import "fishhook.h"
static void (*original_oslog)((os_log_t log, os_log_type_t type, const char *format, ...));
void hook_oslog(os_log_t log, os_log_type_t type, const char *format, ...) {
NSLog(#"hook success!");
}
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
struct rebinding oslog_rebinding = { "os_log_with_type", hook_oslog, (void *)&original_oslog };
rebind_symbols((struct rebinding[1]){oslog_rebinding}, 1);
});
}
Final, I found solution. Not need to hook, Related API have been provided by React Native already.
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
NSLog(#"%#", message);
});
I want to make both the existing singal handler in the project and my own singal handler co-exist so that both can properly capture singal.
typedef void (*signalHandler)(int signo, siginfo_t *info, void *context);
static signalHandler previousSignalHandler = NULL;
void signalExceptionHandler(int signal, siginfo_t* info, void* context)
{
NSMutableString *mstr = [[NSMutableString alloc] init];
[mstr appendString:#"Stack:\n"];
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i <frames; ++i) {
[mstr appendFormat:#"%s\n", strs[i]];
}
BYLOGI(#"%#",mstr);
[BYCrashCacheHelper saveAppCrashDataWithCrashInfo:mstr];
if (previousSignalHandler) {
previousSignalHandler(signal, info, context);
}
}
void signalRegister(int signal)
{
struct sigaction action;
action.sa_sigaction = signalExceptionHandler;
action.sa_flags = SA_NODEFER | SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(signal, &action, 0);
}
void judgePreviousSignalHandlerAndSignalRegister(int signal)
{
struct sigaction old_action;
sigaction(signal, NULL, &old_action);
if (old_action.sa_flags & SA_SIGINFO) {
previousSignalHandler = old_action.sa_sigaction;
}
signalRegister(signal);
}
void installSignalHandler(void)
{
judgePreviousSignalHandlerAndSignalRegister(SIGHUP);
judgePreviousSignalHandlerAndSignalRegister(SIGINT);
judgePreviousSignalHandlerAndSignalRegister(SIGQUIT);
judgePreviousSignalHandlerAndSignalRegister(SIGABRT);
judgePreviousSignalHandlerAndSignalRegister(SIGILL);
judgePreviousSignalHandlerAndSignalRegister(SIGSEGV);
judgePreviousSignalHandlerAndSignalRegister(SIGFPE);
judgePreviousSignalHandlerAndSignalRegister(SIGBUS);
judgePreviousSignalHandlerAndSignalRegister(SIGPIPE);
}
I found the above method in some blogs, but after debugging, I found that it can not get to the previous handler.
Excuse me, how to get the previous handler correctly, and avoid the handler coverage problem?
For a private project I'm trying to use the private MobileWiFi framework in Swift.
I found this website:
http://iphonedevwiki.net/index.php/MobileWiFi.framework
In Objective-C it's working like a charm, but I want to convert the code to Swift.
I have converted the function "Retrieving a list of known networks" into Swift already and that function is working.
Now I'm trying to convert the "Getting the WiFi signal strength" function but the uses a callback function and I have tried so hard, but can't get it to work.
#include <MobileWiFi.h>
static WiFiManagerRef _manager;
static void scan_callback(WiFiDeviceClientRef device, CFArrayRef results, CFErrorRef error, void *token);
int main(int argc, char **argv)
{
_manager = WiFiManagerClientCreate(kCFAllocatorDefault, 0);
CFArrayRef devices = WiFiManagerClientCopyDevices(_manager);
if (!devices) {
fprintf(stderr, "Couldn't get WiFi devices. Bailing.\n");
exit(EXIT_FAILURE);
}
WiFiDeviceClientRef client = (WiFiDeviceClientRef)CFArrayGetValueAtIndex(devices, 0);
WiFiManagerClientScheduleWithRunLoop(_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
WiFiDeviceClientScanAsync(client, (CFDictionaryRef)[NSDictionary dictionary], scan_callback, 0);
CFRelease(devices);
CFRunLoopRun();
return 0;
}
static void scan_callback(WiFiDeviceClientRef device, CFArrayRef results, CFErrorRef error, void *token)
{
NSLog(#"Finished scanning! networks: %#", results);
WiFiManagerClientUnscheduleFromRunLoop(_manager);
CFRelease(_manager);
CFRunLoopStop(CFRunLoopGetCurrent());
}
Can someone explain to me how to use such a callback function in the swift language?
Thanks in advance!
I found this function:
pcap_loop(pcapSession, numberOfPackets,
{
(args: UnsafeMutablePointer<u_char>,
pkthdr:UnsafePointer<pcap_pkthdr>,
packet: UnsafePointer<u_char>) ->Void in
// singleton call
let pa = PacketAnalyser.sharedInstance
pa.Process()
},
nil)
On this website: http://diydeveloper.io/tech/2015/11/27/swift-pcap
I think this is a posible solution for my problem. Can somebody explain to me if I can use this example?
Before we can use CFMessagePort, but now it's invalid for iOS7 and above, is there any replaced methods? I tried CFMessagePort when hooking the constructor of UIApplication in the jailbreak environment, but in most of the apps, it can't CFMessagePortCreateLocal successfully, it just return NULL.Am I wrong somewhere?
static void setupUIApplicationMessagePort()
{
NSString *identifier = #"com.foo.foo.UIApplication";
CFMessagePortRef local = CFMessagePortCreateLocal(NULL, (__bridge CFStringRef)identifier, callBackForUIApplication, NULL, NULL);
if (local) {
NSLog(#"local OK: %#", local);
CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(NULL, local, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
rocketbootstrap_cfmessageportexposelocal(local);
} else {
NSLog(#"local is NULL"); // in most of the apps it returns NULL
}
}
%ctor {
if(%c(UIApplication)) {
setupUIApplicationMessagePort();
}
}
try CFNotificationCenter using CFNotificationCenterGetDarwinNotifyCenter
#include <CoreFoundation/CFNotificationCenter.h>
/* This function will be called whatever a notification posted with the specified name */
void NotificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
}
void addObserver(){
CFStringRef name = CFSTR("NotificationName");
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),&NotificationCallback,name,NULL,CFNotificationSuspensionBehaviorDeliverImmediately);
}
This will listen to notifications named NotificationName
To post a notification
void postNotification(){
CFStringRef name = CFSTR("NotificationName");
/* You have to create the userInfo dictionary and add all the keys to it */
CFDictionaryRef userInfo;
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), name, NULL, userInfo, true);
}
Does MonoTouch have a simple mechanism for retrieving the device serial number (not UDID) of an iOS device? Is there a third-party library which I can use to obtain this?
In case it matters, I'm looking to use this functionality in an in-house application and am not concerned with the App Store approval process.
UPDATE: from iOS 8, we cannot retrieve the serial number of our iDevice.
To retrieve iphone serial number from Monotouch, you can use this technic:
Create a static library .a from XCode that have a function to get serial number
In MonoDevelop, create a binding project to bind you .a library into C# classes/functions (http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries)
In your application, you call this binding library (in step 2).
For detail:
STEP 1. In my library.a, I have a class DeviceInfo, here is the implementation to get Serial number
#import "DeviceInfo.h"
#import <dlfcn.h>
#import <mach/port.h>
#import <mach/kern_return.h>
#implementation DeviceInfo
- (NSString *) serialNumber
{
NSString *serialNumber = nil;
void *IOKit = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_NOW);
if (IOKit)
{
mach_port_t *kIOMasterPortDefault = dlsym(IOKit, "kIOMasterPortDefault");
CFMutableDictionaryRef (*IOServiceMatching)(const char *name) = dlsym(IOKit, "IOServiceMatching");
mach_port_t (*IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching) = dlsym(IOKit, "IOServiceGetMatchingService");
CFTypeRef (*IORegistryEntryCreateCFProperty)(mach_port_t entry, CFStringRef key, CFAllocatorRef allocator, uint32_t options) = dlsym(IOKit, "IORegistryEntryCreateCFProperty");
kern_return_t (*IOObjectRelease)(mach_port_t object) = dlsym(IOKit, "IOObjectRelease");
if (kIOMasterPortDefault && IOServiceGetMatchingService && IORegistryEntryCreateCFProperty && IOObjectRelease)
{
mach_port_t platformExpertDevice = IOServiceGetMatchingService(*kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpertDevice)
{
CFTypeRef platformSerialNumber = IORegistryEntryCreateCFProperty(platformExpertDevice, CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0);
if (CFGetTypeID(platformSerialNumber) == CFStringGetTypeID())
{
serialNumber = [NSString stringWithString:(__bridge NSString*)platformSerialNumber];
CFRelease(platformSerialNumber);
}
IOObjectRelease(platformExpertDevice);
}
}
dlclose(IOKit);
}
return serialNumber;
}
#end
STEP 2. In ApiDefinition.cs of my Binding Library project in Monotouch, I add this binding:
[BaseType (typeof (NSObject))]
public interface DeviceInfo {
[Export ("serialNumber")]
NSString GetSerialNumber ();
}
STEP 3. In my application, I import Reference to Binding library project in step 2, then add
using MyBindingProject;
...
string serialNumber = "";
try {
DeviceInfo nativeDeviceInfo = new DeviceInfo ();
NSString temp = nativeDeviceInfo.GetSerialNumber();
serialNumber = temp.ToString();
} catch (Exception ex) {
Console.WriteLine("Cannot get serial number {0} - {1}",ex.Message, ex.StackTrace);
}
Hope that helps. Don't hesitate if you have any question.