• My Predictions for Apple’s Tablet Event Tomorrow

    Update: I have created a new blog post (Jan 27th, 2010) for my response to what happened and the outcome of each of my predictions.

    Unless you’ve been living under a rock, you are no doubt aware that Apple plans to reveal their “latest creation” tomorrow, January 27th, 2009. It is most likely their long awaited iTablet/iSlate/iWhatever. I’ll be following Engadget’s live blog of the event tomorrow.

    It is also my birthday tomorrow, but I don’t care as much about that. I just want to know what Apple’s been doing all this time and what they’re going to announce. I’m pretty sure that makes me nerdy, among other qualifications.

    These are my tablet related predictions, which I will update with the results:Concept mockup, courtesy of Engadget

    1. Apple will announce a tablet device of some kind.
    2. It’s name will begin with a lower case I. I have to get at least one correct, right? I’ll guess iTablet. I don’t think they’ll do iSlate.
    3. The device will not have an e-ink screen.
    4. The device will not have an AMOLED screen.
    5. It will be a conventional LCD screen with LED backlighting.
    6. It will not run full OS X. Only a subset will be allowed, such as Safari, etc. Only apps from an app store will be allowed.
    7. There will be a tablet app store.
    8. There will be backwards compatibility for iPhone apps running in some kind of emulation mode.
    9. There will be a innovative text input method. I can’t speculate as to what it will be, but knowing Apple, it will be good.
    10. Its battery life will be expressed in hours, not days or weeks, unlike the Kindle or Nook.
    11. Verizon will be announced as a 3G data partner for the tablet device.
    12. The tablet will sell like hotcakes at first because Apple made it, but I think this will be a fad device and perhaps regarded as Apple’s second flop (see Newton). I am putting this down “on paper” because I think it will be funny if I’m completely wrong and I can read my own words in a year or so.

    My other predictions for the event are as follows, which I will also update with results:

    1. No new iPhone will be announced.
    2. No AT&T exclusivity related announcements will be made (this will be saved until WWDC in June).
    3. Incremental changes will be made for the iPhone OS, perhaps allowing some sort of rudimentary multitasking, perhaps in a 3.5 or 4.0 revision of the OS.

    Additionally, I am aware that I haven’t blogged in 5 months. I’ll be following up on this post with some sort of recap explaining what I’ve been doing.


  • Beyonc□, or How We Can All Learn From Other Developers’ Character Encoding Mistakes

    Picture of Unicode Error, displaying Beyoncé as Beyonc-block

    I’m sure everyone who reads this blog has noticed, at some point, the result of another developer’s mistake in dealing with Unicode or other character encodings. I’ve had a few issues myself. To the left, you can see how my Napster displayed a Beyoncé song as Beyonc□. You may have seen a black diamond symbol with a question mark in it while browsing a web page, or perhaps other strange symbols when interacting with programs or web pages.

    Most, if not all of these, are inconsistencies when dealing with character encoding, with most of them being Unicode. Hazarding a guess, Beyoncé’s is likely stored as Unicode (UTF-16) in Napster’s database, but when output on the screen, it is converted down to UTF-8 or ASCII. Either way, it can’t be converted down, so an entity is displayed. There is even a shirt memorializing the problem in T-shirt form:

    I {entity} Unicode T-shirt

    My issues have been even more low-level than this. I deal with a lot of interaction using EDI with older computer systems running UNIX or or some IBM mainframe OS. None of these are using Unicode for their medical claims adjudication, and are either using ASCII or EBCDIC. Yes, EBCDIC; I have to program using EBCDIC in 2009.

    I have to be very careful when I’m converting to and from Unicode, the native format of the string class in .Net, and other character encodings such as ASCII and EBCDIC, and so should you.



  • Hacked by Chinese

    On our main product, in a branch on which I’m working on a Point of Sale product, something happened in the process of checking files into source control. In our case, we’re using Team Foundation Server. My guess is that the corruption happened on my hard drive for who knows what reason, but this is the beginning of the resulting solution file that ended up in TFS: a bunch of Chinese-looking characters instead of a project name.

    Microsoft Visual Studio Solution File, Format Version 10.00
    # Visual Studio 2008
    Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "펐!蝀ጢ", "ProductNameFaxServiceSetup\ProductNameFaxServiceSetup.vdproj", "{DDA7A291-A5F6-4FEA-B11E-BBE90848167D}"
    EndProject
    Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyName.Claim.Common", "CompanyName.Claim.Common\CompanyName.Claim.Common.csproj", "{11EE0005-87E4-44E0-806A-0BCB382468F0}"
    EndProject
    Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyName.Claim.Modem", "CompanyName.Claim.Modem\CompanyName.Claim.Modem.csproj", "{FE62F256-5A9C-4212-8EFB-CCD0AC0D59AF}"
    EndProject

    It took a while to track down, because it manifested itself as missing projects, missing dependencies. I kept adding back things one at a time and then ending up with two more dependencies left to add. Finally, I just looked at the raw solution file and saw how it was messed up. I went back to find a file in the source control history that wasn’t messed up, got that specific version by change set, and then added the specific projects that had been added since then back to the solution.

    Thanks to source control, I was back up and running in no time.

    The title is from the phrase with which the Code Red worm defaced web sites it infected. We didn’t really get hacked by the Chinese.


  • Accessing a Control Without Being Able to See It on a Windows Form

    Menu Key Displayed on KeyboardA coworker of mine had a problem and came to me for help. She had a windows form with a control on it that she wanted to edit or delete, but couldn’t see the control. It was listed in the properties box in the list of controls on the form, but when she selected it, she wasn’t able to click it on the form, because it was behind another control.

    I hypothesized a solution, which worked, but requires the use of a less than frequent key on your keyboard, the menu key. Usually this key is two keys to the right of the space bar on windows keyboards, between Alt and Control. A picture of it is on the right.

    Note: As pointed out by Lee, in the comments, you can press Shift + F10 if your keyboard doesn’t contain the Menu Key.

    The Form With a Hidden Label Behind the Filename TextBox) Form with hidden label control

    Properties Window Listing the Hidden Control, HiddenLabel

    Properties window list of controls

    Select the control that you can’t see. It will be highlighted on the form.

    Form with Hidden Control Highlighted

    Label highlighted after selecting from properties windowThe hidden control becomes highlighted. Click into the title bar of the form. Press the menu key on your keyboard to display the context menu.

    Context Menu Being Displayed After Pressing the Menu Key

    bringtofrontSelect “Bring to Front” to display the control. It will now be visible and can be edited or removed.

    Hidden Control Moved

    Label after being brought to front and movedAs you can see, the control that was previously hidden is now visible and has been moved.

    I know this is a basic solution to an easy problem, but I had to figure it out, and I hope that someone searching may find this useful as well. The above example was a new form I was starting; it is not the actual application in question.


  • Using Reflection to Dynamically Generate ToString() Output

    Update: Added code to show “null” when a property is null, like Visual Studio does.

    If you’ve ever used Visual Studio in any iteration in any language, you have most likely used the immediate window. It’s insanely useful and lets you just type an instance of an object and if the object doesn’t have an overridden ToString() method (I’m back in C#/.Net world here for the purposes of this post), Visual Studio will dynamically generate output for you, so that you can see the current state of the object.

    Here is what Visual Studio’s output looks like on an object I have:

    {CompanyName.CreditCard.Processor.CreditDebit.SaleResponse}
        base {CompanyName.CreditCard.Processor.Response}: {CompanyName.CreditCard.Processor.CreditDebit.SaleResponse}
        AddressVerificationSuccess: true
        AuthorizationCode: null
        AuthorizedAmount: 50
        CvvSuccess: false
        ReferenceNumber: null

    However, what if you want to be able to have ToString() generate this type of output for you, for the purposes of debugging, like using with Debug.WriteLine or Trace or any other logging framework? It is useful to be able to see later what the state of an object was during a problem situation. Sure, you can write your own ToString() code in every object to generate its state in string form, and then aggregate all the base objects using base.ToString(), but that is a lot of iterative, repetitious coding.

    My classes are simple data transfer objects and look like this:

    public class SaleResponse : Response
    {
        public virtual bool AddressVerificationSuccess { get; set; }
        public virtual bool CvvSuccess { get; set; }
        public virtual string AuthorizationCode { get; set; }
        public virtual string ReferenceNumber { get; set; }
        public virtual decimal? AuthorizedAmount { get; set; }
    }
    
    public class Response
    {
        public virtual bool Success { get; set; }
        public virtual string ResponseMessage { get; set; }
        public virtual string TransactionID { get; set; }
        public virtual string GatewayResponseCodeText { get; set; }
        public virtual string IssuerResponseCodeText { get; set; }
        public virtual GatewayResponseCode GatewayResponseCode { get; set; }
        public virtual IssuerResponseCode IssuerResponseCode { get; set; }
    }

    As you can see, Visual Studio didn’t even give me the contents of the base class, but I want this information. My ToString() method I’ve created in the SaleResponse object is the following:

    public override string ToString()
    {
        var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy;
        System.Reflection.PropertyInfo[] infos = this.GetType().GetProperties(flags);
    
        StringBuilder sb = new StringBuilder();
    
        string typeName = this.GetType().Name;
        sb.AppendLine(typeName);
        sb.AppendLine(string.Empty.PadRight(typeName.Length + 5, '='));
    
        foreach (var info in infos)
        {
            object value = info.GetValue(this, null);
            sb.AppendFormat("{0}: {1}{2}", info.Name, value != null ? value : "null", Environment.NewLine);
        }
    
        return sb.ToString();
    }

    Which generates the following output:

    SaleResponse
    =================
    AddressVerificationSuccess: True
    CvvSuccess: False
    AuthorizationCode: null
    ReferenceNumber: null
    AuthorizedAmount: 50
    Success: True
    ResponseMessage: null
    TransactionID: AXB234234
    GatewayResponseCodeText: null
    IssuerResponseCodeText: null
    GatewayResponseCode: ExpiredDevice
    IssuerResponseCode: Error

    What I like about this approach is that it grabs all the base object’s properties recursively. Obviously, there are performance concerns with doing reflection, so I wouldn’t use this constantly, but I think it’s a good way to write out the state of an object in the event of an error. Also, I made the example simple for this blog post, but obviously, you could put that code into an extension method for System.Object or just into a static utility class, adding an object parameter and replacing “this” with the name of the object parameter.


  • Buy My House!

    My house is finally listed and on the market (as MLS #: N114783)! It’s been repainted, the yard has been mowed, and Amanda and I worked really hard to get the house ready to sell by cleaning everything inside. I am using Robin Ramsey of the Chris Hayes Team to sell the house, and so far I’m very satisfied with their work. This is a very important piece of my continuing quest to get out of Shreveport and move to Dallas.

    You have to search to see the listing on the Chris Hayes Team site, so I’ve linked to the data for the house on realtor.com. However, the pictures and captions Robin posted are linkable through their site.

    Here are the pictures and descriptions Robin wrote:

    Exterior Front: Character Galore! Privacy wall in the front that adds protection from the setting sun in the evenings. Nicely manicured yard and landscaping. This home sits on a very quiet street with unbelievable neighbors.

    There are more pictures and descriptions after the jump.

    (more…)


  • Strong Name an Assembly Without Source Code

    Because I program in the 1970’s, part of what I do is programming against modems and serial ports. Specifically, we send medical claims over modem to adjudicators, in the event of unavailable internet access. As a customer, you’ll appreciate having your pharmacy delay you for 20 seconds rather than saying “Sorry; you can’t have your medicine.”

    While taking a break from disco dancing, I was trying to add a strong name to one of our projects. One of the requirements, however, for strong naming is that all of the assemblies you reference must be strong named as well. All are, except one: COMM-DRV/Lib.Net. We use this assembly to talk to the modems, because it abstracts a lot of the serial communications and allows us to program against a logical “modem”.

    I called the vendor, Willies Computer Software Company, and he said that we’d have to have the source license to strong name, but I asked why they don’t strong name their own binary distribution. He just kept saying they don’t do that, and we’d have to buy the source license. We didn’t need to make changes to their code, though; in fact, I already did that by inheriting their class and hiding some methods with new ones.

    So, I set about trying to find out how to strong name an assembly for which you do not have the source. The short answer is “you can’t.” The longer answer is “You can’t, unless you disassemble it, reassemble it, while signing at the same time, and only if it’s not obfuscated.” I finally found the answer I was looking for at geekzilla.

    Here are the steps you need (back up your old assembly):

    Create a Key Pair

    This is only necessary, of course, if you don’t already have one generated for yourself or your company.

    sn.exe -k C:\Path\To\KeyPair.snk

    Disassemble the Assembly into IL

    ildasm.exe CdrvLibNet.dll /out:CdrvLibNet.il

    Reassemble the Assembly from IL While Signing

    ilasm.exe CdrvLibNet.il /dll /output=CdrvLibNet-StrongNamed.dll /key=C:\Path\To\KeyPair.snk

    The Result

    Thankfully, everything worked great, because their assembly was not obfuscated (it’s basically a .Net wrapper around their C++ unmanaged, native DLL product, so no real intellectual property to steal here). Now, we have their product strong named with our public key, and we are able to build on top of it with a strong named product of our own.


  • How Insensitive

    Update: Added section at the bottom detailing what not to do.

    As part of the updater process that I wrote for a current project, a “boot strapper” program queries the database for available versions, and if there is a newer version available, it deletes the current program folder, replaces those files with the new files, and then executes the main program executable. If there are no newer versions, it simply executes the main program executable immediately. This gives the user they are executing the program itself, instead of the “invisible” boot strapper, but we are able to easily manage updates in this manner.

    Obviously, if you are a .Net developer, you know about the venerable app.config, which is used to set program parameters at run-time, rather than at design time. Because these can contain changes to our connection strings and custom configuration sections, we wanted to preserve this and other special files that may be used in the future. As our solution, we created a whitelist of files that we do want to replace, that looked like this:

            ///
            /// Extensions of files that may be deleted during uninstall/reinstall.
            ///
            private List _deletableExtensions = new List(
                new string[] { ".exe", ".dll", ".pdb", ".chm", ".manifest" });
    
            private bool canDeleteOrOverwrite(FileInfo file)
            {
                // Only delete files with specific extensions.
                bool canDelete = _deletableExtensions.Contains(file.Extension);
    
                return canDelete;
            }

    Before anybody murders me, we camel case private methods and underscore prefix and camel case private class-level variables here. As you can see, this will allow deletion of executables, class libraries, debug symbols, help files, and manifests. However, we had a problem in my code that didn’t surface until yesterday. We were trying to figure out why one file out of all the files in the directory was remaining an older version, “ActiveReports3.DLL”.

    What may be obvious to the reader, especially considering the title of this post, is that my List<T>.Contains() check, by default, is case sensitive, and “.DLL” != “.dll”. This required quite a bit of stepping through code to find, as I wrote this code a long time ago. A simple press of “Ctrl+Shift+Space” revealed that there was an overload of IEnumerable<T>.Contains(T item, IEqualityComparer<T> comparer).

    Because I’ve had to do this in the past, I knew that, because my T in this case was string, all I needed to do was use the StringComparer, which implements the IEqualityComparer<string> interface. Because it is filenames, and we are working with Visual Studio generated files, we care neither about culture nor case in this instance. Here is the revised, working version:

            ///
            /// Extensions of files that may be deleted during uninstall/reinstall.
            ///
            private List _deletableExtensions = new List(
                new string[] { ".exe", ".dll", ".pdb", ".chm", ".manifest" });
    
            private bool canDeleteOrOverwrite(FileInfo file)
            {
                // Only delete files with specific extensions.
                bool canDelete = _deletableExtensions.Contains(
                    file.Extension,
                    StringComparer.InvariantCultureIgnoreCase);
    
                return canDelete;
            }

    That’s it! That tiny change fixed our issue and allowed the boot strapper to overwrite that file. It’s amazing that a simple little omission like that can lead to such a strange problem manifesting itself. Everybody makes mistakes; I just thought I’d showcase one of my errors and how I fixed it.

    After talking to one of my coworkers about this post, he mentioned something that we have both seen done to “work around” this particular problem, which should not be done. This is what I have seen before in others’ code:

            ///
            /// Extensions of files that may be deleted during uninstall/reinstall.
            ///
            private List _deletableExtensions = new List(
                new string[] { ".exe", ".dll", ".pdb", ".chm", ".manifest" });
    
            private bool canDeleteOrOverwrite(FileInfo file)
            {
                bool canDelete = false;
    
                // Only delete files with specific extensions.
                foreach (string currentExtension in _deletableExtensions)
                {
                    if (currentExtesion.ToLower() == file.Extension.ToLower())
                    {
                        canDelete = true;
                        break;
                    }
                }
    
                return canDelete;
            }

    This creates a LOT of strings on the heap in the process is and is very inefficient. It’s much better to let .Net handle itself and just let it know whether you care about culture and/or case sensitivity.


  • Happy 123456789 Day!

    123456789!Happy 123456789 day! It just passed 12:34:56 7/8/9 right now in the United States (central time zone)!

    Hooray for arbitrary dates, but at least that one won’t happen like that for a while. For our friends almost everywhere else in the world, you have August 7th to look forward to for your 123456789 day.


  • Kindly Remove My Rootkit

    Rootkit Activity DetectedIt would seem that even being a somewhat responsible computer user can’t stop you from getting a rootkit. Last Night, my computer, using nzbtv and Newzbin, downloaded from USENET, for my girlfriend, what it believed to be True Blood the latest episode of a publicly released television show from its rightful copyright holder. When sabnzbd was done extracting it, I was left with a .exe and a bunch of RAR files. It appeared to be a self-extracting archive that WinRAR created, but I was suspicious. So, like any good little boy would do before running files from an untrusted medium, I scanned the file with AVG.

    AVG detected no viruses or suspicious behavior at all, so I took that as a bill of good health… my mistake. The file did actually extract a video, which was the previous week’s episode. I thought everything was still fine, but a few seconds later, AVG Resident Shield started popping up saying all kinds of files that start with hjgrui*.dll were infected in my C:\Windows\System32 directory. I went back to the post on Newzbin and sure enough it was then tagged SPAM/VIRUS with all kinds of comments on it; I wish I had checked the community’s reaction first. Apparently Nod32 was detecting the virus for its lucky users. Another user said he fell into the same trap as me and “should have known better,” but that he got rid of it with ComboFix.

    I ran ComboFix in safe mode and it popped up the dialog you see here in the post (click to make it larger). The title of this post comes from the sentence in the dialog that reads: “Kindly note down on paper, the name of each file.” Grammatically incorrect sentences that sound like little old ladies wrote them crack me up when juxtaposed with a rootkit detection warning. ComboFix was able to completely remove the infection and AVG Resident Shield no longer shows any traces, but it makes me uncomfortable running a previously compromised machine. I’m going to upgrade to Windows 7 as soon as it’s released and do a clean install.

    I’m not sure what the dolts who make and post this kind of crap get out of it, unless it’s some sick version of computer schadenfreude, but my guess is that its to make computers into botnets for attacks/spam, something of which I’d like no part. This just goes to show, even an experienced software developer is capable of accidentally installing a rootkit trojan, so never be complacent and never let down your guard when dealing with untrusted sources. When in question, just don’t run it, even if it promises to be something you want. Do as I say, not as I’ve done.


Posts navigation