In Drupal 6 the variable creation logic lives in the /includes/theme.inc file.
The functions of note, located at the bottom of the file, are:
* template_preprocess
* template_preprocess_page
* template_preprocess_node
* template_preprocess_block
These preprocessor functions can be used for altering variables in their areas.
By browsing the function definitions you'll see how the variables are created.