flat assembler
Message board for the users of flat assembler.
Index
> Main > Bug in the code or bug in the fasm? |
Author |
|
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
_________________ Forgive for my bad english, I from russia... |
|||||||||||
24 Nov 2008, 15:44 |
|
revolution 24 Nov 2008, 15:46
But you didn't explain what your problem is!
|
|||
24 Nov 2008, 15:46 |
|
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. |
|||
24 Nov 2008, 16:21 |
|
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.
|
|||
24 Nov 2008, 16:43 |
|
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.
|
|||
24 Nov 2008, 16:53 |
|
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' |
|||
24 Nov 2008, 16:54 |
|
revolution 24 Nov 2008, 17:39
Let me suggest a better debugger than DrWatson, Ollydbg.
|
|||
24 Nov 2008, 17:39 |
|
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. |
|||
24 Nov 2008, 17:41 |
|
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 |
|||
24 Nov 2008, 17:48 |
|
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 |
|||
24 Nov 2008, 17:52 |
|
Everhest 24 Nov 2008, 18:08
baldr Äëÿ ëó÷øåãî ïîíèìàíèÿ ïîæàëóéñòà íàïèøèòå ýòî íà ðóññêîì, ÿ ñëèøêîì ïëîõî çíàþ àíãëèéñêèé.
|
|||
24 Nov 2008, 18:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.