Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
taviso committed May 20, 2020
1 parent f1b3dcd commit 3a8698b
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
*.hem
.nobackup
build-*/
*.zip
10 changes: 5 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
include ../GNUmakefile.common
include GNUmakefile.common

LDLIBS += user32

%.hem: %.dll
cp $< $@
$(CP) $< $@

all: keyhelp.hem

keyhelp.dll: input.obj keyhelp.obj hiewgate.obj
keyhelp.dll: input.obj keyhelp.obj hiewgate.obj hiewkey.res

clean::
$(RM) *.hem

install: keyhelp.hem
cp $^ ~/User/Applications/Hiew/hem/
release::
zip hiewkey.zip keyhelp.hem README.md
191 changes: 191 additions & 0 deletions GNUmakefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# vim: syntax=make
#
# Reasonable default GNU Makefile rules for new Windows development projects.
#
# Notes
#
# * You can append rules to clean by using clean::
# * If you dont want the default rules, use one colon, e.g. clean:
# * Add everything you want built as a dependency to all
# * Append to existing flags/lists with +=, e.g. LDLIBS+=user32
# * Target specific changes should look like target: CFLAGS+=/xyz
# * `make debug` is the same as `make all` but without optimization flags.
# * `make release` is the same as `make all` but with NDEBUG and similar.
# * You can append rules to debug and release, just use ::
# * You dont need to override pattern commands, just do this:
# include ../GNUmakefile.common
# all: example.dll
# # The main file should be called example.c
# example.dll: otherdep1.obj otherdep2.obj
# * Append warnings you don't like to WIGNORE, e.g. WIGNORE+=/wd1234
#
# Examples
#
# simplest
#
# include ../GNUmakefile.common
#
# all: example.exe
#
# dependencies
#
# include ../GNUmakefile.common
#
# all: example.exe
#
# example.exe: example.obj foo.obj bar.obj
#
# cmake
#
# .INTERMEDIATE: cmake@dirname
# test.lib: CMPROJECT=Check # name of the project, default is name of dir
# test.lib: cmake@dirname # where the CMakeLists.txt is
# cp build-$(CMPROJECT)/foo.lib $@
#
#
# (c) 2019-2020 Tavis Ormandy <taviso@gmail.com>
#
CC=cl.exe
RC=rc.exe
AR=lib.exe
MIDL=midl.exe
MB=msbuild.exe
MT=mt.exe
CANDLE=candle.exe
LIGHT=light.exe
VSDEVCMD=cmd.exe /c vsdevcmd.bat
CANDLEFLAGS=-nologo
LIGHTFLAGS=-nologo
CPPFLAGS=
RFLAGS=/nologo
COPTFLAGS=/O2
CSECFLAGS=/guard:cf
CDEBFLAGS=/Wall /analyze $(WIGNORE)
BUILDCONFIG=Release
CFLAGS=/nologo $(CPPFLAGS) /Zi $(COPTFLAGS) $(CSECFLAGS) /GF
LFLAGS=/nologo /machine:x86
MFLAGS=
MTFLAGS=-nologo -canonicalize
CXXFLAGS=$(CFLAGS) /EHsc
LDLIBS=
LDFLAGS=/MT
LINKFLAGS=
CM=cmake.exe
CMFLAGS=-A Win32 -D CMAKE_BUILD_TYPE=$(BUILDCONFIG)
MBFLAGS=/nologo /m \
/verbosity:quiet \
/p:Configuration=$(BUILDCONFIG) \
/p:PlatformToolset=v142 \
/p:WindowsTargetPlatformVersion=10
VFLAGS=-no_logo
CMPROJECT=$(<D)

# List of warnings that are rarely useful
WIGNORE=/wd4668

# Commands arch specific actions.
ifeq ($(OS),Windows_NT)
# Native
CC64=$(VSDEVCMD) $(VFLAGS) -arch=amd64 ^& cl
CC32=$(VSDEVCMD) $(VFLAGS) -arch=x86 ^& cl
RM=del /q /f /s
RMDIR=rmdir /s /q
CP=copy
MV=move
CAT=type
else
# WSL
CC64=$(VSDEVCMD) $(VFLAGS) -arch=amd64 "&" cl
CC32=$(VSDEVCMD) $(VFLAGS) -arch=x86 "&" cl
RM=rm -f
RMDIR=rm -rf
CP=cp
MV=mv
CAT=cat

# Allow bash syntax in recipes
SHELL=/bin/bash
endif

.PHONY: clean

.DEFAULT_GOAL = all

# Debug configuration
debug:: COPTFLAGS =
debug:: CFLAGS += $(CDEBFLAGS)
debug:: BUILDCONFIG = Debug
debug:: LDFLAGS += /MTd
debug:: all

release:: CPPFLAGS += /DNDEBUG
release:: all

%.wixobj: %.wxs
$(CANDLE) $(CANDLEFLAGS) -out $@ $<

%.msi: %.wixobj
$(LIGHT) $(LIGHTFLAGS) -out $@ $<

%_i.h: %.odl
$(MIDL) $(MFLAGS) /h $@ $<

%_i.c: %.odl
$(MIDL) $(MFLAGS) /iid $@ $<

%.obj: %.cpp
$(CC) $(CXXFLAGS) /c /Fo:$@ $<

%.res: %.rc
$(RC) $(RFLAGS) $<

%.obj: %.cc
$(CC) $(CXXFLAGS) /c /Fo:$@ $<

%.obj: %.cxx
$(CC) $(CXXFLAGS) /c /Fo:$@ $<

%.obj: %.c
$(CC) $(CFLAGS) /c /Fo:$@ $<

%.exe: %.obj
$(CC) $(CFLAGS) $(LDFLAGS) /Fe:$@ $^ /link $(LINKFLAGS) $(LDLIBS:=.lib)

%.dll: %.obj
$(CC) $(CFLAGS) $(LDFLAGS) /LD /Fe:$@ $^ /link $(LINKFLAGS) $(LDLIBS:=.lib)

%.lib: %.obj
$(AR) $(LFLAGS) /OUT:$@ $^

%64.obj: %.c
$(CC) $(CFLAGS) /c /Fd:$(@:.obj=.pdb) /Fo:$@ $<

%32.obj: %.c
$(CC) $(CFLAGS) /c /Fd:$(@:.obj=.pdb) /Fo:$@ $<

%64.dll: CC=$(CC64)
%64.dll: %64.obj
$(CC) $(CFLAGS) $(LDFLAGS) /LD /Fd:$(@:.dll=.pdb) /Fe:$@ $^ /link $(LINKFLAGS) $(LDLIBS:=.lib)

%32.dll: CC=$(CC32)
%32.dll: %32.obj
$(CC) $(CFLAGS) $(LDFLAGS) /LD /Fd:$(@:.dll=.pdb) /Fe:$@ $^ /link $(LINKFLAGS) $(LDLIBS:=.lib)

%64.exe: CC=$(CC64)
%64.exe: %64.obj
$(CC) $(CFLAGS) $(LDFLAGS) /Fd:$(@:.dll=.pdb) /Fe:$@ $^ /link $(LINKFLAGS) $(LDLIBS:=.lib)

%32.exe: CC=$(CC32)
%32.exe: %32.obj
$(CC) $(CFLAGS) $(LDFLAGS) /Fd:$(@:.dll=.pdb) /Fe:$@ $^ /link $(LINKFLAGS) $(LDLIBS:=.lib)

cmake@%: %/CMakeLists.txt
$(CM) $(CMFLAGS) -S $(<D) -B build-$(CMPROJECT)
$(MB) $(MBFLAGS) build-$(CMPROJECT)/$(CMPROJECT).sln

# You can append more commands using clean::
clean::
-$(RM) *.exp *.exe *.obj *.pdb *.ilk *.msi *.res *.ipdb
-$(RM) *.iobj *.dll *.tmp *.manifest *.lib *.tlb *.wixobj
-$(RM) *.wixpdb *.nativecodeanalysis.xml *.def *.lib
-$(RM) build-*
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Hiewkey

This is a simple HEM (aka plugin) for the Hiew hex editor that simulates key
presses that are not possible when using a virtual terminal.

If you use Hiew over ssh, or under wsl, then this will help you use features
that normally require a Windows console.

![Hiewkey Screenshot](hiewkey.png)

# Installation

Copy `hiewkey.hem` to your `hem` folder, which is usually where you installed
hiew.

# Notes

Please file an issue if there are keystrokes I need to add.

# Author

Tavis Ormandy <taviso@gmail.com>
Binary file added hiewkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions hiewkey.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <windows.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0
{
BLOCK "StringFileInfo"
{
BLOCK "000004B0"
{
VALUE "CompanyName", "Tavis Ormandy"
VALUE "FileDescription", "Hiew Keyboard Helper"
VALUE "ProductName", "Hiewkey"
VALUE "Comment", "https://github.com/taviso/hiewkey"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0000, 0x04B0
}
}
40 changes: 36 additions & 4 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,17 @@ BOOL DecodeKeyString(LPCSTR HotKey, PKEY_EVENT_RECORD Record)
}
}

// In general, for ascii chars the lowercase form seems to be used.
if (KeyCode == Record->uChar.AsciiChar && isalpha(KeyCode)) {

// In general, for ascii chars the lowercase form seems to be used.
Record->uChar.AsciiChar = tolower(KeyCode);

// If you hold ctrl, you get the ctrl characters, in alphabetic
// order.
if (CtrlState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
// Is this right??????????????
Record->uChar.AsciiChar -= 'a' - 1;
}
}

if (KeyCode == Record->uChar.AsciiChar && isdigit(KeyCode)) {
Expand All @@ -258,6 +266,11 @@ BOOL DecodeKeyString(LPCSTR HotKey, PKEY_EVENT_RECORD Record)
// without localization, so I'll just simulate it.
Record->uChar.AsciiChar = ")!@#$%^&*("[KeyCode - '0'];
}
// fallthrough intentional.
// If CTRL is pressed with a digit, AsciiChar is always 0.
if (CtrlState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
Record->uChar.AsciiChar = 0;
}
}

// https://www.codeproject.com/Questions/511401/apluslittleplusaboutplusMSGplusHandingplusaboutplu
Expand All @@ -269,9 +282,28 @@ BOOL DecodeKeyString(LPCSTR HotKey, PKEY_EVENT_RECORD Record)
}
}

if (KeyCode == VK_OEM_PERIOD) {
if (CtrlState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
Record->uChar.AsciiChar = 0;
// This needs some work to understand.
if (CtrlState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
switch (KeyCode) {
case VK_RETURN:
Record->uChar.AsciiChar = '\n';
break;
case VK_OEM_7: // '#'
Record->uChar.AsciiChar = 28;
break;
case VK_OEM_4: // '['
case VK_OEM_6: // ']'
case VK_OEM_5: // '\\'
Record->uChar.AsciiChar -= 'A' - 1;
break;
case VK_OEM_1: // ';'
case VK_OEM_3: // '~'
case VK_OEM_PERIOD:
case VK_OEM_MINUS:
case VK_OEM_PLUS:
case VK_TAB:
Record->uChar.AsciiChar = 0;
break;
}
}

Expand Down
5 changes: 4 additions & 1 deletion keyhelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ typedef struct _HIEW_KEYS {
static HIEW_KEYS HiewKeys[] = {
{ "Ctrl+Alt", "information" },
{ "Ctrl+Backspace", "file history" },
{ "Ctrl+.", "start/stop recording macro to Macro0" }
{ "Ctrl+.", "start/stop recording macro to Macro0" },
{ "Ctrl+-", "Macro manager" },
{ "Ctrl+NumMult", "mark all" },
{ "Alt+NumMult", "resize block to current offset" },
};

DWORD WINAPI SendInputThread(LPVOID lpvThreadParam);
Expand Down

0 comments on commit 3a8698b

Please sign in to comment.