Extracting Reward Functions from Diffusion Models