You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Theodosius/doxygen/latex/df/db4/classtheo_1_1decomp_1_1rout...

251 lines
16 KiB

\hypertarget{classtheo_1_1decomp_1_1routine__t}{}\doxysection{theo\+::decomp\+::routine\+\_\+t Class Reference}
\label{classtheo_1_1decomp_1_1routine__t}\index{theo::decomp::routine\_t@{theo::decomp::routine\_t}}
the routine class which is responsible for creating symbols for routines. if the routine is located inside a section with the name \char`\"{}.\+split\char`\"{} it will break functions into instruction symbols.
{\ttfamily \#include $<$routine.\+hpp$>$}
\doxysubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item
\mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_ab9f0693c5ec50954d953b28bebe4426b}{routine\+\_\+t}} (coff\+::symbol\+\_\+t $\ast$sym, coff\+::image\+\_\+t $\ast$img, coff\+::section\+\_\+header\+\_\+t $\ast$\mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_ad3a75cb97abbcd9b282772401b256f36}{scn}}, std\+::vector$<$ std\+::uint8\+\_\+t $>$ \&fn, \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9}{sym\+\_\+type\+\_\+t}} dcmp\+\_\+type)
\begin{DoxyCompactList}\small\item\em the explicit constructor for \mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t}{routine\+\_\+t}}. \end{DoxyCompactList}\item
std\+::vector$<$ \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t}{decomp\+::symbol\+\_\+t}} $>$ \mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_a1f790bd144badc71d6c4942cac8fc4e8}{decompose}} ()
\begin{DoxyCompactList}\small\item\em decompose the function into symbol(s). \end{DoxyCompactList}\item
coff\+::section\+\_\+header\+\_\+t $\ast$ \mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_ad3a75cb97abbcd9b282772401b256f36}{scn}} ()
\begin{DoxyCompactList}\small\item\em gets the section header of the section in which the symbol is located in. \end{DoxyCompactList}\item
std\+::vector$<$ std\+::uint8\+\_\+t $>$ \mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_a605a2be669a10a5a45325a5dca04401a}{data}} ()
\begin{DoxyCompactList}\small\item\em gets the function bytes. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection{Detailed Description}
the routine class which is responsible for creating symbols for routines. if the routine is located inside a section with the name \char`\"{}.\+split\char`\"{} it will break functions into instruction symbols.
\doxysubsection{Constructor \& Destructor Documentation}
\mbox{\Hypertarget{classtheo_1_1decomp_1_1routine__t_ab9f0693c5ec50954d953b28bebe4426b}\label{classtheo_1_1decomp_1_1routine__t_ab9f0693c5ec50954d953b28bebe4426b}}
\index{theo::decomp::routine\_t@{theo::decomp::routine\_t}!routine\_t@{routine\_t}}
\index{routine\_t@{routine\_t}!theo::decomp::routine\_t@{theo::decomp::routine\_t}}
\doxysubsubsection{\texorpdfstring{routine\_t()}{routine\_t()}}
{\footnotesize\ttfamily theo\+::decomp\+::routine\+\_\+t\+::routine\+\_\+t (\begin{DoxyParamCaption}\item[{coff\+::symbol\+\_\+t $\ast$}]{sym, }\item[{coff\+::image\+\_\+t $\ast$}]{img, }\item[{coff\+::section\+\_\+header\+\_\+t $\ast$}]{scn, }\item[{std\+::vector$<$ std\+::uint8\+\_\+t $>$ \&}]{fn, }\item[{\mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9}{sym\+\_\+type\+\_\+t}}}]{dcmp\+\_\+type }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [explicit]}}
the explicit constructor for \mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t}{routine\+\_\+t}}.
\begin{DoxyParams}{Parameters}
{\em sym} & the coff symbol for the routine.\\
\hline
{\em img} & the coff image which contains the symbol.\\
\hline
{\em scn} & the section header of the section that contains the symbol.\\
\hline
{\em fn} & the data (bytes) of the function.\\
\hline
{\em dcmp\+\_\+type} & the type of decomp to do. if this is sym\+\_\+type\+\_\+t\+::function then this class wont split the function up into individual instructions.\\
\hline
\end{DoxyParams}
\begin{DoxyCode}{0}
\DoxyCodeLine{39 : m\_img(img), m\_scn(\mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_ad3a75cb97abbcd9b282772401b256f36}{scn}}), m\_data(fn), m\_dcmp\_type(dcmp\_type), m\_sym(sym) \{\}}
\end{DoxyCode}
\doxysubsection{Member Function Documentation}
\mbox{\Hypertarget{classtheo_1_1decomp_1_1routine__t_a605a2be669a10a5a45325a5dca04401a}\label{classtheo_1_1decomp_1_1routine__t_a605a2be669a10a5a45325a5dca04401a}}
\index{theo::decomp::routine\_t@{theo::decomp::routine\_t}!data@{data}}
\index{data@{data}!theo::decomp::routine\_t@{theo::decomp::routine\_t}}
\doxysubsubsection{\texorpdfstring{data()}{data()}}
{\footnotesize\ttfamily std\+::vector$<$ std\+::uint8\+\_\+t $>$ theo\+::decomp\+::routine\+\_\+t\+::data (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}
gets the function bytes.
\begin{DoxyReturn}{Returns}
the function bytes.
\end{DoxyReturn}
\begin{DoxyCode}{0}
\DoxyCodeLine{172 \{}
\DoxyCodeLine{173 \textcolor{keywordflow}{return} m\_data;}
\DoxyCodeLine{174 \}}
\end{DoxyCode}
\mbox{\Hypertarget{classtheo_1_1decomp_1_1routine__t_a1f790bd144badc71d6c4942cac8fc4e8}\label{classtheo_1_1decomp_1_1routine__t_a1f790bd144badc71d6c4942cac8fc4e8}}
\index{theo::decomp::routine\_t@{theo::decomp::routine\_t}!decompose@{decompose}}
\index{decompose@{decompose}!theo::decomp::routine\_t@{theo::decomp::routine\_t}}
\doxysubsubsection{\texorpdfstring{decompose()}{decompose()}}
{\footnotesize\ttfamily std\+::vector$<$ \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t}{decomp\+::symbol\+\_\+t}} $>$ theo\+::decomp\+::routine\+\_\+t\+::decompose (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}
decompose the function into symbol(s).
\begin{DoxyReturn}{Returns}
symbol(s) of the function.
\end{DoxyReturn}
\begin{DoxyCode}{0}
\DoxyCodeLine{41 \{}
\DoxyCodeLine{42 std::vector<decomp::symbol\_t> result;}
\DoxyCodeLine{43 }
\DoxyCodeLine{44 \textcolor{keywordflow}{switch} (m\_dcmp\_type) \{}
\DoxyCodeLine{45 \textcolor{keywordflow}{case} \textcolor{keyword}{function}: \{}
\DoxyCodeLine{46 std::vector<recomp::reloc\_t> relocs;}
\DoxyCodeLine{47 \textcolor{keyword}{auto} scn\_relocs = \textcolor{keyword}{reinterpret\_cast<}coff::reloc\_t*\textcolor{keyword}{>}(}
\DoxyCodeLine{48 m\_scn-\/>ptr\_relocs + \textcolor{keyword}{reinterpret\_cast<}std::uint8\_t*\textcolor{keyword}{>}(m\_img));}
\DoxyCodeLine{49 }
\DoxyCodeLine{50 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} idx = 0u; idx < m\_scn-\/>num\_relocs; ++idx) \{}
\DoxyCodeLine{51 \textcolor{keyword}{auto} scn\_reloc = \&scn\_relocs[idx];}
\DoxyCodeLine{52 \textcolor{comment}{// if the reloc is in the current function...}}
\DoxyCodeLine{53 \textcolor{keywordflow}{if} (scn\_reloc-\/>virtual\_address >= m\_sym-\/>value \&\&}
\DoxyCodeLine{54 scn\_reloc-\/>virtual\_address < m\_sym-\/>value + m\_data.size()) \{}
\DoxyCodeLine{55 \textcolor{keyword}{auto} sym\_reloc = m\_img-\/>get\_symbol(scn\_relocs[idx].symbol\_index);}
\DoxyCodeLine{56 \textcolor{keyword}{auto} sym\_name = \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a7c6dee036291ded334aa10d89293fc2a}{symbol\_t::name}}(m\_img, sym\_reloc);}
\DoxyCodeLine{57 \textcolor{keyword}{auto} sym\_hash = \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a8695d75670cc4d61d275464e9109ff06}{decomp::symbol\_t::hash}}(sym\_name.data());}
\DoxyCodeLine{58 relocs.push\_back(}
\DoxyCodeLine{59 recomp::reloc\_t(scn\_reloc-\/>virtual\_address -\/ m\_sym-\/>value,}
\DoxyCodeLine{60 sym\_hash, sym\_name.data()));}
\DoxyCodeLine{61 \}}
\DoxyCodeLine{62 \}}
\DoxyCodeLine{63 }
\DoxyCodeLine{64 result.push\_back(decomp::symbol\_t(}
\DoxyCodeLine{65 m\_img, \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a7c6dee036291ded334aa10d89293fc2a}{symbol\_t::name}}(m\_img, m\_sym).\mbox{\hyperlink{classtheo_1_1decomp_1_1routine__t_a605a2be669a10a5a45325a5dca04401a}{data}}(), m\_sym-\/>value, m\_data,}
\DoxyCodeLine{66 m\_scn, m\_sym, relocs, \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acf6baee49c2ddb7e89724231bbd75d4a}{sym\_type\_t::function}}));}
\DoxyCodeLine{67 \textcolor{keywordflow}{break};}
\DoxyCodeLine{68 \}}
\DoxyCodeLine{69 \textcolor{keywordflow}{case} \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9a4842f4c175b1ec87fc82ef3757d3a0e9}{instruction}}: \{}
\DoxyCodeLine{70 std::uint32\_t offset = \{\};}
\DoxyCodeLine{71 xed\_error\_enum\_t err;}
\DoxyCodeLine{72 }
\DoxyCodeLine{73 xed\_decoded\_inst\_t instr;}
\DoxyCodeLine{74 xed\_state\_t istate\{XED\_MACHINE\_MODE\_LONG\_64, XED\_ADDRESS\_WIDTH\_64b\};}
\DoxyCodeLine{75 xed\_decoded\_inst\_zero\_set\_mode(\&instr, \&istate);}
\DoxyCodeLine{76 }
\DoxyCodeLine{77 \textcolor{comment}{// keep looping over the section, lower the number of bytes each time...}}
\DoxyCodeLine{78 \textcolor{comment}{//}}
\DoxyCodeLine{79 \textcolor{keywordflow}{while} ((err = xed\_decode(\&instr, m\_data.data() + offset,}
\DoxyCodeLine{80 m\_data.size() -\/ offset)) == XED\_ERROR\_NONE) \{}
\DoxyCodeLine{81 \textcolor{comment}{// symbol name is of the format: symbol@instroffset, I.E: main@11...}}
\DoxyCodeLine{82 \textcolor{comment}{//}}
\DoxyCodeLine{83 \textcolor{keyword}{auto} new\_sym\_name = \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a7c6dee036291ded334aa10d89293fc2a}{symbol\_t::name}}(m\_img, m\_sym);}
\DoxyCodeLine{84 }
\DoxyCodeLine{85 \textcolor{comment}{// first instruction doesnt need the @offset...}}
\DoxyCodeLine{86 \textcolor{comment}{//}}
\DoxyCodeLine{87 \textcolor{keywordflow}{if} (offset)}
\DoxyCodeLine{88 new\_sym\_name.append(\textcolor{stringliteral}{"{}@"{}}).append(std::to\_string(offset));}
\DoxyCodeLine{89 }
\DoxyCodeLine{90 std::vector<recomp::reloc\_t> relocs;}
\DoxyCodeLine{91 \textcolor{keyword}{auto} scn\_relocs = \textcolor{keyword}{reinterpret\_cast<}coff::reloc\_t*\textcolor{keyword}{>}(}
\DoxyCodeLine{92 m\_scn-\/>ptr\_relocs + \textcolor{keyword}{reinterpret\_cast<}std::uint8\_t*\textcolor{keyword}{>}(m\_img));}
\DoxyCodeLine{93 }
\DoxyCodeLine{94 \textcolor{comment}{// find if this instruction has a relocation or not...}}
\DoxyCodeLine{95 \textcolor{comment}{// if so, return the reloc\_t...}}
\DoxyCodeLine{96 \textcolor{comment}{//}}
\DoxyCodeLine{97 \textcolor{keyword}{auto} reloc = std::find\_if(}
\DoxyCodeLine{98 scn\_relocs, scn\_relocs + m\_scn-\/>num\_relocs,}
\DoxyCodeLine{99 [\&](coff::reloc\_t reloc) \{}
\DoxyCodeLine{100 return reloc.virtual\_address >= m\_sym-\/>value + offset \&\&}
\DoxyCodeLine{101 reloc.virtual\_address <}
\DoxyCodeLine{102 m\_sym-\/>value + offset +}
\DoxyCodeLine{103 xed\_decoded\_inst\_get\_length(\&instr);}
\DoxyCodeLine{104 \});}
\DoxyCodeLine{105 }
\DoxyCodeLine{106 \textcolor{comment}{// if there is indeed a reloc for this instruction...}}
\DoxyCodeLine{107 \textcolor{comment}{//}}
\DoxyCodeLine{108 \textcolor{keywordflow}{if} (reloc != scn\_relocs + m\_scn-\/>num\_relocs) \{}
\DoxyCodeLine{109 \textcolor{keyword}{auto} sym\_reloc = m\_img-\/>get\_symbol(reloc-\/>symbol\_index);}
\DoxyCodeLine{110 \textcolor{keyword}{auto} sym\_name = \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a7c6dee036291ded334aa10d89293fc2a}{symbol\_t::name}}(m\_img, sym\_reloc);}
\DoxyCodeLine{111 \textcolor{keyword}{auto} sym\_hash = \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a8695d75670cc4d61d275464e9109ff06}{decomp::symbol\_t::hash}}(sym\_name.data());}
\DoxyCodeLine{112 \textcolor{keyword}{auto} reloc\_offset = reloc-\/>virtual\_address -\/ m\_sym-\/>value -\/ offset;}
\DoxyCodeLine{113 }
\DoxyCodeLine{114 relocs.push\_back(}
\DoxyCodeLine{115 recomp::reloc\_t(reloc\_offset, sym\_hash, sym\_name.data()));}
\DoxyCodeLine{116 \}}
\DoxyCodeLine{117 }
\DoxyCodeLine{118 \textcolor{comment}{// add a reloc to the next instruction...}}
\DoxyCodeLine{119 \textcolor{comment}{// note that the offset is ZERO... comp\_t will understand that}}
\DoxyCodeLine{120 \textcolor{comment}{// relocs with offset ZERO means the next instructions...}}
\DoxyCodeLine{121 \textcolor{comment}{//}}
\DoxyCodeLine{122 \textcolor{keyword}{auto} next\_inst\_sym =}
\DoxyCodeLine{123 \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a7c6dee036291ded334aa10d89293fc2a}{symbol\_t::name}}(m\_img, m\_sym)}
\DoxyCodeLine{124 .append(\textcolor{stringliteral}{"{}@"{}})}
\DoxyCodeLine{125 .append(std::to\_string(offset +}
\DoxyCodeLine{126 xed\_decoded\_inst\_get\_length(\&instr)));}
\DoxyCodeLine{127 }
\DoxyCodeLine{128 relocs.push\_back(recomp::reloc\_t(}
\DoxyCodeLine{129 0, \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a8695d75670cc4d61d275464e9109ff06}{decomp::symbol\_t::hash}}(next\_inst\_sym), next\_inst\_sym.data()));}
\DoxyCodeLine{130 }
\DoxyCodeLine{131 \textcolor{comment}{// get the instructions bytes}}
\DoxyCodeLine{132 \textcolor{comment}{//}}
\DoxyCodeLine{133 std::vector<std::uint8\_t> inst\_bytes(}
\DoxyCodeLine{134 m\_data.data() + offset,}
\DoxyCodeLine{135 m\_data.data() + offset + xed\_decoded\_inst\_get\_length(\&instr));}
\DoxyCodeLine{136 }
\DoxyCodeLine{137 result.push\_back(decomp::symbol\_t(m\_img, new\_sym\_name, offset,}
\DoxyCodeLine{138 inst\_bytes, m\_scn, m\_sym, relocs,}
\DoxyCodeLine{139 \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9a4842f4c175b1ec87fc82ef3757d3a0e9}{sym\_type\_t::instruction}}));}
\DoxyCodeLine{140 }
\DoxyCodeLine{141 \textcolor{comment}{// after creating the symbol and dealing with relocs then print the}}
\DoxyCodeLine{142 \textcolor{comment}{// information we have concluded...}}
\DoxyCodeLine{143 \textcolor{comment}{//}}
\DoxyCodeLine{144 \textcolor{keywordtype}{char} buff[255];}
\DoxyCodeLine{145 offset += xed\_decoded\_inst\_get\_length(\&instr);}
\DoxyCodeLine{146 xed\_format\_context(XED\_SYNTAX\_INTEL, \&instr, buff, \textcolor{keyword}{sizeof} buff, NULL,}
\DoxyCodeLine{147 NULL, NULL);}
\DoxyCodeLine{148 }
\DoxyCodeLine{149 spdlog::info(\textcolor{stringliteral}{"{}\{\}: \{\}"{}}, new\_sym\_name, buff);}
\DoxyCodeLine{150 \textcolor{comment}{// need to set this so that instr can be used to decode again...}}
\DoxyCodeLine{151 xed\_decoded\_inst\_zero\_set\_mode(\&instr, \&istate);}
\DoxyCodeLine{152 \}}
\DoxyCodeLine{153 }
\DoxyCodeLine{154 \textcolor{comment}{// remove the relocation to the next symbol from the last instruction}}
\DoxyCodeLine{155 \textcolor{comment}{//}}
\DoxyCodeLine{156 \textcolor{keyword}{auto}\& last\_inst = result.back();}
\DoxyCodeLine{157 \textcolor{keyword}{auto}\& last\_inst\_relocs = last\_inst.relocs();}
\DoxyCodeLine{158 last\_inst\_relocs.erase(last\_inst\_relocs.end() -\/ 1);}
\DoxyCodeLine{159 \textcolor{keywordflow}{break};}
\DoxyCodeLine{160 \}}
\DoxyCodeLine{161 \textcolor{keywordflow}{default}:}
\DoxyCodeLine{162 \textcolor{keywordflow}{break};}
\DoxyCodeLine{163 \}}
\DoxyCodeLine{164 }
\DoxyCodeLine{165 \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{166 \}}
\end{DoxyCode}
\mbox{\Hypertarget{classtheo_1_1decomp_1_1routine__t_ad3a75cb97abbcd9b282772401b256f36}\label{classtheo_1_1decomp_1_1routine__t_ad3a75cb97abbcd9b282772401b256f36}}
\index{theo::decomp::routine\_t@{theo::decomp::routine\_t}!scn@{scn}}
\index{scn@{scn}!theo::decomp::routine\_t@{theo::decomp::routine\_t}}
\doxysubsubsection{\texorpdfstring{scn()}{scn()}}
{\footnotesize\ttfamily coff\+::section\+\_\+header\+\_\+t $\ast$ theo\+::decomp\+::routine\+\_\+t\+::scn (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}
gets the section header of the section in which the symbol is located in.
\begin{DoxyReturn}{Returns}
the section header of the section in which the symbol is located in.
\end{DoxyReturn}
\begin{DoxyCode}{0}
\DoxyCodeLine{168 \{}
\DoxyCodeLine{169 \textcolor{keywordflow}{return} m\_scn;}
\DoxyCodeLine{170 \}}
\end{DoxyCode}
The documentation for this class was generated from the following files\+:\begin{DoxyCompactItemize}
\item
include/decomp/\mbox{\hyperlink{routine_8hpp}{routine.\+hpp}}\item
src/decomp/\mbox{\hyperlink{routine_8cpp}{routine.\+cpp}}\end{DoxyCompactItemize}