缺少类型说明符 - 假定为 int

missing type specifier - int assumed

我一直在尝试解决这些代码堆栈上的问题。我试图在我的可执行文件上阻止注入等。

我这样调用我的函数:

#include "Protect.h"

EL_DenyProcessAccess();

错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int
错误 C2146:语法错误:缺少“;”在标识符 'EL_DenyProcessAccess'

之前
#pragma once

#include "AccCtrl.h"
#include "Aclapi.h"

BOOL EL_FORCEINLINE EL_DenyProcessAccess( void )
{
    BYTE    abyBuffer[0x200];
    PACL    pACL;
    SID_IDENTIFIER_AUTHORITY stIdentifierAuthority = SECURITY_WORLD_SID_AUTHORITY;
    PSID pSid = NULL;
    BOOL bRet = FALSE;
    DWORD dwSize = 0;
    HANDLE hToken = NULL;
    HANDLE hProcess = ::GetCurrentProcess();
    PTOKEN_USER pUserInfo = NULL;

    if( ::AllocateAndInitializeSid( &stIdentifierAuthority, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pSid ) == FALSE )
        goto Cleanup;
    if( ::OpenProcessToken( hProcess, TOKEN_QUERY, &hToken ) == FALSE )
        goto Cleanup;
    ::GetTokenInformation( hToken, TokenUser, NULL, NULL, &dwSize );
    if( dwSize > 1024 )
        goto Cleanup;
    pUserInfo = (PTOKEN_USER) ::GlobalAlloc( GPTR, dwSize );
    if( pUserInfo == NULL )
        goto Cleanup;
    if( ::GetTokenInformation( hToken, TokenUser, pUserInfo, dwSize, &dwSize ) == FALSE )
        goto Cleanup;
    pACL = (PACL) &abyBuffer;
    if( ::InitializeAcl( pACL, 0x200, ACL_REVISION ) == FALSE )
        goto Cleanup;
    // Deny except PROCESS_TERMINATE and PROCESS_SET_SESSIONID
    if( ::AddAccessDeniedAce( pACL, ACL_REVISION, PROCESS_CREATE_PROCESS | PROCESS_DUP_HANDLE | PROCESS_VM_WRITE | PROCESS_VM_READ | PROCESS_VM_OPERATION | PROCESS_CREATE_THREAD, pSid ) == FALSE )
        goto Cleanup;
    // Allow SYNCHRONIZE, PROCESS_QUERY_INFORMATION, PROCESS_SET_INFORMATION, PROCESS_SET_QUOTA and PROCESS_TERMINATE
    if( ::AddAccessAllowedAce( pACL, ACL_REVISION, SYNCHRONIZE | PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION | PROCESS_SET_QUOTA | PROCESS_TERMINATE, pUserInfo->User.Sid ) == FALSE )
        goto Cleanup;
    if( ::SetSecurityInfo( hProcess, SE_KERNEL_OBJECT, PROTECTED_DACL_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION, 0, 0, pACL, 0 ) != ERROR_SUCCESS )
        goto Cleanup;
    bRet = TRUE;
Cleanup:
    if ( hToken )
        ::CloseHandle( hToken );
    if ( pSid )
        ::FreeSid( pSid );
    return bRet;
}

我的代码没有发现任何错误?

代码显然被编译器视为 C++。这就是您收到错误的原因。

问题是 BOOL 和 EL_FORCEINLINE 没有定义。 所以预处理器翻译

BOOL EL_FORCEINLINE EL_DenyProcessAccess( void )

进入

EL_DenyProcessAccess( void )

您应该确保定义了 BOOL。

在 C 中,当未指定 return 类型时,假定类型为 int。这可能是作者想要的行为,但很容易出错。