Is not going to work untill you call PrintDec or probably another macro that make debuger window.
Posted on 2003-11-20 14:48:59 by AceEmbler
I don't understand why you have the problem. I have tested the macro with the following code and it works ok.

.model flat, stdcall
option casemap: none

include \masm32\include\
include \masm32\include\
include \masm32\include\
include \masm32\include\

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\debug.lib

szMessage byte "Message", 0

mov eax, offset szMessage
PrintStringByAddr eax
end start
Posted on 2003-11-25 23:07:18 by vkim
This is working ;

INITHEAP LhHeap,LpHeap,300
; <----Load some string into LpHeap
PrintDec eax
PrintStringByAddr LpHeap

This is not;
INITHEAP LhHeap,LpHeap,300
; <----Load some string into LpHeap
PrintStringByAddr LpHeap

LpHeap and LhHeap are local variables

Maby it's becouse memory is dynamically alocated

This message tells us that instruction from addres xxxxx refers to memory xxxxxxxx memory can't be written
Posted on 2003-12-14 14:02:10 by AceEmbler
please try the attached program. It works fine on my machine.
Posted on 2003-12-14 23:14:46 by vkim
Yep your example is working properly. i Can post my source with this problem if you wish becouse i dont know what's the problem.
Posted on 2003-12-15 07:19:09 by AceEmbler
Please, post it if you can. I'd like to find where the problem is.
Posted on 2003-12-16 02:03:02 by vkim
OK here it is. You have to build it if you want to not working one look in line 1826 and 1827 i have " ; " this lines. So as i was talking before

This is working :
PrintDec eax
PrintStringByAddr LpHeap

This one alone is not:
PrintStringByAddr LpHeap

To see the problem you have to run the prog, db_click on item in list view and then press bottom left button "Kasuj Baze"
Posted on 2003-12-16 06:16:58 by AceEmbler
I have compiled the project but it doesn't work. It generates a protected fault. I don't have a debugger in my work, so I'm going to look the program later.
Posted on 2003-12-17 21:23:54 by vkim
It's probably becouse i didn't preserv some important registers
I'm using XP btw.
Posted on 2003-12-18 06:58:56 by AceEmbler
You dont post so as i see you didn't solve the problem yet. I can prepare win2000 working example if you want.
Posted on 2003-12-28 17:21:48 by AceEmbler
Hi AceEmbler,

I downloaded your example and I get the same GPF as you did using Win2K but even if VKim is not called in the program.

Hi AceEmbler,

You did not preserve EBX in your DlgProc:

20 DlgProc proc uses ebx hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

This takes care of the problem completely ;)
Posted on 2003-12-28 19:48:12 by donkey
Hi AceEmbler,
I did correction in the program as donkey said. I don't see any problem in PrintStringByAddr, it works with PrintDec and without. If I can I will try your program on WinXP later.
Posted on 2003-12-28 21:46:42 by vkim
Hi Vkim !
Sorry for my bad English !
I build your test.asm with Debug info, and run it under MemProof and Purify. All of them report error at the call GlobalFree in PrintStringByAddr macro. I tried to run it with OllyDbg. At the first run, OllyDbg report exception in GlobalFree function, but at many later run, the problem not occur. I step to the macro, and found the macro writed exceed the size of buffer which was allocatted by GlobalAlloc one byte. Here is the asm code in OllyDbg:
00401035 |. 60 pushad
00401036 |. FF35 0B304000 push dword ptr ds:
0040103C |. FF35 0B304000 push dword ptr ds: ; /String = "Hello!"
00401042 |. E8 A7000000 call test.lstrlenA ; \lstrlenA
00401047 |. 50 push eax ; => eax = 6
00401048 |. 83C0 18 add eax, 18 ; => eax = 1Eh, = 30
0040104B |. 50 push eax ; /MemSize = 133CC0 (1260736.)
0040104C |. 6A 40 push 40 ; |Flags = GPTR
0040104E |. E8 7D000000 call test.GlobalAlloc ; \GlobalAlloc
00401053 |. 8BD8 mov ebx, eax
00401055 |. 50 push eax
00401056 |. 8BC3 mov eax, ebx
00401058 |. C700 70486561 mov dword ptr ds:, 61654870 ; "pHea"
0040105E |. 66:C740 04 7000 mov word ptr ds:, 70 ; "a"
00401064 |. 58 pop eax ; 00133B7E
00401065 |. C740 05 203D2000 mov dword ptr ds:, 203D20 ; "^ =^"
0040106C |. 5A pop edx ; 00133B7E
0040106D |. 58 pop eax ; 00133B7E
0040106E |. 50 push eax ; /StringToAdd = "Hello!"
0040106F |. 53 push ebx ; |ConcatString = "pHeap = "
00401070 |. E8 73000000 call test.lstrcatA ; \lstrcatA => "pHeap = Hello!"
00401075 |. 53 push ebx
00401076 |. 83C3 08 add ebx, 8
00401079 |. 03DA add ebx, edx
0040107B |. 50 push eax
0040107C |. 8BC3 mov eax, ebx
0040107E |. C700 20287465 mov dword ptr ds:, 65742820 ; "^(te"
00401084 |. C740 04 73742E61 mov dword ptr ds:, 612E7473; "st.a"
0040108B |. C740 08 736D2C20 mov dword ptr ds:, 202C6D73; "sm,"
00401092 |. C740 0C 33342900 mov dword ptr ds:, 293433 ; "34)"and a 0 byte => exceed here, 31 byte.
00401099 |. 58 pop eax ; 00133B7E
0040109A |. 5B pop ebx ; 00133B7E
0040109B |. 53 push ebx ; /Arg1 = 00133CC0 ASCII "pHeap = Hello!"
0040109C |. E8 53000000 call test.DebugPrint ; \DebugPrint
004010A1 |. 53 push ebx ; /hMem = 00133CC0
004010A2 |. E8 2F000000 call test.GlobalFree ; \GlobalFree
004010A7 |. 61 popad

If I have a mistake, please give me your idea.
Best regards !
Posted on 2003-12-29 02:50:05 by TQN
Hi VKim,

There is a definite problem if the direction flag is set, I have taken care of the bug in the GoAsm implementation by pushfd/cld ... popfd to ensure that the flag wont be passed to debug.lib. Besides that forced exception I still haven't had the problem noted here though.
Posted on 2003-12-29 03:09:12 by donkey
Hi Vkim,

I have been getting a GPF in GoAsm and have traced it back to the buffers in (in my cases) DumpFPU and DumpMem, but the problem seems to be the interaction of the obj's and not a real error anywhere. I redid both routines using GlobalAlloc to allocate runtime buffers and the problem disappeared. For example :

invoke GlobalAlloc,GPTR,256

mov pdbbuf,eax

Was used in place of

dbbuf byte 128 dup (?)

This and the verification of the direction flag makes the application much more robust. However, I believe that in my case GoAsm was not allocating the memory from the BSS segment as it could not "see" it, it is never written to or read from except indirectly through ADDR dbbuf. Since these seem to work well now I will be going through the rest of the code and finding other problems in porting the object file to GoAsm, there should not be many.

If you like I will email the resulting project to you, it also banishes the need for the masm32 library (FloatToStr is referenced but not resident), something that is not desirable for porting to other assemblers.
Posted on 2004-01-01 19:30:25 by donkey
Sorry, I don't see where the acclocated buffer has overflow. Macro in test.asm outputs the string "pHeap = Hello! (test.asm, 34)". The lentgth of it is 29 symbols. GlobalAlloc allocates 30 bytes for the string plus 1 byte for zero.
Posted on 2004-01-02 01:32:42 by vkim
1. You are absolutely right when you say about direction flag. This problem will be fixed in the next version.
2. As you understand I allocate runtime buffer because I don't know the length of the text. It can be autoexec.bat for example.
3. Of course, send me your project if you think I can help you.
Posted on 2004-01-02 01:55:54 by vkim
Hi vkim,

I'll send the 3 source files that I have modified.

I should note that everything is running well, except the problem with TrapException that occurs identically in both MASM and GoAsm versions. My main thing was to make it more portable between assemblers. For example the dependancy on the MASM32 library can be a bit of a pain when using an assembler other than MASM. Also my buffer problem unlike the one TQN encountered, is not a bug in your software. I believe it to be a quirk in the library import function of GoAsm, that was the reason for the runtime buffers in my case, trust me that the results are pretty weird without it. I have also added the dw2hex, dwtoa, and FloatToStr functions (suitably renamed in order to avoid conflicts) to the library in order to have consistent results across all assembers without the need for external libraries. These are design issues for you to consider with your next version that will make it easier for the next assembler to use your excellent library. I will PM you a download URL as I do not have your email address in my book.
Posted on 2004-01-02 02:09:00 by donkey
Hi VKim !
I tested with MASM 6.15.8803 and 7.10.3077, Windows 2000 Server Service pack 4
The string output in my machine is:
pHeap^=^Hello!.^(test.asm,^31) and a 0 byte (^=space character), so total length is 31 bytes.
In, at PrintStringByAddr, if I replace the original code:
add eax, @SizeStr(&Var)+4+@SizeStr(%info)
add eax, @SizeStr(&Var)+4
add eax, @SizeStr(&Var)+8+@SizeStr(%info)
add eax, @SizeStr(&Var)+8
then the problem will not happen.
Best regards !
Posted on 2004-01-02 22:36:29 by TQN
Sorry, may be I'm wrong but the test program outputs the string without dot after "Hello!". So the length of it is 29 bytes plus 1 for zero. I don't think the problem occures because of overflow.
Posted on 2004-01-04 21:28:32 by vkim