Skip to content

Instantly share code, notes, and snippets.

View daiakushi's full-sized avatar
🏠
Working from home

daiakushi daiakushi

🏠
Working from home
View GitHub Profile
@daiakushi
daiakushi / CmdParser.cpp
Created August 21, 2023 03:01
Simple Command Parser
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
/*
* @ A simple parser can recognize shell command options in format
* "--<option> <args>" or "--<option>=<args>".
* @ Note. It tolerate spaces in args.
@daiakushi
daiakushi / winHttpClient.cpp
Last active September 4, 2023 02:31
A simple web client implemented by WinHTTP service APIs
#include <windows.h>
#include <winhttp.h>
#include <array>
#include <iostream>
#include <string>
#pragma comment(lib, "Winhttp.lib")
using namespace std;
@daiakushi
daiakushi / HashData.c
Last active December 13, 2022 02:41
Creating a Hash with CNG
// Client should release HashData with HeapFree()
// e.g. HeapFree(GetProcessHeap(), 0, HashData);
// Ref. https://learn.microsoft.com/en-us/windows/win32/seccng/creating-a-hash-with-cng
NTSTATUS HashCreate (
LPCWSTR HashAlg,
PBYTE RawData,
DWORD RawDataSize,
PBYTE *HashData,
DWORD *HashDataSize
)
@daiakushi
daiakushi / ReadFile.c
Created December 13, 2022 02:26
ReadFile() with standard Windows API
// Client should release FileBuffer with HeapFree()
// e.g. HeapFree(GetProcessHeap(), 0, buffer);
VOID FileRead(
char *Filename,
PBYTE *FileBuffer,
DWORD *FileSize
)
{
HANDLE hFile;
PBYTE buffer = NULL;
import sys
for i in sys.argv:
print i
@daiakushi
daiakushi / VerbalArithmetic.py
Created April 6, 2016 08:36
Solve Verbal Arithmetic in Python
# -*- coding: utf-8 -*-
#
# https://www.udacity.com/course/cs212
import re, itertools, string
def fill_in(formula):
letters = ''.join(set([s for s in formula if s in string.uppercase]))
for i in itertools.permutations('0123456789', len(letters)):
trans = string.maketrans(letters, ''.join(i))
@daiakushi
daiakushi / mylua.c
Created January 21, 2016 14:20
Lua interacts with C
#include "lua.h"
#include "lauxlib.h"
int l_bar(lua_State *L)
{
const char *str = lua_tostring(L, -1);
int length;
while (1) {
char c = str[length];
if (c == '\0')
@daiakushi
daiakushi / GetSmbios.c
Last active December 9, 2022 09:59
Dump raw SMBios table
#include <windows.h>
typedef struct RAW_SMBIOS_DATA
{
BYTE Used20CallingMethod;
BYTE MajorVersion;
BYTE MinorVersion;
BYTE Revision;
DWORD Length;
BYTE SMBIOSTableData[];
@daiakushi
daiakushi / GetBitLockerStatus.cpp
Last active September 11, 2023 06:58
Windows WMI Example to: 1. Get properties from WMI Class 2. Execute methods provided by WMI Class
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")
int main(int argc, char **argv)
{
#include <iostream>
#define STRINGIZE(something) STRINGIZE_HELPER(something)
#define STRINGIZE_HELPER(something) #something
using namespace std;
int Test02()
{
int foo = 999;