1. Be 100% sure that it has got stuck. Else dont try this,
2. If you are sure that it has got stuck, then disconnect phone from PC. Then take out and put the battery. As soon as you do that, you will see that a message saying something about firmware upgarde error and will ask you to go to recovery mode in kies, and it will flash automatically. This situation is called emergency mode.
3. Now hold Volume Down + Home + Power Button for 10-15 seconds, and you will be in regular download mode.
4. Now follow the general firmware flashing steps you were following earlier, and it should do the job this time.
In my case, I was using Samsung Galaxy Star GT-S5282. This method should work for any android based Samsung phones.