Add initial 'depends' sources from w00depends
[msysgit.git] / src / depends / image.c
blob737d6ae09774d0d5b9560f23a7632f90edf144a7
1 #include <windows.h>
2 #include <stdio.h>
3 #include "image.h"
5 PIMAGE_SECTION_HEADER GetSection(LOADED_IMAGE Image, DWORD RVA)
7 DWORD i;
8 PIMAGE_SECTION_HEADER pSection;
10 for (i = 0, pSection = Image.Sections; i < Image.NumberOfSections; i++, pSection++)
12 if (RVA >= pSection->VirtualAddress &&
13 RVA < pSection->VirtualAddress + pSection->Misc.VirtualSize)
15 return pSection;
18 return NULL;
21 BYTE *GetAddressFromRVA(LOADED_IMAGE Image, DWORD RVA)
23 int delta;
24 PIMAGE_SECTION_HEADER pSection;
26 if (!(pSection = GetSection(Image, RVA))) return NULL;
27 delta = (int)(pSection->VirtualAddress - pSection->PointerToRawData);
28 return (BYTE *)Image.MappedAddress + RVA - delta;