united-states
It's legal to take an attacker's gun, and use it in self-defense, until you reach the police.
The legality of using a gun in self-defense is not dependent on whether you're allowed to carry a gun, or this particular gun, in peaceful circumstances. Holding the firearm against the immediate threat (Bob) would fall under temporary lawful possession, or innocent possession defense.
[a] person has innocent possession of a weapon when [that person] comes into possession of the weapon in an excusable manner and maintains possession, or intends to maintain possession, of the weapon only long enough to dispose of it
safely (CJI2d[NY] Temporary and Lawful Possession).
Discharging the firearm in public is allowed for self-defense (typical statute), so no offense there. Assaulting the attacker to take the gun is also covered under self-defense.
Other criminal actions required for legal self-defense, but not covered by self-defense, would generally be covered under the necessity defense.For instance, destruction of property - breaking the assailant's gun, or damaging property while firing it in self-defense - would be protected by necessity.
Holding on to the gun to use it in self-defense some other day would be illegal possession. If you find yourself in a situation of predictable danger, your expected actions are to reach safety as soon as possible. Basically, you're allowed to keep the gun until police arrives, or on your way to the police.
Ultimately, whether the weapon is found fortuitously or obtained by disarming an attacker, the underlying purpose of the charge is to foster a civic duty on
the part of citizens to surrender dangerous weapons to the police.