Page 1 of 2
Hello word
Posted: Wed Dec 09, 2009 10:09 pm
by angel
Hello!
I am writing a small program, but I get two passes, can anyone help me?
How can I do to run the program step by step with the debugger?
;
; EXAMPLE APPLICATION Hello word
;
; Compile with FASM for Kolibrios
;
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x100000 ; memory for app
dd 0x7fff0 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
START: ; start of execution
call draw_window
still:
mov eax,10 ; wait here for event
int 0x40
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
jmp still
red: ; redraw
call draw_window
jmp still
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp still
button: ; button
mov eax,17 ; get id
int 0x40
shr eax , 8
cmp eax , 1 ; Button close
jne noclose
mov eax , -1
int 0x40
noclose:
cmp eax , 0x106 ; Menu close
jne noc
mov eax , -1
int 0x40
noc:
jmp still
; WINDOW DRAW
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW ( Type 4 )
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+300 ; [x start] *65536 + [x size]
mov ecx,100*65536+160 ; [y start] *65536 + [y size]
mov edx,0x04ffffff ; color of work area RRGGBB,8->color gl
mov esi,window_label ; pointer to window label (asciiz) or zero
int 0x40
mov eax,4 ; Draw info text lines
mov ebx,20*65536+65
mov ecx,0x000000
mov edx,text
mov esi,-1
int 0x40
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA AREA
window_label:
db 'EXAMPLE APPLICATION',0
text:
db 'Hello word',0
I_END:
Thank you very much
Ángel
Re: Hello word
Posted: Wed Dec 09, 2009 11:17 pm
by vkos
About debugger:
1. It will be better if you compile your programme with .dbg file (this can be done in at least three ways: compile from KolibriOS with "create debug information" option enabled; use fasm extensions; compile to elf or another such format and get symbols from it)
2. Run mtdbg (KolibriOS debugger). Enter 'load /path/to/file' (to use debugging symbols, you need to put it in the same directory as executable).
3. You can use ctrl-f7/f8 to do step (normal or wide). Little help can be found using command help..
I get two passes
What do you mean? If fasm output is like
flat assembler version 1.68 (16384 kilobytes memory)
2 passes, 229 bytes.
it means that compilation is successful.
PS: IMHO, it is bad idea to write graphical applications now and with kernel built-in features...
Re: Hello word
Posted: Thu Dec 10, 2009 5:05 am
by <Lrz>
Re: Hello word
Posted: Tue Dec 22, 2009 12:17 am
by angel
Hi, I'm analizing the program which Lrz showed me in the
threat.
With the debugger I can see this:
With a hex editor I can see this one:
The lines 0,10,20 and 30 match between them, these lines are header and data, are they important?
I can't see the rest of the lines in the debbuger, why?
Thanks very much
Ángel
Re: Hello word
Posted: Tue Dec 22, 2009 1:49 am
by hidnplayr
To see the rest of the data in the debugger, you must use the 'd' command, followed by the hex address of the data you want to see.
All lines should match.
What is your definition of 'important'?
Without the header, the program cannot be loaded, without the data, it will probably not function correctly.
Re: Hello word
Posted: Tue Dec 22, 2009 10:18 pm
by angel
I think that I'm understanding it.
But, how can I know if the instructions begins in the 24 position memory?
How can I find out in which position are the data?
Which is the program structure?
Is there any documentation about the structure of kolibrios programs?
Thanks very much
Ángel
Re: Hello word
Posted: Wed Dec 23, 2009 1:55 am
by hidnplayr
angel wrote:I think that I'm understanding it.
But, how can I know if the instructions begins in the 24 position memory?
How can I find out in which position are the data?
Which is the program structure?
Is there any documentation about the structure of kolibrios programs?
Thanks very much
Ángel
0x24, it is the address of the label 'START'. If you look in the data at offset 12 (8 + 4) you can see the DWORD 24 00 00 00)
This dword, wich is a part of the so called header tells the kernel where the first instruction to be executed is.
You can find more info about how to program for kolibrios in the distribution, and in the application 'docpack' in kolibrios.
Re: Hello word
Posted: Wed Dec 23, 2009 8:36 pm
by angel
That interesting
Does the program always begin at the 12 position?
What is the ralation between "24 00 00 00" and "B8 28 00 00 00" y "mov eax, 28h" ?
Thank you very much
Ángel
Re: Hello word
Posted: Wed Dec 23, 2009 9:24 pm
by hidnplayr
angel wrote:That interesting
Does the program always begin at the 12 position?
What is the ralation between "24 00 00 00" and "B8 28 00 00 00" y "mov eax, 28h" ?
Thank you very much
Ángel
No, the program begins where the START label is, it is possible to put other code, or data before it. (between the header and START label)
24 00 00 00 is the DWORD 24h (36 decimal)
B8 28 00 00 00 is a piece of code in wich B8 probably means mov eax, ... and 28 00 00 00 is the data to be put in eax
Re: Hello word
Posted: Wed Dec 23, 2009 11:48 pm
by angel
How can I relate what I see with the hex editor with the instructions that I see in the debuger?
For example: The header MENUETO1 = 4D 45 4E 55 45 54 30 31
I'd like to make a little kolibrios / menuetos emulator.
Thanks very much

Re: Hello word
Posted: Thu Dec 24, 2009 1:31 am
by hidnplayr
MENUET01 = 4dh 45h ... is just an ascii conversion (
www.Asciitable.com) it is how the text really is stored in your computer.
currently there are only MENUET00 (old, should not be used for new programs) and MENUET01 headers
Re: Hello word
Posted: Thu Dec 24, 2009 6:43 pm
by angel
I try to explain it with an example:
The program tries to simulate to OS, but I don´t know how to interpret the opcodes.
Can you help me, please?
Thanks so much
Ángel
Re: Hello word
Posted: Thu Dec 24, 2009 7:06 pm
by hidnplayr
The dword after 'MENUET01' gives is the header version number, it should be 1.
The dword after that is the pointer to start of code, as explained before.
The next dword is the size of the whole file, in bytes.
The dword after that is the size the program will take in memory (this should be at least as big as the previous dword, if not larger)
The dword after that is the stack pointer, when the program is loaded, the OS sets the esp register (search on google to know what this register does) to this value.
The last 2 dword are I_Param and I_Path, they are optional and should be 0 if the program does not want to use them.
If you are looking for a way to interpret the code itself, perhaps the source code of MTDBG or Klbrinwin or MeOSEmul can help you out.
Re: Hello word
Posted: Thu Dec 24, 2009 7:11 pm
by vkos
1) There is already emulator for windows - KlbrInWin.
2) To emulate kolibri in such way, you need to write x86-32 emulator which is not good idea really

(the better option is to take Qemu or Bochs, for example). But if you want to write x86-32 emulator, you can see opcode meanings in the Intel 80386 Programmers Reference manual.
3) PHP programme will be extreamly slow.
hidnplayr
If you are looking for a way to interpret the code itself, perhaps the source code of MTDBG or Klbrinwin or MeOSEmul can help you out.
KlbrInWin doesn't emulate processor instructions (and MeOSEmul, I think, too).
Re: Hello word
Posted: Sun Dec 27, 2009 11:27 pm
by angel
If you are looking for a way to interpret the code itself, perhaps the source code of MTDBG or Klbrinwin or MeOSEmul can help you out.
I've used Klbrinwin and MeOSEmul, but I haven't found MTDBG. Where is it?
1) There is already emulator for windows - KlbrInWin.
Yes, but not for
Uzebox.
I made a didactic PLC, for my students, with Uzebox.
3) PHP programme will be extreamly slow.
I use PHP for undestanding the program code. The emulator will be written in C.
I keep working on understanding the code
Thanks and

Merry christmas
Ángel