News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

some bug and modify

Started by zrj99, April 19, 2009, 06:04:34 AM

Previous topic - Next topic

zrj99

Hello, Pelle!
This soft is very good for me. I'm Chinese. But I found some bug in IDE and compiler.
1. When save source file(included Chinese char) IDE will raise exception.
   It's because source editor use UNICODE, so I input and browe source file included Chinese  char. When saving, IDE convert source to ANSI(default), exception raised. It's may be you send error parameter to API function - WideCharToMultiByte...(Use OllyDbg)

004AEB6A   |.  6A 00     |push    0                          ; /pDefaultCharUsed = NULL
004AEB6C   |.  6A 00     |push    0                          ; |pDefaultChar = NULL
004AEB6E   |.  8B45 F8   |mov     eax, dword ptr [ebp-8]     ; |
004AEB71   |.  8945 F0   |mov     dword ptr [ebp-10], eax    ; |
004AEB74   |.  F7D8      |neg     eax                        ; |
004AEB76   |.  01F0      |add     eax, esi                   ; |
004AEB78   |.  D1F8      |sar     eax, 1                     ; |
004AEB7A   |.  8D50 01   |lea     edx, dword ptr [eax+1]     ; |
004AEB7D   |.  52        |push    edx                        ; |MultiByteCount
004AEB7E   |.  8B55 FC   |mov     edx, dword ptr [ebp-4]     ; |
004AEB81   |.  52        |push    edx                        ; |MultiByteStr
004AEB82   |.  50        |push    eax                        ; |WideCharCount
004AEB83   |.  8B45 F0   |mov     eax, dword ptr [ebp-10]    ; |
004AEB86   |.  50        |push    eax                        ; |WideCharStr
004AEB87   |.  6A 00     |push    0                          ; |Options = 0
004AEB89   |.  6A 00     |push    0                          ; |CodePage = CP_ACP
004AEB8B   |.  FF15 D45B>|call    dword ptr [<&KERNEL32.Wide>; \WideCharToMultiByte


at 004AEB78 the dest buffer length too short. Modified to

004AEB6E   |.  8B45 F8   |mov     eax, dword ptr [ebp-8]     ; |
004AEB71   |.  8945 F0   |mov     dword ptr [ebp-10], eax    ; |
004AEB74   |.  F7D8      |neg     eax                        ; |
004AEB76   |.  01F0      |add     eax, esi                   ; |
004AEB7A   |.  8D50 01   |lea     edx, dword ptr [eax+1]     ; |
004AEB7D   |.  52        |push    edx                        ; |MultiByteCount
004AEB7E   |.  8B55 FC   |mov     edx, dword ptr [ebp-4]     ; |
004AEB81   |.  52        |push    edx                        ; |MultiByteStr
004AEB78   |.  D1F8      |sar     eax, 1                     ; |
004AEB82   |.  50        |push    eax                        ; |WideCharCount
004AEB83   |.  8B45 F0   |mov     eax, dword ptr [ebp-10]    ; |
004AEB86   |.  50        |push    eax                        ; |WideCharStr
004AEB87   |.  6A 00     |push    0                          ; |Options = 0
004AEB89   |.  6A 00     |push    0                          ; |CodePage = CP_ACP
004AEB8B   |.  FF15 D45B>|call    dword ptr [<&KERNEL32.Wide>; \WideCharToMultiByte

Here move "004AEB78 sar eax, 1" position after 004AEB81.
So, this bug was cracked OK.

2. If source file length about 4096 bytes, it may be error. I think it is because memory alloc logical error.

004AED7A test byte ptr [ecx+18], 10
004AED83 sentne al
004AED86 and eax, 1
004AED89 add eax, ebx
004AED8B pop ebx
004AED8C retn 4

modified to

004AED7A mov ebx, 1
004AED7F mov eax, ebx
004AED81 shl eax, 1
004AED83 pop ebx
004AED84 retn 4

So, this bug was cracked OK.

3. When debuging, the (char *) Symbol value appear error if string included Chinese.
It is because there has a logical error in POIDE source code.
Your code (sub_427A20):

char *pSrc = ...;
wchar_t *pDst = ...;

*pDst++ = L'\"';
while(*pSrc)
{
    if(IsEscape(*pSrc))
        ConvertToWCharStr(&pDst, &pSrc);
    else
        *pDst++ = *pSrc++;  // bug, a BYTE could not equ a CHAR
}
*pDst++ = L'\"';
*pDst = L'\0';

You maybe modified it to:

char *pSrc = ...;
wchar_t *pTmp = ...;
MultiByteToWideChar(pSrc, pTmp);  // first convert, then convert Escape sequence

wchar_t *pDst = ...;

*pDst++ = L'\"';
while(*pTmp)
{
    if(IsEscape(*pTmp))
        ConvertToWCharStr(&pDst, &pTmp);
    else
        *pDst++ = *pTmp++;  // so, a wchar_t IS a CHAR
}
*pDst++ = L'\"';
*pDst = L'\0';

So, this bug was cracked OK.

Thank Pelle for your excellent kit and Sorry my poor English.

Ref Topic: can't support chinese string resource (at http://forum.pellesc.de/index.php?topic=2243.0)


Pelle

If I find any obvious and general bugs they will be fixed, but since I don't speak/understand Chinese myself there will be no "extras" to make it work. I'm just not that interested...
/Pelle