forked from msysgit/msysgit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.c
More file actions
30 lines (25 loc) · 696 Bytes
/
image.c
File metadata and controls
30 lines (25 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <windows.h>
#include <stdio.h>
#include "image.h"
PIMAGE_SECTION_HEADER GetSection(LOADED_IMAGE Image, DWORD RVA)
{
DWORD i;
PIMAGE_SECTION_HEADER pSection;
for (i = 0, pSection = Image.Sections; i < Image.NumberOfSections; i++, pSection++)
{
if (RVA >= pSection->VirtualAddress &&
RVA < pSection->VirtualAddress + pSection->Misc.VirtualSize)
{
return pSection;
}
}
return NULL;
}
BYTE *GetAddressFromRVA(LOADED_IMAGE Image, DWORD RVA)
{
int delta;
PIMAGE_SECTION_HEADER pSection;
if (!(pSection = GetSection(Image, RVA))) return NULL;
delta = (int)(pSection->VirtualAddress - pSection->PointerToRawData);
return (BYTE *)Image.MappedAddress + RVA - delta;
}