Skip to content

Commit

Permalink
/nodefaultlib applied in dlls
Browse files Browse the repository at this point in the history
  • Loading branch information
w3lh committed Mar 31, 2016
1 parent 22d2cec commit 5998503
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 80 deletions.
2 changes: 1 addition & 1 deletion dll/dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void debug(char *message, ...) {

memset(buf, 0, sizeof(buf));
va_start(args, message);
vsnprintf(buf, sizeof(buf) - 1, message, args);
wvsprintfA(buf, message, args);

file = CreateFile((LPCWSTR)DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
SetFilePointer(file, 0, 0, FILE_END);
Expand Down
18 changes: 14 additions & 4 deletions dll/dll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling />
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -172,6 +172,7 @@
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -181,12 +182,13 @@
<BaseAddress>0x76290000</BaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_SRP3|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;USE_SRP3;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling />
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -195,6 +197,7 @@
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -204,12 +207,13 @@
<BaseAddress>0x76290000</BaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_SRP3|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;USE_SRP3;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling />
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -218,6 +222,7 @@
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -227,12 +232,13 @@
<BaseAddress>0x76290000</BaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DLL_EXPORTS;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling />
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand All @@ -241,6 +247,7 @@
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -251,6 +258,7 @@
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>true</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='WIN98_Release|Win32'">
Expand Down Expand Up @@ -283,13 +291,15 @@
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="functions.c" />
<ClCompile Include="nodefaultlib.c" />
<ClCompile Include="w3lh.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release_SRP3|Win32'">CompileAsC</CompileAs>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="dep.h" />
<ClInclude Include="functions.h" />
<ClInclude Include="nodefaultlib.h" />
<ClInclude Include="patches.h" />
<ClInclude Include="pstdint.h" />
<ClInclude Include="resource.h" />
Expand Down
2 changes: 2 additions & 0 deletions dll/functions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#if !defined(_FUNCTIONS_H)
#define _FUNCTIONS_H

#include "nodefaultlib.h"

#if !defined(USE_SRP3)

#include "pstdint.h"
Expand Down
45 changes: 45 additions & 0 deletions dll/nodefaultlib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "nodefaultlib.h"
#define DEBUG_FILE L"debug.log"

void * __cdecl memset(void *pTarget, int value, size_t cbTarget)
{
unsigned char *p = (unsigned char *)(pTarget);
while (cbTarget-- > 0) {
*p++ = (unsigned char)(value);
}
return pTarget;
}
int __cdecl memcmp(void const* _Buf1, void const* _Buf2, size_t _Size)
{
unsigned char u1, u2;
unsigned char *b1 = (unsigned char *)_Buf1;
unsigned char *b2 = (unsigned char *)_Buf2;

for (; _Size--; b1++, b2++) {
u1 = *b1;
u2 = *b2;
if (u1 != u2) {
return (u1 - u2);
}
}
return 0;
}

/* Print a log message */
void debug(char *message, ...) {
#ifdef DEBUG
DWORD temp;
HANDLE file;
va_list args;
char buf[1024];

memset(buf, 0, sizeof(buf));
va_start(args, message);
wvsprintfA(buf, message, args);

file = CreateFile(DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
SetFilePointer(file, 0, 0, FILE_END);
WriteFile(file, buf, (DWORD)strlen(buf), &temp, NULL);
CloseHandle(file);
#endif
}
12 changes: 12 additions & 0 deletions dll/nodefaultlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#pragma comment(linker, "/entry:DllMain")
#include <windows.h>
#include <stdio.h>
#include <Winternl.h>
#include <winnt.h>
#include <Shlwapi.h>
#pragma intrinsic(strlen)
#pragma function(memset, memcmp)
int __cdecl memcmp(void const* _Buf1, void const* _Buf2, size_t _Size);
void * __cdecl memset(void *pTarget, int value, size_t cbTarget);
void __cdecl debug(char *, ...);
50 changes: 16 additions & 34 deletions dll/w3lh.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "functions.h"

//#define DEBUG /* undef to disable logging */
#define DEBUG_FILE "debug.log"
#define LATENCY_FILE "latency.txt"
#define GAME_DLL_NAME "Game.dll"
#define GAME_MAIN "GameMain"
Expand All @@ -61,40 +60,23 @@ FARPROC real_game_main; /* pointer to the real "Game.dll" GameMain function */
HMODULE game_dll_base; /* pointer to base of the real "Game.dll" */
HANDLE app_process; /* handle to the war3.exe process */

/* Print a log message */
void debug(char *message, ...) {
#ifdef DEBUG
DWORD temp;
HANDLE file;
va_list args;
char buf[1024];

memset(buf, 0, sizeof(buf));
va_start(args, message);
vsnprintf(buf, sizeof(buf) - 1, message, args);

file = CreateFile(DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
SetFilePointer(file, 0, 0, FILE_END);
WriteFile(file, buf, (DWORD)strlen(buf), &temp, NULL);
char read_latency() {
HFILE file;
OFSTRUCT ofFile;
char buf[4];
int lt, readNum;
file = OpenFile(LATENCY_FILE, &ofFile, OF_READ);
if (file == HFILE_ERROR)
return DEFAULT_LATENCY;
ReadFile(file, buf, 3, &readNum, NULL);
CloseHandle(file);
#endif
buf[3] = '\0';
lt = StrToInt(buf);
if (lt > 255 || lt < 30)
return DEFAULT_LATENCY;
return (char)lt;
}


char read_latency ( ) {
FILE *file;
int lt;
file = fopen ( LATENCY_FILE, "rt");
if ( !file)
return DEFAULT_LATENCY;
fscanf( file, "%d", &lt);
fclose( file);
if ( lt > 255 || lt < 30)
return DEFAULT_LATENCY;
return (char )lt;
}


/* write patch to memory */
int apply_patch(char *ptr, t_patch *patch) {
DWORD temp, oldprot, newprot = PAGE_EXECUTE_READWRITE;
Expand Down Expand Up @@ -264,7 +246,7 @@ int patch() {
MessageBox(NULL, GAME_DLL_LOAD_ERROR, "[lib] Patch Error (w3lh.dll)", MB_OK);
return ERR_GAME_DLL_LOAD;
}
debug("base: 0x%08X", game_dll_base);
debug("base: 0x%08X\r\n", game_dll_base);

real_game_main = GetProcAddress(game_dll_base, GAME_MAIN);
if(!real_game_main) {
Expand All @@ -273,7 +255,7 @@ int patch() {
}
/* apply delay reduction patches and adRemove patch */
delay_reducer_patch_data[0] = read_latency( );
debug( "Latency set to: %hhu ms\r\n", ( unsigned char)(delay_reducer_patch_data[0]));
debug( "Latency set to: %hu ms\r\n", ( unsigned char)(delay_reducer_patch_data[0]));
apply_patches((char *)game_dll_base, unimportant_patches, GAME_DLL_SIZE);

#if ! defined USE_SRP3
Expand Down
8 changes: 4 additions & 4 deletions dll/w3lh.rc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
//

1 VERSIONINFO
FILEVERSION 1,4,0,0
PRODUCTVERSION 1,4,0,0
FILEVERSION 1,4,0,1
PRODUCTVERSION 1,4,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -43,12 +43,12 @@ BEGIN
VALUE "Comments", "Latest versions of this loader and other tools @ http://keres.myftp.org"
VALUE "CompanyName", "w3l"
VALUE "FileDescription", "Warcraft 3 Game.dll hook for PvPGN"
VALUE "FileVersion", "1.4.0.0"
VALUE "FileVersion", "1.4.0.1"
VALUE "InternalName", "w3lh"
VALUE "LegalCopyright", "(c) 2008 Keres / Rupan / phatdeeva"
VALUE "OriginalFilename", "w3lh.dll"
VALUE "ProductName", "w3l"
VALUE "ProductVersion", "1.4.0.0"
VALUE "ProductVersion", "1.4.0.1"
END
END
BLOCK "VarFileInfo"
Expand Down
2 changes: 1 addition & 1 deletion dll_27a/dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void debug(char *message, ...) {

memset(buf, 0, sizeof(buf));
va_start(args, message);
vsnprintf(buf, sizeof(buf) - 1, message, args);
wvsprintfA(buf, message, args);

file = CreateFile((LPCWSTR)DEBUG_FILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
SetFilePointer(file, 0, 0, FILE_END);
Expand Down
1 change: 1 addition & 0 deletions dll_27a/dep.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef DEP_H__
#define DEP_H__
#include <windows.h>
#include "nodefaultlib.h"
enum DepEnforcement {
// DEP is completely disabled.
DEP_DISABLED,
Expand Down
Loading

0 comments on commit 5998503

Please sign in to comment.