From 367d9f6f71420e4c7ed5f273e04d280655bb3d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Mon, 24 Dec 2012 21:30:41 +0000 Subject: SMS plugin adopted (32bit version only) git-svn-id: http://svn.miranda-ng.org/main/trunk@2831 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../SMS/src/AdditionalFunctions/MemoryCompare.h | 177 +++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 plugins/SMS/src/AdditionalFunctions/MemoryCompare.h (limited to 'plugins/SMS/src/AdditionalFunctions/MemoryCompare.h') diff --git a/plugins/SMS/src/AdditionalFunctions/MemoryCompare.h b/plugins/SMS/src/AdditionalFunctions/MemoryCompare.h new file mode 100644 index 0000000000..de663c6d8a --- /dev/null +++ b/plugins/SMS/src/AdditionalFunctions/MemoryCompare.h @@ -0,0 +1,177 @@ +#if !defined(AFX_MEMORYCOMPARE__H__INCLUDED_) +#define AFX_MEMORYCOMPARE__H__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + + +// If the string pointed to by lpString1 is less than the string pointed +// to by lpString2, the return value is negative. +// If the string pointed to by lpString1 is greater than the string pointed +// to by lpString2, the return value is positive. +// If the strings are equal, the return value is zero. +// +// lpString1> ret=1=CSTR_LESS_THAN +// lpString1=lpString2 >> ret=2=CSTR_EQUAL +// lpString1>lpString2 >> ret=3=CSTR_GREATER_THAN + + +/*__inline DWORD MemoryCompare(LPCVOID lpcSource1,SIZE_T dwSource1Size,LPCVOID lpcSource2,SIZE_T dwSource2Size) +{ + DWORD dwRet; + + __asm + { + mov ecx,dwSource1Size //; ecx = Source string 1 Size + cmp ecx,dwSource2Size //; сверяем длинны участков памяти + jg short greater_than + jl short less_than + test ecx,ecx + jz short equal //; NULL=NULL + + mov esi,lpcSource1 //; edi = Source string 1 + mov edi,lpcSource2 //; esi = Source string 2 + cmp edi,esi //; сверяем указатели на участки памяти + je short equal //; это один и тотже участок, они естественно равны + + test esi,esi //; lpcSource1=NULL, lpcSource1lpcSource2 + jz short greater_than //; CSTR_GREATER_THAN + + //cld //; сканируя в прямом направлении + + repe cmpsb //; цикл сравнения. + cmp_loop: + //sub ecx,4 + //jz short equal + + //inc esi + //inc edi + //mov al,byte ptr [esi] + //cmpsd + //cmp al,byte ptr [edi] + //je short cmp_loop + jg short greater_than + jl short less_than + + equal: //; если мы попали сюда, значит, они + mov dwRet,CSTR_EQUAL //; совпадают (match) + jmp end_func + less_than: //; не совпадают + mov dwRet,CSTR_LESS_THAN + jmp end_func + greater_than: + mov dwRet,CSTR_GREATER_THAN + + end_func: + } +return(dwRet); +}//*/ + +__inline DWORD MemoryCompare(LPCVOID lpcSource1,SIZE_T dwSource1Size,LPCVOID lpcSource2,SIZE_T dwSource2Size) +{ + DWORD dwRet; + + if (dwSource1Size==dwSource2Size) + { + if (lpcSource1==lpcSource2) + { + dwRet=CSTR_EQUAL; + }else{ + if (lpcSource1 && lpcSource2) + { +#ifdef _INC_MEMORY + dwRet=(2+memcmp(lpcSource1,lpcSource2,dwSource1Size)); +#else + SIZE_T dwDiffPosition; + + //dwDiffPosition=RtlCompareMemory(lpcSource1,lpcSource2,dwSource1Size); + for(dwDiffPosition=0; (dwDiffPosition(*((BYTE*)(((SIZE_T)lpcSource2)+dwDiffPosition)))) + { + dwRet=CSTR_GREATER_THAN; + }else{ + dwRet=CSTR_LESS_THAN; + } + } +#endif + }else{ + if (lpcSource1) + {//lpcSource2==NULL + dwRet=CSTR_GREATER_THAN; + }else{//lpcSource1==NULL + dwRet=CSTR_LESS_THAN; + } + } + } + }else{ + if (dwSource1Size(*((BYTE*)(((SIZE_T)lpcSource2)+dwDiffPosition)))) + { + dwRet=CSTR_GREATER_THAN; + }else{ + dwRet=CSTR_LESS_THAN; + } + } + + if (pdwDiffPosition) (*pdwDiffPosition)=dwDiffPosition; + }else{ + if (lpcSource1) + {//lpcSource2==NULL + dwRet=CSTR_GREATER_THAN; + }else{//lpcSource1==NULL + dwRet=CSTR_LESS_THAN; + } + } + } + }else{ + if (dwSource1Size