Bonjour,

Aprés avoir essayer de compiler certaines sources d'une DLL, qui se passe sans aucun probleme ni erreurs, les fonctions ne marche toujours pas et n'execute pas ce qui leur est demandé.

J'utilise CODE::BLOCK 1.0 Comme IDE & GCC comme compilateur.

Donc, premierement voici la partie de la source concerné :

Code etx.h : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*  pragmas  */
#pragma once
#pragma comment(lib, "opengl32.lib")
#pragma warning(disable: 4311)
#pragma warning(disable: 4312)

/*  includes  */
#include <windows.h>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <tlhelp32.h>
#include <math.h>
#include <gl/gl.h>
#include "CGLDraw.h"
#include "CGLModelRec.h"
#include "CGLHook.h"
#include "consts.h"

/* main etx struct */
typedef struct etx_s
{
	shader_t	shader;
	int			curTexture;
	char		*curShader;
	GLvoid		*curVertexPtr;
} etx_t;

/*  dllmain.cpp  */
extern CGLDraw gldraw;
extern CGLModelRec glmodelrec;
extern CGLHook glhook;
extern etx_t etx;

/*  glhooks.cpp  */
typedef void (__stdcall *glBindTexture_t)(GLenum target, GLuint texture);
typedef void (__stdcall *glDrawElements_t)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
typedef void (__stdcall *glVertexPointer_t)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
typedef void (__stdcall *glViewport_t)(GLint x, GLint y, GLsizei width, GLsizei height);

extern glBindTexture_t		o_glBindTexture;
extern glDrawElements_t		o_glDrawElements;
extern glVertexPointer_t	o_glVertexPointer;
extern glViewport_t			o_glViewport;

void __stdcall h_glBindTexture(GLenum target, GLuint texture);
void __stdcall h_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
void __stdcall h_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
void __stdcall h_glViewport(GLint x, GLint y, GLsizei width, GLsizei height);

/*  log.cpp  */
void log(const char *fmt, ...);
void logs(const char *fmt, ...);

Code log.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "etx.h"


void log(const char *fmt, ...)
{
    static int repcount = 0;
    char logbuf[4096];
    char timestr[32];
    va_list va;
    time_t t;
    tm ttm;
    FILE *f;

    va_start(va, fmt);
    printf(logbuf, sizeof(logbuf), fmt, va);
    va_end (va);

//    time(&t);
//    localtime(&ttm, &t);
//    strftime(timestr, sizeof(timestr), "[%H:%M:%S]", &ttm);

    fopen(ETC_LOGFILE, "a" );
    fprintf(f, "%s", logbuf);
    fclose(f);
}

void logs(const char *fmt, ...)
{
    static int repcount = 0;
    char logbuf[4096];
    va_list va;
    FILE *f;

    va_start(va, fmt);
    printf(logbuf, sizeof(logbuf), fmt, va);
    va_end (va);

    fopen(ETC_LOGFILE, "a");
    fprintf(f, "%s", logbuf);
    fclose(f);
}

Le code concernant la récuperation du temps a etait ignoré car je n'ai pas réussi a le fair marché :s

Code consts.h : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
/* pragmas */
#pragma once

/* etx stuff */
#define ETC_DEBUG
#define ETC_LOGFILE				"ETCLOG.txt"
#define ETX_THREAD(thread)		(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread, 0, 0, 0))
#define ETX_MSG(msg)			(MessageBox(NULL, msg, "Etx Message", MB_OK))

Code CGLHook.cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "etx.h"

DWORD CGLHook::Hook(char *szFuncName, void *pFuncHook)
{
	DWORD dwFuncAddr = 0;
	DWORD dwFuncTblAddr = 0;
	DWORD dwFuncNativeOrig = 0;

	if(!bInit || !pFuncHook) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to hook %s, but not initted, or no hook function provided", szFuncName);
		#endif
		return 0;
	}

	if(!(dwFuncAddr = (DWORD)GetProcAddress(hOpengl32, szFuncName))) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to hook %s, but function not found", szFuncName);
		#endif
		return 0;
	}

	if(!(dwFuncTblAddr = GetTblOffset(dwFuncAddr))) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to hook %s, but failed to find a table offset/address", szFuncName);
		#endif
		return 0;
	}

	if(!(dwFuncNativeOrig = HookGLNative(dwFuncTblAddr, pFuncHook))) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to hook %s, but couldn't retrieve a pointer to the native function", szFuncName);
		#endif
		return 0;
	}

	return dwFuncNativeOrig;
}

bool CGLHook::UnHook(char *szFuncName, void *pFuncOrig)
{
	DWORD dwFuncAddr = 0;
	DWORD dwFuncTblAddr = 0;
	DWORD dwFuncNativeOrig = 0;

	if(!bInit || !pFuncOrig) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to remove %s hook, but not initted, or no original function provided", szFuncName);
		#endif
		return false;
	}

	if(!(dwFuncAddr = (DWORD)GetProcAddress(hOpengl32, szFuncName))) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to remove %s hook, but function not found", szFuncName);
		#endif
		return false;
	}

	if(!(dwFuncTblAddr = GetTblOffset(dwFuncAddr))) {
		#ifdef ETC_DEBUG
		log("etx Error: Attempted to remove %s hook, but failed to find a table offset/address", szFuncName);
		#endif
		return false;
	}

	UnHookGLNative(dwFuncTblAddr, pFuncOrig);

	return true;
}

DWORD CGLHook::GetGLTls()
{
	#define INTEGRITY_CHECK(base, offset, glbase, glsize) (*(DWORD*)(base+offset) < (DWORD)(glbase) || *(DWORD*)(base+offset) > (DWORD)(glbase+glsize))
	MODULEINFO glmi = {0};
	DWORD dataBlock = 0;

	if(!(hOpengl32 = GetModuleHandle("opengl32"))) {
		#ifdef ETC_DEBUG
		log("etx Error: Unable to retrieve a handle to opengl32");
		#endif
		return 0;
	}

	if(!GetModuleInformation(GetCurrentProcess(), hOpengl32, &glmi, sizeof(glmi))) {
		#ifdef ETC_DEBUG
		log("etx Error: Unable to retrieve module information on opengl32");
		#endif
		return 0;
	}

	for(dataBlock=0x7FFD0000; dataBlock<=0x7FFDF000; dataBlock+=0x1000)
	{
		if(IsBadReadPtr((void*)dataBlock, 1)) // valid memory?
			continue;
		if(INTEGRITY_CHECK(dataBlock, 0xA50, hOpengl32, glmi.SizeOfImage)) // valid thread data block?
			continue;
		if(INTEGRITY_CHECK(dataBlock, 0x7C4, hOpengl32, glmi.SizeOfImage)) { // tbl of native or opengl32 ptrs?
			bInit = true; return dataBlock; // native
		}
	}

	#ifdef ETC_DEBUG
	log("etx Error: Unable to find a valid thread data block");
	#endif

	return 0;
}

DWORD CGLHook::GetTblOffset(DWORD dwFuncAddr)
{
	if(*(BYTE*)(dwFuncAddr + 0x07) == 0x83) {
		iHookMethod = 0;
		return ((*(DWORD*)(dwTls + *(DWORD*)(*(DWORD*)(dwFuncAddr + 0x14)))) + (*(DWORD*)(dwFuncAddr + 0x1C)));
	}

	else if(*(BYTE*)(dwFuncAddr + 0x07) == 0xA0) {
		iHookMethod = 1;
		return (*(DWORD*)(dwFuncAddr + 0x08));
	}

	return 0;
}

DWORD CGLHook::HookGLNative(DWORD dwFuncTblAddr, void *pFuncHook)
{
	DWORD dwFuncNativeOrig = 0;

	switch(iHookMethod)
	{
		case 0:
			dwFuncNativeOrig = *(DWORD*)dwFuncTblAddr;
			*(DWORD*)dwFuncTblAddr = (DWORD)pFuncHook;
			break;

		case 1:
			dwFuncNativeOrig = *(DWORD*)(dwTls + dwFuncTblAddr);
			*(DWORD*)(dwTls + dwFuncTblAddr) = (DWORD)pFuncHook;
			break;

		default:
			break;
	}

	return dwFuncNativeOrig;
}

void CGLHook::UnHookGLNative(DWORD dwFuncTblAddr, void *pFuncOrig)
{
	switch(iHookMethod)
	{
		case 0:
			*(DWORD*)dwFuncTblAddr = (DWORD)pFuncOrig;

		case 1:
			*(DWORD*)(dwTls + dwFuncTblAddr) = (DWORD)pFuncOrig;

		default:
			break;
	}
}

Ce code devrait donc ecrire un fichier log selon les paramettres indiqué.
Mais malgré cela, aucun fichier log n'est créer.

Je suis relativement trés débutant et malgré l'aide d'MSDN je n'ai pas réussi a trouver ce qui n'aller pas.

Cordialement.