More reliable method to get library length

Inspirated from CHooker