Batch File with Self-Awareness

Batch file is a double-edged sword, the good side is that batch file runs on almost all of the Microsoft platforms, while the evil side is people just couldn’t get it right. At the highest level, batch file is interpreted by the command processor, which is cmd.exe or command.com. The interpreter is in charge of: Process escape sequences (e.g. caret). Expand…

1

Pop Quiz – JavaScript for Fun

Most people could write something in JavaScript, though they barely made it correct. I started using JavaScript while I was in school, and the project I gave myself was to implement a Scheme interpreter that runs in web browsers. As a result, I’ve realized the tight relationship between JavaScript and Scheme, I became a fan of JavaScript and…

0

Vector Deleting Destructor

Today one guy in my team asked a question regarding the behavior of delete[] operator in C++ – how does the program know it needs to call CBar::~CBar instead of CFoo::~CFoo? Note that the vector deleting destructor is a feature in Microsoft C++ Compiler, not required by the C++ standard. #define _CRTDBG_MAP_ALLOC #include <malloc.h> #include <crtdbg.h> class CFoo { public:   virtual ~CFoo() = 0; }; class CBar…

0

Undocumented Environment Variables

Although we have less Easter Eggs, there are still a huge number of undocumented behaviors. Recently I’m writing a CLR profiler using ICorProfilerCallback for fun, the CLR profiler was modeled as an in-proc COM server, and the activition was done through environment variables: SET COR_ENABLE_PROFILING=1 SET COR_PROFILER={XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} SET COR_PROFILER_PATH=”C:\FOO\BAR\MyProfiler.dll” Immediately I realized there must be a lot more…

0

The Pit of Success

The Pit of Success: in stark contrast to a summit, a peak, or a journey across a desert to find victory through many trials and surprises, we want our customers to simply fall into winning practices by using our platform and frameworks. To the extent that we make it easy to get into trouble we…

0

Error and Exception Revisited

Unless suffering is the direct and immediate object of life, our existence must entirely fail of its aim. It is absurd to look upon the enormous amount of pain that abounds everywhere in the world, and originates in needs and necessities inseparable from life itself, as serving no purpose at all and the result of…

0

A Debugging Approach to Windows RT

Recently I got a Surface with Windows RT. Needless to mention, it’s wonderful! I’ve figured out some quick facts about Windows RT by looking at the C:\Windows\system32\ntdll.dll from Windows RT: A complete NT (instead of WINCE) kernel and almost a full stack of Windows operating system. Almost the same PE/COFF structure as x86. Using ARM’s “non classic RISC style”…

1

Postmortem Debugging – Better Late Than Never

If there is a consistent repro, I would definitely prefer Early Debugging. However in the real life postmortem debugging seems to be unavoidable.  There are three concepts I wish to clarify before digging into the details: AeDebug is a set of registry keys which specify the behavior when unhandled exception happened in an user mode application. \\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug \\HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows…

0

Windows 8 and conhost.exe

While debugging a console application on Windows 8, I noticed the console application is trying to create a process in the very beginning: windbg.exe -xe ld:ntdll.dll -c “bm ntdll!*CreateProcess*; g; k” cmd.exe CommandLine: cmd.exeModLoad: 000007ff`01d60000 000007ff`01f1e000   ntdll.dllntdll!RtlUserThreadStart:000007ff`01d7c3d0 4883ec48        sub     rsp,48hProcessing initial command ‘bm ntdll!*CreateProcess*; g; k’0:000> bm ntdll!*CreateProcess*; g; k  1: 000007ff`01d90f60 @!”ntdll!RtlCreateProcessParametersEx”  2: 000007ff`01d63070…

1

Visualize Assembly using DGML

Starting from Visual Studio 2010 Ultimate there is a cool feature called DGML (Directed Graph Markup Language). I wrote a small script to convert the disassembled code from WinDBG into a DGML. In order to use it, simply type the following commands under a debug session: .shell -o LoadLibraryA.dgml -ci “uf kernel32!LoadLibraryA” cscript.exe /nologo dasm2dgml.js…

0