function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
Symbol_arrayof
struct symbol **Symbol_arrayof() { struct symbol **array; int i,size; if( x2a==0 ) return 0; size = x2a->count; array = (struct symbol **)malloc( sizeof(struct symbol *)*size ); if( array ){ for(i=0; i<size; i++) array[i] = x2a->tbl[i].data; } return array; }
/* Return an array of pointers to all data in the table. ** The array is obtained from malloc. Return NULL if memory allocation ** problems, or if the array is empty. */
Return an array of pointers to all data in the table. The array is obtained from malloc. Return NULL if memory allocation problems, or if the array is empty.
Configcmp
int Configcmp(a,b) struct config *a; struct config *b; { int x; x = a->rp->index - b->rp->index; if( x==0 ) x = a->dot - b->dot; return x; }
/* Compare two configurations */
Compare two configurations
statecmp
PRIVATE int statecmp(a,b) struct config *a; struct config *b; { int rc; for(rc=0; rc==0 && a && b; a=a->bp, b=b->bp){ rc = a->rp->index - b->rp->index; if( rc==0 ) rc = a->dot - b->dot; } if( rc==0 ){ if( a ) rc = 1; if( b ) rc = -1; } return rc; }
/* Compare two states */
Compare two states
statehash
PRIVATE int statehash(a) struct config *a; { int h=0; while( a ){ h = h*571 + a->rp->index*37 + a->dot; a = a->bp; } return h; }
/* Hash a state */
Hash a state
State_new
struct state *State_new() { struct state *new; new = (struct state *)malloc( sizeof(struct state) ); MemoryCheck(new); return new; }
/* Allocate a new state structure */
Allocate a new state structure
State_init
void State_init(){ if( x3a ) return; x3a = (struct s_x3*)malloc( sizeof(struct s_x3) ); if( x3a ){ x3a->size = 128; x3a->count = 0; x3a->tbl = (x3node*)malloc( (sizeof(x3node) + sizeof(x3node*))*128 ); if( x3a->tbl==0 ){ free(x3a); x3a = 0; }else{ int i; x3a->ht = (x3node**)&(x3a->tbl[128]); for(i=0; i<128; i++) x3a->ht[i] = 0; } } }
/* Allocate a new associative array */
Allocate a new associative array
State_find
struct state *State_find(key) struct config *key; { int h; x3node *np; if( x3a==0 ) return 0; h = statehash(key) & (x3a->size-1); np = x3a->ht[h]; while( np ){ if( statecmp(np->key,key)==0 ) break; np = np->next; } return np ? np->data : 0; }
/* Return a pointer to data assigned to the given key. Return NULL ** if no such key. */
Return a pointer to data assigned to the given key. Return NULL if no such key.
State_arrayof
struct state **State_arrayof() { struct state **array; int i,size; if( x3a==0 ) return 0; size = x3a->count; array = (struct state **)malloc( sizeof(struct state *)*size ); if( array ){ for(i=0; i<size; i++) array[i] = x3a->tbl[i].data; } return array; }
/* Return an array of pointers to all data in the table. ** The array is obtained from malloc. Return NULL if memory allocation ** problems, or if the array is empty. */
Return an array of pointers to all data in the table. The array is obtained from malloc. Return NULL if memory allocation problems, or if the array is empty.
confighash
PRIVATE int confighash(a) struct config *a; { int h=0; h = h*571 + a->rp->index*37 + a->dot; return h; }
/* Hash a configuration */
Hash a configuration
Configtable_init
void Configtable_init(){ if( x4a ) return; x4a = (struct s_x4*)malloc( sizeof(struct s_x4) ); if( x4a ){ x4a->size = 64; x4a->count = 0; x4a->tbl = (x4node*)malloc( (sizeof(x4node) + sizeof(x4node*))*64 ); if( x4a->tbl==0 ){ free(x4a); x4a = 0; }else{ int i; x4a->ht = (x4node**)&(x4a->tbl[64]); for(i=0; i<64; i++) x4a->ht[i] = 0; } } }
/* Allocate a new associative array */
Allocate a new associative array
Configtable_find
struct config *Configtable_find(key) struct config *key; { int h; x4node *np; if( x4a==0 ) return 0; h = confighash(key) & (x4a->size-1); np = x4a->ht[h]; while( np ){ if( Configcmp(np->data,key)==0 ) break; np = np->next; } return np ? np->data : 0; }
/* Return a pointer to data assigned to the given key. Return NULL ** if no such key. */
Return a pointer to data assigned to the given key. Return NULL if no such key.
StartProcess
void StartProcess() { // Start the client InitCedar(); CtStartClient(); }
/* Process start function*/
Process start function
StopProcess
void StopProcess() { // Stop the client CtStopClient(); FreeCedar(); }
/* Process termination function*/
Process termination function
StartProcess
void StartProcess() { // Start the server InitCedar(); StInit(); StStartServer(true); }
/* Process start function*/
Process start function
StopProcess
void StopProcess() { // Stop the server StStopServer(); StFree(); FreeCedar(); }
/* Process stop function*/
Process stop function
VwCheckExeSign
bool VwCheckExeSign(HWND hWnd, char *exe) { wchar_t tmp[2048]; bool danger = true; wchar_t *warningMessage = msgWarning; wchar_t *warningMessageTitle = msgWarningTitle; // Validate arguments if (hWnd == NULL || exe == NULL) { return false; } if (VwCheckFileDigitalSignature(hWnd, exe, &danger)) { if (danger == false) { // Safe return true; } else { // Show the message because there is potentially dangerous swprintf(tmp, sizeof(tmp) / 2, warningMessage, VwUrlToFileName(exe), VwUrlToFileName(exe), VwUrlToFileName(exe)); if (MessageBoxW(hWnd, tmp, warningMessageTitle, MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION) == IDOK) { return true; } return false; } } else { // Danger return false; } }
/* Check the signature of the EXE file, and displays a warning if dangerous*/
Check the signature of the EXE file, and displays a warning if dangerous
VwUrlToFileName
char *VwUrlToFileName(char *url) { UINT i, len; char *ret = url; bool b = true; len = lstrlen(url); for (i = 0;i < len;i++) { char c = url[i]; if (c == '?' || c == '#') { b = false; } if (b) { if (c == '/' || c == '\\') { if (lstrlen(url + i + 1) > 1) { ret = url + i + 1; } } } } return ret; }
/* Convert the URL to the file name*/
Convert the URL to the file name
VwPrint
void VwPrint(HWND hWnd, wchar_t *str) { // Validate arguments if (hWnd == NULL || str == NULL) { return; } SetText(hWnd, S_INFO, str); }
/* Show the string*/
Show the string
SetText
void SetText(HWND hWnd, UINT id, wchar_t *str) { wchar_t tmp[512]; // Validate arguments if (hWnd == NULL || str == NULL) { return; } Zero(tmp, sizeof(tmp)); GetWindowTextW(DlgItem(hWnd, id), tmp, sizeof(tmp) - 1); if (lstrcmpW(tmp, str) == 0) { return; } SetWindowTextW(DlgItem(hWnd, id), str); }
/* Set the string to window*/
Set the string to window
IsSupportedOs
bool IsSupportedOs() { OSVERSIONINFO ver; Zero(&ver, sizeof(ver)); ver.dwOSVersionInfoSize = sizeof(ver); if (GetVersionExA(&ver) == false) { return false; } if (ver.dwMajorVersion <= 4) { return false; } if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS || ver.dwPlatformId == VER_PLATFORM_WIN32s) { return false; } return true; }
/* Check whether the OS is supported*/
Check whether the OS is supported
MsgBox
UINT MsgBox(HWND hWnd, UINT flag, wchar_t *msg) { // Validate arguments if (msg == NULL) { msg = L"MessageBox"; } return MessageBoxW(hWnd, msg, msgAppTitle, flag); }
/* Show a message box*/
Show a message box
MakeDir
bool MakeDir(char *name) { // Validate arguments if (name == NULL) { return false; } return CreateDirectory(name, NULL); }
/* Create a directory*/
Create a directory
FileCreate
HANDLE FileCreate(char *name) { HANDLE h; // Validate arguments if (name == NULL) { return NULL; } h = CreateFile(name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (h == NULL || h == INVALID_HANDLE_VALUE) { return NULL; } return h; }
/* Create a file*/
Create a file
FileOpen
HANDLE FileOpen(char *name, bool write_mode) { HANDLE h; DWORD lock_mode; // Validate arguments if (name == NULL) { return NULL; } if (write_mode) { lock_mode = FILE_SHARE_READ; } else { lock_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; } h = CreateFile(name, (write_mode ? GENERIC_READ | GENERIC_WRITE : GENERIC_READ), lock_mode, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE) { return NULL; } return h; }
/* Open the file*/
Open the file
FileClose
void FileClose(HANDLE h) { // Validate arguments if (h == NULL) { return; } FlushFileBuffers(h); CloseHandle(h); }
/* Close the file*/
Close the file
FileRead
bool FileRead(HANDLE h, void *buf, UINT size) { UINT read_size; // Validate arguments if (h == NULL || buf == NULL || size == 0) { return false; } if (ReadFile(h, buf, size, &read_size, NULL) == false) { return false; } if (read_size != size) { return false; } return true; }
/* Read from the file*/
Read from the file
FileWrite
bool FileWrite(HANDLE h, void *buf, UINT size) { DWORD write_size; // Validate arguments if (h == NULL || buf == NULL || size == 0) { return false; } if (WriteFile(h, buf, size, &write_size, NULL) == false) { return false; } if (write_size != size) { return false; } return true; }
/* Write to the file*/
Write to the file
FileSize
UINT64 FileSize(HANDLE h) { UINT64 ret; DWORD tmp; // Validate arguments if (h == NULL) { return 0; } tmp = 0; ret = GetFileSize(h, &tmp); if (ret == (DWORD)-1) { return 0; } if (tmp != 0) { ret += (UINT64)tmp * 4294967296ULL; } return ret; }
/* Get the file size*/
Get the file size
VwGetFileSize
UINT VwGetFileSize(VW_FILE *f) { // Validate arguments if (f == NULL) { return 0; } return f->FileSize; }
/* Get the Internet file size*/
Get the Internet file size
VwReadFile
UINT VwReadFile(VW_FILE *f, void *buf, UINT size) { UINT readsize = 0; // Validate arguments if (f == NULL || buf == NULL) { return INFINITE; } if (InternetReadFile(f->hHttpFile, buf, size, &readsize) == false) { return INFINITE; } return readsize; }
/* Read from the Internet file*/
Read from the Internet file
VwCloseFile
void VwCloseFile(VW_FILE *f) { // Validate arguments if (f == NULL) { return; } InternetCloseHandle(f->hHttpFile); InternetCloseHandle(f->hInternet); Free(f); }
/* Close the Internet file*/
Close the Internet file
VpnWebDummyDlgProc
INT_PTR CALLBACK VpnWebDummyDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { return 0; }
/* Dialog procedure that does not do anything*/
Dialog procedure that does not do anything
InitVpnWebDlg
HWND InitVpnWebDlg(VPNWEBDLG_INIT *init) { HWND hWnd; // Validate arguments if (init == NULL) { return NULL; } _configthreadlocale(_DISABLE_PER_THREAD_LOCALE); setlocale(LC_ALL, ""); ZeroMemory(&data, sizeof(data)); CopyMemory(&data, init, sizeof(data)); LoadTables(data.LanguageId); hWnd = CreateDialog(hDllInstance, MAKEINTRESOURCE(IDD_VPNWEBDLG), data.hControlWnd, VpnWebDlgProc); data.hWnd = hWnd; ShowWindow(hWnd, SW_SHOW); return hWnd; }
/* Initialization of the dialog*/
Initialization of the dialog
FreeVpnWebDlg
void FreeVpnWebDlg() { DestroyWindow(data.hWnd); }
/* Exit the dialog*/
Exit the dialog
GetVpnWebDlgSize
void GetVpnWebDlgSize(SIZE *size) { HWND hWnd; RECT rect; // Validate arguments if (size == NULL) { return; } hWnd = CreateDialog(hDllInstance, MAKEINTRESOURCE(IDD_VPNWEBDLG), GetDesktopWindow(), VpnWebDummyDlgProc); ZeroMemory(&rect, sizeof(rect)); GetWindowRect(hWnd, &rect); DestroyWindow(hWnd); size->cx = rect.right - rect.left; size->cy = rect.bottom - rect.top; }
/* Get the size of the dialog*/
Get the size of the dialog
DlgItem
HWND DlgItem(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return NULL; } if (id == 0) { return hWnd; } else { return GetDlgItem(hWnd, id); } }
/* Get the item in the dialog*/
Get the item in the dialog
Hide
void Hide(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return; } if (IsShow(hWnd, id)) { ShowWindow(DlgItem(hWnd, id), SW_HIDE); } }
/* Hide the window*/
Hide the window
Show
void Show(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return; } if (IsHide(hWnd, id)) { ShowWindow(DlgItem(hWnd, id), SW_SHOW); } }
/* Display the window*/
Display the window
SetShow
void SetShow(HWND hWnd, UINT id, bool b) { // Validate arguments if (hWnd == NULL) { return; } if (b) { Show(hWnd, id); } else { Hide(hWnd, id); } }
/* Changing the visibility setting*/
Changing the visibility setting
IsShow
bool IsShow(HWND hWnd, UINT id) { return IsHide(hWnd, id) ? false : true; }
/* Get whether the window is shown*/
Get whether the window is shown
IsHide
bool IsHide(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return true; } if (GetStyle(hWnd, id) & WS_VISIBLE) { return false; } else { return true; } }
/* Get whether the window is hidden*/
Get whether the window is hidden
RemoveExStyle
void RemoveExStyle(HWND hWnd, UINT id, UINT style) { UINT old; // Validate arguments if (hWnd == NULL) { return; } old = GetExStyle(hWnd, id); if ((old & style) == 0) { return; } SetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE, old & ~style); Refresh(DlgItem(hWnd, id)); }
/* Remove the window style*/
Remove the window style
SetExStyle
void SetExStyle(HWND hWnd, UINT id, UINT style) { UINT old; // Validate arguments if (hWnd == NULL) { return; } old = GetExStyle(hWnd, id); if (old & style) { return; } SetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE, old | style); Refresh(DlgItem(hWnd, id)); }
/* Set the window style*/
Set the window style
GetExStyle
UINT GetExStyle(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return 0; } return GetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE); }
/* Get the window style*/
Get the window style
RemoveStyle
void RemoveStyle(HWND hWnd, UINT id, UINT style) { UINT old; // Validate arguments if (hWnd == NULL) { return; } old = GetStyle(hWnd, id); if ((old & style) == 0) { return; } SetWindowLong(DlgItem(hWnd, id), GWL_STYLE, old & ~style); Refresh(DlgItem(hWnd, id)); }
/* Remove the window style*/
Remove the window style
SetStyle
void SetStyle(HWND hWnd, UINT id, UINT style) { UINT old; // Validate arguments if (hWnd == NULL) { return; } old = GetStyle(hWnd, id); if (old & style) { return; } SetWindowLong(DlgItem(hWnd, id), GWL_STYLE, old | style); Refresh(DlgItem(hWnd, id)); }
/* Set the window style*/
Set the window style
GetStyle
UINT GetStyle(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return 0; } return GetWindowLong(DlgItem(hWnd, id), GWL_STYLE); }
/* Get the window style*/
Get the window style
Refresh
void Refresh(HWND hWnd) { HWND parent; // Validate arguments if (hWnd == NULL) { return; } DoEvents(hWnd); UpdateWindow(hWnd); DoEvents(hWnd); parent = GetParent(hWnd); if (parent != NULL) { Refresh(parent); } }
/* Update the window*/
Update the window
DoEvents
void DoEvents(HWND hWnd) { MSG msg; if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } UpdateWindow(hWnd); if (hWnd) { DoEvents(NULL); } }
/* Handle the event*/
Handle the event
Disable
void Disable(HWND hWnd, UINT id) { SetEnable(hWnd, id, false); }
/* Disable the window*/
Disable the window
Enable
void Enable(HWND hWnd, UINT id) { SetEnable(hWnd, id, true); }
/* Enable the window*/
Enable the window
SetEnable
void SetEnable(HWND hWnd, UINT id, bool b) { // Validate arguments if (hWnd == NULL) { return; } if (b == false) { if (IsEnable(hWnd, id)) { EnableWindow(DlgItem(hWnd, id), false); Refresh(DlgItem(hWnd, id)); } } else { if (IsDisable(hWnd, id)) { EnableWindow(DlgItem(hWnd, id), true); Refresh(DlgItem(hWnd, id)); } } }
/* Set the enabled state of the window*/
Set the enabled state of the window
IsDisable
bool IsDisable(HWND hWnd, UINT id) { return IsEnable(hWnd, id) ? false : true; }
/* Examine whether the Window is disabled*/
Examine whether the Window is disabled
IsEnable
bool IsEnable(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return false; } return IsWindowEnabled(DlgItem(hWnd, id)); }
/* Examine whether the window is enabled*/
Examine whether the window is enabled
SetPos
void SetPos(HWND hWnd, UINT id, UINT pos) { // Validate arguments if (hWnd == NULL) { return; } SendMsg(hWnd, id, PBM_SETPOS, pos, 0); }
/* Set the position of the progress bar*/
Set the position of the progress bar
SetRange
void SetRange(HWND hWnd, UINT id, UINT start, UINT end) { // Validate arguments if (hWnd == NULL) { return; } SendMsg(hWnd, id, PBM_SETRANGE32, start, end); }
/* Set the range of the progress bar*/
Set the range of the progress bar
SendMsg
UINT SendMsg(HWND hWnd, UINT id, UINT msg, WPARAM wParam, LPARAM lParam) { // Validate arguments if (hWnd == NULL) { return 0; } return (UINT)SendMessageA(DlgItem(hWnd, id), msg, wParam, lParam); }
/* Transmit a message to the control*/
Transmit a message to the control
NeoGetNumQueue
UINT NeoGetNumQueue() { return ctx->NumPacketQueue; }
/* Get the number of queue items*/
Get the number of queue items
NeoInsertQueue
void NeoInsertQueue(void *buf, UINT size) { NEO_QUEUE *p; // Validate arguments if (buf == NULL || size == 0) { return; } // Prevent the packet accumulation in large quantities in the queue if (ctx->NumPacketQueue > NEO_MAX_PACKET_QUEUED) { NeoFree(buf); return; } // Create a queue p = NeoMalloc(sizeof(NEO_QUEUE)); p->Next = NULL; p->Size = size; p->Buf = buf; // Append to the queue if (ctx->PacketQueue == NULL) { ctx->PacketQueue = p; } else { NEO_QUEUE *q = ctx->Tail; q->Next = p; } ctx->Tail = p; ctx->NumPacketQueue++; }
/* Insert the queue*/
Insert the queue
NeoGetNextQueue
NEO_QUEUE *NeoGetNextQueue() { NEO_QUEUE *q; if (ctx->PacketQueue == NULL) { // Empty queue return NULL; } // Get the next queued item q = ctx->PacketQueue; ctx->PacketQueue = ctx->PacketQueue->Next; q->Next = NULL; ctx->NumPacketQueue--; if (ctx->PacketQueue == NULL) { ctx->Tail = NULL; } return q; }
/* Get the next queued item*/
Get the next queued item
NeoFreeQueue
void NeoFreeQueue(NEO_QUEUE *q) { // Validate arguments if (q == NULL) { return; } NeoFree(q->Buf); NeoFree(q); }
/* Release the buffer of the queue*/
Release the buffer of the queue
NeoLockPacketQueue
void NeoLockPacketQueue() { NeoLock(ctx->PacketQueueLock); }
/* Lock the packet queue*/
Lock the packet queue
NeoUnlockPacketQueue
void NeoUnlockPacketQueue() { NeoUnlock(ctx->PacketQueueLock); }
/* Unlock the packet queue*/
Unlock the packet queue
NeoInitPacketQueue
void NeoInitPacketQueue() { // Create a lock ctx->PacketQueueLock = NeoNewLock(); // Initialize the packet queue ctx->PacketQueue = NULL; ctx->NumPacketQueue = 0; ctx->Tail = NULL; }
/* Initialize the packet queue*/
Initialize the packet queue
NeoClearPacketQueue
void NeoClearPacketQueue(bool no_lock) { // Release the memory of the packet queue if (no_lock == false) { NeoLock(ctx->PacketQueueLock); } if (true) { 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; } if (no_lock == false) { 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(false); // Delete the lock NeoFreeLock(ctx->PacketQueueLock); ctx->PacketQueueLock = NULL; }
/* Release the packet queue*/
Release the packet queue
NeoStartAdapter
void NeoStartAdapter() { // Initialize the packet queue NeoInitPacketQueue(); }
/* Start the adapter*/
Start the adapter
NeoStopAdapter
void NeoStopAdapter() { // Delete the packet queue NeoFreePacketQueue(); }
/* Stop the adapter*/
Stop the adapter
NeoNewStatus
void NeoNewStatus(NEO_STATUS *s) { // Validate arguments if (s == NULL) { return; } // Memory initialization NeoZero(s, sizeof(NEO_STATUS)); }
/* Create a status information*/
Create a status information
NeoFreeStatus
void NeoFreeStatus(NEO_STATUS *s) { // Validate arguments if (s == NULL) { return; } // Memory initialization NeoZero(s, sizeof(NEO_STATUS)); }
/* Release the status information*/
Release the status information
NeoNdisOnOpen
BOOL NeoNdisOnOpen(IRP *irp, IO_STACK_LOCATION *stack) { char name[MAX_SIZE]; if (ctx == NULL) { return FALSE; } if (ctx->Opened) { // Another client is connected already return FALSE; } ctx->Opened = TRUE; // Initialize the event name sprintf(name, NDIS_NEO_EVENT_NAME, ctx->HardwareID); // Register a Event ctx->Event = NeoNewEvent(name); if (ctx->Event == NULL) { ctx->Opened = FALSE; return FALSE; } // Set the connection state NeoSetConnectState(TRUE); return TRUE; }
/* Open the device*/
Open the device
NeoNdisOnClose
BOOL NeoNdisOnClose(IRP *irp, IO_STACK_LOCATION *stack) { NEO_EVENT *free_event = NULL; if (ctx == NULL) { return FALSE; } if (ctx->Opened == FALSE) { // Client is not connected return FALSE; } ctx->Opened = FALSE; NeoLockPacketQueue(); { // Release the event free_event = ctx->Event; ctx->Event = NULL; // Release all packets NeoClearPacketQueue(true); } NeoUnlockPacketQueue(); if (free_event != NULL) { NeoFreeEvent(free_event); } NeoSetConnectState(FALSE); return TRUE; }
/* Close the device*/
Close the device
NeoFreeControlDevice
void NeoFreeControlDevice() { if (ctx == NULL) { return; } if (ctx->Opened != FALSE) { // Delete the event NeoSet(ctx->Event); NeoFreeEvent(ctx->Event); ctx->Event = NULL; ctx->Opened = FALSE; } // Delete the device NdisDeregisterDeviceEx(ctx->NdisControl); }
/* Release the control device*/
Release the control device
NeoNdisDriverUnload
VOID NeoNdisDriverUnload(PDRIVER_OBJECT DriverObject) { NdisMDeregisterMiniportDriver(ndis_miniport_driver_handle); }
/* Unload the driver*/
Unload the driver
NeoNdisResetEx
NDIS_STATUS NeoNdisResetEx(NDIS_HANDLE MiniportAdapterContext, PBOOLEAN AddressingReset) { return NDIS_STATUS_SUCCESS; }
/* Reset handler of adapter*/
Reset handler of adapter
NeoNdisCheckForHangEx
BOOLEAN NeoNdisCheckForHangEx(NDIS_HANDLE MiniportAdapterContext) { return FALSE; }
/* Hang-up check handler of adapter*/
Hang-up check handler of adapter
NeoSetConnectState
void NeoSetConnectState(BOOL connected) { if (ctx == NULL) { return; } ctx->Connected = connected; NeoCheckConnectState(); }
/* Set the cable connection state*/
Set the cable connection state
NeoNdisSetNetBufferListsStatus
void NeoNdisSetNetBufferListsStatus(NET_BUFFER_LIST *nbl, UINT status) { if (nbl == NULL) { return; } while (nbl != NULL) { NET_BUFFER_LIST_STATUS(nbl) = status; nbl = NET_BUFFER_LIST_NEXT_NBL(nbl); } }
/* Set status values of NET_BUFFER_LISTs*/
Set status values of NET_BUFFER_LISTs
NeoInitPacketArray
void NeoInitPacketArray() { UINT i; // Create a packet buffer for (i = 0;i < NEO_MAX_PACKET_EXCHANGE;i++) { ctx->PacketBuffer[i] = NeoNewPacketBuffer(); } }
/* 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; } }
/* Release the packet array*/
Release the packet array
NeoFreePacketBuffer
void NeoFreePacketBuffer(PACKET_BUFFER *p) { // Validate arguments if (p == NULL) { return; } // Release the NET_BUFFER_LIST NdisFreeNetBufferList(p->NetBufferList); // Release the NET_BUFFER_LIST pool NdisFreeNetBufferListPool(p->NetBufferListPool); // Release the memory NeoFree(p); }
/* Release the packet buffer*/
Release the packet buffer
NeoNewPacketBuffer
PACKET_BUFFER *NeoNewPacketBuffer() { PACKET_BUFFER *p; NET_BUFFER_LIST_POOL_PARAMETERS p1; // Memory allocation p = NeoZeroMalloc(sizeof(PACKET_BUFFER)); // Create a NET_BUFFER_LIST pool NeoZero(&p1, sizeof(p1)); p1.Header.Type = NDIS_OBJECT_TYPE_DEFAULT; p1.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1; p1.Header.Size = NDIS_SIZEOF_NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1; p1.ProtocolId = NDIS_PROTOCOL_ID_DEFAULT; p1.fAllocateNetBuffer = TRUE; p1.DataSize = NEO_MAX_PACKET_SIZE; p1.PoolTag = 'SETH'; p->NetBufferListPool = NdisAllocateNetBufferListPool(NULL, &p1); // Create a NET_BUFFER_LIST p->NetBufferList = NdisAllocateNetBufferList(p->NetBufferListPool, 0, 0); return p; }
/* Create a packet buffer*/
Create a packet buffer
NeoReset
void NeoReset(NEO_EVENT *event) { // Validate arguments if (event == NULL) { return; } KeResetEvent(event->event); }
/* Reset the event*/
Reset the event
NeoSet
void NeoSet(NEO_EVENT *event) { // Validate arguments if (event == NULL) { return; } KeSetEvent(event->event, 0, FALSE); }
/* Set the event*/
Set the event
NeoFreeEvent
void NeoFreeEvent(NEO_EVENT *event) { // Validate arguments if (event == NULL) { return; } ZwClose(event->event_handle); // Release the memory NeoFree(event); }
/* Release the event*/
Release the event
GetUnicode
NDIS_STRING *GetUnicode(UNICODE *u) { // Validate arguments if (u == NULL) { return NULL; } return &u->String; }
/* Get the Unicode string*/
Get the Unicode string
FreeUnicode
void FreeUnicode(UNICODE *u) { // Validate arguments if (u == NULL) { return; } // Release a string NdisFreeString(u->String); // Release the memory NeoFree(u); }
/* Release the Unicode strings*/
Release the Unicode strings
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
NeoFreeLock
void NeoFreeLock(NEO_LOCK *lock) { NDIS_SPIN_LOCK *spin_lock; // Validate arguments if (lock == NULL) { return; } spin_lock = &lock->spin_lock; NdisFreeSpinLock(spin_lock); // Release the memory NeoFree(lock); }
/* Release the lock*/
Release the lock
NeoNewLock
NEO_LOCK *NeoNewLock() { NDIS_SPIN_LOCK *spin_lock; // Memory allocation NEO_LOCK *lock = NeoZeroMalloc(sizeof(NEO_LOCK)); if (lock == NULL) { return NULL; } // Initialize spin lock spin_lock = &lock->spin_lock; NdisAllocateSpinLock(spin_lock); return lock; }
/* Creating a new lock*/
Creating a new lock
NeoZeroMalloc
void *NeoZeroMalloc(UINT size) { void *p = NeoMalloc(size); if (p == NULL) { // Memory allocation failure return NULL; } // Clear to zero NeoZero(p, size); return p; }
/* Clear to zero by memory allocation*/
Clear to zero by memory allocation
NeoFree
void NeoFree(void *p) { // Validate arguments if (p == NULL) { return; } // Release the memory NdisFreeMemory(p, 0, 0); }
/* Release the memory*/
Release the memory
IsWindowsNt
bool IsWindowsNt() { OSVERSIONINFO info; ZeroMemory(&info, sizeof(info)); info.dwOSVersionInfoSize = sizeof(info); if (GetVersionEx(&info) == false) { return false; } if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) { return true; } return false; }
/* Get whether the system is a Windows NT*/
Get whether the system is a Windows NT
NeoNdisOnOpen
BOOL NeoNdisOnOpen(IRP *irp, IO_STACK_LOCATION *stack) { char name[MAX_SIZE]; if (ctx == NULL) { return FALSE; } if (ctx->Opened != FALSE) { // Another client is connected already return FALSE; } ctx->Opened = TRUE; // Initialize the event name sprintf(name, NDIS_NEO_EVENT_NAME, ctx->HardwareID); // Register a Event #ifndef WIN9X ctx->Event = NeoNewEvent(name); if (ctx->Event == NULL) { ctx->Opened = FALSE; return FALSE; } #endif // WIN9X // Set the connection state NeoSetConnectState(TRUE); return TRUE; }
/* Open the device*/
Open the device
NeoNdisOnClose
BOOL NeoNdisOnClose(IRP *irp, IO_STACK_LOCATION *stack) { if (ctx == NULL) { return FALSE; } if (ctx->Opened == FALSE) { // Client is not connected return FALSE; } ctx->Opened = FALSE; // Release the event NeoFreeEvent(ctx->Event); ctx->Event = NULL; // Release all packets NeoClearPacketQueue(); NeoSetConnectState(FALSE); return TRUE; }
/* Close the device*/
Close the device
NeoFreeControlDevice
void NeoFreeControlDevice() { if (ctx == NULL) { return; } if (ctx->Opened != FALSE) { // Delete the event NeoSet(ctx->Event); NeoFreeEvent(ctx->Event); ctx->Event = NULL; ctx->Opened = FALSE; } // Delete the device NdisMDeregisterDevice(ctx->NdisControl); }
/* Release the control device*/
Release the control device
NeoNdisHalt
NDIS_STATUS NeoNdisHalt(NDIS_HANDLE MiniportAdapterContext) { if (ctx == NULL) { return NDIS_STATUS_FAILURE; } if (ctx->Halting != FALSE) { // That has already been stopped return NDIS_STATUS_SUCCESS; } ctx->Halting = TRUE; // Stop the adapter NeoStopAdapter(); // Release the packet array NeoFreePacketArray(); // Delete the control device NeoFreeControlDevice(); // Complete to stop ctx->Initing = ctx->Inited = FALSE; ctx->Connected = ctx->ConnectedForce = ctx->ConnectedOld = FALSE; ctx->Halting = FALSE; // Shutdown of Neo NeoShutdown(); return NDIS_STATUS_SUCCESS; }
/* Stop handler of adapter*/
Stop handler of adapter
NeoNdisReset
NDIS_STATUS NeoNdisReset(BOOLEAN *AddressingReset, NDIS_HANDLE MiniportAdapterContext) { NdisMResetComplete(ctx->NdisMiniport, NDIS_STATUS_SUCCESS, FALSE); return NDIS_STATUS_SUCCESS; }
/* Reset handler of adapter*/
Reset handler of adapter
NeoNdisSend
NDIS_STATUS NeoNdisSend(NDIS_HANDLE MiniportAdapterContext, NDIS_PACKET *Packet, UINT Flags) { NDIS_PACKET *PacketArray[1]; PacketArray[0] = Packet; NeoNdisSendPackets(MiniportAdapterContext, PacketArray, 1); return NDIS_STATUS_SUCCESS; }
/* NDIS 3.0 packet send handler*/
NDIS 3.0 packet send handler
NeoNdisSendPacketsHaltCheck
BOOL NeoNdisSendPacketsHaltCheck(NDIS_PACKET **PacketArray, UINT NumberOfPackets) { UINT i; if (ctx == NULL) { return FALSE; } if (ctx->Halting != FALSE || ctx->Opened == FALSE) { // Finishing for (i = 0;i < NumberOfPackets;i++) { NDIS_SET_PACKET_STATUS(PacketArray[i], NDIS_STATUS_FAILURE); if (g_is_win8) { NdisMSendComplete(ctx->NdisMiniport, PacketArray[i], NDIS_STATUS_SUCCESS); } ctx->Status.NumPacketSendError++; } return FALSE; } return TRUE; }
/* Stop check of packet transmission*/
Stop check of packet transmission