I'm using dlsym to load private APIs (required on iOS 9.3) :
handle = dlopen(CORETELPATH, RTLD_LAZY);
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
When I kill the app (swipe from bottom on multitask mode) and restart app, it crashes on the second line.
The handle is equal to NULL and I didn't succeed in loading the lib twice.
I tried to get the error with dlerror(), but it returns also NULL.
Does anybody got this issue ? How to resolve it ?
Edit :
Here is the full code ; with the if (handle != NULL) the app doesn't crashes, but private frameworks won't load also
#define CORETELPATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
handle = dlopen(CORETELPATH, RTLD_LAZY);
NSLog(#"DL Error : %s", dlerror());
if (handle != NULL) {
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
CTResultConnection = _CTServerConnectionCreate(NULL, simMonitorCallback, NULL);
_CTServerConnectionAddToRunLoop = dlsym(handle, "_CTServerConnectionAddToRunLoop");
_CTServerConnectionAddToRunLoop(CTResultConnection, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
_CTServerConnectionRegisterForNotification = dlsym(handle, "_CTServerConnectionRegisterForNotification");
_CTServerConnectionUnregisterForNotification = dlsym(handle, "_CTServerConnectionUnregisterForNotification");
_CTServerConnectionRegisterForNotification(CTResultConnection, kCTSIMSupportSIMStatusChangeNotification);
_CTServerConnectionGetSIMStatus = dlsym(handle, "_CTServerConnectionGetSIMStatus");
_CTServerConnectionCopyMobileEquipmentInfo = dlsym(handle, "_CTServerConnectionCopyMobileEquipmentInfo");
}
It seems that changing Private API path to public fix the issue ; and the call to private APIs still works :
#define CORETELPATH "/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony"
Related
I am trying this MFC code:
CString strURL = _T("https://www.website-to-use.co.uk/file.php?");
strURL.AppendFormat(_T("mwblang=%d"), theApp.GetForeignLanguageGroupCachedLanguageID());
strURL.AppendFormat(_T("&guilang=%d"), theApp.GetProgramLanguage());
strURL.AppendFormat(_T("&flg=%d"), theApp.GetForeignLanguageGroupMenuID() != ID_OPTIONS_GROUP_LANGUAGE_NONE);
InternetGoOnline((LPTSTR)(LPCTSTR)strURL, GetSafeHwnd(), 0);
It is not working. If I go to the same link using a browser (correct details ofcourse) then it updates my database. But trying to run this from my MFC application, nothing happens
This seems to work:
CString strURL = _T("https://website-to-use.co.uk/file.php?");
strURL.AppendFormat(_T("mwblang=%d"), theApp.GetForeignLanguageGroupCachedLanguageID());
strURL.AppendFormat(_T("&guilang=%d"), theApp.GetProgramLanguage());
strURL.AppendFormat(_T("&flg=%d"), theApp.GetForeignLanguageGroupMenuID() != ID_OPTIONS_GROUP_LANGUAGE_NONE);
if (InternetGoOnline(strURL.GetString(), GetSafeHwnd(), 0))
{
CInternetSession iSession;
CHttpFile* pWebFile = nullptr;
pWebFile = (CHttpFile*)iSession.OpenURL(strURL, 1,
INTERNET_FLAG_SECURE | INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD);
if (pWebFile != nullptr)
{
pWebFile->Close();
delete pWebFile;
}
iSession.Close();
}
I would like to programmatically determine if the iOS app is being run directly from XCode (either in the simulator or on a tethered device).
I've tried the -D DEBUG solution described here, but when I then disconnect from Xcode and re-run the app, it still thinks it's in debug mode.
I think what I'm looking for is a Swift version of this function
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>
static bool AmIBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
int junk;
int mib[4];
struct kinfo_proc info;
size_t size;
// Initialize the flags so that, if sysctl fails for some bizarre
// reason, we get a predictable result.
info.kp_proc.p_flag = 0;
// Initialize mib, which tells sysctl the info we want, in this case
// we're looking for information about a specific process ID.
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
// Call sysctl.
size = sizeof(info);
junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
assert(junk == 0);
// We're being debugged if the P_TRACED flag is set.
return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
}
Clarification: Your C code (and the Swift version below) checks if
the program is run under debugger control, not if it's being run from
Xcode. One can debug a program outside of Xcode (by calling lldb or
gdb directly) and one can run a program from Xcode without debugging it
(if the “Debug Executable” checkbox in the scheme setting is off).
You could simply keep the C function and call it from Swift.
The recipes given in How do I call Objective-C code from Swift? apply to pure C code as well.
But it is actually not too complicated to translate that code to Swift:
func amIBeingDebugged() -> Bool {
// Buffer for "sysctl(...)" call's result.
var info = kinfo_proc()
// Counts buffer's size in bytes (like C/C++'s `sizeof`).
var size = MemoryLayout.stride(ofValue: info)
// Tells we want info about own process.
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
// Call the API (and assert success).
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
// Finally, checks if debugger's flag is present yet.
return (info.kp_proc.p_flag & P_TRACED) != 0
}
Update for Swift 5 (Xcode 10.7):
strideofValue and the related functions do not exist anymore,
they have been replaced by MemoryLayout.stride(ofValue:).
Remarks:
kinfo_proc() creates a fully initialized structure with all
fields set to zero, therefore setting info.kp_proc.p_flag = 0 is not necessary.
The C int type is Int32 is Swift.
sizeof(info) from the C code has to be strideOfValue(info)
in Swift to include the structure padding. With sizeofValue(info)
the above code always returned false in the Simulator for 64-bit devices. This was the most difficult part to figure out.
Swift 2 logic:
func amIBeingDebugged() -> Bool {
var info = kinfo_proc()
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = strideofValue(info)
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
return (info.kp_proc.p_flag & P_TRACED) != 0
}
For those looking for a simpler solution - this works perfectly:
func isDebuggerAttached() -> Bool {
return getppid() != 1
}
I'm attempting to make a simple objective C wrapper by exposing the high level C/C++ API. For a proof of concept, I've implemented the simple SIP UA example given at
http://svn.pjsip.org/repos/pjproject/trunk/pjsip-apps/src/samples/simple_pjsua.c
I can get as far as the creating the SIP user account (pjsua_acc_add function below)
- (void) registerWithSipServer {
/* Register to SIP server by creating SIP account. */
pjsua_acc_config a_cfg;
pjsua_acc_id acc_id;
pj_status_t status;
pjsua_acc_config_default(&a_cfg);
a_cfg.id = pj_str("sip:" SIP_USER "#" SIP_DOMAIN);
a_cfg.reg_uri = pj_str("sip:" SIP_DOMAIN);
a_cfg.cred_count = 1;
a_cfg.cred_info[0].realm = pj_str(SIP_DOMAIN);
a_cfg.cred_info[0].scheme = pj_str("digest");
a_cfg.cred_info[0].username = pj_str(SIP_USER);
a_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
a_cfg.cred_info[0].data = pj_str(SIP_PASSWD);
status = pjsua_acc_add(&a_cfg, PJ_TRUE, &acc_id);
if (status != PJ_SUCCESS) {
NSLog(#"Failed to start PJSUA");
}
}
but when I try and add it, I get an assertion
11:59:07.083 endpoint ..Request msg REGISTER/cseq=1665
(tdta0xbb15200) created. Assertion failed: (mod_stateful_util.id !=
-1), function pjsip_endpt_send_request, file ../src/pjsip/sip_util_statefull.c, line 99.
Tracking that down line 99 in sip_util_statefull.c we get the function
PJ_ASSERT_RETURN(mod_stateful_util.id != -1, PJ_EINVALIDOP);
I've tried to figure out why this fails but have so far come unstuck. Anybody else attempted this?
In ARC XCode application, it uses native C library.
When the library functions are called continuously about 2000 times, the application stopped working on iPad device.
The 'Instrument' showed that, only 'Malloc' is getting accumulated and 'free' is not considered.
I have no clue, what happens with the 'free' call.
The code is given below:
Memory allocations:
efHeapSize = EF_MIN_HEAPSIZE; pEFHeap = (void
*)malloc(efHeapSize);
cedHeapsize = heapMemorySize - efHeapSize; pCEDHeap = (void
*)malloc(cedHeapsize);
Memory Free:
if (pEFHeap != NULL) {
free (pEFHeap);
pEFHeap = NULL;
printf("pEFHeap freed \n");
}
if (pCEDHeap != NULL) {
free (pCEDHeap);
pCEDHeap = NULL;
printf("pCEDHeap freed \n");
}
Need to show browser through my application.
My application should go in background and browser should come in foreground.
int moduleHandle =
CodeModuleManager.getModuleHandle("net_rim_bb_browser_daemon");
if (moduleHandle > 0)
{
// Use the default browser application descriptor as the
// model descriptor.
ApplicationDescriptor[] browserDescriptors =
CodeModuleManager.getApplicationDescriptors(moduleHandle);
// Create the new application descriptor.
String[] args = {"url", url, null};
// Turn off auto restart (the original descriptor has it
// turned on) so we don't end up in a never ending loop of
// restarting the browser.
int flags = browserDescriptors[0].getFlags() ^
ApplicationDescriptor.FLAG_AUTO_RESTART;
ApplicationDescriptor newDescriptor =
new ApplicationDescriptor
(
browserDescriptors[0],
"BrowserPS",
args,
null,
-1,
null,
-1,
flags
);
// Run the application.
try
{
ApplicationManager.getApplicationManager().
runApplication(newDescriptor);
}
catch (ApplicationManagerException ame)
{
System.err.println(ame.toString());
}
}
This is my code it's working fine in simulator, but not on actual device.
any help.
Try like
BrowserSession browserSession = Browser.getDefaultSession();
browserSession.displayPage(URL);