102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
imports.c
Go to the documentation of this file.
1
/* Populate the retained English image's IAT for image-relative data references.
2
* Compiled game code uses the rebuilt executable's own Windows imports. */
3
#include "
imports.h
"
4
#include "
pcdogs/image/storage.h
"
5
#include <stdio.h>
6
7
// Original pcdogs.exe: no direct counterpart (decomp helper)
8
int
bind_imports
(
void
)
9
{
10
const
IMAGE_DOS_HEADER *dos = (
const
IMAGE_DOS_HEADER *)
data_storage
;
11
const
IMAGE_NT_HEADERS32 *pe = (
const
IMAGE_NT_HEADERS32 *)(
data_storage
+ dos->e_lfanew);
12
DWORD directory = pe->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
13
const
IMAGE_IMPORT_DESCRIPTOR *library = (
const
IMAGE_IMPORT_DESCRIPTOR *)(
data_storage
+ directory);
14
static
char
error_message[128];
15
16
/* The retained lookup tables are independent of the slots we overwrite. */
17
for
(; library->Name; ++library)
18
{
19
const
char
*name = (
const
char
*)
data_storage
+ library->Name;
20
HMODULE module = LoadLibraryA(name);
21
if
(!module)
22
{
23
snprintf(error_message,
sizeof
(error_message),
"Cannot load %s"
, name);
24
data_error
= error_message;
25
return
0;
26
}
27
28
const
IMAGE_THUNK_DATA32 *lookup = (
const
IMAGE_THUNK_DATA32 *)(
data_storage
+ library->OriginalFirstThunk);
29
IMAGE_THUNK_DATA32 *slot = (IMAGE_THUNK_DATA32 *)(
data_storage
+ library->FirstThunk);
30
for
(; lookup->u1.AddressOfData; ++lookup, ++slot)
31
{
32
/* Every import in this release has an IMAGE_IMPORT_BY_NAME record. */
33
const
IMAGE_IMPORT_BY_NAME *symbol = (
const
IMAGE_IMPORT_BY_NAME *)(
data_storage
+ lookup->u1.AddressOfData);
34
const
char
*symbol_name = (
const
char
*)symbol->Name;
35
FARPROC address = GetProcAddress(module, symbol_name);
36
if
(!address)
37
{
38
snprintf(error_message,
sizeof
(error_message),
"Missing %s!%s"
, name, symbol_name);
39
data_error
= error_message;
40
return
0;
41
}
42
slot->u1.Function = (DWORD)(uintptr_t)address;
43
}
44
}
45
return
1;
46
}
bind_imports
int bind_imports(void)
Definition
imports.c:8
imports.h
storage.h
data_error
const char * data_error
Definition
image_data.c:17
data_storage
unsigned char data_storage[0x16a2000]
Definition
image_data.c:16
src
runtime
imports.c
Generated by
1.17.0