Tag: c


c – Output coloured text to a Windows terminal

GetStdHandle function retrieves a handle to the specified standard device (standard input, standard output, or standard error). GetConsoleScreenBufferInfo function retrieves information about the specified console screen buffer. SetConsoleTextAttribute function sets the attributes of characters written to the console screen buffer by the WriteFile or WriteConsole function, or echoed by the ReadFile or ReadConsole function. This …

C, Programming

Base64 with CryptoAPI and C

CryptBinaryToString The CryptBinaryToString function converts an array of bytes into a formatted string. – MSDN CryptStringToBinary The CryptStringToBinary function converts a formatted string into an array of bytes. – MSDN Base64 Encoding bool Base64EncodeA(char **dest, unsigned long *dlen, const unsigned char *src, unsigned long slen) { if (src == NULL) return false;   if (!CryptBinaryToStringA(src, …

C, Programming

Calculate SHA 512 hash using C and CryptoAPI

SHA-2 (Secure Hash Algorithm 2) is a set of cryptographic hash functions designed by the National Security Agency (NSA).[3] SHA stands for Secure Hash Algorithm. Cryptographic hash functions are mathematical operations run on digital data; by comparing the computed “hash” (the output from execution of the algorithm) to a known and expected hash value, a …

C, Programming

Edit PE file properties using C

Using MS Windows API you can edit PE file properties such as: * File version * Product version * File Description * Company name * Internal name * Copyright * Original filename * Product name GetFileVersionInfoSize Determines whether the operating system can retrieve version information for a specified file. If version information is available, GetFileVersionInfoSize …

Kernel, Rootkits

Load – Unload drivers during development

The easiest way to load your driver into the kernel, for testing, during kernel development is by creating a system service to load the driver for you. This method, of course, is not suggested for release due to forensics issues.   Windows API functions used in service installer: > OpenSCManager establishes a connection to the …


Suppress all error messages in C

SetErrorMode function controls whether the system will handle the specified types of serious errors or whether the process will handle them. #include <Windows.h>   SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);#include <Windows.h> SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);


Create a process in C

#include <stdlib.h> #include <stdio.h> #include <windows.h>     int main() { STARTUPINFO startInfo; PROCESS_INFORMATION procInfo;   //lock user WCHAR cmd[50] = L"rundll32.exe user32.dll, LockWorkStation\0";   SecureZeroMemory(&startInfo, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); SecureZeroMemory(&procInfo, sizeof(procInfo));   if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startInfo, &procInfo) != 0) return GetLastError();   CloseHandle(procInfo.hProcess); CloseHandle(procInfo.hThread);   return EXIT_SUCCESS; }#include …