function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
NeoInitPacketArray
|
void NeoInitPacketArray()
{
UINT i;
// Create a packet buffer
for (i = 0;i < NEO_MAX_PACKET_EXCHANGE;i++)
{
ctx->PacketBuffer[i] = NeoNewPacketBuffer();
// Store in the array
ctx->PacketBufferArray[i] = ctx->PacketBuffer[i]->NdisPacket;
}
}
|
/* Initialize the packet array*/
|
Initialize the packet array
|
NeoFreePacketArray
|
void NeoFreePacketArray()
{
UINT i;
for (i = 0;i < NEO_MAX_PACKET_EXCHANGE;i++)
{
NeoFreePacketBuffer(ctx->PacketBuffer[i]);
ctx->PacketBuffer[i] = NULL;
ctx->PacketBufferArray[i] = NULL;
}
}
|
/* Release the packet array*/
|
Release the packet array
|
NeoFreePacketBuffer
|
void NeoFreePacketBuffer(PACKET_BUFFER *p)
{
// Validate arguments
if (p == NULL)
{
return;
}
// Detach the buffer from the packet
NdisUnchainBufferAtFront(p->NdisPacket, &p->NdisBuffer);
// Release the packet
NdisFreePacket(p->NdisPacket);
// Release the packet pool
NdisFreePacketPool(p->PacketPool);
// Release the buffer
NdisFreeBuffer(p->NdisBuffer);
// Release the memory
NeoFree(p->Buf);
// Release the buffer pool
NdisFreeBufferPool(p->BufferPool);
// Release the memory
NeoFree(p);
}
|
/* Release the packet buffer*/
|
Release the packet buffer
|
NeoReset
|
void NeoReset(NEO_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
#ifndef WIN9X
KeResetEvent(event->event);
#else // WIN9X
if (event->win32_event != 0)
{
DWORD h = event->win32_event;
_asm mov eax, h;
VxDCall(_VWIN32_ResetWin32Event);
}
#endif // WIN9X
}
|
/* Reset the event*/
|
Reset the event
|
NeoSet
|
void NeoSet(NEO_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
#ifndef WIN9X
KeSetEvent(event->event, 0, FALSE);
#else // WIN9X
if (event->win32_event != 0)
{
DWORD h = event->win32_event;
_asm mov eax, h;
VxDCall(_VWIN32_SetWin32Event);
}
#endif // WIN9X
}
|
/* Set the event*/
|
Set the event
|
NeoFreeEvent
|
void NeoFreeEvent(NEO_EVENT *event)
{
// Validate arguments
if (event == NULL)
{
return;
}
#ifdef WIN9X
if (0)
{
if (event->win32_event != 0)
{
DWORD h = event->win32_event;
_asm mov eax, h;
VxDCall(_VWIN32_CloseVxDHandle);
}
}
#endif WIN9X
ZwClose(event->event_handle);
// Release the memory
NeoFree(event);
}
|
/* Release the event*/
|
Release the event
|
NewUnicode
|
UNICODE *NewUnicode(char *str)
{
UNICODE *u;
// Validate arguments
if (str == NULL)
{
return NULL;
}
// Memory allocation
u = NeoZeroMalloc(sizeof(UNICODE));
if (u == NULL)
{
return NULL;
}
// String initialization
_NdisInitializeString(&u->String, str);
return u;
}
|
/* Create a new Unicode string*/
|
Create a new Unicode string
|
NeoClearPacketQueue
|
void NeoClearPacketQueue()
{
// Release the memory of the packet queue
NeoLock(ctx->PacketQueueLock);
{
NEO_QUEUE *q = ctx->PacketQueue;
NEO_QUEUE *qn;
while (q != NULL)
{
qn = q->Next;
NeoFree(q->Buf);
NeoFree(q);
q = qn;
}
ctx->PacketQueue = NULL;
ctx->Tail = NULL;
ctx->NumPacketQueue = 0;
}
NeoUnlock(ctx->PacketQueueLock);
}
|
/* Delete all the packets from the packet queue*/
|
Delete all the packets from the packet queue
|
NeoFreePacketQueue
|
void NeoFreePacketQueue()
{
// Delete all packets
NeoClearPacketQueue();
// Delete the lock
NeoFreeLock(ctx->PacketQueueLock);
ctx->PacketQueueLock = NULL;
}
|
/* Release the packet queue*/
|
Release the packet queue
|
CalloutInjectionCompleted
|
void NTAPI CalloutInjectionCompleted(void *context, NET_BUFFER_LIST *net_buffer_list, BOOLEAN dispatch_level)
{
WFP_INJECTED_PACKET_CONTEXT *ctx = (WFP_INJECTED_PACKET_CONTEXT *)context;
if (ctx == NULL)
{
return;
}
FreeInjectionCtx(ctx);
}
|
/* Function to finish the insertion of the packet*/
|
Function to finish the insertion of the packet
|
FreeInjectionCtx
|
void FreeInjectionCtx(WFP_INJECTED_PACKET_CONTEXT *ctx)
{
// Validate arguments
if (ctx == NULL)
{
return;
}
if (ctx->CurrentNetBuffer != NULL)
{
Copy(ctx->CurrentNetBuffer, &ctx->OriginalNetBufferData, sizeof(NET_BUFFER));
}
if (ctx->AllocatedNetBufferList != NULL)
{
FwpsFreeCloneNetBufferList0(ctx->AllocatedNetBufferList, 0);
}
if (ctx->AllocatedMdl != NULL)
{
NdisFreeMdl(ctx->AllocatedMdl);
}
if (ctx->AllocatedMemory != NULL)
{
Free(ctx->AllocatedMemory);
}
Free(ctx);
}
|
/* Release the injection data*/
|
Release the injection data
|
IpChecksum
|
USHORT IpChecksum(void *buf, UINT size)
{
int sum = 0;
USHORT *addr = (USHORT *)buf;
int len = (int)size;
USHORT *w = addr;
int nleft = len;
USHORT answer = 0;
while (nleft > 1)
{
sum += *w++;
nleft -= 2;
}
if (nleft == 1)
{
*(UCHAR *)(&answer) = *(UCHAR *)w;
sum += answer;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return answer;
}
|
/* Calculate the checksum*/
|
Calculate the checksum
|
CalloutNotify
|
NTSTATUS NTAPI CalloutNotify(FWPS_CALLOUT_NOTIFY_TYPE notifyType,
const GUID* filterKey, FWPS_FILTER0* filter)
{
//Crush(1,0,0,0);
return 0;
}
|
/* Function to receive notification from the WFP*/
|
Function to receive notification from the WFP
|
IsIPAddressInList
|
bool IsIPAddressInList(struct WFP_LOCAL_IP *ip)
{
bool ret = false;
// Validate arguments
if (ip == NULL)
{
return false;
}
SpinLock(wfp->LocalIPListLock);
{
if (wfp->LocalIPListData != NULL)
{
UINT num = wfp->LocalIPListSize / sizeof(WFP_LOCAL_IP);
WFP_LOCAL_IP *o = (WFP_LOCAL_IP *)wfp->LocalIPListData;
UINT i;
for (i = 0;i < num;i++)
{
if (Cmp(&o[i], ip, sizeof(WFP_LOCAL_IP)) == 0)
{
ret = true;
break;
}
}
}
}
SpinUnlock(wfp->LocalIPListLock);
return ret;
}
|
/* Scan whether the specified IP address is in the local IP address list*/
|
Scan whether the specified IP address is in the local IP address list
|
NewEvent
|
EVENT *NewEvent(wchar_t *name)
{
EVENT *e;
KEVENT *ke;
HANDLE h;
UNICODE_STRING name_str;
// Validate arguments
if (name == NULL)
{
return NULL;
}
RtlInitUnicodeString(&name_str, name);
ke = IoCreateNotificationEvent(&name_str, &h);
if (ke == NULL)
{
return NULL;
}
KeInitializeEvent(ke, NotificationEvent, false);
KeClearEvent(ke);
e = ZeroMalloc(sizeof(EVENT));
e->EventObj = ke;
e->Handle = h;
return e;
}
|
/* Create an Event*/
|
Create an Event
|
FreeEvent
|
void FreeEvent(EVENT *e)
{
// Validate arguments
if (e == NULL)
{
return;
}
ZwClose(e->Handle);
Free(e);
}
|
/* Delete the event*/
|
Delete the event
|
SetEvent
|
void SetEvent(EVENT *e)
{
// Validate arguments
if (e == NULL)
{
return;
}
KeSetEvent(e->EventObj, 0, false);
}
|
/* Set the event*/
|
Set the event
|
ResetEvent
|
void ResetEvent(EVENT *e)
{
// Validate arguments
if (e == NULL)
{
return;
}
KeResetEvent(e->EventObj);
}
|
/* Reset the event*/
|
Reset the event
|
Malloc
|
void *Malloc(UINT size)
{
void *p;
p = ExAllocatePoolWithTag(g_pool_type, size + sizeof(UINT), MEMPOOL_TAG);
*((UINT *)p) = size;
return ((UCHAR *)p) + sizeof(UINT);
}
|
/* Allocate the memory*/
|
Allocate the memory
|
ReAlloc
|
void *ReAlloc(void *p, UINT size)
{
void *ret;
UINT oldsize;
// Validate arguments
if (p == NULL)
{
return NULL;
}
ret = Malloc(size);
if (ret == NULL)
{
Free(p);
return NULL;
}
oldsize = GetMemSize(p);
Copy(ret, p, MIN(size, oldsize));
Free(p);
return ret;
}
|
/* Change the memory block size*/
|
Change the memory block size
|
GetMemSize
|
UINT GetMemSize(void *p)
{
// Validate arguments
if (p == NULL)
{
return 0;
}
return *(UINT *)(((UCHAR *)p) - sizeof(UINT));
}
|
/* Get the memory block size*/
|
Get the memory block size
|
Free
|
void Free(void *p)
{
// Validate arguments
if (p == NULL)
{
return;
}
p = ((UCHAR *)p) - sizeof(UINT);
ExFreePoolWithTag(p, MEMPOOL_TAG);
}
|
/* Release the memory*/
|
Release the memory
|
Zero
|
void Zero(void *p, UINT size)
{
// Validate arguments
if (p == NULL || size == 0)
{
return;
}
memset(p, 0, size);
}
|
/* Clear the memory to zero*/
|
Clear the memory to zero
|
Cmp
|
UINT Cmp(void *p1, void *p2, UINT size)
{
UCHAR *c1 = (UCHAR *)p1;
UCHAR *c2 = (UCHAR *)p2;
UINT i;
for (i = 0;i < size;i++)
{
if (c1[i] != c2[i])
{
if (c1[i] > c2[i])
{
return 1;
}
else
{
return -1;
}
}
}
return 0;
}
|
/* Comparison of memory*/
|
Comparison of memory
|
NewSpinLock
|
SPINLOCK *NewSpinLock()
{
SPINLOCK *s = ZeroMalloc(sizeof(SPINLOCK));
KeInitializeSpinLock(&s->SpinLock);
return s;
}
|
/* Create a spin lock*/
|
Create a spin lock
|
FreeSpinLock
|
void FreeSpinLock(SPINLOCK *s)
{
// Validate arguments
if (s == NULL)
{
return;
}
Free(s);
}
|
/* Release the spin lock*/
|
Release the spin lock
|
Swap16
|
USHORT Swap16(USHORT value)
{
USHORT r;
((BYTE *)&r)[0] = ((BYTE *)&value)[1];
((BYTE *)&r)[1] = ((BYTE *)&value)[0];
return r;
}
|
/* 16-bit swap*/
|
16-bit swap
|
Swap32
|
UINT Swap32(UINT value)
{
UINT r;
((BYTE *)&r)[0] = ((BYTE *)&value)[3];
((BYTE *)&r)[1] = ((BYTE *)&value)[2];
((BYTE *)&r)[2] = ((BYTE *)&value)[1];
((BYTE *)&r)[3] = ((BYTE *)&value)[0];
return r;
}
|
/* 32-bit swap*/
|
32-bit swap
|
Endian16
|
USHORT Endian16(USHORT src)
{
int x = 1;
if (*((char *)&x))
{
return Swap16(src);
}
else
{
return src;
}
}
|
/* Endian conversion 16bit*/
|
Endian conversion 16bit
|
Endian32
|
UINT Endian32(UINT src)
{
int x = 1;
if (*((char *)&x))
{
return Swap32(src);
}
else
{
return src;
}
}
|
/* Endian conversion 32bit*/
|
Endian conversion 32bit
|
Endian64
|
UINT64 Endian64(UINT64 src)
{
int x = 1;
if (*((char *)&x))
{
return Swap64(src);
}
else
{
return src;
}
}
|
/* Endian conversion 64bit*/
|
Endian conversion 64bit
|
StartProcess
|
void StartProcess()
{
// Start the server
InitCedar();
StInit();
StStartServer(false);
}
|
/* Process starting function*/
|
Process starting function
|
init_extended_memory
|
uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex)
{
uint8 *tmp;
if ((mem_ex==NULL)||(mem_ex->buffer==NULL)||(size==0))
return TME_ERROR; /* awfully never reached!!!! */
tmp=mem_ex->buffer;
mem_ex->buffer=NULL;
FREE_MEMORY(tmp);
ALLOCATE_MEMORY(tmp,uint8,size);
if (tmp==NULL)
return TME_ERROR; /* no memory */
mem_ex->size=size;
mem_ex->buffer=tmp;
return TME_SUCCESS;
}
|
/* resizes extended memory */
|
resizes extended memory
|
set_active_tme_block
|
uint32 set_active_tme_block(TME_CORE *tme, uint32 block)
{
if ((block>=MAX_TME_DATA_BLOCKS)||(!IS_VALIDATED(tme->validated_blocks,block)))
return TME_ERROR;
tme->active=block;
tme->working=block;
return TME_SUCCESS;
}
|
/* activates a block of the TME */
|
activates a block of the TME
|
lookup_frontend
|
uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref)
{
if (tme->active==TME_NONE_ACTIVE)
return TME_FALSE;
return (tme->block_data[tme->active].lookup_code)(mem_ex_offset+mem_ex->buffer,&tme->block_data[tme->active],mem_ex, time_ref);
}
|
/* I/F between the bpf machine and the callbacks, just some checks */
|
I/F between the bpf machine and the callbacks, just some checks
|
reset_tme
|
uint32 reset_tme(TME_CORE *tme)
{
if (tme==NULL)
return TME_ERROR;
ZERO_MEMORY(tme, sizeof(TME_CORE));
return TME_SUCCESS;
}
|
/*resets all the TME core*/
|
resets all the TME core
|
set_active_read_tme_block
|
uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block)
{
if ((block>=MAX_TME_DATA_BLOCKS)||(!IS_VALIDATED(tme->validated_blocks,block)))
return TME_ERROR;
tme->active_read=block;
return TME_SUCCESS;
}
|
/* chooses the TME block for read */
|
chooses the TME block for read
|
set_autodeletion
|
uint32 set_autodeletion(TME_DATA *data, uint32 value)
{
if (value==0) /* no autodeletion */
data->enable_deletion=FALSE;
else
data->enable_deletion=TRUE;
return TME_SUCCESS;
}
|
/* chooses if the autodeletion must be used */
|
chooses if the autodeletion must be used
|
MsGetCurrentModuleHandle
|
void *MsGetCurrentModuleHandle()
{
return ms->hInst;
}
|
/* Get the current module handle*/
|
Get the current module handle
|
MsEnumResourcesInternalProc
|
bool CALLBACK MsEnumResourcesInternalProc(HMODULE hModule, const char *type, char *name, LONG_PTR lParam)
{
LIST *o = (LIST *)lParam;
// Validate arguments
if (type == NULL || name == NULL || o == NULL)
{
return true;
}
Add(o, CopyStr(name));
return true;
}
|
/* Resource enumeration procedure*/
|
Resource enumeration procedure
|
MsEnumResources
|
TOKEN_LIST *MsEnumResources(void *hModule, char *type)
{
LIST *o;
TOKEN_LIST *ret;
// Validate arguments
if (hModule == NULL)
{
hModule = MsGetCurrentModuleHandle();
}
if (type == NULL)
{
return NullToken();
}
o = NewListFast(NULL);
if (EnumResourceNamesA(hModule, type, MsEnumResourcesInternalProc, (LONG_PTR)o) == false)
{
ReleaseList(o);
return NullToken();
}
ret = ListToTokenList(o);
FreeStrList(o);
return ret;
}
|
/* Enumeration of resources*/
|
Enumeration of resources
|
MsIsCurrentUserLocaleIdJapanese
|
bool MsIsCurrentUserLocaleIdJapanese()
{
UINT lcid = MsGetUserLocaleId();
if (lcid == 1041)
{
return true;
}
return false;
}
|
/* Get whether the locale ID of the current user is Japanese*/
|
Get whether the locale ID of the current user is Japanese
|
MsGetUserLocaleId
|
UINT MsGetUserLocaleId()
{
static UINT lcid_cache = 0;
if (lcid_cache == 0)
{
lcid_cache = (UINT)GetUserDefaultLCID();
}
return lcid_cache;
}
|
/* Get the locale ID of the user*/
|
Get the locale ID of the user
|
MsSendGlobalPulse
|
void MsSendGlobalPulse(void *p)
{
HANDLE h;
// Validate arguments
if (p == NULL)
{
return;
}
h = (HANDLE)p;
PulseEvent(h);
}
|
/* Send a pulse*/
|
Send a pulse
|
MsCloseGlobalPulse
|
void MsCloseGlobalPulse(void *p)
{
HANDLE h;
// Validate arguments
if (p == NULL)
{
return;
}
h = (HANDLE)p;
CloseHandle(h);
}
|
/* Release a pulse*/
|
Release a pulse
|
MsWaitForGlobalPulse
|
bool MsWaitForGlobalPulse(void *p, UINT timeout)
{
HANDLE h;
UINT ret;
// Validate arguments
if (p == NULL)
{
return false;
}
if (timeout == TIMEOUT_INFINITE)
{
timeout = INFINITE;
}
h = (HANDLE)p;
ret = WaitForSingleObject(h, timeout);
if (ret == WAIT_OBJECT_0)
{
return true;
}
return false;
}
|
/* Wait for arriving the pulse*/
|
Wait for arriving the pulse
|
MsStopIPsecService
|
bool MsStopIPsecService()
{
if (MsIsServiceRunning(MsGetIPsecServiceName()))
{
Debug("Stopping Windows Service: %s\n", MsGetIPsecServiceName());
if (MsStopService(MsGetIPsecServiceName()))
{
return true;
}
}
return false;
}
|
/* Stop the IPsec service*/
|
Stop the IPsec service
|
MsStartIPsecService
|
bool MsStartIPsecService()
{
if (MsIsServiceRunning(MsGetIPsecServiceName()) == false)
{
Debug("Starting Windows Service: %s\n", MsGetIPsecServiceName());
return MsStartService(MsGetIPsecServiceName());
}
return false;
}
|
/* Start the IPsec service*/
|
Start the IPsec service
|
MsGetIPsecServiceName
|
char *MsGetIPsecServiceName()
{
char *svc_name = "PolicyAgent";
if (MsIsVista())
{
svc_name = "ikeext";
}
return svc_name;
}
|
/* Get the IPsec service name*/
|
Get the IPsec service name
|
MsInitGlobalLock
|
void *MsInitGlobalLock(char *name, bool ts_local)
{
char tmp[MAX_SIZE];
HANDLE h;
// Validate arguments
if (name == NULL)
{
name = "default_global_lock";
}
if (ts_local)
{
HashInstanceNameLocal(tmp, sizeof(tmp), name);
}
else
{
HashInstanceName(tmp, sizeof(tmp), name);
}
h = CreateMutexA(NULL, false, tmp);
if (h == NULL || h == INVALID_HANDLE_VALUE)
{
return NULL;
}
return (void *)h;
}
|
/* Initialize the global lock*/
|
Initialize the global lock
|
MsGlobalLock
|
void MsGlobalLock(void *p)
{
HANDLE h = (HANDLE)p;
// Validate arguments
if (h == NULL)
{
return;
}
WaitForSingleObject(p, INFINITE);
}
|
/* Get a global lock*/
|
Get a global lock
|
MsGlobalUnlock
|
void MsGlobalUnlock(void *p)
{
HANDLE h = (HANDLE)p;
// Validate arguments
if (h == NULL)
{
return;
}
ReleaseMutex(h);
}
|
/* Unlock the global lock*/
|
Unlock the global lock
|
MsFreeGlobalLock
|
void MsFreeGlobalLock(void *p)
{
HANDLE h = (HANDLE)p;
// Validate arguments
if (h == NULL)
{
return;
}
CloseHandle(h);
}
|
/* Release the global lock*/
|
Release the global lock
|
MsSetErrorModeToSilent
|
void MsSetErrorModeToSilent()
{
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
}
|
/* Set the mode not to show the errors*/
|
Set the mode not to show the errors
|
MsGetFileInformation
|
bool MsGetFileInformation(void *h, void *info)
{
// Validate arguments
if (h == INVALID_HANDLE_VALUE || info == NULL)
{
return false;
}
if (MsIsNt() == false)
{
return false;
}
if (ms->nt->GetFileInformationByHandle == NULL)
{
return false;
}
return ms->nt->GetFileInformationByHandle(h, info);
}
|
/* Get the file information*/
|
Get the file information
|
MsSetShutdownParameters
|
void MsSetShutdownParameters(UINT level, UINT flag)
{
if (MsIsNt() == false)
{
return;
}
if (ms->nt == false || ms->nt->SetProcessShutdownParameters == NULL)
{
return;
}
ms->nt->SetProcessShutdownParameters(level, flag);
}
|
/* Set the shutdown parameters of the process*/
|
Set the shutdown parameters of the process
|
MsIsWinXPOrWinVista
|
bool MsIsWinXPOrWinVista()
{
OS_INFO *info = GetOsInfo();
if (info == NULL)
{
return false;
}
if (OS_IS_WINDOWS_NT(info->OsType) == false)
{
return false;
}
if (GET_KETA(info->OsType, 100) >= 3)
{
return true;
}
return false;
}
|
/* Get whether the version of the OS is Windows XP or Windows Vista or later*/
|
Get whether the version of the OS is Windows XP or Windows Vista or later
|
MsRestartMMCSS
|
void MsRestartMMCSS()
{
MsStopService("CTAudSvcService");
MsStopService("audiosrv");
MsStopService("MMCSS");
MsStartService("MMCSS");
MsStartService("audiosrv");
MsStartService("CTAudSvcService");
}
|
/* Restart of MMCSS*/
|
Restart of MMCSS
|
MsSetMMCSSNetworkThrottlingEnable
|
void MsSetMMCSSNetworkThrottlingEnable(bool enable)
{
UINT value;
if (MsIsVista() == false)
{
return;
}
if (enable)
{
value = 0x0000000a;
}
else
{
value = 0xffffffff;
}
MsRegWriteIntEx2(REG_LOCAL_MACHINE, MMCSS_PROFILE_KEYNAME, "NetworkThrottlingIndex",
value,
false, true);
MsRestartMMCSS();
}
|
/* Enable / disable network throttling by MMCSS*/
|
Enable / disable network throttling by MMCSS
|
MsIsMMCSSNetworkThrottlingEnabled
|
bool MsIsMMCSSNetworkThrottlingEnabled()
{
UINT value;
if (MsIsVista() == false)
{
return false;
}
if (MsRegIsKeyEx2(REG_LOCAL_MACHINE, MMCSS_PROFILE_KEYNAME, false, true) == false)
{
return false;
}
value = MsRegReadIntEx2(REG_LOCAL_MACHINE, MMCSS_PROFILE_KEYNAME,
"NetworkThrottlingIndex", false, true);
if (value == 0)
{
return false;
}
if (value == 0x0000000a)
{
return true;
}
return false;
}
|
/* Examine whether the Network throttling by MMCSS is enabled*/
|
Examine whether the Network throttling by MMCSS is enabled
|
MsGetHiResTimeSpan
|
double MsGetHiResTimeSpan(UINT64 diff)
{
LARGE_INTEGER t;
UINT64 freq;
if (QueryPerformanceFrequency(&t) == false)
{
freq = 1000ULL;
}
else
{
Copy(&freq, &t, sizeof(UINT64));
}
return (double)diff / (double)freq;
}
|
/* Get the precise time from the value of the high-resolution counter*/
|
Get the precise time from the value of the high-resolution counter
|
MsGetHiResCounter
|
UINT64 MsGetHiResCounter()
{
LARGE_INTEGER t;
UINT64 ret;
if (QueryPerformanceCounter(&t) == false)
{
return Tick64();
}
Copy(&ret, &t, sizeof(UINT64));
return ret;
}
|
/* Get a high-resolution counter*/
|
Get a high-resolution counter
|
MsWaitProcessExit
|
UINT MsWaitProcessExit(void *process_handle)
{
HANDLE h = (HANDLE)process_handle;
UINT ret = 1;
if (h == NULL)
{
return 1;
}
while (true)
{
WaitForSingleObject(h, INFINITE);
ret = 1;
if (GetExitCodeProcess(h, &ret) == false)
{
break;
}
if (ret != STILL_ACTIVE)
{
break;
}
}
CloseHandle(h);
return ret;
}
|
/* Wait for the process termination*/
|
Wait for the process termination
|
MsExecuteEx
|
bool MsExecuteEx(char *exe, char *arg, void **process_handle)
{
return MsExecuteEx2(exe, arg, process_handle, false);
}
|
/* Execution of the file (to get process handle)*/
|
Execution of the file (to get process handle)
|
MsCloseHandle
|
void MsCloseHandle(void *handle)
{
if (handle != NULL)
{
CloseHandle(handle);
}
}
|
/* Close the handle*/
|
Close the handle
|
MsExecute
|
bool MsExecute(char *exe, char *arg)
{
return MsExecute2(exe, arg, false);
}
|
/* Execution of the file*/
|
Execution of the file
|
MsUniMakeDirEx
|
void MsUniMakeDirEx(wchar_t *name)
{
UINT wp;
wchar_t *tmp;
UINT i, len;
// Validate arguments
if (name == NULL)
{
return;
}
tmp = ZeroMalloc(UniStrSize(name) * 2);
wp = 0;
len = UniStrLen(name);
for (i = 0;i < len;i++)
{
wchar_t c = name[i];
if (c == '\\')
{
if (UniStrCmpi(tmp, L"\\\\") != 0 && UniStrCmpi(tmp, L"\\") != 0)
{
MsUniMakeDir(tmp);
}
}
tmp[wp++] = c;
}
Free(tmp);
MsUniMakeDir(name);
}
|
/* Recursive directory creation*/
|
Recursive directory creation
|
MsUniMakeDir
|
bool MsUniMakeDir(wchar_t *name)
{
// Validate arguments
if (name == NULL)
{
return false;
}
if (MsIsNt() == false)
{
char *s = CopyUniToStr(name);
bool ret = MsMakeDir(s);
Free(s);
return ret;
}
return CreateDirectoryW(name, NULL);
}
|
/* Create a directory*/
|
Create a directory
|
MsGetComputerName
|
void MsGetComputerName(char *name, UINT size)
{
DWORD sz;
// Validate arguments
if (name == NULL)
{
return;
}
sz = size;
GetComputerName(name, &sz);
}
|
/* Get the computer name*/
|
Get the computer name
|
MsGetCursorPosHash
|
UINT MsGetCursorPosHash()
{
POINT p;
Zero(&p, sizeof(p));
if (GetCursorPos(&p) == false)
{
return 0;
}
return MAKELONG((USHORT)p.x, (USHORT)p.y);
}
|
/* Get the hash value of the position of the mouse cursor*/
|
Get the hash value of the position of the mouse cursor
|
MsRunAsUserExW
|
void *MsRunAsUserExW(wchar_t *filename, wchar_t *arg, bool hide)
{
void *ret = MsRunAsUserExInnerW(filename, arg, hide);
if (ret == NULL)
{
Debug("MsRunAsUserExInner Failed.\n");
ret = Win32RunExW(filename, arg, hide);
}
return ret;
}
|
/* Start the process as a standard user privileges*/
|
Start the process as a standard user privileges
|
MsGetSidFromAccountName
|
SID *MsGetSidFromAccountName(char *name)
{
SID *sid;
UINT sid_size = 4096;
char *domain_name;
UINT domain_name_size = 4096;
SID_NAME_USE use = SidTypeUser;
// Validate arguments
if (name == NULL)
{
return NULL;
}
if (MsIsNt() == false)
{
return NULL;
}
sid = ZeroMalloc(sid_size);
domain_name = ZeroMalloc(domain_name_size);
if (ms->nt->LookupAccountNameA(NULL, name, sid, &sid_size, domain_name, &domain_name_size, &use) == false)
{
Free(sid);
Free(domain_name);
return NULL;
}
Free(domain_name);
return sid;
}
|
/* Get the SID from the account name*/
|
Get the SID from the account name
|
MsFreeSid
|
void MsFreeSid(SID *sid)
{
// Validate arguments
if (sid == NULL)
{
return;
}
Free(sid);
}
|
/* Release the SID*/
|
Release the SID
|
MsIsSha2KernelModeSignatureSupported
|
bool MsIsSha2KernelModeSignatureSupported()
{
HINSTANCE hDll;
bool ret = false;
if (MsIsWindows8())
{
return true;
}
hDll = LoadLibrary("Wintrust.dll");
if (hDll == NULL)
{
return false;
}
if (GetProcAddress(hDll, "CryptCATAdminAcquireContext2") != NULL)
{
ret = true;
}
FreeLibrary(hDll);
return ret;
}
|
/* Check whether SHA-2 kernel mode signature is supported*/
|
Check whether SHA-2 kernel mode signature is supported
|
MsIsKB3033929RequiredAndMissing
|
bool MsIsKB3033929RequiredAndMissing()
{
OS_INFO *info = GetOsInfo();
if (info == NULL)
{
return false;
}
if (OS_IS_WINDOWS_NT(info->OsType))
{
if (GET_KETA(info->OsType, 100) == 6)
{
if (MsIsX64())
{
if (MsIsSha2KernelModeSignatureSupported() == false)
{
return true;
}
}
}
}
return false;
}
|
/* Check whether KB3033929 is required*/
|
Check whether KB3033929 is required
|
MsDisableWow64FileSystemRedirection
|
void *MsDisableWow64FileSystemRedirection()
{
void *p = NULL;
if (MsIs64BitWindows() == false)
{
return NULL;
}
if (ms->nt->Wow64DisableWow64FsRedirection == NULL ||
ms->nt->Wow64RevertWow64FsRedirection == NULL)
{
return NULL;
}
if (ms->nt->Wow64DisableWow64FsRedirection(&p) == false)
{
return NULL;
}
if (p == NULL)
{
p = (void *)0x12345678;
}
return p;
}
|
/* Disable the WoW64 redirection*/
|
Disable the WoW64 redirection
|
MsRestoreWow64FileSystemRedirection
|
void MsRestoreWow64FileSystemRedirection(void *p)
{
// Validate arguments
if (p == NULL)
{
return;
}
if (p == (void *)0x12345678)
{
p = NULL;
}
if (MsIs64BitWindows() == false)
{
return;
}
if (ms->nt->Wow64DisableWow64FsRedirection == NULL ||
ms->nt->Wow64RevertWow64FsRedirection == NULL)
{
return;
}
ms->nt->Wow64RevertWow64FsRedirection(p);
}
|
/* Restore the WoW64 redirection*/
|
Restore the WoW64 redirection
|
MsIsX64
|
bool MsIsX64()
{
SYSTEM_INFO info;
if (MsIs64BitWindows() == false)
{
return false;
}
if (ms->nt->GetNativeSystemInfo == NULL)
{
return false;
}
Zero(&info, sizeof(info));
ms->nt->GetNativeSystemInfo(&info);
if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
{
return true;
}
return false;
}
|
/* Get whether the x64 version of Windows is currently running*/
|
Get whether the x64 version of Windows is currently running
|
MsIsIA64
|
bool MsIsIA64()
{
if (MsIs64BitWindows() == false)
{
return false;
}
if (MsIsX64())
{
return false;
}
return true;
}
|
/* Get whether the IA64 version of Windows is currently running*/
|
Get whether the IA64 version of Windows is currently running
|
MsIs64BitWindows
|
bool MsIs64BitWindows()
{
if (Is64())
{
return true;
}
else
{
if (MsIsNt() == false)
{
return false;
}
else
{
if (ms == NULL || ms->nt == NULL)
{
return false;
}
if (ms->nt->IsWow64Process == NULL)
{
return false;
}
else
{
bool b = false;
if (ms->nt->IsWow64Process(GetCurrentProcess(), &b) == false)
{
return false;
}
return b;
}
}
}
}
|
/* Acquisition whether it's a 64bit Windows*/
|
Acquisition whether it's a 64bit Windows
|
MsRegistWindowsFirewallEx2
|
void MsRegistWindowsFirewallEx2(char *title, char *exe, char *dir)
{
char tmp[MAX_PATH];
// Validate arguments
if (title == NULL || exe == NULL)
{
return;
}
if (dir == NULL || IsEmptyStr(dir))
{
dir = MsGetExeDirName();
}
ConbinePath(tmp, sizeof(tmp), dir, exe);
if (IsFileExists(tmp) == false)
{
return;
}
MsRegistWindowsFirewallEx(title, tmp);
}
|
/* Windows Firewall registration*/
|
Windows Firewall registration
|
MsGetThreadLocale
|
UINT MsGetThreadLocale()
{
return (UINT)GetThreadLocale();
}
|
/* Get the locale of the current thread*/
|
Get the locale of the current thread
|
MsSetConsoleWidth
|
UINT MsSetConsoleWidth(UINT size)
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
COORD c;
UINT old_x, old_y;
// Validate arguments
if (size == 0)
{
return 0;
}
if (h == INVALID_HANDLE_VALUE)
{
return 0;
}
Zero(&info, sizeof(info));
if (GetConsoleScreenBufferInfo(h, &info) == false)
{
return 0;
}
old_x = info.dwSize.X;
old_y = info.dwSize.Y;
c.X = size;
c.Y = old_y;
SetConsoleScreenBufferSize(h, c);
return old_x;
}
|
/* Set the width of the current console*/
|
Set the width of the current console
|
MsGetConsoleWidth
|
UINT MsGetConsoleWidth()
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO info;
if (h == INVALID_HANDLE_VALUE)
{
return 80;
}
Zero(&info, sizeof(info));
if (GetConsoleScreenBufferInfo(h, &info) == false)
{
return 80;
}
return info.dwSize.X;
}
|
/* Get the width of the current console*/
|
Get the width of the current console
|
MsDisableIme
|
bool MsDisableIme()
{
HINSTANCE h;
bool ret = false;
char dll_name[MAX_PATH];
BOOL (WINAPI *_ImmDisableIME)(DWORD);
Format(dll_name, sizeof(dll_name), "%s\\imm32.dll", MsGetSystem32Dir());
h = MsLoadLibrary(dll_name);
if (h == NULL)
{
return false;
}
_ImmDisableIME = (BOOL (__stdcall *)(DWORD))GetProcAddress(h, "ImmDisableIME");
if (_ImmDisableIME != NULL)
{
ret = _ImmDisableIME(-1);
}
FreeLibrary(h);
return ret;
}
|
/* Disable the MS-IME*/
|
Disable the MS-IME
|
MsPrintTick
|
void MsPrintTick()
{
UINT tick = timeGetTime();
static UINT tick_init = 0;
if (tick_init == 0)
{
tick_init = tick;
tick = 0;
}
else
{
tick -= tick_init;
}
printf("[%u]\n", tick);
}
|
/* Display the current time*/
|
Display the current time
|
MsGetAdapterByGuid
|
MS_ADAPTER *MsGetAdapterByGuid(char *guid)
{
MS_ADAPTER_LIST *o;
MS_ADAPTER *ret = NULL;
// Validate arguments
if (guid == NULL)
{
return NULL;
}
o = MsCreateAdapterList();
if (o == NULL)
{
return NULL;
}
ret = MsGetAdapterByGuidFromList(o, guid);
MsFreeAdapterList(o);
return ret;
}
|
/* Search for the adapter by GUID*/
|
Search for the adapter by GUID
|
MsGetAdapter
|
MS_ADAPTER *MsGetAdapter(char *title)
{
MS_ADAPTER_LIST *o;
MS_ADAPTER *ret = NULL;
UINT i;
// Validate arguments
if (title == NULL)
{
return NULL;
}
o = MsCreateAdapterList();
if (o == NULL)
{
return NULL;
}
for (i = 0;i < o->Num;i++)
{
if (StrCmpi(o->Adapters[i]->Title, title) == 0)
{
ret = MsCloneAdapter(o->Adapters[i]);
break;
}
}
MsFreeAdapterList(o);
return ret;
}
|
/* Get a single adapter*/
|
Get a single adapter
|
MsCreateAdapterList
|
MS_ADAPTER_LIST *MsCreateAdapterList()
{
return MsCreateAdapterListEx(false);
}
|
/* Generation of adapter list*/
|
Generation of adapter list
|
MsInitAdapterListModule
|
void MsInitAdapterListModule()
{
lock_adapter_list = NewLock(NULL);
last_adapter_list = MsCreateAdapterListInner();
}
|
/* Initialization of the adapter module list*/
|
Initialization of the adapter module list
|
MsFreeAdapterListModule
|
void MsFreeAdapterListModule()
{
if (last_adapter_list != NULL)
{
MsFreeAdapterList(last_adapter_list);
last_adapter_list = NULL;
}
DeleteLock(lock_adapter_list);
lock_adapter_list = NULL;
}
|
/* Release of the adapter module list*/
|
Release of the adapter module list
|
MsCloneAdapterList
|
MS_ADAPTER_LIST *MsCloneAdapterList(MS_ADAPTER_LIST *o)
{
MS_ADAPTER_LIST *ret;
UINT i;
// Validate arguments
if (o == NULL)
{
return NULL;
}
ret = ZeroMalloc(sizeof(MS_ADAPTER_LIST));
ret->Num = o->Num;
ret->Adapters = ZeroMalloc(sizeof(MS_ADAPTER *) * ret->Num);
for (i = 0;i < ret->Num;i++)
{
ret->Adapters[i] = ZeroMalloc(sizeof(MS_ADAPTER));
Copy(ret->Adapters[i], o->Adapters[i], sizeof(MS_ADAPTER));
}
return ret;
}
|
/* Clone the adapter list*/
|
Clone the adapter list
|
MsCloneAdapter
|
MS_ADAPTER *MsCloneAdapter(MS_ADAPTER *a)
{
MS_ADAPTER *ret;
// Validate arguments
if (a == NULL)
{
return NULL;
}
ret = ZeroMalloc(sizeof(MS_ADAPTER));
Copy(ret, a, sizeof(MS_ADAPTER));
return ret;
}
|
/* Clone the adapter*/
|
Clone the adapter
|
MsCreateAdapterListInner
|
MS_ADAPTER_LIST *MsCreateAdapterListInner()
{
return MsCreateAdapterListInnerEx(false);
}
|
/* Creating an adapters list*/
|
Creating an adapters list
|
ConvertMidStatusVistaToXp
|
UINT ConvertMidStatusVistaToXp(UINT st)
{
switch (st)
{
case IfOperStatusUp:
return MIB_IF_OPER_STATUS_CONNECTED;
case IfOperStatusDown:
return MIB_IF_OPER_STATUS_DISCONNECTED;
}
return MIB_IF_OPER_STATUS_NON_OPERATIONAL;
}
|
/* Convert the MIB Operational Status from Vista format to XP format*/
|
Convert the MIB Operational Status from Vista format to XP format
|
MsFreeAdapterList
|
void MsFreeAdapterList(MS_ADAPTER_LIST *o)
{
UINT i;
// Validate arguments
if (o == NULL)
{
return;
}
for (i = 0;i < o->Num;i++)
{
MsFreeAdapter(o->Adapters[i]);
}
Free(o->Adapters);
Free(o);
}
|
/* Release the adapter list*/
|
Release the adapter list
|
MsFreeAdapter
|
void MsFreeAdapter(MS_ADAPTER *a)
{
// Validate arguments
if (a == NULL)
{
return;
}
Free(a);
}
|
/* Release the adapter information*/
|
Release the adapter information
|
MsGetAdapterStatusStr
|
wchar_t *MsGetAdapterStatusStr(UINT status)
{
wchar_t *ret;
switch (status)
{
case MIB_IF_OPER_STATUS_NON_OPERATIONAL:
ret = _UU("MS_NON_OPERATIONAL");
break;
case MIB_IF_OPER_STATUS_UNREACHABLE:
ret = _UU("MS_UNREACHABLE");
break;
case MIB_IF_OPER_STATUS_DISCONNECTED:
ret = _UU("MS_DISCONNECTED");
break;
case MIB_IF_OPER_STATUS_CONNECTING:
ret = _UU("MS_CONNECTING");
break;
case MIB_IF_OPER_STATUS_CONNECTED:
ret = _UU("MS_CONNECTED");
break;
default:
ret = _UU("MS_OPERATIONAL");
break;
}
return ret;
}
|
/* Get the status string of the adapter*/
|
Get the status string of the adapter
|
MsKillProcessByExeName
|
UINT MsKillProcessByExeName(wchar_t *name)
{
LIST *o;
UINT me, i;
UINT num = 0;
// Validate arguments
if (name == NULL)
{
return 0;
}
o = MsGetProcessList();
me = MsGetProcessId();
for (i = 0;i < LIST_NUM(o);i++)
{
MS_PROCESS *p = LIST_DATA(o, i);
if (p->ProcessId != me)
{
if (UniStrCmpi(p->ExeFilenameW, name) == 0)
{
if (MsKillProcess(p->ProcessId))
{
num++;
}
}
}
}
MsFreeProcessList(o);
return num;
}
|
/* Kill the process of specified EXE file name*/
|
Kill the process of specified EXE file name
|
MsKillOtherInstance
|
void MsKillOtherInstance()
{
MsKillOtherInstanceEx(NULL);
}
|
/* Terminate all instances except the EXE itself*/
|
Terminate all instances except the EXE itself
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.