2017-08-25 16:04:46 +00:00
|
|
|
#include "fortcommon.h"
|
|
|
|
|
2017-09-11 11:17:27 +00:00
|
|
|
#define _WIN32_WINNT 0x0600
|
2017-08-25 16:04:46 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winioctl.h>
|
|
|
|
#include <fwpmu.h>
|
|
|
|
|
|
|
|
#include "../common/common.h"
|
|
|
|
#include "../common/fortconf.h"
|
|
|
|
|
|
|
|
#include "../common/fortconf.c"
|
|
|
|
#include "../common/fortlog.c"
|
|
|
|
#include "../common/fortprov.c"
|
|
|
|
|
|
|
|
FortCommon::FortCommon(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString FortCommon::deviceName()
|
|
|
|
{
|
|
|
|
return QLatin1String(FORT_DEVICE_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 FortCommon::ioctlSetConf()
|
|
|
|
{
|
|
|
|
return FORT_IOCTL_SETCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 FortCommon::ioctlSetFlags()
|
|
|
|
{
|
|
|
|
return FORT_IOCTL_SETFLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 FortCommon::ioctlGetLog()
|
|
|
|
{
|
|
|
|
return FORT_IOCTL_GETLOG;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 FortCommon::bufferSize()
|
|
|
|
{
|
|
|
|
return FORT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-01 13:49:11 +00:00
|
|
|
quint32 FortCommon::logBlockedHeaderSize()
|
2017-08-25 16:04:46 +00:00
|
|
|
{
|
2017-11-01 13:49:11 +00:00
|
|
|
return FORT_LOG_BLOCKED_HEADER_SIZE;
|
2017-08-25 16:04:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 13:49:11 +00:00
|
|
|
quint32 FortCommon::logBlockedSize(quint32 pathLen)
|
2017-08-25 16:04:46 +00:00
|
|
|
{
|
2017-11-01 13:49:11 +00:00
|
|
|
return FORT_LOG_BLOCKED_SIZE(pathLen);
|
2017-08-25 16:04:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 08:53:11 +00:00
|
|
|
quint32 FortCommon::logProcNewHeaderSize()
|
|
|
|
{
|
|
|
|
return FORT_LOG_PROC_NEW_HEADER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 FortCommon::logProcNewSize(quint32 pathLen)
|
|
|
|
{
|
|
|
|
return FORT_LOG_PROC_NEW_SIZE(pathLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 FortCommon::logProcDelSize()
|
|
|
|
{
|
|
|
|
return FORT_LOG_PROC_DEL_SIZE;
|
|
|
|
}
|
|
|
|
|
2017-11-07 12:15:58 +00:00
|
|
|
quint32 FortCommon::logType(const char *input)
|
|
|
|
{
|
|
|
|
return fort_log_type(input);
|
|
|
|
}
|
|
|
|
|
2017-11-01 13:49:11 +00:00
|
|
|
void FortCommon::logBlockedHeaderWrite(char *output,
|
|
|
|
quint32 remoteIp, quint32 pid,
|
|
|
|
quint32 pathLen)
|
2017-08-25 16:04:46 +00:00
|
|
|
{
|
2017-11-01 13:49:11 +00:00
|
|
|
fort_log_blocked_header_write(output, remoteIp, pid, pathLen);
|
2017-08-25 16:04:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 13:49:11 +00:00
|
|
|
void FortCommon::logBlockedHeaderRead(const char *input,
|
|
|
|
quint32 *remoteIp, quint32 *pid,
|
|
|
|
quint32 *pathLen)
|
2017-08-25 16:04:46 +00:00
|
|
|
{
|
2017-11-01 13:49:11 +00:00
|
|
|
fort_log_blocked_header_read(input, remoteIp, pid, pathLen);
|
2017-08-25 16:04:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 08:53:11 +00:00
|
|
|
void FortCommon::logProcNewHeaderWrite(char *output,
|
|
|
|
quint32 pid, quint32 pathLen)
|
|
|
|
{
|
|
|
|
fort_log_proc_new_header_write(output, pid, pathLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FortCommon::logProcNewHeaderRead(const char *input,
|
|
|
|
quint32 *pid, quint32 *pathLen)
|
|
|
|
{
|
|
|
|
fort_log_proc_new_header_read(input, pid, pathLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FortCommon::logProcDelWrite(char *output, quint32 pid)
|
|
|
|
{
|
|
|
|
fort_log_proc_del_write(output, pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FortCommon::logProcDelRead(const char *input, quint32 *pid)
|
|
|
|
{
|
|
|
|
fort_log_proc_del_read(input, pid);
|
|
|
|
}
|
|
|
|
|
2017-08-30 08:34:37 +00:00
|
|
|
void FortCommon::confAppPermsMaskInit(void *drvConf)
|
2017-08-29 08:40:23 +00:00
|
|
|
{
|
2017-08-30 08:34:37 +00:00
|
|
|
fort_conf_app_perms_mask_init((PFORT_CONF) drvConf);
|
2017-08-29 08:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FortCommon::confIpInRange(const void *drvConf, quint32 ip,
|
|
|
|
bool included)
|
|
|
|
{
|
|
|
|
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
|
|
|
|
const char *data = (const char *) conf + conf->data_off;
|
|
|
|
|
|
|
|
const quint32 count = included ? conf->ip_include_n : conf->ip_exclude_n;
|
|
|
|
const quint32 fromOff = included ? conf->ip_from_include_off : conf->ip_from_exclude_off;
|
|
|
|
const quint32 toOff = included ? conf->ip_to_include_off : conf->ip_to_exclude_off;
|
|
|
|
|
|
|
|
return fort_conf_ip_inrange(ip, count,
|
|
|
|
(const quint32 *) (data + fromOff),
|
|
|
|
(const quint32 *) (data + toOff));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FortCommon::confAppBlocked(const void *drvConf,
|
2017-11-05 04:40:11 +00:00
|
|
|
const QString &kernelPath)
|
2017-08-29 08:40:23 +00:00
|
|
|
{
|
|
|
|
const PFORT_CONF conf = (const PFORT_CONF) drvConf;
|
2017-09-13 08:26:51 +00:00
|
|
|
const QString kernelPathLower = kernelPath.toLower();
|
|
|
|
const int len = kernelPathLower.size() * sizeof(wchar_t);
|
|
|
|
const wchar_t *p = (const wchar_t *) kernelPathLower.utf16();
|
2017-08-29 08:40:23 +00:00
|
|
|
|
2017-11-05 04:40:11 +00:00
|
|
|
return fort_conf_app_blocked(conf, len, (const char *) p);
|
2017-08-29 08:40:23 +00:00
|
|
|
}
|
2017-09-03 09:20:37 +00:00
|
|
|
|
2017-10-27 10:59:09 +00:00
|
|
|
uint FortCommon::provRegister(bool isBoot)
|
2017-09-03 09:20:37 +00:00
|
|
|
{
|
2017-11-07 02:28:25 +00:00
|
|
|
return fort_prov_register(isBoot);
|
2017-09-03 09:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FortCommon::provUnregister()
|
|
|
|
{
|
|
|
|
fort_prov_unregister();
|
|
|
|
}
|