| 205 | } |
| 206 | |
| 207 | bool TEView::Init() |
| 208 | { |
| 209 | BinaryReader reader(GetParentView(), LittleEndian); |
| 210 | struct TEImageHeader header; |
| 211 | Ref<Platform> platform; |
| 212 | |
| 213 | try |
| 214 | { |
| 215 | // Read image header and section headers |
| 216 | ReadTEImageHeader(reader, header); |
| 217 | ReadTEImageSectionHeaders(reader, header.numberOfSections); |
| 218 | m_headersOffset = header.strippedSize - EFI_TE_IMAGE_HEADER_SIZE; |
| 219 | |
| 220 | // m_imageBase represents the base of the original PE image (before headers were stripped), not the base of the |
| 221 | // TE image (bv.start) |
| 222 | m_imageBase = header.imageBase; |
| 223 | |
| 224 | // Set architecture and platform |
| 225 | auto settings = GetLoadSettings(GetTypeName()); |
| 226 | if (settings) |
| 227 | { |
| 228 | if (settings->Contains("loader.imageBase")) |
| 229 | { |
| 230 | uint64_t baseOverride = settings->Get<uint64_t>("loader.imageBase", this); |
| 231 | // Apply the headers offset adjustment to compute the base of the original PE image |
| 232 | m_imageBase = baseOverride - m_headersOffset; |
| 233 | } |
| 234 | |
| 235 | if (settings->Contains("loader.platform")) |
| 236 | platform = Platform::GetByName(settings->Get<string>("loader.platform", this)); |
| 237 | } |
| 238 | |
| 239 | if (!platform) |
| 240 | { |
| 241 | switch (header.machine) |
| 242 | { |
| 243 | case IMAGE_FILE_MACHINE_I386: |
| 244 | platform = Platform::GetByName("efi-x86"); |
| 245 | m_addressSize = 4; |
| 246 | break; |
| 247 | case IMAGE_FILE_MACHINE_AMD64: |
| 248 | platform = Platform::GetByName("efi-x86_64"); |
| 249 | m_addressSize = 8; |
| 250 | break; |
| 251 | case IMAGE_FILE_MACHINE_ARM64: |
| 252 | platform = Platform::GetByName("efi-aarch64"); |
| 253 | m_addressSize = 8; |
| 254 | break; |
| 255 | case IMAGE_FILE_MACHINE_ARM: |
| 256 | platform = Platform::GetByName("efi-armv7"); |
| 257 | m_addressSize = 4; |
| 258 | break; |
| 259 | case IMAGE_FILE_MACHINE_THUMB: |
| 260 | platform = Platform::GetByName("efi-thumb2"); |
| 261 | m_addressSize = 4; |
| 262 | break; |
| 263 | default: |
| 264 | LogError("TE platform '0x%x' is not supported", header.machine); |
no test coverage detected