forked from cyberkitsune/PSO2Proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.c
More file actions
126 lines (102 loc) · 2.75 KB
/
Copy pathdllmain.c
File metadata and controls
126 lines (102 loc) · 2.75 KB
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
// Preprocessor related:
// Specify to the Windows API that we're not using all of it.
#define WIN32_LEAN_AND_MEAN
// Includes:
// Windows specific headers:
#include <windows.h>
// Standard C includes:
#include <stdio.h>
#include <stdlib.h>
// Constant variable(s):
const unsigned char* RSAaddr = (unsigned char*)0x03A00740;
// Text to Inject failed to open publickey.blob
LPCTSTR InjectText = "Failed to open publickey.blob";
// Caption to Inject failed to open publickey.blob
LPCTSTR InjectCaptionText = "fopen() failed";
const UINT InjectBoxFlags = MB_OK|MB_ICONERROR;
// Functions:
#if DUMPER
// Just in case we want to export this, I'm using 'VOID'.
VOID grabRSAKeysToFile()
{
// At some point we may just want to put this on the stack.
char* str = (char*)malloc(14); // SEGAKey#.blob\0
FILE* outFile;
/*
This is for the loop, if we didn't care about C99 compatibility,
we would have this in the 'for' loop.
*/
int i;
for (i = 0; i < 4; i++)
{
// Setup the pointer.
const void* ptr = (void*)(RSAaddr + (i * 0xA0));
// Prepare the file name, then open the output file-stream:
#if !defined(_CRT_SECURE_NO_WARNINGS) && (defined(_MSC_VER) || defined(MINGW_HAS_SECURE_API))
// This is just for the sake of shutting MSVC up:
sprintf_s(str, 14, "SEGAKey%d.blob", i);
fopen_s(&outFile, str, "wb");
#else
// Here's the standard C version:
sprintf(str, "SEGAKey%d.blob", i);
outFile = fopen(str, "wb");
#endif
if (outFile)
{
// Write to the disk.
fwrite(ptr, 0xA0, 1, outFile);
// Close the output-file.
fclose(outFile);
}
}
// Free the 'str' buffer.
free(str);
return;
}
#endif
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(hinstDLL);
UNREFERENCED_PARAMETER(lpvReserved);
if (fdwReason == DLL_PROCESS_ATTACH)
{
#if DUMPER
grabRSAKeysToFile();
#else
FILE* filePtr;
// Open the public-key file.
#if !defined(_CRT_SECURE_NO_WARNINGS) && (defined(_MSC_VER) || defined(MINGW_HAS_SECURE_API))
fopen_s(&filePtr, "publickey.blob", "rb");
#else
filePtr = fopen("publickey.blob", "rb");
#endif
if (filePtr)
{
// Allocate the key.
void* keyPtr = malloc(0xA0);
memset(keyPtr, 0, 0xA0);
// Read the key from the file.
size_t read = fread(keyPtr, 0x94, 1, filePtr);
// Close the file.
fclose(filePtr);
/*
As specified in 'grabRSAKeysToFile',
this is for compatibility with C99.
*/
int i;
for (i = 0; i < 4 && read == 1; i++)
{
memcpy((void*)(RSAaddr + (0xA0 * i)), keyPtr, 0xA0);
}
// Free the key.
free(keyPtr);
}
else
{
MessageBoxA(NULL, InjectText, InjectCaptionText, InjectBoxFlags);
}
#endif
}
// Return the default response.
return TRUE;
}