Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
koemaeda committed Apr 10, 2015
0 parents commit cf4e031
Show file tree
Hide file tree
Showing 22 changed files with 3,701 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .gitignore
@@ -0,0 +1,36 @@
# Object files
*.o
*.ko
*.obj
*.elf
*.ppx
*.tag
dll/output
exe/output

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Guilherme Maeda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

96 changes: 96 additions & 0 deletions dll/dll.ppj
@@ -0,0 +1,96 @@
#
# PROJECT FILE generated by "Pelles C for Windows, version 8.00".
# WARNING! DO NOT EDIT THIS FILE.
#

POC_PROJECT_VERSION = 7.00#
POC_PROJECT_TYPE = 1#
POC_PROJECT_OUTPUTDIR = output#
POC_PROJECT_RESULTDIR = .#
POC_PROJECT_ARGUMENTS = #
POC_PROJECT_WORKPATH = .#
POC_PROJECT_EXECUTOR = ..\exe\sapgui_multilogon.exe#
POC_PROJECT_ZIPEXTRA = #
CC = pocc.exe#
AS = poasm.exe#
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -std:C11 -Tx86-coff -MT -Os -Ox -Ob1 -fp:precise -W1 -Gz -Ze#
ASFLAGS = -AIA32 -Gz#
RCFLAGS = #
LINKFLAGS = -subsystem:windows -machine:x86 -release -dll kernel32.lib user32.lib gdi32.lib#
SIGNFLAGS = -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -location:CU -store:MY -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#

#
# Build sapgui_multilogon.dll.
#
sapgui_multilogon.dll: \
output\asmserv.obj \
output\disasm.obj \
output\dllmain.obj \
output\hook.obj \
output\resources.res \
output\sapgui_hooks.obj
$(LINK) $(LINKFLAGS) -out:"$@" $**

#
# Build dllmain.obj.
#
output\dllmain.obj: \
dllmain.c \
dllmain.h \
resources.h \
sapgui_hooks.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build resources.res.
#
output\resources.res: \
resources.rc \
resources.h \
resources\logo.bmp
$(RC) $(RCFLAGS) "$!" -Fo"$@"

#
# Build hook.obj.
#
output\hook.obj: \
hook\hook.c \
hook\hook.h \
hook\ollyasm\disasm.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build asmserv.obj.
#
output\asmserv.obj: \
hook\ollyasm\asmserv.c \
hook\ollyasm\disasm.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build disasm.obj.
#
output\disasm.obj: \
hook\ollyasm\disasm.c \
hook\ollyasm\disasm.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build sapgui_hooks.obj.
#
output\sapgui_hooks.obj: \
sapgui_hooks.c \
dllmain.h \
hook\hook.h \
resources.h \
sapgui_hooks.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

.EXCLUDEDFILES:

.SILENT:
127 changes: 127 additions & 0 deletions dll/dllmain.c
@@ -0,0 +1,127 @@
#define WIN32_LEAN_AND_MEAN

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <windowsx.h>
#include "dllmain.h"
#include "sapgui_hooks.h"
#include "resources.h"

static HMODULE ghThisModule = NULL;
static HBITMAP ghBmpLogo = NULL;
static HBITMAP ghBmpLogoMask = NULL;


BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD iReason, void * pReserved) {
switch (iReason) {
case DLL_PROCESS_ATTACH:
ghThisModule = hInstance;

// Load our resources
LoadLogoBitmap();

// Install SAPGUI hooks //
if (! InstallSAPGUIHooks(hInstance)) {
MessageBox(NULL, APPLICATION_NAME" não foi inicializado corretamente.", APPLICATION_NAME, MB_ICONERROR);
ExitProcess(-1);
}

DisableThreadLibraryCalls (hInstance);
break;

case DLL_PROCESS_DETACH:
// Remove SAPGUI hooks //
if (! RemoveSAPGUIHooks())
MessageBox(NULL, APPLICATION_NAME" não foi finalizado corretamente.", APPLICATION_NAME, MB_ICONERROR);
break;
}

return TRUE;
}


void LoadLogoBitmap (void) {
BITMAP bm;

// Load logo bitmap
ghBmpLogo = LoadBitmap(ghThisModule, "BMP_LOGO");
GetObject(ghBmpLogo, sizeof(bm), &bm);

HDC hdcLogo = CreateCompatibleDC(NULL);
SelectBitmap(hdcLogo, ghBmpLogo);

COLORREF iBkColor = GetPixel(hdcLogo, 0, 0); // transparency color

// Print version information text
HFONT hFont = CreateFont(12, 0, 0, 0, FW_BLACK, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
DEFAULT_PITCH | FW_NORMAL, "Courier New");
SelectObject(hdcLogo, hFont);
SetTextAlign(hdcLogo, TA_CENTER);
int iTextX = (bm.bmWidth/2 - 1);
int iTextY = 35;

SetBkMode(hdcLogo, TRANSPARENT);

SetTextColor(hdcLogo, RGB(0,0,0)); // black
TextOut(hdcLogo, iTextX, iTextY, APPLICATION_VERSION, sizeof(APPLICATION_VERSION) - 1);

// Mask out the background
ghBmpLogoMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
HDC hdcLogoMask = CreateCompatibleDC(NULL);
SelectBitmap(hdcLogoMask, ghBmpLogoMask);

SetBkColor(hdcLogo, iBkColor); // get the mask color
BitBlt(hdcLogoMask, 0, 0, bm.bmWidth, bm.bmHeight, hdcLogo, 0, 0, SRCCOPY);

SetTextColor(hdcLogo, RGB(255,255,255));
SetBkColor(hdcLogo, RGB(0,0,0));
BitBlt(hdcLogo, 0, 0, bm.bmWidth, bm.bmHeight, hdcLogoMask, 0, 0, SRCAND);

// Cleanup
DeleteDC(hdcLogo);
DeleteDC(hdcLogoMask);
DeleteObject(hFont);
}


void PaintLogoBitmap(HWND hWindow, int iX, int iY) {
RECT stRect;
BITMAP bm;

// Calculate relative positions
GetWindowRect(hWindow, &stRect);
GetObject(ghBmpLogo, sizeof(bm), &bm);
if (iX < 0)
iX = stRect.right - stRect.left - bm.bmWidth + iX;
if (iY < 0)
iY = stRect.bottom - stRect.top - bm.bmHeight + iY;

// Paint the bitmap
HDC hDC = GetDC(hWindow);
HDC hdcMem = CreateCompatibleDC(NULL);
SelectBitmap(hdcMem, ghBmpLogoMask);
BitBlt(hDC, iX, iY, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCAND);
SelectBitmap(hdcMem, ghBmpLogo);
BitBlt(hDC, iX, iY, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);

DeleteDC(hdcMem);
}


DWORD ShowLastErrorMessage (void) {
char szMessage[512];
DWORD iErrorCode;

// Get the last message code //
iErrorCode = GetLastError ();

// Show the system error text //
if ( FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, iErrorCode, 0,
szMessage, sizeof (szMessage), NULL));
MessageBox (NULL, szMessage, APPLICATION_NAME, MB_ICONERROR);

return iErrorCode;
}
22 changes: 22 additions & 0 deletions dll/dllmain.h
@@ -0,0 +1,22 @@
#ifndef DLLMAIN_H_INCLUDED
#define DLLMAIN_H_INCLUDED

#define APPLICATION_NAME "SAPGUI MultiLogon"
#define APPLICATION_VERSION "v1.0.0"

#define SPLASH_WINDOW_LOGO_X 250
#define SPLASH_WINDOW_LOGO_Y 0

#define LOGO_BITMAP_WIDTH 200
#define LOGO_BITMAP_HEIGHT 200


BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD iReason, void * pReserved);

void LoadLogoBitmap (void);
void PaintLogoBitmap (HWND hWindow, int iX, int iY);

DWORD ShowLastErrorMessage (void);


#endif // DLLMAIN_H_INCLUDED

0 comments on commit cf4e031

Please sign in to comment.