Get the section of some rva.
| 181 | |
| 182 | // Get the section of some rva. |
| 183 | BOOL cobf::section_of_rva(DWORD rva, PIMAGE_SECTION_HEADER& sec) |
| 184 | { |
| 185 | // Get the sections. |
| 186 | PIMAGE_DOS_HEADER dos_hdr = (PIMAGE_DOS_HEADER)this->pe_rawf.data(); |
| 187 | PIMAGE_NT_HEADERS nt_hdrs = (PIMAGE_NT_HEADERS)&this->pe_rawf[dos_hdr->e_lfanew]; |
| 188 | PIMAGE_SECTION_HEADER c_sec = (PIMAGE_SECTION_HEADER)&this->pe_rawf[dos_hdr->e_lfanew + |
| 189 | sizeof(nt_hdrs->Signature) + sizeof(nt_hdrs->FileHeader) + |
| 190 | nt_hdrs->FileHeader.SizeOfOptionalHeader]; |
| 191 | |
| 192 | // Loop on the sections. |
| 193 | WORD n_secs = nt_hdrs->FileHeader.NumberOfSections; |
| 194 | while (n_secs--) |
| 195 | { |
| 196 | // Check if not contained. |
| 197 | if (rva < (size_t)c_sec->VirtualAddress || rva >= (size_t)c_sec->VirtualAddress + |
| 198 | c_sec->Misc.VirtualSize) |
| 199 | { |
| 200 | // Move to the next one. |
| 201 | c_sec++; |
| 202 | continue; |
| 203 | }; |
| 204 | |
| 205 | // Found. |
| 206 | sec = c_sec; |
| 207 | return TRUE; |
| 208 | }; |
| 209 | |
| 210 | // Not found. |
| 211 | return FALSE; |
| 212 | }; |
| 213 | |
| 214 | // Verify and get the dos header. |
| 215 | BOOL cobf::get_dos_header(PIMAGE_DOS_HEADER& dos_hdr) |
no outgoing calls
no test coverage detected