Thursday, November 8, 2012

The most convincing malicious Message I have ever received

The most convincing malicious Message I have ever received:

I was expecting an airlines ticket from my HR, so I almost fell for it. I consider myself as above average computer user, and I thought I pretty much know all the scams and attacks used in the social media, but this is something new.. I got this message when I was expecting something similar on my office. Although my HR would never send anything to my personal ID, still I would have opened it if I didn't disable "Hide Extensions for known file types" on my PC (I do that on all my PC's)


The message was convincing, and the archive was password protected and sent only to me. How cool is that? Some one is trying to target me specifically... I am so honored..





None of the following were able to detect the virus on the file as of 11/8/12, 5.01 PM CST.

Windows Defender for 8
Norton Security Suite.
Both of the applications happily said “Nothing Found”.



But this is obviously virus:


AS you can see, it is just an exe file with PDF icon.

Wednesday, October 31, 2012

Microsoft's 2013 Office pricing is a Joke!

Before reading this blog, Please see the official pricing from MS:

http://www.microsoft.com/en-us/news/download/presskits/office/docs/PlacematFS.docx


Now, I have a smart phone and a tablet and I should say, I am spoiled by the pricing models of those. 

  1. You pay for the apps only once and you get to use it on multiple devices. 
  2. You don't have to pay for the same app again, when you replace the phone / tablet.
  3. Updates or mostly seamless


I, like millions of other users, was excited to see that MS was going to have a subscription based model for office and it was going to affordable (!). I should say that I was disappointed to see the pricing. $100 / year for 5 user license? What were you guys thinking? Is this your way of making things affordable? We get it, you can't discount the retail version to make sure that the millions of businesses which pays for volume licenses think that they get a good deal. But $100 / year? Really? So, let us take a simple example, I paid $149 for 3 user license in 2007 or something for Office 2K7, I would have paid $500 over 5 years for same stupid piece of software, if I were to subscribe to your "Affordable" subscription based model. BTW, I still can use office 2K7 and it works pretty good. 

These sort of stupid decisions from MS makes me think, do they really listen to their users? I was excited when they announced that Win 8 is going to be $39.99 and bought two copies. I would have done the same if MS Office is priced similarly. We all live in a age where we buy games and apps for our phones/tablets for $0.25  - $15, I don't see why I should pay more for desktop based software? I am not asking for $15 MS office, but a $40/license or $5/month subscription for home users would make more sense. Or MS could have left the $149 price tag on the retail version and just could have just offered the subscription based model for, let's say $5/month. If MS is afraid that users might subscribe when it is needed and cancel it next month, should I remind them that, it IS  the advantage of subscription based model? Consumers win? For eg: I can put Netflix subscription on hold for a month, when I go for a vacation.

Anyway, I have decided to start using LibreOffice, and try to avoid using MS office going forward. When O2K7 is unsupported or if my hardware dies, I will use only LibreOffice. MS - Thanks for reminding me that you don't listen to your customers. You just lost one MS office customer (which is not a big deal as most of your money comes from enterprise customers). 

Cleaning up the old installation after Windows 8 Upgrade


Note: Please make sure that you copy the required files from Windows.old before following the steps mentioned in the article. Once you cleanup the old install, there is no easy way to get the files from there.

If you have upgraded from Windows XP / Vista / 7 to Windows 8 recently, you could be running in to this issue, like me. Unlike the previous version (Win 7), you cannot “Forcibly” delete system files, even if you have logged in as admin. If you try to force delete the files, you might receive this error :





It used to happen to me all the time, after the OS reinstall with Windows 7, but usually I will be able to reset the security permissions for the folder and clear out the ACL’s, but with Windows 8, I am unable to do so. I get below error while trying to reset the permissions. Looks like this is the expected behavior! (or a bug).




I found a simple solution to get rid of this. Tick is to use the good old “Disk Cleanup” tool (For those, who don’t know what it is, this is a  small utility I am using ever since 98 to “Safely” delete the temp files”)

Hit start button (Win key) and start typing “Free up disk space” or “Disk cleanup” and select “Settings”. In that select the option “Free up disk space by deleting unnecessary files”.




In the subsequent menu, click on the button “Cleanup System files” (Of course you need to login as Administrator)




It will be a while until this utility does it’s thing and gather all the required info.



In the subsequent screen, select “Previous Windows installation(s)”




Also, if you don’t require the Windows 8 install files, check that as well.
Click “Delete Files”



Wait till this to complete:



Voila! It’s gone!

Thursday, October 18, 2012

Microsoft Stops support for Windows XP Mode (VM) in Windows 8

Well, I was planning to upgrade to Windows 8 when it arrives on Oct 26 2012, since the $40 price tag was too tempting. I realized I have few legacy apps, which I need to use (Ahem... VB6), So I naturally out of curiosity, I searched the internet to see if the XP Mode is still supported. But long behold, nope. It looks like you can boot to the VM, but the activation would fail. So, That makes me wonder, whoever is paying Microsoft for their "Software Assurance" program (Big corporations) will not be affected by this change. Only home users like me would be affected. As much as I hate to admit it, I think MS is willing to screw their own customers, so that they will get rid of XP. From a technical standpoint, there isn't much they have to do.. All they have to do is to update their validation logic such that XP mode will validate successfully even on Win8, but they are not willing to do that. 

Read more about that announcement here : http://www.microsoft.com/windows/virtual-pc/support/faq.aspx

The forum post where I read this news originally : http://social.technet.microsoft.com/Forums/en/w8itprovirt/thread/a0a8ccd4-6f54-41bc-b679-7ae23ac1e653


Their lame explanation for this, according to the link above? 


"With the end of extended support for Windows XP in April 2014, Microsoft has decided not to develop Windows XP Mode for Windows 8.  If you’re a Windows 7 customer who uses Windows XP Mode and are planning a move to Windows 8, this article may be helpful to you.  

When you upgrade from Windows 7 to Windows 8, Windows XP Mode is installed on your machine, however Windows Virtual PC is not present anymore. This issue occurs because Windows Virtual PC is not supported on Windows 8. To retrieve data from the Windows XP Mode virtual machine, perform the steps listed in the More Information section."

I found this to be amusing an also depressing. But I don't use my XP mode that often, so I am going to use the work laptop for XP related stuff for now, I guess. 

Thursday, October 4, 2012

Limitation of dtexec utility

For the convenience of developers who wants to automate the SSIS loads, Microsoft has bundled a dtexec.exe utility with SQL Server client installation, which you can use in command line (or in scripts) to run a SSIS packages and set values for the variables. All you need to do is, execute the command, 

dtexec /option value

Sounds simple right?? Well in my case it is not. I am having a strange issue with dtexec utility. I am passing the connection string using a variable. For example, I am trying to call the package with the following:

dtexec /set "Package1.ConnectionString;DataSource=localhost;Initial catalog=Dev;Integrated Security=SSPI" Package.dtsx

This doesn't work. As you know, most of the connection strings will have semi colon in it. If I try with this command, it is throwing me out. I can't figure out why this is happening, so I wrote a small .NET client using Microsoft.SQLServer.DTS.Runtime and solved it temporarily. I have posted this question to MS, I will update this when I get back from them.

SSIS - Excel source interpreting the data type incorrectly!

I was having this crazy problem with SSIS today.. Basically I was trying to read out a excel file, which has multiple data types in the same column.. (The problem is neatly described by this blogger :http://microsoft-ssis.blogspot.com/2011/06/mixed-data-types-in-excel-column.html )


Summary of the problem: Excel always tries to "determine" the data type of the column. And in SSIS (As of 2008 R2), there is no way to override it. (Microsoft says that this is Excel's limitation). So, If you add "IMEX=1" in the extended properties, it solves "most" of the issue.

But wait.. If the first 8 rows have numeric data and subsequent rows have string, then this approach fails. So as a workaround, you should modify this registry key : HKLM\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows (For 64 bit, HKLM\SOFTWARE\wow6432node\microsoft\jet\4.0\engines\excel)and change it up to 16. 


Another workaround suggested by MS - (http://support.microsoft.com/kb/281517) Add the rows which has string on top, you will just be fine !!!

Thursday, August 30, 2012

Using .NET / C# to Save and Retrieve files to/from SQL Server

Hi All,

Welcome again.. I always wanted to use SQL Server as a storage area to save the files using .NET. Below is a simple example using Windows forms and SQL Server express. Do let me know what you think in the comments section.

Step 1 Create the tables in SQL Server

I have created a small file with as few columns as possible:


CREATE TABLE [dbo].[Test_FileTable](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [Name] [varchar](max) NULL,
      [Data] [varbinary](max) NULL,
      [Size] [int] NULL,
      [Description] [varchar](max) NULL,
PRIMARY KEY CLUSTERED
(
      [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Step 2 Create the windows project with two forms. In my example, I have used three forms. One as a menu, one for uploading files and other for downloading. Here is the settings file:

xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ConnectionString" value="Data Source=LocalHost\SQLExpress;Initial Catalog=SampleDB;Integrated Security=SSPI"/>
    <add key="InsertQuery" value="Insert into Test_FileTable (Name,Size,Data,Description)  values(@strName,@intSize,@binData,@strDescription)"/>
    <add key="SelectQuery" value="Select ID,Name as FileName,Size,Description from Test_FileTable"/>
    <add key="DataQuery" value="Select Data from Test_FileTable where ID=@i_ID"/>
    <add key="FileNameQuery" value="Select Name as FileName from Test_FileTable where ID=@i_ID" />
    <add key="TableName" value="Test_FileTable"/>
    <add key="TempPath" value="D:\Temp\"/>
  </appSettings>
</configuration>



Step 3 :  Do the actual code for saving/retrieving the files.

Saving to DB:

private static void UploadFile(string FilePath, string FileDescription)
{
    SqlConnection oConn ;
    SqlCommand oCmd;
    string ConnectionString,CommandString;
    byte[] BytBuffer;
    try
    {
        if (File.Exists(FilePath))
        {
            ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();
            CommandString = System.Configuration.ConfigurationManager.AppSettings["InsertQuery"].ToString();
            oConn = new SqlConnection(ConnectionString);
            oConn.Open();
            /* Parameters(@strName,@intSize,@binData,@strDescription)
                *
                */
            oCmd = new SqlCommand(CommandString, oConn);
            oCmd.CommandText = CommandString;
            oCmd.CommandType = System.Data.CommandType.Text;
            oCmd.Parameters.Add("@strName", System.Data.SqlDbType.VarChar );
            oCmd.Parameters.Add("@intSize", System.Data.SqlDbType.Int);
            oCmd.Parameters.Add("@binData", System.Data.SqlDbType.VarBinary);
            oCmd.Parameters.Add("@strDescription", System.Data.SqlDbType.VarChar);
                   

            oCmd.Parameters["@strName"].Value = FilePath.Substring(FilePath.LastIndexOf(@"\")+1);
            BytBuffer = File.ReadAllBytes(FilePath);
            oCmd.Parameters["@intSize"].Value = BytBuffer.Length;
            oCmd.Parameters["@binData"].Value = BytBuffer;
            oCmd.Parameters["@strDescription"].Value = FileDescription;

            oCmd.ExecuteNonQuery();

            MessageBox.Show("File uploaded to DB", "Sucess!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        /*
        * Warning: This code might fail if you attempt to store
 * very large files in to the database.
        * For that, just modify the buffer variable such that it reads a
 * block of approx. few megabytes
        * from the database at once.
        * On Most modern computers, this code should work just fine
        */
        }
    }
    catch (Exception ex)
    {
        System.Console.WriteLine(ex.Message);
    }
}




Retrieving from DB:

private byte[] GetFileFromDB(int id)
{
    byte[] Return = null;
    SqlConnection oConn;
    SqlCommand oCMD;

    DataTable oDT;

    try {

        oConn = new SqlConnection();
        //Get the connection string from DB
        oConn.ConnectionString =
System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();
        oConn.Open();
        oCMD = new SqlCommand();
        oCMD.Connection = oConn;
        oCMD.CommandType = System.Data.CommandType.Text;
        oCMD.CommandText = System.Configuration.ConfigurationManager.AppSettings["DataQuery"].ToString();//
        oCMD.Parameters.Add(new SqlParameter("@i_ID", id));


        //I have structured this query such that you it will just return the file data
        oDT = new DataTable();
        Return = (byte[]) oCMD.ExecuteScalar();

        /*
        * Warning: This code might fail if you attempt to store
 * very large files in to the database.
        * For that, just modify the buffer variable such that it reads a
 * block of approx. few megabytes
        * from the database at once.
        * On Most modern computers, this code should work just fine
        */
           
    }
    catch (Exception ex)
    {
        System.Console.WriteLine(ex.Message);
    }

    return Return;
}


Screen shots:

Menu Form:

 




Uploading a file:
Downloading a file:




Tuesday, August 28, 2012

C# Code to change the encoding of a text file to the desired encoding

Note: I started writing this blog a few months ago, and forgot to publish this. Anyway, better late than never, enjoy.

This code lets you convert multiple files in a directory to the desired encoding. The reason for this utility is the source control which is being used by my client doesn't support anything other than ASCII (7 bit). This function I have below should be sufficient for the most needs, but I have shared the entire code as well.

Function to change the encoding:


        private static void ChangeEncoding(string FolderPath, string TargetEncoding)
        {
            try
            {
                DirectoryInfo info = new DirectoryInfo(FolderPath);
                FileInfo[] Fi = info.GetFiles();
                StreamWriter swriter;
                StreamReader sreader;
                string FileName;
                foreach (FileInfo obj in Fi)
                {
                    FileName = obj.FullName;
                    File.SetAttributes(FileName, FileAttributes.Normal);
                    File.Move(FileName, FileName + ".proback");
                    sreader = new StreamReader(FileName + ".proback");
                    if (TargetEncoding.Equals("BigEndianUnicode"))
                    {

                        swriter = new
StreamWriter(FileName, false, Encoding.BigEndianUnicode);
                    }
                    else if (TargetEncoding.Equals("Unicode"))
                    {
                        swriter = new StreamWriter(FileName, false, Encoding.Unicode);
                    }
                    else if (TargetEncoding.Equals("UTF32"))
                    {
                        swriter = new StreamWriter(FileName, false, Encoding.UTF32);
                    }
                    else if (TargetEncoding.Equals("UTF7"))
                    {
                        swriter = new StreamWriter(FileName, false, Encoding.UTF7);
                    }
                    else if (TargetEncoding.Equals("UTF8"))
                    {
                        swriter = new StreamWriter(FileName, false, Encoding.UTF8);
                    }
                    else if (TargetEncoding.Equals("ASCII"))
                    {
                        swriter = new StreamWriter(FileName, false, Encoding.ASCII);
                    }
                    else
                    {
                        swriter = new StreamWriter(FileName, false, Encoding.Default);
                    }

                    while (!sreader.EndOfStream)
                    {
                        swriter.WriteLine(sreader.ReadLine());
                    }

                    sreader.Close();
                    swriter.Close();
                    sreader.Dispose();
                    swriter.Dispose();
                    File.Delete(FileName + ".proback");
                   
                }
            }
            catch (Exception ex)
            {
                throw ex;  
            }
        }


 Downloads:  


Note: You need .NET framework 4

Complete Source - https://docs.google.com/open?id=0B1z9Rc2ld5VPSExPSE9sUEh1SkE


(Once the link opens, press Ctrl+S to download)

Monday, August 27, 2012

"Ferb" Latin encoder :) [In .NET/C#]

In the previous post, I had mentioned about the "Pig" latin, which offers some sort of "Perceived" privacy. This morning when I was watching Phineas and Ferb, they invent a new language called "Ferb" latin, so I thought since very less people know about that, we can very well use those rules instead. Here is the program to encode:


public static string GetFerbLatinFromText(string strText)
{
    string strRetVal = string.Empty;
    int i, j;
    try
    {

        StringBuilder sb = new StringBuilder();
        char[] chrLetters;
        string[] strWord = strText.Split(' ', '\n');

        for (i = 0; i < strWord.Length; i++)
        {
            chrLetters = strWord[i].ToCharArray();
            if (chrLetters.Length > 2)
            {

                for (j = 1; j < chrLetters.Length; j++)
                {
                    sb.Append(Char.ToLower(chrLetters[j]));
                }

                sb.Append(Char.ToLower(chrLetters[0]));
                sb.Append("erb ");

            }
            else
            {
                sb.Append(strWord[i]);
                sb.Append(" ");
            }
        }

        strRetVal = sb.ToString();
    }
    catch (Exception exp)
    {
        throw exp;
    }

    return strRetVal;
}


Code to decode the text :

public static string GetTextFromFerbLatin(string strText)
{
    string strRetVal = string.Empty;
    int i, j;
    try
    {
        StringBuilder sb = new StringBuilder();
        char[] chrLetters;
        string[] strWord = strText.Split(' ', '\n');

        for (i = 0; i < strWord.Length; i++)
        {
            chrLetters = strWord[i].ToCharArray();
            if (chrLetters.Length > 2)
            {

                if(chrLetters.Length >4)
                    sb.Append(Char.ToLower(chrLetters[chrLetters.Length - 4]));

                for (j = 0; j < chrLetters.Length-4; j++)
                {
                    sb.Append(Char.ToLower(chrLetters[j]));
                }

                sb.Append(' ');

            }
            else
            {
                sb.Append(strWord[i]);
                sb.Append(" ");
            }
        }

        strRetVal = sb.ToString();
    }
    catch (Exception exp)
    {
        throw exp;
    }

    return strRetVal;
}


Source code for this program can be downloaded from here : Link

Executable can be found here : Link