\documentclass{article}
\usepackage{luacode}
\usepackage[pdfencoding=unicode]{hyperref}
\begin{luacode}
function getcharactercode ()
local t=token.get_next()
tex.print(t.mode)
end
\end{luacode}
\makeatletter
\def\HyPsd@Char#1{%
\ifnum\directlua{getcharactercode ()}#1<128 %
\@backslashchar 000\Uchar\directlua{getcharactercode ()}#1%
\else
\ifnum\directlua{getcharactercode ()}#1<65536 %
\expandafter\HyPsd@CharTwoByte\directlua{getcharactercode ()}#1!%
\else