Skip to content

Commit

Permalink
more posix support and change makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizuku committed Apr 4, 2024
1 parent b391d4c commit 7c84421
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 103 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/yurisizuku/reversetool?color=green&label=ReverseTool)![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/YuriSizuku/ReverseTool/build_wintools.yml?label=build_wintools)

This repo contains some libraries for my reverse projects.
The building example is in `project`, support for `Makefile` for `tcc`, `gcc` and `msvc`.
Some libraries (single header) for my reverse projects.
In `project`, `Makefile` for `gcc` (llvm-mingw or mingw-w64), `tcc` (not support inline) and `sln` for `msvc`.

Scripts for localization are moved to [LocalizationTool](https://github.com/YuriSizuku/LocalizationTool).

Expand Down
22 changes: 11 additions & 11 deletions project/windll_winhook/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# build example
# make libwinhook helloexe hellodll libwinhook_test CC=i686-w64-mingw32-gcc BUILD=32d
# make libwinhook helloexe hellodll libwinhook_test CC=x86_64-w64-mingw32-gcc BUILD=64d
# make libwinhook helloexe hellodll libwinhook_test CC=i686-w64-mingw32-gcc BUILD_TYPE=32d
# make libwinhook helloexe hellodll libwinhook_test CC=x86_64-w64-mingw32-gcc BUILD_TYPE=64d
# wine build/libwinhook_test32d.exe && wine build/libwinhook_test64d.exe

# general config
CC:=gcc # clang (llvm-mingw), gcc (mingw-w64), tcc (x86 stdcall name has problem)
BUILD:=32# 32, 32d, 64, 64d
BUILD_TYPE:=32# 32, 32d, 64, 64d
BUILD_DIR:=build
INCS:=-I../../src
LIBS:=-luser32 -lgdi32 -lpsapi
CFLAGS:=-fPIC -std=gnu99 \
CFLAGS:=-fPIC -std=c99 \
-fvisibility=hidden \
-ffunction-sections -fdata-sections
LDFLAGS:=-Wl,--enable-stdcall-fixup \
-Wl,--kill-at \
-Wl,--gc-sections

# build config
ifneq (,$(findstring 64, $(BUILD)))
ifneq (,$(findstring 64, $(BUILD_TYPE)))
CFLAGS+=-m64
else
CFLAGS+=-m32
endif
ifneq (,$(findstring d, $(BUILD)))
ifneq (,$(findstring d, $(BUILD_TYPE)))
CFLAGS+=-g -D_DEBUG
else
CFLAGS+=-Os
Expand All @@ -44,28 +44,28 @@ prepare:

libwinhook: src/libwinhook.c
@echo "## $@"
$(CC) -shared $^ -o $(BUILD_DIR)/$@$(BUILD).dll \
$(CC) -shared $^ -o $(BUILD_DIR)/$@$(BUILD_TYPE).dll \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)

libwinhook_test: src/libwinhook_test.c
@echo "## $@"
$(CC) $< -o $(BUILD_DIR)/$@$(BUILD).exe \
-L$(BUILD_DIR) -lwinhook$(BUILD) -DWINHOOK_NOINLINE \
$(CC) $< -o $(BUILD_DIR)/$@$(BUILD_TYPE).exe \
-L$(BUILD_DIR) -lwinhook$(BUILD_TYPE) -DWINHOOK_NOINLINE \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)

helloexe: src/helloexe.c
@echo "## $@"
@echo \#\#building $@ ...
$(CC) $< -o $(BUILD_DIR)/hello$(BUILD).exe \
$(CC) $< -o $(BUILD_DIR)/hello$(BUILD_TYPE).exe \
$(CFLAGS) -lgdi32 -luser32 \
-Wl,-subsystem,windows -municode

hellodll: src/hellodll.c
@echo "## $@"
@echo \#\#building $@ ...
$(CC) -shared $< -o $(BUILD_DIR)/hello$(BUILD).dll \
$(CC) -shared $< -o $(BUILD_DIR)/hello$(BUILD_TYPE).dll \
$(CFLAGS) -luser32

.PHONY: all clean prepare libwinhook helloexe hellodll
18 changes: 9 additions & 9 deletions project/windll_winpe/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# build example
# make libwinpe libwinpe_test CC=i686-w64-mingw32-gcc BUILD=32d
# make libwinpe libwinpe_test CC=x86_64-w64-mingw32-gcc BUILD=64d
# make libwinpe libwinpe_test CC=i686-w64-mingw32-gcc BUILD_TYPE=32d
# make libwinpe libwinpe_test CC=x86_64-w64-mingw32-gcc BUILD_TYPE=64d
# wine build/libwinpe_test32d.exe && wine build/libwinpe_test64d.exe

# general config
CC:=gcc # clang (llvm-mingw), gcc (mingw-w64), tcc (x86 stdcall name has problem)
BUILD:=32# 32, 32d, 64, 64d
BUILD_TYPE:=32# 32, 32d, 64, 64d
BUILD_DIR:=build
INCS:=-I../../src
LIBS:=-luser32 -lgdi32 -lpsapi
CFLAGS:=-fPIC -std=c99 \
CFLAGS:=-fPIC -std=gnu99 \
-fvisibility=hidden \
-ffunction-sections -fdata-sections
LDFLAGS:=-Wl,--enable-stdcall-fixup \
-Wl,--kill-at \
-Wl,--gc-sections

# build config
ifneq (,$(findstring 64, $(BUILD)))
ifneq (,$(findstring 64, $(BUILD_TYPE)))
CFLAGS+=-m64
else
CFLAGS+=-m32
endif
ifneq (,$(findstring d, $(BUILD)))
ifneq (,$(findstring d, $(BUILD_TYPE)))
CFLAGS+=-g -D_DEBUG
else
CFLAGS+=-Os
Expand All @@ -42,15 +42,15 @@ prepare:

libwinpe: src/libwinpe.c
@echo "## $@"
$(CC) -shared $^ -o $(BUILD_DIR)/$@$(BUILD).dll \
$(CC) -shared $^ -o $(BUILD_DIR)/$@$(BUILD_TYPE).dll \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)

# can not use tcc here
libwinpe_test: src/libwinpe_test.c
@echo "## $@"
$(CC) $< -o $(BUILD_DIR)/$@$(BUILD).exe \
-L$(BUILD_DIR) -lwinpe$(BUILD) -DWINPE_NOINLINE \
$(CC) $< -o $(BUILD_DIR)/$@$(BUILD_TYPE).exe \
-L$(BUILD_DIR) -lwinpe$(BUILD_TYPE) -DWINPE_NOINLINE \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)

Expand Down
117 changes: 37 additions & 80 deletions project/winexe_winloader/Makefile
Original file line number Diff line number Diff line change
@@ -1,97 +1,54 @@
# main config
LIBPREFIX?=./../../
ARCH?=i686
PREFIX?=./build

CC:=clang
INCS:=-I$(LIBPREFIX)src
LIBDIRS:=
# build example
# make winloader CC=i686-w64-mingw32-gcc WINDRES=i686-w64-mingw32-windres BUILD_TYPE=32d
# make winloader CC=x86_64-w64-mingw32-gcc WINDRES=x86_64-w64-mingw32-windres BUILD_TYPE=64d

# general config
CC:=gcc # clang (llvm-mingw), gcc (mingw-w64), tcc (x86 stdcall name has problem)
WINDRES:=windres
BUILD_TYPE:=32# 32, 32d, 64, 64d
BUILD_DIR:=build
INCS:=-I../../src
LIBS:=-luser32 -lgdi32 -lpsapi
CFLAGS:=-ffunction-sections\
-fdata-sections -std=c99
LDFLAGS:=

# arch config
ifeq ($(ARCH), x86_64)
ARCH_POSTFIX:=64
LIBDIRS+=-L$(LIBPREFIX)lib64
CFLAGS+=-D_WIN64
ifdef DEBUG
BUILD_POSTFIX:=64d
else
BUILD_POSTFIX:=64
endif
else # x86
ARCH_POSTFIX:=32
LIBDIRS+=-L$(LIBPREFIX)lib32
ifdef DEBUG
BUILD_POSTFIX:=32d
CFLAGS:=-fPIC -std=c99 \
-fvisibility=hidden \
-ffunction-sections -fdata-sections
LDFLAGS:=-Wl,--enable-stdcall-fixup \
-Wl,--kill-at \
-Wl,--gc-sections

# build config
ifneq (,$(findstring 64, $(BUILD_TYPE)))
CFLAGS+=-m64
ARCH_WINDRES=pe-x86-64
else
BUILD_POSTFIX:=32
endif
endif

# compiler config
ifneq (,$(findstring clang, $(CC)))
CFLAGS+=-target $(ARCH)-pc-windows-msvc \
-D_CRT_SECURE_NO_DEPRECATE
LDFLAGS+= -Wl,/OPT:REF\
-Wno-undefined-inline
else # mingw
CFLAGS+=-m$(ARCH_POSTFIX) \
-fPIC\
-fvisibility=hidden\
-fgnu89-inline\
-DWINPE_NOASM
ifneq (,$(findstring gcc, $(CC)))
LDFLAGS+=-lwinpthread \
-static-libgcc \
-static-libstdc++ \
-Wl,-Bstatic,--whole-archive \
-Wl,--no-whole-archive\
-Wl,--gc-sections\
-Wl,--enable-stdcall-fixup\
-Wl,--kill-at
endif
CFLAGS+=-m32
ARCH_WINDRES=pe-i386
endif

# optimization config
ifdef DEBUG
ifneq (,$(findstring d, $(BUILD_TYPE)))
CFLAGS+=-g -D_DEBUG
else
CFLAGS+=-Os
endif
LIBDIRS+=-L$(PREFIX)

# system config
ifeq ($(shell echo ${OS}), Windows_NT)
DLL_EXT=.dll
EXE_EXT=.exe
else
DLL_EXT?=.so
EXE_EXT?=
endif

# other config
ifneq (,$(findstring clang, $(CC)))
ifneq (,$(findstring tcc, $(CC)))
LDFLAGS= # tcc can not remove at at stdcall in i686
else
ifneq (,$(findstring gcc, $(CC)))
endif
endif

all: prepare\
winloader
all: prepare winloader

clean:
rm -rf $(PREFIX)/*winloader*
@rm -rf $(BUILD_DIR)/*winloader*

prepare:
@if ! [ -d $(PREFIX) ]; then mkdir -p $(PREFIX); fi
@if ! [ -d $(BUILD_DIR) ]; then mkdir -p $(BUILD_DIR); fi

$(BUILD_DIR)/winloader$(BUILD_TYPE).res: src/winloader.rc
$(WINDRES) $< -F $(ARCH_WINDRES) -O coff -o $@

winloader: src\winloader.c
@echo \#\#building $@ ...
$(CC) $< \
-o $(PREFIX)/$@$(BUILD_POSTFIX)$(EXE_EXT) \
$(CFLAGS) $(LDFLAGS) $(INCS) $(LIBS) $(LIBDIRS)
winloader: src/winloader.c $(BUILD_DIR)/winloader$(BUILD_TYPE).res
@echo "## $@"
$(CC) $^ -o $(BUILD_DIR)/$@$(BUILD_TYPE).exe \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)

.PHONY: all clean prepare winloader
Binary file modified project/winexe_winloader/src/resource.h
Binary file not shown.
Binary file removed project/winexe_winloader/src/winloader.aps
Binary file not shown.
2 changes: 1 addition & 1 deletion project/winexe_winloader/src/winloader.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <windows.h>
#define WINHOOK_IMPLEMENTATION
#define WINHOOK_NOINLINEHOOK
#define WINHOOK_NO3RDLIB
#include "winhook.h"

#ifndef _DEBUG
Expand Down
Binary file modified project/winexe_winloader/src/winloader.rc
Binary file not shown.
6 changes: 6 additions & 0 deletions src/windyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
#define EXPORT __attribute__((visibility("default")))
#endif
#endif // _MSC_VER
#if defined(__TINYC__) // fix tcc not support inline
#ifdef INLINE
#undef INLINE
#endif
#define INLINE
#endif

// define specific macro
#ifdef WINDYN_API
Expand Down
6 changes: 6 additions & 0 deletions src/winhook.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
#define EXPORT __attribute__((visibility("default")))
#endif
#endif // _MSC_VER
#if defined(__TINYC__) // fix tcc not support inline
#ifdef INLINE
#undef INLINE
#endif
#define INLINE
#endif

// define specific macro
#ifdef WINHOOK_API
Expand Down
6 changes: 6 additions & 0 deletions src/winpe.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
#ifdef WINPE_API_INLINE
#undef WINPE_API_INLINE
#endif
#if defined(__TINYC__) // fix tcc not support inline
#ifdef INLINE
#undef INLINE
#endif
#define INLINE
#endif

#ifdef WINPE_STATIC
#define WINPE_API_DEF static
Expand Down

0 comments on commit 7c84421

Please sign in to comment.