//windows_x86
#pragma once
volatile bool __cdecl _memset(void *_dst, int _val, size_t _nlen);
volatile bool __cdecl _memxch(void *_dst, void *_src, size_t _nlen);
volatile bool __cdecl _memxch_s(void *_dst, void *_src, size_t _nlen);
volatile bool __cdecl _memcpy(void *_dst, const void *_src, size_t _nlen);
volatile bool __cdecl _memcmp(const void *_dst, const void *_src, size_t _nlen);
#include "stdafx.h"
#include "almem.h"
volatile __declspec(naked) bool __cdecl _memset(void *_dst, int _val, size_t _nlen)
{
_asm
{
push ebp
mov ebp,esp
push edi
mov edi, dword ptr ss : [esp+0x0C]
cmp edi,0x00
jz _error
push ecx
mov ecx, dword ptr ss : [esp+0x18]
mov al, byte ptr ss : [esp+0x014]
rep stos byte ptr es : [edi]
mov ax,0x01
_quit :
pop ecx
pop edi
leave
ret
_error :
mov ax,0x00
jmp _quit
nop
nop
nop
nop
}
}
volatile __declspec(naked) bool __cdecl _memxch(void *_dst, void *_src, size_t _nlen)
{
_asm
{
push ebp
mov ebp,esp
mov eax, dword ptr ss : [esp+0x08]
cmp eax,0x00
jz _error
push esi
mov esi, dword ptr ss : [esp+0x10]
cmp esi,0x00
jz _error
cmp eax,esi
je _error
push ebx
mov ebx, dword ptr ss : [esp+0x18]
sub esp,ebx
mov edi,esp
mov ecx,ebx
rep movs //xchg reg,[reg/adr]
lea edx,dword ptr es : [edi-0x01]
sub esi,ebx
mov edi,esi
mov esi,eax
mov ecx,ebx
rep movs
std
lea edi,dword ptr es : [esi-0x01]
mov esi,edx
mov ecx,ebx
rep movs
cld
add esp,ebx
mov ax,0x01
_quit :
pop ebx
pop esi
leave
ret
_error :
mov ax,0x00
jmp _quit
nop
nop
nop
nop
}
}
volatile __declspec(naked) bool __cdecl _memxch_s(void *_dst, void *_src, size_t _nlen)
{
_asm
{
push ebp
mov ebp,esp
push edi
mov edi, dword ptr ss : [esp+0x0C]
cmp edi,0x00
je _error
push esi
mov esi, dword ptr ss : [esp+0x14]
cmp esi,0x00
je _error
cmp edi,esi
je _error
push ecx
mov ecx, dword ptr ss : [esp+0x1C]
mov edx,ecx
shr ecx,0x02
_next_dword :
cmp ecx,0x00
je _next_sing
mov eax, dword ptr es : [edi]
mov ebx, dword ptr es : [esi]
xor eax,ebx
xor ebx,eax
mov dword ptr es : [esi], ebx
xor eax,ebx
mov dword ptr es : [edi], eax
add edi,0x04
add esi,0x04
dec ecx
jmp _next_dword
_next_sing :
mov ecx,edx
and ecx,0x03
jnz _next_byte
_quit :
mov ax,0x01
pop ecx
pop esi
pop edi
leave
ret
_next_byte :
cmp ecx, 0x00
je _quit
mov al, byte ptr es : [edi]
mov bl, byte ptr es : [esi]
xor al,bl
xor bl,al
mov byte ptr es : [esi],bl
xor al,bl
mov byte ptr es : [edi],al
inc edi
inc esi
dec ecx
jmp _next_byte
_error :
mov ax,0x00
pop ecx
pop esi
pop edi
leave
ret
nop
nop
nop
nop
}
}
volatile __declspec(naked) bool __cdecl _memcpy(void *_dst, const void *_src, size_t _nlen)
{
_asm
{
push ebp
mov ebp,esp
push edi
mov edi, dword ptr ss : [esp+0x0C]
cmp edi,0x00
jz _error
push esi
mov esi, dword ptr ss : [esp+0x14]
cmp esi,0x00
jz _error
cmp edi,esi
je _error
push ecx
mov ecx, dword ptr ss : [esp+0x1C]
mov edx,ecx
shr ecx,0x02
rep movs dword ptr es : [edi], dword ptr es : [esi]
mov ecx,edx
and ecx,0x03
je _quit
rep movs byte ptr es : [edi], byte ptr es : [esi]
_quit :
mov ax,0x01
pop ecx
pop esi
pop edi
leave
ret
_error :
mov ax,0x00
jmp _quit
nop
nop
nop
nop
}
}
volatile __declspec(naked) bool __cdecl _memcmp(const void *_dst, const void *_src, size_t _nlen)
{
_asm
{
push ebp
mov ebp,esp
push edi
mov edi, dword ptr ss : [esp+0x0C]
cmp edi,0x00
jz _error
push esi
mov esi, dword ptr ss : [esp+0x14]
cmp esi,0x00
jz _error
cmp edi,esi
je _quit
push ecx
mov ecx, dword ptr ss : [esp+0x1C]
mov edx,ecx
shr ecx,0x02
repe cmps dword ptr es : [edi], dword ptr es : [esi]
jne _error
mov ecx,edx
and ecx,0x03
jnz _next_byte
_quit :
mov ax,0x01
pop ecx
pop esi
pop edi
leave
ret
_next_byte :
repe cmps byte ptr es : [edi], byte ptr es : [esi]
je _quit
_error :
mov ax, 0x00
pop ecx
pop esi
pop edi
leave
ret
nop
nop
nop
nop
}
}