All pastes #625346 Raw Edit

Something

public text v1 · immutable
·published 2007-07-18 21:39 UTC
rendered paste body
		fprintf(stderr, "AFCDeviceInfoOpen: %08x\n", err);
		AFCPlatformInit();
		
		char *strings[3] = {
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"> <dict><key>Command</key><string>PostNotification</string><key>Name</key><string>com.apple.itunes-mobdev.syncWillStart</string></dict></plist>\r\n",
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>Command</key><string>PostNotification</string><key>Name</key><string>com.apple.itunes-mobdev.syncDidStart</string></dict></plist>\r\n",
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>Command</key><string>PostNotification</string><key>Name</key><string>com.apple.itunes-mobdev.syncDidFinish</string></dict></plist>\r\n",
			};

	int pipe1[2], pipe2[2];

	if (pipe(pipe1) != 0) {
		printf("pipe()\n");
		exit(1);
	}

	if (pipe(pipe2) != 0) {
		printf("pipe()\n");
		exit(1);
	}
	
//	int fd_r = fds[0];
//	int fd_w = fds[1];
//	printf("created pipe with fds %d and %d\n", fd_r, fd_w);
	pid_t pid;
	if ((pid = fork()) == 0) {
		printf("starting child process\n");
		char *proc = "/System/Library/PrivateFrameworks/MobileDevice.framework/Resources/AppleMobileDeviceHelper.app/Contents/MacOS/AppleMobileDeviceHelper";
		char *argv[5];
		char argv2[10];
		char argv3[10];
		sprintf(argv2, "%d", pipe2[0]);
		sprintf(argv3, "%d", pipe1[1]);


	close(pipe1[0]); // close read
	close(pipe2[1]); // close write

		argv[0] = proc;
		argv[1] = "--pipe";
		argv[2] = argv2;
		argv[3] = argv3;
		argv[4] = NULL;
		if (execv(proc, argv) == -1) {
			printf("unable to start child: %d\n", errno);
		}
	}
		int status;
	printf("forked with pid %d\n", pid);
//	write(fd_w, strings[0], strlen(strings[0]));
	err = write(pipe1[1], strings[0], strlen(strings[0]));
	
	err = write(pipe1[1], strings[1], strlen(strings[1]));
	//err = send(pipe1[1], strings[1], strlen(strings[1]), MSG_OOB);
	//	waitpid (pid, &status, 0);
	//size_t len, int flags);
	//write(fd_w, strings[1], strlen(strings[1]));
	
	char buffer[1024];
	int err;
	err = read(pipe2[0], buffer, 1024);

	fprintf(stdout, "err = %d buf = [%s]\n", err, buffer);