<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-19381597</id><updated>2009-12-26T12:38:59.079+08:00</updated><title type='text'>Shaoting's Programming Blog</title><subtitle type='html'>Java, ANTLR, PHP, Flex programming blog.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://caishaoting.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-19381597.post-8978227278606454402</id><published>2009-06-25T11:47:00.001+08:00</published><updated>2009-06-25T11:47:47.713+08:00</updated><title type='text'>PhpXmlRpc localhost problem</title><content type='html'>&lt;p&gt;Found a problem using PhpXmlRpc library today:&lt;/p&gt;  &lt;p&gt;Running XAMPP on Windows Vista machine, PHP ver 5.&lt;/p&gt;  &lt;p&gt;I have an XML-RPC service running on my localhost.&amp;#160; I can access the service php page via browser.&lt;/p&gt;  &lt;p&gt;Both my XML-RPC client and server resides on “localhost”.&lt;/p&gt;  &lt;p&gt;However, when I create the XML-RPC client using “localhost” as the server address, the client can’t connect to the server.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;$client = new xmlrpc_client(&amp;quot;/hs/service/users.php&amp;quot;, &amp;quot;&lt;font color="#0000a0"&gt;localhost&lt;/font&gt;&amp;quot;, 80);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;After replacing the “localhost” with “127.0.0.1”, the client works fine.&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;$client = new xmlrpc_client(&amp;quot;/hs/service/users.php&amp;quot;, &amp;quot;&lt;font color="#0000a0"&gt;127.0.0.1&lt;/font&gt;&amp;quot;, 80);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I’m still not sure what causes the issue.&amp;#160; Just take a note here for future references.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-8978227278606454402?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/8978227278606454402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/8978227278606454402'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2009/06/phpxmlrpc-localhost-problem.html' title='PhpXmlRpc localhost problem'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-3514992490810283867</id><published>2009-03-24T05:57:00.002+08:00</published><updated>2009-03-24T05:59:54.699+08:00</updated><title type='text'>Port tinypy to Android</title><content type='html'>Full text can be found on my wiki:&lt;br /&gt;&lt;a href="http://www.caichoi.com/mediawiki/index.php?title=Porting_tinypy_to_Android_Project"&gt;http://www.caichoi.com/mediawiki/index.php?title=Porting_tinypy_to_Android_Project&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt; Write a native tinypy interpreter that &lt;ul&gt;&lt;li&gt; reads in Python script from stdin &lt;/li&gt;&lt;li&gt; prints execution results to stdout &lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;li&gt; Create the tinypy process in Android Java application by calling &lt;a href="http://developer.android.com/reference/java/lang/Runtime.html#exec%28java.lang.String%29" class="external text" title="http://developer.android.com/reference/java/lang/Runtime.html#exec(java.lang.String)" rel="nofollow"&gt;Runtime.exec()&lt;/a&gt; &lt;/li&gt;&lt;li&gt; Communicate with the native process on its I/O stream. &lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-3514992490810283867?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/3514992490810283867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/3514992490810283867'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2009/03/port-tinypy-to-android.html' title='Port tinypy to Android'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-7404659726145896889</id><published>2009-01-11T14:33:00.001+08:00</published><updated>2009-01-11T14:46:30.629+08:00</updated><title type='text'>[Flex] Control creation time</title><content type='html'>&lt;div&gt;In my Flex gallery program, I have a custom MXML component 'DisplayImage' and a piece of program that popup the component.&lt;/div&gt;&lt;div&gt;The 'DisplayImage' component is just a &lt;mx:panel&gt; with a &lt;mx:image&gt; in it.&lt;/mx:image&gt;&lt;/mx:panel&gt;&lt;/div&gt;&lt;div&gt;I instantiate a 'DisplayImage' control and popup it using the following code in my main application:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;var img:DisplayImage = new DisplayImage();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;img.innerImage.source = file;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;PopUpManager.addPopUp(img, this, true);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;...&lt;span class="Apple-style-span"   style="  ;font-family:Georgia;font-size:16px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span"   style="  ;font-family:Georgia;font-size:16px;"&gt;When I run the program, I'll get error information saying the Image control in my DisplayImage control is null.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span"   style="  ;font-family:Georgia;font-size:16px;"&gt;I tried to change the object 'img' to mx:Image type and the program runs correctly.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span"   style="  ;font-family:Georgia;font-size:16px;"&gt;If I add the DisplayImage to the popup manager before I set the image source, the program runs correctly, as well.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span"   style="  ;font-family:Georgia;font-size:16px;"&gt;It seems to me a compound component like my DisplayImage is not instantiated until paint is required.  However, an simple  Image component gets instantiated right after being constructed.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-7404659726145896889?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/7404659726145896889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/7404659726145896889'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2009/01/flex-control-creation-time.html' title='[Flex] Control creation time'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-6262215190603709643</id><published>2008-06-21T02:49:00.002+08:00</published><updated>2008-06-21T02:55:02.853+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ANTLR'/><title type='text'>[ANTLR] Add children to derived Tree</title><content type='html'>I defined a Tree node class from org.antlr.Runtime.Tree.CommonTree, say MyTree.  When I add a MyTree object as a child to another tree object, the MyTree node is not actually added.&lt;br /&gt;&lt;br /&gt;The problem is that I didn't override Tree.isNil() method.  When Tree.addChild() is called, it check to see if the node is an imaginary node by isNil().  If it is and it has no children, the tree node will not be added.&lt;br /&gt;&lt;br /&gt;After forcing MyTree.isNil() to return true, the MyTree object can be added as a child.&lt;br /&gt;&lt;br /&gt;Reference: http://www.antlr.org/api/Java/classorg_1_1antlr_1_1runtime_1_1tree_1_1_base_tree.html#ffa585d68d73d750699da8fb311226b2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-6262215190603709643?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/6262215190603709643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/6262215190603709643'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2008/06/antlr-add-children-to-derived-tree.html' title='[ANTLR] Add children to derived Tree'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-3633878387245362656</id><published>2008-05-07T01:44:00.003+08:00</published><updated>2008-05-07T01:49:13.084+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ANTLR'/><title type='text'>Syntax color for "label" in ANTLRWorks</title><content type='html'>One of my frequent mistake using ANTLRWorks is that I always forget the $ prefix of the labels.  By changing the syntax color setting and change the default black color for "labels" would help remind me of that.  &lt;div&gt;But the rule arguments and return values aren't yet recognized as "label" though they need a "$" prefix as well.  If these variables can be highlighted, that would be more helpful.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-3633878387245362656?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/3633878387245362656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/3633878387245362656'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2008/05/syntax-color-for-label-in-antlrworks.html' title='Syntax color for &quot;label&quot; in ANTLRWorks'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-6029766780571877165</id><published>2008-04-28T06:53:00.004+08:00</published><updated>2008-04-28T07:39:42.923+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ANTLR'/><title type='text'>Use Scope definition instead of rule parameters in ANTLR3</title><content type='html'>In the SimpleC to LLVM translation project, I need to pass a parameter as a flag variable into a parser rule.  However, if I add a parameter to the rule declaration, I have to change all the references to that rule into rule[args].&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;As an alternative solution, I use Scope definition and put that flag variable in to the declared scope.  Whenever I need that flag variable, I can import that global scope within the parser rule to get reference to that variable.  &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In this case:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;grammar G;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;assignment&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;scope {boolean isLeftHandSide;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;    :  {$assignment::isLeftHandSide=true;}ID '=' &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;       {$assignment::isLeftHandSide=false;}ID&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;    ;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;expression &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;    :  ID {if($assignment::isLeftHandSide) doSomething();}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;    ;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;Reference: The Definitive ANTLR Reference, chapter 4.5&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-6029766780571877165?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/6029766780571877165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/6029766780571877165'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2008/04/use-scope-definition-instead-of-rule.html' title='Use Scope definition instead of rule parameters in ANTLR3'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-6135505245998399390</id><published>2008-04-25T15:26:00.003+08:00</published><updated>2008-04-25T15:36:48.863+08:00</updated><title type='text'>Java sound</title><content type='html'>After switched to MAC, I can't find a bemani emulator for MacOS.  I want to write one myself.&lt;div&gt;I'm trying to make Java play wave audio.  Found a sample code online.  But the sound doesn't play in run mode.  It only plays in debug mode.  I found the Clip.drain() method can block the program till the audio data in I/O is empty/played.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: courier new;"&gt;import javax.sound.sampled.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;import java.io.*;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;import java.net.*;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;public class EntryPoint {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    public void playSound() {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;           try {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // From file&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                AudioInputStream stream = AudioSystem.getAudioInputStream(new File("/Users/shaotingcai/Documents/USF/cs652/JavaSound/src/me.wav"));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // From URL&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                //stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // At present, ALAW and ULAW encodings must be converted&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // to PCM_SIGNED before it can be played&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                AudioFormat format = stream.getFormat();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                    format = new AudioFormat(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            AudioFormat.Encoding.PCM_SIGNED,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            format.getSampleRate(),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            format.getSampleSizeInBits()*2,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            format.getChannels(),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            format.getFrameSize()*2,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            format.getFrameRate(),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                            true);        // big endian&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                    stream = AudioSystem.getAudioInputStream(format, stream);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // Create the clip&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                DataLine.Info info = new DataLine.Info(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                    Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                Clip clip = (Clip) AudioSystem.getLine(info);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // This method does not return until the audio file is completely loaded&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                clip.open(stream);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                System.out.println("opened.");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                // Start playing&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                clip.start();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                clip.drain();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                System.out.println("played");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            } catch (MalformedURLException e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                e.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            } catch (IOException e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                e.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            } catch (LineUnavailableException e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                e.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            } catch (UnsupportedAudioFileException e) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                e.printStackTrace();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    public static void main(String[] args) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        EntryPoint main = new EntryPoint();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        main.playSound();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-6135505245998399390?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/6135505245998399390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/6135505245998399390'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2008/04/java-sound.html' title='Java sound'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-8662371700751639505</id><published>2007-02-06T11:16:00.000+08:00</published><updated>2007-02-06T13:39:53.646+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ANTLR'/><title type='text'>Working with ANTLR in VS2003</title><content type='html'>ANTLR is an scalable framework for building language recognition programs. I just built the front-end part of a scripting engine under ANTLR 2.77 (can be found &lt;a href="http://www.antlr.org/"&gt;here&lt;/a&gt;) in Microsoft Visual Studio 2003 using C++ language. I'd like to share some simple steps that can save your time in working with ANTLR tools.&lt;br /&gt;&lt;br /&gt;[environment info]&lt;br /&gt;ANTLR ver 2.77&lt;br /&gt;Visual Studio 2003&lt;br /&gt;C++ language&lt;br /&gt;&lt;br /&gt;Thanks to the detailed "getting started" documents from the ANTLR online resources, I successfully compiled and run my first ANTLR project in VC++. This &lt;a href="http://www.imada.sdu.dk/~morling/issue1.htm"&gt;tutorial&lt;/a&gt; is very clear on building ANTLR Library and configurations of your own projects. It is written for VC6, but can be easily implemented in VC7. I'd suggest you refer to this tutorial first to get your first ANTLR project live before reading the following staff.&lt;br /&gt;&lt;br /&gt;Usually, we use ANTLR tools like this:&lt;br /&gt;&lt;span style="font-family:arial;"&gt;&lt;strong&gt;[translate grammar file into source code] --&gt; [compile project] --&gt; [edit test case] --&gt; [run]&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;I used to swithing among my project in VS, editor for my test case and "antlr.Tools" frequently everytime I modified my grammar file. That was really challenging for my Alt-Tab action. So I wrote two small batch files and integrated them into VS2003.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1. copy antlr.jar to your source code folder&lt;/strong&gt;&lt;br /&gt;antlr.jar file is not big (435k). So I copied it to my source code folder to avoid all the classpath settings. If you really don't like this step, you can skip it and set your classpath as is described in the tutorials mentioned above.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2. create batch file for Parser/Lexer generation&lt;/strong&gt;&lt;br /&gt;Create the following batch file -- gen.bat&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;color:#3333ff;"&gt;@echo off&lt;br /&gt;cls&lt;br /&gt;echo ---------------------------------------------&lt;br /&gt;echo Generate using ANTLR&lt;br /&gt;echo ---------------------------------------------&lt;br /&gt;java antlr.Tool mygrammar.g&lt;br /&gt;echo -------------------end-----------------------&lt;br /&gt;pause&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Save it as gen.bat in your source code folder. The bat file will popup a cmd window telling the result of the generation and will disappear on "any key pressed".&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3. create batch file for running exe&lt;/strong&gt;&lt;br /&gt;By default, debug/release exe file will be built in the sub folder of the project source folder. So we create the following batch file -- run.bat (my exe filename is "sdscript.exe" and the test case script is "demo.script")&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;color:#3333ff;"&gt;@echo off&lt;br /&gt;cls&lt;br /&gt;cd debug&lt;br /&gt;sdscript demo.script&lt;br /&gt;pause&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4. run everything in VS2003&lt;/strong&gt;&lt;br /&gt;drag and drop these files into your project explorer tree:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;grammar file (*.g)&lt;/li&gt;&lt;li&gt;test case scripts&lt;/li&gt;&lt;li&gt;gen.bat&lt;/li&gt;&lt;li&gt;run.bat&lt;/li&gt;&lt;/ul&gt;I created a project folder called ANTRL to put all these stuff in.&lt;br /&gt;&lt;br /&gt;Then, &lt;strong&gt;right click&lt;/strong&gt; on the gen.bat batch file item in the project tree --&gt; open as...&lt;br /&gt;In the popup dialog, choose the "gen.bat" item and "set default". (Repeat this step for run.bat)&lt;br /&gt;We now can double click on the batch file item to run it!&lt;br /&gt;&lt;br /&gt;If you did all the steps, the general compiling routine would be:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;edit your grammar file (*.g) in vs2003 ( and save )&lt;/li&gt;&lt;li&gt;double click gen.bat item to refresh parser/lexer source code&lt;/li&gt;&lt;li&gt;perform "build" &lt;/li&gt;&lt;li&gt;edit your testing files in vs2003 ( and save)&lt;/li&gt;&lt;li&gt;double click run.bat item to see the result&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Isn't that cool?&lt;/p&gt;&lt;p&gt;There are also some other tricks helping us automating our build/generate works. You can found one of them &lt;a href="http://www.antlr.org/wiki/display/ANTLR3/Integration+with+development+environments"&gt;here&lt;/a&gt; in antlr's wiki site.&lt;/p&gt;&lt;p&gt;Hope you enjoy it :)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-8662371700751639505?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/8662371700751639505'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/8662371700751639505'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2007/02/work-with-antlr-in-vs2003.html' title='Working with ANTLR in VS2003'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-115937078104028705</id><published>2006-09-27T23:26:00.000+08:00</published><updated>2006-09-27T23:26:21.683+08:00</updated><title type='text'>Some conventions for Javadoc comments</title><content type='html'>I'm learning to use Java dev under Eclipse JDT these days and I find one interesting function -- JavaDOC.  When in Delphi environment, I had to recompose all the explaintive documents after a new class established or some methods updated.  It did take a lot of time to deal with  the task.&lt;br /&gt;However, in JavaDoc, the document is automatically generated upon some formatted comments.  This is convenient.  I searched for some conventions of writing effective and effecient javadoc comments and here are some main points:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;the following contents are abstracted from SDN references:&lt;/span&gt;&lt;br /&gt;&lt;b&gt;Order of Block Tags&lt;/b&gt;&lt;br /&gt;Include block tags in the following order:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;* @param       &lt;/code&gt;(classes, interfaces, methods and constructors only)&lt;br /&gt;&lt;code&gt;* @return      &lt;/code&gt;(methods only)&lt;br /&gt;&lt;code&gt;* @exception   &lt;/code&gt;(@throws is a synonym added in Javadoc 1.2)&lt;br /&gt;&lt;code&gt;* @author      &lt;/code&gt;(classes and interfaces only, required)&lt;br /&gt;&lt;code&gt;* @version     &lt;/code&gt;(classes and interfaces only, required. See &lt;a href="http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#footnote1"&gt;footnote 1&lt;/a&gt;)&lt;br /&gt;&lt;code&gt;* @see         &lt;/code&gt;&lt;br /&gt;&lt;code&gt;* @since       &lt;/code&gt;&lt;br /&gt;&lt;code&gt;* @serial      &lt;/code&gt;(or @serialField or @serialData)&lt;br /&gt;&lt;code&gt;* @deprecated  &lt;/code&gt;(see &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/deprecation/deprecation.html"&gt;How and When To Deprecate APIs&lt;/a&gt;)&lt;br /&gt;&lt;/pre&gt; &lt;p&gt; &lt;a name="orderingmultipletags"&gt;&lt;/a&gt; &lt;b&gt;Ordering Multiple Instances of Same Tags&lt;/b&gt;&lt;br /&gt;&lt;a name="multiple@author"&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt; Multiple @author tags should be listed in chronological order, with the creator of the class listed at the top. &lt;a name="multiple@param"&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt; Multiple @param tags should be listed in argument-declaration order. This makes it easier to visually match the list to the declaration. &lt;a name="multiple@throws"&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt; Multiple @throws tags (also known as @exception) should be listed  alphabetically by the exception names. &lt;!-- Multiple @throws tags should generally be listed alphabetically by the exception names. However, there may be times when it may be more sensible to group them primarily by inheritance and secondarily  alphabetically.  For example, a method for reading a serialized  object from a file can throw a host of exceptions, including: &lt;pre&gt;    IOException    EOFException    FileNotFoundException    StreamCorruptedException &lt;/pre&gt; &lt;p&gt; A client object interested merely in a simple success/failure of  such a method call can try/catch IOException alone. All the other  exceptions are subclasses of IOException. --&gt; &lt;a name="multiple@see"&gt;&lt;/a&gt; &lt;a name="multiple@seetags"&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt; Multiple @see tags should be ordered as follows: &lt;!-- BEGIN VCD7 CODE SAMPLE COMPONENT  --&gt; &lt;/p&gt;&lt;table class="grey4" border="0" cellpadding="10" cellspacing="0" width="100%"&gt; &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre&gt;   @see #field&lt;br /&gt;  @see #Constructor(Type, Type...)&lt;br /&gt;  @see #Constructor(Type id, Type id...)&lt;br /&gt;  @see #method(Type, Type,...)&lt;br /&gt;  @see #method(Type id, Type, id...)&lt;br /&gt;  @see Class&lt;br /&gt;  @see Class#field&lt;br /&gt;  @see Class#Constructor(Type, Type...)&lt;br /&gt;  @see Class#Constructor(Type id, Type id)&lt;br /&gt;  @see Class#method(Type, Type,...)&lt;br /&gt;  @see Class#method(Type id, Type id,...)&lt;br /&gt;  @see package.Class&lt;br /&gt;  @see package.Class#field&lt;br /&gt;  @see package.Class#Constructor(Type, Type...)&lt;br /&gt;  @see package.Class#Constructor(Type id, Type id)&lt;br /&gt;  @see package.Class#method(Type, Type,...)&lt;br /&gt;  @see package.Class#method(Type id, Type, id)&lt;br /&gt;  @see package&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;span class="sp20"&gt; &lt;/span&gt;&lt;br /&gt;&lt;!-- END VCD7 CODE SAMPLE COMPONENT  --&gt; &lt;p&gt; &lt;a name="requiredtags"&gt;&lt;/a&gt; &lt;b&gt;Required Tags&lt;/b&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;@param &lt;/span&gt;tag is "required" (by convention) for every parameter,  even when the description is obvious.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-weight: bold;"&gt;@return&lt;/span&gt; tag is required for every method that returns something  other than &lt;code&gt;void&lt;/code&gt;, even if it is redundant with the method description.  (Whenever possible, find something non-redundant (ideally, more specific) to use  for the tag comment.) &lt;/p&gt;Complete document on this topic can be found here:&lt;br /&gt;&lt;a href="http://java.sun.com/j2se/javadoc/writingdoccomments/index.html"&gt;How to Write Doc Comments for the Javadoc Tool&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-115937078104028705?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/115937078104028705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/115937078104028705'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2006/09/some-conventions-for-javadoc-comments.html' title='Some conventions for Javadoc comments'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-115718129114214058</id><published>2006-09-02T15:14:00.000+08:00</published><updated>2006-09-02T15:14:51.160+08:00</updated><title type='text'>The Hottest Pill – Blue Pill</title><content type='html'>Let the computer swallow the Blue Pill and take control of it.  This is an interesting issue in the recent ‘Security Now! Podcast #54’.  It’s amazing that the concept in the ‘Matrix’ movie comes to the real world.  After googling the internet, I found that this is really a hot topic in the field of information security these days.&lt;br /&gt;&lt;br /&gt;Joanna Rutkowska, the most mentioned name in my search result pages, is the one who carried out the idea.  In her own interpret ion, the Blue Pill works in the following steps:&lt;br /&gt;1. The computer – actually the operation system – swallows the Blue Pill at such circumstances as executing an intentional script or program in which way most malware start their plot.&lt;br /&gt;2. The Blue Pill grab the HyperVisor privilege of the computer on-the-fly which means no reboot is needed.&lt;br /&gt;3. The Blue Pill then take over the full control of the host OS using its HyperVisor power and place the OS in a Virtual Machine environment while the OS will never feel anything about this disastrous alternation.&lt;br /&gt;Just as we are running another OS via Virtual PC program in our Host System, power on the machine or shutting it down as we like, the Blue Pill can perform any unexpected tricks to the VM mode OS.  What an impact it brings to the security of our computer!&lt;br /&gt;&lt;br /&gt;As is claimed by Joanna, the Blue Pill root kit is un-detectable since it’s not relying on any flaws or bugs of the victim OS and all the actions to be taken are on-the-fly.  As a result, neither the operation system nor the user will found any clues.  Furthermore, when the Blue Pill rip off the HyperVisor privilege, it can make any camouflages needed to keep away from those scanning process.  After all, the OS is under virtual machine mode which means its just a toy in the hand over the Blue Pill. &lt;br /&gt;&lt;br /&gt;According to Joanna’s explanation, the Blue Pill mechanism relies on Hardware layer technology which has be provided by the latest AMD chip – SVM, an CPU level support for virtualization.  Also, Joanna established a prototype of the Blue Pill with a small Blue Pill program in C Language which can take effect on Windows Vista running on the new AMD chip.&lt;br /&gt;&lt;br /&gt;However, there are also different voices.  Toward the claim-to-be invincible Blue Pill, Anthony Liguori from IBM Linux Technology Center shows different attitude.  He argued that the ideal effect claimed for Blue Pill is impossible.  There two aspects he held for his contradiction.&lt;br /&gt;1. The self-aware problem.&lt;br /&gt;The host OS is still able to detect whether its running under a VM mode.  This is the most controversial point while Joanna, the establisher, insists that detection is by no means implemental. &lt;br /&gt;2. The clock-time problem.&lt;br /&gt;There will be a considerable difference in the time of instruction execution between VM and non-VM OS which can be a critical clue to check whether the system has been taken over by the Blue Pill.  According to Anthony, the clock-cycle can be sub-categorized to two types: internal and external.  Though he confessed that the internal clock-time problem can be concealed due to the HyperVisor privilege of the Blue Pill, the external one is unavoidable. &lt;br /&gt;Though he didn’t demonstrate a detailed method to support his arguments, there is a feasible principle illustrated by the host of the podcast ‘Security Now!’ and I’ll mention this later in my passage.&lt;br /&gt;&lt;br /&gt;An optimistic manner kept by Anthony upon the Blue Pill threat, he yet gave a passive solution by recommending the manufacturer of the chip turning off the virtualization function on the CPU side.&lt;br /&gt;&lt;br /&gt;Differ from the sharp positions hold by Joanna and Anthorny, Steve Gibson and Leo Laporte in the ‘Security Now!’ podcast organized a neutral discussion on the Blue Pill Issue.&lt;br /&gt;&lt;br /&gt;Firstly, they demonstrated a common routine taken by general malware root kit to hide from detection: process hiding and file hiding.  As for me, when I feel any suspicious mal-function or slow reaction in my computer, I would check the process list in the task manager and then search for evil files on my hard drive with the help of the anti-virus tools.  So, a malware usually tries its best to conceal itself both in the process list and the file filter.  The process list is a chained data structure—the task monitor maintains a pointer to the first process and each process has a pointer to the next process.  When we open the task monitor in Windows, processes are sequentially visited and listed according to the chain structure.  In order not to be found in the task monitor, an evil process break the chain at the node of itself by removing the pointer to itself from the predecessor object and link the pointer of the predecessor to the next process.  As a result, the evil process disappears in the task monitor.  Regarding the file hiding, the principle is similar.  When the search procedure is enumerating the files, the root kit extracts its related files from the file list by intercepting the search API so as not to be displayed in the result.&lt;br /&gt;&lt;br /&gt;The root kits of the general malware are always detectable owing to the common mechanism they employed—API hooking.  And API hooking skill is traceable.  Therefore, anti-malware tools can always give warnings when system is haunted.  However, when it comes to the Blue Pill attack, problem shifts.  The malware encapsulated in the Blue Pill can surpass the OS level and operate without bothering the APIs.&lt;br /&gt;&lt;br /&gt;Besides showing us the terrible situation after the system is intruded by the Blue Pill, Steve also described possible ways to detect the Blue Pill threat in detail for Anthony’s arguments.&lt;br /&gt;&lt;br /&gt;In Anthony’s words, Blue Pill is detectable.  Steve partially agrees with him.  He picked out some registers in the AMD chip which supports CPU-level virtualization and is now the best seedbed for Blue Pill.  The value of such registers can indicate whether the Host OS is under VM mode or not.  However, considering the HyperVisor privilege of the swallowed Blue Pill, it can still ‘filter’ such read-operation to these critical registers which means the value reflected from these VM-stated related registers can still be camouflaged if actions are taken by the Blue Pill.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another weak point of Joanna’s Blue Pill prototype is more focus-worthy – the clock cycle delay problem.  As we all know, OS performs obvious different in efficiency between VM mode and non-VM mode.  Steve mentioned the RDMSR instruction particularly to figure out that the time stamp result can easily tell whether the system in VM mode.  In his explanation, normal cycle time is around 90 while in VM mode it can rocket to 2100.  But, here comes the same problem for auto detection via time stamp as the first solution meets – register reading filter controlled by the Blue Pill.  The return value of the time stamp can still be changed by the malware if it hopes to.  Then, Steve gave another idea about the time stamp detection – Manual Detection (external clock cycle as is mentioned by Anthony).  Since the unit for time is extremely small, if such kind of detection is expected, the time stamp checking operation needs to be performed over millions of times to reveal the perceptible delay the users.  And what seems to be ridiculous is that the user will have to tap their stopwatch every few hours or even minutes to ensure their system is not abducted.  &lt;br /&gt;&lt;br /&gt;In Steve and Leo’s perspective, the Blue Pill is not a brand new concept.  The research department of Microsoft has established a similar program named ‘SubVirt’ which can achieve similar functions as Blue Pill does.  However the Blue Pill is more advanced in the following ways.&lt;br /&gt;1. SubVirt requires system reboot to take effect while Blue Pill is all on-the-fly.&lt;br /&gt;2. SubVirt is hardware based in the way it store its root kit on the hard drive while Blue Pill just slip in to the memory without leaving any clues on the hard drive.&lt;br /&gt;3. SubVirt is detectable while Blue Pill claims to be not.&lt;br /&gt;Joanna Rutkowska also wrote a small program called Red Pill which can run tell whether the OS is under VM mode or not in and only in VM Station and Virtual PC environment.  The Red Pill checks a certain offset in the memory to make the judgment.  The Red Pill and Blue Pill seems to be a pair of spear and shield but currently the Blue Pill gets the run upon the other owing to its HyperVisor privilege.&lt;br /&gt;&lt;br /&gt;Steve believes that the Blue Pill would be a big problem for Microsoft Vista OS and his advice for Microsoft is produce their its own Blue Pill first and get the highland of the computer before other Blue Pills try to intrude.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-115718129114214058?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/115718129114214058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/115718129114214058'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2006/09/hottest-pill-blue-pill.html' title='The Hottest Pill – Blue Pill'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-115631551012336552</id><published>2006-08-23T14:43:00.000+08:00</published><updated>2006-08-23T14:49:30.446+08:00</updated><title type='text'>Revival!</title><content type='html'>Oh! It's amaizing that this weblog is accessible again~~~&lt;br /&gt;I was so upset when google service told me that the Chinese Government blocked this site and I even didn't see anything wrong with blogspot.&lt;br /&gt;&lt;br /&gt;Anyway, it's great to have my blog back again.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-115631551012336552?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/115631551012336552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/115631551012336552'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2006/08/revival.html' title='Revival!'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-113423323708014615</id><published>2005-12-11T00:21:00.000+08:00</published><updated>2005-12-11T01:09:50.786+08:00</updated><title type='text'>Exception Handling</title><content type='html'>I had an argue with the team leader of my ZA-project(the computer-based test application). We are arriving at the integration testing program now, but the application doesn't seems to be that stable. Since we have a lot of interactions with xml parsers, file compressor/decompressor and the web apps(we use jsp for courseware extractions), unexpected exceptions pop up sometimes. Although it's we are working hard in clearing them, the situation appears to be beyond our control.&lt;br /&gt;Usually, the exceptions are about memory access violation and memory leaks. In addition, I found that the application sometimes won't stop when an exception appears not to mention handle it properly before it stands in the way. And after the unhandled exceptions, more horrible problems will come along. We do have defined a set of customed exception classes in a hierachy structure. But I don't see they are correctly used.&lt;br /&gt;&lt;br /&gt;I think we should had big problems in exception management. So, in the regular meeting, I suggests that we should strengthen our codes in exception handling. I gave some ideas:&lt;br /&gt;&lt;ol&gt;   &lt;li&gt;Provide a component structure diagrams to show the relationships and the hierachy among among the components to all the team members.&lt;/li&gt;   &lt;li&gt;Every should mark the possible exceptions in his own module in the diagram. He should give a explicit exception lifetime-line in order to tell the others whether:&lt;/li&gt;   &lt;ol&gt;     &lt;li&gt;the exceptions are safely handled within his own module&lt;/li&gt;     &lt;li&gt;the exceptions are raised for the inability to handle in the current module&lt;/li&gt;     &lt;li&gt;all the captured system(VCL) exceptions are converted into our defined exceptions&lt;/li&gt;     &lt;li&gt;all the known user errors are advertised in form of our defined exceptions&lt;/li&gt;   &lt;/ol&gt;   &lt;li&gt;Everyone uses other team members' components should keep an eye on the exception lifetime information provided by the component author and continue work on it within the range of his own module/component.&lt;/li&gt;&lt;li&gt;I strongly advise the team members never handle any handles that should not be handled within their module/level.  We've already lost many runtime information by missing these exceptions thus result in the uncontrollable exceptions.&lt;/li&gt;  &lt;/ol&gt;However the team lead doesn't seem to be interested in my suggestions, since he thought this would be a extra burden on the project and he don't believe we can convert ALL VCL exceptions to our defined exception classes.  I don't agree with that.  I've been told to put a try..except statement every time I need to deal with fileIO/db/network/memRes/...  I don't think that would be a burden while it should be a guideline.&lt;br /&gt;&lt;br /&gt;I insist on converting all we-have-known vcl exceptions into defined exceptions because I want the upper layer caller would get a well-catagorized problem list to solve or keep.  And any we-do-not-know exceptions should not be touched and keep raising to the top layer(UI), at least in our development period, so that we could see what kind of problems there are.  When the application is to be released, we could then capture all unsolved exceptions in the most outside layer and change them into a smoother informations instead of the frightening "ding!".&lt;br /&gt;&lt;br /&gt;Any way, I'm not supported.  But I'll try to work this way in my modules.&lt;br /&gt;&lt;br /&gt;After this arguement, I found there are a lot to be thought in the part of exception management.  I'm very interested in doing some research on that, but my graduate paper topic has already been set to the ZA project.  I think I can try implement an "exception life management tool" which can provide a diagram as I mentioned above in way as UML did.  And perhaps the tool could serve as Rational ClearQuest does in the bug-lifetime management.&lt;br /&gt;&lt;br /&gt;I've made some small investigation these days to have a look at the development in this field and I found some books and articles.&lt;br /&gt;&lt;br /&gt;&lt;exceptional&gt;&lt;br /&gt;&lt;br /&gt;A discussion&lt;br /&gt;&lt;a href="http://dev.csdn.net/article/81200.shtm"&gt;http://dev.csdn.net/article/81200.shtm&lt;/a&gt;&lt;br /&gt;&lt;a href="http://community.csdn.net/Expert/TopicView3.asp?id=4432545"&gt;&lt;span id="ArticleContent1_ArticleContent1_lblContent"&gt;http://community.csdn.net/Expert/TopicView3.asp?id=4432545&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I will hunt for more related resourse and post them here.&lt;br /&gt;&lt;br /&gt;Another dissapointing news is my poor verbal score in GRE test.  That wouldn't be an attractive score without which I will no longer have any opportunities to do my interested researches...  But I'll not give up.  There's still time.  I don't have much time prepare for the last GRE test because my whole summer vacation is devoted to the ZA project.  But I'll have time for the next June test.  Cheer!  God Bless.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-113423323708014615?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113423323708014615'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113423323708014615'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2005/12/exception-handling.html' title='Exception Handling'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-113392332281631435</id><published>2005-12-07T10:42:00.000+08:00</published><updated>2005-12-07T10:42:05.170+08:00</updated><title type='text'>ASCII Table</title><content type='html'>I need this from time to time.  So just save it here.&lt;br /&gt;http://www.neurophys.wisc.edu/www/comp/docs/ascii.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-113392332281631435?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113392332281631435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113392332281631435'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2005/12/ascii-table.html' title='ASCII Table'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-113378497628699502</id><published>2005-12-05T19:56:00.000+08:00</published><updated>2005-12-05T20:16:16.386+08:00</updated><title type='text'>[Delphi] Static Variables</title><content type='html'>I'm on my PL/x compiler project today and I've added to it some new features such as 'single line comment filter' and 'charcase pre-processor'.&lt;br /&gt;&lt;br /&gt;When dealing with comments, I was trying to use a static variable as is defined as 'static' in the C language. But I can't find one in help contents.  Then I found one way on the web using compiler directives:&lt;br /&gt; &lt;span style="color: rgb(0, 153, 0); font-family: courier new;"&gt;{$J+} &lt;span style="color: rgb(51, 51, 255);"&gt;typed_const&lt;/span&gt; {$J-}&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0); font-family: courier new;"&gt;&lt;br /&gt;{$WRITEABLECONST ON} &lt;span style="color: rgb(51, 51, 255);"&gt;typed_const&lt;/span&gt; {$WRITEABLECONST OFF}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;These compiler directives enable the assignment to the constants.  For instance:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;&lt;span style="font-weight: bold;"&gt;procedure &lt;/span&gt;StaticVars;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255); font-weight: bold; font-family: courier new;"&gt;const&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0); font-family: courier new;"&gt;{$J+}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;  iCount: Integer = 0;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0); font-family: courier new;"&gt;{$J-}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255); font-weight: bold; font-family: courier new;"&gt;begin&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;  Inc(iCount);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;  ShowMessage(IntToStr(iCount));&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;&lt;span style="font-weight: bold;"&gt;end&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Just take care of one thing that the constants declaired should be &lt;span style="font-weight: bold;"&gt;explicitly typed&lt;/span&gt;.  Such declairation as "const a=1" will raise a error when compiled even when {$J+/-} is used&lt;br /&gt;.&lt;br /&gt;&lt;br /&gt;I'm much confused by this feature provided by Delphi.  The constants are declaired in the scope of a procedure, but how can the value assigned to the constant be preserved to next procedure call.  I made some experiment on the address of the const/vars.  The result shows that the constants are allocated together with global/class variables of the Unit while local vars are still allocated within the scope of the procedure.&lt;br /&gt;&lt;br /&gt;I still don't have any idea about this and I couldn't find any better way to implement static var directly or indirectly.  I'll be glad to receive your advice.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-113378497628699502?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113378497628699502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113378497628699502'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2005/12/delphi-static-variables.html' title='[Delphi] Static Variables'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-113333974280185275</id><published>2005-11-30T16:22:00.000+08:00</published><updated>2005-11-30T16:35:42.813+08:00</updated><title type='text'>[Delphi] Avoid Auto Generated Accelerator Key in ActionList</title><content type='html'>To my greate pleasure, my coursework, a PL/x compiler, is basically completed.  It can now compile/run a program prints all prime numbers within 1-100.&lt;br /&gt;&lt;br /&gt;Then, I plan to build a proper IDE for it.  I get two powerful tools -- &lt;span style="color: rgb(51, 255, 51);"&gt;SyncEdit&lt;/span&gt; and &lt;span style="color: rgb(51, 255, 51);"&gt;ActionManager&lt;/span&gt;.  SyncEdit is an open-source VCL component, I guess whether such apps like Ultra-Edit use this component.   ActionMananger is a better choice than ActionList + ToolBar + Menu.  ActionManager behaves just the same as MS Office Toobars/Menus.  All the stuffs are based on actions and item on display can be customized.  For example, add/remove buttons on toolbar or menu, hide/show toolbar, re-arrange toolbars...&lt;br /&gt;&lt;br /&gt;One problem I met with is the auto-generated accelerator-key provided by delphi.  If I don't define a (&amp;*) key in the caption property of an TAction object, Delphi will provide one in alphabit-reverse sequence.  That's annoying sometimes.&lt;br /&gt;&lt;br /&gt;However, I find out a way to get away from them: &lt;span style="color: rgb(255, 0, 0);"&gt;append a '&amp;amp;' char at the end of each action caption&lt;/span&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-113333974280185275?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113333974280185275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113333974280185275'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2005/11/delphi-avoid-auto-generated.html' title='[Delphi] Avoid Auto Generated Accelerator Key in ActionList'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-113323851812149271</id><published>2005-11-29T12:16:00.000+08:00</published><updated>2005-11-29T12:28:38.140+08:00</updated><title type='text'>Take Care When Changing FormStyle in Delphi</title><content type='html'>A new bug from my assessment-tool project pops up this morning.  I wrote a Hotkey Configuration Component which enables the users to define their preferred hotkey mode for certain provided functions.  On the other hand, there is an 'Always on Top' menu item in the main form.  I found that every time I changed the formStyle between 'fsAlwaysOnTop' and 'fsNormal' all my registered hotkeys were inactivated.&lt;br /&gt;&lt;br /&gt;Then I refer to the VCL Help, it says in the document:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);font-size:85%;" &gt;&lt;span style="font-family: courier new; font-weight: bold;"&gt;TCustomForm.FormStyle&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;&lt;span style="font-weight: bold;"&gt;Note: &lt;/span&gt;   It is not advisable to change FormStyle at runtime.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And then, I made a experiment to see why it's 'not advisable'.  I guess that would be problems with Handle of form.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);font-size:85%;" &gt;&lt;span style="font-family: courier new;"&gt;  ShowMessage(IntToStr(Handle);&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;  if Self.FormStyle &lt;&gt; fsStayOnTop then&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    Self.FormStyle := fsStayOnTop&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;  else&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;    Self.FormStyle := fsNormal;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-family: courier new;"&gt;  ShowMessage(IntToStr(Handle);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Yes, when FormStyle property is changed, the Handle of the form will be re-allocated.  As a result, all hotkey message(WM_HOTKEY) were not received by the form with new handle.&lt;br /&gt;&lt;br /&gt;My solution for this bus is to deactivate all hotkeys before changing FormStyle and then re-activate them after the change. &lt;br /&gt;&lt;br /&gt;But, I still wonder whether there are yet any other traps here.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-113323851812149271?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113323851812149271'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113323851812149271'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2005/11/take-care-when-changing-formstyle-in.html' title='Take Care When Changing FormStyle in Delphi'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry><entry><id>tag:blogger.com,1999:blog-19381597.post-113317602060426941</id><published>2005-11-28T18:29:00.000+08:00</published><updated>2005-11-28T19:07:05.750+08:00</updated><title type='text'>Hello Blogger</title><content type='html'>Hello World!&lt;br /&gt;My name is Cai Shao Ting.  I'm a senior student in Computer Science Technology in East China Normal University.   I'm interested in programming and I open this blog to meet friends sharing the same interest with me.&lt;br /&gt;&lt;br /&gt;I've been programming on Delphi 7 for about 2 years. I have 2 social project experience.  One is VisualBasic+MSAccess application for information management of public physics lab.  The other one is Delphi+MySQL MIS application for the local Sanitation bureau.&lt;br /&gt;&lt;br /&gt;Currently, I'm working on 2 projects. &lt;br /&gt;One is the course work for "Compiler Principle Practice".  The goal is to implement a simple PL/x language compiler.  I've completed the programe parser, compiler and the virtual machine. Next, I will design a proper IDE for the compiler and try extend the language in such aspects as grammer definition and error checking.&lt;br /&gt;Another one is a Delphi project which is component-framework application for assessment of ERP software.  The project aims at designing a flexible tool for creating computer-based examination and tranning.  In this version, our assessment target is Microsoft Axapta.  Our team has established a framework for our goal.  My work concerns more on then component part.  We learnt a lot from the VCL framework of Delphi, so I implemented a set of similar components such as Property Editor and Object Inspector.  There is also a standard interface between the communication between our customized controls and the framework.  From the very beginning, our project manager just intended to implement a compact version of Delphi.&lt;br /&gt;Now the first version is going to be released, so we are now busy with testing.&lt;br /&gt;Though this is not my first project, but I think this is the most formal one among others.&lt;br /&gt;&lt;br /&gt;As you can see, I prefer Delphi as my first weapon.  However, I don't resist any other programming language or IDEs.  I'm in favor of programming as that a kind of magical work in my mind, in addition, I'm curiosity at any programe languages.  Most of my school work are implemented under Visual C++ 6.0.  Regarding browser-based applications, I uses Jbuilder on Jsp/Servlet.  I've always been looking for a chance to step into the .Net world.  But it has not come yet.&lt;br /&gt;&lt;br /&gt;This blog will record my progress and I think this would be a good chance to practise my written English.  Also, I'll be glad to talk with any of you who are interested in my study and project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19381597-113317602060426941?l=caishaoting.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113317602060426941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19381597/posts/default/113317602060426941'/><link rel='alternate' type='text/html' href='http://caishaoting.blogspot.com/2005/11/hello-blogger.html' title='Hello Blogger'/><author><name>Shaoting</name><uri>http://www.blogger.com/profile/17457501305394408406</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05268037947042316264'/></author></entry></feed>