Laws vary greatly from country. And we should be aware of regulations and laws before you go abroad. What may be a minor infraction in your own country could land you in jail or even facing the death penalty in a foreign jurisdiction. But, what if by certain circumstances, we are subjected for imprisonment, what would be the best to do?
Well, contact the embassy of your country of residence / citizenship. Mind you, they can't do anything for you, but it's important that someone knows where you are.
Well, even as minor infraction, it still means someone has broken the law somewhat. So the rule is simple - don't engage in any of those activities. Period. Embassies may help in giving advises and stuff, but they will not act to sort out your legal mess for you. They can try to contact a solicitor on your behalf but after that, you're pretty much on your own.
Unless of course, the case has political implications.