I was working on XCode5-DP4 and I switched to DP5.
Now I have this nasty errors on my logs:
AssertMacros: queueEntry, file: /SourceCache/IOKitUser/IOKitUser-920.1.11/hid.subproj/IOHIDEventQueue.c, line: 512
Any ideas? I don't even know where to start searching.
This is a bug in Xcode 5 DP5. Just ignore it, it will go away in the next BETA build eventually.
change your main.m file with this
#import <UIKit/UIKit.h>
#import "QDAppDelegate.h"
typedef int (*PYStdWriter)(void *, const char *, int);
static PYStdWriter _oldStdWrite;
int __pyStderrWrite(void *inFD, const char *buffer, int size)
{
if ( strncmp(buffer, "AssertMacros:", 13) == 0 )
{
return 0;
}
return _oldStdWrite(inFD, buffer, size);
}
int main(int argc, char * argv[])
{
_oldStdWrite = stderr->_write;
stderr->_write = __pyStderrWrite;
#autoreleasepool
{
return UIApplicationMain(argc, argv, nil, NSStringFromClass([QDAppDelegate class]));
}
}
Related
I'm trying to get .text segment size of Mach-O executable of my iOS app.
size_t size_of_image(struct mach_header *header) {
size_t sz = sizeof(*header); // Size of the header
sz += header->sizeofcmds; // Size of the load commands
struct load_command *lc = (struct load_command *) (header + 1);
for (uint32_t i = 0; i < header->ncmds; i++) {
if (lc->cmd == LC_SEGMENT_64) {
sz += ((struct segment_command *) lc)->vmsize; // Size of segments
}
lc = (struct load_command *) ((char *) lc + lc->cmdsize);
}
return sz;
}
and i call this function from main
int main(int argc, char * argv[]) {
const struct mach_header * header;
Dl_info dlinfo;
//
if (dladdr(main, &dlinfo) == 0 || dlinfo.dli_fbase == NULL)
return 0; // Can't find symbol for main
//
header = dlinfo.dli_fbase; // Pointer on the Mach-O header
size_of_image(header);
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Problem is lc->cmd is always 0, and i never get LC_SEGMENT_64 command.
I've tried LC_SEGMENT - same result
Running iOS 12 on iPhone 6.
I need to get the .text segment of the executable for reverse - engineering protection functions.
It seems my ** mach_header *header** is wrongly field by dladdr function.
Any ideas what is wrong?
The culprit is in struct mach_header *header.
Replace it with struct mach_header_64 *header instead.
Keep using LC_SEGMENT_64 for modern binaries.
When I have the following C source code, which is running on an IBM i Midrange, then I get a non-zero result from pthread_create, specifically 3025, which is ENOENT (No such path or directory), which doesn't make any sense to me. Anyone have any thoughts on what the error actually means in this context.
#define _MULTI_THREADED
#define _XOPEN_SOURCE 520
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
void* workerThread(void* parm) {
// Do some work here
pthread_exit(NULL);
}
int main(int argc, char* argv[]) {
pthread_t t;
int rc;
rc = pthread_create(&t, NULL, workerThread, NULL);
if (rc != 0) {
char *msg = strerror(errno);
perror("pthread_create failed");
}
// Other code here
return 0;
}
pthread_create doesn't set errno. You should be checking strerror of rc.
http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_create.html
char *msg = strerror(rc);
Client side:
#define BUFFSIZE 4096
main(argc, argv)
int argc;
char *argv[];
{
int fd,i,n;
char buff[BUFFSIZE];
extern char *pname;
pname = argv[0];
argv++; argc--;
fd=0;
i=0;
do{
if(arg>0 && (fd=my_open(argv[i],0)) <0) {
err_ret("cant open %s", argv[i]);
continue;
}
while((n=read(fd,buff,BUFFSIZE))>0)
if (write(1,buff,n) !=n)
err_sys("write error:);
if(n<0)
err_sys("read error");
} while(++i<argc);
exit(0);
}
Server side:
main(argc, argv)
int argc;
char *intv[];
{
int fd;
extern int errno;
extern char *pname;
pname= argv[0];
if(argc !=4)
err_quit("open file <sockfd#> <filename><mode>");
if((fd=open(argv[2],atoi(argv[3]))) < 0)
exit((errno>0) ? errno:255);
exit(sendfile(atoi(argv[1]),fd));
}
If I send a config file from client to server like this, then can I run a polling code on server which runs a python code on receiving config file.
I got the D-Bus server.c and client.c code, and made some modification.
I want the result that when type for example "hi" from client.c
server will print "receive message hi", and reply "reply_content!!!!!!" to client.c
But it seems that now client.c cannot get the reply message.
Anyone have the idea?
Thanks in advance.
"server.c"
/* server.c */
#include <dbus/dbus.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
static DBusHandlerResult
filter_func(DBusConnection *connection, DBusMessage *message, void *usr_data)
{
DBusMessage *reply;
dbus_bool_t handled = false;
char *word = NULL;
DBusError dberr;
dbus_error_init(&dberr);
dbus_message_get_args(message, &dberr, DBUS_TYPE_STRING, &word, DBUS_TYPE_INVALID);
printf("receive message: %s\n", word);
handled = true;
reply = dbus_message_new_method_return(message);
char * reply_content = "reply_content!!!!!!";
dbus_message_append_args(reply, DBUS_TYPE_STRING, &reply_content, DBUS_TYPE_INVALID);
dbus_connection_send(connection, reply, NULL);
dbus_connection_flush(connection);
dbus_message_unref(reply);
return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
}
int main(int argc, char *argv[])
{
DBusError dberr;
DBusConnection *dbconn;
dbus_error_init(&dberr);
dbconn = dbus_bus_get(DBUS_BUS_SESSION, &dberr);
if (!dbus_connection_add_filter(dbconn, filter_func, NULL, NULL)) {
return -1;
}
dbus_bus_add_match(dbconn, "type='signal',interface='client.signal.Type'", &dberr);
while(dbus_connection_read_write_dispatch(dbconn, -1)) {
/* loop */
}
return 0;
}
Here is client.c
#include <dbus/dbus.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
static DBusHandlerResult
filter_func(DBusConnection *connection, DBusMessage *message, void *usr_data)
{
dbus_bool_t handled = false;
char *word = NULL;
DBusError dberr;
dbus_error_init(&dberr);
dbus_message_get_args(message, &dberr, DBUS_TYPE_STRING, &word, DBUS_TYPE_INVALID);
printf("receive message %s\n", word);
handled = true;
return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
}
int db_send(DBusConnection *dbconn)
{
DBusMessage *dbmsg;
char *word = (char *)malloc(sizeof(char));
int i;
dbmsg = dbus_message_new_signal("/client/signal/Object", "client.signal.Type", "Test");
scanf("%s", word);
if (!dbus_message_append_args(dbmsg, DBUS_TYPE_STRING, &word, DBUS_TYPE_INVALID)) {
return -1;
}
if (!dbus_connection_send(dbconn, dbmsg, NULL)) {
return -1;
}
dbus_connection_flush(dbconn);
printf("send message %s\n", word);
dbus_message_unref(dbmsg);
return 0;
}
int main(int argc, char *argv[])
{
DBusError dberr;
DBusConnection *dbconn;
dbus_error_init(&dberr);
dbconn = dbus_bus_get(DBUS_BUS_SESSION, &dberr);
if (!dbus_connection_add_filter(dbconn, filter_func, NULL, NULL)) {
return -1;
}
db_send(dbconn);
while(dbus_connection_read_write_dispatch(dbconn, -1)) {
db_send(dbconn);
}
dbus_connection_unref(dbconn);
return 0;
}
You're communicating only with signals at the moment, which don't have a return value.
In client.c, use dbus_message_new_method_call instead of dbus_message_new_signal, and in server.c you probably have to change type='signal' to type='method_call'.
I'm wondering why the following code gives unexpected output: a can get 110...!
pthread_t th[nbT];
void * func(void *d)
{
while(a<100)
{
pthread_mutex_lock(&l);
cout <<a <<" in thread "<<pthread_self()<<"\n";
a+=1;
pthread_mutex_unlock(&l);
}
return NULL;
}
int main(int argc, const char* argv[])
{
for(int i=0;i<nbT;i++)
pthread_create(&(th[i]), NULL, func, NULL);
for(int i=0;i<nbT;i++)
pthread_join(th[i],NULL);
}
The problem is that you get the lock (mutex) after checking the condition, so you don't know if it's still true or not once you get the lock. You should just do a simple double-check:
while(a<100)
{
pthread_mutex_lock(&l);
cout <<a <<" in thread "<<pthread_self()<<"\n";
if (a<100) a+=1; // <== Added condition here!
pthread_mutex_unlock(&l);
}