diff --git a/Makefile b/Makefile index 3fca117..6890feb 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,6 @@ LDFLAGS := \ -lkernel32 \ -luser32 \ third_party/msvcrt/msvcrt.lib \ - third_party/msvcrt/rtsyms.o \ -Wl,--enable-stdcall-fixup \ -s @@ -35,7 +34,8 @@ OBJS := \ obj/ijl15.o \ obj/json.o \ obj/patch.o \ - obj/regex.o + obj/regex.o \ + obj/stubs.o TESTOBJS := \ $(OBJS) \ @@ -56,6 +56,9 @@ all: $(OUT) $(TESTOUT) $(OBJDIR)%.o: $(SRCDIR)%.c @mkdir -p "$(dir $@)" $(CC) -c $(CFLAGS) "$<" -o "$@" +$(OBJDIR)%.o: $(SRCDIR)%.S + @mkdir -p "$(dir $@)" + $(CC) -c $(CFLAGS) "$<" -o "$@" $(OUT): $(OBJS) @mkdir -p "$(dir $@)" $(CC) $(OBJS) $(LDFLAGS) -shared -o "$@" export.def -Wl,-e_DllMain diff --git a/rugburn.vcxproj b/rugburn.vcxproj index 08485a2..8ba6ef9 100644 --- a/rugburn.vcxproj +++ b/rugburn.vcxproj @@ -201,15 +201,31 @@ + + Document + ml /c /Fo$(OutDir)%(Filename).obj %(FullPath) + $(OutDir)%(Filename).obj + ml /c /Fo$(OutDir)%(Filename).obj %(FullPath) + $(OutDir)%(Filename).obj + ml /c /Fo$(OutDir)%(Filename).obj %(FullPath) + $(OutDir)%(Filename).obj + ml /c /Fo$(OutDir)%(Filename).obj %(FullPath) + $(OutDir)%(Filename).obj + false + false + false + false + Object + Object + Object + Object + - - - diff --git a/src/common.c b/src/common.c index d614981..101a359 100644 --- a/src/common.c +++ b/src/common.c @@ -27,82 +27,11 @@ static PSTR pszLogPrefix = NULL; #pragma function(memcmp) #pragma function(memcpy) #pragma function(memset) - -void __declspec(naked) _aullshr() { - __asm { - cmp cl,40h - jae RETZERO - cmp cl,20h - jae MORE32 - shrd eax,edx,cl - shr edx,cl - ret -MORE32: - mov eax,edx - xor edx,edx - and cl,1Fh - shr eax,cl - ret -RETZERO: - xor eax,eax - xor edx,edx - ret - } -} #else void __chkstk_ms(void) { return; } unsigned long long __stdcall _aullshr(unsigned long long a, long b) { return a >> b; } #endif -// C standard library functions -int strcmp(LPCSTR dest, LPCSTR src) { - int cmp; - do { - cmp = *dest - *src; - if (cmp > 0) { - return 1; - } else if (cmp < 0) { - return -1; - } - } while (*dest++ && *src++); - return 0; -} - -int memcmp(LPCVOID dest, LPCVOID src, size_t size) { - LPCSTR bdest = (LPCSTR)dest; - LPCSTR bsrc = (LPCSTR)src; - int cmp; - while (size > 0) { - cmp = *bdest++ - *bsrc++; - if (cmp > 0) { - return 1; - } else if (cmp < 0) { - return -1; - } - --size; - } - return 0; -} - -PVOID memcpy(PVOID dest, VOID const *src, size_t size) { - BYTE *bdest = (BYTE *)dest; - BYTE const *bsrc = (BYTE const *)src; - while (size > 0) { - *bdest++ = *bsrc++; - --size; - } - return dest; -} - -PVOID memset(PVOID p, INT c, UINT size) { - PCHAR data = (PCHAR)p; - while (size > 0) { - *data++ = c; - --size; - } - return p; -} - // String formatting int VSPrintfZ(LPSTR dest, LPCSTR fmt, va_list args) { return wvsprintfA(dest, fmt, args); } diff --git a/src/stubs.S b/src/stubs.S new file mode 100644 index 0000000..bcf87f4 --- /dev/null +++ b/src/stubs.S @@ -0,0 +1,34 @@ +.intel_syntax noprefix + +.global __fltused +.set __fltused, 0x9876 + +.global __ldused +.set __ldused, 0x9876 + +.global __except_list +.set __except_list, 0 + +.section .text + +.global __aullshr +__aullshr: + cmp cl, 0x40 + jae retzero + cmp cl, 0x20 + jae more32 + shrd eax, edx, cl + shr edx, cl + ret +more32: + mov eax, edx + xor edx, edx + and cl, 0x1f + shr eax, cl + ret +retzero: + xor eax, eax + xor edx, edx + ret + +.end diff --git a/src/stubs.asm b/src/stubs.asm new file mode 100644 index 0000000..1e6c6be --- /dev/null +++ b/src/stubs.asm @@ -0,0 +1,36 @@ +.386 +.model flat + +.code + +public __fltused +__fltused equ 9876h + +public __ldused +__ldused equ 9876h + +public __except_list +__except_list equ 0 + +public __aullshr +__aullshr PROC + cmp cl, 40h + jae retzero + cmp cl, 20h + jae more32 + shrd eax, edx, cl + shr edx, cl + ret +more32: + mov eax, edx + xor edx, edx + and cl, 1Fh + shr eax, cl + ret +retzero: + xor eax, eax + xor edx, edx + ret +__aullshr ENDP + +END diff --git a/third_party/msvcrt/rtsyms.o b/third_party/msvcrt/rtsyms.o deleted file mode 100644 index 7086f07..0000000 Binary files a/third_party/msvcrt/rtsyms.o and /dev/null differ