function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
Win32RunExW
|
void *Win32RunExW(wchar_t *filename, wchar_t *arg, bool hide)
{
return Win32RunEx2W(filename, arg, hide, NULL);
}
|
/* Run the process (return the handle)*/
|
Run the process (return the handle)
|
Win32ThreadId
|
UINT Win32ThreadId()
{
return GetCurrentThreadId();
}
|
/* Get the Thread ID*/
|
Get the Thread ID
|
Win32FileRenameW
|
bool Win32FileRenameW(wchar_t *old_name, wchar_t *new_name)
{
// Validate arguments
if (old_name == NULL || new_name == NULL)
{
return false;
}
if (IsNt() == false)
{
char *old_name_a = CopyUniToStr(old_name);
char *new_name_a = CopyUniToStr(new_name);
bool ret = Win32FileRename(old_name_a, new_name_a);
Free(old_name_a);
Free(new_name_a);
return ret;
}
// Rename
if (MoveFileW(old_name, new_name) == FALSE)
{
return false;
}
return true;
}
|
/* Rename the file*/
|
Rename the file
|
Win32GetExeDirW
|
void Win32GetExeDirW(wchar_t *name, UINT size)
{
wchar_t exe_path[MAX_SIZE];
wchar_t exe_dir[MAX_SIZE];
// Validate arguments
if (name == NULL)
{
return;
}
if (IsNt() == false)
{
char name_a[MAX_PATH];
Win32GetExeDir(name_a, sizeof(name_a));
StrToUni(name, size, name_a);
return;
}
// Get the EXE file name
GetModuleFileNameW(NULL, exe_path, sizeof(exe_path));
// Get the directory name
Win32GetDirFromPathW(exe_dir, sizeof(exe_dir), exe_path);
UniStrCpy(name, size, exe_dir);
}
|
/* Getting the name of the directory where the EXE file is in*/
|
Getting the name of the directory where the EXE file is in
|
Win32NukuEnW
|
void Win32NukuEnW(wchar_t *dst, UINT size, wchar_t *src)
{
wchar_t str[MAX_SIZE];
int i;
if (src)
{
UniStrCpy(str, sizeof(str), src);
}
else
{
UniStrCpy(str, sizeof(str), dst);
}
i = UniStrLen(str);
if (str[i - 1] == L'\\')
{
str[i - 1] = 0;
}
UniStrCpy(dst, size, str);
}
|
/* Remove the '\' at the end*/
|
Remove the '' at the end
|
Win32DeleteDirW
|
bool Win32DeleteDirW(wchar_t *name)
{
// Validate arguments
if (name == NULL)
{
return false;
}
if (IsNt() == false)
{
char *name_a = CopyUniToStr(name);
bool ret = Win32DeleteDir(name_a);
Free(name_a);
return ret;
}
if (RemoveDirectoryW(name) == FALSE)
{
return false;
}
return true;
}
|
/* Delete the directory*/
|
Delete the directory
|
Win32MakeDirW
|
bool Win32MakeDirW(wchar_t *name)
{
// Validate arguments
if (name == NULL)
{
return false;
}
if (IsNt() == false)
{
char *name_a = CopyUniToStr(name);
bool ret = Win32MakeDir(name_a);
Free(name_a);
return ret;
}
if (CreateDirectoryW(name, NULL) == FALSE)
{
return false;
}
return true;
}
|
/* Create a directory*/
|
Create a directory
|
Win32FileDeleteW
|
bool Win32FileDeleteW(wchar_t *name)
{
// Validate arguments
if (name == NULL)
{
return false;
}
if (IsNt() == false)
{
bool ret;
char *name_a = CopyUniToStr(name);
ret = Win32FileDelete(name_a);
Free(name_a);
return ret;
}
if (DeleteFileW(name) == FALSE)
{
return false;
}
return true;
}
|
/* Delete the file*/
|
Delete the file
|
Win32FileSeek
|
bool Win32FileSeek(void *pData, UINT mode, int offset)
{
WIN32IO *p;
DWORD ret;
// Validate arguments
if (pData == NULL)
{
return false;
}
if (mode != FILE_BEGIN && mode != FILE_END && mode != FILE_CURRENT)
{
return false;
}
p = (WIN32IO *)pData;
ret = SetFilePointer(p->hFile, (LONG)offset, NULL, mode);
if (ret == INVALID_SET_FILE_POINTER || ret == ERROR_NEGATIVE_SEEK)
{
return false;
}
return true;
}
|
/* Seek in the file*/
|
Seek in the file
|
Win32FileSize
|
UINT64 Win32FileSize(void *pData)
{
WIN32IO *p;
UINT64 ret;
DWORD tmp;
// Validate arguments
if (pData == NULL)
{
return 0;
}
p = (WIN32IO *)pData;
tmp = 0;
ret = GetFileSize(p->hFile, &tmp);
if (ret == (DWORD)-1)
{
return 0;
}
if (tmp != 0)
{
ret += (UINT64)tmp * 4294967296ULL;
}
return ret;
}
|
/* Get the file size*/
|
Get the file size
|
Win32FileWrite
|
bool Win32FileWrite(void *pData, void *buf, UINT size)
{
WIN32IO *p;
DWORD write_size;
// Validate arguments
if (pData == NULL || buf == NULL || size == 0)
{
return false;
}
p = (WIN32IO *)pData;
if (WriteFile(p->hFile, buf, size, &write_size, NULL) == FALSE)
{
return false;
}
if (write_size != size)
{
return false;
}
return true;
}
|
/* Write to the file*/
|
Write to the file
|
Win32FileRead
|
bool Win32FileRead(void *pData, void *buf, UINT size)
{
WIN32IO *p;
DWORD read_size;
// Validate arguments
if (pData == NULL || buf == NULL || size == 0)
{
return false;
}
p = (WIN32IO *)pData;
if (ReadFile(p->hFile, buf, size, &read_size, NULL) == FALSE)
{
return false;
}
if (read_size != size)
{
return false;
}
return true;;
}
|
/* Read from a file*/
|
Read from a file
|
Win32FileClose
|
void Win32FileClose(void *pData, bool no_flush)
{
WIN32IO *p;
// Validate arguments
if (pData == NULL)
{
return;
}
p = (WIN32IO *)pData;
if (p->WriteMode && no_flush == false)
{
FlushFileBuffers(p->hFile);
}
CloseHandle(p->hFile);
p->hFile = NULL;
// Memory release
Win32MemoryFree(p);
}
|
/* Close the file*/
|
Close the file
|
Win32FileFlush
|
void Win32FileFlush(void *pData)
{
WIN32IO *p;
// Validate arguments
if (pData == NULL)
{
return;
}
p = (WIN32IO *)pData;
if (p->WriteMode)
{
FlushFileBuffers(p->hFile);
}
}
|
/* Flush to the file*/
|
Flush to the file
|
Win32DefaultThreadProc
|
DWORD CALLBACK Win32DefaultThreadProc(void *param)
{
WIN32THREADSTARTUPINFO *info = (WIN32THREADSTARTUPINFO *)param;
// Validate arguments
if (info == NULL)
{
return 0;
}
Win32InitNewThread();
CoInitialize(NULL);
// Call the thread function
info->thread_proc(info->thread, info->param);
// Release the reference
ReleaseThread(info->thread);
Win32MemoryFree(info);
FreeOpenSSLThreadState();
CoUninitialize();
_endthreadex(0);
return 0;
}
|
/* Default Win32 thread*/
|
Default Win32 thread
|
Win32WaitThread
|
bool Win32WaitThread(THREAD *t)
{
WIN32THREAD *w;
// Validate arguments
if (t == NULL)
{
return false;
}
w = (WIN32THREAD *)t->pData;
if (w == NULL)
{
return false;
}
// Wait for the thread event
if (WaitForSingleObject(w->hThread, INFINITE) == WAIT_OBJECT_0)
{
// The thread was signaled
return true;
}
// Wait failure (time-out, etc.)
return false;
}
|
/* Wait for the termination of the thread*/
|
Wait for the termination of the thread
|
Win32FreeThread
|
void Win32FreeThread(THREAD *t)
{
WIN32THREAD *w;
// Validate arguments
if (t == NULL)
{
return;
}
w = (WIN32THREAD *)t->pData;
if (w == NULL)
{
return;
}
// Close the handle
CloseHandle(w->hThread);
// Memory release
Win32MemoryFree(t->pData);
t->pData = NULL;
}
|
/* Release the thread*/
|
Release the thread
|
Win32Free
|
void Win32Free()
{
// Close the symbol handler
if (IsMemCheck())
{
#ifndef WIN32_NO_DEBUG_HELP_DLL
SymCleanup(hCurrentProcessHandle);
#endif // WIN32_NO_DEBUG_HELP_DLL
}
if (use_heap_api)
{
HeapDestroy(heap_handle);
heap_handle = NULL;
}
CoUninitialize();
DeleteCriticalSection(&fasttick_lock);
}
|
/* Release the library for Win32*/
|
Release the library for Win32
|
Win32GetTick
|
UINT Win32GetTick()
{
return (UINT)timeGetTime();
}
|
/* Get the system timer*/
|
Get the system timer
|
Win32GetSystemTime
|
void Win32GetSystemTime(SYSTEMTIME *system_time)
{
// Get the System Time
GetSystemTime(system_time);
}
|
/* Get the System Time*/
|
Get the System Time
|
Win32Inc32
|
void Win32Inc32(UINT *value)
{
InterlockedIncrement(value);
}
|
/* Increment of 32bit integer*/
|
Increment of 32bit integer
|
Win32Dec32
|
void Win32Dec32(UINT *value)
{
InterlockedDecrement(value);
}
|
/* Decrement of 32bit integer*/
|
Decrement of 32bit integer
|
Win32Sleep
|
void Win32Sleep(UINT time)
{
Sleep(time);
}
|
/* Sleep the thread*/
|
Sleep the thread
|
Win32NewLock
|
LOCK *Win32NewLock()
{
// Memory allocation
LOCK *lock = Win32MemoryAlloc(sizeof(LOCK));
// Allocate a critical section
CRITICAL_SECTION *critical_section = Win32MemoryAlloc(sizeof(CRITICAL_SECTION));
if (lock == NULL || critical_section == NULL)
{
Win32MemoryFree(lock);
Win32MemoryFree(critical_section);
return NULL;
}
// Initialize the critical section
InitializeCriticalSection(critical_section);
lock->pData = (void *)critical_section;
lock->Ready = true;
return lock;
}
|
/* Creating a lock*/
|
Creating a lock
|
Win32DeleteLock
|
void Win32DeleteLock(LOCK *lock)
{
CRITICAL_SECTION *critical_section;
// Reset the Ready flag safely
Win32Lock(lock);
lock->Ready = false;
Win32UnlockEx(lock, true);
// Delete the critical section
critical_section = (CRITICAL_SECTION *)lock->pData;
DeleteCriticalSection(critical_section);
// Memory release
Win32MemoryFree(critical_section);
Win32MemoryFree(lock);
}
|
/* Delete the lock*/
|
Delete the lock
|
Win32InitEvent
|
void Win32InitEvent(EVENT *event)
{
// Creating an auto-reset event
HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
event->pData = hEvent;
}
|
/* Initialization of the event*/
|
Initialization of the event
|
Win32SetEvent
|
void Win32SetEvent(EVENT *event)
{
HANDLE hEvent = (HANDLE)event->pData;
if (hEvent == NULL)
{
return;
}
SetEvent(hEvent);
}
|
/* Set the event*/
|
Set the event
|
Win32ResetEvent
|
void Win32ResetEvent(EVENT *event)
{
HANDLE hEvent = (HANDLE)event->pData;
if (hEvent == NULL)
{
return;
}
ResetEvent(hEvent);
}
|
/* Reset the event*/
|
Reset the event
|
Win32WaitEvent
|
bool Win32WaitEvent(EVENT *event, UINT timeout)
{
HANDLE hEvent = (HANDLE)event->pData;
UINT ret;
if (hEvent == NULL)
{
return false;
}
// Wait for an object
ret = WaitForSingleObject(hEvent, timeout);
if (ret == WAIT_TIMEOUT)
{
// Time-out
return false;
}
else
{
// Signaled state
return true;
}
}
|
/* Wait for the event*/
|
Wait for the event
|
Win32FreeEvent
|
void Win32FreeEvent(EVENT *event)
{
HANDLE hEvent = (HANDLE)event->pData;
if (hEvent == NULL)
{
return;
}
CloseHandle(hEvent);
}
|
/* Release of the event*/
|
Release of the event
|
Win32FastTick64
|
UINT64 Win32FastTick64()
{
static UINT last_tick = 0;
static UINT counter = 0;
UINT64 ret;
UINT tick;
EnterCriticalSection(&fasttick_lock);
// Get the current tick value
tick = Win32GetTick();
if (last_tick > tick)
{
// When the previously acquired tick value is larger than acquired this time,
// it can be considered that the counter have gone one around
counter++;
}
last_tick = tick;
ret = (UINT64)tick + (UINT64)counter * 4294967296ULL;
LeaveCriticalSection(&fasttick_lock);
if (start_tick == 0)
{
start_tick = ret;
ret = 0;
}
else
{
ret -= start_tick;
}
return ret + 1;
}
|
/* Fast getting 64 bit Tick functions for only Win32*/
|
Fast getting 64 bit Tick functions for only Win32
|
Win32InputFromFileW
|
bool Win32InputFromFileW(wchar_t *str, UINT size)
{
char *a;
if (str == NULL)
{
wchar_t tmp[MAX_SIZE];
Win32InputFromFileW(tmp, sizeof(tmp));
return false;
}
a = Win32InputFromFileLineA();
if (a == NULL)
{
UniStrCpy(str, size, L"");
return false;
}
UtfToUni(str, size, a);
UniTrimCrlf(str);
Free(a);
return true;
}
|
/* Get a line from standard input*/
|
Get a line from standard input
|
Win32PrintW
|
void Win32PrintW(wchar_t *str)
{
DWORD write_size = 0;
// Validate arguments
if (str == NULL)
{
return;
}
if (IsNt())
{
if (WriteConsoleW(hstdout, str, UniStrLen(str), &write_size, NULL) == false)
{
Win32PrintToFileW(str);
}
}
else
{
char *ansi_str = CopyUniToStr(str);
if (WriteConsoleA(hstdout, ansi_str, StrLen(ansi_str), &write_size, NULL) == false)
{
Win32PrintToFileW(str);
}
Free(ansi_str);
}
}
|
/* Print the string to the console*/
|
Print the string to the console
|
Win32IsDeviceSupported
|
bool Win32IsDeviceSupported(SECURE_DEVICE *dev)
{
HINSTANCE hInst;
// Validate arguments
if (dev == NULL)
{
return false;
}
// Check whether the DLL is readable
hInst = Win32SecureLoadLibraryEx(dev->ModuleName, DONT_RESOLVE_DLL_REFERENCES);
if (hInst == NULL)
{
return false;
}
FreeLibrary(hInst);
return true;
}
|
/* Examine whether the specified device is installed*/
|
Examine whether the specified device is installed
|
Win32FreeSecModule
|
void Win32FreeSecModule(SECURE *sec)
{
// Validate arguments
if (sec == NULL)
{
return;
}
if (sec->Data == NULL)
{
return;
}
// Unload
FreeLibrary(sec->Data->hInst);
Free(sec->Data);
sec->Data = NULL;
}
|
/* Unload the device module*/
|
Unload the device module
|
IsJPKI
|
bool IsJPKI(bool id)
{
if (id == 9 || id == 13)
{
return true;
}
return false;
}
|
/* Whether the specified device is a JPKI*/
|
Whether the specified device is a JPKI
|
SignSec
|
bool SignSec(SECURE *sec, char *name, void *dst, void *src, UINT size)
{
SEC_OBJ *obj;
UINT ret;
// Validate arguments
if (sec == NULL)
{
return false;
}
if (name == NULL || dst == NULL || src == NULL)
{
sec->Error = SEC_ERROR_BAD_PARAMETER;
return false;
}
obj = FindSecObject(sec, name, SEC_K);
if (obj == NULL)
{
return false;
}
ret = SignSecByObject(sec, obj, dst, src, size);
FreeSecObject(obj);
return ret;
}
|
/* Sign with the private key which is specified by the name in the secure device*/
|
Sign with the private key which is specified by the name in the secure device
|
ReadSecCert
|
X *ReadSecCert(SECURE *sec, char *name)
{
SEC_OBJ *obj;
X *x;
// Validate arguments
if (sec == NULL)
{
return false;
}
if (sec->SessionCreated == false)
{
sec->Error = SEC_ERROR_NO_SESSION;
return false;
}
// Search
obj = FindSecObject(sec, name, SEC_X);
if (obj == NULL)
{
return false;
}
// Acquisition
x = ReadSecCertFromObject(sec, obj);
FreeSecObject(obj);
return x;
}
|
/* Read the certificate object by specifying the name*/
|
Read the certificate object by specifying the name
|
DeleteSecKey
|
bool DeleteSecKey(SECURE *sec, char *name)
{
return DeleteSecObjectByName(sec, name, SEC_K);
}
|
/* Delete the private key object*/
|
Delete the private key object
|
DeleteSecCert
|
bool DeleteSecCert(SECURE *sec, char *name)
{
return DeleteSecObjectByName(sec, name, SEC_X);
}
|
/* Delete the certificate object*/
|
Delete the certificate object
|
CkDateToUINT64
|
UINT64 CkDateToUINT64(struct CK_DATE *ck_date)
{
SYSTEMTIME st;
char year[32], month[32], day[32];
// Validate arguments
if (ck_date == NULL)
{
return 0;
}
Zero(year, sizeof(year));
Zero(month, sizeof(month));
Zero(day, sizeof(day));
Copy(year, ck_date->year, 4);
Copy(month, ck_date->month, 2);
Copy(day, ck_date->day, 2);
st.wYear = ToInt(year);
st.wMonth = ToInt(month);
st.wDay = ToInt(day);
return SystemToUINT64(&st);
}
|
/* Convert the the CK_DATE to the 64 bit time*/
|
Convert the the CK_DATE to the 64 bit time
|
DeleteSecObjectByName
|
bool DeleteSecObjectByName(SECURE *sec, char *name, UINT type)
{
bool ret;
SEC_OBJ *obj;
// Validate arguments
if (sec == NULL)
{
return false;
}
if (name == NULL)
{
sec->Error = SEC_ERROR_BAD_PARAMETER;
return false;
}
if (sec->SessionCreated == false)
{
sec->Error = SEC_ERROR_NO_SESSION;
return false;
}
// Get the Object
obj = FindSecObject(sec, name, type);
if (obj == NULL)
{
// Failure
return false;
}
// Delete the Object
ret = DeleteSecObject(sec, obj);
// Memory release
FreeSecObject(obj);
return ret;
}
|
/* Delete the object by specifying the name*/
|
Delete the object by specifying the name
|
DeleteSecData
|
bool DeleteSecData(SECURE *sec, char *name)
{
// Validate arguments
if (sec == NULL)
{
return false;
}
if (name == NULL)
{
sec->Error = SEC_ERROR_BAD_PARAMETER;
return false;
}
return DeleteSecObjectByName(sec, name, SEC_DATA);
}
|
/* Delete the Data*/
|
Delete the Data
|
DeleteSecObjFromEnumCache
|
void DeleteSecObjFromEnumCache(SECURE *sec, char *name, UINT type)
{
UINT i;
// Validate arguments
if (sec == NULL || name == NULL || sec->EnumCache == NULL)
{
return;
}
for (i = 0;i < LIST_NUM(sec->EnumCache);i++)
{
SEC_OBJ *obj = LIST_DATA(sec->EnumCache, i);
if (StrCmpi(obj->Name, name) == 0)
{
if (obj->Type == type)
{
Delete(sec->EnumCache, obj);
FreeSecObject(obj);
break;
}
}
}
}
|
/* Remove the object which have the specified name from the cache*/
|
Remove the object which have the specified name from the cache
|
ReadSecData
|
int ReadSecData(SECURE *sec, char *name, void *data, UINT size)
{
UINT ret = 0;
SEC_OBJ *obj;
// Validate arguments
if (sec == NULL || name == NULL || data == NULL)
{
return 0;
}
if (sec->SessionCreated == false)
{
sec->Error = SEC_ERROR_NO_SESSION;
return 0;
}
// Read
obj = FindSecObject(sec, name, SEC_DATA);
if (obj == NULL)
{
// Not found
return 0;
}
// Read
ret = ReadSecDataFromObject(sec, obj, data, size);
FreeSecObject(obj);
return ret;
}
|
/* Read by searching a secure object by name*/
|
Read by searching a secure object by name
|
EraseEnumSecObjectCache
|
void EraseEnumSecObjectCache(SECURE *sec)
{
// Validate arguments
if (sec == NULL || sec->EnumCache == NULL)
{
return;
}
FreeEnumSecObject(sec->EnumCache);
sec->EnumCache = NULL;
}
|
/* Clear the cache*/
|
Clear the cache
|
CheckSecObject
|
bool CheckSecObject(SECURE *sec, char *name, UINT type)
{
SEC_OBJ *obj;
// Validate arguments
if (sec == NULL)
{
return false;
}
if (name == NULL)
{
sec->Error = SEC_ERROR_BAD_PARAMETER;
return false;
}
if (sec->SessionCreated == false)
{
sec->Error = SEC_ERROR_NO_SESSION;
return 0;
}
obj = FindSecObject(sec, name, type);
if (obj == NULL)
{
return false;
}
else
{
FreeSecObject(obj);
return true;
}
}
|
/* Check for the existence of a secure object*/
|
Check for the existence of a secure object
|
CloneSecObject
|
SEC_OBJ *CloneSecObject(SEC_OBJ *obj)
{
SEC_OBJ *ret;
// Validate arguments
if (obj == NULL)
{
return NULL;
}
ret = ZeroMalloc(sizeof(SEC_OBJ));
ret->Name = CopyStr(obj->Name);
ret->Object = obj->Object;
ret->Private = obj->Private;
ret->Type = obj->Type;
return ret;
}
|
/* Cloning a secure object structure*/
|
Cloning a secure object structure
|
FreeEnumSecObject
|
void FreeEnumSecObject(LIST *o)
{
UINT i;
// Validate arguments
if (o == NULL)
{
return;
}
for (i = 0;i < LIST_NUM(o);i++)
{
SEC_OBJ *obj = LIST_DATA(o, i);
FreeSecObject(obj);
}
ReleaseList(o);
}
|
/* Release of enumeration results of the secure object*/
|
Release of enumeration results of the secure object
|
FreeSecObject
|
void FreeSecObject(SEC_OBJ *obj)
{
// Validate arguments
if (obj == NULL)
{
return;
}
Free(obj->Name);
Free(obj);
}
|
/* Release the secure object*/
|
Release the secure object
|
CloneEnumSecObject
|
LIST *CloneEnumSecObject(LIST *o)
{
LIST *ret;
UINT i;
// Validate arguments
if (o == NULL)
{
return NULL;
}
ret = NewListFast(NULL);
for (i = 0;i < LIST_NUM(o);i++)
{
SEC_OBJ *obj = LIST_DATA(o, i);
Add(ret, CloneSecObject(obj));
}
return ret;
}
|
/* Clone the secure object enumeration results*/
|
Clone the secure object enumeration results
|
GetSecInfo
|
void GetSecInfo(SECURE *sec)
{
CK_TOKEN_INFO token_info;
// Validate arguments
if (sec == NULL)
{
return;
}
if (sec->Info != NULL)
{
return;
}
// Acquisition
Zero(&token_info, sizeof(token_info));
if (sec->Api->C_GetTokenInfo(sec->SlotIdList[sec->SessionSlotNumber], &token_info) != CKR_OK)
{
// Failure
return;
}
sec->Info = TokenInfoToSecInfo(&token_info);
}
|
/* Get the token information*/
|
Get the token information
|
FreeSecInfo
|
void FreeSecInfo(SECURE *sec)
{
// Validate arguments
if (sec == NULL)
{
return;
}
if (sec->Info == NULL)
{
return;
}
FreeSecInfoMemory(sec->Info);
sec->Info = NULL;
}
|
/* Release the token information*/
|
Release the token information
|
FreeSecInfoMemory
|
void FreeSecInfoMemory(SEC_INFO *s)
{
// Validate arguments
if (s == NULL)
{
return;
}
Free(s->Label);
Free(s->ManufacturerId);
Free(s->Model);
Free(s->SerialNumber);
Free(s->HardwareVersion);
Free(s->FirmwareVersion);
Free(s);
}
|
/* Release the memory of the SEC_INFO*/
|
Release the memory of the SEC_INFO
|
CloseSecSession
|
void CloseSecSession(SECURE *sec)
{
// Validate arguments
if (sec == NULL)
{
return;
}
if (sec->SessionCreated == false)
{
return;
}
// Close the session
sec->Api->C_CloseSession(sec->SessionId);
sec->SessionCreated = false;
sec->SessionId = 0;
sec->SessionSlotNumber = 0;
FreeSecInfo(sec);
// Clear the cache
EraseEnumSecObjectCache(sec);
}
|
/* Close the session*/
|
Close the session
|
CloseSec
|
void CloseSec(SECURE *sec)
{
// Validate arguments
if (sec == NULL)
{
return;
}
// Log out
LogoutSec(sec);
// Close the session
CloseSecSession(sec);
// Release the token information
FreeSecInfo(sec);
// Release of the slot list memory
if (sec->SlotIdList != NULL)
{
Free(sec->SlotIdList);
sec->SlotIdList = NULL;
}
// Unload the module
FreeSecModule(sec);
// Memory release
DeleteLock(sec->lock);
Free(sec);
}
|
/* Close the secure device*/
|
Close the secure device
|
LoadSecModule
|
bool LoadSecModule(SECURE *sec)
{
bool ret = false;
// Validate arguments
if (sec == NULL)
{
return false;
}
#ifdef OS_WIN32
ret = Win32LoadSecModule(sec);
#endif // OS_WIN32
// Initialization
if (sec->Api->C_Initialize(NULL) != CKR_OK)
{
// Initialization Failed
FreeSecModule(sec);
return false;
}
sec->Initialized = true;
return ret;
}
|
/* Load the module of the secure device*/
|
Load the module of the secure device
|
FreeSecModule
|
void FreeSecModule(SECURE *sec)
{
// Validate arguments
if (sec == NULL)
{
return;
}
if (sec->Initialized)
{
// Release because it is initialized
sec->Api->C_Finalize(NULL);
sec->Initialized = false;
}
#ifdef OS_WIN32
Win32FreeSecModule(sec);
#endif // OS_WIN32
}
|
/* Unload the module of the secure device*/
|
Unload the module of the secure device
|
GetSecureDevice
|
SECURE_DEVICE *GetSecureDevice(UINT id)
{
UINT i;
if (id == 0)
{
return NULL;
}
for (i = 0;i < LIST_NUM(SecureDeviceList);i++)
{
SECURE_DEVICE *dev = LIST_DATA(SecureDeviceList, i);
if (dev->Id == id)
{
return dev;
}
}
return NULL;
}
|
/* Get a secure device*/
|
Get a secure device
|
CheckSecureDeviceId
|
bool CheckSecureDeviceId(UINT id)
{
UINT i;
for (i = 0;i < LIST_NUM(SecureDeviceList);i++)
{
SECURE_DEVICE *dev = LIST_DATA(SecureDeviceList, i);
if (dev->Id == id)
{
return true;
}
}
return false;
}
|
/* Confirm the ID of the secure device*/
|
Confirm the ID of the secure device
|
GetSecureDeviceList
|
LIST *GetSecureDeviceList()
{
return GetSupportedDeviceList();
}
|
/* Get a list of supported devices*/
|
Get a list of supported devices
|
GetSupportedDeviceList
|
LIST *GetSupportedDeviceList()
{
// Increase the reference count
AddRef(SecureDeviceList->ref);
return SecureDeviceList;
}
|
/* Get a list of supported devices*/
|
Get a list of supported devices
|
IsDeviceSupported
|
bool IsDeviceSupported(SECURE_DEVICE *dev)
{
bool b = false;
#ifdef OS_WIN32
b = Win32IsDeviceSupported(dev);
#endif // OS_WIN32
return b;
}
|
/* Examine whether the specified device is installed and available*/
|
Examine whether the specified device is installed and available
|
InitSecureDeviceList
|
void InitSecureDeviceList()
{
UINT i, num_supported_list;
SecureDeviceList = NewList(NULL);
num_supported_list = sizeof(SupportedList) / sizeof(SECURE_DEVICE);
for (i = 0; i < num_supported_list;i++)
{
SECURE_DEVICE *dev = &SupportedList[i];
// Support Checking
if (IsDeviceSupported(dev))
{
// Add the device to the list because it is supported
Add(SecureDeviceList, dev);
}
}
}
|
/* Initialization of the secure device list*/
|
Initialization of the secure device list
|
FreeSecureDeviceList
|
void FreeSecureDeviceList()
{
ReleaseList(SecureDeviceList);
}
|
/* Release of the secure device list*/
|
Release of the secure device list
|
InitSecure
|
void InitSecure()
{
// Initialization of the secure device list
InitSecureDeviceList();
}
|
/* Initialization of the security token module*/
|
Initialization of the security token module
|
FreeSecure
|
void FreeSecure()
{
// Release of the secure device list
FreeSecureDeviceList();
}
|
/* Release of the security token module*/
|
Release of the security token module
|
FreeCfgRw
|
void FreeCfgRw(CFG_RW *rw)
{
// Validate arguments
if (rw == NULL)
{
return;
}
if (rw->Io != NULL)
{
FileClose(rw->Io);
}
DeleteLock(rw->lock);
Free(rw->FileNameW);
Free(rw->FileName);
Free(rw);
}
|
/* Close the configuration file R/W*/
|
Close the configuration file R/W
|
SaveCfgRw
|
UINT SaveCfgRw(CFG_RW *rw, FOLDER *f)
{
return SaveCfgRwEx(rw, f, INFINITE);
}
|
/* Writing to the configuration file*/
|
Writing to the configuration file
|
NewCfgRw
|
CFG_RW *NewCfgRw(FOLDER **root, char *cfg_name)
{
return NewCfgRwEx(root, cfg_name, false);
}
|
/* Creating a configuration file R/W*/
|
Creating a configuration file R/W
|
FileCopy
|
bool FileCopy(char *src, char *dst)
{
BUF *b;
bool ret = false;
// Validate arguments
if (src == NULL || dst == NULL)
{
return false;
}
b = ReadDump(src);
if (b == NULL)
{
return false;
}
SeekBuf(b, 0, 0);
ret = DumpBuf(b, dst);
FreeBuf(b);
return ret;
}
|
/* Copy a file*/
|
Copy a file
|
CfgSave
|
void CfgSave(FOLDER *f, char *name)
{
CfgSaveEx(NULL, f, name);
}
|
/* Save the settings to a file*/
|
Save the settings to a file
|
CfgRead
|
FOLDER *CfgRead(char *name)
{
wchar_t *name_w = CopyStrToUni(name);
FOLDER *ret = CfgReadW(name_w);
Free(name_w);
return ret;
}
|
/* Read the settings from the file*/
|
Read the settings from the file
|
CfgBufTextToFolder
|
FOLDER *CfgBufTextToFolder(BUF *b)
{
FOLDER *f, *c;
// Validate arguments
if (b == NULL)
{
return NULL;
}
// Read recursively from the root folder
c = CfgCreateFolder(NULL, "tmp");
while (true)
{
// Read the text stream
if (CfgReadNextTextBUF(b, c) == false)
{
break;
}
}
// Getting root folder
f = CfgGetFolder(c, TAG_ROOT);
if (f == NULL)
{
// Root folder is not found
CfgDeleteFolder(c);
return NULL;
}
// Remove the reference from tmp folder to the root
Delete(c->Folders, f);
f->Parent = NULL;
// Delete the tmp folder
CfgDeleteFolder(c);
// Return the root folder
return f;
}
|
/* Convert the stream text to a folder*/
|
Convert the stream text to a folder
|
CfgBufBinToFolder
|
FOLDER *CfgBufBinToFolder(BUF *b)
{
FOLDER *f, *c;
// Validate arguments
if (b == NULL)
{
return NULL;
}
// Create a temporary folder
c = CfgCreateFolder(NULL, "tmp");
// Read a binary
CfgReadNextFolderBin(b, c);
// Get root folder
f = CfgGetFolder(c, TAG_ROOT);
if (f == NULL)
{
// Missing
CfgDeleteFolder(c);
return NULL;
}
Delete(c->Folders, f);
f->Parent = NULL;
CfgDeleteFolder(c);
return f;
}
|
/* Convert the binary to folder*/
|
Convert the binary to folder
|
CfgFolderToBufBin
|
BUF *CfgFolderToBufBin(FOLDER *f)
{
BUF *b;
UCHAR hash[SHA1_SIZE];
// Validate arguments
if (f == NULL)
{
return NULL;
}
b = NewBuf();
// Header
WriteBuf(b, TAG_BINARY, 8);
// Hash area
Zero(hash, sizeof(hash));
WriteBuf(b, hash, sizeof(hash));
// Output the root folder (recursive)
CfgOutputFolderBin(b, f);
// Hash
Sha0(((UCHAR *)b->Buf) + 8, ((UCHAR *)b->Buf) + 8 + SHA1_SIZE, b->Size - 8 - SHA1_SIZE);
return b;
}
|
/* Convert the folder to binary*/
|
Convert the folder to binary
|
CfgFolderToBufTextEx
|
BUF *CfgFolderToBufTextEx(FOLDER *f, bool no_banner)
{
BUF *b;
// Validate arguments
if (f == NULL)
{
return NULL;
}
// Create a stream
b = NewBuf();
// Copyright notice
if (no_banner == false)
{
WriteBuf(b, TAG_CPYRIGHT, StrLen(TAG_CPYRIGHT));
}
// Output the root folder (recursive)
CfgOutputFolderText(b, f, 0);
return b;
}
|
/* Convert the folder to a stream text*/
|
Convert the folder to a stream text
|
CfgEnumFolderProc
|
bool CfgEnumFolderProc(FOLDER *f, void *param)
{
CFG_ENUM_PARAM *p;
// Validate arguments
if (f == NULL || param == NULL)
{
return false;
}
p = (CFG_ENUM_PARAM *)param;
// Output the folder contents (recursive)
CfgOutputFolderText(p->b, f, p->depth);
return true;
}
|
/* Output the folder contents (Enumerate folders)*/
|
Output the folder contents (Enumerate folders)
|
CfgEnumItemProc
|
bool CfgEnumItemProc(ITEM *t, void *param)
{
CFG_ENUM_PARAM *p;
// Validate arguments
if (t == NULL || param == NULL)
{
return false;
}
p = (CFG_ENUM_PARAM *)param;
CfgAddItemText(p->b, t, p->depth);
return true;
}
|
/* Output the contents of the item (enumeration)*/
|
Output the contents of the item (enumeration)
|
CfgTypeToStr
|
char *CfgTypeToStr(UINT type)
{
switch (type)
{
case ITEM_TYPE_INT:
return TAG_INT;
case ITEM_TYPE_INT64:
return TAG_INT64;
case ITEM_TYPE_BYTE:
return TAG_BYTE;
case ITEM_TYPE_STRING:
return TAG_STRING;
case ITEM_TYPE_BOOL:
return TAG_BOOL;
}
return NULL;
}
|
/* Convert the type of data to a string*/
|
Convert the type of data to a string
|
CfgAddEnd
|
void CfgAddEnd(BUF *b, UINT depth)
{
// Validate arguments
if (b == NULL)
{
return;
}
CfgAddLine(b, "}", depth);
// CfgAddLine(b, TAG_END, depth);
}
|
/* Outputs the End line*/
|
Outputs the End line
|
CfgAddDeclare
|
void CfgAddDeclare(BUF *b, char *name, UINT depth)
{
char *tmp;
char *name2;
UINT tmp_size;
// Validate arguments
if (b == NULL || name == NULL)
{
return;
}
name2 = CfgEscape(name);
tmp_size = StrLen(name2) + 2 + StrLen(TAG_DECLARE);
tmp = Malloc(tmp_size);
Format(tmp, 0, "%s %s", TAG_DECLARE, name2);
CfgAddLine(b, tmp, depth);
CfgAddLine(b, "{", depth);
Free(tmp);
Free(name2);
}
|
/* Outputs the Declare lines*/
|
Outputs the Declare lines
|
CfgAddLine
|
void CfgAddLine(BUF *b, char *str, UINT depth)
{
UINT i;
// Validate arguments
if (b == NULL)
{
return;
}
for (i = 0;i < depth;i++)
{
WriteBuf(b, "\t", 1);
}
WriteBuf(b, str, StrLen(str));
WriteBuf(b, "\r\n", 2);
}
|
/* Outputs one line*/
|
Outputs one line
|
CfgFolderToBuf
|
BUF *CfgFolderToBuf(FOLDER *f, bool textmode)
{
return CfgFolderToBufEx(f, textmode, false);
}
|
/* Convert the folder to a stream*/
|
Convert the folder to a stream
|
CfgCheckCharForName
|
bool CfgCheckCharForName(char c)
{
if (c >= 0 && c <= 31)
{
return false;
}
if (c == ' ' || c == '\t')
{
return false;
}
if (c == '$')
{
return false;
}
return true;
}
|
/* Check if the character can be used in the name*/
|
Check if the character can be used in the name
|
CfgGetStr
|
bool CfgGetStr(FOLDER *f, char *name, char *str, UINT size)
{
wchar_t *tmp;
UINT tmp_size;
// Validate arguments
if (f == NULL || name == NULL || str == NULL)
{
return false;
}
str[0] = 0;
// Get unicode string temporarily
tmp_size = size * 4 + 10; // Just to make sure, a quantity of this amount is secured.
tmp = Malloc(tmp_size);
if (CfgGetUniStr(f, name, tmp, tmp_size) == false)
{
// Failure
Free(tmp);
return false;
}
// Copy to the ANSI string
UniToStr(str, size, tmp);
Free(tmp);
return true;
}
|
/* Get the string type value*/
|
Get the string type value
|
CfgGetUniStr
|
bool CfgGetUniStr(FOLDER *f, char *name, wchar_t *str, UINT size)
{
ITEM *t;
// Validate arguments
if (f == NULL || name == NULL || str == NULL)
{
return false;
}
str[0] = 0;
t = CfgFindItem(f, name);
if (t == NULL)
{
return false;
}
if (t->Type != ITEM_TYPE_STRING)
{
return false;
}
UniStrCpy(str, size, t->Buf);
return true;
}
|
/* Get the value of the unicode_string type*/
|
Get the value of the unicode_string type
|
CfgIsItem
|
bool CfgIsItem(FOLDER *f, char *name)
{
ITEM *t;
// Validate arguments
if (f == NULL || name == NULL)
{
return false;
}
t = CfgFindItem(f, name);
if (t == NULL)
{
return false;
}
return true;
}
|
/* Check for the existence of item*/
|
Check for the existence of item
|
CfgGetBuf
|
BUF *CfgGetBuf(FOLDER *f, char *name)
{
ITEM *t;
BUF *b;
// Validate arguments
if (f == NULL || name == NULL)
{
return NULL;
}
t = CfgFindItem(f, name);
if (t == NULL)
{
return NULL;
}
b = NewBuf();
WriteBuf(b, t->Buf, t->size);
SeekBuf(b, 0, 0);
return b;
}
|
/* Get the byte[] type as a BUF*/
|
Get the byte[] type as a BUF
|
CfgGetByte
|
UINT CfgGetByte(FOLDER *f, char *name, void *buf, UINT size)
{
ITEM *t;
// Validate arguments
if (f == NULL || name == NULL || buf == NULL)
{
return 0;
}
t = CfgFindItem(f, name);
if (t == NULL)
{
return 0;
}
if (t->Type != ITEM_TYPE_BYTE)
{
return 0;
}
if (t->size <= size)
{
Copy(buf, t->Buf, t->size);
return t->size;
}
else
{
Copy(buf, t->Buf, size);
return t->size;
}
}
|
/* Get the value of type byte[]*/
|
Get the value of type byte[]
|
CfgGetInt64
|
UINT64 CfgGetInt64(FOLDER *f, char *name)
{
ITEM *t;
UINT64 *ret;
// Validate arguments
if (f == NULL || name == NULL)
{
return 0;
}
t = CfgFindItem(f, name);
if (t == NULL)
{
return 0;
}
if (t->Type != ITEM_TYPE_INT64)
{
return 0;
}
if (t->size != sizeof(UINT64))
{
return 0;
}
ret = (UINT64 *)t->Buf;
return *ret;
}
|
/* Get the value of type int64*/
|
Get the value of type int64
|
CfgGetBool
|
bool CfgGetBool(FOLDER *f, char *name)
{
ITEM *t;
bool *ret;
// Validate arguments
if (f == NULL || name == NULL)
{
return 0;
}
t = CfgFindItem(f, name);
if (t == NULL)
{
return 0;
}
if (t->Type != ITEM_TYPE_BOOL)
{
return 0;
}
if (t->size != sizeof(bool))
{
return 0;
}
ret = (bool *)t->Buf;
if (*ret == false)
{
return false;
}
else
{
return true;
}
}
|
/* Get the value of the bool type*/
|
Get the value of the bool type
|
CfgGetInt
|
UINT CfgGetInt(FOLDER *f, char *name)
{
ITEM *t;
UINT *ret;
// Validate arguments
if (f == NULL || name == NULL)
{
return 0;
}
t = CfgFindItem(f, name);
if (t == NULL)
{
return 0;
}
if (t->Type != ITEM_TYPE_INT)
{
return 0;
}
if (t->size != sizeof(UINT))
{
return 0;
}
ret = (UINT *)t->Buf;
return *ret;
}
|
/* Get the value of the int type*/
|
Get the value of the int type
|
CfgFindItem
|
ITEM *CfgFindItem(FOLDER *parent, char *name)
{
ITEM *t, tt;
// Validate arguments
if (parent == NULL || name == NULL)
{
return NULL;
}
tt.Name = ZeroMalloc(StrLen(name) + 1);
StrCpy(tt.Name, 0, name);
t = Search(parent->Items, &tt);
Free(tt.Name);
return t;
}
|
/* Search for an item*/
|
Search for an item
|
CfgGetFolder
|
FOLDER *CfgGetFolder(FOLDER *parent, char *name)
{
return CfgFindFolder(parent, name);
}
|
/* Get a folder*/
|
Get a folder
|
CfgFindFolder
|
FOLDER *CfgFindFolder(FOLDER *parent, char *name)
{
FOLDER *f, ff;
// Validate arguments
if (parent == NULL || name == NULL)
{
return NULL;
}
ff.Name = ZeroMalloc(StrLen(name) + 1);
StrCpy(ff.Name, 0, name);
f = Search(parent->Folders, &ff);
Free(ff.Name);
return f;
}
|
/* Search a folder*/
|
Search a folder
|
CfgAddStr
|
ITEM *CfgAddStr(FOLDER *f, char *name, char *str)
{
wchar_t *tmp;
UINT tmp_size;
ITEM *t;
// Validate arguments
if (f == NULL || name == NULL || str == NULL)
{
return NULL;
}
// Convert to a Unicode string
tmp_size = CalcStrToUni(str);
if (tmp_size == 0)
{
return NULL;
}
tmp = Malloc(tmp_size);
StrToUni(tmp, tmp_size, str);
t = CfgAddUniStr(f, name, tmp);
Free(tmp);
return t;
}
|
/* Adding a string type*/
|
Adding a string type
|
CfgAddUniStr
|
ITEM *CfgAddUniStr(FOLDER *f, char *name, wchar_t *str)
{
// Validate arguments
if (f == NULL || name == NULL || str == NULL)
{
return NULL;
}
return CfgCreateItem(f, name, ITEM_TYPE_STRING, str, UniStrSize(str));
}
|
/* Add unicode_string type*/
|
Add unicode_string type
|
CfgAddBuf
|
ITEM *CfgAddBuf(FOLDER *f, char *name, BUF *b)
{
// Validate arguments
if (f == NULL || name == NULL || b == NULL)
{
return NULL;
}
return CfgAddByte(f, name, b->Buf, b->Size);
}
|
/* Add a binary*/
|
Add a binary
|
CfgAddByte
|
ITEM *CfgAddByte(FOLDER *f, char *name, void *buf, UINT size)
{
// Validate arguments
if (f == NULL || name == NULL || buf == NULL)
{
return NULL;
}
return CfgCreateItem(f, name, ITEM_TYPE_BYTE, buf, size);
}
|
/* Add byte type*/
|
Add byte type
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.