\hypertarget{decomp_8cpp_source}{}\doxysection{decomp.\+cpp} \label{decomp_8cpp_source}\index{src/decomp/decomp.cpp@{src/decomp/decomp.cpp}} \mbox{\hyperlink{decomp_8cpp}{Go to the documentation of this file.}} \begin{DoxyCode}{0} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00001}00001 \textcolor{comment}{// Copyright (c) 2022, \_xeroxz}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00002}00002 \textcolor{comment}{// All rights reserved.}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00003}00003 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00004}00004 \textcolor{comment}{// Redistribution and use in source and binary forms, with or without}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00005}00005 \textcolor{comment}{// modification, are permitted provided that the following conditions are met:}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00006}00006 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00007}00007 \textcolor{comment}{// 1. Redistributions of source code must retain the above copyright notice,}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00008}00008 \textcolor{comment}{// this list of conditions and the following disclaimer.}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00009}00009 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00010}00010 \textcolor{comment}{// 2. Redistributions in binary form must reproduce the above copyright notice,}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00011}00011 \textcolor{comment}{// this list of conditions and the following disclaimer in the documentation}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00012}00012 \textcolor{comment}{// and/or other materials provided with the distribution.}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00013}00013 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00014}00014 \textcolor{comment}{// 3. Neither the name of the copyright holder nor the names of its}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00015}00015 \textcolor{comment}{// contributors may be used to endorse or promote products derived from}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00016}00016 \textcolor{comment}{// this software without specific prior written permission.}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00017}00017 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00018}00018 \textcolor{comment}{// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "{}AS IS"{}}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00019}00019 \textcolor{comment}{// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00020}00020 \textcolor{comment}{// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00021}00021 \textcolor{comment}{// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00022}00022 \textcolor{comment}{// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00023}00023 \textcolor{comment}{// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00024}00024 \textcolor{comment}{// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00025}00025 \textcolor{comment}{// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00026}00026 \textcolor{comment}{// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00027}00027 \textcolor{comment}{// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00028}00028 \textcolor{comment}{// POSSIBILITY OF SUCH DAMAGE.}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00029}00029 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00030}00030 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00031}00031 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{decomp_8hpp}{decomp/decomp.hpp}}>}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00032}00032 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00033}00033 \textcolor{keyword}{namespace }\mbox{\hyperlink{namespacetheo_1_1decomp}{theo::decomp}} \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00034}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_a35cfac16bd918d576b29e04388690d68}{00034}} \mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_a35cfac16bd918d576b29e04388690d68}{decomp\_t::decomp\_t}}(std::vector\& lib, \mbox{\hyperlink{classtheo_1_1recomp_1_1symbol__table__t}{recomp::symbol\_table\_t}}* syms)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00035}00035 : m\_lib(lib), m\_syms(syms) \{\}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00036}00036 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00037}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_ae23353a4293aa30969b6d3fa37359469}{00037}} std::optional \mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_ae23353a4293aa30969b6d3fa37359469}{decomp\_t::decompose}}(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00038}00038 std::string\& entry\_sym) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00039}00039 \textcolor{comment}{// extract obj files from the archive file...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00040}00040 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00041}00041 ar::view \mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_aa728bde8ec1c5c28ec09f86adf427ae2}{lib}}(m\_lib.data(), m\_lib.size());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00042}00042 std::for\_each(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00043}00043 \mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_aa728bde8ec1c5c28ec09f86adf427ae2}{lib}}.begin(), \mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_aa728bde8ec1c5c28ec09f86adf427ae2}{lib}}.end(),} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00044}00044 [\&](std::pair itr) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00045}00045 \textcolor{comment}{// if the entry isnt the symbol table or the string table}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00046}00046 \textcolor{comment}{// then we know its an obj file...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00047}00047 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00048}00048 if (!itr.second.is\_symbol\_table() \&\& !itr.second.is\_string\_table()) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00049}00049 spdlog::info(\textcolor{stringliteral}{"{}extracted obj from archive: \{\}"{}}, itr.first);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00050}00050 std::vector data(itr.second.begin(), itr.second.end());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00051}00051 m\_objs.push\_back(data);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00052}00052 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00053}00053 \});} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00054}00054 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00055}00055 std::for\_each(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00056}00056 m\_objs.begin(), m\_objs.end(), [\&](std::vector\& img\_data) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00057}00057 auto img = reinterpret\_cast(img\_data.data());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00058}00058 for (auto idx = 0u; idx < img-\/>file\_header.num\_symbols; ++idx) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00059}00059 auto sym = img-\/>get\_symbol(idx);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00060}00060 if (sym-\/>section\_index -\/ 1 > img-\/>file\_header.num\_sections)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00061}00061 continue;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00062}00062 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00063}00063 auto sym\_name = symbol\_t::name(img, sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00064}00064 if (sym\_name.length()) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00065}00065 auto sym\_hash = symbol\_t::hash(sym\_name.data());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00066}00066 auto sym\_size =} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00067}00067 sym-\/>has\_section()} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00068}00068 ? next\_sym(img, img-\/>get\_section(sym-\/>section\_index -\/ 1),} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00069}00069 sym)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00070}00070 : 0u;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00071}00071 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00072}00072 m\_lookup\_tbl[sym\_hash].emplace\_back(img, sym, sym\_size);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00073}00073 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00074}00074 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00075}00075 \});} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00076}00076 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00077}00077 \textcolor{comment}{// extract used symbols from objs and create a nice little set of them so that}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00078}00078 \textcolor{comment}{// we can easily decompose them... no need deal with every single symbol...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00079}00079 spdlog::info(\textcolor{stringliteral}{"{}extracted \{\} symbols being used..."{}},} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00080}00080 ext\_used\_syms(entry\_sym.data()));} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00081}00081 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00082}00082 \textcolor{comment}{// generate symbols, populate section hash table, for each object file}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00083}00083 \textcolor{comment}{// extracted from the archive file...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00084}00084 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00085}00085 std::for\_each(m\_used\_syms.begin(), m\_used\_syms.end(), [\&](\mbox{\hyperlink{namespacetheo_1_1decomp_abbf09e1f7eb9e42057ff9c9e8be41266}{sym\_data\_t}} \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acdb885c0ea7f6b2874224487c69b8112}{data}}) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00086}00086 auto [img, sym, size] = data;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00087}00087 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00088}00088 \textcolor{comment}{// populate section hash table with sections for the img of this}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00089}00089 \textcolor{comment}{// symbol... only populate the hash table if its not been populated for}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00090}00090 \textcolor{comment}{// this obj before...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00091}00091 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00092}00092 if (m\_processed\_objs.emplace(img).second) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00093}00093 for (auto idx = 0u; idx < img-\/>file\_header.num\_sections; ++idx) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00094}00094 auto scn = img-\/>get\_section(idx);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00095}00095 auto scn\_sym\_name =} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00096}00096 std::string(scn-\/>name.to\_string(img-\/>get\_strings()))} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00097}00097 .append(\textcolor{stringliteral}{"{}\#"{}})} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00098}00098 .append(std::to\_string(idx))} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00099}00099 .append(\textcolor{stringliteral}{"{}!"{}})} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00100}00100 .append(std::to\_string(img-\/>file\_header.timedate\_stamp));} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00101}00101 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00102}00102 \textcolor{comment}{// hash the name of the section + the index + the timestamp of the}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00103}00103 \textcolor{comment}{// obj file it is in...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00104}00104 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00105}00105 m\_scn\_hash\_tbl.insert(\{scn, decomp::symbol\_t::hash(scn\_sym\_name)\});} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00106}00106 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00107}00107 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00108}00108 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00109}00109 \textcolor{comment}{// if the symbol is a function then we are going to decompose it...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00110}00110 \textcolor{comment}{// data symbols are handled after this...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00111}00111 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00112}00112 if (sym-\/>has\_section()) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00113}00113 if (sym-\/>derived\_type == coff::derived\_type\_id::function) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00114}00114 auto scn = img-\/>get\_section(sym-\/>section\_index -\/ 1);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00115}00115 auto dcmp\_type =} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00116}00116 scn-\/>name.to\_string(img-\/>get\_strings()) == INSTR\_SPLIT\_SECTION\_NAME} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00117}00117 ? decomp::sym\_type\_t::instruction} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00118}00118 : decomp::sym\_type\_t::function;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00119}00119 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00120}00120 auto fn\_size = next\_sym(img, scn, sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00121}00121 auto fn\_bgn = scn-\/>ptr\_raw\_data + reinterpret\_cast(img) +} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00122}00122 sym-\/>value;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00123}00123 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00124}00124 std::vector fn(fn\_bgn, fn\_bgn + fn\_size);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00125}00125 decomp::routine\_t rtn(sym, img, scn, fn, dcmp\_type);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00126}00126 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00127}00127 auto syms = rtn.decompose();} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00128}00128 m\_syms-\/>put\_symbols(syms);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00129}00129 \} \textcolor{keywordflow}{else} if (sym-\/>storage\_class == coff::storage\_class\_id::public\_symbol ||} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00130}00130 sym-\/>storage\_class == coff::storage\_class\_id::private\_symbol) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00131}00131 auto scn = img-\/>get\_section(sym-\/>section\_index -\/ 1);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00132}00132 auto scn\_sym = m\_syms-\/>sym\_from\_hash(m\_scn\_hash\_tbl[scn]);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00133}00133 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00134}00134 \textcolor{comment}{// if the section doesnt have a symbol then make one and put it into}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00135}00135 \textcolor{comment}{// the symbol table...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00136}00136 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00137}00137 if (!scn\_sym.has\_value()) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00138}00138 auto scn\_sym\_name =} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00139}00139 std::string(scn-\/>name.to\_string(img-\/>get\_strings()))} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00140}00140 .append(\textcolor{stringliteral}{"{}\#"{}})} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00141}00141 .append(std::to\_string(sym-\/>section\_index -\/ 1))} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00142}00142 .append(\textcolor{stringliteral}{"{}!"{}})} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00143}00143 .append(std::to\_string(img-\/>file\_header.timedate\_stamp));} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00144}00144 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00145}00145 std::vector scn\_data(scn-\/>size\_raw\_data);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00146}00146 if (scn-\/>characteristics.cnt\_uninit\_data) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00147}00147 scn\_data.insert(scn\_data.begin(), scn-\/>size\_raw\_data, 0);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00148}00148 \} else \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00149}00149 scn\_data.insert(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00150}00150 scn\_data.begin(),} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00151}00151 reinterpret\_cast(img) + scn-\/>ptr\_raw\_data,} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00152}00152 reinterpret\_cast(img) + scn-\/>ptr\_raw\_data +} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00153}00153 scn-\/>size\_raw\_data);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00154}00154 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00155}00155 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00156}00156 std::vector relocs;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00157}00157 auto scn\_relocs = reinterpret\_cast(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00158}00158 scn-\/>ptr\_relocs + reinterpret\_cast(img));} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00159}00159 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00160}00160 for (auto idx = 0u; idx < scn-\/>num\_relocs; ++idx) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00161}00161 auto scn\_reloc = \&scn\_relocs[idx];} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00162}00162 auto sym\_reloc = img-\/>get\_symbol(scn\_relocs[idx].symbol\_index);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00163}00163 auto sym\_name = symbol\_t::name(img, sym\_reloc);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00164}00164 auto sym\_hash = decomp::symbol\_t::hash(sym\_name.data());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00165}00165 relocs.push\_back(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00166}00166 recomp::reloc\_t(scn\_reloc-\/>virtual\_address -\/ sym-\/>value,} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00167}00167 sym\_hash, sym\_name.data()));} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00168}00168 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00169}00169 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00170}00170 decomp::symbol\_t new\_scn\_sym(img, scn\_sym\_name, 0, scn\_data, scn, \{\},} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00171}00171 relocs, sym\_type\_t::section);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00172}00172 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00173}00173 m\_syms-\/>put\_symbol(new\_scn\_sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00174}00174 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00175}00175 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00176}00176 \textcolor{comment}{// create a symbol for the data...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00177}00177 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00178}00178 \mbox{\hyperlink{classtheo_1_1decomp_1_1symbol__t}{decomp::symbol\_t}} new\_sym(img, symbol\_t::name(img, sym).\mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acdb885c0ea7f6b2874224487c69b8112}{data}}(),} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00179}00179 sym-\/>value, \{\}, scn, sym, \{\},} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00180}00180 \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acdb885c0ea7f6b2874224487c69b8112}{sym\_type\_t::data}});} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00181}00181 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00182}00182 m\_syms-\/>put\_symbol(new\_sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00183}00183 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00184}00184 \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (sym-\/>storage\_class ==} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00185}00185 coff::storage\_class\_id::} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00186}00186 external\_definition) \{ \textcolor{comment}{// else if the symbol has no}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00187}00187 \textcolor{comment}{// section... these symbols}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00188}00188 \textcolor{comment}{// require the linker to allocate}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00189}00189 \textcolor{comment}{// space for them...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00190}00190 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00191}00191 std::vector data(sym-\/>value, 0);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00192}00192 decomp::symbol\_t bss\_sym(img, symbol\_t::name(img, sym).data(), \{\}, \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acdb885c0ea7f6b2874224487c69b8112}{data}},} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00193}00193 \{\}, sym, \{\}, \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acdb885c0ea7f6b2874224487c69b8112}{sym\_type\_t::data}});} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00194}00194 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00195}00195 m\_syms-\/>put\_symbol(bss\_sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00196}00196 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00197}00197 \});} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00198}00198 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00199}00199 \textcolor{comment}{// return the extract symbols to the caller...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00200}00200 \textcolor{comment}{//}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00201}00201 \textcolor{keywordflow}{return} m\_syms;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00202}00202 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00203}00203 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00204}00204 std::uint32\_t decomp\_t::next\_sym(coff::image\_t* img,} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00205}00205 coff::section\_header\_t* hdr,} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00206}00206 coff::symbol\_t* s) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00207}00207 \textcolor{comment}{// loop over all symbols in this object...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00208}00208 \textcolor{comment}{// find the next symbol inside of the same section...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00209}00209 \textcolor{comment}{// if there is no next symbol then we use the end of the section...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00210}00210 std::uint32\_t res = hdr-\/>size\_raw\_data;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00211}00211 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} idx = 0u; idx < img-\/>file\_header.num\_symbols; ++idx) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00212}00212 \textcolor{keyword}{auto} q = img-\/>get\_symbol(idx);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00213}00213 \textcolor{keywordflow}{if} (q-\/>derived\_type == \mbox{\hyperlink{namespacetheo_1_1decomp_af96177687d0ad683c5897d8fa01135f9acf6baee49c2ddb7e89724231bbd75d4a}{coff::derived\_type\_id::function}} \&\&} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00214}00214 q-\/>section\_index == s-\/>section\_index \&\& q != s)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00215}00215 \textcolor{keywordflow}{if} (q-\/>value > s-\/>value \&\& q-\/>value < res)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00216}00216 res = q-\/>value;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00217}00217 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00218}00218 \textcolor{keywordflow}{return} res;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00219}00219 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00220}00220 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00221}00221 std::uint32\_t decomp\_t::ext\_used\_syms(\textcolor{keyword}{const} std::string\&\& entry\_sym) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00222}00222 std::optional entry = get\_symbol(entry\_sym.data());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00223}00223 \textcolor{keywordflow}{if} (!entry.has\_value())} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00224}00224 \textcolor{keywordflow}{return} 0u;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00225}00225 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00226}00226 std::set cache;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00227}00227 \textcolor{keyword}{const} \textcolor{keyword}{auto} finding\_syms = [\&]() -\/> \textcolor{keywordtype}{bool} \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00228}00228 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} itr = m\_used\_syms.begin(); itr != m\_used\_syms.end(); ++itr) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00229}00229 \textcolor{keyword}{auto} [img, sym, size] = *itr;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00230}00230 \textcolor{keywordflow}{if} (sym-\/>has\_section() \&\& !cache.count(sym) \&\& size) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00231}00231 \textcolor{keyword}{auto} scn = img-\/>get\_section(sym-\/>section\_index -\/ 1);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00232}00232 \textcolor{keyword}{auto} num\_relocs = scn-\/>num\_relocs;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00233}00233 \textcolor{keyword}{auto} relocs = \textcolor{keyword}{reinterpret\_cast<}coff::reloc\_t*\textcolor{keyword}{>}(} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00234}00234 scn-\/>ptr\_relocs + \textcolor{keyword}{reinterpret\_cast<}std::uint8\_t*\textcolor{keyword}{>}(img));} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00235}00235 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00236}00236 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} idx = 0u; idx < num\_relocs; ++idx) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00237}00237 \textcolor{keyword}{auto} reloc = \&relocs[idx];} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00238}00238 \textcolor{comment}{// if the reloc is inside of the current symbol...}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00239}00239 \textcolor{keywordflow}{if} (reloc-\/>virtual\_address >= sym-\/>value \&\&} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00240}00240 reloc-\/>virtual\_address < sym-\/>value + size) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00241}00241 \textcolor{keyword}{auto} reloc\_sym = img-\/>get\_symbol(reloc-\/>symbol\_index);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00242}00242 \textcolor{keyword}{auto} sym\_name = symbol\_t::name(img, reloc\_sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00243}00243 entry = get\_symbol(sym\_name);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00244}00244 \textcolor{keywordflow}{if} (m\_used\_syms.emplace(entry.value()).second)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00245}00245 \textcolor{keywordflow}{return} \textcolor{keyword}{true};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00246}00246 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00247}00247 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00248}00248 cache.emplace(sym);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00249}00249 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00250}00250 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00251}00251 \textcolor{keywordflow}{return} \textcolor{keyword}{false};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00252}00252 \};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00253}00253 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00254}00254 m\_used\_syms.emplace(entry.value());} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00255}00255 \textcolor{keywordflow}{for} (m\_used\_syms.emplace(entry.value()); finding\_syms();)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00256}00256 ;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00257}00257 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00258}00258 \textcolor{keywordflow}{return} m\_used\_syms.size();} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00259}00259 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00260}00260 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00261}00261 std::optional decomp\_t::get\_symbol(\textcolor{keyword}{const} std::string\_view\& name) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00262}00262 coff::image\_t* img = \{\};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00263}00263 coff::symbol\_t* sym = \{\};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00264}00264 std::uint32\_t size = \{\};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00265}00265 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00266}00266 \textcolor{keyword}{auto}\& syms = m\_lookup\_tbl[symbol\_t::hash(name.data())];} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00267}00267 \textcolor{keywordflow}{for} (\textcolor{keyword}{auto} idx = 0u; idx < syms.size(); ++idx) \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00268}00268 img = std::get<0>(syms[idx]);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00269}00269 sym = std::get<1>(syms[idx]);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00270}00270 size = std::get<2>(syms[idx]);} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00271}00271 \textcolor{keywordflow}{if} (sym-\/>has\_section())} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00272}00272 \textcolor{keywordflow}{return} \{\{img, sym, size\}\};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00273}00273 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00274}00274 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00275}00275 \textcolor{keywordflow}{if} (img \&\& sym)} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00276}00276 \textcolor{keywordflow}{return} \{\{img, sym, size\}\};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00277}00277 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00278}00278 \textcolor{keywordflow}{return} \{\};} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00279}00279 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00280}00280 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00281}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_a79c965ec0a996a936faae7f54b0e055e}{00281}} std::vector decomp\_t::rtns() \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00282}00282 \textcolor{keywordflow}{return} m\_rtns;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00283}00283 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00284}00284 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00285}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_aa728bde8ec1c5c28ec09f86adf427ae2}{00285}} std::vector decomp\_t::lib() \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00286}00286 \textcolor{keywordflow}{return} m\_lib;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00287}00287 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00288}00288 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00289}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_a81ae70b313a9ef24ea5d8f404699baef}{00289}} std::vector> decomp\_t::objs() \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00290}00290 \textcolor{keywordflow}{return} m\_objs;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00291}00291 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00292}00292 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00293}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_a8630f2ee0f4fb9516f5b20014e4c6120}{00293}} \mbox{\hyperlink{classtheo_1_1recomp_1_1symbol__table__t}{recomp::symbol\_table\_t}}* decomp\_t::syms() \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00294}00294 \textcolor{keywordflow}{return} m\_syms;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00295}00295 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00296}00296 } \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00297}\mbox{\hyperlink{classtheo_1_1decomp_1_1decomp__t_a860dddc3a5d12231b685dbaa12a0db06}{00297}} std::map\& decomp\_t::scn\_hash\_tbl() \{} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00298}00298 \textcolor{keywordflow}{return} m\_scn\_hash\_tbl;} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00299}00299 \}} \DoxyCodeLine{\Hypertarget{decomp_8cpp_source_l00300}00300 \} \textcolor{comment}{// namespace theo::decomp}} \end{DoxyCode}