Let's talk about rocks. The art and science of getting useful things from rocks is one of the oldest in human civilization. All of the example products you mention (gunpowder, petroleum, silica, and iron) were discovered or developed from experimentation on rocks.
In the ancient world, composition was determined by qualitative analysis, or a series of chemical tests and determination of important physical properties. For example, if a lump of shiny yellow stuff was soft, melted easily, did not lose its lustre in air or water, did not dissolve in vitriol (sulfuric acid) or aqua fortis (nitric acid), but did dissolve in aqua regia (made then by dissolving sal ammoniac (ammonium chloride) in aqua fortis), then we probably have gold.
In the modern age, the field of analytical chemistry was developed to answer the very questions you asked: What is this stuff? What are its constituents? How can we separate them? How do we determine that we successfully separated/purified them?
To continue the rock example, the modern technique of x-ray fluorescence is used to determine the elemental compositions of rocks (and other things, like ceramic fragments found at archaeological sites). In this technique, high frequency x-rays are used to excite the core electrons in the atoms of the sample. When these core electrons relax, they spit out x-rays of characteristic frequency/wavelength that is specific to the element. These emitted x-rays are collectively measured and converted into a spectrum like the one below.
This spectrum indicates that many elements will have more than one spectral line because there is more than one electronic transition that is possible. It also demonstrates the clear resolution of one element from another. After some maths (and better yet a calibration), you can use the heights of these peaks to determine the specific ratios of elements in your sample.
Not everyone is ignorant of the utility of natural objects. Most of us who become scientists do so to study the natural world and learn from it. For example, organic and medicinal chemists do not design new drug molecules from scratch. Rather, they take cues from nature. A folk legend about the curative properties of the leaves of a plant that grows along the riverside might turn in to an effort to extract and analyze the phytochemicals in those leaves, including throwing those compounds at bacteria, viruses, cancer, etc. Any that look promising are studied further. Taxol (paclitaxel) is a successful chemotherapeutic agent that was isolated from the bark of the pacific yew. It is now mass-produced by a semi-synthetic pathway which isolates a late-stage precursor from the needles of the European yew.
If you are specifically interested in rocks, then you should study geoscience.