Install Windows 7 x64 on iMac 24

by Jesse 24. October 2009 00:42

Preorder windows 7 when its price is only £99, and happily received it yesterday (Have to travel 15 miles to pick it up local depot of CityLink though). I tried to install it on my iMac today, but as I expected, it has the same issue mentioned in my previous blog.

http://elian.co.uk/post/2009/05/11/Installing-VISTA-x64-on-iMac.aspx

Update:
I can confirm the old solution still works, just little note that, you need to disable UAC or use Run as administrator to install BootCamp drivers.

Bouncy Castle C#

by Jesse 29. July 2009 11:54

It has been really long time since my last post. And finally I get a few minutes to write this post on using BouncyCacle encryption in C#, hopefully it can help some one.

BouncyCastle is a encryption library widely used in Java, and has been porting to C# ages ago. But due to lack of documentation, I believe many people including myself have much trouble on implement any encrypt/decrypt functions by using it. Right, let's start.

 

First of all, you need to get BouncyCastle library from its website on http://www.bouncycastle.org/csharp/. It is not necessary to get the source code. Also, there are two type of binary format libraries you can download. One is with IDEA, and another is not. If you dont know which one you need, just download the one without IDEA. As IDEA is patented in many country, so you must be more careful when choosing to use.

My implementation consist of two  parts: block cipher encryption engine, and encryption/decryption interface.

BCEngine class (Block cipher engine)

public class BCEngine
    {
        private readonly Encoding _encoding;
        private readonly IBlockCipher _blockCipher;
        private PaddedBufferedBlockCipher _cipher;
        private IBlockCipherPadding _padding;

        public BCEngine(IBlockCipher blockCipher, Encoding encoding)
        {
            _blockCipher = blockCipher;
            _encoding = encoding;
        }

        public void SetPadding(IBlockCipherPadding padding)
        {
            if(padding != null)
                _padding = padding;
        }

        public string Encrypt(string plain, string key)
        {
            byte[] result = BouncyCastleCrypto(true, _encoding.GetBytes(plain), key);
            return Convert.ToBase64String(result);
        }

        public string Decrypt(string cipher, string key)
        {
            byte[] result = BouncyCastleCrypto(false, Convert.FromBase64String(cipher), key);
            return _encoding.GetString(result);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="forEncrypt"></param>
        /// <param name="input"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        /// <exception cref="CryptoException"></exception>


        private byte[] BouncyCastleCrypto(bool forEncrypt, byte[] input, string key)
        {
            try
            {
                _cipher = _padding == null ? new PaddedBufferedBlockCipher(_blockCipher) : new PaddedBufferedBlockCipher(_blockCipher, _padding);
                byte[] keyByte = _encoding.GetBytes(key);
                _cipher.Init(forEncrypt, new KeyParameter(keyByte));
                return _cipher.DoFinal(input);
            }
            catch (Org.BouncyCastle.Crypto.CryptoException ex)
            {
                throw new CryptoException(ex);
            }
        }
    }

 

The encryption/decryption interface:

public string AESEncryption(string plain, string key, bool fips)
        {
            BCEngine bcEngine = new BCEngine(new AesEngine(), _encoding);
            bcEngine.SetPadding(_padding);
            return bcEngine.Encrypt(plain, key);
        }

        public string AESDecryption(string cipher, string key, bool fips)
        {
            BCEngine bcEngine = new BCEngine(new AesEngine(), _encoding);
            bcEngine.SetPadding(_padding);
            return bcEngine.Decrypt(cipher, key);
        }

 

You can easily change the BouncyCastle engine to Blowfish, DES, TripleDES, TwoFish, etc.

Firefox 3.5 supports HTML 5

by Jesse 1. July 2009 16:16

Yesterday 30/06/2009, one of the most famous internet browser, and my favourite browser, released a new version 3.5 and becomes one of very first browser supports HTML 5 <video> and <audio> tag.

Following is the new features in FF 3.5 release note.

    *  Available in more than 70 languages. (Get your local version!)
    * Support for the HTML5 <video> and <audio> elements including native support for Ogg Theora encoded video and Vorbis encoded audio. (Try it here!)
    * Improved tools for controlling your private data, including a Private Browsing Mode.
    * Better web application performance using the new TraceMonkey JavaScript engine.
    * The ability to share your location with websites using Location Aware Browsing. (Try it here!)
    * Support for native JSON, and web worker threads.
    * Improvements to the Gecko layout engine, including speculative parsing for faster content rendering.
    * Support for new web technologies such as: downloadable fonts, CSS media queries, new transformations and properties, JavaScript query selectors, HTML5 local storage and offline application storage, <canvas> text, ICC profiles, and SVG transforms.

I have already downloaded and installed the new version, to be honst, you cannot really tell any different, and there are only few HTML 5. The Video Bay may be the most popular one because of the success of its founder TPB.

Tags: , , , , , ,
Categories: General | IT | News | Me | Web

TTPlayer dll

by Jesse 19. June 2009 15:08

上传一个TTPlayer的DLL, 想知道它是干什么的吗? 请用正确的email留言, 我会Email给你所有的细节. 现在所能说的就是, 它与TTPlayer的安全漏洞有关, 相关讨论可以在

http://bbs.chinaunix.net/viewthread.php?tid=1340433&extra=&page=2
http://bbs.chinaunix.net/viewthread.php?tid=1341275

Jesse

 

lrcsh.rar (19.00 kb)

Make "Repository Factory" work on VS 2008

by Jesse 5. June 2009 13:33

I am writing another post at the same time to compare several MS ORM technic. Put the result first, I finally decide to use "Repository Factory". Well, it is NOT really a ORM, but a code generator like "MyGeneration". The reason I like it is: 1. it is open-source. it is very important if you want to use a long-last technic, and not need to worry about MS abandoning it during your projects are still going. 2. it is light-weight. comparing ADO.NET EF, it doesnt eat into your performance lots. There are so many reason I want to use it, even Patterns & Practice team gave up this project.

I download the source code from https://RepositoryFactory.svn.codeplex.com/svn, the last commition is Feb this year! The good news, or say best news, is the solution is compilable. But the bad news is it is not working!!!! I can tell the code in SVN trunk is a incomplete/bugy copy of RF. You have to change couple things to make it. The issues mentioned in below posts on Codeplex are still there, I put my patch in or find a workaround.

http://repositoryfactory.codeplex.com/Thread/View.aspx?ThreadId=32194
http://repositoryfactory.codeplex.com/Thread/View.aspx?ThreadId=46567

The main changes are done in "t4" files (template file, Im interesting to know where the name t4 comes from if anyone knows). Download them as you will, and use it as your risk. If you know other fixs, please do leave comments. It will benifit all of us.

Repository Factory VS 2008 Fix.rar (8.13 kb)

Fix W3C validation failure on ImageButton control (Server-wise)

by Jesse 18. May 2009 19:55

Recently runs into a problem on passing validation my .NET pages on W3C validator(http://validator.w3.org). Generally speaking the HTML code rendered from ImageButton control contains a invalid html tag border="0" which caused failure on passing XHTML 1.0 Transitional check.

Microsoft claimed it is not their issue, as it is not appear in "View code" of IE, which sounds more like an excuse to me. Dig several pages in google, one guy in asp.net forume suggested to use app_browser file which is working for me. Following is my w3c.browser file which sits in ~/App_Browsers folder


<browsers>
    <browser id="W3C" parentID="default">
        <identification>
            <userAgent match="^W3C_Validator" />
        </identification>

        <capture>
            <userAgent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" />
        </capture>

        <capabilities>
          <capability name="browser" value="w3cValidator" />
          <capability name="majorversion" value="${major}" />
          <capability name="minorversion" value="${minor}" />
          <capability name="version" value="${version}" />
          <capability name="w3cdomversion" value="1.0" />
          <capability name="xml" value="true" />
          <capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" />
        </capabilities>
    </browser>
</browsers>

However, there are many websites running on my server, it is not a enjoyable jobs to copy it to every website. A server-wise solution will be a big time-saver. Read the post about "Browser Definition File Schema" (http://msdn.microsoft.com/en-us/library/ms228122.aspx) carefully, I mean line by line and word by word. You may find following paragraph

However, if changes are made to .browser files in the %SystemRoot%\Microsoft.NET\Framework\version\CONFIG\Browsers directory, you must manually recompile the application by using the %SystemRoot%\Microsoft.NET\Framework\version\aspnet_regbrowsers.exe tool

Haha, this sounds like a server-wise solution. I copied my w3c.browser to both C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers and C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\CONFIG\Browsers, if you cannot find the second folder, you may be running on a 32 bit system, so don't need to worry about it. And the last thing needs to do

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regbrowsers.exe -i

The assembly will automatically installed into GAC. ^_^

Just out of curiosity, I reflected the code aspnet_regbrowsers generated. If you are a "dead cat" like me, here is the code

private bool W3cProcess(NameValueCollection headers, HttpBrowserCapabilities browserCaps)
{
    IDictionary capabilities = browserCaps.Capabilities;
    string target = browserCaps[string.Empty];
    RegexWorker worker = new RegexWorker(browserCaps);
    if (!worker.ProcessRegex(target, "^W3C_Validator"))
    {
        return false;
    }
    worker.ProcessRegex(browserCaps[string.Empty], @"^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*");
    capabilities["browser"] = "w3cValidator";
    capabilities["majorversion"] = worker["${major}"];
    capabilities["minorversion"] = worker["${minor}"];
    capabilities["version"] = worker["${version}"];
    capabilities["w3cdomversion"] = "1.0";
    capabilities["xml"] = "true";
    capabilities["tagWriter"] = "System.Web.UI.HtmlTextWriter";
    browserCaps.AddBrowser("W3C");
    this.W3cProcessGateways(headers, browserCaps);
    bool ignoreApplicationBrowsers = false;
    this.W3cProcessBrowsers(ignoreApplicationBrowsers, headers, browserCaps);
    return true;
}

protected virtual void W3cProcessBrowsers(bool ignoreApplicationBrowsers, NameValueCollection headers, HttpBrowserCapabilities browserCaps)
{
}

protected virtual void W3cProcessGateways(NameValueCollection headers, HttpBrowserCapabilities browserCaps)
{
}

Stop annoying VISTA services

by Jesse 14. May 2009 22:25

After upgrading XP to VISTA recently, my hard disk seems getting a lot busier than before. It is very annoying, especially during a quiet mid-night. You just feel VISTA keeping f*k your HD, even you are doing nothing!

Check the 70+ processes running at background, which none of them is my application, no Visual Studio 2008, no IE, no firefox, no Photoshop...... just VISTA servies!!! One process is really bringing my attention, "searchindexer.exe". It belongs to VISTA new Windows Search Service. In theory, all those sort of indexing service should running when your PC is idle, but this indexer seems very like to compete with other processes. It normally takes 1-7% of CPU, takes more when copying stuff, and uses even more when some heavy processes running. It really kills the overall performance of your VISTA box.

To stop it is very easy, just go to "Service" in whatever way you want to. My way is Win+R, services.msc. Find out "Windows Searh", stop and disable it. I read some other blog, people always left comment to argue index service is light weight service, it has very low IO. But the truth is, after disable it, I can feel there is less hard disk activity.

 

Another annoying service is superfetch, as describ by Microsoft

"Windows SuperFetch enables programs and files to load much faster than they would on Windows XP–based PCs."

Mmmm, maybe. But it eats me so much memory for the preload applications which I may not use. I never do some testing to see how much I can benifit on openning an application, but at the mean time, it takes me lots of memory, and make VISTA load like a tortoise.

 

Note: I killed both services on my machine, but it doesnt mean I suggest you doing this as well. using a common phrase "You are at your own risk" to do this. ^_^

Installing VISTA x64 on iMac

by Jesse 11. May 2009 19:08

I bought my iMac 24" months ago and upgraded 4 Gb RAM immediately after bought. But I was using XP 32bit in the past months, the reason is simple. First, Apple does not officially support VISTA b4. The result is that you cannot install Boot Camp without a little trick. Secondly, 4 Gb RAM can still be used under 32bit system by using PAE (Physical Address Extension). I really dont want to risk my hours to re-install OS.

Recently I get more and more interesting in WCF TCP binding in IIS, I have no choice to get VISTA on my machine. (Well, VMWARE is pain to use during development) It gives me a chance to think should I get 64 bit VISTA instead 32bit. No matter which one, I will need to spend hours on it, nothing to lose. ^_^.

Right, back to my story. Trying to install VISTA 64 on my iMac last week, Boot Camp wizard, partition, reboot to install, everything Apple done is smooth, beautiful and easy.

After machine rebooted, load disc, stop!!!!!

1.
2.
Select CD-ROM Boot Type :

This first message VISTA 64 gave me. As explained by Microsoft:

This problem occurs because the ETFSBOOT.COM program does not handle file versions according to the International Standards Organization (ISO) 9660 specification.

Note The ETFSBOOT.COM program creates the CD boot sector.

The ISO 9660 specification instructs that a name for a file record should consist of the file name that is followed by the file version. Also, the specification instructs that you must separate the file name and the file version by a semicolon. For example, the following file record is valid:

FileName;1

The Windows PE file system driver handles the file version as an option. However, the ETFSBOOT.COM program cannot locate the Setupldr.bin/Bootmgr file if you use a file version. 

Google the answer, you may find a quite complex solution from Jowie 

Or a much more simple solution by Sergio, I used Sergio's way,because I am using a DVD instead of image, my procedure is a little easier.

1. Download oscdimg (external link) and put it in a easy access path, such as c:\
2. Check the space on your hard disk, make sure there is 3.6G at lease space on one of your disk partition.
3. Open a command console and run

oscdimg -n -m -be:\boot\etfsboot.com e:\ c:\vista64.iso

e: is DVD drive

After it finishes (around 5 minutes on my computer), just burn it to disk as normal, and you should be able to boot into VISTA installation wizard now.

New home

by Jesse 6. May 2009 22:54

Hi all,

I have NEW HOME now!!!!!

This is a big upgrading to my blog system, moving from LAMP+WordPress to Windows+BlogEngine. I am not really a blogging guy, but it should be nice to have a place to let friends know what I am doing and what sort of sh*t I am dealing with. ^_^.  I may migrate my old posts from previous system later, it may take quite a long time as I am really busy (or you can say *lazy*). If you come from GOOGLE, and want to read some OLD posts "RIGHT NOW", leave a comment, I will get that for you.

Be together, Be nice.

Jesse

Tags: , , ,
Categories: Me

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant