Skip to content

Commit de7840a

Browse files
committed
Removed trailing whitespaces.
1 parent f76963b commit de7840a

File tree

5 files changed

+52
-52
lines changed

5 files changed

+52
-52
lines changed

MemoryModule.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ FinalizeSections(PMEMORYMODULE module)
140140
#else
141141
#define imageOffset 0
142142
#endif
143-
143+
144144
// loop through all sections and change access flags
145145
for (i=0; i<module->headers->FileHeader.NumberOfSections; i++, section++) {
146146
DWORD protect, oldProtect, size;
@@ -185,10 +185,10 @@ FinalizeSections(PMEMORYMODULE module)
185185
}
186186

187187
static void
188-
ExecuteTLS(PMEMORYMODULE module)
188+
ExecuteTLS(PMEMORYMODULE module)
189189
{
190190
unsigned char *codeBase = module->codeBase;
191-
191+
192192
PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_TLS);
193193
if (directory->VirtualAddress > 0) {
194194
PIMAGE_TLS_DIRECTORY tls = (PIMAGE_TLS_DIRECTORY) (codeBase + directory->VirtualAddress);
@@ -225,7 +225,7 @@ PerformBaseRelocation(PMEMORYMODULE module, SIZE_T delta)
225225
type = *relInfo >> 12;
226226
// the lower 12 bits define the offset
227227
offset = *relInfo & 0xfff;
228-
228+
229229
switch (type)
230230
{
231231
case IMAGE_REL_BASED_ABSOLUTE:
@@ -237,7 +237,7 @@ PerformBaseRelocation(PMEMORYMODULE module, SIZE_T delta)
237237
patchAddrHL = (DWORD *) (dest + offset);
238238
*patchAddrHL += (DWORD) delta;
239239
break;
240-
240+
241241
#ifdef _WIN64
242242
case IMAGE_REL_BASED_DIR64:
243243
patchAddr64 = (ULONGLONG *) (dest + offset);
@@ -325,7 +325,7 @@ static HCUSTOMMODULE _LoadLibrary(LPCSTR filename, void *userdata)
325325
if (result == NULL) {
326326
return NULL;
327327
}
328-
328+
329329
return (HCUSTOMMODULE) result;
330330
}
331331

@@ -389,7 +389,7 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
389389
return NULL;
390390
}
391391
}
392-
392+
393393
result = (PMEMORYMODULE)HeapAlloc(GetProcessHeap(), 0, sizeof(MEMORYMODULE));
394394
if (result == NULL) {
395395
SetLastError(ERROR_OUTOFMEMORY);
@@ -411,7 +411,7 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
411411
old_header->OptionalHeader.SizeOfHeaders,
412412
MEM_COMMIT,
413413
PAGE_READWRITE);
414-
414+
415415
// copy PE header to code
416416
memcpy(headers, dos_header, old_header->OptionalHeader.SizeOfHeaders);
417417
result->headers = (PIMAGE_NT_HEADERS)&((const unsigned char *)(headers))[dos_header->e_lfanew];
@@ -557,7 +557,7 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
557557
DWORD start;
558558
DWORD end;
559559
DWORD middle;
560-
560+
561561
if (!IS_INTRESOURCE(key) && key[0] == TEXT('#')) {
562562
// special case: resource id given as string
563563
TCHAR *endpos = NULL;
@@ -570,15 +570,15 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
570570
key = MAKEINTRESOURCE(tmpkey);
571571
}
572572
}
573-
573+
574574
// entries are stored as ordered list of named entries,
575575
// followed by an ordered list of id entries - we can do
576576
// a binary search to find faster...
577577
if (IS_INTRESOURCE(key)) {
578578
WORD check = (WORD) (POINTER_TYPE) key;
579579
start = resources->NumberOfNamedEntries;
580580
end = start + resources->NumberOfIdEntries;
581-
581+
582582
while (end > start) {
583583
WORD entryName;
584584
middle = (start + end) >> 1;
@@ -611,7 +611,7 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
611611
if (tmp == NULL) {
612612
break;
613613
}
614-
614+
615615
searchKey = (char *) tmp;
616616
}
617617
wcstombs(searchKey, resourceString->NameString, resourceString->Length);
@@ -632,8 +632,8 @@ static PIMAGE_RESOURCE_DIRECTORY_ENTRY _MemorySearchResourceEntry(
632632
free(searchKey);
633633
#endif
634634
}
635-
636-
635+
636+
637637
return result;
638638
}
639639

@@ -652,7 +652,7 @@ HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE module, LPCTSTR name, LPCTSTR typ
652652
SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
653653
return NULL;
654654
}
655-
655+
656656
if (language == DEFAULT_LANGUAGE) {
657657
// use language from current thread
658658
language = LANGIDFROMLCID(GetThreadLocale());
@@ -668,14 +668,14 @@ HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE module, LPCTSTR name, LPCTSTR typ
668668
SetLastError(ERROR_RESOURCE_TYPE_NOT_FOUND);
669669
return NULL;
670670
}
671-
671+
672672
typeResources = (PIMAGE_RESOURCE_DIRECTORY) (codeBase + directory->VirtualAddress + (foundType->OffsetToData & 0x7fffffff));
673673
foundName = _MemorySearchResourceEntry(rootResources, typeResources, name);
674674
if (foundName == NULL) {
675675
SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
676676
return NULL;
677677
}
678-
678+
679679
nameResources = (PIMAGE_RESOURCE_DIRECTORY) (codeBase + directory->VirtualAddress + (foundName->OffsetToData & 0x7fffffff));
680680
foundLanguage = _MemorySearchResourceEntry(rootResources, nameResources, (LPCTSTR) (POINTER_TYPE) language);
681681
if (foundLanguage == NULL) {
@@ -684,25 +684,25 @@ HMEMORYRSRC MemoryFindResourceEx(HMEMORYMODULE module, LPCTSTR name, LPCTSTR typ
684684
SetLastError(ERROR_RESOURCE_LANG_NOT_FOUND);
685685
return NULL;
686686
}
687-
687+
688688
foundLanguage = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (nameResources + 1);
689689
}
690-
690+
691691
return (codeBase + directory->VirtualAddress + (foundLanguage->OffsetToData & 0x7fffffff));
692692
}
693693

694694
DWORD MemorySizeofResource(HMEMORYMODULE module, HMEMORYRSRC resource)
695695
{
696696
PIMAGE_RESOURCE_DATA_ENTRY entry = (PIMAGE_RESOURCE_DATA_ENTRY) resource;
697-
697+
698698
return entry->Size;
699699
}
700700

701701
LPVOID MemoryLoadResource(HMEMORYMODULE module, HMEMORYRSRC resource)
702702
{
703703
unsigned char *codeBase = ((PMEMORYMODULE) module)->codeBase;
704704
PIMAGE_RESOURCE_DATA_ENTRY entry = (PIMAGE_RESOURCE_DATA_ENTRY) resource;
705-
705+
706706
return codeBase + entry->OffsetToData;
707707
}
708708

@@ -721,13 +721,13 @@ MemoryLoadStringEx(HMEMORYMODULE module, UINT id, LPTSTR buffer, int maxsize, WO
721721
if (maxsize == 0) {
722722
return 0;
723723
}
724-
724+
725725
resource = MemoryFindResourceEx(module, MAKEINTRESOURCE((id >> 4) + 1), RT_STRING, language);
726726
if (resource == NULL) {
727727
buffer[0] = 0;
728728
return 0;
729729
}
730-
730+
731731
data = MemoryLoadResource(module, resource);
732732
id = id & 0x0f;
733733
while (id--) {
@@ -738,7 +738,7 @@ MemoryLoadStringEx(HMEMORYMODULE module, UINT id, LPTSTR buffer, int maxsize, WO
738738
buffer[0] = 0;
739739
return 0;
740740
}
741-
741+
742742
size = data->Length;
743743
if (size >= (DWORD) maxsize) {
744744
size = maxsize;

doc/readme.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ stub that normally just displays an error message about the program not being
6060
able to be run from DOS mode.
6161

6262
Microsoft defines the DOS header as follows::
63-
63+
6464
typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
6565
WORD e_magic; // Magic number
6666
WORD e_cblp; // Bytes on last page of file
@@ -114,14 +114,14 @@ about symbols, etc::
114114

115115
.. _OptionalHeader:
116116

117-
The `OptionalHeader` contains informations about the *logical* format of the library,
117+
The `OptionalHeader` contains informations about the *logical* format of the library,
118118
including required OS version, memory requirements and entry points::
119119

120120
typedef struct _IMAGE_OPTIONAL_HEADER {
121121
//
122122
// Standard fields.
123123
//
124-
124+
125125
WORD Magic;
126126
BYTE MajorLinkerVersion;
127127
BYTE MinorLinkerVersion;
@@ -131,11 +131,11 @@ including required OS version, memory requirements and entry points::
131131
DWORD AddressOfEntryPoint;
132132
DWORD BaseOfCode;
133133
DWORD BaseOfData;
134-
134+
135135
//
136136
// NT additional fields.
137137
//
138-
138+
139139
DWORD ImageBase;
140140
DWORD SectionAlignment;
141141
DWORD FileAlignment;
@@ -247,25 +247,25 @@ When issuing the API call `LoadLibrary`, Windows basically performs these tasks:
247247

248248
2. Try to allocate a memory block of `PEHeader.OptionalHeader.SizeOfImage` bytes
249249
at position `PEHeader.OptionalHeader.ImageBase`.
250-
250+
251251
3. Parse section headers and copy sections to their addresses. The destination
252252
address for each section, relative to the base of the allocated memory block,
253253
is stored in the `VirtualAddress` attribute of the `IMAGE_SECTION_HEADER`
254254
structure.
255-
255+
256256
4. If the allocated memory block differs from `ImageBase`, various references in
257257
the code and/or data sections must be adjusted. This is called *Base
258258
relocation*.
259-
259+
260260
5. The required imports for the library must be resolved by loading the
261261
corresponding libraries.
262-
262+
263263
6. The memory regions of the different sections must be protected depending on
264264
the section's characteristics. Some sections are marked as *discardable*
265265
and therefore can be safely freed at this point. These sections normally
266266
contain temporary data that is only needed during the import, like the
267267
informations for the base relocation.
268-
268+
269269
7. Now the library is loaded completely. It must be notified about this by
270270
calling the entry point using the flag `DLL_PROCESS_ATTACH`.
271271

@@ -363,7 +363,7 @@ as follows::
363363
// -1 if bound, and real date\time stamp
364364
// in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
365365
// O.W. date/time stamp of DLL bound to (Old BIND)
366-
366+
367367
DWORD ForwarderChain; // -1 if no forwarders
368368
DWORD Name;
369369
DWORD FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
@@ -401,10 +401,10 @@ These flags can be one or a combination of
401401

402402
IMAGE_SCN_MEM_EXECUTE
403403
The section contains data that can be executed.
404-
404+
405405
IMAGE_SCN_MEM_READ
406406
The section contains data that is readable.
407-
407+
408408
IMAGE_SCN_MEM_WRITE
409409
The section contains data that is writeable.
410410

@@ -428,7 +428,7 @@ In addition the section flags above, the following can be added:
428428
IMAGE_SCN_MEM_DISCARDABLE
429429
The data in this section can be freed after the import. Usually this is
430430
specified for relocation data.
431-
431+
432432
IMAGE_SCN_MEM_NOT_CACHED
433433
The data in this section must not get cached by Windows. Add the bit
434434
flag `PAGE_NOCACHE` to the protection flags above.
@@ -444,7 +444,7 @@ to a process.
444444
The function at the entry point is defined as
445445

446446
::
447-
447+
448448
typedef BOOL (WINAPI *DllEntryProc)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
449449

450450
So the last code we need to execute is
@@ -497,7 +497,7 @@ To free the custom loaded library, perform the steps
497497

498498
DllEntryProc entry = (DllEntryProc)(baseAddress + PEHeader->OptionalHeader.AddressOfEntryPoint);
499499
(*entry)((HINSTANCE)baseAddress, DLL_PROCESS_ATTACH, 0);
500-
500+
501501
- Free external libraries used to resolve imports.
502502
- Free allocated memory.
503503

@@ -510,7 +510,7 @@ MemoryModule is a C-library that can be used to load a DLL from memory.
510510
The interface is very similar to the standard methods for loading of libraries::
511511

512512
typedef void *HMEMORYMODULE;
513-
513+
514514
HMEMORYMODULE MemoryLoadLibrary(const void *);
515515
FARPROC MemoryGetProcAddress(HMEMORYMODULE, const char *);
516516
void MemoryFreeLibrary(HMEMORYMODULE);

example/DllLoader/DllLoader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ void LoadFromFile(void)
1818
DWORD resourceSize;
1919
LPVOID resourceData;
2020
TCHAR buffer[100];
21-
21+
2222
HINSTANCE handle = LoadLibrary(DLL_FILE);
2323
if (handle == NULL)
2424
return;
2525

2626
addNumber = (addNumberProc)GetProcAddress(handle, "addNumbers");
2727
_tprintf(_T("From file: %d\n"), addNumber(1, 2));
28-
28+
2929
resourceInfo = FindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
3030
_tprintf(_T("FindResource returned 0x%p\n"), resourceInfo);
31-
31+
3232
resourceSize = SizeofResource(handle, resourceInfo);
3333
resourceData = LoadResource(handle, resourceInfo);
3434
_tprintf(_T("Resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
35-
35+
3636
LoadString(handle, 1, buffer, sizeof(buffer));
3737
_tprintf(_T("String1: %s\n"), buffer);
38-
38+
3939
LoadString(handle, 20, buffer, sizeof(buffer));
4040
_tprintf(_T("String2: %s\n"), buffer);
4141

@@ -53,7 +53,7 @@ void LoadFromMemory(void)
5353
DWORD resourceSize;
5454
LPVOID resourceData;
5555
TCHAR buffer[100];
56-
56+
5757
fp = _tfopen(DLL_FILE, _T("rb"));
5858
if (fp == NULL)
5959
{
@@ -80,14 +80,14 @@ void LoadFromMemory(void)
8080

8181
resourceInfo = MemoryFindResource(handle, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
8282
_tprintf(_T("MemoryFindResource returned 0x%p\n"), resourceInfo);
83-
83+
8484
resourceSize = MemorySizeofResource(handle, resourceInfo);
8585
resourceData = MemoryLoadResource(handle, resourceInfo);
8686
_tprintf(_T("Memory resource data: %ld bytes at 0x%p\n"), resourceSize, resourceData);
87-
87+
8888
MemoryLoadString(handle, 1, buffer, sizeof(buffer));
8989
_tprintf(_T("String1: %s\n"), buffer);
90-
90+
9191
MemoryLoadString(handle, 20, buffer, sizeof(buffer));
9292
_tprintf(_T("String2: %s\n"), buffer);
9393

example/DllLoader/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif
1515

1616
RM = rm
1717
CFLAGS = -Wall -g
18-
LDFLAGS =
18+
LDFLAGS =
1919

2020
ifdef UNICODE
2121
CFLAGS += -DUNICODE -D_UNICODE

example/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $(SUBDIRS):
1010
CLEANDIRS = $(SUBDIRS:%=clean-%)
1111

1212
clean: $(CLEANDIRS)
13-
$(CLEANDIRS):
13+
$(CLEANDIRS):
1414
$(MAKE) -C $(@:clean-%=%) clean
1515

1616
.PHONY: subdirs $(INSTALLDIRS)

0 commit comments

Comments
 (0)