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.
90 lines
12 KiB
90 lines
12 KiB
\hypertarget{jcc__rewrite__pass_8cpp_source}{}\doxysection{jcc\+\_\+rewrite\+\_\+pass.\+cpp}
|
|
\label{jcc__rewrite__pass_8cpp_source}\index{src/obf/passes/jcc\_rewrite\_pass.cpp@{src/obf/passes/jcc\_rewrite\_pass.cpp}}
|
|
\mbox{\hyperlink{jcc__rewrite__pass_8cpp}{Go to the documentation of this file.}}
|
|
\begin{DoxyCode}{0}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00001}00001 \textcolor{comment}{// Copyright (c) 2022, \_xeroxz}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00002}00002 \textcolor{comment}{// All rights reserved.}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00003}00003 \textcolor{comment}{//}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00004}00004 \textcolor{comment}{// Redistribution and use in source and binary forms, with or without}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00005}00005 \textcolor{comment}{// modification, are permitted provided that the following conditions are met:}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00006}00006 \textcolor{comment}{//}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00007}00007 \textcolor{comment}{// 1. Redistributions of source code must retain the above copyright notice,}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00008}00008 \textcolor{comment}{// this list of conditions and the following disclaimer.}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00009}00009 \textcolor{comment}{//}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00010}00010 \textcolor{comment}{// 2. Redistributions in binary form must reproduce the above copyright notice,}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00011}00011 \textcolor{comment}{// this list of conditions and the following disclaimer in the documentation}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00012}00012 \textcolor{comment}{// and/or other materials provided with the distribution.}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00013}00013 \textcolor{comment}{//}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00014}00014 \textcolor{comment}{// 3. Neither the name of the copyright holder nor the names of its}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00015}00015 \textcolor{comment}{// contributors may be used to endorse or promote products derived from}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00016}00016 \textcolor{comment}{// this software without specific prior written permission.}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00017}00017 \textcolor{comment}{//}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00018}00018 \textcolor{comment}{// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "{}AS IS"{}}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00019}00019 \textcolor{comment}{// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00020}00020 \textcolor{comment}{// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00021}00021 \textcolor{comment}{// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00022}00022 \textcolor{comment}{// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00023}00023 \textcolor{comment}{// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00024}00024 \textcolor{comment}{// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00025}00025 \textcolor{comment}{// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00026}00026 \textcolor{comment}{// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00027}00027 \textcolor{comment}{// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00028}00028 \textcolor{comment}{// POSSIBILITY OF SUCH DAMAGE.}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00029}00029 \textcolor{comment}{//}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00030}00030 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00031}00031 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{jcc__rewrite__pass_8hpp}{obf/passes/jcc\_rewrite\_pass.hpp}}>}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00032}00032 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{next__inst__pass_8hpp}{obf/passes/next\_inst\_pass.hpp}}>}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00033}00033 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00034}00034 \textcolor{keyword}{namespace }\mbox{\hyperlink{namespacetheo_1_1obf}{theo::obf}} \{}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00035}\mbox{\hyperlink{classtheo_1_1obf_1_1jcc__rewrite__pass__t_afc17278f751fe3f5868c988faffb3c92}{00035}} \mbox{\hyperlink{classtheo_1_1obf_1_1jcc__rewrite__pass__t}{jcc\_rewrite\_pass\_t}}* \mbox{\hyperlink{classtheo_1_1obf_1_1jcc__rewrite__pass__t_afc17278f751fe3f5868c988faffb3c92}{jcc\_rewrite\_pass\_t::get}}() \{}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00036}00036 \textcolor{keyword}{static} \mbox{\hyperlink{classtheo_1_1obf_1_1jcc__rewrite__pass__t}{jcc\_rewrite\_pass\_t}} obj;}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00037}00037 \textcolor{keywordflow}{return} \&obj;}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00038}00038 \}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00039}00039 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00040}\mbox{\hyperlink{classtheo_1_1obf_1_1jcc__rewrite__pass__t_a5a93eb0945025ef3caefed8c63b65b23}{00040}} \textcolor{keywordtype}{void} \mbox{\hyperlink{classtheo_1_1obf_1_1jcc__rewrite__pass__t_a5a93eb0945025ef3caefed8c63b65b23}{jcc\_rewrite\_pass\_t::run}}(\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t}{decomp::symbol\_t}}* sym) \{}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00041}00041 std::int32\_t disp = \{\};}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00042}00042 xed\_decoded\_inst\_t inst;}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00043}00043 xed\_state\_t istate\{XED\_MACHINE\_MODE\_LONG\_64, XED\_ADDRESS\_WIDTH\_64b\};}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00044}00044 xed\_decoded\_inst\_zero\_set\_mode(\&inst, \&istate);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00045}00045 xed\_decode(\&inst, sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_aa3ecf0b480d10bffe68812409c06d61b}{data}}().data(), XED\_MAX\_INSTRUCTION\_BYTES);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00046}00046 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00047}00047 \textcolor{comment}{// if the instruction is branching...}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00048}00048 \textcolor{keywordflow}{if} ((disp = xed\_decoded\_inst\_get\_branch\_displacement(\&inst))) \{}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00049}00049 disp += xed\_decoded\_inst\_get\_length(\&inst);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00050}00050 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00051}00051 \textcolor{comment}{// update displacement...}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00052}00052 xed\_decoded\_inst\_set\_branch\_displacement(}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00053}00053 \&inst, sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_aa3ecf0b480d10bffe68812409c06d61b}{data}}().size() -\/ xed\_decoded\_inst\_get\_length(\&inst),}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00054}00054 xed\_decoded\_inst\_get\_branch\_displacement\_width(\&inst));}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00055}00055 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00056}00056 xed\_encoder\_request\_init\_from\_decode(\&inst);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00057}00057 xed\_encoder\_request\_t* req = \&inst;}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00058}00058 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00059}00059 \textcolor{comment}{// update jcc in the buffer...}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00060}00060 std::uint32\_t len = \{\};}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00061}00061 xed\_encode(req, sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_aa3ecf0b480d10bffe68812409c06d61b}{data}}().data(), xed\_decoded\_inst\_get\_length(\&inst),}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00062}00062 \&len);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00063}00063 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00064}00064 \textcolor{comment}{// create a relocation to the instruction the branch would normally go}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00065}00065 \textcolor{comment}{// too...}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00066}00066 \textcolor{keyword}{auto} offset = disp < 0 ? sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a79759d343ddb6a62e4149aef92e2d70b}{offset}}() -\/ std::abs(disp)}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00067}00067 : sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a79759d343ddb6a62e4149aef92e2d70b}{offset}}() + std::abs(disp);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00068}00068 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00069}00069 \textcolor{keyword}{auto} sym\_name =}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00070}00070 std::string(}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00071}00071 sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a0e6f850f25a51609fbe5dc0a61b27bc9}{sym}}()-\/>name.to\_string(sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_ad97ad0395e18dcfb42017fb7753e0665}{img}}()-\/>get\_strings()).data())}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00072}00072 .append(\textcolor{stringliteral}{"{}@"{}})}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00073}00073 .append(std::to\_string(offset));}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00074}00074 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00075}00075 sym-\/>\mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_abc158e1dc1567161f0a57ed15fc718f7}{relocs}}().push\_back(}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00076}00076 \mbox{\hyperlink{classtheo_1_1recomp_1_1reloc__t}{recomp::reloc\_t}}(0, \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t_a8695d75670cc4d61d275464e9109ff06}{decomp::symbol\_t::hash}}(sym\_name), sym\_name.data()));}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00077}00077 }
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00078}00078 \textcolor{comment}{// run next\_inst\_pass on this symbol to generate the transformations for the}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00079}00079 \textcolor{comment}{// relocation to the jcc branch dest instruction...}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00080}00080 \mbox{\hyperlink{classtheo_1_1obf_1_1next__inst__pass__t_a964e6f5291ccba0442519f2563b3a2e9}{next\_inst\_pass\_t::get}}()-\/>\mbox{\hyperlink{classtheo_1_1obf_1_1next__inst__pass__t_ae4cbba78b14c2b9da794386e4d92f40f}{run}}(sym);}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00081}00081 \}}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00082}00082 \};}
|
|
\DoxyCodeLine{\Hypertarget{jcc__rewrite__pass_8cpp_source_l00083}00083 \} \textcolor{comment}{// namespace theo::obf}}
|
|
|
|
\end{DoxyCode}
|