Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for non-portable mode #539

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions altsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ int HookSystem()
return 1;
}
}
HWND (WINAPI *Load)(HWND) = (HWND (WINAPI *)(HWND))GetProcAddress(hinstDLL, LOAD_PROC);
HWND (WINAPI *Load)(HWND, const TCHAR *) = (HWND (WINAPI *)(HWND, const TCHAR*))GetProcAddress(hinstDLL, LOAD_PROC);
if(Load) {
g_dllmsgHKhwnd = Load(g_hwnd);
g_dllmsgHKhwnd = Load(g_hwnd, inipath);
}

LOG("HOOKS.DLL Loaded");
Expand Down Expand Up @@ -438,6 +438,28 @@ int WINAPI tWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, TCHAR *params, int
GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
inipath[MAX_PATH-1] = '\0';
lstrcpy_s(&inipath[lstrlen(inipath)-3], 4, TEXT("ini"));
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(inipath)
&& GetEnvironmentVariable(TEXT("APPDATA"), NULL, 0)) {
// .ini file is not in current directorry, and APPDATA exists
// we should look for %APPDATA%\AltSnap\AltSnap.ini
TCHAR userini[MAX_PATH];
GetEnvironmentVariable(TEXT("APPDATA"), userini, ARR_SZ(userini));
lstrcat_s(userini, ARR_SZ(userini), TEXT("\\AltSnap"));
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(userini)) {
CreateDirectory(userini, NULL);
LOG("CreateDirectory(%S)", userini);
}
// Full user ini name.
lstrcat_s(userini, ARR_SZ(userini), TEXT("\\AltSnap.ini"));
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(userini)) {
// Copy AltSnap.dni (Default ini file) if no ini present
lstrcpy_s(&inipath[lstrlen(inipath)-3], 4, TEXT("dni"));
CopyFile(inipath, userini, FALSE); // AltSnap.dni -> AltSnap.ini
LOG("CopyFile(%S -> %S)", inipath, userini);
}

lstrcpy_s(inipath, ARR_SZ(inipath), userini);
}
LOG("ini file: %S", inipath);

// Read parameters on command line
Expand Down
9 changes: 4 additions & 5 deletions hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -6153,7 +6153,7 @@ static void readblacklist(const TCHAR *section, struct blacklist *blacklist, con
}
// Read all the blacklitsts
#define blacklist_section_length 32767
void readallblacklists(TCHAR *inipath)
void readallblacklists(const TCHAR *inipath)
{
mem00(&BlkLst, sizeof(BlkLst));

Expand Down Expand Up @@ -6376,13 +6376,12 @@ static void freeallinputSequences(void)
#ifdef __cplusplus
extern "C"
#endif
__declspec(dllexport) HWND WINAPI Load(HWND mainhwnd)
__declspec(dllexport) HWND WINAPI Load(HWND mainhwnd, const TCHAR inipath[AT_LEAST MAX_PATH])
{
#if defined(_MSC_VER) && _MSC_VER > 1300
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
#endif
// Load settings
TCHAR inipath[MAX_PATH];
unsigned i;
state.action = AC_NONE;
state.shift = 0;
Expand All @@ -6405,8 +6404,8 @@ __declspec(dllexport) HWND WINAPI Load(HWND mainhwnd)


// Get ini path
GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
lstrcpy(&inipath[lstrlen(inipath)-3], TEXT("ini"));
// GetModuleFileName(NULL, inipath, ARR_SZ(inipath));
// lstrcpy(&inipath[lstrlen(inipath)-3], TEXT("ini"));

TCHAR stk_inisection[1420], *inisection; // Stack buffer.
size_t inisectionlen = 8192;
Expand Down
2 changes: 1 addition & 1 deletion hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define UNLOAD_PROC "Unload"
#else
#define LOW_LEVEL_KB_PROC "_LowLevelKeyboardProc@12"
#define LOAD_PROC "_Load@4"
#define LOAD_PROC "_Load@8"
#define UNLOAD_PROC "_Unload@0"
#endif
#endif
Expand Down