调用windows API内联程序集时出现问题
Problem with call windows API inline assembly
我想反调试和编写一个函数,像下面的代码调用API调试"IsDebuggerPresent"检查:
#include "windows.h"
bool checkdbg(){
int i = 1;
__asm{
call IsDebuggerPresent //gọi api debug
test eax, eax
jne L1
mov i,0
L1 :
}
if(i == 0) return false;
else return true;
}
但是当编译时,VS2010找不到IsDebuggerPresent
调用。
#include "Windows.h"
bool checkdbg() {
__asm {
call IsDebuggerPresent //gọi api debug
test eax, eax
jne L1
mov i,0
L1 :
}
if(i == 0) return false;
else return true;
}
int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
checkdbg();
return ERROR_SUCCESS;
}
可以很好地编译。它可能是在抱怨,因为你错过了一个入口。您在项目选项中提供的子系统规定了需要什么main,无论是WinMain(用于Windows子系统)还是main(用于控制台子系统)。
我还建议使用:
#include <Windows.h>
相对于:
#include "Windows.h"
请看这里的解释。你还应该这样做:
#include <Windows.h>
BOOL checkdbg() {
int i = 1;
__asm{
call IsDebuggerPresent
ret
}
}
int main() {
checkdbg();
return ERROR_SUCCESS;
}
返回值在eax中是预期的,所以你也可以返回,否则你所做的就是检查返回值是否为真,然后返回真。如果为false,则返回false。就回来了。你所做的唯一一件事就是有效地从BOOL转换为BOOL。我不明白你为什么要用内联ASM。
为什么不直接从C调用API呢?
#include <windows.h>
#pragma comment(lib, "kernel32.lib")
bool checkdbg() {
return IsDebuggerPresent();
}
不要使用
call balabala
使用call dword ptr [balabala]
相关文章:
- 内联程序集printf将整数解释为地址
- 正在解码MSVC 32位版本的程序集(作业).没有手术做什么
- 具有外部"c"和程序集的未定义函数
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- CoreCLR 中的检测探查器 - 将帮助程序程序集加载到 dotnet 进程的方法
- 不同于按值传递和常量引用传递的程序集
- 为什么在堆栈和堆上创建变量会产生相同的程序集代码?
- C++变量在调用 x64 程序集函数后重置为 0
- 如何将C++子例程链接到 x86 程序集程序?
- Qt 网页程序集缓存
- 测试操作系统时执行程序集"sti"时虚拟框崩溃
- 为什么从 constexpr 引用生成的程序集代码与从 constexpr 指针生成的程序集代码不同?
- 将内联程序集尾调用函数尾声替换为用于x86/x64 msvc的Intrinsics
- 解析 C# 中的C++程序集
- Visual Studio:C++\CLI 包装程序集路径依赖性问题
- visual studio c++中的内联程序集问题
- 以下内联程序集有什么问题
- 编译器为内部函数生成程序集的问题
- 调用windows API内联程序集时出现问题