Skip to content

Instantly share code, notes, and snippets.

@wordijp
Created December 2, 2016 06:30
Show Gist options
  • Select an option

  • Save wordijp/134846e38d908130f1a7fd2f502d7eab to your computer and use it in GitHub Desktop.

Select an option

Save wordijp/134846e38d908130f1a7fd2f502d7eab to your computer and use it in GitHub Desktop.
Paper Plane xUIのモジュールを作る際のヘルパコマンド

ビルド & インストール

$ make
$ make test
test ok

生成されたppx-commandhash.exeをパスが通った場所に置く

使い方

例えば、「testcommand」を作りたい場合

$ ppx-commandhash testcommand
0xdd7757f7

と表示されるので、PPx Text Moduleのソース等にこのハッシュ値を使って

pxs.command->commandhash == 0xdd7757f7

と条件を追加する。

#include <Windows.h>
#include <stdio.h>
// from CHRTYPE.C
char T_CHRTYPE[256] = {
0x40,0x41,0x41,0x41,0x41,0x41,0x41,0x41, /*00*/
0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41, /*10*/
0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, /*20*/
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d, /*30*/
0x0d,0x0d,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x19,0x19,0x19,0x19,0x19,0x19,0x11, /*40*/
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, /*50*/
0x11,0x11,0x11,0x01,0x01,0x01,0x01,0x01,
0x01,0x29,0x29,0x29,0x29,0x29,0x29,0x21, /*60*/
0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,
0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21, /*70*/
0x21,0x21,0x21,0x01,0x01,0x01,0x01,0x41,
0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02, /*80*/
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, /*90*/
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, /*a0*/
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, /*b0*/
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, /*c0*/
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, /*d0*/
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, /*e0*/
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, /*f0*/
0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x01};
// from CHRTYPE.H
#define T_IS_LOW 32 /* 英小文字 */
// ANSI
#define IslowerA(c) (T_CHRTYPE[(unsigned char)(c)] & T_IS_LOW)
// UNICODE
#define IslowerW(c) ((c) >= 'a' && (c) <= 'z')
#ifdef UNICODE
#define Ispunct IspunctW
#define Islower IslowerW
#else
#define Islower IslowerA
#endif
// from TOROWIN.H
#define B31 0x80000000
// from PPXCMDS.C
#define CID_USERNAME B31 // この一覧にないコマンド
// ----------------------------------------------
// from PPX_CV
TCHAR upper(TCHAR c)
{
if (Islower(c)) c -= (TCHAR)0x20;
return c;
}
// from PPD_CMD.C
DWORD GetModuleNameHash(const TCHAR *src,TCHAR *dest)
{
DWORD hash = 0;
while( *src != '\0' ){
TCHAR c;
c = upper(*src++);
*dest++ = c;
hash = (DWORD)(hash << 6) | (DWORD)(hash >> (32 - 6)) | (DWORD)c;
}
*dest = '\0';
return hash | CID_USERNAME;
}
// ----------------------------------------------
void test()
{
TCHAR strHash[11];
TCHAR dest[64];
sprintf(strHash, "0x%lx", GetModuleNameHash("clippedtext", dest));
if (strcmp(strHash, "0xf75d5755") == 0) {
printf("test ok");
} else {
fprintf(stderr, "test failed");
exit(-1);
}
}
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("usage) %s CMDNAME\n", argv[0]);
printf(" %s --test", argv[0]);
return 1;
}
if (strcmp(argv[1], "--test") == 0) {
test();
return 0;
}
TCHAR dest[64];
printf("0x%lx", GetModuleNameHash(argv[1], dest));
return 0;
}
TARGET = ppx-commandhash.exe
#CXX = gcc
CXX = i686-w64-mingw32-gcc
CXXFLAGS = -Wall -O2 -g
SRCS = main.c
OBJS = $(patsubst %, obj/%, $(SRCS:.c=.o))
# -----------------------------------------------
all: obj $(TARGET)
obj:
mkdir obj
obj/%.o: %.c
$(CXX) $(CXXFLAGS) -o $@ -c $<
$(TARGET): $(OBJS)
$(CXX) $(OBJS) -o $@
strip $@
test: $(TARGET)
@$(TARGET) --test
clean:
rm -f $(TARGET)
rm -Rf obj
# -----------------------------------------------
.PHONY: clean test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment