We model the cratering of the Moon and terrestrial planets from the present knowledge of the orbital and size distribution of asteroids and comets in the inner Solar System, in order to refine the crater chronology method. Impact occurrences, locations, velocities and incidence angles are calculated semi-analytically, and scaling laws are used to convert impactor sizes into crater sizes. Our approach is generalizable to other moons or planets. The lunar cratering rate varies with both latitude and longitude: with respect to the global average, it is about 25% lower at (±65°N, 90°E) and larger by the same amount at the apex of motion (0°N, 90°W) for the present Earth-Moon separation. The measured size-frequency distributions of lunar craters are reconciled with the observed population of near-Earth objects under the assumption that craters smaller than a few kilometers in diameter form in a porous megaregolith. Varying depths of this megaregolith between the mare and highlands is a plausible partial explanation for differences in previously reported measured size-frequency distributions. We give a revised analytical relationship between the number of craters and the age of a lunar surface. For the inner planets, expected size-frequency crater distributions are calculated that account for differences in impact conditions, and the age of a few key geologic units is given. We estimate the Orientale and Caloris basins to be 3.73 Ga old, and the surface of Venus to be 240 Ma old. The terrestrial cratering record is consistent with the revised chronology and a constant impact rate over the last 400 Ma. Better knowledge of the orbital dynamics, crater scaling laws and megaregolith properties are needed to confidently assess the net uncertainty of the model ages that result from the combination of numerous steps, from the observation of asteroids to the formation of craters. Our model may be inaccurate for periods prior to 3.5 Ga because of a different impactor population, or for craters smaller than a few kilometers on Mars and Mercury, due to the presence of subsurface ice and to the abundance of large secondaries, respectively. Standard parameter values allow for the first time to naturally reproduce both the size distribution and absolute number of lunar craters up to 3.5 Ga ago, and give self-consistent estimates of the planetary cratering rates relative to the Moon.