Skip to content

Instantly share code, notes, and snippets.

@kennico
Last active February 24, 2019 07:49
Show Gist options
  • Save kennico/35769df278ebc87605a503b9cebcd019 to your computer and use it in GitHub Desktop.
Save kennico/35769df278ebc87605a503b9cebcd019 to your computer and use it in GitHub Desktop.
Handy commands in daily windows coding

Handy commands on Windows

Visual Studio

Macros

Go to "Properties" -> "C/C++" -> "Preprocessor" and add the following contents to "Preprocessor Definitions".

_MSC_PLATFORM_TOOLSET_$(PlatformToolset)
_MSC_PLATFORM_TOOLSET_VERSION=$(PlatformToolsetVersion)

Then you can use it in your code:

#ifndef _MSC_PLATFORM_TOOLSET_v141_xp
// ...
#endif

It seems that _USING_V110_SDK71_ inherited from defaults also works. :-D

Open dev tools in powershell from Visual Studio

  1. Open VS
  2. "Tools" -> "External Tools..." -> select "Visual Studio &Command Prompt"
  3. Change the value in "Initial directory" to $(SolutionDir)
  4. Change the value in "Arguments" to /K "vsdevcmd.bat -no_logo" & powershell

Similarily, you can open a command line prompt with all environment variables inherited from dev tools.

  • Dev Command Prompt
Title Command Arguments Initial directory
Dev Command %systemroot%\system32\cmd.exe /K "vsdevcmd.bat -no_logo" $(ProjectDir)
  • Dev Powershell
Title Command Arguments Initial directory
Dev Powershell %systemroot%\system32\cmd.exe /K "vsdevcmd.bat -no_logo" & powershell $(ProjectDir)
  • Open Binary Directory
Title Command Arguments Initial directory
Open Binary Directory %systemroot%\system32\cmd.exe /C "start ." $(BinDir)

See here for more options of cmd.

Dump binary - dumpbin

  • Output information of sections
dumpbin 0day-console-app.exe /headers

Dump binary like hexdump in powershell

format-hex tmp.out

output:

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   66 51 B4 01                                      fQ´.

Compiler cl

Compiler options on MSDN docs

  • /FA : output assembly in text

Environment variables and basic input/output

Commands Powershell Batch
Print path echo $env:path echo %path%
Print the working directory echo $pwd echo %cd%
Set an environment variable $env:GEOS_DIR="$pwd\build" set GEOS_DIR=%cd%\build

Powershell

  • Concantenate strings and ouput "Hello, world" using command substitution which is not supported in command prompt:
echo ", " > 1.in
echo "Hellow$(type 1.in)world!" > 2.in
type 2.in

However, neither type nor gc(Get-Content) could outperform the unix-like cat on manipulating binary file in a convenient way. MinGW saves the day.:-p

Command line prompt

Default settings for command prompt are stored under HKEY_CURRENT_USER\Console and HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe.

  • Dump bytes to file using python
python -c "print('\x44'*(220-177))" > test.out
  • Print file content:
type test.out

Enable just-in-time debugging in Win10

See here for tennical information.

Disable Windows error reporting:

Windows Error Reporting could be taking over the error handling on your computer. To fix this issue, use Registry Editor to add a DWORD Value of Disabled, with Value data of 1, to the following registry keys:

  • HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Windows Error Reporting
  • (For 64-bit machines): HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows\Windows Error Reporting

Configuring Automatic Debugging:

A known Windows issue may be causing the Just-In-Time debugger to fail. The fix is to add a DWORD Value of Auto, with Value data of 1, to the following registry keys:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug
  • (For 64-bit machines): HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug

Additionally, run windbg -I to install windbg as the default debugger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment