| 1165 | } |
| 1166 | |
| 1167 | void |
| 1168 | CElf::Copy(const CElf& celf) |
| 1169 | { |
| 1170 | if (!celf.m_Initialized) |
| 1171 | { |
| 1172 | return; |
| 1173 | } |
| 1174 | |
| 1175 | // This is a utility with below... |
| 1176 | |
| 1177 | // Copy the image header to get the ones that we care about. |
| 1178 | m_Header = celf.m_Header; |
| 1179 | size_t numberSections = celf.m_Sections.size(); |
| 1180 | m_Sections.resize(numberSections); |
| 1181 | |
| 1182 | // Iterate over celf's sections. |
| 1183 | // Copy, but don't populate the string tables. |
| 1184 | // Copy ordinary sections. |
| 1185 | // Make a map from celf's sections to their index. |
| 1186 | map<const CElfSection*, size_t> sectionMap; |
| 1187 | |
| 1188 | for (size_t i = 0; i < numberSections; ++i) |
| 1189 | { |
| 1190 | sectionMap[celf.m_Sections[i]] = i; |
| 1191 | |
| 1192 | CElfSection* section; |
| 1193 | |
| 1194 | switch (celf.m_Sections[i]->GetType()) |
| 1195 | { |
| 1196 | case SHT_SYMTAB: |
| 1197 | m_SymbolTable = new CElfSymbolTable(); |
| 1198 | section = m_SymbolTable; |
| 1199 | break; |
| 1200 | |
| 1201 | case SHT_STRTAB: |
| 1202 | if (celf.m_Sections[i] == celf.m_SectionHeaderStringTable) |
| 1203 | { |
| 1204 | m_SectionHeaderStringTable = new CElfStringTable(); |
| 1205 | section = m_SectionHeaderStringTable; |
| 1206 | } |
| 1207 | else |
| 1208 | { |
| 1209 | section = new CElfStringTable(); |
| 1210 | } |
| 1211 | |
| 1212 | break; |
| 1213 | |
| 1214 | default: |
| 1215 | section = new CElfSection(); |
| 1216 | const vector<char>& data = celf.m_Sections[i]->GetData(); |
| 1217 | section->SetData(data); |
| 1218 | break; |
| 1219 | } |
| 1220 | |
| 1221 | m_Sections[i] = section; |
| 1222 | |
| 1223 | // I could just copy celf.m_Sections[i]->m_Header, but that's ugly. |
| 1224 | // Copy just the fields that are maintained through the section's lifetime. |
nothing calls this directly
no test coverage detected