├── .gitignore ├── COPYING.BSD ├── Makefile ├── Makefile.msvc ├── README.md ├── msrt ├── msvcrt-light-x64.def ├── msvcrt-light-x86.def ├── ntdll-x64.def └── ntdll-x86.def └── src ├── balance.c ├── balance.h ├── bosskey.c ├── bosskey.h ├── cjson.c ├── cjson.h ├── cpu_info.c ├── cpu_info.h ├── general.c ├── general.h ├── ice_error.c ├── ice_error.h ├── ini_parser.c ├── ini_parser.h ├── inject.c ├── inject.h ├── json_paser.c ├── json_paser.h ├── lz4.c ├── lz4.h ├── minhook ├── LICENSE.txt ├── Makefile ├── Makefile.msvc ├── README.md ├── include │ ├── MinHook.h │ ├── intrin_c.h │ ├── intrin_gcc.h │ └── intrin_x86.h └── src │ ├── buffer.c │ ├── buffer.h │ ├── hde │ ├── hde32.c │ ├── hde32.h │ ├── hde64.c │ ├── hde64.h │ ├── table32.h │ └── table64.h │ ├── hook.c │ ├── trampoline.c │ └── trampoline.h ├── new_process.c ├── new_process.h ├── on_tabs.c ├── on_tabs.h ├── portable(example).ini ├── portable.c ├── portable.h ├── resource.rc ├── safe_ex.c ├── safe_ex.h ├── set_env.c ├── set_env.h ├── win_automation.h ├── win_registry.c ├── win_registry.h └── winapis.h /.gitignore: -------------------------------------------------------------------------------- 1 | #OS junk files 2 | [Tt]humbs.db 3 | *.DS_Store 4 | 5 | #Visual Studio files 6 | *.[Oo]bj 7 | *.user 8 | *.aps 9 | *.pch 10 | *.vspscc 11 | *.vssscc 12 | *_i.c 13 | *_p.c 14 | *.ncb 15 | *.suo 16 | *.tlb 17 | *.tlh 18 | *.bak 19 | *.[Cc]ache 20 | *.ilk 21 | *.log 22 | *.sbr 23 | *.sdf 24 | *.opensdf 25 | *.unsuccessfulbuild 26 | Ankh.NoLoad 27 | 28 | #GCC files 29 | *.o 30 | *.d 31 | *.res 32 | *.dll 33 | *.a 34 | 35 | #the build output directory 36 | ipch/ 37 | obj/ 38 | [Ll]ib 39 | [Bb]in 40 | [Dd]ebug*/ 41 | [Rr]elease*/ 42 | .dep/ 43 | -------------------------------------------------------------------------------- /COPYING.BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2018, libportable for Iceweasel project authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are 4 | permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of 7 | conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 10 | of conditions and the following disclaimer in the documentation and/or other materials 11 | provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY SUMATRAPDF PROJECT AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 15 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUMATRAPDF PROJECT AUTHORS OR 16 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 20 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 21 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC := $(CROSS_COMPILING)gcc 2 | CFLAGS = -O2 3 | LD = $(CC) -o 4 | MSCRT := -mcrtdll=ucrt 5 | MSVC = 0 6 | DFLAGS ?= 7 | LTO ?= 8 | AR ?= ar 9 | RC ?= windres -i 10 | 11 | RC_TAR32 = -F pe-i386 12 | RC_TAR64 = -F pe-x86-64 13 | RCFLAGS = --define UNICODE -J rc -O coff 14 | USE_GCC = 15 | 16 | ifeq ($(findstring clang,$(CC)),) 17 | USE_GCC = 1 18 | endif 19 | 20 | BUILD = $(shell file `which $(CC) 2>/dev/null` 2>/dev/null | grep x86-64) 21 | T_CC = $(findstring x86_64-w64-mingw32-clang,$(CC)) 22 | 23 | ifeq ($(BUILD),) 24 | BITS = 32 25 | else 26 | BITS = 64 27 | endif 28 | 29 | ifneq ($(CROSS_COMPILING),) 30 | ifneq ($(BITS),32) 31 | BITS = 64 32 | endif 33 | endif 34 | 35 | CFLAGS += $(DFLAGS) -Wall -Wno-unused -Wno-format -Wno-int-to-pointer-cast \ 36 | -Wno-unknown-pragmas -finline-functions -DINITGUID \ 37 | -DWINVER=0x0501 -D_WIN32_IE=0x0601 -mavx 38 | 39 | ifeq ($(findstring clang,$(CC)),clang) 40 | CXX = $(CC)++ 41 | CFLAGS += -Wno-ignored-attributes -Wno-unknown-attributes -Wno-deprecated-declarations 42 | ifneq (,$(filter $(DFLAGS),--target=x86_64-pc-windows --target=x86_64-pc-windows-msvc --target=i686-pc-windows --target=i686-pc-windows-msvc)) 43 | CFLAGS += -D_CRT_SECURE_NO_WARNINGS -DVC12_CRT 44 | MSCRT = 45 | MSVC = 1 46 | LDFLAGS := $(filter-out -s,$(LDFLAGS)) -fuse-ld=lld 47 | endif #target x86_64 or i686 48 | ifneq (,$(findstring i686,$(DFLAGS))) 49 | BITS = 32 50 | else 51 | BITS = 64 52 | endif 53 | endif # clang 54 | 55 | #llvm-rc not support clang-gnu-ld Toolchains,we use windres 56 | ifeq ($(USE_GCC),) 57 | AR = llvm-ar.exe 58 | ifneq ($(filter $(MSVC)-$(T_CC),1-$(T_CC) 0-$(CC)),) 59 | RC = llvm-rc.exe 60 | RCFLAGS = -nologo -D "_UNICODE" -D "UNICODE" -FO 61 | else 62 | USE_RES = 1 63 | endif 64 | else 65 | USE_RES = 1 66 | endif 67 | 68 | MD = mkdir -p 69 | CP = cp 70 | SRC = src 71 | SUB_DIR = $(SRC)/minhook 72 | SUBMK = $(MAKE) -C $(SUB_DIR) 73 | DEP = .dep 74 | X86FLAG = -D_WIN32 -m32 75 | X64FLAG = -D_WIN64 -m64 76 | OBJECTS = $(DEP)/portable.o $(DEP)/general.o $(DEP)/ice_error.o $(DEP)/safe_ex.o \ 77 | $(DEP)/inject.o $(DEP)/bosskey.o $(DEP)/new_process.o $(DEP)/set_env.o\ 78 | $(DEP)/cpu_info.o $(DEP)/balance.o $(DEP)/win_registry.o $(DEP)/on_tabs.o \ 79 | $(DEP)/lz4.o $(DEP)/cjson.o $(DEP)/json_paser.o $(DEP)/ini_parser.o 80 | MIN_INC = $(SRC)/minhook/include 81 | CFLAGS += -fvisibility=hidden -DCJSON_HIDE_SYMBOLS -I$(MIN_INC) -I$(SRC) 82 | DISTDIR = Release 83 | OUT1 = $(DISTDIR)/libminhook$(BITS).a 84 | ifeq ($(MSVC),1) 85 | OBJECTS += $(DEP)/on_tabs.o 86 | endif 87 | 88 | EXEC = \ 89 | @echo Starting Compile... \ 90 | $(shell $(MD) $(DISTDIR) 2>/dev/null) \ 91 | $(shell $(MD) $(DEP) 2>/dev/null) \ 92 | 93 | ifeq ($(BITS),32) 94 | CFLAGS += $(X86FLAG) 95 | LDFLAGS += -m32 96 | ASMFLAGS = -fwin32 -DWINDOWS -D__i386__ -DWIN32 -Worphan-labels 97 | else ifeq ($(BITS),64) 98 | CFLAGS += $(X64FLAG) 99 | LDFLAGS += -m64 100 | ASMFLAGS = -fwin64 -DWINDOWS -D__x86_64__ -Worphan-labels 101 | endif 102 | 103 | ifeq ($(LIBPORTABLE_STATIC),1) 104 | CFLAGS += -DLIBPORTABLE_STATIC 105 | LD = $(AR) rcs 106 | OUT = $(DISTDIR)/portable$(BITS)_s.lib 107 | TETE = $(DISTDIR)/tmemutil_s.lib 108 | LDFLAGS = 109 | OBJS = $(DEP)/*.o 110 | else # not build LIBPORTABLE_STATIC 111 | OUT = $(DISTDIR)/portable$(BITS).dll 112 | TETE = $(DISTDIR)/tmemutil.dll 113 | DEPLIBS = -lminhook$(BITS) 114 | LDLIBS = -lshlwapi -lshell32 -lole32 115 | LDFLAGS += -L$(DISTDIR) $(DEPLIBS) -lkernel32 -luser32 -s 116 | DLLFLAGS += -fPIC -shared 117 | 118 | ifdef USE_RES 119 | ifeq ($(BITS),32) 120 | RCFLAGS += $(RC_TAR32) -o 121 | else 122 | RCFLAGS += $(RC_TAR64) -o 123 | endif 124 | endif # USE_GCC 125 | 126 | OBJECTS += $(DEP)/resource.o 127 | OBJS = $(OBJECTS) 128 | 129 | ifeq ($(findstring clang,$(CC)), clang) 130 | LDFLAGS += -static -Wno-unused-command-line-argument -v 131 | else ifeq ($(USE_GCC),1) 132 | LDLIBS += $(MSCRT) 133 | LDFLAGS += -static-libgcc -Wl,--out-implib,$(DISTDIR)/libportable$(BITS).dll.a 134 | ifeq ($(LTO), 1) 135 | AR := $(filter-out ar,$(AR )) gcc-ar 136 | CFLAGS := $(filter-out -O2,$(CFLAGS)) -D__LTO__ -Os -flto 137 | #warning is only during the LTO link, debug(--verbose --save-temps ) 138 | DLLFLAGS := $(filter-out -fPIC,$(DLLFLAGS)) -flto 139 | endif 140 | else 141 | $(error "unknown compiler") 142 | endif 143 | endif # LIBPORTABLE_STATIC end 144 | 145 | all : $(OUT1) $(OUT) 146 | $(OUT1) : $(SUB_DIR)/Makefile 147 | $(call SUBMK) 148 | $(OUT) : $(OBJECTS) $(OUT1) 149 | ifeq ($(LIBPORTABLE_STATIC),1) 150 | $(LD) $@ $(OBJS) 151 | else 152 | $(LD) $@ $(OBJS) $(DFLAGS) $(DLLFLAGS) $(LDFLAGS) $(LDLIBS) 153 | endif 154 | -$(CP) $(OUT) $(TETE) 2>/dev/null 155 | $(DEP)/portable.o : $(SRC)/portable.c $(SRC)/portable.h $(SRC)/general.h 156 | $(call EXEC) 157 | $(CC) -c $< $(CFLAGS) -o $@ 158 | $(DEP)/ini_parser.o : $(SRC)/ini_parser.c $(SRC)/ini_parser.h 159 | $(CC) -c $< $(CFLAGS) -o $@ 160 | $(DEP)/general.o : $(SRC)/general.c $(SRC)/general.h 161 | $(CC) -c $< $(CFLAGS) -o $@ 162 | $(DEP)/inject.o : $(SRC)/inject.c $(SRC)/inject.h $(SRC)/winapis.h 163 | $(CC) -c $< $(CFLAGS) -o $@ 164 | $(DEP)/safe_ex.o : $(SRC)/safe_ex.c $(SRC)/safe_ex.h $(SRC)/winapis.h 165 | $(CC) -c $< $(CFLAGS) -o $@ 166 | $(DEP)/ice_error.o : $(SRC)/ice_error.c $(SRC)/ice_error.h 167 | $(CC) -c $< $(CFLAGS) -o $@ 168 | $(DEP)/bosskey.o : $(SRC)/bosskey.c $(SRC)/bosskey.h 169 | $(CC) -c $< $(CFLAGS) -o $@ 170 | $(DEP)/new_process.o : $(SRC)/new_process.c $(SRC)/new_process.h 171 | $(CC) -c $< $(CFLAGS) -o $@ 172 | $(DEP)/cpu_info.o : $(SRC)/cpu_info.c $(SRC)/cpu_info.h 173 | $(CC) -c $< $(CFLAGS) -o $@ 174 | $(DEP)/balance.o : $(SRC)/balance.c $(SRC)/balance.h 175 | $(CC) -c $< $(CFLAGS) -o $@ 176 | $(DEP)/win_registry.o : $(SRC)/win_registry.c $(SRC)/win_registry.h 177 | $(CC) -c $< $(CFLAGS) -o $@ 178 | $(DEP)/set_env.o : $(SRC)/set_env.c $(SRC)/set_env.h 179 | $(CC) -c $< $(CFLAGS) -o $@ 180 | $(DEP)/on_tabs.o : $(SRC)/on_tabs.c $(SRC)/on_tabs.h $(SRC)/win_automation.h 181 | $(CC) -c $< $(CFLAGS) -o $@ 182 | $(DEP)/json_paser.o : $(SRC)/json_paser.c $(SRC)/json_paser.h 183 | $(CC) -c $< $(CFLAGS) -o $@ 184 | $(DEP)/lz4.o : $(SRC)/lz4.c $(SRC)/lz4.h 185 | $(CC) -c $< $(CFLAGS) -o $@ 186 | $(DEP)/cjson.o : $(SRC)/cjson.c $(SRC)/cjson.h 187 | $(CC) -c $< $(CFLAGS) -o $@ 188 | ifeq ($(LIBPORTABLE_STATIC),) 189 | $(DEP)/resource.o : $(SRC)/resource.rc 190 | $(RC) $< $(RCFLAGS) $@ 191 | endif 192 | 193 | .PHONY : clean 194 | clean : 195 | -rm -rf $(DISTDIR) $(DEP) *.pdb 196 | 197 | -------------------------------------------------------------------------------- /Makefile.msvc: -------------------------------------------------------------------------------- 1 | # nmake -f Makefile.msvc 2 | 3 | CC = cl 4 | CXX = cl 5 | MSVC_CRT = 6 | MY_DEBUG = 7 | MSVC_CRT = 8 | CFLAGS = /nologo /W3 /WX- /wd4996 /wd4819 /Gd /fp:precise /D "_UNICODE" /D "UNICODE" \ 9 | /D "_CRT_SECURE_NO_WARNINGS" /D "CJSON_HIDE_SYMBOLS" 10 | LDFLAGS = /NOLOGO 11 | 12 | !if "$(CC)"=="clang-cl" 13 | LD = lld-link.exe /DLL 14 | RC = llvm-rc.exe 15 | GEN_LIB = llvm-dlltool.exe 16 | !ELSEIF "$(CC)"=="cl" 17 | LD = link.exe /DLL 18 | RC = rc.exe 19 | GEN_LIB = lib.exe 20 | !else 21 | !ERROR Unsupported platforms! 22 | !endif 23 | 24 | MAKE = nmake 25 | LIBPORTABLE_STATIC = 26 | 27 | !if "$(APP_DEBUG)"=="1" 28 | CFLAGS = $(CFLAGS) /O2 /Zi /Fd$(DISTDIR)\portable$(BITS).pdb /D "DEBUG" /D "_LOGDEBUG" 29 | LDFLAGS = $(LDFLAGS) /DEBUG 30 | !elseif "$(CC)"=="cl" 31 | CFLAGS = $(CFLAGS) /O2 /GL /Gd /D "NDEBUG" 32 | LDFLAGS = $(LDFLAGS) /LTCG 33 | !else 34 | CFLAGS = $(CFLAGS) /O2 /D "NDEBUG" -flto=thin 35 | !endif 36 | 37 | !if "$(MSVC_CRT)"=="1" 38 | CFLAGS = $(CFLAGS) /MD /GS- /GR- /utf-8 /D "USE_UTF8" 39 | !else 40 | CFLAGS = $(CFLAGS) /MD /GS- /GR- /utf-8 /D "USE_UTF8" /D "VC12_CRT" 41 | !endif 42 | 43 | !if "$(PLATFORM)"=="X64" || "$(TARGET_CPU)"=="x64" || "$(VSCMD_ARG_HOST_ARCH)"=="x64" 44 | PLATFORM = x64 45 | BITS = 64 46 | CFLAGS = $(CFLAGS) /D "WIN64" /D "_WIN64" 47 | GEN_FLAGS = -m i386:x86-64 48 | !else 49 | PLATFORM = x86 50 | BITS = 32 51 | CFLAGS = $(CFLAGS) /D "WIN32" /D "_WIN32" 52 | GEN_FLAGS = -m i386 53 | !if "$(CC)"=="clang-cl" 54 | CFLAGS = $(CFLAGS) --target=i686-pc-windows-msvc 55 | !endif 56 | !endif 57 | 58 | !if "$(CC)"=="clang-cl" 59 | CFLAGS = $(CFLAGS) -Wno-unused-function 60 | !endif 61 | 62 | MD = @mkdir 63 | CP = copy /y 64 | RM = @del /q 65 | RMDIR = @rmdir /s /q 66 | SRC = src 67 | SUB_DIR = $(SRC)\minhook 68 | SUBMK =\ 69 | @cd $(SUB_DIR) && $(MAKE) -f Makefile.msvc 70 | 71 | DEP = .dep 72 | RCFLAGS = /nologo /D "_UNICODE" /D "UNICODE" 73 | MIN_INC = $(SRC)\minhook\include 74 | 75 | OBJDLL = $(DEP)\portable.obj $(DEP)\general.obj $(DEP)\ice_error.obj $(DEP)\bosskey.obj \ 76 | $(DEP)\new_process.obj $(DEP)\cpu_info.obj $(DEP)\balance.obj \ 77 | $(DEP)\win_registry.obj $(DEP)\set_env.obj $(DEP)\on_tabs.obj \ 78 | $(DEP)\lz4.obj $(DEP)\cjson.obj $(DEP)\json_paser.obj $(DEP)\ini_parser.obj 79 | 80 | !if "$(DISABLE_SAFE)"!="1" 81 | OBJDLL = $(DEP)\safe_ex.obj $(DEP)\inject.obj $(OBJDLL) 82 | !else 83 | CFLAGS = $(CFLAGS) /D "DISABLE_SAFE" 84 | !endif 85 | 86 | CFLAGS = $(CFLAGS) /I$(MIN_INC) 87 | 88 | !if "$(LIBPORTABLE_STATIC)"=="1" 89 | LD = llvm-lib.exe 90 | OUT = $(DISTDIR)\portable$(BITS)_s.lib 91 | TETE = $(DISTDIR)\tmemutil_s.lib 92 | CFLAGS = $(CFLAGS) /D "LIBPORTABLE_STATIC" 93 | CRTFLAGS = 94 | OBJS = $(DEP)\*.obj 95 | !else 96 | CFLAGS = $(CFLAGS) /D "LIBPORTABLE_EXPORTS" 97 | !if "$(MSVC_CRT)">="1" 98 | OBJDLL = $(OBJDLL) $(DEP)\msvcrt-light-$(PLATFORM).lib $(DEP)\ntdll-$(PLATFORM).lib 99 | LDFLAGS = $(LDFLAGS) /opt:ref /opt:icf /MACHINE:$(PLATFORM) /NODEFAULTLIB 100 | !else 101 | LDFLAGS = $(LDFLAGS) /opt:ref /opt:icf /ignore:4078 /MACHINE:$(PLATFORM) /DEFAULTLIB:MSVCRT 102 | !endif 103 | CRTFLAGS = $(OUT1) kernel32.lib shell32.lib shlwapi.lib user32.lib ole32.lib $(CRTFLAGS) 104 | OUT = $(DISTDIR)\portable$(BITS).dll 105 | TETE = $(DISTDIR)\tmemutil.dll 106 | OBJDLL = $(OBJDLL) $(DEP)\resource.res 107 | OBJS = $(OBJDLL) 108 | !endif 109 | 110 | DISTDIR = Release 111 | OUT1 = $(DISTDIR)\minhook$(BITS).lib 112 | 113 | all : dirs $(OUT1) $(OUT) 114 | 115 | $(OUT1) : $(SUB_DIR)/Makefile.msvc 116 | $(SUBMK) 117 | 118 | $(OUT) : $(OBJDLL) 119 | $(LD) /OUT:"$@" $(OBJS) $(LDFLAGS) $(MIN_LIB) $(CRTFLAGS) 120 | -$(CP) $(OUT) $(TETE) 2>&1>NUL 121 | 122 | $(DEP)\portable.obj : $(SRC)\portable.c $(SRC)\portable.h 123 | $(CC) $(CFLAGS) /c $(SRC)\portable.c /Fo$@ 124 | $(DEP)\general.obj : $(SRC)\general.c $(SRC)\general.h 125 | $(CC) $(CFLAGS) /c $(SRC)\general.c /Fo$@ 126 | !if "$(DISABLE_SAFE)"!="1" 127 | $(DEP)\inject.obj : $(SRC)\inject.c $(SRC)\inject.h $(SRC)\winapis.h 128 | $(CC) $(CFLAGS) /c $(SRC)\inject.c /Fo$@ 129 | $(DEP)\safe_ex.obj : $(SRC)\safe_ex.c $(SRC)\safe_ex.h $(SRC)\winapis.h 130 | $(CC) $(CFLAGS) /c $(SRC)\safe_ex.c /Fo$@ 131 | !endif 132 | $(DEP)\ice_error.obj : $(SRC)\ice_error.c $(SRC)\ice_error.h 133 | $(CC) $(CFLAGS) /c $(SRC)\ice_error.c /Fo$@ 134 | $(DEP)\bosskey.obj : $(SRC)\bosskey.c $(SRC)\bosskey.h 135 | $(CC) $(CFLAGS) /c $(SRC)\bosskey.c /Fo$@ 136 | $(DEP)\new_process.obj : $(SRC)\new_process.c $(SRC)\new_process.h 137 | $(CC) $(CFLAGS) /c $(SRC)\new_process.c /Fo$@ 138 | $(DEP)\cpu_info.obj : $(SRC)\cpu_info.c $(SRC)\cpu_info.h 139 | $(CC) $(CFLAGS) /arch:AVX /c $(SRC)\cpu_info.c /Fo$@ 140 | $(DEP)\balance.obj : $(SRC)\balance.c $(SRC)\balance.h 141 | $(CC) $(CFLAGS) /c $(SRC)\balance.c /Fo$@ 142 | $(DEP)\win_registry.obj : $(SRC)\win_registry.c $(SRC)\win_registry.h 143 | $(CC) $(CFLAGS) /c $(SRC)\win_registry.c /Fo$@ 144 | $(DEP)\set_env.obj : $(SRC)\set_env.c $(SRC)\set_env.h 145 | $(CC) $(CFLAGS) /c $(SRC)\set_env.c /Fo$@ 146 | $(DEP)\on_tabs.obj : $(SRC)\on_tabs.c $(SRC)\on_tabs.h 147 | $(CC) $(CFLAGS) /c $(SRC)\on_tabs.c /Fo$@ 148 | $(DEP)\lz4.obj : $(SRC)\lz4.c $(SRC)\lz4.h 149 | $(CC) $(CFLAGS) /c $(SRC)\lz4.c /Fo$@ 150 | $(DEP)\cjson.obj : $(SRC)\cjson.c $(SRC)\cjson.h 151 | $(CC) $(CFLAGS) /c $(SRC)\cjson.c /Fo$@ 152 | $(DEP)\json_paser.obj : $(SRC)\json_paser.c $(SRC)\json_paser.h 153 | $(CC) $(CFLAGS) /c $(SRC)\json_paser.c /Fo$@ 154 | $(DEP)\ini_parser.obj : $(SRC)\ini_parser.c $(SRC)\ini_parser.h 155 | $(CC) $(CFLAGS) /c $(SRC)\ini_parser.c /Fo$@ 156 | 157 | !if "$(VC12_CRT)"=="" && "$(MSVC_CRT)"=="1" 158 | $(DEP)\msvcrt-light-$(PLATFORM).lib : msrt\msvcrt-light-$(PLATFORM).def 159 | !if "$(CC)"=="clang-cl" 160 | $(GEN_LIB) -D msvcrt.dll -d msrt\msvcrt-light-$(PLATFORM).def -l $(DEP)\msvcrt-light-$(PLATFORM).lib $(GEN_FLAGS) 161 | !else 162 | $(GEN_LIB) /DEF:msrt\msvcrt-light-$(PLATFORM).def /OUT:$(DEP)\msvcrt-light-$(PLATFORM).lib \ 163 | /NOLOGO /NODEFAULTLIB /IGNORE:4102 /MACHINE:$(PLATFORM) /NAME:msvcrt.dll 164 | !endif 165 | $(DEP)\ntdll-$(PLATFORM).lib : msrt\ntdll-$(PLATFORM).def 166 | !if "$(CC)"=="clang-cl" 167 | $(GEN_LIB) -D ntdll.dll -d msrt\ntdll-$(PLATFORM).def -l $(DEP)\ntdll-$(PLATFORM).lib $(GEN_FLAGS) 168 | !else 169 | $(GEN_LIB) /DEF:msrt\ntdll-$(PLATFORM).def /OUT:$(DEP)\ntdll-$(PLATFORM).lib /NOLOGO \ 170 | /NODEFAULTLIB /IGNORE:4102 /MACHINE:$(PLATFORM) /NAME:ntdll.dll 171 | !endif 172 | !endif 173 | 174 | .PHONY : dirs 175 | dirs: 176 | @if not exist "$(DISTDIR)" mkdir "$(DISTDIR)" && echo. Created $(DISTDIR) 177 | @if not exist "$(DEP)" mkdir "$(DEP)" && echo. Created $(DEP) 178 | 179 | .PHONY : install 180 | install : all 181 | @if not defined LIBPORTABLE_PATH @echo please defined LIBPORTABLE_PATH environment variable&exit 1 182 | @if not exist "%LIBPORTABLE_PATH%" mkdir "%LIBPORTABLE_PATH%" 183 | @if not exist "%LIBPORTABLE_PATH%\bin" mkdir "%LIBPORTABLE_PATH%\bin" 184 | @if not exist "%LIBPORTABLE_PATH%\lib" mkdir "%LIBPORTABLE_PATH%\lib" 185 | @if not exist "%LIBPORTABLE_PATH%\include" mkdir "%LIBPORTABLE_PATH%\include" 186 | -$(CP) $(SRC)\portable.h "%LIBPORTABLE_PATH%\include" 187 | -$(CP) $(DISTDIR)\portable$(BITS).lib "%LIBPORTABLE_PATH%\lib" 188 | -$(CP) $(OUT) "%LIBPORTABLE_PATH%\bin" 189 | -$(CP) $(SRC)\portable(example).ini "%LIBPORTABLE_PATH%\bin" 190 | 191 | $(DEP)\resource.res : $(SRC)\resource.rc 192 | $(RC) $(RCFLAGS) /fo$@ $(SRC)\resource.rc 193 | 194 | .PHONY : clean 195 | clean : 196 | -$(RMDIR) $(DISTDIR) $(DEP) 2>NUL 1>NUL 197 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## How to build libportable source code? 2 | 3 | - C compiler 4 | Microsoft Visual Studio . 5 | 6 | - or 7 | 8 | - gcc, msys/msys2 9 | gcc for windows: 10 | https://sourceforge.net/projects/libportable/files/Tools/ 11 | msys msys2 project on: 12 | https://sourceforge.net/projects/mingw/files/MSYS 13 | https://sourceforge.net/projects/msys2/ 14 | 15 | ## Build! 16 | - vc14 or above (cmd shell) 17 | 18 | nmake -f Makefile.msvc clean 19 | nmake -f Makefile.msvc 20 | 21 | link against minimal msvcrt.dll: 22 | nmake -f Makefile.msvc MSVC_CRT=1 23 | 24 | - gcc/mingw64 compiler (msys shell) 25 | 26 | make clean 27 | make 28 | 29 | enable GCC Link-time optimization(LTO): 30 | make LTO=1 31 | 32 | If gcc is a cross-compiler, use the CROSS_COMPILING option: 33 | 34 | make clean 35 | 64bits: 36 | make CROSS_COMPILING=x86_64-w64-mingw32- 37 | 32bits: 38 | make CROSS_COMPILING=x86_64-w64-mingw32- BITS=32 39 | 40 | - clang compiler,If you have MSVC compiler installed 41 | **(cmd shell):** 42 | 43 | nmake -f Makefile.msvc CC=clang-cl clean 44 | nmake -f Makefile.msvc CC=clang-cl 45 | 46 | **(msys shell):** 47 | 48 | make clean 49 | make CC=clang DFLAGS=--target=x86_64-w64-windows-gnu // (64bits target build) 50 | make CC=clang DFLAGS=--target=i686-w64-windows-gnu // (32bits target build) 51 | 52 | make clean 53 | make CC=clang DFLAGS=--target=i686-pc-windows-msvc 54 | make CC=clang DFLAGS=--target=x86_64-pc-windows-msvc 55 | 56 | 57 | ## Add libportable into Firefox? 58 | **Binary static injection,example:** 59 | 60 | setdll32 /d:portable32.dll mozglue.dll // 32 bits firefox 61 | setdll64 /d:portable64.dll mozglue.dll // 64 bits firefox 62 | 63 | **Compiled from firefox's source code,patches example:** 64 | ``` 65 | diff --git a/toolkit/library/nsDllMain.cpp b/toolkit/library/nsDllMain.cpp 66 | --- a/toolkit/library/nsDllMain.cpp 67 | +++ b/toolkit/library/nsDllMain.cpp 68 | @@ -8,6 +8,16 @@ 69 | #include "mozilla/Assertions.h" 70 | #include "mozilla/WindowsVersion.h" 71 | 72 | +#if defined(_MSC_VER) && defined(TT_MEMUTIL) 73 | +#if defined(_M_IX86) 74 | +#pragma comment(lib,"portable32.lib") 75 | +#pragma comment(linker, "/include:_GetCpuFeature_tt") 76 | +#elif defined(_M_AMD64) || defined(_M_X64) 77 | +#pragma comment(lib,"portable64.lib") 78 | +#pragma comment(linker, "/include:GetCpuFeature_tt") 79 | +#endif 80 | +#endif /* _MSC_VER && TT_MEMUTIL */ 81 | + 82 | #if defined(__GNUC__) 83 | // If DllMain gets name mangled, it won't be seen. 84 | extern "C" { 85 | ``` -------------------------------------------------------------------------------- /msrt/msvcrt-light-x64.def: -------------------------------------------------------------------------------- 1 | ;This list is taken from Windows XP x64 MSVCRT.DLL 6.1.7601.17651 2 | EXPORTS 3 | $I10_OUTPUT=?Y@@YAXXZ 4 | ??0__non_rtti_object@@QEAA@AEBV0@@Z=?Y@@YAXXZ 5 | ??0__non_rtti_object@@QEAA@PEBD@Z=?Y@@YAXXZ 6 | ??0bad_cast@@AEAA@PEBQEBD@Z=?Y@@YAXXZ 7 | ??0bad_cast@@QEAA@AEBQEBD@Z=?Y@@YAXXZ 8 | ??0bad_cast@@QEAA@AEBV0@@Z=?Y@@YAXXZ 9 | ??0bad_cast@@QEAA@PEBD@Z=?Y@@YAXXZ 10 | ??0bad_typeid@@QEAA@AEBV0@@Z=?Y@@YAXXZ 11 | ??0bad_typeid@@QEAA@PEBD@Z=?Y@@YAXXZ 12 | ??0exception@@QEAA@AEBQEBD@Z=?Y@@YAXXZ 13 | ??0exception@@QEAA@AEBQEBDH@Z=?Y@@YAXXZ 14 | ??0exception@@QEAA@AEBV0@@Z=?Y@@YAXXZ 15 | ??0exception@@QEAA@XZ=?Y@@YAXXZ 16 | ??1__non_rtti_object@@UEAA@XZ=?Y@@YAXXZ 17 | ??1bad_cast@@UEAA@XZ=?Y@@YAXXZ 18 | ??1bad_typeid@@UEAA@XZ=?Y@@YAXXZ 19 | ??1exception@@UEAA@XZ=?Y@@YAXXZ 20 | ??1type_info@@UEAA@XZ=?Y@@YAXXZ 21 | ??2@YAPEAX_K@Z=?Y@@YAXXZ 22 | ??3@YAXPEAX@Z=?Y@@YAXXZ 23 | ??4__non_rtti_object@@QEAAAEAV0@AEBV0@@Z=?Y@@YAXXZ 24 | ??4bad_cast@@QEAAAEAV0@AEBV0@@Z=?Y@@YAXXZ 25 | ??4bad_typeid@@QEAAAEAV0@AEBV0@@Z=?Y@@YAXXZ 26 | ??4exception@@QEAAAEAV0@AEBV0@@Z=?Y@@YAXXZ 27 | ??8type_info@@QEBAHAEBV0@@Z=?Y@@YAXXZ 28 | ??9type_info@@QEBAHAEBV0@@Z=?Y@@YAXXZ 29 | ??_7__non_rtti_object@@6B@=?Y@@YAXXZ 30 | ??_7bad_cast@@6B@=?Y@@YAXXZ 31 | ??_7bad_typeid@@6B@=?Y@@YAXXZ 32 | ??_7exception@@6B@=?Y@@YAXXZ 33 | ??_Fbad_cast@@QEAAXXZ=?Y@@YAXXZ 34 | ??_Fbad_typeid@@QEAAXXZ=?Y@@YAXXZ 35 | ??_U@YAPEAX_K@Z=?Y@@YAXXZ 36 | ??_V@YAXPEAX@Z=?Y@@YAXXZ 37 | ?_query_new_handler@@YAP6AH_K@ZXZ=?Y@@YAXXZ 38 | ?_query_new_mode@@YAHXZ=?Y@@YAXXZ 39 | ?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z=?Y@@YAXXZ 40 | ?_set_new_mode@@YAHH@Z=?Y@@YAXXZ 41 | ?_set_se_translator@@YAP6AXIPEAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z=?Y@@YAXXZ 42 | ?before@type_info@@QEBAHAEBV1@@Z=?Y@@YAXXZ 43 | ?name@type_info@@QEBAPEBDXZ=?Y@@YAXXZ 44 | ?raw_name@type_info@@QEBAPEBDXZ=?Y@@YAXXZ 45 | ?set_new_handler@@YAP6AXXZP6AXXZ@Z=?Y@@YAXXZ 46 | ?set_terminate@@YAP6AXXZP6AXXZ@Z=?Y@@YAXXZ 47 | ?set_unexpected@@YAP6AXXZP6AXXZ@Z=?Y@@YAXXZ 48 | ?terminate@@YAXXZ=?Y@@YAXXZ 49 | ?unexpected@@YAXXZ=?Y@@YAXXZ 50 | ?what@exception@@UEBAPEBDXZ=?Y@@YAXXZ 51 | abort=X 52 | abs=X 53 | _abs64=X 54 | _access=X 55 | _acmdln=X 56 | acos=X 57 | acosf=X 58 | _aexit_rtn=X 59 | _aligned_free=X 60 | _aligned_malloc=X 61 | _aligned_offset_malloc=X 62 | _aligned_offset_realloc=X 63 | _aligned_realloc=X 64 | _amsg_exit=X 65 | __argc=Z DATA 66 | __argv=Z DATA 67 | asctime=X 68 | asin=X 69 | asinf=X 70 | _assert=X 71 | atan=X 72 | atan2=X 73 | atan2f=X 74 | atanf=X 75 | atexit=X 76 | _atodbl=X 77 | atof=X 78 | atoi=X 79 | _atoi64=X 80 | atol=X 81 | _atoldbl=X 82 | __badioinfo=X 83 | _beep=X 84 | _beginthread=X 85 | _beginthreadex=X 86 | bsearch=X 87 | _c_exit=X 88 | __C_specific_handler=X 89 | _cabs=X 90 | _callnewh=X 91 | calloc=X 92 | ceil=X 93 | ceilf=X 94 | _cexit=X 95 | _cgets=X 96 | _cgetws=X 97 | _chdir=X 98 | _chdrive=X 99 | _chgsign=X 100 | _chgsignf=X 101 | _chmod=X 102 | _chsize=X 103 | clearerr=X 104 | _clearfp=X 105 | clock=X 106 | _close=X 107 | _commit=X 108 | _commode=X 109 | _control87=X 110 | _controlfp=X 111 | _copysign=X 112 | _copysignf=X 113 | cos=X 114 | cosf=X 115 | cosh=X 116 | coshf=X 117 | __CppXcptFilter=X 118 | _cprintf=X 119 | _cputs=X 120 | _cputws=X 121 | _creat=X 122 | __crtCompareStringA=X 123 | __crtCompareStringW=X 124 | __crtGetLocaleInfoW=X 125 | __crtGetStringTypeW=X 126 | __crtLCMapStringA=X 127 | __crtLCMapStringW=X 128 | _cscanf=X 129 | ctime=X 130 | _ctime64=X 131 | _ctype=X 132 | _cwait=X 133 | _cwprintf=X 134 | _cwscanf=X 135 | __CxxFrameHandler=X 136 | _CxxThrowException=X 137 | _daylight=X 138 | __DestructExceptionObject=X 139 | difftime=X 140 | div=X 141 | __dllonexit=X 142 | __doserrno=Z DATA 143 | _dstbias=Z DATA 144 | _dup=X 145 | _dup2=X 146 | _ecvt=X 147 | _endthread=X 148 | _endthreadex=X 149 | _environ=Z DATA 150 | _eof=X 151 | _errno=Z DATA 152 | _execl=X 153 | _execle=X 154 | _execlp=X 155 | _execlpe=X 156 | _execv=X 157 | _execve=X 158 | _execvp=X 159 | _execvpe=X 160 | _exit=X 161 | exit=X 162 | exp=X 163 | _expand=X 164 | expf=X 165 | fabs=X 166 | fclose=X 167 | _fcloseall=X 168 | _fcvt=X 169 | _fdopen=X 170 | feof=X 171 | ferror=X 172 | fflush=X 173 | fgetc=X 174 | _fgetchar=X 175 | fgetpos=X 176 | fgets=X 177 | fgetwc=X 178 | _fgetwchar=X 179 | fgetws=X 180 | _filbuf=X 181 | _fileinfo=X 182 | _filelength=X 183 | _filelengthi64=X 184 | _fileno=X 185 | _findclose=X 186 | _findfirst=X 187 | _findfirst64=X 188 | _findfirsti64=X 189 | _findnext=X 190 | _findnext64=X 191 | _findnexti64=X 192 | _finite=X 193 | _finitef=X 194 | floor=X 195 | floorf=X 196 | _flsbuf=X 197 | _flushall=X 198 | fmod=X 199 | _fmode=X 200 | fmodf=X 201 | fopen=X 202 | _fpclass=X 203 | _fpclassf=X 204 | __fpecode=Z DATA 205 | _fpreset=X 206 | fprintf=X 207 | fputc=X 208 | _fputchar=X 209 | fputs=X 210 | fputwc=X 211 | _fputwchar=X 212 | fputws=X 213 | fread=X 214 | free=X 215 | freopen=X 216 | frexp=X 217 | fscanf=X 218 | fseek=X 219 | fsetpos=X 220 | _fsopen=X 221 | _fstat=X 222 | _fstat64=X 223 | _fstati64=X 224 | ftell=X 225 | _ftime=X 226 | _ftime64=X 227 | _fullpath=X 228 | _futime=X 229 | _futime64=X 230 | fwprintf=X 231 | fwrite=X 232 | fwscanf=X 233 | _gcvt=X 234 | _get_heap_handle=X 235 | _get_osfhandle=X 236 | _get_sbh_threshold=X 237 | getc=X 238 | _getch=X 239 | getchar=X 240 | _getche=X 241 | _getcwd=X 242 | _Getdays=X 243 | _getdcwd=X 244 | _getdiskfree=X 245 | _getdllprocaddr=X 246 | _getdrive=X 247 | _getdrives=X 248 | getenv=X 249 | __getmainargs=X 250 | _getmaxstdio=X 251 | _getmbcp=X 252 | _Getmonths=X 253 | _getpid=X 254 | gets=X 255 | _getsystime=X 256 | _Gettnames=X 257 | _getw=X 258 | getwc=X 259 | _getwch=X 260 | getwchar=X 261 | _getwche=X 262 | _getws=X 263 | gmtime=X 264 | _gmtime64=X 265 | _heapadd=X 266 | _heapchk=X 267 | _heapmin=X 268 | _heapset=X 269 | _heapused=X 270 | _heapwalk=X 271 | _HUGE=X 272 | _hypot=X 273 | _hypotf=X 274 | _i64toa=X 275 | _i64tow=X 276 | __initenv=X 277 | _initterm=X 278 | _iob=X 279 | __iob_func=X 280 | is_wctype=X 281 | isalnum=X 282 | isalpha=X 283 | __isascii=X 284 | _isatty=X 285 | iscntrl=X 286 | __iscsym=X 287 | __iscsymf=X 288 | _isctype=X 289 | isdigit=X 290 | isgraph=X 291 | isleadbyte=X 292 | islower=X 293 | _ismbbalnum=X 294 | _ismbbalpha=X 295 | _ismbbgraph=X 296 | _ismbbkalnum=X 297 | _ismbbkana=X 298 | _ismbbkprint=X 299 | _ismbbkpunct=X 300 | _ismbblead=X 301 | _ismbbprint=X 302 | _ismbbpunct=X 303 | _ismbbtrail=X 304 | _ismbcalnum=X 305 | _ismbcalpha=X 306 | _ismbcdigit=X 307 | _ismbcgraph=X 308 | _ismbchira=X 309 | _ismbckata=X 310 | _ismbcl0=X 311 | _ismbcl1=X 312 | _ismbcl2=X 313 | _ismbclegal=X 314 | _ismbclower=X 315 | _ismbcprint=X 316 | _ismbcpunct=X 317 | _ismbcspace=X 318 | _ismbcsymbol=X 319 | _ismbcupper=X 320 | _ismbslead=X 321 | _ismbstrail=X 322 | _isnan=X 323 | _isnanf=X 324 | isprint=X 325 | ispunct=X 326 | isspace=X 327 | isupper=X 328 | iswalnum=X 329 | iswalpha=X 330 | iswascii=X 331 | iswcntrl=X 332 | iswctype=X 333 | iswdigit=X 334 | iswgraph=X 335 | iswlower=X 336 | iswprint=X 337 | iswpunct=X 338 | iswspace=X 339 | iswupper=X 340 | iswxdigit=X 341 | isxdigit=X 342 | _itoa=X 343 | _itow=X 344 | _j0=X 345 | _j1=X 346 | _jn=X 347 | _kbhit=X 348 | labs=X 349 | __lc_codepage=X 350 | ___lc_codepage_func=X 351 | __lc_collate_cp=X 352 | ___lc_collate_cp_func=X 353 | __lc_handle=X 354 | ___lc_handle_func=X 355 | __lconv_init=X 356 | ldexp=X 357 | ldiv=X 358 | _lfind=X 359 | _loaddll=X 360 | _local_unwind=X 361 | localeconv=X 362 | localtime=X 363 | _localtime64=X 364 | _lock=X 365 | _locking=X 366 | log=X 367 | log10=X 368 | log10f=X 369 | _logb=X 370 | _logbf=X 371 | logf=X 372 | longjmp=X 373 | _lrotl=X 374 | _lrotr=X 375 | _lsearch=X 376 | _lseek=X 377 | _lseeki64=X 378 | _ltoa=X 379 | _ltow=X 380 | _makepath=X 381 | malloc=X 382 | __mb_cur_max=X 383 | ___mb_cur_max_func=X 384 | _mbbtombc=X 385 | _mbbtype=X 386 | _mbcasemap=X 387 | _mbccpy=X 388 | _mbcjistojms=X 389 | _mbcjmstojis=X 390 | _mbclen=X 391 | _mbctohira=X 392 | _mbctokata=X 393 | _mbctolower=X 394 | _mbctombb=X 395 | _mbctoupper=X 396 | _mbctype=X 397 | mblen=X 398 | _mbsbtype=X 399 | _mbscat=X 400 | _mbschr=X 401 | _mbscmp=X 402 | _mbscoll=X 403 | _mbscpy=X 404 | _mbscspn=X 405 | _mbsdec=X 406 | _mbsdup=X 407 | _mbsicmp=X 408 | _mbsicoll=X 409 | _mbsinc=X 410 | _mbslen=X 411 | _mbslwr=X 412 | _mbsnbcat=X 413 | _mbsnbcmp=X 414 | _mbsnbcnt=X 415 | _mbsnbcoll=X 416 | _mbsnbcpy=X 417 | _mbsnbicmp=X 418 | _mbsnbicoll=X 419 | _mbsnbset=X 420 | _mbsncat=X 421 | _mbsnccnt=X 422 | _mbsncmp=X 423 | _mbsncoll=X 424 | _mbsncpy=X 425 | _mbsnextc=X 426 | _mbsnicmp=X 427 | _mbsnicoll=X 428 | _mbsninc=X 429 | _mbsnset=X 430 | _mbspbrk=X 431 | _mbsrchr=X 432 | _mbsrev=X 433 | _mbsset=X 434 | _mbsspn=X 435 | _mbsspnp=X 436 | _mbsstr=X 437 | _mbstok=X 438 | mbstowcs=X 439 | _mbstrlen=X 440 | _mbsupr=X 441 | mbtowc=X 442 | _memccpy=X 443 | memchr=X 444 | memcmp=X 445 | memcpy=X 446 | _memicmp=X 447 | memmove=X 448 | memset=X 449 | _mkdir=X 450 | _mkgmtime=X 451 | _mkgmtime64=X 452 | _mktemp=X 453 | mktime=X 454 | _mktime64=X 455 | modf=X 456 | modff=X 457 | _msize=X 458 | _nextafter=X 459 | _nextafterf=X 460 | _onexit=X 461 | _open=X 462 | _open_osfhandle=X 463 | _osplatform=Z DATA 464 | _osver=Z DATA 465 | _pclose=X 466 | _pctype=X 467 | __pctype_func=X 468 | perror=X 469 | _pgmptr=X 470 | __pioinfo=X 471 | _pipe=X 472 | _popen=X 473 | pow=X 474 | powf=X 475 | printf=X 476 | _purecall=X 477 | putc=X 478 | _putch=X 479 | putchar=X 480 | _putenv=X 481 | puts=X 482 | _putw=X 483 | putwc=X 484 | _putwch=X 485 | putwchar=X 486 | _putws=X 487 | _pwctype=X 488 | __pwctype_func=X 489 | __pxcptinfoptrs=X 490 | qsort=X 491 | raise=X 492 | rand=X 493 | _read=X 494 | realloc=X 495 | remove=X 496 | rename=X 497 | _resetstkoflw=X 498 | rewind=X 499 | _rmdir=X 500 | _rmtmp=X 501 | _rotl=X 502 | _rotl64=X 503 | _rotr=X 504 | _rotr64=X 505 | __RTCastToVoid=X 506 | __RTDynamicCast=X 507 | __RTtypeid=X 508 | _scalb=X 509 | _scalbf=X 510 | scanf=X 511 | _scprintf=X 512 | _scwprintf=X 513 | _searchenv=X 514 | __set_app_type=X 515 | _set_error_mode=X 516 | _set_sbh_threshold=X 517 | setbuf=X 518 | _seterrormode=X 519 | _setjmp=X 520 | setjmp=X 521 | _setjmpex=X 522 | __setlc_active=X 523 | ___setlc_active_func=X 524 | setlocale=X 525 | _setmaxstdio=X 526 | _setmbcp=X 527 | _setmode=X 528 | _setsystime=X 529 | __setusermatherr=X 530 | setvbuf=X 531 | signal=X 532 | sin=X 533 | sinf=X 534 | sinh=X 535 | sinhf=X 536 | _sleep=X 537 | _snprintf=X 538 | _snscanf=X 539 | _snwprintf=X 540 | _snwscanf=X 541 | _sopen=X 542 | _spawnl=X 543 | _spawnle=X 544 | _spawnlp=X 545 | _spawnlpe=X 546 | _spawnv=X 547 | _spawnve=X 548 | _spawnvp=X 549 | _spawnvpe=X 550 | _splitpath=X 551 | sprintf=X 552 | sqrt=X 553 | sqrtf=X 554 | srand=X 555 | sscanf=X 556 | _stat=X 557 | _stat64=X 558 | _stati64=X 559 | _statusfp=X 560 | strcat=X 561 | strchr=X 562 | strcmp=X 563 | _strcmpi=X 564 | strcoll=X 565 | strcpy=X 566 | strcspn=X 567 | _strdate=X 568 | _strdup=X 569 | _strerror=X 570 | strerror=X 571 | _Strftime=X 572 | strftime=X 573 | _stricmp=X 574 | _stricoll=X 575 | __STRINGTOLD=X 576 | strlen=X 577 | _strlwr=X 578 | strncat=X 579 | strncmp=X 580 | _strncoll=X 581 | strncpy=X 582 | _strnicmp=X 583 | _strnicoll=X 584 | _strnset=X 585 | strpbrk=X 586 | strrchr=X 587 | _strrev=X 588 | _strset=X 589 | strspn=X 590 | strstr=X 591 | _strtime=X 592 | strtod=X 593 | _strtoi64=X 594 | strtok=X 595 | strtol=X 596 | _strtoui64=X 597 | strtoul=X 598 | _strupr=X 599 | strxfrm=X 600 | _swab=X 601 | swprintf=X 602 | swscanf=X 603 | _sys_errlist=X 604 | _sys_nerr=X 605 | system=X 606 | tan=X 607 | tanf=X 608 | tanh=X 609 | _tell=X 610 | _telli64=X 611 | _tempnam=X 612 | __threadhandle=X 613 | __threadid=X 614 | time=X 615 | _time64=X 616 | _timezone=X 617 | tmpfile=X 618 | tmpnam=X 619 | __toascii=X 620 | _tolower=X 621 | tolower=X 622 | _toupper=X 623 | toupper=X 624 | towlower=X 625 | towupper=X 626 | _tzname=X 627 | _tzset=X 628 | _ui64toa=X 629 | _ui64tow=X 630 | _ultoa=X 631 | _ultow=X 632 | _umask=X 633 | __uncaught_exception=X 634 | __unDName=X 635 | __unDNameEx=X 636 | ungetc=X 637 | _ungetch=X 638 | ungetwc=X 639 | _ungetwch=X 640 | __unguarded_readlc_active=X 641 | ___unguarded_readlc_active_add_func=X 642 | _unlink=X 643 | _unloaddll=X 644 | _unlock=X 645 | _utime=X 646 | _utime64=X 647 | vfprintf=X 648 | vfwprintf=X 649 | vprintf=X 650 | _vscprintf=X 651 | _vscwprintf=X 652 | _vsnprintf=X 653 | _vsnwprintf=X 654 | vsprintf=X 655 | vswprintf=X 656 | vwprintf=X 657 | _waccess=X 658 | __wargv=Z DATA 659 | _wasctime=X 660 | _wchdir=X 661 | _wchmod=X 662 | _wcmdln=X 663 | _wcreat=X 664 | wcscat=X 665 | wcschr=X 666 | wcscmp=X 667 | wcscoll=X 668 | wcscpy=X 669 | wcscspn=X 670 | _wcsdup=X 671 | __wcserror=X 672 | _wcserror=X 673 | wcsftime=X 674 | _wcsicmp=X 675 | _wcsicoll=X 676 | wcslen=X 677 | _wcslwr=X 678 | wcsncat=X 679 | wcsncmp=X 680 | _wcsncoll=X 681 | wcsncpy=X 682 | _wcsnicmp=X 683 | _wcsnicoll=X 684 | _wcsnset=X 685 | wcspbrk=X 686 | wcsrchr=X 687 | _wcsrev=X 688 | _wcsset=X 689 | wcsspn=X 690 | wcsstr=X 691 | wcstod=X 692 | _wcstoi64=X 693 | wcstok=X 694 | wcstol=X 695 | wcstombs=X 696 | _wcstoui64=X 697 | wcstoul=X 698 | _wcsupr=X 699 | wcsxfrm=X 700 | _wctime=X 701 | _wctime64=X 702 | wctomb=X 703 | _wctype=X 704 | _wenviron=Z DATA 705 | _wexecl=X 706 | _wexecle=X 707 | _wexeclp=X 708 | _wexeclpe=X 709 | _wexecv=X 710 | _wexecve=X 711 | _wexecvp=X 712 | _wexecvpe=X 713 | _wfdopen=X 714 | _wfindfirst=X 715 | _wfindfirst64=X 716 | _wfindfirsti64=X 717 | _wfindnext=X 718 | _wfindnext64=X 719 | _wfindnexti64=X 720 | _wfopen=X 721 | _wfreopen=X 722 | _wfsopen=X 723 | _wfullpath=X 724 | _wgetcwd=X 725 | _wgetdcwd=X 726 | _wgetenv=X 727 | __wgetmainargs=X 728 | __winitenv=X 729 | _winmajor=X 730 | _winminor=X 731 | _winver=X 732 | _wmakepath=X 733 | _wmkdir=X 734 | _wmktemp=X 735 | _wopen=X 736 | _wperror=X 737 | _wpgmptr=X 738 | _wpopen=X 739 | wprintf=X 740 | _wputenv=X 741 | _wremove=X 742 | _wrename=X 743 | _write=X 744 | _wrmdir=X 745 | wscanf=X 746 | _wsearchenv=X 747 | _wsetlocale=X 748 | _wsopen=X 749 | _wspawnl=X 750 | _wspawnle=X 751 | _wspawnlp=X 752 | _wspawnlpe=X 753 | _wspawnv=X 754 | _wspawnve=X 755 | _wspawnvp=X 756 | _wspawnvpe=X 757 | _wsplitpath=X 758 | _wstat=X 759 | _wstat64=X 760 | _wstati64=X 761 | _wstrdate=X 762 | _wstrtime=X 763 | _wsystem=X 764 | _wtempnam=X 765 | _wtmpnam=X 766 | _wtof=X 767 | _wtoi=X 768 | _wtoi64=X 769 | _wtol=X 770 | _wunlink=X 771 | _wutime=X 772 | _wutime64=X 773 | _XcptFilter=X 774 | _y0=X 775 | _y1=X 776 | _yn=X 777 | -------------------------------------------------------------------------------- /msrt/msvcrt-light-x86.def: -------------------------------------------------------------------------------- 1 | ;This list is taken from Windows xp x86 MSVCRT.DLL 6.1.9844.0 2 | EXPORTS 3 | $I10_OUTPUT=?Y@@YAXXZ 4 | ??0__non_rtti_object@@QAE@ABV0@@Z=?Y@@YAXXZ 5 | ??0__non_rtti_object@@QAE@PBD@Z=?Y@@YAXXZ 6 | ??0bad_cast@@QAE@ABQBD@Z=?Y@@YAXXZ 7 | ??0bad_cast@@QAE@ABV0@@Z=?Y@@YAXXZ 8 | ??0bad_typeid@@QAE@ABV0@@Z=?Y@@YAXXZ 9 | ??0bad_typeid@@QAE@PBD@Z=?Y@@YAXXZ 10 | ??0exception@@QAE@ABQBD@Z=?Y@@YAXXZ 11 | ??0exception@@QAE@ABV0@@Z=?Y@@YAXXZ 12 | ??0exception@@QAE@XZ=?Y@@YAXXZ 13 | ??1__non_rtti_object@@UAE@XZ=?Y@@YAXXZ 14 | ??1bad_cast@@UAE@XZ=?Y@@YAXXZ 15 | ??1bad_typeid@@UAE@XZ=?Y@@YAXXZ 16 | ??1exception@@UAE@XZ=?Y@@YAXXZ 17 | ??1type_info@@UAE@XZ=?Y@@YAXXZ 18 | ??2@YAPAXI@Z=?Y@@YAXXZ 19 | ??3@YAXPAX@Z=?Y@@YAXXZ 20 | ??4__non_rtti_object@@QAEAAV0@ABV0@@Z=?Y@@YAXXZ 21 | ??4bad_cast@@QAEAAV0@ABV0@@Z=?Y@@YAXXZ 22 | ??4bad_typeid@@QAEAAV0@ABV0@@Z=?Y@@YAXXZ 23 | ??4exception@@QAEAAV0@ABV0@@Z=?Y@@YAXXZ 24 | ??8type_info@@QBEHABV0@@Z=?Y@@YAXXZ 25 | ??9type_info@@QBEHABV0@@Z=?Y@@YAXXZ 26 | ??_7__non_rtti_object@@6B@=?Y@@YAXXZ 27 | ??_7bad_cast@@6B@=?Y@@YAXXZ 28 | ??_7bad_typeid@@6B@=?Y@@YAXXZ 29 | ??_7exception@@6B@=?Y@@YAXXZ 30 | ??_E__non_rtti_object@@UAEPAXI@Z=?Y@@YAXXZ 31 | ??_Ebad_cast@@UAEPAXI@Z=?Y@@YAXXZ 32 | ??_Ebad_typeid@@UAEPAXI@Z=?Y@@YAXXZ 33 | ??_Eexception@@UAEPAXI@Z=?Y@@YAXXZ 34 | ??_G__non_rtti_object@@UAEPAXI@Z=?Y@@YAXXZ 35 | ??_Gbad_cast@@UAEPAXI@Z=?Y@@YAXXZ 36 | ??_Gbad_typeid@@UAEPAXI@Z=?Y@@YAXXZ 37 | ??_Gexception@@UAEPAXI@Z=?Y@@YAXXZ 38 | ??_U@YAPAXI@Z=?Y@@YAXXZ 39 | ??_V@YAXPAX@Z=?Y@@YAXXZ 40 | ?_query_new_handler@@YAP6AHI@ZXZ=?Y@@YAXXZ 41 | ?_query_new_mode@@YAHXZ=?Y@@YAXXZ 42 | ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z=?Y@@YAXXZ 43 | ?_set_new_mode@@YAHH@Z=?Y@@YAXXZ 44 | ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z=?Y@@YAXXZ 45 | ?before@type_info@@QBEHABV1@@Z=?Y@@YAXXZ 46 | ?name@type_info@@QBEPBDXZ=?Y@@YAXXZ 47 | ?raw_name@type_info@@QBEPBDXZ=?Y@@YAXXZ 48 | ?set_new_handler@@YAP6AXXZP6AXXZ@Z=?Y@@YAXXZ 49 | ?set_terminate@@YAP6AXXZP6AXXZ@Z=?Y@@YAXXZ 50 | ?set_unexpected@@YAP6AXXZP6AXXZ@Z=?Y@@YAXXZ 51 | ?terminate@@YAXXZ=?Y@@YAXXZ 52 | ?unexpected@@YAXXZ=?Y@@YAXXZ 53 | ?what@exception@@UBEPBDXZ=?Y@@YAXXZ 54 | _abnormal_termination=X 55 | abort=X 56 | abs=X 57 | _access=X 58 | _acmdln=X 59 | acos=X 60 | _adj_fdiv_m16i=X 61 | _adj_fdiv_m32=X 62 | _adj_fdiv_m32i=X 63 | _adj_fdiv_m64=X 64 | _adj_fdiv_r=X 65 | _adj_fdivr_m16i=X 66 | _adj_fdivr_m32=X 67 | _adj_fdivr_m32i=X 68 | _adj_fdivr_m64=X 69 | _adj_fpatan=X 70 | _adj_fprem=X 71 | _adj_fprem1=X 72 | _adj_fptan=X 73 | _adjust_fdiv=X 74 | _aexit_rtn=X 75 | _amsg_exit=X 76 | __argc=Z DATA 77 | __argv=Z DATA 78 | asctime=X 79 | asin=X 80 | _assert=X 81 | atan=X 82 | atan2=X 83 | atexit=X 84 | _atodbl=X 85 | atof=X 86 | atoi=X 87 | _atoi64=X 88 | atol=X 89 | _atoldbl=X 90 | __badioinfo=X 91 | _beep=X 92 | _beginthread=X 93 | _beginthreadex=X 94 | bsearch=X 95 | _c_exit=X 96 | _cabs=X 97 | _callnewh=X 98 | calloc=X 99 | ceil=X 100 | _cexit=X 101 | _cgets=X 102 | _chdir=X 103 | _chdrive=X 104 | _chgsign=X 105 | _chkesp=X 106 | _chmod=X 107 | _chsize=X 108 | _CIacos=X 109 | _CIasin=X 110 | _CIatan=X 111 | _CIatan2=X 112 | _CIcos=X 113 | _CIcosh=X 114 | _CIexp=X 115 | _CIfmod=X 116 | _CIlog=X 117 | _CIlog10=X 118 | _CIpow=X 119 | _CIsin=X 120 | _CIsinh=X 121 | _CIsqrt=X 122 | _CItan=X 123 | _CItanh=X 124 | clearerr=X 125 | _clearfp=X 126 | clock=X 127 | _close=X 128 | _commit=X 129 | _commode=X 130 | _control87=X 131 | _controlfp=X 132 | _copysign=X 133 | cos=X 134 | cosh=X 135 | _cprintf=X 136 | _cputs=X 137 | _creat=X 138 | __crtCompareStringA=X 139 | __crtGetLocaleInfoW=X 140 | __crtLCMapStringA=X 141 | _cscanf=X 142 | ctime=X 143 | _ctime64=X 144 | _ctype=X 145 | _cwait=X 146 | __CxxFrameHandler=X 147 | __CxxLongjmpUnwind=X 148 | _CxxThrowException=X 149 | _daylight=X 150 | difftime=X 151 | div=X 152 | __dllonexit=X 153 | __doserrno=Z DATA 154 | _dstbias=Z DATA 155 | _dup=X 156 | _dup2=X 157 | _ecvt=X 158 | _EH_prolog=X 159 | _endthread=X 160 | _endthreadex=X 161 | _environ=Z DATA 162 | _eof=X 163 | _errno=Z DATA 164 | _except_handler2=X 165 | _except_handler3=X 166 | _execl=X 167 | _execle=X 168 | _execlp=X 169 | _execlpe=X 170 | _execv=X 171 | _execve=X 172 | _execvp=X 173 | _execvpe=X 174 | _exit=X 175 | exit=X 176 | exp=X 177 | _expand=X 178 | fabs=X 179 | fclose=X 180 | _fcloseall=X 181 | _fcvt=X 182 | _fdopen=X 183 | feof=X 184 | ferror=X 185 | fflush=X 186 | fgetc=X 187 | _fgetchar=X 188 | fgetpos=X 189 | fgets=X 190 | fgetwc=X 191 | _fgetwchar=X 192 | fgetws=X 193 | _filbuf=X 194 | _fileinfo=X 195 | _filelength=X 196 | _filelengthi64=X 197 | _fileno=X 198 | _findclose=X 199 | _findfirst=X 200 | _findfirst64=X 201 | _findfirsti64=X 202 | _findnext=X 203 | _findnext64=X 204 | _findnexti64=X 205 | _finite=X 206 | floor=X 207 | _flsbuf=X 208 | _flushall=X 209 | fmod=X 210 | _fmode=X 211 | fopen=X 212 | _fpclass=X 213 | __fpecode=Z DATA 214 | _fpieee_flt=X 215 | _fpreset=X 216 | fprintf=X 217 | fputc=X 218 | _fputchar=X 219 | fputs=X 220 | fputwc=X 221 | _fputwchar=X 222 | fputws=X 223 | fread=X 224 | free=X 225 | freopen=X 226 | frexp=X 227 | fscanf=X 228 | fseek=X 229 | fsetpos=X 230 | _fsopen=X 231 | _fstat=X 232 | _fstat64=X 233 | _fstati64=X 234 | ftell=X 235 | _ftime=X 236 | _ftime64=X 237 | _ftol=X 238 | _fullpath=X 239 | _futime=X 240 | _futime64=X 241 | fwprintf=X 242 | fwrite=X 243 | fwscanf=X 244 | _gcvt=X 245 | _get_heap_handle=X 246 | _get_osfhandle=X 247 | _get_sbh_threshold=X 248 | getc=X 249 | _getch=X 250 | getchar=X 251 | _getche=X 252 | _getcwd=X 253 | _Getdays=X 254 | _getdcwd=X 255 | _getdiskfree=X 256 | _getdllprocaddr=X 257 | _getdrive=X 258 | _getdrives=X 259 | getenv=X 260 | __getmainargs=X 261 | _getmaxstdio=X 262 | _getmbcp=X 263 | _Getmonths=X 264 | _getpid=X 265 | gets=X 266 | _getsystime=X 267 | _Gettnames=X 268 | _getw=X 269 | getwc=X 270 | getwchar=X 271 | _getws=X 272 | _global_unwind2=X 273 | gmtime=X 274 | _gmtime64=X 275 | _heapadd=X 276 | _heapchk=X 277 | _heapmin=X 278 | _heapset=X 279 | _heapused=X 280 | _heapwalk=X 281 | _HUGE=X 282 | _hypot=X 283 | _i64toa=X 284 | _i64tow=X 285 | __initenv=X 286 | _initterm=X 287 | _inp=X 288 | _inpd=X 289 | _inpw=X 290 | _iob=X 291 | is_wctype=X 292 | isalnum=X 293 | isalpha=X 294 | __isascii=X 295 | _isatty=X 296 | iscntrl=X 297 | __iscsym=X 298 | __iscsymf=X 299 | _isctype=X 300 | isdigit=X 301 | isgraph=X 302 | isleadbyte=X 303 | islower=X 304 | _ismbbalnum=X 305 | _ismbbalpha=X 306 | _ismbbgraph=X 307 | _ismbbkalnum=X 308 | _ismbbkana=X 309 | _ismbbkprint=X 310 | _ismbbkpunct=X 311 | _ismbblead=X 312 | _ismbbprint=X 313 | _ismbbpunct=X 314 | _ismbbtrail=X 315 | _ismbcalnum=X 316 | _ismbcalpha=X 317 | _ismbcdigit=X 318 | _ismbcgraph=X 319 | _ismbchira=X 320 | _ismbckata=X 321 | _ismbcl0=X 322 | _ismbcl1=X 323 | _ismbcl2=X 324 | _ismbclegal=X 325 | _ismbclower=X 326 | _ismbcprint=X 327 | _ismbcpunct=X 328 | _ismbcspace=X 329 | _ismbcsymbol=X 330 | _ismbcupper=X 331 | _ismbslead=X 332 | _ismbstrail=X 333 | _isnan=X 334 | isprint=X 335 | ispunct=X 336 | isspace=X 337 | isupper=X 338 | iswalnum=X 339 | iswalpha=X 340 | iswascii=X 341 | iswcntrl=X 342 | iswctype=X 343 | iswdigit=X 344 | iswgraph=X 345 | iswlower=X 346 | iswprint=X 347 | iswpunct=X 348 | iswspace=X 349 | iswupper=X 350 | iswxdigit=X 351 | isxdigit=X 352 | _itoa=X 353 | _itow=X 354 | _j0=X 355 | _j1=X 356 | _jn=X 357 | _kbhit=X 358 | labs=X 359 | __lc_codepage=X 360 | __lc_collate_cp=X 361 | __lc_handle=X 362 | __lconv_init=X 363 | ldexp=X 364 | ldiv=X 365 | _lfind=X 366 | _loaddll=X 367 | _local_unwind2=X 368 | localeconv=X 369 | localtime=X 370 | _localtime64=X 371 | _lock=X 372 | _locking=X 373 | log=X 374 | log10=X 375 | _logb=X 376 | longjmp=X 377 | _longjmpex=X 378 | _lrotl=X 379 | _lrotr=X 380 | _lsearch=X 381 | _lseek=X 382 | _lseeki64=X 383 | _ltoa=X 384 | _ltow=X 385 | _makepath=X 386 | malloc=X 387 | __mb_cur_max=X 388 | _mbbtombc=X 389 | _mbbtype=X 390 | _mbcasemap=X 391 | _mbccpy=X 392 | _mbcjistojms=X 393 | _mbcjmstojis=X 394 | _mbclen=X 395 | _mbctohira=X 396 | _mbctokata=X 397 | _mbctolower=X 398 | _mbctombb=X 399 | _mbctoupper=X 400 | _mbctype=X 401 | mblen=X 402 | _mbsbtype=X 403 | _mbscat=X 404 | _mbschr=X 405 | _mbscmp=X 406 | _mbscoll=X 407 | _mbscpy=X 408 | _mbscspn=X 409 | _mbsdec=X 410 | _mbsdup=X 411 | _mbsicmp=X 412 | _mbsicoll=X 413 | _mbsinc=X 414 | _mbslen=X 415 | _mbslwr=X 416 | _mbsnbcat=X 417 | _mbsnbcmp=X 418 | _mbsnbcnt=X 419 | _mbsnbcoll=X 420 | _mbsnbcpy=X 421 | _mbsnbicmp=X 422 | _mbsnbicoll=X 423 | _mbsnbset=X 424 | _mbsncat=X 425 | _mbsnccnt=X 426 | _mbsncmp=X 427 | _mbsncoll=X 428 | _mbsncpy=X 429 | _mbsnextc=X 430 | _mbsnicmp=X 431 | _mbsnicoll=X 432 | _mbsninc=X 433 | _mbsnset=X 434 | _mbspbrk=X 435 | _mbsrchr=X 436 | _mbsrev=X 437 | _mbsset=X 438 | _mbsspn=X 439 | _mbsspnp=X 440 | _mbsstr=X 441 | _mbstok=X 442 | mbstowcs=X 443 | _mbstrlen=X 444 | _mbsupr=X 445 | mbtowc=X 446 | _memccpy=X 447 | memchr=X 448 | memcmp=X 449 | memcpy=X 450 | _memicmp=X 451 | memmove=X 452 | memset=X 453 | _mkdir=X 454 | _mktemp=X 455 | mktime=X 456 | _mktime64=X 457 | modf=X 458 | _msize=X 459 | _nextafter=X 460 | _onexit=X 461 | _open=X 462 | _open_osfhandle=X 463 | _osplatform=Z DATA 464 | _osver=Z DATA 465 | _outp=X 466 | _outpd=X 467 | _outpw=X 468 | __p___argc=Z DATA 469 | __p___argv=Z DATA 470 | __p___initenv=X 471 | __p___mb_cur_max=X 472 | __p___wargv=Z DATA 473 | __p___winitenv=X 474 | __p__acmdln=X 475 | __p__amblksiz=X 476 | __p__commode=X 477 | __p__daylight=X 478 | __p__dstbias=Z DATA 479 | __p__environ=Z DATA 480 | __p__fileinfo=X 481 | __p__fmode=X 482 | __p__iob=X 483 | __p__mbcasemap=X 484 | __p__mbctype=X 485 | __p__osver=Z DATA 486 | __p__pctype=X 487 | __p__pgmptr=X 488 | __p__pwctype=X 489 | __p__timezone=X 490 | __p__tzname=X 491 | __p__wcmdln=X 492 | __p__wenviron=Z DATA 493 | __p__winmajor=X 494 | __p__winminor=X 495 | __p__winver=X 496 | __p__wpgmptr=X 497 | _pclose=X 498 | _pctype=X 499 | perror=X 500 | _pgmptr=X 501 | __pioinfo=X 502 | _pipe=X 503 | _popen=X 504 | pow=X 505 | printf=X 506 | _purecall=X 507 | putc=X 508 | _putch=X 509 | putchar=X 510 | _putenv=X 511 | puts=X 512 | _putw=X 513 | putwc=X 514 | putwchar=X 515 | _putws=X 516 | _pwctype=X 517 | __pxcptinfoptrs=X 518 | qsort=X 519 | raise=X 520 | rand=X 521 | _read=X 522 | realloc=X 523 | remove=X 524 | rename=X 525 | rewind=X 526 | _rmdir=X 527 | _rmtmp=X 528 | _rotl=X 529 | _rotr=X 530 | __RTCastToVoid=X 531 | __RTDynamicCast=X 532 | __RTtypeid=X 533 | _safe_fdiv=X 534 | _safe_fdivr=X 535 | _safe_fprem=X 536 | _safe_fprem1=X 537 | _scalb=X 538 | scanf=X 539 | _searchenv=X 540 | _seh_longjmp_unwind=X 541 | __set_app_type=X 542 | _set_error_mode=X 543 | _set_sbh_threshold=X 544 | setbuf=X 545 | _seterrormode=X 546 | _setjmp=X 547 | _setjmp3=X 548 | __setlc_active=X 549 | setlocale=X 550 | _setmaxstdio=X 551 | _setmbcp=X 552 | _setmode=X 553 | _setsystime=X 554 | __setusermatherr=X 555 | setvbuf=X 556 | signal=X 557 | sin=X 558 | sinh=X 559 | _sleep=X 560 | _vscprintf=X 561 | _vscwprintf=X 562 | _snprintf=X 563 | _snwprintf=X 564 | _sopen=X 565 | _spawnl=X 566 | _spawnle=X 567 | _spawnlp=X 568 | _spawnlpe=X 569 | _spawnv=X 570 | _spawnve=X 571 | _spawnvp=X 572 | _spawnvpe=X 573 | _splitpath=X 574 | sprintf=X 575 | sqrt=X 576 | srand=X 577 | sscanf=X 578 | _stat=X 579 | _stat64=X 580 | _stati64=X 581 | _statusfp=X 582 | strcat=X 583 | strchr=X 584 | strcmp=X 585 | _strcmpi=X 586 | strcoll=X 587 | strcpy=X 588 | strcspn=X 589 | _strdate=X 590 | _strdup=X 591 | _strerror=X 592 | strerror=X 593 | _Strftime=X 594 | strftime=X 595 | _stricmp=X 596 | _stricoll=X 597 | __STRINGTOLD=X 598 | strlen=X 599 | _strlwr=X 600 | strncat=X 601 | strncmp=X 602 | _strncoll=X 603 | strncpy=X 604 | _strnicmp=X 605 | _strnicoll=X 606 | _strnset=X 607 | strpbrk=X 608 | strrchr=X 609 | _strrev=X 610 | _strset=X 611 | strspn=X 612 | strstr=X 613 | _strtime=X 614 | strtod=X 615 | strtok=X 616 | strtol=X 617 | strtoul=X 618 | _strupr=X 619 | strxfrm=X 620 | _swab=X 621 | swprintf=X 622 | swscanf=X 623 | _sys_errlist=X 624 | _sys_nerr=X 625 | system=X 626 | tan=X 627 | tanh=X 628 | _tell=X 629 | _telli64=X 630 | _tempnam=X 631 | __threadhandle=X 632 | __threadid=X 633 | time=X 634 | _time64=X 635 | _timezone=X 636 | tmpfile=X 637 | tmpnam=X 638 | __toascii=X 639 | _tolower=X 640 | tolower=X 641 | _toupper=X 642 | toupper=X 643 | towlower=X 644 | towupper=X 645 | _tzname=X 646 | _tzset=X 647 | _ui64toa=X 648 | _ui64tow=X 649 | _ultoa=X 650 | _ultow=X 651 | _umask=X 652 | __unDName=X 653 | __unDNameEx=X 654 | ungetc=X 655 | _ungetch=X 656 | ungetwc=X 657 | __unguarded_readlc_active=X 658 | _unlink=X 659 | _unloaddll=X 660 | _unlock=X 661 | _utime=X 662 | _utime64=X 663 | vfprintf=X 664 | vfwprintf=X 665 | vprintf=X 666 | _vsnprintf=X 667 | _vsnwprintf=X 668 | vsprintf=X 669 | vswprintf=X 670 | vwprintf=X 671 | _waccess=X 672 | __wargv=Z DATA 673 | _wasctime=X 674 | _wchdir=X 675 | _wchmod=X 676 | _wcmdln=X 677 | _wcreat=X 678 | wcscat=X 679 | wcschr=X 680 | wcscmp=X 681 | wcscoll=X 682 | wcscpy=X 683 | wcscspn=X 684 | _wcsdup=X 685 | wcsftime=X 686 | _wcsicmp=X 687 | _wcsicoll=X 688 | wcslen=X 689 | _wcslwr=X 690 | wcsncat=X 691 | wcsncmp=X 692 | _wcsncoll=X 693 | wcsncpy=X 694 | _wcsnicmp=X 695 | _wcsnicoll=X 696 | _wcsnset=X 697 | wcspbrk=X 698 | wcsrchr=X 699 | _wcsrev=X 700 | _wcsset=X 701 | wcsspn=X 702 | wcsstr=X 703 | wcstod=X 704 | wcstok=X 705 | wcstol=X 706 | wcstombs=X 707 | _wcstoui64=X 708 | wcstoul=X 709 | _wcsupr=X 710 | wcsxfrm=X 711 | _wctime=X 712 | _wctime64=X 713 | wctomb=X 714 | _wenviron=Z DATA 715 | _wexecl=X 716 | _wexecle=X 717 | _wexeclp=X 718 | _wexeclpe=X 719 | _wexecv=X 720 | _wexecve=X 721 | _wexecvp=X 722 | _wexecvpe=X 723 | _wfdopen=X 724 | _wfindfirst=X 725 | _wfindfirst64=X 726 | _wfindfirsti64=X 727 | _wfindnext=X 728 | _wfindnext64=X 729 | _wfindnexti64=X 730 | _wfopen=X 731 | _wfreopen=X 732 | _wfsopen=X 733 | _wfullpath=X 734 | _wgetcwd=X 735 | _wgetdcwd=X 736 | _wgetenv=X 737 | __wgetmainargs=X 738 | __winitenv=X 739 | _winmajor=X 740 | _winminor=X 741 | _winver=X 742 | _wmakepath=X 743 | _wmkdir=X 744 | _wmktemp=X 745 | _wopen=X 746 | _wperror=X 747 | _wpgmptr=X 748 | _wpopen=X 749 | wprintf=X 750 | _wputenv=X 751 | _wremove=X 752 | _wrename=X 753 | _write=X 754 | _wrmdir=X 755 | wscanf=X 756 | _wsearchenv=X 757 | _wsetlocale=X 758 | _wsopen=X 759 | _wspawnl=X 760 | _wspawnle=X 761 | _wspawnlp=X 762 | _wspawnlpe=X 763 | _wspawnv=X 764 | _wspawnve=X 765 | _wspawnvp=X 766 | _wspawnvpe=X 767 | _wsplitpath=X 768 | _wstat=X 769 | _wstat64=X 770 | _wstati64=X 771 | _wstrdate=X 772 | _wstrtime=X 773 | _wsystem=X 774 | _wtempnam=X 775 | _wtmpnam=X 776 | _wtoi=X 777 | _wtoi64=X 778 | _wtol=X 779 | _wunlink=X 780 | _wutime=X 781 | _wutime64=X 782 | _XcptFilter=X 783 | _y0=X 784 | _y1=X 785 | _yn=X 786 | -------------------------------------------------------------------------------- /msrt/ntdll-x64.def: -------------------------------------------------------------------------------- 1 | LIBRARY NTDLL.DLL 2 | EXPORTS 3 | __chkstk 4 | _aullshr 5 | _fltused 6 | -------------------------------------------------------------------------------- /msrt/ntdll-x86.def: -------------------------------------------------------------------------------- 1 | LIBRARY NTDLL.DLL 2 | EXPORTS 3 | _chkstk 4 | _alldiv 5 | _allmul 6 | _allshr 7 | _aullrem 8 | _aulldvrm 9 | _aulldiv 10 | _aullshr 11 | _allshl 12 | _fltused 13 | -------------------------------------------------------------------------------- /src/balance.c: -------------------------------------------------------------------------------- 1 | #include "general.h" 2 | #include "ini_parser.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /************************************************************************** 9 | * 时间转换函数. 10 | */ 11 | static 12 | LIB_INLINE uint64_t 13 | ft2ull(const FILETIME* ftime) 14 | { 15 | ULARGE_INTEGER li; 16 | li.LowPart = ftime->dwLowDateTime; 17 | li.HighPart = ftime->dwHighDateTime; 18 | return li.QuadPart; 19 | } 20 | 21 | /************************************************************************** 22 | * 通过apc的连续调用,计算出cpu系统使用率. 23 | * cpu利用率 = (sys-idl)/sys 24 | * lpArg, 用户apc回调参数 25 | * dwTimerLowValue, 定时器低位值 26 | * dwTimerHighValue, 定时器高位值 27 | */ 28 | static void CALLBACK 29 | get_cpu_usage(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHighValue) 30 | { 31 | FILETIME idle, kernel, user; 32 | static FILETIME prev_idle, prev_kernel, prev_user; 33 | static int first = 1; 34 | uint64_t sys; 35 | int* cpu = (int *)lpArg; 36 | if (GetSystemTimes(&idle, &kernel, &user) && first) 37 | { 38 | prev_idle = idle; 39 | prev_kernel = kernel; 40 | prev_user = user; 41 | first = 0; 42 | return; 43 | } 44 | sys = (ft2ull(&user) - ft2ull(&prev_user)) + \ 45 | (ft2ull(&kernel) - ft2ull(&prev_kernel)); 46 | *cpu= (int)((sys - ft2ull(&idle) + ft2ull(&prev_idle)) * 100 / sys); 47 | prev_idle = idle; 48 | prev_kernel = kernel; 49 | prev_user = user; 50 | } 51 | 52 | static 53 | LIB_INLINE uint32_t 54 | get_foreground_window(void) 55 | { 56 | uint32_t pid = 0; 57 | GetWindowThreadProcessId(GetForegroundWindow(), (LPDWORD)&pid); 58 | return pid; 59 | } 60 | 61 | static void 62 | set_cpu_priority(int val, int m_rate) 63 | { 64 | uint32_t m_pri = GetPriorityClass(GetCurrentProcess()); 65 | if (m_rate > val) 66 | { 67 | uint32_t m_windows = get_foreground_window(); 68 | if (GetCurrentProcessId() == m_windows) 69 | { 70 | if (m_pri != ABOVE_NORMAL_PRIORITY_CLASS) 71 | { 72 | SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); 73 | } 74 | } 75 | else if (GetCurrentProcessId() != BELOW_NORMAL_PRIORITY_CLASS) 76 | { 77 | SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS); 78 | } 79 | } 80 | else if (m_pri != NORMAL_PRIORITY_CLASS) 81 | { 82 | SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); 83 | } 84 | } 85 | 86 | /************************************************************************** 87 | * 提供所谓的进程均衡调度功能.当cpu达到某个阈值,即CpuUse=? 88 | * 浏览器如果在前台运行,则提高它的运行级别. 89 | * 浏览器如果在后台运行,则降低它的运行级别. 90 | */ 91 | unsigned WINAPI 92 | set_cpu_balance(void *lparam) 93 | { 94 | HANDLE m_timer = NULL; 95 | LPCWSTR m_pref = L"cpu_pri_timer"; 96 | WCHAR m_name[32] = {0}; 97 | WNDINFO m_windows; 98 | int m_cpu = 0; 99 | LARGE_INTEGER m_duetime; 100 | int value = ini_read_int("attach", "CpuUse", ini_portable_path, true); 101 | memset(&m_windows, 0, sizeof(WNDINFO)); 102 | m_windows.hPid = GetCurrentProcessId(); 103 | if (!get_moz_hwnd(&m_windows)) 104 | { 105 | return (0); 106 | } 107 | wnsprintfW(m_name, 32, L"%ls_%lu",m_pref, m_windows.hPid); 108 | if ((m_timer = CreateWaitableTimerW(NULL, false, m_name)) == NULL) 109 | { 110 | return (0); 111 | } 112 | m_duetime.QuadPart = -20000000; /* 2 seconds pass */ 113 | if (!SetWaitableTimer(m_timer, &m_duetime,2000, get_cpu_usage, (LPVOID)&m_cpu, false)) 114 | { 115 | CloseHandle(m_timer); 116 | return (0); 117 | } 118 | if (value < 0 || value > 99) 119 | { 120 | value = 25; /* default cpu usage 25% */ 121 | } 122 | while (SleepEx(INFINITE,true)) 123 | { 124 | #ifdef _LOGDEBUG 125 | logmsg("CpuUse: %d%%\n", m_cpu); 126 | #endif 127 | set_cpu_priority(value, m_cpu); 128 | } 129 | CloseHandle(m_timer); 130 | return (1); 131 | } 132 | -------------------------------------------------------------------------------- /src/balance.h: -------------------------------------------------------------------------------- 1 | #ifndef _BAL_ANCE_H_ 2 | # define _BAL_ANCE_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern unsigned __stdcall set_cpu_balance(void *fx_info); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif /* end _BAL_ANCE_H_ */ 15 | -------------------------------------------------------------------------------- /src/bosskey.c: -------------------------------------------------------------------------------- 1 | #include "general.h" 2 | #include "ini_parser.h" 3 | #include 4 | #include 5 | 6 | static int g_atom = 0; 7 | 8 | bool init_bosskey(LPWNDINFO pInfo) 9 | { 10 | WCHAR atom[8+1] = {0}; 11 | if ( !get_moz_hwnd(pInfo) ) 12 | { 13 | return false; 14 | } 15 | _ui64tow(pInfo->hPid,atom,10); 16 | pInfo->atom_str = GlobalAddAtomW(atom)-0xC000; 17 | return RegisterHotKey(NULL, pInfo->atom_str, pInfo->key_mod, pInfo->key_vk); 18 | } 19 | 20 | bool is_mozclass(HWND hwnd) 21 | { 22 | WCHAR m_temp[VALUE_LEN+1] = {0}; 23 | GetClassNameW(hwnd,m_temp,VALUE_LEN); 24 | return ( _wcsnicmp(m_temp,L"MozillaWindowClass",VALUE_LEN) ==0 || 25 | _wcsnicmp(m_temp,L"MozillaDialogClass",VALUE_LEN) ==0 ) ; 26 | } 27 | 28 | int CALLBACK find_chwnd(HWND hwnd, LPARAM lParam) 29 | { 30 | LPWNDINFO pInfo = (LPWNDINFO)lParam; 31 | DWORD dwPid = 0; 32 | GetWindowThreadProcessId(hwnd, &dwPid); 33 | if ( (dwPid == pInfo->hPid) && dwPid && IsWindowVisible(hwnd) ) 34 | { 35 | if ( is_mozclass(hwnd) ) 36 | { 37 | ShowWindow(hwnd,SW_HIDE); 38 | } 39 | } 40 | else if ( (dwPid == pInfo->hPid) && dwPid && !IsWindowVisible(hwnd) ) 41 | { 42 | if ( is_mozclass(hwnd) ) 43 | { 44 | SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, 3); 45 | ShowWindow(hwnd,SW_SHOW); 46 | if ( IsIconic(hwnd) ) 47 | { 48 | ShowWindow(hwnd,SW_RESTORE); 49 | } 50 | } 51 | } 52 | return true; 53 | } 54 | 55 | bool is_modkey(int n) 56 | { 57 | return ( n == MOD_ALT || 58 | n == MOD_CONTROL || 59 | n == MOD_SHIFT || 60 | n == MOD_WIN ) ; 61 | } 62 | 63 | void set_hotkey(LPWNDINFO pInfo) 64 | { 65 | char *lpstr = NULL; 66 | const char *delim = "+"; 67 | char tmp_stor[3][16] = { {0,0} }; 68 | pInfo->key_mod = 0x06; /* CONTROL+SHIFT 键 */ 69 | pInfo->key_vk = 0xc0; /* ~键 */ 70 | if (ini_read_string("attach","Hotkey",&lpstr,ini_portable_path, true)) 71 | { 72 | int i = 0; 73 | char *p = lpstr; 74 | int tmp[3] = {0}; 75 | int num; 76 | char *strtmp = strstr(lpstr, delim); 77 | while( strtmp != NULL && i < 3 ) 78 | { 79 | strtmp[0]='\0'; 80 | strncpy(tmp_stor[i++],p,15); 81 | p = strtmp + strlen(delim); 82 | strtmp = strstr(p, delim); 83 | if (!strtmp) 84 | { 85 | strncpy(tmp_stor[i],p,15); 86 | } 87 | } 88 | for (num = 0 ; num <= i ; num++) 89 | { 90 | tmp[num] = atoi(tmp_stor[num]); 91 | } 92 | if (is_modkey(tmp[0])) 93 | { 94 | if ((i==2) && is_modkey(tmp[1]) && !is_modkey(tmp[2])) 95 | { 96 | pInfo->key_mod = tmp[0]|tmp[1]; 97 | pInfo->key_vk = tmp[2]; 98 | } 99 | else if ( i==1 && tmp[1]>0x2f ) 100 | { 101 | pInfo->key_mod = tmp[0]; 102 | pInfo->key_vk = tmp[1]; 103 | } 104 | } 105 | } 106 | } 107 | 108 | void WINAPI uninstall_bosskey(void) 109 | { 110 | if (g_atom) 111 | { 112 | UnregisterHotKey(NULL, g_atom); 113 | GlobalDeleteAtom(g_atom); 114 | g_atom = 0; 115 | } 116 | } 117 | 118 | unsigned WINAPI bosskey_thread(void *lparam) 119 | { 120 | WNDINFO ff_info = { 0 }; 121 | ff_info.hPid = GetCurrentProcessId(); 122 | set_hotkey(&ff_info); 123 | if ( init_bosskey(&ff_info) ) 124 | { 125 | MSG msg; 126 | g_atom = ff_info.atom_str; 127 | while (GetMessageW(&msg, NULL, 0, 0) > 0) 128 | { 129 | TranslateMessage(&msg); 130 | DispatchMessage(&msg); 131 | EnumWindows(find_chwnd, (LPARAM)&ff_info); 132 | } 133 | } 134 | return (1); 135 | } 136 | -------------------------------------------------------------------------------- /src/bosskey.h: -------------------------------------------------------------------------------- 1 | #ifndef _BOSS_KEY_H_ 2 | # define _BOSS_KEY_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern unsigned __stdcall bosskey_thread(void * lparam); 9 | extern unsigned __stdcall uninstall_bosskey(void); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* end _BOSS_KEY_H_ */ 16 | -------------------------------------------------------------------------------- /src/cjson.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef cJSON__h 24 | #define cJSON__h 25 | 26 | #ifdef __cplusplus 27 | extern "C" 28 | { 29 | #endif 30 | 31 | #if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) 32 | #define __WINDOWS__ 33 | #endif 34 | 35 | #ifdef __WINDOWS__ 36 | 37 | /* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: 38 | 39 | CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols 40 | CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) 41 | CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol 42 | 43 | For *nix builds that support visibility attribute, you can define similar behavior by 44 | 45 | setting default visibility to hidden by adding 46 | -fvisibility=hidden (for gcc) 47 | or 48 | -xldscope=hidden (for sun cc) 49 | to CFLAGS 50 | 51 | then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does 52 | 53 | */ 54 | 55 | #define CJSON_CDECL __cdecl 56 | #define CJSON_STDCALL __stdcall 57 | 58 | /* export symbols by default, this is necessary for copy pasting the C and header file */ 59 | #if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) 60 | #define CJSON_EXPORT_SYMBOLS 61 | #endif 62 | 63 | #if defined(CJSON_HIDE_SYMBOLS) 64 | #define CJSON_PUBLIC(type) type CJSON_STDCALL 65 | #elif defined(CJSON_EXPORT_SYMBOLS) 66 | #define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL 67 | #elif defined(CJSON_IMPORT_SYMBOLS) 68 | #define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL 69 | #endif 70 | #else /* !__WINDOWS__ */ 71 | #define CJSON_CDECL 72 | #define CJSON_STDCALL 73 | 74 | #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) 75 | #define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type 76 | #else 77 | #define CJSON_PUBLIC(type) type 78 | #endif 79 | #endif 80 | 81 | /* project version */ 82 | #define CJSON_VERSION_MAJOR 1 83 | #define CJSON_VERSION_MINOR 7 84 | #define CJSON_VERSION_PATCH 12 85 | 86 | #include 87 | 88 | /* cJSON Types: */ 89 | #define cJSON_Invalid (0) 90 | #define cJSON_False (1 << 0) 91 | #define cJSON_True (1 << 1) 92 | #define cJSON_NULL (1 << 2) 93 | #define cJSON_Number (1 << 3) 94 | #define cJSON_String (1 << 4) 95 | #define cJSON_Array (1 << 5) 96 | #define cJSON_Object (1 << 6) 97 | #define cJSON_Raw (1 << 7) /* raw json */ 98 | 99 | #define cJSON_IsReference 256 100 | #define cJSON_StringIsConst 512 101 | 102 | /* The cJSON structure: */ 103 | typedef struct cJSON 104 | { 105 | /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ 106 | struct cJSON *next; 107 | struct cJSON *prev; 108 | /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ 109 | struct cJSON *child; 110 | 111 | /* The type of the item, as above. */ 112 | int type; 113 | 114 | /* The item's string, if type==cJSON_String and type == cJSON_Raw */ 115 | char *valuestring; 116 | /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ 117 | int valueint; 118 | /* The item's number, if type==cJSON_Number */ 119 | double valuedouble; 120 | 121 | /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ 122 | char *string; 123 | } cJSON; 124 | 125 | typedef struct cJSON_Hooks 126 | { 127 | /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ 128 | void *(CJSON_CDECL *malloc_fn)(size_t sz); 129 | void (CJSON_CDECL *free_fn)(void *ptr); 130 | } cJSON_Hooks; 131 | 132 | typedef bool cJSON_bool; 133 | 134 | /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. 135 | * This is to prevent stack overflows. */ 136 | #ifndef CJSON_NESTING_LIMIT 137 | #define CJSON_NESTING_LIMIT 1000 138 | #endif 139 | 140 | /* returns the version of cJSON as a string */ 141 | CJSON_PUBLIC(const char*) cJSON_Version(void); 142 | 143 | /* Supply malloc, realloc and free functions to cJSON */ 144 | CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); 145 | 146 | /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ 147 | /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ 148 | CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); 149 | /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ 150 | /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ 151 | CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); 152 | 153 | /* Render a cJSON entity to text for transfer/storage. */ 154 | CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); 155 | /* Render a cJSON entity to text for transfer/storage without any formatting. */ 156 | CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); 157 | /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ 158 | CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); 159 | /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ 160 | /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ 161 | CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); 162 | /* Delete a cJSON entity and all subentities. */ 163 | CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); 164 | 165 | /* Returns the number of items in an array (or object). */ 166 | CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); 167 | /* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ 168 | CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); 169 | /* Get item "string" from object. Case insensitive. */ 170 | CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); 171 | CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); 172 | CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); 173 | /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ 174 | CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); 175 | 176 | /* Check if the item is a string and return its valuestring */ 177 | CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); 178 | 179 | /* These functions check the type of an item */ 180 | CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); 181 | CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); 182 | CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); 183 | CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); 184 | CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); 185 | CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); 186 | CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); 187 | CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); 188 | CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); 189 | CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); 190 | 191 | /* These calls create a cJSON item of the appropriate type. */ 192 | CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); 193 | CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); 194 | CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); 195 | CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); 196 | CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); 197 | CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); 198 | /* raw json */ 199 | CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); 200 | CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); 201 | CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); 202 | 203 | /* Create a string where valuestring references a string so 204 | * it will not be freed by cJSON_Delete */ 205 | CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); 206 | /* Create an object/arrray that only references it's elements so 207 | * they will not be freed by cJSON_Delete */ 208 | CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); 209 | CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); 210 | 211 | /* These utilities create an Array of count items. */ 212 | CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); 213 | CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); 214 | CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); 215 | CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); 216 | 217 | /* Append item to the specified array/object. */ 218 | CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); 219 | CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); 220 | /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. 221 | * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before 222 | * writing to `item->string` */ 223 | CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); 224 | /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ 225 | CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); 226 | CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); 227 | 228 | /* Remove/Detatch items from Arrays/Objects. */ 229 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); 230 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); 231 | CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); 232 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); 233 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); 234 | CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); 235 | CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); 236 | 237 | /* Update array items. */ 238 | CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ 239 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); 240 | CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); 241 | CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); 242 | CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); 243 | 244 | /* Duplicate a cJSON item */ 245 | CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); 246 | /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will 247 | need to be released. With recurse!=0, it will duplicate any children connected to the item. 248 | The item->next and ->prev pointers are always zero on return from Duplicate. */ 249 | /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. 250 | * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ 251 | CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); 252 | 253 | 254 | CJSON_PUBLIC(void) cJSON_Minify(char *json); 255 | 256 | /* Helper functions for creating and adding items to an object at the same time. 257 | * They return the added item or NULL on failure. */ 258 | CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); 259 | CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); 260 | CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); 261 | CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); 262 | CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); 263 | CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); 264 | CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); 265 | CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); 266 | CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); 267 | 268 | /* When assigning an integer value, it needs to be propagated to valuedouble too. */ 269 | #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) 270 | /* helper for the cJSON_SetNumberValue macro */ 271 | CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); 272 | #define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) 273 | 274 | /* Macro for iterating over an array or object */ 275 | #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) 276 | 277 | /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ 278 | CJSON_PUBLIC(void *) cJSON_malloc(size_t size); 279 | CJSON_PUBLIC(void) cJSON_free(void *object); 280 | 281 | #ifdef __cplusplus 282 | } 283 | #endif 284 | 285 | #endif 286 | -------------------------------------------------------------------------------- /src/cpu_info.c: -------------------------------------------------------------------------------- 1 | #include "cpu_info.h" 2 | #include 3 | #include 4 | 5 | #define UU16(x) ( (uint8_t)x | (((uint16_t)(x)&0xff) << 8) ) 6 | #define UU32(y) ( UU16(y) | (((uint32_t)(UU16(y))&0xffff) << 16) ) 7 | 8 | static LIB_INLINE void* 9 | memset_less32(void *dst, int a, size_t n) 10 | { 11 | uint8_t *dt = (uint8_t *)dst; 12 | if (n & 0x01) 13 | { 14 | *dt++ = (uint8_t)a; 15 | } 16 | if (n & 0x02) 17 | { 18 | *(uint16_t *)dt = UU16(a); 19 | dt += 2; 20 | } 21 | if (n & 0x04) 22 | { 23 | _mm_stream_si32((int *)dt, UU32(a)); 24 | dt += 4; 25 | } 26 | if (n & 0x08) 27 | { 28 | uint32_t c = UU32(a); 29 | _mm_stream_si32((int *)dt+0, c); 30 | _mm_stream_si32((int *)dt+1, c); 31 | dt += 8; 32 | } 33 | if (n & 0x10) 34 | { 35 | uint32_t c = UU32(a); 36 | _mm_stream_si32((int *)dt+0, c); 37 | _mm_stream_si32((int *)dt+1, c); 38 | _mm_stream_si32((int *)dt+2, c); 39 | _mm_stream_si32((int *)dt+3, c); 40 | dt += 16; 41 | } 42 | return dst; 43 | } 44 | 45 | /* using non-temporal avx */ 46 | void* __cdecl 47 | memset_avx(void* dst, int c, size_t size) 48 | { 49 | __m256i vals; 50 | uint8_t *buffer = (uint8_t *)dst; 51 | const uint8_t non_aligned = (uintptr_t)buffer % 32; 52 | /* memory address not 32-byte aligned */ 53 | if ( non_aligned ) 54 | { 55 | /* fill head */ 56 | uintptr_t head = 32 - non_aligned; 57 | memset_less32(buffer, c, head); 58 | buffer += head; 59 | size -= head; 60 | } 61 | if ( c ) 62 | { 63 | vals = _mm256_set1_epi8(c); 64 | } 65 | else 66 | { 67 | vals = _mm256_setzero_si256(); 68 | } 69 | while (size >= 32) 70 | { 71 | _mm256_stream_si256((__m256i*)buffer, vals); 72 | buffer += 32; 73 | size -= 32; 74 | } 75 | if ( size > 0 ) 76 | { 77 | /* fill tail */ 78 | memset_less32(buffer, c, size); 79 | } 80 | return dst; 81 | } 82 | -------------------------------------------------------------------------------- /src/cpu_info.h: -------------------------------------------------------------------------------- 1 | #ifndef _CPU_INFO_H_ 2 | # define _CPU_INFO_H_ 3 | 4 | #include "general.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern void* __cdecl memset_avx(void*, int, size_t); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | 17 | #endif /* _CPU_INFO_H_ */ 18 | -------------------------------------------------------------------------------- /src/general.h: -------------------------------------------------------------------------------- 1 | #ifndef _INI_PARA_H_ 2 | # define _INI_PARA_H_ 3 | 4 | #include 5 | #include 6 | #include "intrin_c.h" 7 | 8 | #define SYS_MALLOC(x) (HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (x))) 9 | #define SYS_FREE(x) (HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, (x)),(x = NULL)) 10 | 11 | #define EXCLUDE_NUM 32 /* 白名单个数(数组最大行数) */ 12 | #define VALUE_LEN 128 /* 保存值的最大长度 */ 13 | #define BUFSIZE (MAX_PATH*2) 14 | #define MAX_BUFF 1024 15 | #define LOCK_SPIN_COUNT 1500 16 | #define SIZE_OF_NT_SIGNATURE sizeof (DWORD) 17 | #define NAMES_LEN 64 18 | #define goodHandle(m_handle) ( (m_handle != NULL) && (m_handle != INVALID_HANDLE_VALUE) ) 19 | 20 | #if defined(__GNUC__) 21 | #define LIB_INLINE inline __attribute__((__gnu_inline__)) 22 | #define SHARED __attribute__((section(".shrd"), shared)) 23 | #define USERED __attribute__ ((__used__)) 24 | #define ALIGNED32 __attribute((aligned (32))) 25 | #else 26 | #define LIB_INLINE __inline 27 | #define SHARED 28 | #define USERED extern 29 | #define ALIGNED32 __declspec(align(32)) 30 | #endif 31 | 32 | #define fzero(b,len) (memset((LPBYTE)(b), '\0', (len))) 33 | extern LIB_INLINE bool is_wow64() {int wow64=0; return \ 34 | IsWow64Process(GetCurrentProcess(),&wow64)?(wow64==1?true:false):false;} 35 | 36 | typedef HMODULE (WINAPI *LoadLibraryExPtr)(LPCWSTR lpFileName,HANDLE hFile,DWORD dwFlags); 37 | typedef struct tagWNDINFO 38 | { 39 | int atom_str; 40 | int key_mod; 41 | int key_vk; 42 | DWORD hPid; 43 | HWND hFF; 44 | } WNDINFO, *LPWNDINFO; 45 | 46 | typedef enum 47 | { 48 | MOZ_UNKOWN = 0, 49 | MOZ_ICEWEASEL, 50 | MOZ_FIREFOX, 51 | MOZ_BETA, 52 | MOZ_DEV, 53 | MOZ_NIGHTLY 54 | } m_family; 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | #if defined(_MSC_VER) && !defined(VC12_CRT) 61 | typedef int (__cdecl *sprintf_ptr)(char *buffer,const char *fmt, ...); 62 | typedef int (__cdecl *snprintf_ptr)(char *_s, size_t n, const char *fmt, ...); 63 | typedef int (__cdecl *sscanf_ptr)(const char *string,const char *fmt, ...); 64 | typedef uint64_t (__cdecl *strtoui64_ptr)(const char *_s,char **_e,int _r); 65 | extern sprintf_ptr crt_sprintf; 66 | extern snprintf_ptr crt_snprintf; 67 | extern sscanf_ptr crt_sscanf; 68 | extern strtoui64_ptr crt_strtoui64; 69 | extern bool WINAPI init_crt_funcs(void); 70 | #else 71 | #define crt_sprintf sprintf 72 | #define crt_snprintf snprintf 73 | #define crt_sscanf sscanf 74 | #define crt_strtoui64 _strtoui64 75 | #endif 76 | 77 | extern char ini_portable_path[MAX_PATH + 1]; 78 | extern WCHAR xre_profile_path[MAX_BUFF]; 79 | extern WCHAR xre_profile_local_path[MAX_BUFF]; 80 | extern LoadLibraryExPtr sLoadLibraryExStub; 81 | extern HMODULE dll_module; 82 | extern bool creator_hook(void *target, void *func, void **original); 83 | extern bool remove_hook(void **target); 84 | 85 | #ifdef _LOGDEBUG 86 | extern void __cdecl logmsg(const char * format, ...); 87 | extern void WINAPI init_logs(void); 88 | #endif /* _LOGDEBUG */ 89 | 90 | extern int WINAPI get_file_version(void); 91 | extern LPWSTR WINAPI wstr_replace(LPWSTR in, size_t in_size, LPCWSTR pattern, LPCWSTR by); 92 | extern bool WINAPI wget_process_directory(LPWSTR lpstrName, DWORD len); 93 | extern bool WINAPI wcreate_dir(LPCWSTR dir); 94 | extern bool WINAPI exists_dir(const char *path, int mode); 95 | extern bool WINAPI exists_file(const char *path, int mode); 96 | extern bool WINAPI create_dir(const char *dir); 97 | extern bool WINAPI path_to_absolute(LPWSTR lpfile, int str_len); 98 | extern HWND WINAPI get_moz_hwnd(LPWNDINFO pInfo); 99 | extern bool WINAPI is_gui(LPCWSTR lpFileName); 100 | extern bool WINAPI get_process_directory(char *name, uint32_t len); 101 | extern bool WINAPI is_specialdll(uintptr_t callerAddress,LPCWSTR dll_file); 102 | extern bool WINAPI is_flash_plugins(uintptr_t caller); 103 | extern m_family WINAPI is_ff_official(void); 104 | extern bool WINAPI write_file(LPCWSTR appdata_path); 105 | extern bool WINAPI print_process_module(DWORD pid); 106 | extern bool WINAPI get_appdt_path(WCHAR *ini, int len); 107 | extern bool WINAPI get_localdt_path(WCHAR *ini, int len); 108 | extern DWORD WINAPI get_os_version(void); 109 | extern uint32_t WINAPI get_level_size(void); 110 | extern bool WINAPI cpu_has_avx(void); 111 | extern bool WINAPI cmd_has_setup(void); 112 | extern bool WINAPI cmd_has_profile(char *pout, const int size); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif /* end _INI_PARA_H_ */ 119 | -------------------------------------------------------------------------------- /src/ice_error.c: -------------------------------------------------------------------------------- 1 | #include "ice_error.h" 2 | #include "general.h" 3 | #include 4 | #include 5 | 6 | typedef LPTOP_LEVEL_EXCEPTION_FILTER (WINAPI *SetUnhandledExceptionFilterPtr)( 7 | LPTOP_LEVEL_EXCEPTION_FILTER 8 | lpTopLevelExceptionFilter); 9 | typedef BOOL (WINAPI *MiniDumpWriteDumpPtr)(HANDLE,DWORD,HANDLE,MINIDUMP_TYPE, 10 | PMINIDUMP_EXCEPTION_INFORMATION, 11 | PMINIDUMP_USER_STREAM_INFORMATION, 12 | PMINIDUMP_CALLBACK_INFORMATION); 13 | 14 | static SetUnhandledExceptionFilterPtr sSetUnhandledExceptionFilterStub; 15 | static SetUnhandledExceptionFilterPtr pSetUnhandledExceptionFilter; 16 | static MiniDumpWriteDumpPtr sMiniDumpWriteDumpStub; 17 | static HMODULE m_dbg; 18 | 19 | static LONG WINAPI 20 | ProcessException_ice(PEXCEPTION_POINTERS pExceptionInfo) 21 | { 22 | /* 异常信息结构体 */ 23 | MINIDUMP_EXCEPTION_INFORMATION ExInfo; 24 | /* dump生成目录 */ 25 | wchar_t appdir[MAX_PATH+1] = {0}; 26 | HANDLE hFile = NULL; 27 | if ( !(GetEnvironmentVariableW(L"APPDATA",appdir,MAX_PATH) > 0) ) 28 | { 29 | return EXCEPTION_CONTINUE_SEARCH; 30 | } 31 | PathAppendW(appdir,L"Iceweasel.dmp"); 32 | /* 创建文件句柄 */ 33 | hFile = CreateFileW(appdir, 34 | GENERIC_WRITE, 35 | FILE_SHARE_WRITE, 36 | NULL, 37 | TRUNCATE_EXISTING, 38 | FILE_ATTRIBUTE_NORMAL, 39 | NULL); 40 | if (INVALID_HANDLE_VALUE == hFile && ERROR_FILE_NOT_FOUND == GetLastError()) 41 | { 42 | hFile = CreateFileW(appdir, 43 | GENERIC_WRITE, 44 | FILE_SHARE_WRITE, 45 | NULL, 46 | CREATE_ALWAYS, 47 | FILE_ATTRIBUTE_NORMAL, 48 | NULL); 49 | } 50 | if (INVALID_HANDLE_VALUE == hFile) 51 | { 52 | return EXCEPTION_CONTINUE_SEARCH; 53 | } 54 | ExInfo.ThreadId = GetCurrentThreadId(); 55 | ExInfo.ExceptionPointers = pExceptionInfo; 56 | ExInfo.ClientPointers = true; 57 | 58 | /* MiniDumpWriteDump输出dump */ 59 | sMiniDumpWriteDumpStub(GetCurrentProcess(), 60 | GetCurrentProcessId(), 61 | hFile, 62 | MiniDumpNormal, 63 | &ExInfo, 64 | NULL, 65 | NULL ); 66 | 67 | CloseHandle(hFile); 68 | return EXCEPTION_EXECUTE_HANDLER; 69 | } 70 | 71 | static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI 72 | HookSetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter) 73 | { 74 | return sSetUnhandledExceptionFilterStub(ProcessException_ice); 75 | } 76 | 77 | unsigned WINAPI init_exeception(void * pParam) 78 | { 79 | HMODULE m_kernel; 80 | m_dbg = sLoadLibraryExStub?sLoadLibraryExStub(L"dbghelp.dll",NULL,0):LoadLibraryExW(L"dbghelp.dll",NULL,0); 81 | m_kernel = GetModuleHandleW(L"kernel32.dll"); 82 | if ( m_dbg == NULL || m_kernel == NULL || 83 | (sMiniDumpWriteDumpStub = (MiniDumpWriteDumpPtr)GetProcAddress(m_dbg, "MiniDumpWriteDump")) == NULL) 84 | { 85 | return (0); 86 | } 87 | pSetUnhandledExceptionFilter = (SetUnhandledExceptionFilterPtr)GetProcAddress(m_kernel, "SetUnhandledExceptionFilter"); 88 | return creator_hook(pSetUnhandledExceptionFilter, HookSetUnhandledExceptionFilter, (LPVOID*)&sSetUnhandledExceptionFilterStub); 89 | } 90 | 91 | void WINAPI jmp_end(void) 92 | { 93 | if ( m_dbg ) 94 | { 95 | FreeLibrary(m_dbg); 96 | } 97 | return; 98 | } 99 | -------------------------------------------------------------------------------- /src/ice_error.h: -------------------------------------------------------------------------------- 1 | #ifndef _ICE_ERROR_H_ 2 | # define _ICE_ERROR_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern unsigned __stdcall init_exeception(void * pParam); 9 | extern void __stdcall jmp_end(void); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* end _ICE_ERROR_H_ */ -------------------------------------------------------------------------------- /src/ini_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef _INI_PARSER_H 2 | #define _INI_PARSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define LEN_SECTION 64 9 | #define LEN_STRINGS 128 10 | #define MAX_BUFFER_SIZE (16 * 1024) 11 | #define ini_safe_free(p) ((p) ? ((free((void *)(p))), ((p) = NULL)) : (void *)(p)) 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef enum 18 | { 19 | CHR_UNKOWN = 0, 20 | CHR_WIN, 21 | CHR_UNIX 22 | } str_line; 23 | 24 | typedef enum 25 | { 26 | E_OTHER = 0, 27 | E_ANSI, 28 | E_UNICODE, 29 | E_UNICODE_BIG, 30 | E_UTF8, 31 | E_UTF8_BOM, 32 | E_ZERO, 33 | } str_encoding; 34 | 35 | typedef struct _node 36 | { 37 | struct _node *next; 38 | char content[1]; 39 | } node, *position; 40 | 41 | typedef struct _list 42 | { 43 | str_encoding codes; 44 | str_line breaks; 45 | bool write; 46 | FILE *pf; 47 | node *pd; 48 | } ini_list, *ini_cache; 49 | 50 | extern bool __stdcall ini_foreach_key(const char *sec, char (*lpdata)[LEN_STRINGS], int line, const char *path, const bool isfile); 51 | extern bool __stdcall ini_foreach_wkey(const char *sec, wchar_t (*lpdata)[LEN_STRINGS], int line, const char *path, const bool isfile); 52 | extern bool __stdcall inicache_foreach_key(const char *sec, char (*lpdata)[LEN_STRINGS], int line, ini_cache *ini); 53 | extern bool __stdcall inicache_foreach_wkey(const char *sec, wchar_t (*lpdata)[LEN_STRINGS], int line, ini_cache *ini); 54 | extern bool __stdcall ini_foreach_string(const char *sec, char (*lpdata)[LEN_STRINGS], int line, const char *path, const bool isfile); 55 | extern bool __stdcall ini_foreach_wstring(const char *sec, wchar_t (*lpdata)[LEN_STRINGS], int line, const char *path, const bool isfile); 56 | extern bool __stdcall inicache_foreach_string(const char *sec, char (*lpdata)[LEN_STRINGS], int line, ini_cache *ini); 57 | extern bool __stdcall inicache_foreach_wstring(const char *sec, wchar_t (*lpdata)[LEN_STRINGS], int line, ini_cache *ini); 58 | extern bool __stdcall ini_read_string(const char *sec, const char *key, char **buf, const char *path, const bool isfile); 59 | extern bool __stdcall inicache_read_string(const char *sec, const char *key, char **buf, ini_cache *ini); 60 | extern bool __stdcall ini_write_string(const char *sec, const char *key, const char *new_value, const char *path); 61 | extern bool __stdcall inicache_write_string(const char *sec, const char *key, const char *new_value, ini_cache *ini); 62 | extern bool __stdcall ini_new_section(const char *value, const char *path); 63 | extern bool __stdcall inicache_new_section(const char *value, ini_cache *ini); 64 | extern bool __stdcall ini_delete_section(const char *sec, const char *path); 65 | extern bool __stdcall inicache_delete_section(const char *sec, ini_cache *ini); 66 | extern bool __stdcall ini_search_string(const char *key, char **buf, const char *path, const bool isfile); 67 | extern bool __stdcall inicache_search_string(const char *key, char **buf, ini_cache *ini); 68 | extern int __stdcall inicache_read_int(const char *sec, const char *key, ini_cache *ini); 69 | extern int __stdcall ini_read_int(const char *sec, const char *key, const char *path, const bool isfile); 70 | extern bool __stdcall inicache_sort_section(const char *sec, ini_cache *ini); 71 | extern bool __stdcall ini_sort_section(const char *sec, const char *path); 72 | extern void __stdcall inicache_foreach_section(char (*lpdata)[LEN_SECTION], const int line, ini_cache *ini); 73 | extern void __stdcall ini_foreach_section(char (*lpdata)[LEN_SECTION], const int line, const char *path, const bool isfile); 74 | extern char* __stdcall ini_utf16_utf8(const wchar_t *utf16, size_t *out_len); 75 | extern char* __stdcall ini_utf16_mbcs(int codepage, const wchar_t *utf16, size_t *out_len); 76 | extern wchar_t* __stdcall ini_mbcs_utf16(int codepage, const char *ansi, size_t *out_len); 77 | extern char* __stdcall ini_mbcs_utf8(int codepage, const char *ansi, size_t *out_len); 78 | extern wchar_t* __stdcall ini_utf8_utf16(const char *utf8, size_t *out_len); 79 | extern char* __stdcall ini_utf8_mbcs(int codepage, const char *utf8, size_t *out_len); 80 | extern uint64_t __stdcall inicache_read_uint64(const char *sec, const char *key, ini_cache *ini); 81 | extern uint64_t __stdcall ini_read_uint64(const char *sec, const char *key, const char *path, const bool isfile); 82 | extern ini_cache __stdcall iniparser_create_cache(const char *ini, const int access_or_size, const bool isfile); 83 | extern void __stdcall iniparser_destroy_cache(ini_cache *li); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /* _INI_PARSER_H */ 90 | -------------------------------------------------------------------------------- /src/inject.c: -------------------------------------------------------------------------------- 1 | #ifdef DISABLE_SAFE 2 | #error This file should not be compiled! 3 | #endif 4 | 5 | #include "general.h" 6 | #include "winapis.h" 7 | 8 | #ifdef _MSC_VER 9 | #define MOZ_NOINLINE __declspec(noinline) 10 | #elif defined(__GNUC__) 11 | #define MOZ_NOINLINE __attribute__((noinline)) 12 | #else 13 | #define MOZ_NOINLINE 14 | #endif 15 | 16 | typedef struct _thread_data 17 | { 18 | WCHAR strDll[VALUE_LEN+1]; 19 | uintptr_t dwFuncAddr; 20 | uintptr_t dwRtlInitStr; 21 | } thread_data; 22 | 23 | typedef struct _thread_info 24 | { 25 | LPVOID data_buff; 26 | LPVOID func_buff; 27 | LPVOID code_buff; 28 | size_t data_size; 29 | size_t func_size; 30 | size_t code_size; 31 | } thread_info; 32 | 33 | #if defined(_MSC_VER) && !defined(__clang__) 34 | #pragma check_stack (off) 35 | #endif 36 | 37 | #if defined(_WIN64) 38 | unsigned char shell_code[] = 39 | { 40 | /* Push a dummy value for the return address */ 41 | 0x50, // push rax 42 | 0x9c, // pushfq 43 | 0x50, // push rax 44 | /* rax is saved, now overwrite the return address we pushed earlier */ 45 | 0x48, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // mov rax, 0CCCCCCCCCCCCCCCCh 46 | 0x48, 0x89, 0x84, 0x24, 0x10, 0x00, 0x00, 0x00, // mov qword ptr [rsp+16],rax 47 | 0x51, // push rcx 48 | 0x52, // push rdx 49 | 0x53, // push rbx 50 | 0x55, // push rbp 51 | 0x56, // push rsi 52 | 0x57, // push rdi 53 | 0x41, 0x50, // push r8 54 | 0x41, 0x51, // push r9 55 | 0x41, 0x52, // push r10 56 | 0x41, 0x53, // push r11 57 | 0x41, 0x54, // push r12 58 | 0x41, 0x55, // push r13 59 | 0x41, 0x56, // push r14 60 | 0x41, 0x57, // push r15 61 | 0x48, 0xB9, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // mov rcx, 0CCCCCCCCCCCCCCCCh 62 | 0x48, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // mov rax, 0CCCCCCCCCCCCCCCCh 63 | 0xFF, 0xD0, // call rax 64 | /* Restore the registers */ 65 | 0x41, 0x5F, // pop r15 66 | 0x41, 0x5E, // pop r14 67 | 0x41, 0x5D, // pop r13 68 | 0x41, 0x5C, // pop r12 69 | 0x41, 0x5B, // pop r11 70 | 0x41, 0x5A, // pop r10 71 | 0x41, 0x59, // pop r9 72 | 0x41, 0x58, // pop r8 73 | 0x5F, // pop rdi 74 | 0x5E, // pop rsi 75 | 0x5D, // pop rbp 76 | 0x5B, // pop rbx 77 | 0x5A, // pop rdx 78 | 0x59, // pop rcx 79 | 0x58, // pop rax 80 | /* Restore the flags */ 81 | 0x9D, // popfq 82 | 0xC3 // ret 83 | }; 84 | #elif defined(_M_IX86) || (defined __i386__) 85 | unsigned char shell_code[] = 86 | { 87 | 0x68, 0xef, 0xbe, 0xad, 0xde, // push 0xDEADBEEF 88 | 0x9c, // pushfd 89 | 0x60, // pushad 90 | 0x68, 0xef, 0xbe, 0xad, 0xde, // push 0xDEADBEEF 91 | 0xb8, 0xef, 0xbe, 0xad, 0xde, // mov eax, 0xDEADBEEF 92 | 0xff, 0xd0, // call eax 93 | 0x61, // popad 94 | 0x9d, // popfd 95 | 0xc3 // ret 96 | }; 97 | #else 98 | #error Unsupported compiler. 99 | #endif 100 | 101 | static void WINAPI 102 | ThreadProc(thread_data* pt) 103 | { 104 | typedef NTSTATUS (NTAPI *LdrLoadDllPtr) 105 | ( 106 | PWCHAR PathToFile, 107 | PULONG Flags, 108 | PUNICODE_STRING ModuleFileName, 109 | PHANDLE ModuleHandle 110 | ); 111 | typedef VOID (WINAPI *RtlInitStrPtr) 112 | ( 113 | PUNICODE_STRING DestinationString, 114 | PCWSTR SourceString 115 | ); 116 | UNICODE_STRING usDllName; 117 | HANDLE DllHandle; 118 | LdrLoadDllPtr pfnLdrLoadDll = (LdrLoadDllPtr)pt->dwFuncAddr; 119 | RtlInitStrPtr pfnRtlInitStr = (RtlInitStrPtr)pt->dwRtlInitStr; 120 | pfnRtlInitStr(&usDllName, pt->strDll); 121 | pfnLdrLoadDll(NULL, NULL, &usDllName, &DllHandle); 122 | } 123 | 124 | MOZ_NOINLINE 125 | static void WINAPI 126 | AfterThreadProc (void) 127 | { 128 | __nop(); 129 | __nop(); 130 | __nop(); 131 | __nop(); 132 | } 133 | 134 | #if defined(_MSC_VER) && !defined(__clang__) 135 | #pragma check_stack 136 | #endif 137 | 138 | static bool 139 | init_data(thread_data *pt) 140 | { 141 | bool res = false; 142 | WCHAR dll_name[VALUE_LEN+1]; 143 | HMODULE nt_handle = GetModuleHandleW(L"ntdll.dll"); 144 | if (NULL == nt_handle) 145 | { 146 | return res; 147 | } 148 | fzero(pt, sizeof(thread_data)); 149 | pt->dwFuncAddr = (uintptr_t)GetProcAddress(nt_handle, "LdrLoadDll"); 150 | pt->dwRtlInitStr = (uintptr_t)GetProcAddress(nt_handle, "RtlInitUnicodeString"); 151 | if (pt->dwFuncAddr && pt->dwRtlInitStr && GetModuleFileNameW(dll_module,dll_name,VALUE_LEN) >0) 152 | { 153 | wcsncpy(pt->strDll,dll_name,VALUE_LEN); 154 | res = true; 155 | } 156 | return res; 157 | } 158 | 159 | static bool 160 | write_memory(HANDLE handle, LPVOID base, LPCVOID buffer, size_t size) 161 | { 162 | DWORD flags = 0; 163 | do 164 | { 165 | if (!WriteProcessMemory(handle, base, buffer, size, NULL)) 166 | { 167 | #ifdef _LOGDEBUG 168 | logmsg("%s_WriteProcessMemory error:[%lu]\n", __FUNCTION__, GetLastError()); 169 | #endif 170 | break; 171 | } 172 | if (!VirtualProtectEx(handle, base, size, PAGE_EXECUTE_READ, &flags)) 173 | { 174 | #ifdef _LOGDEBUG 175 | logmsg("%s_VirtualProtectExy error:[%lu]\n", __FUNCTION__, GetLastError()); 176 | #endif 177 | break; 178 | } 179 | }while (0); 180 | return (flags != 0); 181 | } 182 | 183 | static void 184 | install_jmp(CONTEXT *pc, thread_info *pinfo) 185 | { 186 | #if defined(_WIN64) 187 | /* 替换shellcode跳转地址 */ 188 | uintptr_t old_ip = pc->Rip; 189 | memcpy(shell_code + 5, &old_ip, sizeof(old_ip)); 190 | *(uintptr_t*)((uintptr_t)shell_code + 45) = (uintptr_t)pinfo->code_buff+pinfo->code_size; 191 | *(uintptr_t*)((uintptr_t)shell_code + 55) = (uintptr_t)pinfo->code_buff+pinfo->code_size+pinfo->data_size; 192 | /* 栈指针下移,因为怕覆盖某些代码,被调用函数恢复栈平衡 */ 193 | pc->Rsp -= 128; 194 | /* 确保栈16位右对齐 用于LdrLoadDll调用 */ 195 | pc->Rsp = pc->Rsp & ~15; 196 | pc->Rsp -= 8; 197 | pc->Rip = (uintptr_t)pinfo->code_buff; 198 | #else 199 | *(uintptr_t*)((uintptr_t)shell_code + 1) = pc->Eip; 200 | *(uintptr_t*)((uintptr_t)shell_code + 8) = (uintptr_t)pinfo->code_buff+pinfo->code_size; 201 | *(uintptr_t*)((uintptr_t)shell_code + 13) = (uintptr_t)pinfo->code_buff+pinfo->code_size+pinfo->data_size; 202 | pc->Eip = (uintptr_t)pinfo->code_buff; 203 | #endif 204 | } 205 | 206 | unsigned WINAPI 207 | InjectDll(void *process) 208 | { 209 | thread_data dt; 210 | CONTEXT ctx; 211 | thread_info df = {0}; 212 | PROCESS_INFORMATION pi = *(LPPROCESS_INFORMATION)process; 213 | size_t t_size = 0; 214 | 215 | df.data_size = sizeof(thread_data); 216 | df.code_size = sizeof(shell_code); 217 | df.func_size = ((LPBYTE)&AfterThreadProc - (LPBYTE)&ThreadProc + 0x0F) & ~0x0F; 218 | /* 有可能会被编译器优化掉 */ 219 | if (df.func_size < 1 || df.func_size > 16384) 220 | { 221 | #ifdef _LOGDEBUG 222 | logmsg("size error , func_size = %lu\n",df.func_size); 223 | #endif 224 | /* 我们并不需要获取函数精确的尺寸,不小于函数体就行 */ 225 | df.func_size = VALUE_LEN; 226 | } 227 | t_size = df.data_size + df.code_size + df.func_size; 228 | do 229 | { 230 | if (SuspendThread(pi.hThread) == (uint32_t)-1) 231 | { 232 | #ifdef _LOGDEBUG 233 | logmsg("SuspendThread error:[%lu]\n", GetLastError()); 234 | #endif 235 | break; 236 | } 237 | ctx.ContextFlags = CONTEXT_CONTROL; 238 | if(!GetThreadContext(pi.hThread, &ctx)) 239 | { 240 | #ifdef _LOGDEBUG 241 | logmsg("GetThreadContext(ctx) error:[%lu]\n", GetLastError()); 242 | #endif 243 | break; 244 | } 245 | if (!init_data(&dt)) 246 | { 247 | #ifdef _LOGDEBUG 248 | logmsg("init_data false\n"); 249 | #endif 250 | break; 251 | } 252 | if ((df.code_buff = VirtualAllocEx(pi.hProcess, 0, t_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)) == NULL) 253 | { 254 | #ifdef _LOGDEBUG 255 | logmsg("VirtualAllocEx error:[%lu]\n", GetLastError()); 256 | #endif 257 | break; 258 | } 259 | if (!write_memory(pi.hProcess, (uint8_t *)df.code_buff+df.code_size, &dt, df.data_size)) 260 | { 261 | break; 262 | } 263 | if (!write_memory(pi.hProcess, (uint8_t *)df.code_buff+df.code_size+df.data_size, ThreadProc, df.func_size)) 264 | { 265 | break; 266 | } 267 | install_jmp(&ctx, &df); 268 | if (!write_memory(pi.hProcess, df.code_buff, shell_code, df.code_size)) 269 | { 270 | break; 271 | } 272 | if (!SetThreadContext(pi.hThread, &ctx)) 273 | { 274 | #ifdef _LOGDEBUG 275 | logmsg("SetThreadContext(ctx) error:[%lu]\n", GetLastError()); 276 | #endif 277 | } 278 | }while (0); 279 | if(df.code_buff && t_size) 280 | { 281 | VirtualFreeEx(pi.hProcess, df.code_buff, t_size, MEM_RELEASE); 282 | } 283 | return ResumeThread(pi.hThread); 284 | } -------------------------------------------------------------------------------- /src/inject.h: -------------------------------------------------------------------------------- 1 | #ifndef _IN_JECT_H 2 | #define _IN_JECT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern unsigned __stdcall InjectDll(void *mpara); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif /* _IN_JECT_H */ 15 | -------------------------------------------------------------------------------- /src/json_paser.h: -------------------------------------------------------------------------------- 1 | #ifndef _FILE_PASER_H_ 2 | # define _FILE_PASER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern bool __stdcall json_parser(void *json, const WCHAR *profile_dir, const char *app_dir); 9 | extern void* __stdcall json_lookup(const WCHAR *file, const char *path); 10 | extern unsigned __stdcall fn_update(void *lparam); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif /* end _FILE_PASER_H_ */ -------------------------------------------------------------------------------- /src/minhook/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MinHook - The Minimalistic API Hooking Library for x64/x86 2 | Copyright (C) 2009-2014 Tsuda Kageyu. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 18 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ================================================================================ 28 | Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov. 29 | ================================================================================ 30 | Hacker Disassembler Engine 32 C 31 | Copyright (c) 2008-2009, Vyacheslav Patkov. 32 | All rights reserved. 33 | 34 | Redistribution and use in source and binary forms, with or without 35 | modification, are permitted provided that the following conditions 36 | are met: 37 | 38 | 1. Redistributions of source code must retain the above copyright 39 | notice, this list of conditions and the following disclaimer. 40 | 2. Redistributions in binary form must reproduce the above copyright 41 | notice, this list of conditions and the following disclaimer in the 42 | documentation and/or other materials provided with the distribution. 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 45 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 48 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 49 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 50 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 51 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 52 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 53 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 54 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 | 56 | ------------------------------------------------------------------------------- 57 | Hacker Disassembler Engine 64 C 58 | Copyright (c) 2008-2009, Vyacheslav Patkov. 59 | All rights reserved. 60 | 61 | Redistribution and use in source and binary forms, with or without 62 | modification, are permitted provided that the following conditions 63 | are met: 64 | 65 | 1. Redistributions of source code must retain the above copyright 66 | notice, this list of conditions and the following disclaimer. 67 | 2. Redistributions in binary form must reproduce the above copyright 68 | notice, this list of conditions and the following disclaimer in the 69 | documentation and/or other materials provided with the distribution. 70 | 71 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 72 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 73 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 74 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 75 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 76 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 77 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 78 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 79 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 80 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 81 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 | -------------------------------------------------------------------------------- /src/minhook/Makefile: -------------------------------------------------------------------------------- 1 | CC := $(CROSS_COMPILING)gcc 2 | CFLAGS = -O2 3 | DFLAGS ?= 4 | LD = $(CC) -o 5 | AR = ar 6 | LDFLAGS = -Wl,-s 7 | CFLAGS += $(DFLAGS) -Wall -Wno-unused -Wno-format -DNDEBUG \ 8 | -finline-functions -DWINVER=0x0501 -D_WIN32_IE=0x0601 -mavx 9 | LTO ?= 10 | OUT = libminhook$(BITS).a 11 | USE_GCC = 12 | 13 | ifeq ($(findstring clang,$(CC)),) 14 | BUILD = $(shell file `which $(CC)` 2>/dev/null | grep x86-64) 15 | USE_GCC = 1 16 | else 17 | AR = llvm-ar.exe 18 | BUILD = $(shell file `which $(CC)` 2>/dev/null | grep x86-64) 19 | endif 20 | 21 | ifneq ($(CROSS_COMPILING),) 22 | ifneq ($(BITS),32) 23 | BITS ?= 64 24 | endif 25 | else 26 | ifeq ($(BUILD),) 27 | BITS ?= 32 28 | else 29 | BITS ?= 64 30 | endif 31 | endif 32 | 33 | ifeq ($(findstring clang,$(CC)),clang) 34 | CFLAGS += -Wno-ignored-attributes -Wno-unknown-attributes -Wno-deprecated-declarations 35 | ifneq (,$(filter $(DFLAGS),--target=x86_64-pc-windows --target=x86_64-pc-windows-msvc --target=i686-pc-windows --target=i686-pc-windows-msvc)) 36 | CFLAGS += -D_CRT_SECURE_NO_WARNINGS -DVC12_CRT 37 | OUT = minhook$(BITS).lib 38 | endif #target x86_64 or i686 39 | ifneq (,$(findstring i686,$(DFLAGS))) 40 | BITS = 32 41 | else 42 | BITS = 64 43 | endif 44 | endif # clang 45 | 46 | MD = mkdir -p 47 | SRC = src 48 | DEP = ../../.dep 49 | X86FLAG = -m32 -march=i686 50 | X64FLAG = -m64 51 | MIN_INC = include 52 | OBJECTS = $(DEP)/buffer.o $(DEP)/hde$(BITS).o $(DEP)/hook.o $(DEP)/trampoline.o 53 | DISTDIR = ../../Release 54 | CFLAGS += -I$(MIN_INC) -I$(SRC) 55 | 56 | EXEC = \ 57 | @echo coming to minhook subdir... \ 58 | $(shell $(MD) $(DISTDIR) 2>/dev/null) \ 59 | $(shell $(MD) $(DEP) 2>/dev/null) \ 60 | 61 | ifeq ($(BITS),32) 62 | CFLAGS += $(X86FLAG) 63 | LDFLAGS += $(X86FLAG) 64 | else ifeq ($(BITS),64) 65 | CFLAGS += $(X64FLAG) 66 | LDFLAGS += $(X64FLAG) 67 | endif 68 | 69 | ifeq ($(USE_GCC),1) 70 | ifeq ($(LTO), 1) 71 | AR := $(filter-out ar,$(AR )) gcc-ar 72 | CFLAGS := $(filter-out -O2,$(CFLAGS)) -D__LTO__ -Os -flto 73 | endif 74 | endif 75 | 76 | $(DISTDIR)/$(OUT) : $(OBJECTS) 77 | $(AR) rcs $@ $^ 78 | $(DEP)/buffer.o : $(SRC)/buffer.c $(SRC)/buffer.h 79 | $(call EXEC) 80 | $(CC) -c $< $(CFLAGS) -o $@ 81 | $(DEP)/hde$(BITS).o : $(SRC)/hde/hde$(BITS).c $(SRC)/hde/hde$(BITS).h 82 | $(CC) -c $< $(CFLAGS) -o $@ 83 | $(DEP)/hook.o : $(SRC)/hook.c $(MIN_INC)/MinHook.h 84 | $(CC) -c $< $(CFLAGS) -o $@ 85 | $(DEP)/trampoline.o : $(SRC)/trampoline.c $(SRC)/trampoline.h 86 | $(CC) -c $< $(CFLAGS) -o $@ 87 | 88 | .PHONY : clean 89 | clean : 90 | -rm -rf $(DISTDIR) $(DEP) 91 | 92 | -------------------------------------------------------------------------------- /src/minhook/Makefile.msvc: -------------------------------------------------------------------------------- 1 | # nmake -f Makefile.msvc 2 | CC = $(CC).exe 3 | CXX = $(CXX).exe 4 | CFLAGS = /nologo /W3 /WX- /TC /fp:precise /D "_LIB" /D "_UNICODE" /D "UNICODE" /D "_CRT_SECURE_NO_WARNINGS" 5 | LIBFLAGS = /NOLOGO 6 | 7 | !if "$(CC)"=="clang-cl.exe" 8 | AR = llvm-lib.exe 9 | !elseif "$(CC)"=="cl.exe" 10 | AR = lib.exe 11 | !else 12 | !ERROR Unsupported platforms! 13 | !endif 14 | 15 | !if "$(APP_DEBUG)"=="1" 16 | CFLAGS = $(CFLAGS) /O2 /Zi /Fd$(DISTDIR)\minhook$(BITS).pdb /D "DEBUG" /D "_LOGDEBUG" 17 | LDFLAGS = $(LDFLAGS) /DEBUG 18 | !elseif "$(CC)"=="cl.exe" 19 | CFLAGS = $(CFLAGS) /O2 /GL /Gd /D "NDEBUG" 20 | LIBFLAGS = $(LIBFLAGS) /LTCG 21 | !else 22 | CFLAGS = $(CFLAGS) /O2 /D "NDEBUG" -flto=thin 23 | LIBFLAGS = $(LIBFLAGS) /llvmlibthin 24 | !endif 25 | 26 | !if "$(LIBPORTABLE_STATIC)"=="1" 27 | CFLAGS = $(CFLAGS) /D "LIBPORTABLE_STATIC" 28 | !else 29 | CFLAGS = $(CFLAGS) /D "LIBPORTABLE_EXPORTS" 30 | !endif 31 | 32 | !if "$(TCMALLOC)"=="1" 33 | CFLAGS = $(CFLAGS) /MT /utf-8 /D "USE_UTF8" /D "VC12_CRT" /D "ENABLE_TCMALLOC" /D "_NO_CRT_STDIO_INLINE" 34 | !elseif "$(MSVC_CRT)"=="1" 35 | CFLAGS = $(CFLAGS) /MD /GS- /GR- 36 | !else 37 | CFLAGS = $(CFLAGS) /MD /GS- /GR- /utf-8 /D "USE_UTF8" /D "VC12_CRT" 38 | !endif 39 | 40 | !if "$(PLATFORM)"=="X64" || "$(TARGET_CPU)"=="x64" || "$(VSCMD_ARG_HOST_ARCH)"=="x64" 41 | PLATFORM = x64 42 | BITS = 64 43 | CFLAGS = $(CFLAGS) /D "WIN64" /D "_WIN64" 44 | !else 45 | PLATFORM = x86 46 | BITS = 32 47 | CFLAGS = $(CFLAGS) /D "WIN32" /D "_WIN32" 48 | !if "$(CC)"=="clang-cl.exe" 49 | CFLAGS = $(CFLAGS) --target=i686-pc-windows-msvc 50 | !endif 51 | !endif 52 | 53 | MD = @mkdir 54 | CP = copy 55 | RM = @del /q 56 | RMDIR = @rmdir /s /q 57 | SRC = src 58 | MIN_INC = include 59 | DEP = ..\..\.dep 60 | 61 | OBJECTS = $(DEP)\buffer.obj $(DEP)\hde$(BITS).obj $(DEP)\hook.obj $(DEP)\trampoline.obj 62 | CFLAGS = $(CFLAGS) /I$(MIN_INC) 63 | DISTDIR = ..\..\Release 64 | OUT = minhook$(BITS).lib 65 | EXEC = \ 66 | @echo coming to minhook subdir... &&\ 67 | @if not exist $(DISTDIR) $(MD) $(DISTDIR) 2>NUL 1>NUL &&\ 68 | @if not exist $(DEP) $(MD) $(DEP) 2>NUL 1>NUL 69 | 70 | $(DISTDIR)\$(OUT) : $(OBJECTS) 71 | $(AR) $(LIBFLAGS) $(OBJECTS) /OUT:$@ 72 | $(DEP)\buffer.obj : $(SRC)\buffer.c $(SRC)\buffer.h 73 | $(EXEC) 74 | $(CC) $(CFLAGS) /c $(SRC)\buffer.c /Fo$@ 75 | $(DEP)\hde$(BITS).obj : $(SRC)\hde\hde$(BITS).c $(SRC)\hde\hde$(BITS).h 76 | $(CC) $(CFLAGS) /c $(SRC)\hde\hde$(BITS).c /Fo$@ 77 | $(DEP)\hook.obj : $(SRC)\hook.c $(MIN_INC)\MinHook.h 78 | $(CC) $(CFLAGS) /c $(SRC)\hook.c /Fo$@ 79 | $(DEP)\trampoline.obj : $(SRC)\trampoline.c $(SRC)\trampoline.h 80 | $(CC) $(CFLAGS) /c $(SRC)\trampoline.c /Fo$@ 81 | 82 | .PHONY : clean 83 | clean : 84 | -$(RMDIR) $(DISTDIR) $(DEP) 2>NUL 1>NUL 85 | 86 | -------------------------------------------------------------------------------- /src/minhook/README.md: -------------------------------------------------------------------------------- 1 | # MinHook 2 | 3 | The Minimalistic x86/x64 API Hooking Library for Windows 4 | 5 | https://github.com/TsudaKageyu/minhook 6 | 7 | ### Version history 8 | - ####v1.3.2 - 1 Nov 2015 9 | 10 | * Fixed some small bugs. 11 | 12 | - ####v1.3-beta3 - 31 Jul 2014 13 | 14 | * Fixed some small bugs. 15 | * Improved the memory management. 16 | 17 | - ####v1.3-beta2 - 21 Jul 2014 18 | 19 | * Changed the parameters to Windows-friendly types. (void* to LPVOID) 20 | * Fixed some small bugs. 21 | * Reorganized the source files. 22 | * Reduced the footprint a little more. 23 | 24 | - ####v1.3-beta - 17 Jul 2014 25 | 26 | * Rewrote in plain C to reduce the footprint and memory usage. (suggested by Andrey Unis) 27 | * Simplified the overall code base to make it more readable and maintainable. 28 | * Changed the license from 3-clause to 2-clause BSD License. 29 | 30 | - ####v1.2 - 28 Sep 2013 31 | 32 | * Removed boost dependency ([jarredholman](https://github.com/jarredholman/minhook)). 33 | * Fixed a small bug in the GetRelativeBranchDestination function ([pillbug99](http://www.codeproject.com/Messages/4058892/Small-Bug-Found.aspx)). 34 | * Added the ```MH_RemoveHook``` function, which removes a hook created with the ```MH_CreateHook``` function. 35 | * Added the following functions to enable or disable multiple hooks in one go: ```MH_QueueEnableHook```, ```MH_QueueDisableHook```, ```MH_ApplyQueued```. This is the preferred way of handling multiple hooks as every call to `MH_EnableHook` or `MH_DisableHook` suspends and resumes all threads. 36 | * Made the functions ```MH_EnableHook``` and ```MH_DisableHook``` enable/disable all created hooks when the ```MH_ALL_HOOKS``` parameter is passed. This, too, is an efficient way of handling multiple hooks. 37 | * If the target function is too small to be patched with a jump, MinHook tries to place the jump above the function. If that fails as well, the ```MH_CreateHook``` function returns ```MH_ERROR_UNSUPPORTED_FUNCTION```. This fixes an issue of hooking the LoadLibraryExW function on Windows 7 x64 ([reported by Obble](http://www.codeproject.com/Messages/4578613/Re-Bug-LoadLibraryExW-hook-fails-on-windows-2008-r.aspx)). 38 | 39 | - ####v1.1 - 26 Nov 2009 40 | 41 | * Changed the interface to create a hook and a trampoline function in one go to prevent the detour function from being called before the trampoline function is created. ([reported by xliqz](http://www.codeproject.com/Messages/3280374/Unsafe.aspx)) 42 | * Shortened the function names from ```MinHook_*``` to ```MH_*``` to make them handier. 43 | 44 | - ####v1.0 - 22 Nov 2009 45 | 46 | * Initial release. 47 | -------------------------------------------------------------------------------- /src/minhook/include/MinHook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2014 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _MIN_HOOK_H_ 30 | # define _MIN_HOOK_H_ 31 | 32 | #ifndef WINVER /* Define WINVER to fix building on MinGW */ 33 | # define WINVER 0x0501 34 | #endif 35 | 36 | #include 37 | 38 | #if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) 39 | #error MinHook supports only x86 and x64 systems. 40 | #endif 41 | 42 | // MinHook Error Codes. 43 | typedef enum MH_STATUS 44 | { 45 | // Unknown error. Should not be returned. 46 | MH_UNKNOWN = -1, 47 | 48 | // Successful. 49 | MH_OK = 0, 50 | 51 | // MinHook is already initialized. 52 | MH_ERROR_ALREADY_INITIALIZED, 53 | 54 | // MinHook is not initialized yet, or already uninitialized. 55 | MH_ERROR_NOT_INITIALIZED, 56 | 57 | // The hook for the specified target function is already created. 58 | MH_ERROR_ALREADY_CREATED, 59 | 60 | // The hook for the specified target function is not created yet. 61 | MH_ERROR_NOT_CREATED, 62 | 63 | // The hook for the specified target function is already enabled. 64 | MH_ERROR_ENABLED, 65 | 66 | // The hook for the specified target function is not enabled yet, or already 67 | // disabled. 68 | MH_ERROR_DISABLED, 69 | 70 | // The specified pointer is invalid. It points the address of non-allocated 71 | // and/or non-executable region. 72 | MH_ERROR_NOT_EXECUTABLE, 73 | 74 | // The specified target function cannot be hooked. 75 | MH_ERROR_UNSUPPORTED_FUNCTION, 76 | 77 | // Failed to allocate memory. 78 | MH_ERROR_MEMORY_ALLOC, 79 | 80 | // Failed to change the memory protection. 81 | MH_ERROR_MEMORY_PROTECT 82 | } MH_STATUS; 83 | 84 | // Thread access rights for suspending/resuming threads. 85 | #define THREAD_ACCESS \ 86 | (THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION | THREAD_SET_CONTEXT) 87 | 88 | // Suspended threads for Freeze()/Unfreeze(). 89 | typedef struct _FROZEN_THREADS 90 | { 91 | LPDWORD pItems; // Data heap 92 | UINT capacity; // Size of allocated data heap, items 93 | UINT size; // Actual number of data items 94 | } FROZEN_THREADS, *PFROZEN_THREADS; 95 | 96 | // Can be passed as a parameter to MH_EnableHook, MH_DisableHook, 97 | // MH_QueueEnableHook or MH_QueueDisableHook. 98 | #define MH_ALL_HOOKS NULL 99 | 100 | #ifdef __cplusplus 101 | extern "C" { 102 | #endif 103 | 104 | // Initialize the MinHook library. You must call this function EXACTLY ONCE 105 | // at the beginning of your program. 106 | extern MH_STATUS WINAPI MH_Initialize(VOID); 107 | 108 | // Uninitialize the MinHook library. You must call this function EXACTLY 109 | // ONCE at the end of your program. 110 | extern MH_STATUS WINAPI MH_Uninitialize(VOID); 111 | 112 | // Creates a Hook for the specified target function, in disabled state. 113 | // Parameters: 114 | // pTarget [in] A pointer to the target function, which will be 115 | // overridden by the detour function. 116 | // pDetour [in] A pointer to the detour function, which will override 117 | // the target function. 118 | // ppOriginal [out] A pointer to the trampoline function, which will be 119 | // used to call the original target function. 120 | // This parameter can be NULL. 121 | extern MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal); 122 | 123 | // Removes an already created hook. 124 | 125 | // Parameters: 126 | // pTarget [in] A pointer to the target function. 127 | extern MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); 128 | 129 | // Enables an already created hook. 130 | // Parameters: 131 | // pTarget [in] A pointer to the target function. 132 | // If this parameter is MH_ALL_HOOKS, all created hooks are 133 | // enabled in one go. 134 | extern MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); 135 | 136 | // Disables an already created hook. 137 | // Parameters: 138 | // pTarget [in] A pointer to the target function. 139 | // If this parameter is MH_ALL_HOOKS, all created hooks are 140 | // disabled in one go. 141 | extern MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); 142 | 143 | // Queues to enable an already created hook. 144 | // Parameters: 145 | // pTarget [in] A pointer to the target function. 146 | // If this parameter is MH_ALL_HOOKS, all created hooks are 147 | // queued to be enabled. 148 | extern MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); 149 | 150 | // Queues to disable an already created hook. 151 | // Parameters: 152 | // pTarget [in] A pointer to the target function. 153 | // If this parameter is MH_ALL_HOOKS, all created hooks are 154 | // queued to be disabled. 155 | extern MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); 156 | 157 | // Applies all queued changes in one go. 158 | extern MH_STATUS WINAPI MH_ApplyQueued(VOID); 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif 165 | -------------------------------------------------------------------------------- /src/minhook/include/intrin_c.h: -------------------------------------------------------------------------------- 1 | #ifndef __INTRIN_C_H_ 2 | #define __INTRIN_C_H_ 3 | 4 | /* do not have a C99 compiler */ 5 | #if (defined _MSC_VER && _MSC_VER < 1800 && !(defined __cplusplus)) ||\ 6 | (defined __GNUC__&& __STDC_VERSION__ < 199901L && __GNUC__ < 3) 7 | typedef unsigned char _Bool; 8 | # define bool _Bool 9 | # define true 1 10 | # define false 0 11 | # define __bool_true_false_are_defined 1 12 | #else 13 | # include 14 | #endif 15 | 16 | #if defined(__GNUC__) 17 | /*** Stack frame juggling ***/ 18 | #define _ReturnAddress() (__builtin_return_address(0)) 19 | #define _AddressOfReturnAddress() (&(((void **)(__builtin_frame_address(0)))[1])) 20 | #if defined(__AVX__) 21 | #include 22 | #if (!defined(__clang__) && __GNUC__ < 8) || (defined(__clang_major__) && (__clang_major__ < 9)) 23 | extern __inline__ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 24 | unsigned long long _xgetbv(unsigned int __xcr_no) 25 | { 26 | unsigned int __eax, __edx; 27 | __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no)); 28 | return ((unsigned long long)__edx << 32) | __eax; 29 | } 30 | #endif 31 | extern __inline__ __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 32 | void __nop(void) 33 | { 34 | __asm__ __volatile__("nop"); 35 | } 36 | #endif 37 | #endif 38 | 39 | #ifndef __INTRIN_H_ 40 | #define __INTRIN_H_ /* 不支持mingw64,它已经从windows.h引入 */ 41 | 42 | #if defined(_MSC_VER) && (_MSC_VER >= 1600) 43 | #include 44 | #pragma intrinsic(_InterlockedCompareExchange, _InterlockedExchange, \ 45 | __stosb, _ReturnAddress, strlen, wcslen, \ 46 | wcscmp, memcpy, memset) 47 | #elif defined(__GNUC__) 48 | #include "intrin_gcc.h" 49 | #else 50 | #error Unsupported compiler 51 | #endif 52 | 53 | #endif /* __INTRIN_H_ */ 54 | #endif /* __INTRIN_C_H_ */ 55 | -------------------------------------------------------------------------------- /src/minhook/include/intrin_gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Compatibility header for GCC -- GCC equivalents of intrinsic 3 | Microsoft Visual C++ functions. Originally developed for the ReactOS 4 | () and TinyKrnl () 5 | projects. 6 | 7 | Copyright (c) 2006 KJK::Hyperion 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a 10 | copy of this software and associated documentation files (the "Software"), 11 | to deal in the Software without restriction, including without limitation 12 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | and/or sell copies of the Software, and to permit persons to whom the 14 | Software is furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef KJK_INTRIN_GCC_H_ 29 | #define KJK_INTRIN_GCC_H_ 30 | 31 | #ifndef __GNUC__ 32 | #error Unsupported compiler 33 | #endif 34 | 35 | #endif 36 | 37 | /* EOF */ 38 | -------------------------------------------------------------------------------- /src/minhook/src/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2014 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include "buffer.h" 31 | 32 | // Size of each memory block. (= page size of VirtualAlloc) 33 | #define MEMORY_BLOCK_SIZE 0x1000 34 | 35 | // Max range for seeking a memory block. (= 1024MB) 36 | #define MAX_MEMORY_RANGE 0x40000000 37 | 38 | // Memory protection flags to check the executable address. 39 | #define PAGE_EXECUTE_FLAGS \ 40 | (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) 41 | 42 | // Memory slot. 43 | typedef struct _MEMORY_SLOT 44 | { 45 | union 46 | { 47 | struct _MEMORY_SLOT *pNext; 48 | UINT8 buffer[MEMORY_SLOT_SIZE]; 49 | }; 50 | } MEMORY_SLOT, *PMEMORY_SLOT; 51 | 52 | // Memory block info. Placed at the head of each block. 53 | typedef struct _MEMORY_BLOCK 54 | { 55 | struct _MEMORY_BLOCK *pNext; 56 | PMEMORY_SLOT pFree; // First element of the free slot list. 57 | UINT usedCount; 58 | } MEMORY_BLOCK, *PMEMORY_BLOCK; 59 | 60 | //------------------------------------------------------------------------- 61 | // Global Variables: 62 | //------------------------------------------------------------------------- 63 | 64 | // First element of the memory block list. 65 | PMEMORY_BLOCK g_pMemoryBlocks; 66 | 67 | //------------------------------------------------------------------------- 68 | VOID InitializeBuffer(VOID) 69 | { 70 | // Nothing to do for now. 71 | } 72 | 73 | //------------------------------------------------------------------------- 74 | VOID UninitializeBuffer(VOID) 75 | { 76 | PMEMORY_BLOCK pBlock = g_pMemoryBlocks; 77 | g_pMemoryBlocks = NULL; 78 | 79 | while (pBlock) 80 | { 81 | PMEMORY_BLOCK pNext = pBlock->pNext; 82 | VirtualFree(pBlock, 0, MEM_RELEASE); 83 | pBlock = pNext; 84 | } 85 | } 86 | 87 | //------------------------------------------------------------------------- 88 | #if defined(_M_X64) || defined(__x86_64__) 89 | static LPVOID FindPrevFreeRegion(LPVOID pAddress, LPVOID pMinAddr, DWORD dwAllocationGranularity) 90 | { 91 | ULONG_PTR tryAddr = (ULONG_PTR)pAddress; 92 | 93 | // Round down to the allocation granularity. 94 | tryAddr -= tryAddr % dwAllocationGranularity; 95 | 96 | // Start from the previous allocation granularity multiply. 97 | tryAddr -= dwAllocationGranularity; 98 | 99 | while (tryAddr >= (ULONG_PTR)pMinAddr) 100 | { 101 | MEMORY_BASIC_INFORMATION mbi; 102 | if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(mbi)) == 0) 103 | break; 104 | 105 | if (mbi.State == MEM_FREE) 106 | return (LPVOID)tryAddr; 107 | 108 | if ((ULONG_PTR)mbi.AllocationBase < dwAllocationGranularity) 109 | break; 110 | 111 | tryAddr = (ULONG_PTR)mbi.AllocationBase - dwAllocationGranularity; 112 | } 113 | 114 | return NULL; 115 | } 116 | #endif 117 | 118 | //------------------------------------------------------------------------- 119 | #if defined(_M_X64) || defined(__x86_64__) 120 | static LPVOID FindNextFreeRegion(LPVOID pAddress, LPVOID pMaxAddr, DWORD dwAllocationGranularity) 121 | { 122 | ULONG_PTR tryAddr = (ULONG_PTR)pAddress; 123 | 124 | // Round down to the allocation granularity. 125 | tryAddr -= tryAddr % dwAllocationGranularity; 126 | 127 | // Start from the next allocation granularity multiply. 128 | tryAddr += dwAllocationGranularity; 129 | 130 | while (tryAddr <= (ULONG_PTR)pMaxAddr) 131 | { 132 | MEMORY_BASIC_INFORMATION mbi; 133 | if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(mbi)) == 0) 134 | break; 135 | 136 | if (mbi.State == MEM_FREE) 137 | return (LPVOID)tryAddr; 138 | 139 | tryAddr = (ULONG_PTR)mbi.BaseAddress + mbi.RegionSize; 140 | 141 | // Round up to the next allocation granularity. 142 | tryAddr += dwAllocationGranularity - 1; 143 | tryAddr -= tryAddr % dwAllocationGranularity; 144 | } 145 | 146 | return NULL; 147 | } 148 | #endif 149 | //------------------------------------------------------------------------- 150 | static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin) 151 | { 152 | PMEMORY_BLOCK pBlock; 153 | #if defined(_M_X64) || defined(__x86_64__) 154 | ULONG_PTR minAddr; 155 | ULONG_PTR maxAddr; 156 | 157 | 158 | SYSTEM_INFO si; 159 | GetSystemInfo(&si); 160 | minAddr = (ULONG_PTR)si.lpMinimumApplicationAddress; 161 | maxAddr = (ULONG_PTR)si.lpMaximumApplicationAddress; 162 | 163 | 164 | // pOrigin ± 512MB 165 | if ((ULONG_PTR)pOrigin > MAX_MEMORY_RANGE && minAddr < (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE) 166 | minAddr = (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE; 167 | 168 | if (maxAddr > (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE) 169 | maxAddr = (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE; 170 | 171 | // Make room for MEMORY_BLOCK_SIZE bytes. 172 | maxAddr -= MEMORY_BLOCK_SIZE - 1; 173 | #endif 174 | 175 | 176 | // Look the registered blocks for a reachable one. 177 | for (pBlock = g_pMemoryBlocks; pBlock != NULL; pBlock = pBlock->pNext) 178 | { 179 | #if defined(_M_X64) || defined(__x86_64__) 180 | // Ignore the blocks too far. 181 | if ((ULONG_PTR)pBlock < minAddr || (ULONG_PTR)pBlock >= maxAddr) 182 | continue; 183 | #endif 184 | // The block has at least one unused slot. 185 | if (pBlock->pFree != NULL) 186 | return pBlock; 187 | } 188 | 189 | #if defined(_M_X64) || defined(__x86_64__) 190 | // Alloc a new block above if not found. 191 | { 192 | LPVOID pAlloc = pOrigin; 193 | while ((ULONG_PTR)pAlloc >= minAddr) 194 | { 195 | pAlloc = FindPrevFreeRegion(pAlloc, (LPVOID)minAddr, si.dwAllocationGranularity); 196 | if (pAlloc == NULL) 197 | break; 198 | 199 | pBlock = (PMEMORY_BLOCK)VirtualAlloc( 200 | pAlloc, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 201 | if (pBlock != NULL) 202 | break; 203 | } 204 | } 205 | 206 | // Alloc a new block below if not found. 207 | if (pBlock == NULL) 208 | { 209 | LPVOID pAlloc = pOrigin; 210 | while ((ULONG_PTR)pAlloc <= maxAddr) 211 | { 212 | pAlloc = FindNextFreeRegion(pAlloc, (LPVOID)maxAddr, si.dwAllocationGranularity); 213 | if (pAlloc == NULL) 214 | break; 215 | 216 | pBlock = (PMEMORY_BLOCK)VirtualAlloc( 217 | pAlloc, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 218 | if (pBlock != NULL) 219 | break; 220 | } 221 | } 222 | #else 223 | // In x86 mode, a memory block can be placed anywhere. 224 | pBlock = (PMEMORY_BLOCK)VirtualAlloc( 225 | NULL, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 226 | #endif 227 | 228 | if (pBlock != NULL) 229 | { 230 | // Build a linked list of all the slots. 231 | PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBlock + 1; 232 | pBlock->pFree = NULL; 233 | pBlock->usedCount = 0; 234 | do 235 | { 236 | pSlot->pNext = pBlock->pFree; 237 | pBlock->pFree = pSlot; 238 | pSlot++; 239 | } while ((ULONG_PTR)pSlot - (ULONG_PTR)pBlock <= MEMORY_BLOCK_SIZE - MEMORY_SLOT_SIZE); 240 | 241 | pBlock->pNext = g_pMemoryBlocks; 242 | g_pMemoryBlocks = pBlock; 243 | } 244 | 245 | return pBlock; 246 | } 247 | 248 | //------------------------------------------------------------------------- 249 | LPVOID AllocateBuffer(LPVOID pOrigin) 250 | { 251 | PMEMORY_SLOT pSlot; 252 | PMEMORY_BLOCK pBlock = GetMemoryBlock(pOrigin); 253 | if (pBlock == NULL) 254 | return NULL; 255 | 256 | // Remove an unused slot from the list. 257 | pSlot = pBlock->pFree; 258 | pBlock->pFree = pSlot->pNext; 259 | pBlock->usedCount++; 260 | #ifdef _DEBUG 261 | // Fill the slot with INT3 for debugging. 262 | memset(pSlot, 0xCC, sizeof(MEMORY_SLOT)); 263 | #endif 264 | return pSlot; 265 | } 266 | 267 | //------------------------------------------------------------------------- 268 | VOID FreeBuffer(LPVOID pBuffer) 269 | { 270 | PMEMORY_BLOCK pBlock = g_pMemoryBlocks; 271 | PMEMORY_BLOCK pPrev = NULL; 272 | ULONG_PTR pTargetBlock = ((ULONG_PTR)pBuffer / MEMORY_BLOCK_SIZE) * MEMORY_BLOCK_SIZE; 273 | 274 | while (pBlock != NULL) 275 | { 276 | if ((ULONG_PTR)pBlock == pTargetBlock) 277 | { 278 | PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBuffer; 279 | #ifdef _DEBUG 280 | // Clear the released slot for debugging. 281 | memset(pSlot, 0x00, sizeof(MEMORY_SLOT)); 282 | #endif 283 | // Restore the released slot to the list. 284 | pSlot->pNext = pBlock->pFree; 285 | pBlock->pFree = pSlot; 286 | pBlock->usedCount--; 287 | 288 | // Free if unused. 289 | if (pBlock->usedCount == 0) 290 | { 291 | if (pPrev) 292 | pPrev->pNext = pBlock->pNext; 293 | else 294 | g_pMemoryBlocks = pBlock->pNext; 295 | 296 | VirtualFree(pBlock, 0, MEM_RELEASE); 297 | } 298 | 299 | break; 300 | } 301 | 302 | pPrev = pBlock; 303 | pBlock = pBlock->pNext; 304 | } 305 | } 306 | 307 | //------------------------------------------------------------------------- 308 | BOOL IsExecutableAddress(LPVOID pAddress) 309 | { 310 | MEMORY_BASIC_INFORMATION mi; 311 | VirtualQuery(pAddress, &mi, sizeof(mi)); 312 | 313 | return (mi.State == MEM_COMMIT && (mi.Protect & PAGE_EXECUTE_FLAGS)); 314 | } 315 | -------------------------------------------------------------------------------- /src/minhook/src/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2014 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _MEM_BUFFER_H_ 30 | # define _MEM_BUFFER_H_ 31 | 32 | // Size of each memory slot. 33 | #if defined(_M_X64) || defined(__x86_64__) 34 | #define MEMORY_SLOT_SIZE 64 35 | #else 36 | #define MEMORY_SLOT_SIZE 32 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | VOID InitializeBuffer(VOID); 43 | VOID UninitializeBuffer(VOID); 44 | LPVOID AllocateBuffer(LPVOID pOrigin); 45 | VOID FreeBuffer(LPVOID pBuffer); 46 | BOOL IsExecutableAddress(LPVOID pAddress); 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/minhook/src/hde/hde32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | #include 8 | #include 9 | #include "hde32.h" 10 | #include "table32.h" 11 | #include "intrin_c.h" 12 | 13 | unsigned int hde32_disasm(const void *code, hde32s *hs) 14 | { 15 | uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0; 16 | uint8_t *ht = hde32_table, m_mod, m_reg, m_rm, disp_size = 0; 17 | 18 | memset(hs, 0, sizeof(hde32s)); 19 | 20 | for (x = 16; x; x--) 21 | switch (c = *p++) { 22 | case 0xf3: 23 | hs->p_rep = c; 24 | pref |= PRE_F3; 25 | break; 26 | case 0xf2: 27 | hs->p_rep = c; 28 | pref |= PRE_F2; 29 | break; 30 | case 0xf0: 31 | hs->p_lock = c; 32 | pref |= PRE_LOCK; 33 | break; 34 | case 0x26: case 0x2e: case 0x36: 35 | case 0x3e: case 0x64: case 0x65: 36 | hs->p_seg = c; 37 | pref |= PRE_SEG; 38 | break; 39 | case 0x66: 40 | hs->p_66 = c; 41 | pref |= PRE_66; 42 | break; 43 | case 0x67: 44 | hs->p_67 = c; 45 | pref |= PRE_67; 46 | break; 47 | default: 48 | goto pref_done; 49 | } 50 | pref_done: 51 | 52 | hs->flags = (uint32_t)pref << 23; 53 | 54 | if (!pref) 55 | pref |= PRE_NONE; 56 | 57 | if ((hs->opcode = c) == 0x0f) { 58 | hs->opcode2 = c = *p++; 59 | ht += DELTA_OPCODES; 60 | } else if (c >= 0xa0 && c <= 0xa3) { 61 | if (pref & PRE_67) 62 | pref |= PRE_66; 63 | else 64 | pref &= ~PRE_66; 65 | } 66 | 67 | opcode = c; 68 | cflags = ht[ht[opcode / 4] + (opcode % 4)]; 69 | 70 | if (cflags == C_ERROR) { 71 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 72 | cflags = 0; 73 | if ((opcode & -3) == 0x24) 74 | cflags++; 75 | } 76 | 77 | x = 0; 78 | if (cflags & C_GROUP) { 79 | uint16_t t; 80 | t = *(uint16_t *)(ht + (cflags & 0x7f)); 81 | cflags = (uint8_t)t; 82 | x = (uint8_t)(t >> 8); 83 | } 84 | 85 | if (hs->opcode2) { 86 | ht = hde32_table + DELTA_PREFIXES; 87 | if (ht[ht[opcode / 4] + (opcode % 4)] & pref) 88 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 89 | } 90 | 91 | if (cflags & C_MODRM) { 92 | hs->flags |= F_MODRM; 93 | hs->modrm = c = *p++; 94 | hs->modrm_mod = m_mod = c >> 6; 95 | hs->modrm_rm = m_rm = c & 7; 96 | hs->modrm_reg = m_reg = (c & 0x3f) >> 3; 97 | 98 | if (x && ((x << m_reg) & 0x80)) 99 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 100 | 101 | if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { 102 | uint8_t t = opcode - 0xd9; 103 | if (m_mod == 3) { 104 | ht = hde32_table + DELTA_FPU_MODRM + t*8; 105 | t = ht[m_reg] << m_rm; 106 | } else { 107 | ht = hde32_table + DELTA_FPU_REG; 108 | t = ht[t] << m_reg; 109 | } 110 | if (t & 0x80) 111 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 112 | } 113 | 114 | if (pref & PRE_LOCK) { 115 | if (m_mod == 3) { 116 | hs->flags |= F_ERROR | F_ERROR_LOCK; 117 | } else { 118 | uint8_t *table_end, op = opcode; 119 | if (hs->opcode2) { 120 | ht = hde32_table + DELTA_OP2_LOCK_OK; 121 | table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; 122 | } else { 123 | ht = hde32_table + DELTA_OP_LOCK_OK; 124 | table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; 125 | op &= -2; 126 | } 127 | for (; ht != table_end; ht++) 128 | if (*ht++ == op) { 129 | if (!((*ht << m_reg) & 0x80)) 130 | goto no_lock_error; 131 | else 132 | break; 133 | } 134 | hs->flags |= F_ERROR | F_ERROR_LOCK; 135 | no_lock_error: 136 | ; 137 | } 138 | } 139 | 140 | if (hs->opcode2) { 141 | switch (opcode) { 142 | case 0x20: case 0x22: 143 | m_mod = 3; 144 | if (m_reg > 4 || m_reg == 1) 145 | goto error_operand; 146 | else 147 | goto no_error_operand; 148 | case 0x21: case 0x23: 149 | m_mod = 3; 150 | if (m_reg == 4 || m_reg == 5) 151 | goto error_operand; 152 | else 153 | goto no_error_operand; 154 | } 155 | } else { 156 | switch (opcode) { 157 | case 0x8c: 158 | if (m_reg > 5) 159 | goto error_operand; 160 | else 161 | goto no_error_operand; 162 | case 0x8e: 163 | if (m_reg == 1 || m_reg > 5) 164 | goto error_operand; 165 | else 166 | goto no_error_operand; 167 | } 168 | } 169 | 170 | if (m_mod == 3) { 171 | uint8_t *table_end; 172 | if (hs->opcode2) { 173 | ht = hde32_table + DELTA_OP2_ONLY_MEM; 174 | table_end = ht + sizeof(hde32_table) - DELTA_OP2_ONLY_MEM; 175 | } else { 176 | ht = hde32_table + DELTA_OP_ONLY_MEM; 177 | table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; 178 | } 179 | for (; ht != table_end; ht += 2) 180 | if (*ht++ == opcode) { 181 | if ((*ht++ & pref) && !((*ht << m_reg) & 0x80)) 182 | goto error_operand; 183 | else 184 | break; 185 | } 186 | goto no_error_operand; 187 | } else if (hs->opcode2) { 188 | switch (opcode) { 189 | case 0x50: case 0xd7: case 0xf7: 190 | if (pref & (PRE_NONE | PRE_66)) 191 | goto error_operand; 192 | break; 193 | case 0xd6: 194 | if (pref & (PRE_F2 | PRE_F3)) 195 | goto error_operand; 196 | break; 197 | case 0xc5: 198 | goto error_operand; 199 | } 200 | goto no_error_operand; 201 | } else 202 | goto no_error_operand; 203 | 204 | error_operand: 205 | hs->flags |= F_ERROR | F_ERROR_OPERAND; 206 | no_error_operand: 207 | 208 | c = *p++; 209 | if (m_reg <= 1) { 210 | if (opcode == 0xf6) 211 | cflags |= C_IMM8; 212 | else if (opcode == 0xf7) 213 | cflags |= C_IMM_P66; 214 | } 215 | 216 | switch (m_mod) { 217 | case 0: 218 | if (pref & PRE_67) { 219 | if (m_rm == 6) 220 | disp_size = 2; 221 | } else 222 | if (m_rm == 5) 223 | disp_size = 4; 224 | break; 225 | case 1: 226 | disp_size = 1; 227 | break; 228 | case 2: 229 | disp_size = 2; 230 | if (!(pref & PRE_67)) 231 | disp_size <<= 1; 232 | break; 233 | } 234 | 235 | if (m_mod != 3 && m_rm == 4 && !(pref & PRE_67)) { 236 | hs->flags |= F_SIB; 237 | p++; 238 | hs->sib = c; 239 | hs->sib_scale = c >> 6; 240 | hs->sib_index = (c & 0x3f) >> 3; 241 | if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) 242 | disp_size = 4; 243 | } 244 | 245 | p--; 246 | switch (disp_size) { 247 | case 1: 248 | hs->flags |= F_DISP8; 249 | hs->disp.disp8 = *p; 250 | break; 251 | case 2: 252 | hs->flags |= F_DISP16; 253 | hs->disp.disp16 = *(uint16_t *)p; 254 | break; 255 | case 4: 256 | hs->flags |= F_DISP32; 257 | hs->disp.disp32 = *(uint32_t *)p; 258 | break; 259 | } 260 | p += disp_size; 261 | } else if (pref & PRE_LOCK) 262 | hs->flags |= F_ERROR | F_ERROR_LOCK; 263 | 264 | if (cflags & C_IMM_P66) { 265 | if (cflags & C_REL32) { 266 | if (pref & PRE_66) { 267 | hs->flags |= F_IMM16 | F_RELATIVE; 268 | hs->imm.imm16 = *(uint16_t *)p; 269 | p += 2; 270 | goto disasm_done; 271 | } 272 | goto rel32_ok; 273 | } 274 | if (pref & PRE_66) { 275 | hs->flags |= F_IMM16; 276 | hs->imm.imm16 = *(uint16_t *)p; 277 | p += 2; 278 | } else { 279 | hs->flags |= F_IMM32; 280 | hs->imm.imm32 = *(uint32_t *)p; 281 | p += 4; 282 | } 283 | } 284 | 285 | if (cflags & C_IMM16) { 286 | if (hs->flags & F_IMM32) { 287 | hs->flags |= F_IMM16; 288 | hs->disp.disp16 = *(uint16_t *)p; 289 | } else if (hs->flags & F_IMM16) { 290 | hs->flags |= F_2IMM16; 291 | hs->disp.disp16 = *(uint16_t *)p; 292 | } else { 293 | hs->flags |= F_IMM16; 294 | hs->imm.imm16 = *(uint16_t *)p; 295 | } 296 | p += 2; 297 | } 298 | if (cflags & C_IMM8) { 299 | hs->flags |= F_IMM8; 300 | hs->imm.imm8 = *p++; 301 | } 302 | 303 | if (cflags & C_REL32) { 304 | rel32_ok: 305 | hs->flags |= F_IMM32 | F_RELATIVE; 306 | hs->imm.imm32 = *(uint32_t *)p; 307 | p += 4; 308 | } else if (cflags & C_REL8) { 309 | hs->flags |= F_IMM8 | F_RELATIVE; 310 | hs->imm.imm8 = *p++; 311 | } 312 | 313 | disasm_done: 314 | 315 | if ((hs->len = (uint8_t)(p-(uint8_t *)code)) > 15) { 316 | hs->flags |= F_ERROR | F_ERROR_LENGTH; 317 | hs->len = 15; 318 | } 319 | 320 | return (unsigned int)hs->len; 321 | } 322 | -------------------------------------------------------------------------------- /src/minhook/src/hde/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 14 | #error Unsupported compiler 15 | #else 16 | #include 17 | #endif 18 | 19 | #define F_MODRM 0x00000001 20 | #define F_SIB 0x00000002 21 | #define F_IMM8 0x00000004 22 | #define F_IMM16 0x00000008 23 | #define F_IMM32 0x00000010 24 | #define F_DISP8 0x00000020 25 | #define F_DISP16 0x00000040 26 | #define F_DISP32 0x00000080 27 | #define F_RELATIVE 0x00000100 28 | #define F_2IMM16 0x00000800 29 | #define F_ERROR 0x00001000 30 | #define F_ERROR_OPCODE 0x00002000 31 | #define F_ERROR_LENGTH 0x00004000 32 | #define F_ERROR_LOCK 0x00008000 33 | #define F_ERROR_OPERAND 0x00010000 34 | #define F_PREFIX_REPNZ 0x01000000 35 | #define F_PREFIX_REPX 0x02000000 36 | #define F_PREFIX_REP 0x03000000 37 | #define F_PREFIX_66 0x04000000 38 | #define F_PREFIX_67 0x08000000 39 | #define F_PREFIX_LOCK 0x10000000 40 | #define F_PREFIX_SEG 0x20000000 41 | #define F_PREFIX_ANY 0x3f000000 42 | 43 | #define PREFIX_SEGMENT_CS 0x2e 44 | #define PREFIX_SEGMENT_SS 0x36 45 | #define PREFIX_SEGMENT_DS 0x3e 46 | #define PREFIX_SEGMENT_ES 0x26 47 | #define PREFIX_SEGMENT_FS 0x64 48 | #define PREFIX_SEGMENT_GS 0x65 49 | #define PREFIX_LOCK 0xf0 50 | #define PREFIX_REPNZ 0xf2 51 | #define PREFIX_REPX 0xf3 52 | #define PREFIX_OPERAND_SIZE 0x66 53 | #define PREFIX_ADDRESS_SIZE 0x67 54 | 55 | #pragma pack(push,1) 56 | 57 | typedef struct { 58 | uint8_t len; 59 | uint8_t p_rep; 60 | uint8_t p_lock; 61 | uint8_t p_seg; 62 | uint8_t p_66; 63 | uint8_t p_67; 64 | uint8_t opcode; 65 | uint8_t opcode2; 66 | uint8_t modrm; 67 | uint8_t modrm_mod; 68 | uint8_t modrm_reg; 69 | uint8_t modrm_rm; 70 | uint8_t sib; 71 | uint8_t sib_scale; 72 | uint8_t sib_index; 73 | uint8_t sib_base; 74 | union { 75 | uint8_t imm8; 76 | uint16_t imm16; 77 | uint32_t imm32; 78 | } imm; 79 | union { 80 | uint8_t disp8; 81 | uint16_t disp16; 82 | uint32_t disp32; 83 | } disp; 84 | uint32_t flags; 85 | } hde32s; 86 | 87 | #pragma pack(pop) 88 | 89 | #ifdef __cplusplus 90 | extern "C" { 91 | #endif 92 | 93 | /* __cdecl */ 94 | unsigned int hde32_disasm(const void *code, hde32s *hs); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif /* _HDE32_H_ */ 101 | -------------------------------------------------------------------------------- /src/minhook/src/hde/hde64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #include 9 | #include 10 | #include "hde64.h" 11 | #include "table64.h" 12 | #include "intrin_c.h" 13 | 14 | unsigned int hde64_disasm(const void *code, hde64s *hs) 15 | { 16 | uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0; 17 | uint8_t *ht = hde64_table, m_mod, m_reg, m_rm, disp_size = 0; 18 | uint8_t op64 = 0; 19 | 20 | memset(hs, 0, sizeof(hde64s)); 21 | 22 | for (x = 16; x; x--) 23 | switch (c = *p++) { 24 | case 0xf3: 25 | hs->p_rep = c; 26 | pref |= PRE_F3; 27 | break; 28 | case 0xf2: 29 | hs->p_rep = c; 30 | pref |= PRE_F2; 31 | break; 32 | case 0xf0: 33 | hs->p_lock = c; 34 | pref |= PRE_LOCK; 35 | break; 36 | case 0x26: case 0x2e: case 0x36: 37 | case 0x3e: case 0x64: case 0x65: 38 | hs->p_seg = c; 39 | pref |= PRE_SEG; 40 | break; 41 | case 0x66: 42 | hs->p_66 = c; 43 | pref |= PRE_66; 44 | break; 45 | case 0x67: 46 | hs->p_67 = c; 47 | pref |= PRE_67; 48 | break; 49 | default: 50 | goto pref_done; 51 | } 52 | pref_done: 53 | 54 | hs->flags = (uint32_t)pref << 23; 55 | 56 | if (!pref) 57 | pref |= PRE_NONE; 58 | 59 | if ((c & 0xf0) == 0x40) { 60 | hs->flags |= F_PREFIX_REX; 61 | if ((hs->rex_w = (c & 0xf) >> 3) && (*p & 0xf8) == 0xb8) 62 | op64++; 63 | hs->rex_r = (c & 7) >> 2; 64 | hs->rex_x = (c & 3) >> 1; 65 | hs->rex_b = c & 1; 66 | if (((c = *p++) & 0xf0) == 0x40) { 67 | opcode = c; 68 | goto error_opcode; 69 | } 70 | } 71 | 72 | if ((hs->opcode = c) == 0x0f) { 73 | hs->opcode2 = c = *p++; 74 | ht += DELTA_OPCODES; 75 | } else if (c >= 0xa0 && c <= 0xa3) { 76 | op64++; 77 | if (pref & PRE_67) 78 | pref |= PRE_66; 79 | else 80 | pref &= ~PRE_66; 81 | } 82 | 83 | opcode = c; 84 | cflags = ht[ht[opcode / 4] + (opcode % 4)]; 85 | 86 | if (cflags == C_ERROR) { 87 | error_opcode: 88 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 89 | cflags = 0; 90 | if ((opcode & -3) == 0x24) 91 | cflags++; 92 | } 93 | 94 | x = 0; 95 | if (cflags & C_GROUP) { 96 | uint16_t t; 97 | t = *(uint16_t *)(ht + (cflags & 0x7f)); 98 | cflags = (uint8_t)t; 99 | x = (uint8_t)(t >> 8); 100 | } 101 | 102 | if (hs->opcode2) { 103 | ht = hde64_table + DELTA_PREFIXES; 104 | if (ht[ht[opcode / 4] + (opcode % 4)] & pref) 105 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 106 | } 107 | 108 | if (cflags & C_MODRM) { 109 | hs->flags |= F_MODRM; 110 | hs->modrm = c = *p++; 111 | hs->modrm_mod = m_mod = c >> 6; 112 | hs->modrm_rm = m_rm = c & 7; 113 | hs->modrm_reg = m_reg = (c & 0x3f) >> 3; 114 | 115 | if (x && ((x << m_reg) & 0x80)) 116 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 117 | 118 | if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { 119 | uint8_t t = opcode - 0xd9; 120 | if (m_mod == 3) { 121 | ht = hde64_table + DELTA_FPU_MODRM + t*8; 122 | t = ht[m_reg] << m_rm; 123 | } else { 124 | ht = hde64_table + DELTA_FPU_REG; 125 | t = ht[t] << m_reg; 126 | } 127 | if (t & 0x80) 128 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 129 | } 130 | 131 | if (pref & PRE_LOCK) { 132 | if (m_mod == 3) { 133 | hs->flags |= F_ERROR | F_ERROR_LOCK; 134 | } else { 135 | uint8_t *table_end, op = opcode; 136 | if (hs->opcode2) { 137 | ht = hde64_table + DELTA_OP2_LOCK_OK; 138 | table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; 139 | } else { 140 | ht = hde64_table + DELTA_OP_LOCK_OK; 141 | table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; 142 | op &= -2; 143 | } 144 | for (; ht != table_end; ht++) 145 | if (*ht++ == op) { 146 | if (!((*ht << m_reg) & 0x80)) 147 | goto no_lock_error; 148 | else 149 | break; 150 | } 151 | hs->flags |= F_ERROR | F_ERROR_LOCK; 152 | no_lock_error: 153 | ; 154 | } 155 | } 156 | 157 | if (hs->opcode2) { 158 | switch (opcode) { 159 | case 0x20: case 0x22: 160 | m_mod = 3; 161 | if (m_reg > 4 || m_reg == 1) 162 | goto error_operand; 163 | else 164 | goto no_error_operand; 165 | case 0x21: case 0x23: 166 | m_mod = 3; 167 | if (m_reg == 4 || m_reg == 5) 168 | goto error_operand; 169 | else 170 | goto no_error_operand; 171 | } 172 | } else { 173 | switch (opcode) { 174 | case 0x8c: 175 | if (m_reg > 5) 176 | goto error_operand; 177 | else 178 | goto no_error_operand; 179 | case 0x8e: 180 | if (m_reg == 1 || m_reg > 5) 181 | goto error_operand; 182 | else 183 | goto no_error_operand; 184 | } 185 | } 186 | 187 | if (m_mod == 3) { 188 | uint8_t *table_end; 189 | if (hs->opcode2) { 190 | ht = hde64_table + DELTA_OP2_ONLY_MEM; 191 | table_end = ht + sizeof(hde64_table) - DELTA_OP2_ONLY_MEM; 192 | } else { 193 | ht = hde64_table + DELTA_OP_ONLY_MEM; 194 | table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; 195 | } 196 | for (; ht != table_end; ht += 2) 197 | if (*ht++ == opcode) { 198 | if ((*ht++ & pref) && !((*ht << m_reg) & 0x80)) 199 | goto error_operand; 200 | else 201 | break; 202 | } 203 | goto no_error_operand; 204 | } else if (hs->opcode2) { 205 | switch (opcode) { 206 | case 0x50: case 0xd7: case 0xf7: 207 | if (pref & (PRE_NONE | PRE_66)) 208 | goto error_operand; 209 | break; 210 | case 0xd6: 211 | if (pref & (PRE_F2 | PRE_F3)) 212 | goto error_operand; 213 | break; 214 | case 0xc5: 215 | goto error_operand; 216 | } 217 | goto no_error_operand; 218 | } else 219 | goto no_error_operand; 220 | 221 | error_operand: 222 | hs->flags |= F_ERROR | F_ERROR_OPERAND; 223 | no_error_operand: 224 | 225 | c = *p++; 226 | if (m_reg <= 1) { 227 | if (opcode == 0xf6) 228 | cflags |= C_IMM8; 229 | else if (opcode == 0xf7) 230 | cflags |= C_IMM_P66; 231 | } 232 | 233 | switch (m_mod) { 234 | case 0: 235 | if (pref & PRE_67) { 236 | if (m_rm == 6) 237 | disp_size = 2; 238 | } else 239 | if (m_rm == 5) 240 | disp_size = 4; 241 | break; 242 | case 1: 243 | disp_size = 1; 244 | break; 245 | case 2: 246 | disp_size = 2; 247 | if (!(pref & PRE_67)) 248 | disp_size <<= 1; 249 | break; 250 | } 251 | 252 | if (m_mod != 3 && m_rm == 4) { 253 | hs->flags |= F_SIB; 254 | p++; 255 | hs->sib = c; 256 | hs->sib_scale = c >> 6; 257 | hs->sib_index = (c & 0x3f) >> 3; 258 | if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) 259 | disp_size = 4; 260 | } 261 | 262 | p--; 263 | switch (disp_size) { 264 | case 1: 265 | hs->flags |= F_DISP8; 266 | hs->disp.disp8 = *p; 267 | break; 268 | case 2: 269 | hs->flags |= F_DISP16; 270 | hs->disp.disp16 = *(uint16_t *)p; 271 | break; 272 | case 4: 273 | hs->flags |= F_DISP32; 274 | hs->disp.disp32 = *(uint32_t *)p; 275 | break; 276 | } 277 | p += disp_size; 278 | } else if (pref & PRE_LOCK) 279 | hs->flags |= F_ERROR | F_ERROR_LOCK; 280 | 281 | if (cflags & C_IMM_P66) { 282 | if (cflags & C_REL32) { 283 | if (pref & PRE_66) { 284 | hs->flags |= F_IMM16 | F_RELATIVE; 285 | hs->imm.imm16 = *(uint16_t *)p; 286 | p += 2; 287 | goto disasm_done; 288 | } 289 | goto rel32_ok; 290 | } 291 | if (op64) { 292 | hs->flags |= F_IMM64; 293 | hs->imm.imm64 = *(uint64_t *)p; 294 | p += 8; 295 | } else if (!(pref & PRE_66)) { 296 | hs->flags |= F_IMM32; 297 | hs->imm.imm32 = *(uint32_t *)p; 298 | p += 4; 299 | } else 300 | goto imm16_ok; 301 | } 302 | 303 | 304 | if (cflags & C_IMM16) { 305 | imm16_ok: 306 | hs->flags |= F_IMM16; 307 | hs->imm.imm16 = *(uint16_t *)p; 308 | p += 2; 309 | } 310 | if (cflags & C_IMM8) { 311 | hs->flags |= F_IMM8; 312 | hs->imm.imm8 = *p++; 313 | } 314 | 315 | if (cflags & C_REL32) { 316 | rel32_ok: 317 | hs->flags |= F_IMM32 | F_RELATIVE; 318 | hs->imm.imm32 = *(uint32_t *)p; 319 | p += 4; 320 | } else if (cflags & C_REL8) { 321 | hs->flags |= F_IMM8 | F_RELATIVE; 322 | hs->imm.imm8 = *p++; 323 | } 324 | 325 | disasm_done: 326 | 327 | if ((hs->len = (uint8_t)(p-(uint8_t *)code)) > 15) { 328 | hs->flags |= F_ERROR | F_ERROR_LENGTH; 329 | hs->len = 15; 330 | } 331 | 332 | return (unsigned int)hs->len; 333 | } 334 | -------------------------------------------------------------------------------- /src/minhook/src/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 14 | #error Unsupported compiler 15 | #else 16 | #include 17 | #endif 18 | 19 | #define F_MODRM 0x00000001 20 | #define F_SIB 0x00000002 21 | #define F_IMM8 0x00000004 22 | #define F_IMM16 0x00000008 23 | #define F_IMM32 0x00000010 24 | #define F_IMM64 0x00000020 25 | #define F_DISP8 0x00000040 26 | #define F_DISP16 0x00000080 27 | #define F_DISP32 0x00000100 28 | #define F_RELATIVE 0x00000200 29 | #define F_ERROR 0x00001000 30 | #define F_ERROR_OPCODE 0x00002000 31 | #define F_ERROR_LENGTH 0x00004000 32 | #define F_ERROR_LOCK 0x00008000 33 | #define F_ERROR_OPERAND 0x00010000 34 | #define F_PREFIX_REPNZ 0x01000000 35 | #define F_PREFIX_REPX 0x02000000 36 | #define F_PREFIX_REP 0x03000000 37 | #define F_PREFIX_66 0x04000000 38 | #define F_PREFIX_67 0x08000000 39 | #define F_PREFIX_LOCK 0x10000000 40 | #define F_PREFIX_SEG 0x20000000 41 | #define F_PREFIX_REX 0x40000000 42 | #define F_PREFIX_ANY 0x7f000000 43 | 44 | #define PREFIX_SEGMENT_CS 0x2e 45 | #define PREFIX_SEGMENT_SS 0x36 46 | #define PREFIX_SEGMENT_DS 0x3e 47 | #define PREFIX_SEGMENT_ES 0x26 48 | #define PREFIX_SEGMENT_FS 0x64 49 | #define PREFIX_SEGMENT_GS 0x65 50 | #define PREFIX_LOCK 0xf0 51 | #define PREFIX_REPNZ 0xf2 52 | #define PREFIX_REPX 0xf3 53 | #define PREFIX_OPERAND_SIZE 0x66 54 | #define PREFIX_ADDRESS_SIZE 0x67 55 | 56 | #pragma pack(push,1) 57 | 58 | typedef struct { 59 | uint8_t len; 60 | uint8_t p_rep; 61 | uint8_t p_lock; 62 | uint8_t p_seg; 63 | uint8_t p_66; 64 | uint8_t p_67; 65 | uint8_t rex; 66 | uint8_t rex_w; 67 | uint8_t rex_r; 68 | uint8_t rex_x; 69 | uint8_t rex_b; 70 | uint8_t opcode; 71 | uint8_t opcode2; 72 | uint8_t modrm; 73 | uint8_t modrm_mod; 74 | uint8_t modrm_reg; 75 | uint8_t modrm_rm; 76 | uint8_t sib; 77 | uint8_t sib_scale; 78 | uint8_t sib_index; 79 | uint8_t sib_base; 80 | union { 81 | uint8_t imm8; 82 | uint16_t imm16; 83 | uint32_t imm32; 84 | uint64_t imm64; 85 | } imm; 86 | union { 87 | uint8_t disp8; 88 | uint16_t disp16; 89 | uint32_t disp32; 90 | } disp; 91 | uint32_t flags; 92 | } hde64s; 93 | 94 | #pragma pack(pop) 95 | 96 | #ifdef __cplusplus 97 | extern "C" { 98 | #endif 99 | 100 | /* __cdecl */ 101 | unsigned int hde64_disasm(const void *code, hde64s *hs); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* _HDE64_H_ */ 108 | -------------------------------------------------------------------------------- /src/minhook/src/hde/table32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #ifndef _TABLE32_H_ 9 | #define _TABLE32_H_ 10 | 11 | #define C_NONE 0x00 12 | #define C_MODRM 0x01 13 | #define C_IMM8 0x02 14 | #define C_IMM16 0x04 15 | #define C_IMM_P66 0x10 16 | #define C_REL8 0x20 17 | #define C_REL32 0x40 18 | #define C_GROUP 0x80 19 | #define C_ERROR 0xff 20 | 21 | #define PRE_ANY 0x00 22 | #define PRE_NONE 0x01 23 | #define PRE_F2 0x02 24 | #define PRE_F3 0x04 25 | #define PRE_66 0x08 26 | #define PRE_67 0x10 27 | #define PRE_LOCK 0x20 28 | #define PRE_SEG 0x40 29 | #define PRE_ALL 0xff 30 | 31 | #define DELTA_OPCODES 0x4a 32 | #define DELTA_FPU_REG 0xf1 33 | #define DELTA_FPU_MODRM 0xf8 34 | #define DELTA_PREFIXES 0x130 35 | #define DELTA_OP_LOCK_OK 0x1a1 36 | #define DELTA_OP2_LOCK_OK 0x1b9 37 | #define DELTA_OP_ONLY_MEM 0x1cb 38 | #define DELTA_OP2_ONLY_MEM 0x1da 39 | 40 | unsigned char hde32_table[] = { 41 | 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, 42 | 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, 43 | 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, 44 | 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, 45 | 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, 46 | 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, 47 | 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, 48 | 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, 49 | 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, 50 | 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, 51 | 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, 52 | 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, 53 | 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, 54 | 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, 55 | 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, 56 | 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, 57 | 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, 58 | 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, 59 | 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 60 | 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 61 | 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, 62 | 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, 63 | 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, 64 | 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, 65 | 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, 66 | 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, 67 | 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 68 | 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, 69 | 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, 70 | 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, 71 | 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, 72 | 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, 73 | 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, 74 | 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, 75 | 0xe7,0x08,0x00,0xf0,0x02,0x00 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/minhook/src/hde/table64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #ifndef _TABLE64_H_ 9 | #define _TABLE64_H_ 10 | 11 | #define C_NONE 0x00 12 | #define C_MODRM 0x01 13 | #define C_IMM8 0x02 14 | #define C_IMM16 0x04 15 | #define C_IMM_P66 0x10 16 | #define C_REL8 0x20 17 | #define C_REL32 0x40 18 | #define C_GROUP 0x80 19 | #define C_ERROR 0xff 20 | 21 | #define PRE_ANY 0x00 22 | #define PRE_NONE 0x01 23 | #define PRE_F2 0x02 24 | #define PRE_F3 0x04 25 | #define PRE_66 0x08 26 | #define PRE_67 0x10 27 | #define PRE_LOCK 0x20 28 | #define PRE_SEG 0x40 29 | #define PRE_ALL 0xff 30 | 31 | #define DELTA_OPCODES 0x4a 32 | #define DELTA_FPU_REG 0xfd 33 | #define DELTA_FPU_MODRM 0x104 34 | #define DELTA_PREFIXES 0x13c 35 | #define DELTA_OP_LOCK_OK 0x1ae 36 | #define DELTA_OP2_LOCK_OK 0x1c6 37 | #define DELTA_OP_ONLY_MEM 0x1d8 38 | #define DELTA_OP2_ONLY_MEM 0x1e7 39 | 40 | unsigned char hde64_table[] = { 41 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 42 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 43 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 44 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 45 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 46 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 47 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 48 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 49 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 50 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 51 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 52 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 53 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 54 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 55 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 56 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 57 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 58 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 59 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 60 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 61 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 62 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 63 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 64 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 65 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 66 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 67 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 68 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 69 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 70 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 71 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 72 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 73 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 74 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 75 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 76 | 0x00,0xf0,0x02,0x00 77 | }; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/minhook/src/trampoline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2014 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "intrin_c.h" 30 | #include 31 | 32 | #if defined(_M_X64) || defined(__x86_64__) 33 | #include "hde/hde64.h" 34 | typedef hde64s HDE; 35 | #define HDE_DISASM(code, hs) hde64_disasm(code, hs) 36 | #else 37 | #include "hde/hde32.h" 38 | typedef hde32s HDE; 39 | #define HDE_DISASM(code, hs) hde32_disasm(code, hs) 40 | #endif 41 | 42 | #include "trampoline.h" 43 | #include "buffer.h" 44 | 45 | // Maximum size of a trampoline function. 46 | #if defined(_M_X64) || defined(__x86_64__) 47 | #define TRAMPOLINE_MAX_SIZE (MEMORY_SLOT_SIZE - sizeof(JMP_ABS)) 48 | #else 49 | #define TRAMPOLINE_MAX_SIZE MEMORY_SLOT_SIZE 50 | #endif 51 | 52 | //------------------------------------------------------------------------- 53 | static BOOL IsCodePadding(LPBYTE pInst, UINT size) 54 | { 55 | UINT i; 56 | 57 | if (pInst[0] != 0x00 && pInst[0] != 0x90 && pInst[0] != 0xCC) 58 | return FALSE; 59 | 60 | for (i = 1; i < size; ++i) 61 | { 62 | if (pInst[i] != pInst[0]) 63 | return FALSE; 64 | } 65 | return TRUE; 66 | } 67 | 68 | //------------------------------------------------------------------------- 69 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct) 70 | { 71 | #if defined(_M_X64) || defined(__x86_64__) 72 | CALL_ABS call = { 73 | 0xFF, 0x15, 0x00000002, // FF15 00000002: CALL [RIP+8] 74 | 0xEB, 0x08, // EB 08: JMP +10 75 | 0x0000000000000000ULL // Absolute destination address 76 | }; 77 | JMP_ABS jmp = { 78 | 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6] 79 | 0x0000000000000000ULL // Absolute destination address 80 | }; 81 | JCC_ABS jcc = { 82 | 0x70, 0x0E, // 7* 0E: J** +16 83 | 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6] 84 | 0x0000000000000000ULL // Absolute destination address 85 | }; 86 | #else 87 | CALL_REL call = { 88 | 0xE8, // E8 xxxxxxxx: CALL +5+xxxxxxxx 89 | 0x00000000 // Relative destination address 90 | }; 91 | JMP_REL jmp = { 92 | 0xE9, // E9 xxxxxxxx: JMP +5+xxxxxxxx 93 | 0x00000000 // Relative destination address 94 | }; 95 | JCC_REL jcc = { 96 | 0x0F, 0x80, // 0F8* xxxxxxxx: J** +6+xxxxxxxx 97 | 0x00000000 // Relative destination address 98 | }; 99 | #endif 100 | 101 | UINT8 oldPos = 0; 102 | UINT8 newPos = 0; 103 | ULONG_PTR jmpDest = 0; // Destination address of an internal jump. 104 | BOOL finished = FALSE; // Is the function completed? 105 | #if defined(_M_X64) || defined(__x86_64__) 106 | UINT8 instBuf[16]; 107 | #endif 108 | 109 | ct->patchAbove = FALSE; 110 | ct->nIP = 0; 111 | 112 | do 113 | { 114 | HDE hs; 115 | UINT copySize; 116 | LPVOID pCopySrc; 117 | ULONG_PTR pOldInst = (ULONG_PTR)ct->pTarget + oldPos; 118 | ULONG_PTR pNewInst = (ULONG_PTR)ct->pTrampoline + newPos; 119 | 120 | copySize = HDE_DISASM((LPVOID)pOldInst, &hs); 121 | if (hs.flags & F_ERROR) 122 | return FALSE; 123 | 124 | pCopySrc = (LPVOID)pOldInst; 125 | if (oldPos >= sizeof(JMP_REL)) 126 | { 127 | // The trampoline function is long enough. 128 | // Complete the function with the jump to the target function. 129 | #if defined(_M_X64) || defined(__x86_64__) 130 | jmp.address = pOldInst; 131 | #else 132 | jmp.operand = (UINT32)(pOldInst - (pNewInst + sizeof(jmp))); 133 | #endif 134 | pCopySrc = &jmp; 135 | copySize = sizeof(jmp); 136 | 137 | finished = TRUE; 138 | } 139 | #if defined(_M_X64) || defined(__x86_64__) 140 | else if ((hs.modrm & 0xC7) == 0x05) 141 | { 142 | // Instructions using RIP relative addressing. (ModR/M = 00???101B) 143 | 144 | // Modify the RIP relative address. 145 | PUINT32 pRelAddr; 146 | 147 | // compiler-optimized memcpy. 148 | memcpy(instBuf, (LPBYTE)pOldInst, copySize); 149 | pCopySrc = instBuf; 150 | 151 | // Relative address is stored at (instruction length - immediate value length - 4). 152 | pRelAddr = (PUINT32)(instBuf + hs.len - ((hs.flags & 0x3C) >> 2) - 4); 153 | *pRelAddr 154 | = (UINT32)((pOldInst + hs.len + (INT32)hs.disp.disp32) - (pNewInst + hs.len)); 155 | 156 | // Complete the function if JMP (FF /4). 157 | if (hs.opcode == 0xFF && hs.modrm_reg == 4) 158 | finished = TRUE; 159 | } 160 | #endif 161 | else if (hs.opcode == 0xE8) 162 | { 163 | // Direct relative CALL 164 | ULONG_PTR dest = pOldInst + hs.len + (INT32)hs.imm.imm32; 165 | #if defined(_M_X64) || defined(__x86_64__) 166 | call.address = dest; 167 | #else 168 | call.operand = (UINT32)(dest - (pNewInst + sizeof(call))); 169 | #endif 170 | pCopySrc = &call; 171 | copySize = sizeof(call); 172 | } 173 | else if ((hs.opcode & 0xFD) == 0xE9) 174 | { 175 | // Direct relative JMP (EB or E9) 176 | ULONG_PTR dest = pOldInst + hs.len; 177 | 178 | if (hs.opcode == 0xEB) // isShort jmp 179 | dest += (INT8)hs.imm.imm8; 180 | else 181 | dest += (INT32)hs.imm.imm32; 182 | 183 | // Simply copy an internal jump. 184 | if ((ULONG_PTR)ct->pTarget <= dest 185 | && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL))) 186 | { 187 | if (jmpDest < dest) 188 | jmpDest = dest; 189 | } 190 | else 191 | { 192 | #if defined(_M_X64) || defined(__x86_64__) 193 | jmp.address = dest; 194 | #else 195 | jmp.operand = (UINT32)(dest - (pNewInst + sizeof(jmp))); 196 | #endif 197 | pCopySrc = &jmp; 198 | copySize = sizeof(jmp); 199 | 200 | // Exit the function If it is not in the branch 201 | finished = (pOldInst >= jmpDest); 202 | } 203 | } 204 | else if ((hs.opcode & 0xF0) == 0x70 205 | || (hs.opcode & 0xFC) == 0xE0 206 | || (hs.opcode2 & 0xF0) == 0x80) 207 | { 208 | // Direct relative Jcc 209 | ULONG_PTR dest = pOldInst + hs.len; 210 | 211 | if ((hs.opcode & 0xF0) == 0x70 // Jcc 212 | || (hs.opcode & 0xFC) == 0xE0) // LOOPNZ/LOOPZ/LOOP/JECXZ 213 | dest += (INT8)hs.imm.imm8; 214 | else 215 | dest += (INT32)hs.imm.imm32; 216 | 217 | // Simply copy an internal jump. 218 | if ((ULONG_PTR)ct->pTarget <= dest 219 | && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL))) 220 | { 221 | if (jmpDest < dest) 222 | jmpDest = dest; 223 | } 224 | else if ((hs.opcode & 0xFC) == 0xE0) 225 | { 226 | // LOOPNZ/LOOPZ/LOOP/JCXZ/JECXZ to the outside are not supported. 227 | return FALSE; 228 | } 229 | else 230 | { 231 | UINT8 cond = ((hs.opcode != 0x0F ? hs.opcode : hs.opcode2) & 0x0F); 232 | #if defined(_M_X64) || defined(__x86_64__) 233 | // Invert the condition in x64 mode to simplify the conditional jump logic. 234 | jcc.opcode = 0x71 ^ cond; 235 | jcc.address = dest; 236 | #else 237 | jcc.opcode1 = 0x80 | cond; 238 | jcc.operand = (UINT32)(dest - (pNewInst + sizeof(jcc))); 239 | #endif 240 | pCopySrc = &jcc; 241 | copySize = sizeof(jcc); 242 | } 243 | } 244 | else if ((hs.opcode & 0xFE) == 0xC2) 245 | { 246 | // RET (C2 or C3) 247 | 248 | // Complete the function if not in a branch. 249 | finished = (pOldInst >= jmpDest); 250 | } 251 | 252 | // Can't alter the instruction length in a branch. 253 | if (pOldInst < jmpDest && copySize != hs.len) 254 | return FALSE; 255 | 256 | // Trampoline function is too large. 257 | if ((newPos + copySize) > TRAMPOLINE_MAX_SIZE) 258 | return FALSE; 259 | 260 | // Trampoline function has too many instructions. 261 | if (ct->nIP >= ARRAYSIZE(ct->oldIPs)) 262 | return FALSE; 263 | 264 | ct->oldIPs[ct->nIP] = oldPos; 265 | ct->newIPs[ct->nIP] = newPos; 266 | ct->nIP++; 267 | 268 | memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize); 269 | newPos += copySize; 270 | oldPos += hs.len; 271 | } 272 | while (!finished); 273 | 274 | // Is there enough place for a long jump? 275 | if (oldPos < sizeof(JMP_REL) 276 | && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL) - oldPos)) 277 | { 278 | // Is there enough place for a short jump? 279 | if (oldPos < sizeof(JMP_REL_SHORT) 280 | && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL_SHORT) - oldPos)) 281 | { 282 | return FALSE; 283 | } 284 | 285 | // Can we place the long jump above the function? 286 | if (!IsExecutableAddress((LPBYTE)ct->pTarget - sizeof(JMP_REL))) 287 | return FALSE; 288 | 289 | if (!IsCodePadding((LPBYTE)ct->pTarget - sizeof(JMP_REL), sizeof(JMP_REL))) 290 | return FALSE; 291 | 292 | ct->patchAbove = TRUE; 293 | } 294 | 295 | #if defined(_M_X64) || defined(__x86_64__) 296 | // Create a relay function. 297 | jmp.address = (ULONG_PTR)ct->pDetour; 298 | 299 | ct->pRelay = (LPBYTE)ct->pTrampoline + newPos; 300 | memcpy(ct->pRelay, &jmp, sizeof(jmp)); 301 | #endif 302 | 303 | return TRUE; 304 | } 305 | -------------------------------------------------------------------------------- /src/minhook/src/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2014 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _TRAMP_ONLINE_H_ 30 | # define _TRAMP_ONLINE_H_ 31 | 32 | #pragma pack(push, 1) 33 | 34 | #ifndef ARRAYSIZE 35 | # define ARRAYSIZE(a) (sizeof(a)/sizeof((a)[0])) 36 | #endif 37 | 38 | // Structs for writing x86/x64 instructions. 39 | 40 | // 8-bit relative jump. 41 | typedef struct _JMP_REL_SHORT 42 | { 43 | UINT8 opcode; // EB xx: JMP +2+xx 44 | UINT8 operand; 45 | } JMP_REL_SHORT, *PJMP_REL_SHORT; 46 | 47 | // 32-bit direct relative jump/call. 48 | typedef struct _JMP_REL 49 | { 50 | UINT8 opcode; // E9/E8 xxxxxxxx: JMP/CALL +5+xxxxxxxx 51 | UINT32 operand; // Relative destination address 52 | } JMP_REL, *PJMP_REL, CALL_REL; 53 | 54 | // 64-bit indirect absolute jump. 55 | typedef struct _JMP_ABS 56 | { 57 | UINT8 opcode0; // FF25 00000000: JMP [+6] 58 | UINT8 opcode1; 59 | UINT32 dummy; 60 | UINT64 address; // Absolute destination address 61 | } JMP_ABS, *PJMP_ABS; 62 | 63 | // 64-bit indirect absolute call. 64 | typedef struct _CALL_ABS 65 | { 66 | UINT8 opcode0; // FF15 00000002: CALL [+6] 67 | UINT8 opcode1; 68 | UINT32 dummy0; 69 | UINT8 dummy1; // EB 08: JMP +10 70 | UINT8 dummy2; 71 | UINT64 address; // Absolute destination address 72 | } CALL_ABS; 73 | 74 | // 32-bit direct relative conditional jumps. 75 | typedef struct _JCC_REL 76 | { 77 | UINT8 opcode0; // 0F8* xxxxxxxx: J** +6+xxxxxxxx 78 | UINT8 opcode1; 79 | UINT32 operand; // Relative destination address 80 | } JCC_REL; 81 | 82 | // 64bit indirect absolute conditional jumps that x64 lacks. 83 | typedef struct _JCC_ABS 84 | { 85 | UINT8 opcode; // 7* 0E: J** +16 86 | UINT8 dummy0; 87 | UINT8 dummy1; // FF25 00000000: JMP [+6] 88 | UINT8 dummy2; 89 | UINT32 dummy3; 90 | UINT64 address; // Absolute destination address 91 | } JCC_ABS; 92 | 93 | #pragma pack(pop) 94 | 95 | typedef struct _TRAMPOLINE 96 | { 97 | LPVOID pTarget; // [In] Address of the target function. 98 | LPVOID pDetour; // [In] Address of the detour function. 99 | LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function. 100 | 101 | #if defined(_M_X64) || defined(__x86_64__) 102 | LPVOID pRelay; // [Out] Address of the relay function. 103 | #endif 104 | BOOL patchAbove; // [Out] Should use the hot patch area? 105 | UINT nIP; // [Out] Number of the instruction boundaries. 106 | UINT8 oldIPs[8]; // [Out] Instruction boundaries of the target function. 107 | UINT8 newIPs[8]; // [Out] Instruction boundaries of the trampoline function. 108 | } TRAMPOLINE, *PTRAMPOLINE; 109 | 110 | #ifdef __cplusplus 111 | extern "C" { 112 | #endif 113 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct); 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif -------------------------------------------------------------------------------- /src/new_process.c: -------------------------------------------------------------------------------- 1 | #include "general.h" 2 | #include "ini_parser.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define PROCESS_NUM 10 12 | static void* g_handle[PROCESS_NUM]; 13 | 14 | static HANDLE 15 | search_process(LPCWSTR lpstr, DWORD m_parent) 16 | { 17 | bool b_more; 18 | PROCESSENTRY32W pe32; 19 | HANDLE hSnapshot = INVALID_HANDLE_VALUE; 20 | DWORD chi_pid[PROCESS_NUM] = {0}; 21 | HANDLE m_handle = NULL; 22 | volatile int i = 1; 23 | static int h_num = 1; 24 | hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); 25 | if( hSnapshot == INVALID_HANDLE_VALUE ) 26 | { 27 | #ifdef _LOGDEBUG 28 | logmsg("CreateToolhelp32Snapshot (of processes) error %lu\n",GetLastError() ); 29 | #endif 30 | return m_handle; 31 | } 32 | chi_pid[0] = m_parent; 33 | pe32.dwSize=sizeof(pe32); 34 | b_more = Process32FirstW(hSnapshot,&pe32); 35 | while (b_more) 36 | { 37 | if ( m_parent == pe32.th32ParentProcessID ) 38 | { 39 | chi_pid[i++] = pe32.th32ProcessID; 40 | if (i>=PROCESS_NUM) 41 | { 42 | break; 43 | } 44 | } 45 | if ( lpstr && pe32.th32ParentProcessID>4 && StrStrIW((LPWSTR)lpstr,(LPCWSTR)pe32.szExeFile) ) 46 | { 47 | m_handle = (HANDLE)(uintptr_t)pe32.th32ProcessID; 48 | break; 49 | } 50 | b_more = Process32NextW(hSnapshot,&pe32); 51 | } 52 | CloseHandle(hSnapshot); 53 | if ( !m_handle && chi_pid[0] ) 54 | { 55 | for ( i=1 ; i0) 187 | { 188 | int i; 189 | for ( i =0 ; i0 ; ++i ) 190 | { 191 | TerminateProcess(g_handle[i], (DWORD)-1); 192 | CloseHandle(g_handle[i]); 193 | } 194 | refresh_tray(); 195 | } 196 | return; 197 | } 198 | 199 | HANDLE WINAPI 200 | create_new(LPCWSTR wcmd, LPCWSTR param, LPCWSTR pcd, int flags, DWORD *opid) 201 | { 202 | PROCESS_INFORMATION pi; 203 | STARTUPINFOW si; 204 | DWORD dwCreat = 0; 205 | LPCWSTR lp_dir = NULL; 206 | WCHAR process[MAX_PATH+1] = {0}; 207 | if (pcd != NULL && wcslen(pcd) > 1) 208 | { 209 | lp_dir = pcd; 210 | } 211 | if (param != NULL && wcslen(param ) > 1) 212 | { 213 | wnsprintfW(process, MAX_PATH, L"%ls %ls", wcmd, param); 214 | } 215 | else 216 | { 217 | wnsprintfW(process, MAX_PATH, L"%ls", wcmd); 218 | } 219 | if (true) 220 | { 221 | fzero(&si,sizeof(si)); 222 | si.cb = sizeof(si); 223 | si.dwFlags = STARTF_USESHOWWINDOW; 224 | if (flags > 1) 225 | { 226 | si.wShowWindow = SW_SHOWNOACTIVATE; 227 | } 228 | else if (flags == 1) 229 | { 230 | si.wShowWindow = SW_MINIMIZE; 231 | } 232 | else if (!flags) 233 | { 234 | si.wShowWindow = SW_HIDE; 235 | dwCreat |= CREATE_NEW_PROCESS_GROUP; 236 | } 237 | if(!CreateProcessW(NULL, 238 | process, 239 | NULL, 240 | NULL, 241 | FALSE, 242 | dwCreat, 243 | NULL, 244 | lp_dir, 245 | &si,&pi)) 246 | { 247 | #ifdef _LOGDEBUG 248 | logmsg("CreateProcessW %ls error, cause: %lu\n", wcmd, GetLastError()); 249 | #endif 250 | return NULL; 251 | } 252 | if (NULL != opid) 253 | { 254 | *opid = pi.dwProcessId; 255 | } 256 | } 257 | return pi.hProcess; 258 | } 259 | 260 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 261 | * 此函数必须以线程方式调用,因为会阻塞主进程 262 | */ 263 | unsigned WINAPI 264 | run_process(void * lparam) 265 | { 266 | WCHAR wcmd[VALUE_LEN+1] = {0}; 267 | WCHAR pcd[VALUE_LEN+1] = {0}; 268 | WCHAR param[VALUE_LEN+1] = {0}; 269 | int flags = get_parameters(wcmd, param, pcd, VALUE_LEN); 270 | if (flags<0) 271 | { 272 | return (0); 273 | } 274 | /* 如果是无界面启动,直接返回 */ 275 | if (no_gui_boot()) 276 | { 277 | return (0); 278 | } 279 | #ifdef _LOGDEBUG 280 | logmsg("wcmd[%ls], param[%ls], pcd[%ls]\n", wcmd, param, pcd); 281 | #endif 282 | /* 重启外部进程需要延迟一下 */ 283 | Sleep(500); 284 | if (wcslen(wcmd)>0 && !search_process(wcmd,0)) 285 | { 286 | DWORD pid = 0; 287 | g_handle[0] = create_new(wcmd, param, pcd, flags, &pid); 288 | if (g_handle[0] != NULL && (SleepEx(3000,false) == 0)) 289 | { 290 | /* 延迟,因为有可能进程还没创建,无法结束进程树 */ 291 | search_process(NULL, pid); 292 | } 293 | } 294 | return (1); 295 | } 296 | -------------------------------------------------------------------------------- /src/new_process.h: -------------------------------------------------------------------------------- 1 | #ifndef _NEW_PROCESS_H 2 | #define _NEW_PROCESS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern unsigned __stdcall run_process(void * lparam); 9 | extern void __stdcall kill_trees(void); 10 | extern bool __stdcall no_gui_boot(void); 11 | extern HANDLE __stdcall create_new(LPCWSTR, LPCWSTR, LPCWSTR, int, DWORD*); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* _NEW_PROCESS_H */ 18 | -------------------------------------------------------------------------------- /src/on_tabs.h: -------------------------------------------------------------------------------- 1 | #ifndef _ON_TABS_H_ 2 | # define _ON_TABS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern void __stdcall threads_on_tabs(void); 9 | extern void __stdcall un_uia(void); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif /* end _ON_TABS_H_ */ -------------------------------------------------------------------------------- /src/portable(example).ini: -------------------------------------------------------------------------------- 1 | ;SafeEx --安全增强 (0 不启用 1 启用) 2 | ;Portable --便携式 (0 不启用 1 启用) 3 | ;EnableWhiteList --启用白名单,最严格的安全策略 (0 不启用 1 启用) 4 | ;PortableDataPath --配置文件目录所在,支持相对路径 5 | ;ProcessAffinityMask --启用进程平衡功能,参见attach字段的说明 (0 不启用 1 启用) 6 | ;Bosskey --老板键配置,参见attach字段的说明 7 | ;ProxyExe --随浏览器启动的进程,参见attach字段的说明 8 | ;DisableScan --禁止扫描注册表的扩展与插件 (0 浏览器默认 1 禁止扫描) 9 | ;OnTabs --启用定制的标签页功能 (0 不启用 1 启用) 10 | ;Update --启用自动更新 (0 不启用 1 启用) 11 | ;更多参数说明请见(https://sourceforge.net/p/libportable/wiki/Home/) 12 | [General] 13 | SafeEx= 14 | Portable=1 15 | EnableWhiteList=0 16 | PortableDataPath=../Profiles 17 | CreateCrashDump=0 18 | ProcessAffinityMask= 19 | Bosskey= 20 | ProxyExe= 21 | DisableScan=0 22 | OnTabs=0 23 | Update=1 24 | DisableExtensionPortable=0 25 | 26 | ;会自动导入本段下方的环境变量已获得浏览器的高级功能,例如,设置MOZ_NO_REMOTE=1 27 | ;TmpDataPath为自定义临时文件路径(包括网页缓存与mozilla临时文件,需设置Portable=1) 28 | ;NpluginPath为自定义插件路径, 注意, 85.0及以后版本已不再支持插件. 29 | [Env] 30 | ;MOZ_NO_REMOTE=1 31 | TmpDataPath= 32 | 33 | ;模块与进程白名单( <=16 ),支持通配符匹配与环境变量. 34 | ;如需启用请删除前面的";"符号 35 | [whitelist] 36 | Path1=%ProgramFiles%\Internet Explorer\iexplore.exe 37 | ;Path2=c:\windows\system32\cmd.exe 38 | ;Path3=*xThunder.exe 39 | ;Path4=*opentext22.dll 40 | ;Path5=*WordStrokeHelper32.dll 41 | ;Path6=*AM32-*.dll 42 | ;Path7=../local/goagent.exe 43 | ;Path8= 44 | ;Path9= 45 | ;Path10= 46 | 47 | ;当 Bosskey=1 时生效,如果下面的值设置出错或未设置,默认老板键为(Ctrl+Shift+~). 48 | ;Hotkey设置必须是虚拟键码(Virtual Key Codes)的十进制格式,以+号分开. 49 | ;例如, 02+192 (热键为 Ctrl+~) 02+04+188 (热键为 Ctrl+Shift+,). 50 | ;当ProxyExe=1时启动ExPath下的进程,0代表尽可能的隐藏进程. 51 | ;当ProcessAffinityMask=1时,CpuUse为系统cpu利用率,有效值(0-99),当设置出错时默认值为25. 52 | [attach] 53 | CpuUse=25 54 | Hotkey= 55 | ExPath=../local/goagent.exe,0 56 | 57 | ;当OnTabs=1时,可设置下面的一些标签页功能(需浏览器保持accessibility.force_disabled为默认值0). 58 | ;mouse_time为鼠标停留在标签页上的时间(毫秒),如果不设置,默认为300毫秒激活标签页(0 不启用 1 启用). 59 | ;double_click_close为鼠标左键双击关闭标签页 (0 不启用 1 启用). 60 | ;double_click_new为鼠标左键双击标签栏时新建标签页 (0 不启用 1 启用). 61 | ;mouse_hover_close为鼠标悬停在关闭按钮时关闭标签页 (0 不启用 1 启用). 62 | ;mouse_hover_new为鼠标悬停在新建按钮时新建标签页 (0 不启用 1 启用). 63 | ;right_click_close为鼠标右键单击标签时关闭标签页 (0 不启用 1 启用). 64 | ;right_click_recover为鼠标右键单击标签栏空白处时恢复标签页 (0 不启用 1 启用). 65 | ;left_click_close为鼠标左键单击时关闭标签页.注意,左键单击关闭需mouse_time, 66 | ;double_click_close, left_click_close同时启用且在标签切换时单击才有效. (0 不启用 1 启用). 67 | [tabs] 68 | mouse_time=200 69 | double_click_close= 70 | double_click_new= 71 | mouse_hover_close= 72 | mouse_hover_new= 73 | right_click_close=1 74 | right_click_recover= 75 | left_click_close= 76 | 77 | ;upcheck.exe右键菜单优先调用此命令行程序,例如,../../idman.exe /d %s /q 78 | ;如果程序不存在,则调用pc上安装的迅雷下载,如果迅雷不存在,使用upcheck自身多线程下载 79 | [player] 80 | command= 81 | 82 | ;此区段为自动更新配置,如果启用自动更新,请确保此区段存在 83 | ;upcheck.exe为辅助更新程序,请确保它存在于浏览器的安装目录 84 | ;upcheck.exe每24小时随浏览器启动一次,并不会常驻内存 85 | ;url为更新服务器所在,由开发者设置,不要随意变更 86 | ;msg为更新准备好后的提示消息,如果不需要提示,请设为空 87 | [update] 88 | url=https://sourceforge.net/projects/libportable/files/Iceweasel/update_info.txt/download 89 | msg=Download Complete! The update is being applied at the next startup.\nI hope you feel satisfied ^_^ 90 | 91 | ;此区段为自动更新进程的代理配置,支持https, socks5, 92 | ;addr的格式, 例如, https://127.0.0.1:1080 或者 socks5://127.0.0.1:1080 93 | ;user的格式为用户名:密码 94 | [proxy] 95 | ;addr=http://127.0.0.1:1080 96 | ;user=test:12345678 97 | -------------------------------------------------------------------------------- /src/portable.h: -------------------------------------------------------------------------------- 1 | #ifndef _POR_TABLE_H_ 2 | #define _POR_TABLE_H_ 3 | 4 | #include /* for uint32_t define */ 5 | 6 | #ifndef TETE_CLASS_EXPORT 7 | # define TETE_CLASS_EXPORT __declspec(dllexport) 8 | #endif 9 | 10 | #ifndef TETE_CLASS_IMPORT 11 | # define TETE_CLASS_IMPORT __declspec(dllimport) 12 | #endif 13 | 14 | #if defined(LIBPORTABLE_STATIC) 15 | # define TETE_EXT_CLASS extern 16 | #elif defined(TETE_BUILD) 17 | # define TETE_EXT_CLASS TETE_CLASS_EXPORT 18 | #else 19 | # define TETE_EXT_CLASS TETE_CLASS_IMPORT 20 | #endif 21 | 22 | #define NON_TEMPORAL_STORES_NOT_SUPPORTED 0 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | TETE_EXT_CLASS void __stdcall undo_it( void ); 29 | TETE_EXT_CLASS uint32_t GetNonTemporalDataSizeMin_tt ( void ); 30 | TETE_EXT_CLASS void * __cdecl memset_nontemporal_tt ( void*, int, size_t ); 31 | 32 | /* compatibility with tete's patches */ 33 | TETE_EXT_CLASS int GetCpuFeature_tt ( void ); 34 | TETE_EXT_CLASS intptr_t GetAppDirHash_tt ( void ); 35 | 36 | #if defined(LIBPORTABLE_STATIC) 37 | TETE_EXT_CLASS void __stdcall do_it( void ); 38 | #endif 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* end _POR_TABLE_H_ */ -------------------------------------------------------------------------------- /src/resource.rc: -------------------------------------------------------------------------------- 1 | #ifndef _APP_RES_INVOKED_ 2 | #define _APP_RES_INVOKED_ 3 | 4 | #ifndef _MAC 5 | 6 | // Version 7 | 8 | 1 VERSIONINFO 9 | FILEVERSION 9,0,7,100 10 | PRODUCTVERSION 9,0,7,100 11 | BEGIN 12 | BLOCK "StringFileInfo" 13 | BEGIN 14 | BLOCK "080904E4" 15 | BEGIN 16 | VALUE "CompanyName", "ZH_CN NetWork\0" 17 | VALUE "FileDescription", "Portable DLL for Mozilla by adonais\0" 18 | VALUE "FileVersion", "9.0.7" 19 | VALUE "InternalName", "Portable\0" 20 | VALUE "LegalCopyright", "License: BSD 2\0" 21 | VALUE "OriginalFilename", "Portable.dll\0" 22 | VALUE "ProductName", "Portable.dll" 23 | VALUE "ProductVersion", "9.0.7" 24 | END 25 | END 26 | 27 | BLOCK "VarFileInfo" 28 | BEGIN 29 | VALUE "Translation", 0x809, 1252 30 | END 31 | END 32 | 33 | #endif // !_MAC 34 | 35 | #endif // _APP_RES_INVOKED_ 36 | -------------------------------------------------------------------------------- /src/safe_ex.h: -------------------------------------------------------------------------------- 1 | #ifndef _SAFE_EX_H_ 2 | # define _SAFE_EX_H_ 3 | 4 | #define LIBTBL_LOCK (L"LIBPORTABLE_LAUNCHER_PROCESS=1") 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern HANDLE g_mutex; 11 | extern unsigned __stdcall init_safed(void); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* end _SAFE_EX_H_ */ -------------------------------------------------------------------------------- /src/set_env.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "set_env.h" 7 | #include "general.h" 8 | #include "ini_parser.h" 9 | 10 | #define MAX_ENV_SIZE 8192 11 | typedef int (__cdecl *setenv_ptr)(const wchar_t *env); 12 | static setenv_ptr crt_setenv; 13 | 14 | /* * * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 15 | * 字符串大写字母转为小写 16 | */ 17 | static 18 | char *strlowr(char *str) 19 | { 20 | char *orign=str; 21 | for (; *str!='\0'; str++) 22 | { 23 | *str = tolower(*str); 24 | } 25 | return orign; 26 | } 27 | 28 | /* * * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 29 | * 在 PE 输入表查找 crt 文件, 把 crt 文件名写入crt_buf缓冲区 30 | */ 31 | static bool 32 | find_mscrt(void *hmod, WCHAR *crt_buf, int len) 33 | { 34 | bool ret = false; 35 | IMAGE_OPTIONAL_HEADER *pheader; 36 | IMAGE_IMPORT_DESCRIPTOR *pimport; 37 | IMAGE_DOS_HEADER *pdos = (IMAGE_DOS_HEADER *) hmod; 38 | if (!pdos || !crt_buf || !len) 39 | { 40 | return false; 41 | } 42 | pheader = (IMAGE_OPTIONAL_HEADER *) ((BYTE *) hmod + pdos->e_lfanew + SIZE_OF_NT_SIGNATURE + sizeof(IMAGE_FILE_HEADER)); 43 | pimport = (IMAGE_IMPORT_DESCRIPTOR *) ((BYTE *) hmod + pheader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); 44 | *crt_buf = L'\0'; 45 | while (true) 46 | { 47 | char name[CRT_LEN + 1] = {0}; 48 | IMAGE_THUNK_DATA *pThunk = (PIMAGE_THUNK_DATA)(uintptr_t) pimport->Characteristics; 49 | IMAGE_THUNK_DATA *pThunkIAT = (PIMAGE_THUNK_DATA)(uintptr_t) pimport->FirstThunk; 50 | if (pThunk == 0 && pThunkIAT == 0) 51 | { 52 | break; 53 | } 54 | const char *dll_name = (const char *) ((BYTE *) hmod + pimport->Name); 55 | if (PathMatchSpecA(dll_name, "api-ms-win-crt-environment-*.dll") || PathMatchSpecA(dll_name, "msvcr*.dll")) 56 | { 57 | strncpy(name, dll_name, CRT_LEN); 58 | ret = MultiByteToWideChar(CP_UTF8, 0, strlowr(name), -1, crt_buf, len) > 0; 59 | break; 60 | } 61 | pimport++; 62 | } 63 | return ret; 64 | } 65 | 66 | /* * * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 67 | * 检测是否链接新版c库, 移除了旧的兼容代码 68 | */ 69 | 70 | static bool 71 | init_process_envp(void) 72 | { 73 | WCHAR crt_names[CRT_LEN + 1] = {0}; 74 | if (find_mscrt(dll_module, crt_names, CRT_LEN) && *crt_names == L'a') 75 | { 76 | #ifdef _LOGDEBUG 77 | logmsg("ok, The /MD build was also used\n"); 78 | #endif 79 | crt_setenv = _wputenv; 80 | return true; 81 | } 82 | return false; 83 | } 84 | 85 | /* * * ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 86 | * 导入Env区段下的环境变量,忽略NpluginPath与TmpDataPath,因为前面已经读入变量了. 87 | * 因为crt版本的差异,以及链接方式的不同,先查询dll与目标加载crt的方式. 88 | */ 89 | void WINAPI 90 | setenv_tt(void) 91 | { 92 | ini_cache plist = NULL; 93 | if (init_process_envp()) 94 | { 95 | wchar_t env_buf[EXCLUDE_NUM][VALUE_LEN]; 96 | crt_setenv(L"LIBPORTABLE_SETENV_DEFINED=1"); 97 | if ((plist = iniparser_create_cache(ini_portable_path, false, true)) != NULL) 98 | { 99 | char *val_str = NULL; 100 | if (inicache_read_string("Env", "NpluginPath", &val_str, &plist)) 101 | { 102 | WCHAR plugin_str[VALUE_LEN] = {L'M',L'O',L'Z',L'_',L'P',L'L',L'U',L'G',L'I', 103 | L'N',L'_',L'P',L'A',L'T',L'H',L'=',0}; 104 | int envlen = (int)wcslen(plugin_str); 105 | MultiByteToWideChar(CP_UTF8, 0, val_str, -1, plugin_str+envlen, VALUE_LEN-envlen); 106 | path_to_absolute(plugin_str+envlen, VALUE_LEN-envlen); 107 | crt_setenv(plugin_str); 108 | free(val_str); 109 | } 110 | if (inicache_read_int("General", "Portable", &plist) > 0) 111 | { 112 | WCHAR env_appdt[MAX_BUFF] = {0}; 113 | WCHAR env_localdt[MAX_BUFF] = {0}; 114 | if (get_file_version() > 131 && _wgetenv(L"XRE_PROFILE_PATH") == NULL && !cmd_has_setup()) 115 | { 116 | if (*xre_profile_path) 117 | { 118 | wnsprintfW(env_appdt, MAX_BUFF, L"XRE_PROFILE_PATH=%ls", xre_profile_path); 119 | } 120 | if (*xre_profile_local_path) 121 | { 122 | wnsprintfW(env_localdt, MAX_BUFF, L"XRE_PROFILE_LOCAL_PATH=%ls", xre_profile_local_path); 123 | } 124 | if (env_appdt[0]) 125 | { 126 | crt_setenv(env_appdt); 127 | #ifdef _LOGDEBUG 128 | logmsg("we setup XRE_PROFILE_PATH\n"); 129 | #endif 130 | } 131 | if (env_localdt[0]) 132 | { 133 | crt_setenv(env_localdt); 134 | } 135 | } 136 | if (!cmd_has_profile(NULL, 0)) 137 | { 138 | crt_setenv(L"MOZ_LEGACY_PROFILES=0"); 139 | crt_setenv(L"SNAP_NAME=firefox"); 140 | #ifdef _LOGDEBUG 141 | logmsg("disable multipath configuration\n"); 142 | #endif 143 | } 144 | #ifdef _LOGDEBUG 145 | else 146 | { 147 | logmsg("browser profile boot\n"); 148 | } 149 | #endif 150 | } 151 | if (inicache_foreach_wkey("Env", env_buf, EXCLUDE_NUM, &plist)) 152 | { 153 | for (int i = 0; i < EXCLUDE_NUM && *env_buf[i] != L'\0'; ++i) 154 | { 155 | if (_wcsnicmp(env_buf[i], L"NpluginPath", 11) && 156 | _wcsnicmp(env_buf[i], L"TmpDataPath", 11)) 157 | { 158 | crt_setenv(env_buf[i]); 159 | } 160 | } 161 | } 162 | iniparser_destroy_cache(&plist); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/set_env.h: -------------------------------------------------------------------------------- 1 | #ifndef _SET_ENV_H_ 2 | # define _SET_ENV_H_ 3 | 4 | #define CRT_LEN 128 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern void __stdcall setenv_tt(void); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif /* end _SET_ENV_H_ */ -------------------------------------------------------------------------------- /src/win_registry.c: -------------------------------------------------------------------------------- 1 | #include "general.h" 2 | #include "win_registry.h" 3 | #include 4 | #include 5 | 6 | typedef LONG (WINAPI *RegOpenKeyExPtr)(HKEY, LPCWSTR, DWORD, REGSAM, PHKEY); 7 | static RegOpenKeyExPtr pRegOpenKeyExW, sRegOpenKeyExWStub; 8 | 9 | static LONG WINAPI 10 | HookRegOpenKeyExW(HKEY hKey, 11 | LPCWSTR lpSubKey, 12 | DWORD ulOptions, 13 | REGSAM samDesired, 14 | PHKEY phkResult) 15 | { 16 | if ( lpSubKey && 17 | (StrStrIW(lpSubKey, L"\\Extensions") || 18 | StrStrIW(lpSubKey, L"\\MozillaPlugins") || 19 | StrStrIW(lpSubKey, L"\\QuickTimePlayer.exe") || 20 | StrStrIW(lpSubKey, L"\\wmplayer.exe") || 21 | StrStrIW(lpSubKey, L"\\Adobe\\")) ) 22 | { 23 | #ifdef _LOGDEBUG 24 | logmsg("lpSubKey[%ls]\n", lpSubKey); 25 | #endif 26 | return ERROR_REGISTRY_IO_FAILED; 27 | } 28 | return sRegOpenKeyExWStub(hKey, lpSubKey, ulOptions, samDesired, phkResult); 29 | } 30 | 31 | unsigned WINAPI init_winreg(void * pParam) 32 | { 33 | HMODULE m_adv = GetModuleHandleW(L"advapi32.dll"); 34 | if ( m_adv && (pRegOpenKeyExW = (RegOpenKeyExPtr)GetProcAddress(m_adv, "RegOpenKeyExW")) != NULL ) 35 | { 36 | return creator_hook(pRegOpenKeyExW, HookRegOpenKeyExW, (LPVOID*)&sRegOpenKeyExWStub); 37 | } 38 | return (0); 39 | } 40 | -------------------------------------------------------------------------------- /src/win_registry.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIN_REGISTRY_H_ 2 | # define _WIN_REGISTRY_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern unsigned __stdcall init_winreg(void *); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif /* end _WIN_REGISTRY_H_ */ 15 | --------------------------------------------------------------------------------