Git Product home page Git Product logo

jandedobbeleer / clink Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisant996/clink

1.0 2.0 0.0 22.99 MB

Bash's powerful command line editing in cmd.exe

Home Page: https://chrisant996.github.io/clink/

License: GNU General Public License v3.0

C 28.93% Shell 1.68% Lua 3.51% NSIS 0.17% Makefile 0.32% HTML 5.11% CSS 0.03% C++ 50.72% Perl 2.21% TeX 5.64% Batchfile 0.31% Roff 1.22% M4 0.14%

clink's Introduction

Overview

Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities. Readline is best known for its use in the well-known Unix shell Bash, the standard shell for Mac OS X and many Linux distributions.

For details, refer to the Clink documentation.

Download

Downloads are available from the releases page.

See the issues page for known issues or to file new issues.

Features

  • The same line editing as Bash (from the GNU Readline library version 8.1).
  • History persistence between sessions.
  • Context sensitive completion;
    • Executables (and aliases).
    • Directory commands.
    • Environment variables.
  • Context sensitive colored input text.
  • New keyboard shortcuts;
    • Paste from clipboard (Ctrl+V).
    • Incremental history search (Ctrl+R and Ctrl+S).
    • Powerful completion (Tab).
    • Undo (Ctrl+Z).
    • Automatic cd .. (Ctrl+Alt+U).
    • Environment variable expansion (Ctrl+Alt+E).
    • Doskey alias expansion (Ctrl+Alt+F).
    • Scroll the screen buffer (Alt+Up, etc).
    • Shift+Arrow keys to select text, typing replaces selected text, etc.
    • (press Alt+H for many more...)
  • Directory shortcuts;
    • Typing a directory name followed by a path separator is a shortcut for cd /d to that directory.
    • Typing .. or ... is a shortcut for cd .. or cd ..\.. (each additional . adds another \..).
    • Typing - or cd - changes to the previous current working directory.
  • Scriptable completion with Lua.
  • Scriptable key bindings with Lua.
  • Colored and scriptable prompt.
  • Auto-answering of the "Terminate batch job?" prompt.

By default Clink binds Alt+H to display the current key bindings. More features can also be found in GNU's Readline and History libraries' manuals.

Usage

There are several ways to start Clink.

  1. If you installed the auto-run, just start cmd.exe. Run clink autorun --help for more info.
  2. To manually start, run the Clink shortcut from the Start menu (or the clink.bat located in the install directory).
  3. To establish Clink to an existing cmd.exe process, use <install_dir>\clink.exe inject.

Upgrading from Clink v0.4.9

The new Clink tries to be as backward compatible with Clink v0.4.9 as possible. However, in some cases upgrading may require a little bit of configuration work. More details can be found in the Clink documentation.

Extending Clink

Clink can be extended through its Lua API which allows easy creation of context sensitive match generators, prompt filtering, and more. More details can be found in the Clink documentation.

Building Clink

Clink uses Premake to generate Visual Studio solutions or makefiles for MinGW. Note that Premake >= 5.0-alpha12 is required.

  1. Cd to your clone of Clink.
  2. Run premake5.exe <toolchain> (where <toolchain> is one of Premake's actions - see premake5.exe --help)
  3. Build scripts will be generated in .build\<toolchain>. For example .build\vs2013\clink.sln.
  4. Call your toolchain of choice (VS, mingw32-make.exe, msbuild.exe, etc). GNU makefiles (Premake's gmake target) have a help target for more info.

Building Documentation

  1. Run npm install marked to install the marked markdown library.
  2. Run premake5.exe docs.

Debugging Clink

  1. Start Clink using any of the normal ways.
  2. Launch a debugger such as Visual Studio.
  3. Attach the debugger to the CMD.exe process that Clink was injected into.
    • If you break into the debugger now, it will be inside Clink code, waiting for keyboard input.
  4. Here are some breakpoints that might be useful:
    • host::edit_line is the start of showing a prompt and accepting input.
    • line_editor_impl::update_matches is where the match pipeline uses .generate() to collect matches and .select() to filter the matches.
    • rl_module::on_input and readline_internal_char (and the _rl_dispatch inside it) is where keys are translated through Readline's keymap to invoke commands.
    • rl_complete or rl_menu_complete or rl_old_menu_complete are the Readline completion commands.
    • alternative_matches builds a Readline match array from the results collected by the match pipeline.

Debugging Clink startup

The easiest way to debug Clink startup is to use simulated injection rather than real injection: set a breakpoint on initialise_clink and start clink testbed --hook under the debugger. All of the usual Clink startup code is executed, but the cross-process injection is only simulated, so the resulting prompts of course are not actually executed by CMD.exe.

To debug Clink startup during real injection, you must attach the debugger to the target CMD.exe before injection, set a breakpoint on initialise_clink (it will be an unresolved breakpoint at first), and then use clink inject -p process_id. The debugger should resolve the breakpoint as soon as the Clink DLL is loaded, and should hit the breakpoint soon after.

Debugging Clink DLL injection

To debug the actual DLL injection procedure, you must debug both the clink_x64.exe (or clink_x86.exe) process and the target CMD.exe process.

  • Set a breakpoint on process::remote_call_internal in the Clink process.
    • The first time it's reached should be for injecting a LoadLibrary call into the target CMD.exe process.
    • The second time it's reached should be for injecting an initialise_clink call into the target CMD.exe process.
  • Set a breakpoint on initialise_clink in the target CMD.exe process.
  • Step through the remote_call_internal function to inspect the local side of the operation.
    • The stdcall_thunk function is the instruction payload that will be copied into the target CMD.exe process.
    • Observe the value of region.base before the CreateRemoteThread call executes -- this is the address of the instruction payload that has been copied into the target CMD.exe process.
    • Set a breakpoint in the target CMD.exe process for that address -- when CreateRemoteThread executes, it will transfer execution to that address in the target CMD.exe process, and you can debug through the execution of the instruction payload itself.
    • Note: If the instruction payload references any functions or variables from the Clink process, it will crash during execution inside the target CMD.exe process.

Debugging Lua Scripts

  1. Use clink set lua.debug true to enable using the Lua debugger.
  2. Use clink set lua.break_on_error true to automatically break into the Lua debugger on any Lua script error.
  3. Add a pause() line in a Lua script to break into the debugger at that spot, if the lua.debug setting is enabled.
  4. Use help in the Lua debugger to get help on using the Lua debugger.

License

Clink is distributed under the terms of the GNU General Public License v3.0.

clink's People

Contributors

aavramch avatar adrianba avatar chi-bd avatar chrisant996 avatar cooloppo avatar elyscape avatar jandedobbeleer avatar jasper-bekkers avatar jtnord avatar koppor avatar matrixik avatar matthias-oe avatar michelepagot avatar mindw avatar mlloreda avatar mridgers avatar nikitalita avatar techtonik avatar vladimir-kotikov avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.