Skip to content

Instantly share code, notes, and snippets.

Avatar

Jad Altahan xv

View GitHub Profile
@xv
xv / notepad_encoding.c
Last active Jan 14, 2021
Decompiled subroutine used to detect the encoding of a given buffer.
View notepad_encoding.c
// FileTypeFromBuffer(LPCCH lpMultiByteStr, int cbMultiByte)
// arg1 -> buffer
// arg2 -> buffer size
uint64_t sub_140008284(int16_t* arg1, int64_t arg2)
uint64_t rax = zx.q(*data_140031648) // g_defaultEncoding = Reg val 'iDefaultEncoding' @ HKCU\SOFTWARE\Microsoft\Notepad
uint32_t rcx = zx.d(*arg1)
uint64_t rbx = zx.q(arg2.d)
if (rcx != 0xbbef)
int32_t rax_1
if (rcx != 0xfeff)
@xv
xv / ShellFileIcon.cs
Created Nov 6, 2020
Simple method to retrieve the 16x16 shell file icon using SHFILEINFO structure.
View ShellFileIcon.cs
internal const uint FILE_ATTRIBUTE_NORMAL = 0x80;
[Flags]
internal enum SHGetFileInfoFlags
{
SHGFI_LARGEICON = 0x0,
SHGFI_SMALLICON = 0x1,
SHGFI_OPENICON = 0x2,
SHGFI_SHELLICONSIZE = 0x4,
SHGFI_PIDL = 0x8,
@xv
xv / UndocumentedAcrylic.cs
Created Nov 5, 2020
Undocumented API for Windows 10 Acrylic style.
View UndocumentedAcrylic.cs
internal enum WindowCompositionAttribute
{
WCA_UNDEFINED = 0,
WCA_NCRENDERING_ENABLED = 1,
WCA_NCRENDERING_POLICY = 2,
WCA_TRANSITIONS_FORCEDISABLED = 3,
WCA_ALLOW_NCPAINT = 4,
WCA_CAPTION_BUTTON_BOUNDS = 5,
WCA_NONCLIENT_RTL_LAYOUT = 6,
WCA_FORCE_ICONIC_REPRESENTATION = 7,
@xv
xv / toggle_disk_space_warning.bat
Last active Oct 17, 2020
Tiny script to enbale/disable the "Low Disk Space" warning.
View toggle_disk_space_warning.bat
@echo off
rem Run this script as administrator
rem You may need to restart your computer to take effect
set hKey=HKLM
for /f "tokens=2 delims==." %%a in ('wmic os get version /value') do (
if %%a neq 10 set hKey=HKCU
)
@xv
xv / ColorFromHTML.cs
Created May 13, 2020
A much faster alternative to Microsoft's ColorTranslator.FromHtml() function.
View ColorFromHTML.cs
/// <summary>
/// Translates an HTML-format color value to a GDI+
/// <see cref="System.Drawing.Color"/> structure.
/// </summary>
///
/// <param name="htmlVal">
/// A 3 or 6 digit hexadecimal value to translate. Do not include the
/// leading "#" sign.
/// </param>
///
@xv
xv / mgsvtpp_gmp_address.txt
Created May 9, 2020
Static memory addresses for offline and online GMP/money values in Metal Gear Solid V: The Phantom Pain.
View mgsvtpp_gmp_address.txt
GMP Offline: mgsvtpp.exe+2BECE68
GMP Online : mgsvtpp.exe+2BECE6C
@xv
xv / InvertWindowBorder.cs
Created Mar 4, 2020
Flashes a screen-inverted rectangle around a window like in Microsoft Spy++.
View InvertWindowBorder.cs
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
static extern int SaveDC(IntPtr hWnd);
@xv
xv / cpp-cli-form-set-up.md
Created Sep 8, 2019
A really short guide on how to set up a UI form in C++/CLI.
View cpp-cli-form-set-up.md

If you are playing with C++/CLI you are probably already familiar with the C# or VB.NET way of doing WinForms, so there's nothing to be afraid of in CLI -- it is just a bit of pain in the ass at first.

Setting up the project

Assuming that you have C++/CLI installed, fire up Visual Studio and create an empty CLR project. Once the project is created, we need to let Visual Studio know what type of project (WinForms in this case) this is, as well as set an entry point for the application.

Open the project's Properties dialog (Alt+Enter) and select All Platforms from the Platform combo box. After that, you need to:

Define the project type

  1. Navigate to Configuration Properties >> Linker >> System in the tree-view control on the left side.
@xv
xv / del_file_content.bat
Created May 18, 2019
Iterates through files of a matching extension and deletes their content while keeping the files themselves.
View del_file_content.bat
@echo off
rem change .txt to whatever extension you want
type nul > content
for %%f in (*.txt) do copy /y content %%f
del content
@xv
xv / GetRelativeTime.py
Created Apr 10, 2019
Returns the relative time (also known as 'time ago') based on the given datetime object input.
View GetRelativeTime.py
from datetime import datetime
from math import floor
def get_relative_time(dateTime):
current_time = datetime.utcnow()
time_diff = current_time - dateTime
intervals = (
(time_diff.days / 36500, "century", "centuries"),
(time_diff.days / 3650, "decade", "decades"),
You can’t perform that action at this time.