| 164 | } |
| 165 | |
| 166 | BOOLEAN |
| 167 | ConvertElf ( |
| 168 | UINT8 **FileBuffer, |
| 169 | UINT32 *FileLength |
| 170 | ) |
| 171 | { |
| 172 | ELF_FUNCTION_TABLE ElfFunctions; |
| 173 | UINT8 EiClass; |
| 174 | |
| 175 | mFileBufferSize = *FileLength; |
| 176 | // |
| 177 | // Determine ELF type and set function table pointer correctly. |
| 178 | // |
| 179 | VerboseMsg ("Check Elf Image Header"); |
| 180 | EiClass = (*FileBuffer)[EI_CLASS]; |
| 181 | if (EiClass == ELFCLASS32) { |
| 182 | #ifndef JIEF_DEBUG |
| 183 | // Some globals have the same name and that confuses the debugger. |
| 184 | // So it's better not to link with Elf32Convert.o when debugging x64 |
| 185 | if (!InitializeElf32 (*FileBuffer, &ElfFunctions)) { |
| 186 | return FALSE; |
| 187 | } |
| 188 | #endif |
| 189 | } else if (EiClass == ELFCLASS64) { |
| 190 | if (!InitializeElf64 (*FileBuffer, &ElfFunctions)) { |
| 191 | return FALSE; |
| 192 | } |
| 193 | } else { |
| 194 | Error (NULL, 0, 3000, "Unsupported", "ELF EI_CLASS not supported."); |
| 195 | return FALSE; |
| 196 | } |
| 197 | |
| 198 | // |
| 199 | // Compute sections new address. |
| 200 | // |
| 201 | VerboseMsg ("Compute sections new address."); |
| 202 | ElfFunctions.ScanSections (); |
| 203 | |
| 204 | // |
| 205 | // Write and relocate sections. |
| 206 | // |
| 207 | VerboseMsg ("Write and relocate sections."); |
| 208 | if (!ElfFunctions.WriteSections (SECTION_TEXT)) { |
| 209 | return FALSE; |
| 210 | } |
| 211 | if (!ElfFunctions.WriteSections (SECTION_DATA)) { |
| 212 | return FALSE; |
| 213 | } |
| 214 | if (!ElfFunctions.WriteSections (SECTION_HII)) { |
| 215 | return FALSE; |
| 216 | } |
| 217 | |
| 218 | // |
| 219 | // Translate and write relocations. |
| 220 | // |
| 221 | VerboseMsg ("Translate and write relocations."); |
| 222 | ElfFunctions.WriteRelocations (); |
| 223 |
no test coverage detected