<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nyx0uf&#039;s blog</title>
	<atom:link href="http://whine.fr/feed/langswitch_lang/en/" rel="self" type="application/rss+xml" />
	<link>http://whine.fr</link>
	<description>Mac OS Programming</description>
	<lastBuildDate>Mon, 01 Mar 2010 19:02:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SLNTFS 2.0.0 Out !</title>
		<link>http://whine.fr/2010/slntfs-2-0-0-out/</link>
		<comments>http://whine.fr/2010/slntfs-2-0-0-out/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 18:56:33 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[SL-NTFS]]></category>
		<category><![CDATA[slntfs]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=261</guid>
		<description><![CDATA[Finally ! I released SL-NTFS 2.0, I was spaeking of it for a certain time now, I had to release it one day&#8230;
Here are the updates :
- Add an installer
- Better authorization handling
- Button to uninstall properly the preference
- Remove the UUID column
- Add a daemon to alert when a NTFS disk is mounted and [...]]]></description>
			<content:encoded><![CDATA[<p>Finally ! I released SL-NTFS 2.0, I was spaeking of it for a certain time now, I had to release it one day&#8230;<br />
Here are the updates :<br />
- Add an installer<br />
- Better authorization handling<br />
- Button to uninstall properly the preference<br />
- Remove the UUID column<br />
- Add a daemon to alert when a NTFS disk is mounted and writing not enabled on it (TOP feature :>)<br />
- Fix various bugs</p>
<p>You can grab it <a href="http://whine.fr/Softs/SLNTFS/index.php?file=SLNTFS.pkg">here</a>.</p>
<p>For any remarks, <a href="http://whine.fr/contact/">contact me</a></p>
<p>See ya !</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2010/slntfs-2-0-0-out/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Back in business</title>
		<link>http://whine.fr/2010/back-in-business/</link>
		<comments>http://whine.fr/2010/back-in-business/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 11:26:44 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=255</guid>
		<description><![CDATA[My blog was lost onto the web during the transfer, so I didn&#8217;t post, but all is good now, I will write some articles soon 
And as you see, I&#8217;m currently working on internationalize the blog 
PS : I added a contact form, cause I figured out that there was nothing to contact me directly.
See [...]]]></description>
			<content:encoded><![CDATA[<p>My blog was lost onto the web during the transfer, so I didn&#8217;t post, but all is good now, I will write some articles soon <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_wink.png' alt=';)' class='wp-smiley' /><br />
And as you see, I&#8217;m currently working on internationalize the blog <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_smile.png' alt=':)' class='wp-smiley' /><br />
PS : I added a contact form, cause I figured out that there was nothing to contact me directly.<br />
See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2010/back-in-business/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Improving NSLog()</title>
		<link>http://whine.fr/2010/ameliorer-nslog/</link>
		<comments>http://whine.fr/2010/ameliorer-nslog/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 19:22:24 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[NSLog]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=252</guid>
		<description><![CDATA[When you debug an app, you often need to print informations on screen to check out if everything is ok etc… But when you are done and you are ready to release your application it&#8217;s a real pain in the ass to comment or remove all the call to these functions, plus they might be [...]]]></description>
			<content:encoded><![CDATA[<p>When you debug an app, you often need to print informations on screen to check out if everything is ok etc… But when you are done and you are ready to release your application it&#8217;s a real pain in the ass to comment or remove all the call to these functions, plus they might be useful later.<br />
To fix this problem you just need to define a macro that indicates if you are in a debug phase or not, if it&#8217;s the case informations will be printed on the screen otherwise nothing will happen.<br />
Not so long age I found a article who just talk about this, and in the end a <a href="http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog">code</a> was proposed :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifdef DEBUG</span>
<span style="color: #339933;">#define DLog(fmt, ...) NSLog((@&quot;%s [Line %d] &quot; fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);</span>
<span style="color: #339933;">#else</span>
<span style="color: #339933;">#define DLog(...)</span>
<span style="color: #339933;">#endif</span>
<span style="color: #339933;">#define ALog(fmt, ...) NSLog((@&quot;%s [Line %d] &quot; fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);</span></pre></td></tr></table></div>

<p>Place this code in the [PROJECT_NAME]_Prefix.pch file, and it&#8217;s almost done <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_wink.png' alt=';)' class='wp-smiley' /> </p>
<p>The macro <b>DLog()</b> works exaclty like <b>NSLog()</b>, so you can pass arguments etc… the advantage is that the line and the function name will be printed thanks to <b>__PRETTY_FUNCTION__</b> &#038; <b>__LINE__</b> macros.<br />
As for the macro <b>ALog()</b>, it remplaces NSLog() and will always produce an output.</p>
<p>The last thing you have to do is to define the <b>DEBUG</b> macro. In XCode go to project information, chose Debug configuration and in the <b>Preprocessing</b> part look for the line <b>Preprocessor Macros</b> and add it :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">DEBUG<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span></pre></td></tr></table></div>

<p>See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2010/ameliorer-nslog/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Theme update</title>
		<link>http://whine.fr/2010/changement-de-look/</link>
		<comments>http://whine.fr/2010/changement-de-look/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 18:02:51 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[OVH]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=248</guid>
		<description><![CDATA[For the new year (nope, I didn&#8217;t wish you anything) I decided to change the blog theme.
The old one was becoming boring, and it was too often updated.
This new theme is called Carbonize
]]></description>
			<content:encoded><![CDATA[<p>For the new year (nope, I didn&#8217;t wish you anything) I decided to change the blog theme.<br />
The old one was becoming boring, and it was too often updated.<br />
This new theme is called <a href="http://nischalmaniar.info/2009/05/carbonize-theme/">Carbonize</a></p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2010/changement-de-look/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MISC 47</title>
		<link>http://whine.fr/2010/misc-47/</link>
		<comments>http://whine.fr/2010/misc-47/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 17:34:06 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[64-bit]]></category>
		<category><![CDATA[dyld]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Thread Hijacking]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=247</guid>
		<description><![CDATA[MISC is a french magazine which talk about security.
For the first edit of 2010 there is a very interesting article on Mac OS X code injection, it&#8217;s not something new, but what is really cool is that all the injection are 64-bit, and that&#8217;s pretty unusual 
The article presents 2 different methods, the first one [...]]]></description>
			<content:encoded><![CDATA[<p>MISC is a french magazine which talk about security.<br />
For the first edit of 2010 there is a very interesting article on Mac OS X code injection, it&#8217;s not something new, but what is really cool is that all the injection are 64-bit, and that&#8217;s pretty unusual <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_wink.png' alt=';)' class='wp-smiley' /><br />
The article presents 2 different methods, the first one is classic, it&#8217;s a simple dynamic library injection, but the second is much more interesting because it uses <b>Thread hijacking</b>.</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2010/misc-47/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 7 sur iPhone</title>
		<link>http://whine.fr/2009/windows-7-sur-iphone/</link>
		<comments>http://whine.fr/2009/windows-7-sur-iphone/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 11:59:40 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://whine.fr/2009/windows-7-sur-iphone/</guid>
		<description><![CDATA[Depuis hier ça fait fureur, faut dire qu&#8217;il y a de quoi, donc voilà, enjoy !

]]></description>
			<content:encoded><![CDATA[<p>Depuis hier ça fait fureur, faut dire qu&#8217;il y a de quoi, donc voilà, enjoy !</p>
<p><center><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/1QyyTOe-0f0&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/1QyyTOe-0f0&#038;hl=en_US&#038;fs=1&#038;rel=0&#038;color1=0x2b405b&#038;color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></center></p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2009/windows-7-sur-iphone/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coding an Apple compliant Daemon</title>
		<link>http://whine.fr/2009/coder-un-daemon-apple-compliant/</link>
		<comments>http://whine.fr/2009/coder-un-daemon-apple-compliant/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 14:57:21 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Daemon]]></category>
		<category><![CDATA[DiskArbitration]]></category>
		<category><![CDATA[LaunchAgents]]></category>
		<category><![CDATA[launchctl]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[LaunchDaemons]]></category>
		<category><![CDATA[signal]]></category>
		<category><![CDATA[SIGTERM]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=240</guid>
		<description><![CDATA[In a precedent article I was showing you how to prevent a disk from mounting on the file system, at the end of the artcile I said that it would probably be best if this kind of program could run as a daemon, so this is what I&#8217;ll show you in this post, to begin [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://whine.fr/2009/empecher-un-disque-de-monter/">precedent article</a> I was showing you how to prevent a disk from mounting on the file system, at the end of the artcile I said that it would probably be best if this kind of program could run as a daemon, so this is what I&#8217;ll show you in this post, to begin let&#8217;s take a look at the precedent code :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &lt;Foundation/Foundation.h&gt;</span>
<span style="color: #339933;">#import &lt;DiskArbitration/DiskArbitration.h&gt;</span>
&nbsp;
DADissenterRef diskDidMount<span style="color: #009900;">&#40;</span>DADiskRef dsk<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> context<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    DADissenterRef ref <span style="color: #339933;">=</span> DADissenterCreate<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #339933;">,</span> kDAReturnNotPermitted<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> ref<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    NSAutoreleasePool<span style="color: #339933;">*</span> pool <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSAutoreleasePool alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    DASessionRef session <span style="color: #339933;">=</span> DASessionCreate<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    DARegisterDiskMountApprovalCallback<span style="color: #009900;">&#40;</span>session<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> diskDidMount<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    DASessionScheduleWithRunLoop<span style="color: #009900;">&#40;</span>session<span style="color: #339933;">,</span> CFRunLoopGetCurrent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> kCFRunLoopDefaultMode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CFRunLoopRun<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
    <span style="color: #009900;">&#91;</span>pool drain<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>First, there are some things that you need to know, OS X is an UNIX system but since Mac OS X 10.4 the daemons aren&#8217;t handled like the traditionals *BSD systems.<br />
Since this release, daemons are managed by <a href="http://en.wikipedia.org/wiki/Launchd">launchd</a>. OS X have 2 kind of programs that run in background :<br />
- <i>Daemons</i> : Their owner is the system, there are launched even when nobody is logged and a very important thing, they don&#8217;t have to launch any kind of GUI.<br />
- <i>Agents</i> : Their owner is a normal user, there are only launched when an user is logged and can display a GUI.<br />
In order to make a difference betwneen them, there are 2 distincts folders : <b>/Library/LaunchDaemons</b> and <b>/Library/LaunchAgents</b></p>
<p>So let&#8217;s get working now, there is noting hard, first we will take a look at the Apple doc, <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html#//apple_ref/doc/man/5/launchd.plist">here</a> and <a href="http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html#TABFRAMEWORKCROSSREFERENCE">here</a>.<br />
The second link is important because it shows what frameworks are daemons safe, and you can see that DiskArbitration is daemon safe, so we can adapt our program to run as a daemon.</p>
<p>Now look at the first link, it&#8217;s the man for launchd.plist, the first section that you must read is the <b>EXPECTATIONS</b> one, it tells you what you <b>can</b> do, what you <b>can&#8217;t</b> and what you <b>must</b>.<br />
If you read correctly, you know that you need 2 fields at least in your plist :<br />
- <i>Label</i><br />
- <i>Program</i> or <i>ProgramArguments</i><br />
You can take a look to the others flags too, some are interesting, like <b>RunAtLoad</b> which indicates that the program will run at login.<br />
Here is our finalized plist :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>fr.whine.diskblocker<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RunAtLoad<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Program<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/tmp/DiskBlocker<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UserName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Nyxouf<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The name of the file must follow this scheme : <b>[Label].plist</b>, in my case I name it <b>fr.whine.diskblocker.plist.</b><br />
Let&#8217;s put the file in /Library/LaunchDaemons and you are done with the config file.<br />
Now we need to add some code in our program to adapt it to run as a daemon. If you correctly read the doc, you know that you must catch the <a href="http://en.wikipedia.org/wiki/SIGTERM">SIGTERM</a> signal in order to terminate properly the daemon (free the memory etc..)<br />
There is nothing complicated, to do that we use the functions in <b>signal.h</b>, we first create an handler function :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> SIGTERM_handler<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">int</span> sigid<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>SIGTERM <span style="color: #339933;">==</span> sigid<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        CFRunLoopStop<span style="color: #009900;">&#40;</span>CFRunLoopGetCurrent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the main function before the runloop, we call the <a href="http://www.opengroup.org/onlinepubs/000095399/functions/signal.html">signal</a> function :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">signal<span style="color: #009900;">&#40;</span>SIGTERM<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>sig_t<span style="color: #009900;">&#41;</span>SIGTERM_handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once the signal received, the runloop will stop, so we could properly end the program :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">DASessionUnscheduleFromRunLoop<span style="color: #009900;">&#40;</span>session<span style="color: #339933;">,</span> CFRunLoopGetCurrent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> kCFRunLoopDefaultMode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
CFRelease<span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>pool drain<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, let&#8217;s compile</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gcc</span> DiskBlocker.m <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>DiskBlocker <span style="color: #660033;">-framework</span> DiskArbitration <span style="color: #660033;">-framework</span> Foundation</pre></td></tr></table></div>

<p>In the man, it&#8217;s written that the system daemon owner must be root, so need to do a chown :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> root:wheel <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>DiskBlocker</pre></td></tr></table></div>

<p>Last thing, launch the daemon, to do that we use <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html">launchctl</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">launchctl load <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>fr.whine.diskblocker.plist</pre></td></tr></table></div>

<p>If like me, you specified the <b>RunAtLoad</b> flag, you can try to reboot to se if the daemon is launched <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_wink.png' alt=';)' class='wp-smiley' /> </p>
<p>You can get all the source code <a href="http://whine.fr/wordpress/wp-content/uploads/2009/12/DiskBlocker.zip">here</a></p>
<p>see ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2009/coder-un-daemon-apple-compliant/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dur Dur&#8230;</title>
		<link>http://whine.fr/2009/dur-dur/</link>
		<comments>http://whine.fr/2009/dur-dur/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 20:55:13 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[SL-NTFS]]></category>
		<category><![CDATA[Torchlight]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=239</guid>
		<description><![CDATA[Not many posts these days, it&#8217;s not that I have no idea, but I haven&#8217;t much time&#8230;
And well, december 23th, it&#8217;s christmas soon, plus I just found a cool game, so I can&#8217;t write ! 
Except this, the blog has now is mobile version 
see ya !
]]></description>
			<content:encoded><![CDATA[<p>Not many posts these days, it&#8217;s not that I have no idea, but I haven&#8217;t much time&#8230;<br />
And well, december 23th, it&#8217;s christmas soon, plus I just found a <a href="http://www.torchlightgame.com/">cool game</a>, so I can&#8217;t write ! <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_yuck.png' alt=':P' class='wp-smiley' /><br />
Except this, the blog has now is mobile version <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_smile.png' alt=':)' class='wp-smiley' /><br />
see ya !</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2009/dur-dur/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>paraNORMAL activity…</title>
		<link>http://whine.fr/2009/paranormal-activity…/</link>
		<comments>http://whine.fr/2009/paranormal-activity…/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 17:17:48 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[Movies]]></category>
		<category><![CDATA[Paranormal Activity]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=238</guid>
		<description><![CDATA[Un post sur le ciné pour changer un peu de l&#8217;info, et puis y a de quoi là..
Qui n&#8217;a pas entendu parler de Paranormal Activity ?
Pour faire simple, ça reprend le principe du Projet Blair Witch, tout est filmé en caméra portée.
Ce film qui fait un buzz depuis un certain temps, serait terrifiant, au point [...]]]></description>
			<content:encoded><![CDATA[<p>Un post sur le ciné pour changer un peu de l&#8217;info, et puis y a de quoi là..<br />
Qui n&#8217;a pas entendu parler de <a href="http://www.allocine.fr/film/fichefilm_gen_cfilm=140608.html">Paranormal Activity</a> ?<br />
Pour faire simple, ça reprend le principe du <a href="http://www.allocine.fr/film/fichefilm_gen_cfilm=20268.html">Projet Blair Witch</a>, tout est filmé en caméra portée.<br />
Ce film qui fait un buzz depuis un certain temps, serait terrifiant, au point que Steven Spielberg en personne ne dormirait plus tranquillement…<br />
Vu que je suis cinéfil, et que seulement 2 films m&#8217;ont fait sursauté dans ma vie, je me suis dit qu&#8217;il fallait que je vois ce film… erreur fatale !<br />
La dernière fois que je m&#8217;étais autant fait chier devant un film c&#8217;était justement en regardant Blair Witch, qui est, il faut le souligner, une vraie daube internationale.</p>
<p>Que dire, j&#8217;ai lutté pour garder les yeux ouverts devant ce film soit disant si terrifiant, il ne se passe rien pendant 1H20, et les seuls effets de surprise qui auraient pu être bien ne sont pas exploités.<br />
Les spectateurs qui étaient dans la salle n&#8217;ont pas eu l&#8217;air plus terrifiés que moi, même les femmes n&#8217;ont pas crié, ce qui est rassurant, ça prouve que ça ne vient pas de moi <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_yuck.png' alt=':P' class='wp-smiley' /><br />
Faudra donc qu&#8217;on m&#8217;explique les vidéos sur lesquelles on peut voir des gens terrifiés dans les salles de cinéma (Fake peut-être?), pourquoi Spielberg a SOI-DISANT eu aussi peur ?<br />
La conclusion est simple, la seule chose paranormale c&#8217;est d&#8217;arriver à faire un film aussi médiocre et chiant.</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2009/paranormal-activity…/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Prevent a disk from mounting on the filesystem</title>
		<link>http://whine.fr/2009/empecher-un-disque-de-monter/</link>
		<comments>http://whine.fr/2009/empecher-un-disque-de-monter/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 13:09:55 +0000</pubDate>
		<dc:creator>Nyx0uf</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[DiskArbitration]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://whine.fr/?p=237</guid>
		<description><![CDATA[Today I will show you how to prevent a disk (physical or virtual) to mount on the filesystem.
In order to do that, we will use the DiskArbitration framework. There is very few documentation for this framework, the best is to read the header files, which are very well commented.

Let&#8217;s begin, first open XCode and create [...]]]></description>
			<content:encoded><![CDATA[<p>Today I will show you how to prevent a disk (physical or virtual) to mount on the filesystem.<br />
In order to do that, we will use the <b>DiskArbitration</b> framework. There is very few documentation for this framework, the best is to read the header files, which are very well commented.<br />
<!--more--><br />
Let&#8217;s begin, first open XCode and create a new Foundation <b>Command line tool</b> project. Name it as you like.<br />
Once the project created, add the DiskArbitration framework, right click &#8211;> Add existing frameworks.<br />
Now let&#8217;s code, first import the framework header :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &lt;DiskArbitration/DiskArbitration.h&gt;</span></pre></td></tr></table></div>

<p>Now, we need a DASessionRef object that we initialiaze like this :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">DASessionRef session <span style="color: #339933;">=</span> DASessionCreate<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>At this point, it becomes really interesting to read the header we just imported.<br />
By traversing it, we can see a function that could correspond as what we are looking for :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">void</span> DARegisterDiskMountApprovalCallback<span style="color: #009900;">&#40;</span>DAApprovalSessionRef session<span style="color: #339933;">,</span> CFDictionaryRef match<span style="color: #339933;">,</span> DADiskMountApprovalCallback callback<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As I said before, all the comments are very explicit, the most important parameter is the third, it&#8217;s a pointer to the function which will be called when a disk will want to mount, its definition is just above.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">typedef</span> DADissenterRef <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>DADiskMountApprovalCallback<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>DADiskRef disk<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So, we need to create an handler function, name it diskDidMount.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">DADissenterRef diskDidMount<span style="color: #009900;">&#40;</span>DADiskRef dsk<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> context<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	DADissenterRef ref <span style="color: #339933;">=</span> DADissenterCreate<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #339933;">,</span> kDAReturnNotPermitted<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> ref<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>For what we want to do, all the parameters are useless, we just have to create a <b>DADissenterRef</b> object which is the return value of the function. The interesting parameter here is the second, whicj is a flah that indicates the action to do. The flag list is available in the documentation.</p>
<p>All we have to do now, is create a loop to let the program run. The best would be to make this program a daemon, whicj if the object of a futur post <img src='http://whine.fr/wordpress/wp-includes/images/smilies/sml_wink.png' alt=';)' class='wp-smiley' /> </p>
<p>Here is the full code :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#import &lt;Foundation/Foundation.h&gt;</span>
<span style="color: #339933;">#import &lt;DiskArbitration/DiskArbitration.h&gt;</span>
&nbsp;
DADissenterRef diskDidMount<span style="color: #009900;">&#40;</span>DADiskRef dsk<span style="color: #339933;">,</span> <span style="color: #993333;">void</span><span style="color: #339933;">*</span> context<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	DADissenterRef ref <span style="color: #339933;">=</span> DADissenterCreate<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #339933;">,</span> kDAReturnNotPermitted<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> ref<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    NSAutoreleasePool<span style="color: #339933;">*</span> pool <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span>NSAutoreleasePool alloc<span style="color: #009900;">&#93;</span> init<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    DASessionRef session <span style="color: #339933;">=</span> DASessionCreate<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    DARegisterDiskMountApprovalCallback<span style="color: #009900;">&#40;</span>session<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> diskDidMount<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    DASessionScheduleWithRunLoop<span style="color: #009900;">&#40;</span>session<span style="color: #339933;">,</span> CFRunLoopGetCurrent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> kCFRunLoopDefaultMode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    CFRunLoopRun<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
    <span style="color: #009900;">&#91;</span>pool drain<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>see ya !</p>
]]></content:encoded>
			<wfw:commentRss>http://whine.fr/2009/empecher-un-disque-de-monter/feed/langswitch_lang/en/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
