Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / client-socket-shell1.cpp
Last active December 10, 2018 18:34
Basic client socket with Winsock - or Windows socket API - https://caiorss.github.io/C-Cpp-Notes/WindowsAPI-cpp.htm
//-----------------------------------------------------------------
// File: client-socket-shell1.cpp
// Brief: Basic Winsocket (Windows socket) echo client shell in C++.
// Author: Caio Rodrigues
//-----------------------------------------------------------------
#include <iostream>
#include <string>
#include <windows.h>
#pragma comment (lib, "Ws2_32.lib")
@caiorss
caiorss / WinBase.h
Last active December 10, 2018 15:29
Windows system header files - Collected from Windows 10
// File: c:/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/um/WinBase.h
//@[contract("winbase"), comment("MVI_tracked - https://osgwiki.com/wiki/Microsoft_Virus_Initiative")];
#include <winapifamily.h>
/************************************************************************
* *
* winbase.h -- This module defines the 32-Bit Windows Base APIs *
* *
@caiorss
caiorss / listFiles.cpp
Created December 8, 2018 18:42
Winapi - List directory files - program similar to Linux ls - https://caiorss.github.io/C-Cpp-Notes/WindowsAPI-cpp.html
// File: listFiles.cpp
// Brief: List all files of a given directory
// Note: Windows-only - Uses API
// Author: Caio Rodrigues
//----------------------------------------------------
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <functional>
@caiorss
caiorss / showModulesDLL.cpp
Created December 8, 2018 05:27
List all modules DLLs (Dynamic Linked Libraries) loaded by some process. -- https://caiorss.github.io/C-Cpp-Notes/WindowsAPI-cpp.html
// File; showModulesDLL.cpp
// Brief: List all modules DLLs (Dynamic Linked Libraries) loaded by some process.
// Author: Caio Rodrigues
//-----------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <iomanip>
#include <functional>
//- Windows Headers ---
@caiorss
caiorss / console-utf8.cpp
Created December 7, 2018 17:38
Windows console (cmd.exe) in Unicode UTF8 mode
// File: console-utf8.cpp
// Brief: Sets Windows Console to UTF8
// Author: Caio Rodrigues
//-------------------------------------------------------------
#include <iostream>
#include <string>
#include <windows.h>
// Uses RAII for setting console to UTF8
@caiorss
caiorss / winapi-enconding1.cpp
Created December 7, 2018 05:51
Test Windows API character enconding features. - https://caiorss.github.io/C-Cpp-Notes/WindowsAPI-cpp.html
// File: winapi-enconding1.cpp
// Brief: Test Windows API character enconding features.
// Author: Caio Rodrigues
//-----------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
// Enable Unicode version of Windows API compile with -DWITH_UNICODE
@caiorss
caiorss / copy-swap1.cpp
Created December 3, 2018 22:21
Copy-and-swap idiom for implementing rule-of-three and rule-of-five in C++11. - https://caiorss.github.io/C-Cpp-Notes/cpp-design-patterns.html
// File: copy-swap1.cpp
// Brief: Demonstration of copy-and-swap idiom for implementing rule-of-three and rule-of-five.
// Author: Caio Rodrigues
//-----------------------------------------------------------------
#include <iostream>
#include <ostream> // Operator (<<) overload for class ostream
#include <utility> // std::swap
#include <iterator> // std::begin, std::end
#include <algorithm>
#include <cstring> // strlen, strcpy, ...
// File: binfo.cpp
// Brief: Get information about binary files and identify them using the "magic numbers".
// Author: Caio Rodrigues
// File signature or magic number database: https://gist.github.com/overtrue/0a2aec7c2fbe9621a869
// C++ Standard: >= C++14
//----------------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
@caiorss
caiorss / rpn-calculator.cpp
Created November 20, 2018 15:07
Example HP-48 Reverse Polish Notation Interpreter in moder C++ (>= C++11) - https://caiorss.github.io/C-Cpp-Notes/sample-modern-cpp-programs.html
/** File: rpn-calculator.cpp
* Author: Caio Rodrigues - caiorss <DOT> rodrigues <AT> gmail <DOT> com
* Brief: Reverse Polish Notation Calculator
* Description: A simple reverse polish notation command line calculator
* implemented in modern C++.
* Site: https://caiorss.github.io/C-Cpp-Notes/sample-modern-cpp-programs.htm
***************************************************************************/
#include <iostream>
#include <cmath>
#include <map>
@caiorss
caiorss / bsd-socket-shell.cpp
Last active November 28, 2022 14:40
A telnet-like tool. It can bind a login shell to client or server socket - https://caiorss.github.io/C-Cpp-Notes/sample-modern-cpp-programs.html
// File: bsd-socket-shell.cpp
// Brief: A telnet-like tool. It can bind a login shell to client or server socket.
// Objective: Model client/server sockets on U-nix like OSes and play with C++ and Posix syscalls.
// Author: Caio Rodrigues
// Url: https://caiorss.github.io/C-Cpp-Notes/sample-modern-cpp-programs.html
//--------------------------------------------------------------------------------------
//-------- C++ specific headers>
#include <iostream>
#include <string>