Windows x86 또는 WOW64 에서 작동하지만 Windows x64에서는 액세스 위반 오류로 인해 작동하지 않는 코드 스 니펫을 컴파일 및 실행하려고합니다.32 비트 코드를 64 비트 플랫폼으로 이식하려고 할 때 메모리 오류가 발생했습니다.
gcc와 Microsoft C/C++ 컴파일러 모두를 사용하여 컴파일하십시오.
/*Microsoft (R) C/C++ Optimizing Compiler Version 15.00.30729.01 for x64
(x64)cl -W3 -Zi tx.c -Fetx64
(x86)cl -W3 -Zi tx.c -Fetx32
gcc (tdm64-1) 4.7.1
(x64)gcc -m64 -Wall -O2 -o tx64 tx.c
(x86)gcc -m32 -Wall -O2 -o tx32 tx.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int (*fpPUTS)(const char *str); /*function pointer that takes an const char * as an argument and returns int*/
typedef void (*fpMEMEXEC)(fpPUTS pPuts, char *str) ;/*function pointer on which first argument is pointer to above function*/
void toMem(fpPUTS pPuts, char *str)
{
pPuts(str);
}
int main(int argc, char* argv[])
{
fpMEMEXEC pMemexec;
pMemexec = (fpMEMEXEC) malloc(4*1024);/* Allocate 4 KB memory space to the function pointer */
memcpy(pMemexec, toMem, 4*1024); /* Copy the content of toMem into newly allocated memory */
pMemexec(puts, "Hello word !!\n"); /* execute it in memory */
return 0;
}
제 질문은이 코드가 64 비트 환경에서 제대로 작동하지 않는 이유는 무엇입니까?
이 규칙을 제대로 준수하려면 어떤 규칙이 충족되지 않아야합니까?
가이드 라인을 보내 주셔서 감사합니다. SetProcessDEPPolicy return GetLastError() - 50 - 요청이 지원되지 않습니다. MSDN에서 말한 것처럼 32 비트 프로세스에서만 지원됩니다. – boleto
@boleto 당신 말이 맞습니다. 나는 대답을 편집했다. – Elazar
제공된 링크 http://icebuddha.com/slopfinder.htm은 실행 파일 (.exe)에서 DEP 보호 (데이터 실행 방지)를 사용할 수 있는지 확인하는 데 유용합니다. –