I've said it before - there is no self defense against a gun.
But in the unlikely event that you are close enough, you might be able to get your finger between the hammer and the firing pin. It's tricky though.
If there aren't too many people around and ideally if you're not close to hard surfaces that may cause a ricochet, you could focus all your effort on the gun, take the blows and just use all your strength to point it somewhere safe and pull the trigger until all the rounds are spent.
Finding the magazine release catch would also be really hard.
If a gun is pointed at you, you'd better do what they say. If you're going to get a bullet anyway, then in my opinion the best solution is to try to fire all the bullets somewhere else.