With a 2 pin plug, and no other assumptions, no.
If you had a three pin plug, so a ground reference, then you could have some active electronics in your box labelled '?', that detected which conductor was at roughly ground potential, and which had a large voltage difference, and swapped the conductors over accordingly.
The simplest concept to imagine would be a mains operated DPDT relay, energised between N and E. If N was in fact L, then it would operate, and switch the poles over. This dumping of a few mA into the ground conductor would probably be frowned on, if not outright forbidden, by most electrical authorities, and could trip a GFI if there was one on the system, so is not a practical solution, only conceptual.
With some electronics, you could do the job properly, detecting which incoming cable had the larger swing with respect to the incoming ground.
If you had only a 2 pin plug, you may still be able to get a reasonable ground reference using a large electrode in fresh air. Its capacitance to ground would mean that usually, the detected potential (using a high impedance sensor) would be less to the actual N lead than the actual L lead coming in. However, this could be fooled if there were strong electric fields around, so is less reliable than using a ground connector.
If it really matters to you which conductor is L and which N, then that probably means you have a ground reference available. Without any sort of ground, which is N and which L is not meaningful.
You can assume that any equipment fitted with a reversible 2 pin plug does not care which pole is which. It will be safe by having 'double insulated' components, requiring at least 2 faults before any shock hazzard is created. Any 'unsafe with a single insulation fault' equipment must have a safety ground connection.