This sample code illustrates how to compute the effective balance of a Bitcoin wallet. As explained in a blog post, the balance of a public address as returned via online APIs such as blockchain.info, does not necessarily reflect the effective balance visible in the Bitcoin Core wallet.
This code parses the wallet.dat file to extract all the keys from the key pools and uses the the public blockchain.info to compute the balance of a wallet.