Skip to content

Instantly share code, notes, and snippets.

View chaelim's full-sized avatar

C.S. Lim chaelim

View GitHub Profile
@chaelim
chaelim / RestoreIME.reg
Created December 19, 2012 08:05
Windows Vista and Windows 7 에서 한글, 일본, 중국 입력기 (IME)를 사용하게 해주는 레지스트리 파일입니다. Restore original IME on Windows Vista and Windows 7.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E0010404]
"Layout File"="KBDUS.DLL"
"Layout Text"="Chinese (Traditional) - Phonetic (IME)"
"IME file"="phon.ime"
"Layout Display Name"="@%SystemRoot%\\system32\\input.dll,-5066"
@chaelim
chaelim / WinConsoleSettings.reg
Created December 19, 2012 08:07
My Windows Command console settings registry file.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console]
"ColorTable00"=dword:00000000
"ColorTable01"=dword:00800000
"ColorTable02"=dword:00008000
"ColorTable03"=dword:00808000
"ColorTable04"=dword:00000080
"ColorTable05"=dword:00800080
"ColorTable06"=dword:00008080
@chaelim
chaelim / gist:5131715
Created March 11, 2013 03:33
C++ Macros
#if _MSC_VER
#define COMPILER_CHECK(expr, msg) typedef char COMPILE_ERROR_##msg[1][(expr)]
#else
#define COMPILER_CHECK(expr, msg) typedef char COMPILE_ERROR_##msg[1][(expr)?1:-1]
#endif
// Note From MSDN:
// In past versions of the Visual C++ compiler, the _ReadWriteBarrier
// and _WriteBarrier functions were enforced only locally and did not
// affect functions up the call tree. In Visual C++ 2005 and later,
// these functions are enforced all the way up the call tree.
// Intel and AMD (x86 and AMD64) enforces strong ordering (program ordering)
// except a store followed by a load (the store becomes visible before
// the load executes) http://en.wikipedia.org/wiki/Memory_ordering
#include <windows.h>
#include <process.h>
#include <stdio.h>
#include <intrin.h>
#define DO_FLUSH
unsigned __stdcall thread(void* p)
{
unsigned __int64 t1 = __rdtsc();
/****************************************************************************
*
* BrokenGuardPage.cpp
*
* Just use following commands for compile:
* cl BrokenGuardPage.cpp
*
* Written by CS Lim (9/26/2006)
*
***/
@chaelim
chaelim / C++ ArraySize Macros
Last active December 17, 2015 01:39
C++ ArraySize Macros
VC stdlib.h macro
/* _countof helper */
#if !defined(_countof)
#if !defined(__cplusplus)
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
#else
extern "C++"
{
template <typename _CountofType, size_t _SizeOfArray>
@chaelim
chaelim / gist:ec362cfbfa72728b57ee
Created June 20, 2014 04:55
InterLockedSList internals (Kernel exception handler trick)
========================================================================
FIND PAGE FAULT IDT (KiTrap0E)
========================================================================
kd> !pcr 0
Find "KPCR for Processor 0 at fffff80001176000:"
kd> dt _KPCR fffff80001176000
Find "+0?38 IdtBase : 0xfffff800`03694070 _KIDTENTRY64"
kd> r? $t0=(_KIDTENTRY64 *)0xfffff800`03694070; .for (r $t1=0; @$t1 <= 13; r? $t0=(_KIDTENTRY64 *)@$t0+1) { .printf "Interrupt vector %d (0x%x):\n", @$t1, @$t1; ln @@c++(@$t0->OffsetHigh*0x100000000 + @$t0->OffsetMiddle*0x10000 + @$t0->OffsetLow); r $t1=$t1+1 }
@chaelim
chaelim / gist:3bcd0eb1e29b82ddac1e
Created June 20, 2014 04:59
FlushProcessWriteBuffers API disassembly
Opened log file 'FlushProcessWriteBuffers.log'
0: kd> x nt!*FlushProcessWriteBuffers*
fffff800`0226da70 nt!KeFlushProcessWriteBuffers = <no type information>
fffff800`0225a9d0 nt!NtFlushProcessWriteBuffers = <no type information>
fffff800`022a0720 nt!ZwFlushProcessWriteBuffers = <no type information>
fffff800`0226e3cc nt!KiFlushProcessWriteBuffersTarget = <no type information>
0: kd> u fffff800`0225a9d0
nt!NtFlushProcessWriteBuffers:
fffff800`0225a9d0 33c9 xor ecx,ecx
fffff800`0225a9d2 e999300100 jmp nt!KeFlushProcessWriteBuffers (fffff800`0226da70)
@chaelim
chaelim / EncodePointerAPI
Last active December 13, 2016 22:48
Win32 Encode/DecodePointer
Obfuscating memory pointer using EncodePointer/DecodePointer APIs
https://msdn.microsoft.com/en-us/library/bb432254%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/bb432242(v=vs.85).aspx