Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Commit

Permalink
v1.0.0.18 - patch SDL_LogMessageV to EEexSDL_LogMessageV to allow log…
Browse files Browse the repository at this point in the history
…ging output to EEex.log file as well. Added PeakNamedPipe call in EEex.exe to check if anything to process thus preventing ReadFile from hanging once EE game has closed
  • Loading branch information
mrfearless committed Sep 6, 2019
1 parent d161f35 commit 74e82d8
Show file tree
Hide file tree
Showing 17 changed files with 621 additions and 306 deletions.
269 changes: 143 additions & 126 deletions EEex/EEex.asm

Large diffs are not rendered by default.

Binary file modified EEex/EEex.exe
Binary file not shown.
8 changes: 6 additions & 2 deletions EEex/EEex.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ EEEX_ALIGN TEXTEQU <ALIGN 16>
;------------------------------------------------------------------------------
AppName DB "EEex loader",0
szAppName DB "[EEex loader]",0
szAppVersion DB " v1.0.0.17",0
szAppVersion DB " v1.0.0.18",0
szEEexLoaderByfearless DB "EEex loader by fearless: github.com/mrfearless/EEexLoader",0
szEEexByBubb DB "EEex by Bubb: github.com/Bubb13/EEex",0
szCRLF DB 13,10,0
Expand Down Expand Up @@ -151,6 +151,10 @@ hWnd DD ?
startinfo STARTUPINFO <>
pi PROCESS_INFORMATION <>
wfd WIN32_FIND_DATA <>
ExitCode DD ?
ProcessExitCode DD ?
ThreadExitCode DD ?
hConOutput DD ?
hParentStdOut DD ?
hParentStdErr DD ?


20 changes: 10 additions & 10 deletions EEex/EEex.rap
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ Menu=1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0
[VerInf]
Nme=VERINF1
ID=1
FV=1.0.0.17
PV=1.0.0.17
FV=1.0.0.18
PV=1.0.0.18
VerOS=0x00000004
VerFT=0x00000001
VerLNG=0x00000409
VerCHS=0x000004B0
ProductVersion=1.0.0.17
ProductVersion=1.0.0.18
ProductName=EEex.exe
OriginalFilename=EEex.exe
LegalTrademarks=fearless
LegalCopyright=fearless
InternalName=EEex.exe
FileDescription=EEex loader
FileVersion=1.0.0.17
FileVersion=1.0.0.18
CompanyName=fearless
[Group]
Group=Assembly,Resources,Misc
Expand Down Expand Up @@ -99,16 +99,16 @@ AutoLoad=2,1,4,3,5
10="dwFileVerInfoSize"
[Size]
4=0,0,0,0,0
5=0,0,0,0,7961
5=0,0,0,0,8701
3=0,0,0,0,19
1=0,0,0,0,436
1=0,0,0,0,24328
2=0,0,0,0,1503
[Collapse]
3=
1=1107296770,,4194304
1=557842689,,524288
2=
4=
5=808256
5=6466048
[VersionControl]
Settings=1279
Milestones=129
Expand All @@ -119,7 +119,7 @@ MilestoneOnTime=2
MilestoneOnDate=0
MilestoneOnDateWhen=1
MilestoneOnDateStatus=0
MilestoneOnDateDate=5
MilestoneOnDateDate=6
MilestoneOnDateTimeYear=2019
MilestoneOnDateTimeMonth=1
MilestoneOnDateTimeDate=26
Expand All @@ -143,7 +143,7 @@ ProductVer2Range=0
ProductVer3Range=0
ProductVer4Range=0
[PTimer]
PTimer=67090707
PTimer=72276867
[GroupExpand]
GroupExpand=1,0,1,0
[BookMark]
Expand Down
81 changes: 51 additions & 30 deletions EEex/EEexConsole.asm
Original file line number Diff line number Diff line change
Expand Up @@ -236,50 +236,71 @@ EEEX_ALIGN
; Stop when there is no more data.
;------------------------------------------------------------------------------
ReadFromPipe PROC
LOCAL dwTotalBytesToRead:DWORD
LOCAL dwRead:DWORD
LOCAL dwWritten:DWORD
LOCAL hParentStdOut:DWORD
LOCAL hParentStdErr:DWORD
LOCAL bSuccess:DWORD
LOCAL nCount:DWORD

IFDEF DEBUG32
PrintText 'ReadFromPipe'
ENDIF

mov nCount, 0
mov bSuccess, FALSE
Invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hParentStdOut, eax
Invoke GetStdHandle, STD_ERROR_HANDLE
mov hParentStdErr, eax

.WHILE TRUE
Invoke GetExitCodeProcess, pi.hProcess, Addr ExitCode
.IF ExitCode != STILL_ACTIVE
ret
.ENDIF
Invoke ReadFile, hChildStd_OUT_Rd, Addr PIPEBUFFER, SIZEOF PIPEBUFFER, Addr dwRead, NULL
mov bSuccess, eax
.IF bSuccess == FALSE || dwRead == 0
Invoke GetExitCodeProcess, pi.hProcess, Addr ProcessExitCode
.IF eax == 0
IFDEF DEBUG32
PrintText 'GetExitCodeProcess error'
Invoke GetLastError
PrintDec eax
ENDIF
.ENDIF
.IF ProcessExitCode != STILL_ACTIVE
IFDEF DEBUG32
PrintText 'Exit from ReadFromPipe::GetExitCodeProcess'
ENDIF
ret
.ENDIF
.IF hLogFile != 0
Invoke WriteFile, hLogFile, Addr PIPEBUFFER, dwRead, Addr dwWritten, NULL
Invoke PeekNamedPipe, hChildStd_OUT_Rd, NULL, NULL, NULL, Addr dwTotalBytesToRead, NULL
.IF eax == 0
IFDEF DEBUG32
PrintText 'PeekNamedPipe Error'
Invoke GetLastError
PrintDec eax
ENDIF
.ENDIF
Invoke WriteFile, hParentStdOut, Addr PIPEBUFFER, dwRead, Addr dwWritten, NULL
mov bSuccess, eax
.IF bSuccess == FALSE
ret
.IF dwTotalBytesToRead != 0
IFDEF DEBUG32
PrintDec dwTotalBytesToRead
ENDIF
Invoke ReadFile, hChildStd_OUT_Rd, Addr PIPEBUFFER, SIZEOF PIPEBUFFER, Addr dwRead, NULL
mov bSuccess, eax
.IF bSuccess == FALSE || dwRead == 0
IFDEF DEBUG32
PrintText 'Exit from ReadFromPipe::ReadFile'
ENDIF
ret
.ENDIF
.IF hLogFile != 0
Invoke WriteFile, hLogFile, Addr PIPEBUFFER, dwRead, Addr dwWritten, NULL
.ENDIF
Invoke WriteFile, hParentStdOut, Addr PIPEBUFFER, dwRead, Addr dwWritten, NULL
mov bSuccess, eax
.IF bSuccess == FALSE
IFDEF DEBUG32
PrintText 'Exit from ReadFromPipe::WriteFile'
ENDIF
ret
.ENDIF
.ENDIF
; .IF dwWritten != 0
; Invoke FlushFileBuffers, hChildStd_OUT_Rd
; Invoke FlushFileBuffers, hParentStdOut
; .ENDIF
; Invoke FlushFileBuffers, hLogFile

; Invoke FlushFileBuffers, hChildStd_OUT_Wr
; Invoke FlushFileBuffers, hParentStdOut
; Invoke FlushFileBuffers, hParentStdErr
Invoke Sleep, 100
.ENDW
Expand Down
8 changes: 4 additions & 4 deletions EEex/Res/EEexVer.rc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define VERINF1 1
VERINF1 VERSIONINFO
FILEVERSION 1,0,0,17
PRODUCTVERSION 1,0,0,17
FILEVERSION 1,0,0,18
PRODUCTVERSION 1,0,0,18
FILEOS 0x00000004
FILETYPE 0x00000001
BEGIN
Expand All @@ -10,14 +10,14 @@ BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "fearless\0"
VALUE "FileVersion", "1.0.0.17\0"
VALUE "FileVersion", "1.0.0.18\0"
VALUE "FileDescription", "EEex loader\0"
VALUE "InternalName", "EEex.exe\0"
VALUE "LegalCopyright", "fearless\0"
VALUE "LegalTrademarks", "fearless\0"
VALUE "OriginalFilename", "EEex.exe\0"
VALUE "ProductName", "EEex.exe\0"
VALUE "ProductVersion", "1.0.0.17\0"
VALUE "ProductVersion", "1.0.0.18\0"
END
END
BLOCK "VarFileInfo"
Expand Down
86 changes: 71 additions & 15 deletions EEexDLL/EEex.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ option casemap:none
EEEX_ALIGN TEXTEQU <ALIGN 16>
EEEX_LOGGING EQU 1 ; comment out if we dont require logging
;EEEX_LUALIB EQU 1 ; comment out to use lua function found in EE game. Otherwise use some lua functions from static lib
EEEX_SDLINTERNAL EQU 1 ; comment out to use SDL_Log as found in EE game. Otherwise patch to use EEexSDL_Log

;
;DEBUG32 EQU 1
;IFDEF DEBUG32
; PRESERVEXMMREGS equ 1
Expand All @@ -39,7 +39,9 @@ include EEexPattern.asm ; Pattern array/table, function pointers, game globals,
include EEexIni.asm ; Ini functions, strings for sections and key names
include EEexLog.asm ; Log functions, strings for logging output
include EEexLua.asm ; EEexLuaInit, EEex_Init and other Lua functions used by EEex

IFDEF EEEX_SDLINTERNAL
include EEexPrint.asm ; SDL_Log redirection functions
ENDIF

.CODE

Expand Down Expand Up @@ -251,19 +253,19 @@ EEexInitDll PROC USES EBX


;--------------------------------------------------------------------------
; Apply Patch Stage (Call EEexLuaInit) - At PatchLocation In EE Game
; Apply luaL_loadstring Patch Stage (Call EEexLuaInit) - At PatchLocation In EE Game
;--------------------------------------------------------------------------
Invoke EEexPatchLocation
mov PatchLocation, eax
.IF PatchLocation != 0
Invoke EEexApplyCallPatch, PatchLocation ; (call EEexLuaInit)
Invoke EEexApplyCallPatch, PatchLocation, Addr EEexLuaInit, FALSE ; (call EEexLuaInit)
.IF eax == TRUE ; Patch Success! - Write status to log and exit EEex.dll
IFDEF DEBUG32
PrintText 'EEexApplyCallPatch Success'
PrintText 'EEexApplyCallPatch::luaL_loadstring Success'
ENDIF
IFDEF EEEX_LOGGING
.IF gEEexLog >= LOGLEVEL_DETAIL
Invoke LogMessage, CTEXT("EEexApplyCallPatch:"), LOG_INFO, 0
Invoke LogMessage, CTEXT("EEexApplyCallPatch - [call luaL_loadstring] to [call EEexLuaInit]:"), LOG_INFO, 0
Invoke LogMessageAndHexValue, CTEXT("Applied patch at"), PatchLocation
Invoke LogMessage, 0, LOG_CRLF, 0
.ENDIF
Expand All @@ -275,11 +277,11 @@ EEexInitDll PROC USES EBX
;------------------------------------------------------------------
.ELSE ; Patch Failure! - Write status to log and exit EEex.dll
IFDEF DEBUG32
PrintText 'EEexApplyCallPatch Failure'
PrintText 'EEexApplyCallPatch::luaL_loadstring Failure'
ENDIF
IFDEF EEEX_LOGGING
.IF gEEexLog > LOGLEVEL_NONE
Invoke LogMessage, CTEXT("EEexApplyCallPatch:"), LOG_ERROR, 0
Invoke LogMessage, CTEXT("EEexApplyCallPatch::luaL_loadstring:"), LOG_ERROR, 0
Invoke LogMessageAndHexValue, CTEXT("Failed to apply patch at"), PatchLocation
Invoke LogMessage, 0, LOG_CRLF, 0
Invoke LogClose
Expand Down Expand Up @@ -309,13 +311,54 @@ EEexInitDll PROC USES EBX
ret ; Exit EEexInitDll
.ENDIF
;--------------------------------------------------------------------------
; Finished Apply Patch Stage
; Finished luaL_loadstring Apply Patch Stage
;--------------------------------------------------------------------------


;--------------------------------------------------------------------------
; Apply SDL_LogMessageV Patch Stage (Call EEexSDL_LogMessageV) - At F_SDL_Log In EE Game
;--------------------------------------------------------------------------
IFDEF EEEX_SDLINTERNAL
mov eax, F_SDL_Log
add eax, 14
mov PatchSDL_LogMessageV, eax
Invoke EEexApplyCallPatch, PatchSDL_LogMessageV, Addr EEexSDL_LogMessageV, FALSE ; (call EEexSDL_LogMessageV in SDL_Log)
;Invoke EEexApplyCallPatch, F_SDL_Log, Addr EEexSDL_Log, TRUE ; (call EEexSDL_LogMessageV in SDL_Log)
.IF eax == TRUE ; Patch Success! - Write status to log and exit EEex.dll
IFDEF DEBUG32
PrintText 'EEexApplyCallPatch::SDL_LogMessageV Success'
ENDIF
IFDEF EEEX_LOGGING
.IF gEEexLog >= LOGLEVEL_DETAIL
Invoke LogMessage, CTEXT("EEexApplyCallPatch - [call SDL_LogMessageV] to [call EEexSDL_LogMessageV]:"), LOG_INFO, 0
Invoke LogMessageAndHexValue, CTEXT("Applied patch at"), PatchSDL_LogMessageV
Invoke LogMessage, 0, LOG_CRLF, 0
.ENDIF
ENDIF
.ELSE ; Patch Failure! - Write status to log and exit EEex.dll
IFDEF DEBUG32
PrintText 'EEexApplyCallPatch::SDL_LogMessageV Failure'
ENDIF
IFDEF EEEX_LOGGING
.IF gEEexLog > LOGLEVEL_NONE
Invoke LogMessage, CTEXT("EEexApplyCallPatch::SDL_LogMessageV:"), LOG_ERROR, 0
Invoke LogMessageAndHexValue, CTEXT("Failed to apply patch at"), PatchSDL_LogMessageV
Invoke LogMessage, 0, LOG_CRLF, 0
.ENDIF
ENDIF
.ENDIF
ENDIF
;--------------------------------------------------------------------------
; Finished SDL_Log Apply Patch Stage
;--------------------------------------------------------------------------


Invoke EEexFunctionAddresses ; get function address for lua functions etc
Invoke EEexVariableValues ; get pointers to game globals
Invoke EEexLogInformation, INFO_ADDRESSES ; lists function and resolved global addresses


;--------------------------------------------------------------------------
; EEex.DLL EXITS HERE - Execution continues with EE game
;--------------------------------------------------------------------------
Expand Down Expand Up @@ -395,6 +438,8 @@ EEexInitGlobals PROC USES EBX
mov F_SDL_free, eax
Invoke GetProcAddress, 0, Addr szSDL_LogExport
mov F_SDL_Log, eax
Invoke GetProcAddress, 0, Addr szSDL_vsnprintfExport
mov F_SDL_vsnprintf, eax
IFDEF DEBUG32
PrintText 'Api calls and exports'
Expand Down Expand Up @@ -1554,10 +1599,11 @@ EEEX_ALIGN
; EEexApplyCallPatch - Patches EE Game to Call EEexLuaInit
; Returns: TRUE if succesful or FALSE otherwise.
;------------------------------------------------------------------------------
EEexApplyCallPatch PROC USES EBX ESI dwAddressToPatch:DWORD
EEexApplyCallPatch PROC USES EBX ESI dwAddressToPatch:DWORD, dwRedirectToFunction:DWORD, bReturn:DWORD
LOCAL dwDistance:DWORD
LOCAL dwOldProtect:DWORD

LOCAL LenToPatch:DWORD
IFDEF DEBUG32
PrintText 'EEexApplyCallPatch'
ENDIF
Expand All @@ -1567,7 +1613,7 @@ EEexApplyCallPatch PROC USES EBX ESI dwAddressToPatch:DWORD
ret
.ENDIF

lea eax, EEexLuaInit
mov eax, dwRedirectToFunction
mov ebx, dwAddressToPatch
sub eax, ebx
.IF eax == 0
Expand All @@ -1584,16 +1630,26 @@ EEexApplyCallPatch PROC USES EBX ESI dwAddressToPatch:DWORD
.ENDIF
mov dwDistance, eax

.IF bReturn == TRUE
mov LenToPatch, 6 ; call xxxxxxxx followed by ret C3h
.ELSE
mov LenToPatch, 5 ; call xxxxxxxx
.ENDIF

; VirtualProtect to write to address
Invoke VirtualProtectEx, hEEGameProcess, dwAddressToPatch, 5, PAGE_EXECUTE_READWRITE, Addr dwOldProtect
Invoke VirtualProtectEx, hEEGameProcess, dwAddressToPatch, LenToPatch, PAGE_EXECUTE_READWRITE, Addr dwOldProtect
.IF eax != NULL
mov esi, dwAddressToPatch
mov byte ptr [esi], 0E8h ; call opcode
inc esi
mov eax, dwDistance
mov [esi], eax
mov [esi], eax ; call offset/distance
.IF bReturn == TRUE
add esi, 4
mov byte ptr [esi], 0C3h ; ret opcode
.ENDIF
Invoke FlushInstructionCache, hEEGameProcess, NULL, NULL
Invoke VirtualProtectEx, hEEGameProcess, dwAddressToPatch, 5, dwOldProtect, Addr dwOldProtect
Invoke VirtualProtectEx, hEEGameProcess, dwAddressToPatch, LenToPatch, dwOldProtect, Addr dwOldProtect
mov eax, TRUE
.ELSE
mov eax, FALSE
Expand Down
Binary file modified EEexDLL/EEex.dll
Binary file not shown.

0 comments on commit 74e82d8

Please sign in to comment.