flat assembler
Message board for the users of flat assembler.

Index > Main > Bug in the code or bug in the fasm?

Author
Thread Post new topic Reply to topic
Everhest



Joined: 26 Jun 2008
Posts: 83
Location: Russia
Everhest 24 Nov 2008, 15:44
Hello, explain please that causes the mistake? debugger i not was able to find the reasons...
Code:
        proc name#.append title, text                              ; Íàäî ðàñæåâàòü
                add     [name#.LenTable], sizeof.BOOK32_TABLE_ITEM
                stdcall MemoryReSize, name#.table, [name#.LenTable]
                mov     [name#.table+4], eax
                invoke  lstrcpy, name#.item.title, [title]
                cld
                lea     esi, [name#.item]
                lea     edi, [name#.table+4]
                add     edi, [name#.LenTable]
                sub     edi, sizeof.BOOK32_TABLE_ITEM
                mov     ecx, sizeof.BOOK32_TABLE_ITEM
                rep     movsb
                inc     [name#.head.count]
                add     [name#.LenSect], sizeof.BOOK32_SECTION
                stdcall MemoryReSize, name#.sections, [name#.LenSect]
                mov     [name#.sections+4], eax                       ; error
                invoke  lstrlen,[text]
                inc     eax
                mov     [name#.sect.lengthof], eax
                stdcall MemoryInit, name#.sect.handle, [name#.sect.lengthof]
                mov     [name#.sect.buffer], eax
                cld
                lea     esi, [name#.sect]
                lea     edi, [name#.sections+4]
                add     edi, [name#.LenSect]
                sub     edi, sizeof.BOOK32_SECTION
                mov     ecx, sizeof.BOOK32_SECTION
                rep     movsb
                invoke  lstrcpy, [name#.sect.buffer], [text]  ; error not copy text
                invoke  MessageBox,0,[name#.sect.buffer],0,0
                mov     eax, [name#.sect.lengthof]
                add     [name#.LenSect], eax
                stdcall MemoryReSize, name#.sections, [name#.LenSect]
                mov     [name#.sections+4], eax                ; error
                mov     esi, [text]
                mov     ecx, [name#.sect.lengthof]
                rep     movsb
                ret
        endp       


Description: All code project in the attachment...
Download
Filename: TEST BK API.rar
Filesize: 9.14 KB
Downloaded: 411 Time(s)


_________________
Forgive for my bad english, I from russia...
Post 24 Nov 2008, 15:44
View user's profile Send private message ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 24 Nov 2008, 15:46
But you didn't explain what your problem is!
Post 24 Nov 2008, 15:46
View user's profile Send private message Visit poster's website Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 83
Location: Russia
Everhest 24 Nov 2008, 16:13
Sory, lines noted as error, produce terminated application...I do not know as this it is correct to describe in english, if you will compile application you themselves all will understand... No viruses...
Post 24 Nov 2008, 16:13
View user's profile Send private message ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 24 Nov 2008, 16:21
Is it an assembly time error? Or a runtime error? What did you expect to happen at the lines you marked, and what did happen? What is the application supposed to do anyway?

You need to provide more information.
Post 24 Nov 2008, 16:21
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 24 Nov 2008, 16:43
I have compiled it and crash on runtime due to access to an invalid pointer. I haven't checked anymore than that.
Post 24 Nov 2008, 16:43
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Nov 2008, 16:53
Everhest: just by a quick glance, you don't seem to be checking return value of functions "MemoryInit", "MemoryResize", etc. Do you check error cases inside them? If not, you are asking for this kind of problem.
Post 24 Nov 2008, 16:53
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 83
Location: Russia
Everhest 24 Nov 2008, 16:54
compile with fasm - no error.
run program - no error.
step book.open - no error
enter book.append - no error
Code:
                stdcall MemoryReSize, name#.sections, [name#.LenSect] 
                mov     [name#.sections+4], eax ; this error a run drwatson. why?
                invoke  lstrlen,[text] 
    

if set comment at < mov [name#.sections+4], eax>,then drwatson start in the line <invoke lstrcpy, [name#.sect.buffer], [text]> why? text not are copy... if set comment on this line, then
Code:
                stdcall MemoryReSize, name#.sections, [name#.LenSect] 
                mov     [name#.sections+4], eax  ; hi drwatson 
                mov     esi, [text] 
    

main asm file:
Code:
format PE GUI 4.0
entry start

include '../../include/win32a.inc'
include 'book.imp'

ERR_AUTO        = 0
soFromBeginning = 0

section '.data' data readable writable

        name                    db 'file.bk',0
        error_format            db 'Íåâåðíûé ôîðìàò ôàéëà',0
        NubersOfBytesRead       dd ?

        buffer                  rb 260

        class <TBOOK book>

section '.code' code readable executable

  start:
        stdcall book.open, name

        stdcall book.append, name, error_format ; any text and any title

    ;    stdcall book.save, name
        stdcall book.close
  exit:
        invoke  ExitProcess,0

include 'winapi.inc'      
    
Post 24 Nov 2008, 16:54
View user's profile Send private message ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 24 Nov 2008, 17:39
Let me suggest a better debugger than DrWatson, Ollydbg.
Post 24 Nov 2008, 17:39
View user's profile Send private message Visit poster's website Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 83
Location: Russia
Everhest 24 Nov 2008, 17:41
im see code from ollydbg and im not find error. why exhibit works without mistake if im add seh construction?
Code:
        proc name#.append title, text    
                add     [name#.LenTable], sizeof.BOOK32_TABLE_ITEM
                stdcall MemoryReSize, name#.table, [name#.LenTable]
                mov     [name#.table+4], eax
                invoke  lstrcpy, name#.item.title, [title]
                cld
                lea     esi, [name#.item]
                lea     edi, [name#.table+4]
                add     edi, [name#.LenTable]
                sub     edi, sizeof.BOOK32_TABLE_ITEM
                mov     ecx, sizeof.BOOK32_TABLE_ITEM
                rep     movsb

             .seh_install:
                push    .error1
                pushd   dword[fs:0]
                mov     [fs:0], esp
                inc     [name#.head.count]
             .error1:                       
    

Can here errors OS, rather then in code of application.
Post 24 Nov 2008, 17:41
View user's profile Send private message ICQ Number Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 83
Location: Russia
Everhest 24 Nov 2008, 17:48
vid

Code:
error_memory    db 'Íå âûïîëíåí çàïðîñ íà ïîëó÷åíèå\ðàñïðåäåëåíèå ãëîáàëüíîé ïàìÿòè äëÿ ïðèëîæåíèÿ.',0

proc MemoryInit HGLOBAL, size
        invoke  GlobalAlloc, GMEM_MOVEABLE + GMEM_ZEROINIT, [size]
        mov     ecx, [HGLOBAL]; retrieve pointer parameter (ecx==hglb1)
        mov     [ecx], eax; save heap pointer
        cmp     eax, 0
        je      mem_error
        invoke  GlobalLock, eax   ; Âîçðàùàåò àäðåñ ïàìÿòè
        cmp     eax, 0
        je      mem_error
        mov     [HGLOBAL+4], eax
        ret
endp

proc MemoryReSize HGLOBAL, size
        mov     ecx, [HGLOBAL]; retrieve pointer parameter (ecx==hglb1)er
        invoke  GlobalReAlloc, [ecx], [size], GMEM_MOVEABLE + GMEM_ZEROINIT
        xor     ecx, ecx
        cmp     eax, ecx
        je      mem_error
        mov     [HGLOBAL], eax
        ret
endp

proc MemoryFree HGLOBAL
        invoke  GlobalUnlock,[HGLOBAL]
        invoke  GlobalFree,[HGLOBAL]
        ret
endp

     mem_error:
        invoke  MessageBox,0,error_memory,0,MB_ICONERROR
        invoke  ExitProcess,0
        ret    
    
Post 24 Nov 2008, 17:48
View user's profile Send private message ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 24 Nov 2008, 17:52
Everhest,

The same error as before:
Code:
proc MemoryInit HGLOBAL, size
        invoke  GlobalAlloc, GMEM_MOVEABLE + GMEM_ZEROINIT, [size]
        mov     ecx, [HGLOBAL]; retrieve pointer parameter (ecx==hglb1)
        mov     [ecx], eax; save heap pointer
        cmp     eax, 0
        je      mem_error
        invoke  GlobalLock, eax   ; Âîçðàùàåò àäðåñ ïàìÿòè
        cmp     eax, 0
        je      mem_error
        mov     [HGLOBAL+4], eax; <- !!! LOOK HERE !!!
        ret
endp

proc MemoryReSize HGLOBAL, size
        mov     ecx, [HGLOBAL]; retrieve pointer parameter (ecx==hglb1)er
        invoke  GlobalReAlloc, [ecx], [size], GMEM_MOVEABLE + GMEM_ZEROINIT
        xor     ecx, ecx
        cmp     eax, ecx
        je      mem_error
        mov     [HGLOBAL], eax; <- !!! LOOK HERE !!!
        ret
endp    
Remember, procedure parameters are just values on stack, you have to dereference them if they are addresses. My answer to your GlobalReAlloc question was not the exact solution, just a clue (copy/pasted even with my comments Wink). mov [name#.table+4], eax after invoke is a workaround for erroneous code inside MemoryInit/MemoryReSize. Revise your code, mov [param], something inside proc is not a method to return something. Feel free to PM me, I speak Russian (as you may remember).
Post 24 Nov 2008, 17:52
View user's profile Send private message Reply with quote
Everhest



Joined: 26 Jun 2008
Posts: 83
Location: Russia
Everhest 24 Nov 2008, 18:08
baldr Äëÿ ëó÷øåãî ïîíèìàíèÿ ïîæàëóéñòà íàïèøèòå ýòî íà ðóññêîì, ÿ ñëèøêîì ïëîõî çíàþ àíãëèéñêèé.
Post 24 Nov 2008, 18:08
View user's profile Send private message ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.