Same code as above,  same comments as above :) Please first do auto detection, then proceed with exploitation. And use metadata for addresses as asked. Thanks!

Don't hesitate to ask for example if needed.