There are a couple of different types of expanding foams.
There's the "in the can" Great stuff, it's made for sealing small cracks. It cures using water vapor in the air, so if you try to fill a big weapon all at once, the inside will stay mushy forever. Make sure you do it in small increments. Rinse out the top and the straw with acetone if you want your one-time-use can to turn into a use-until-it's-empty can. This foam will expand to about twice its size (Usually, some types expand more or less, make sure you read the label). It will, after it cures, contract slightly, due to "degassing", which is when the gases made during the curing process escape the cured foam. Spray the FULLY CURED foam with a coat of Latex or acrylic paint (Or any other paint that doesn't dissolve foam) to prevent this from happening. This foam cures stiff, and will break if you bend it.
There are then the fancy shmancy "Part A" and "Part B" foams. These react chemically with one another, and will not leave the center uncured, unless you mix them poorly. They are generally far more expensive, but can work better for large cavities. Some of these will cure stiff like Great Stuff, and others will cure to a flexible "Nerf-ball" feel. The flexible foams are generally more expensive, and should not be used for filling weapons. Again, read the specs of the foam before you buy, so you get what you want.