subr_pe.c (142387) | subr_pe.c (151703) |
---|---|
1/*- 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_pe.c 142387 2005-02-24 17:58:27Z wpaul $"); | 34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_pe.c 151703 2005-10-26 18:46:27Z wpaul $"); |
35 36/* 37 * This file contains routines for relocating and dynamically linking 38 * executable object code files in the Windows(r) PE (Portable Executable) 39 * format. In Windows, anything with a .EXE, .DLL or .SYS extention is 40 * considered an executable, and all such files have some structures in 41 * common. The PE format was apparently based largely on COFF but has 42 * mutated significantly over time. We are mainly concerned with .SYS files, --- 9 unchanged lines hidden (view full) --- 52#include <sys/types.h> 53#include <sys/errno.h> 54#ifdef _KERNEL 55#include <sys/systm.h> 56extern int ndis_strncasecmp(const char *, const char *, size_t); 57#define strncasecmp(a, b, c) ndis_strncasecmp(a, b, c) 58#else 59#include <stdio.h> | 35 36/* 37 * This file contains routines for relocating and dynamically linking 38 * executable object code files in the Windows(r) PE (Portable Executable) 39 * format. In Windows, anything with a .EXE, .DLL or .SYS extention is 40 * considered an executable, and all such files have some structures in 41 * common. The PE format was apparently based largely on COFF but has 42 * mutated significantly over time. We are mainly concerned with .SYS files, --- 9 unchanged lines hidden (view full) --- 52#include <sys/types.h> 53#include <sys/errno.h> 54#ifdef _KERNEL 55#include <sys/systm.h> 56extern int ndis_strncasecmp(const char *, const char *, size_t); 57#define strncasecmp(a, b, c) ndis_strncasecmp(a, b, c) 58#else 59#include <stdio.h> |
60#include <stddef.h> |
|
60#include <stdlib.h> 61#include <unistd.h> 62#include <string.h> 63#endif 64 65#include <compat/ndis/pe_var.h> 66 67static vm_offset_t pe_functbl_match(image_patch_table *, char *); --- 69 unchanged lines hidden (view full) --- 137 138 if (pe_is_nt_image(imgbase)) 139 return (EINVAL); 140 141 dos_hdr = (image_dos_header *)(imgbase); 142 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); 143 144 bcopy ((char *)&nt_hdr->inh_optionalhdr, (char *)hdr, | 61#include <stdlib.h> 62#include <unistd.h> 63#include <string.h> 64#endif 65 66#include <compat/ndis/pe_var.h> 67 68static vm_offset_t pe_functbl_match(image_patch_table *, char *); --- 69 unchanged lines hidden (view full) --- 138 139 if (pe_is_nt_image(imgbase)) 140 return (EINVAL); 141 142 dos_hdr = (image_dos_header *)(imgbase); 143 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); 144 145 bcopy ((char *)&nt_hdr->inh_optionalhdr, (char *)hdr, |
145 sizeof(image_optional_header)); | 146 nt_hdr->inh_filehdr.ifh_optionalhdrlen); |
146 147 return(0); 148} 149 150/* 151 * Return a copy of the file header. Contains the number of 152 * sections in this image. 153 */ --- 10 unchanged lines hidden (view full) --- 164 return(EINVAL); 165 166 if (pe_is_nt_image(imgbase)) 167 return (EINVAL); 168 169 dos_hdr = (image_dos_header *)imgbase; 170 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); 171 | 147 148 return(0); 149} 150 151/* 152 * Return a copy of the file header. Contains the number of 153 * sections in this image. 154 */ --- 10 unchanged lines hidden (view full) --- 165 return(EINVAL); 166 167 if (pe_is_nt_image(imgbase)) 168 return (EINVAL); 169 170 dos_hdr = (image_dos_header *)imgbase; 171 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); 172 |
173 /* 174 * Note: the size of the nt_header is variable since it 175 * can contain optional fields, as indicated by ifh_optionalhdrlen. 176 * However it happens we're only interested in fields in the 177 * non-variant portion of the nt_header structure, so we don't 178 * bother copying the optional parts here. 179 */ 180 |
|
172 bcopy ((char *)&nt_hdr->inh_filehdr, (char *)hdr, 173 sizeof(image_file_header)); 174 175 return(0); 176} 177 178/* 179 * Return the header of the first section in this image (usually --- 12 unchanged lines hidden (view full) --- 192 if (imgbase == 0 || hdr == NULL) 193 return(EINVAL); 194 195 if (pe_is_nt_image(imgbase)) 196 return (EINVAL); 197 198 dos_hdr = (image_dos_header *)imgbase; 199 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); | 181 bcopy ((char *)&nt_hdr->inh_filehdr, (char *)hdr, 182 sizeof(image_file_header)); 183 184 return(0); 185} 186 187/* 188 * Return the header of the first section in this image (usually --- 12 unchanged lines hidden (view full) --- 201 if (imgbase == 0 || hdr == NULL) 202 return(EINVAL); 203 204 if (pe_is_nt_image(imgbase)) 205 return (EINVAL); 206 207 dos_hdr = (image_dos_header *)imgbase; 208 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); |
200 sect_hdr = (image_section_header *)((vm_offset_t)nt_hdr + 201 sizeof(image_nt_header)); | 209 sect_hdr = IMAGE_FIRST_SECTION(nt_hdr); |
202 203 bcopy ((char *)sect_hdr, (char *)hdr, sizeof(image_section_header)); 204 205 return(0); 206} 207 208/* 209 * Return the number of sections in this executable, or 0 on error. --- 65 unchanged lines hidden (view full) --- 275 276 if (pe_get_optional_header(imgbase, &opt_hdr)) 277 return(0); 278 279 sections = pe_numsections(imgbase); 280 281 dos_hdr = (image_dos_header *)imgbase; 282 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); | 210 211 bcopy ((char *)sect_hdr, (char *)hdr, sizeof(image_section_header)); 212 213 return(0); 214} 215 216/* 217 * Return the number of sections in this executable, or 0 on error. --- 65 unchanged lines hidden (view full) --- 283 284 if (pe_get_optional_header(imgbase, &opt_hdr)) 285 return(0); 286 287 sections = pe_numsections(imgbase); 288 289 dos_hdr = (image_dos_header *)imgbase; 290 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); |
283 sect_hdr = (image_section_header *)((vm_offset_t)nt_hdr + 284 sizeof(image_nt_header)); | 291 sect_hdr = IMAGE_FIRST_SECTION(nt_hdr); |
285 286 /* 287 * The test here is to see if the RVA falls somewhere 288 * inside the section, based on the section's start RVA 289 * and its length. However it seems sometimes the 290 * virtual length isn't enough to cover the entire 291 * area of the section. We fudge by taking into account 292 * the section alignment and rounding the section length --- 41 unchanged lines hidden (view full) --- 334 335 if (pe_is_nt_image(imgbase)) 336 return (EINVAL); 337 338 sections = pe_numsections(imgbase); 339 340 dos_hdr = (image_dos_header *)imgbase; 341 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); | 292 293 /* 294 * The test here is to see if the RVA falls somewhere 295 * inside the section, based on the section's start RVA 296 * and its length. However it seems sometimes the 297 * virtual length isn't enough to cover the entire 298 * area of the section. We fudge by taking into account 299 * the section alignment and rounding the section length --- 41 unchanged lines hidden (view full) --- 341 342 if (pe_is_nt_image(imgbase)) 343 return (EINVAL); 344 345 sections = pe_numsections(imgbase); 346 347 dos_hdr = (image_dos_header *)imgbase; 348 nt_hdr = (image_nt_header *)(imgbase + dos_hdr->idh_lfanew); |
342 sect_hdr = (image_section_header *)((vm_offset_t)nt_hdr + 343 sizeof(image_nt_header)); | 349 sect_hdr = IMAGE_FIRST_SECTION(nt_hdr); |
344 345 for (i = 0; i < sections; i++) { 346 if (!strcmp ((char *)§_hdr->ish_name, name)) { 347 bcopy((char *)sect_hdr, (char *)hdr, 348 sizeof(image_section_header)); 349 return(0); 350 } else 351 sect_hdr++; --- 287 unchanged lines hidden --- | 350 351 for (i = 0; i < sections; i++) { 352 if (!strcmp ((char *)§_hdr->ish_name, name)) { 353 bcopy((char *)sect_hdr, (char *)hdr, 354 sizeof(image_section_header)); 355 return(0); 356 } else 357 sect_hdr++; --- 287 unchanged lines hidden --- |