flat assembler
Message board for the users of flat assembler.

Index > Windows > Easy Question

Author
Thread Post new topic Reply to topic
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Hi,
I'm (very) new to assembler.
I'm trying to learning something coding dumb examples with API...


; GetVolumeInformation

format PE GUI 4.0

include '%include%\win32a.inc'

invoke GetVolumeInformation,0,0,0,ddSerial,0,0,0,0
invoke wsprintf,szSerial,fmt,[ddSerial]
invoke MessageBox,0,szSerial,szCaption,MB_ICONQUESTION
invoke ExitProcess,0

ddSerial dd 8
szSerial rb 8
fmt db '%X',0
szCaption db 'GetVolumeInformation',0


[import data removed]

This example retrieve your serial number from hd (where application is running).
I don't know if syntax is right, but this works for me!
The produced output is, for example, 12341234, I'm asking how to insert a "-" sign between 2 numbers (1234-1234).
In C I can use HIWORD and LOWORD, but in asm?
I must use AX and AH instead?
ROL and SHL ?

Thank you for answer.
Post 26 Sep 2003, 19:36
View user's profile Send private message MSN Messenger Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
Just place the following code after wsprintf call:
Code:
mov edx, szSerial+4
mov eax, [edx]
mov [edx+1], eax
mov byte [edx], '-'
    

_________________
Best regards,
Antoch Victor
Post 26 Sep 2003, 20:19
View user's profile Send private message Yahoo Messenger Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Thank you,
but it display an X after the serial (1234-1234X)
I think it came from fmt.
Post 26 Sep 2003, 20:32
View user's profile Send private message MSN Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
You have to increase the size of the buffer to receive the formatted string from 8 to 9 bytes.
Post 26 Sep 2003, 20:41
View user's profile Send private message Visit poster's website Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Ehm, I change from 8 to 7 'cause from 8 to 9 bytes the outputted string is 1234-1234X%
Post 26 Sep 2003, 23:00
View user's profile Send private message MSN Messenger Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
Sorry, I forgot to tell you how szSerial should be declared:
Code:
 szSerial rb 10
    

_________________
Best regards,
Antoch Victor
Post 26 Sep 2003, 23:04
View user's profile Send private message Yahoo Messenger Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
It (seems) to works

invoke GetVolumeInformation,0,0,0,ddSerial,0,0,0,0
invoke wsprintf,szSerial,fmt,[ddSerial]
mov edx,szSerial+4
mov eax,[edx]
mov [edx+1],eax
mov byte[edx],'-'
invoke MessageBox,0,szSerial,szCaption,MB_ICONQUESTION
invoke ExitProcess,0

ddSerial dd 7
szSerial rb 7
fmt db '%X',0
szCaption db 'GetVolumeInformation',0

Thank you all.
Post 26 Sep 2003, 23:15
View user's profile Send private message MSN Messenger Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
Well, but you should know, that this code overwrites the "%X" string.

_________________
Best regards,
Antoch Victor
Post 26 Sep 2003, 23:18
View user's profile Send private message Yahoo Messenger Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Thank you again, I'm new to assembler and I don't understand this F***ING registers very well.
Post 26 Sep 2003, 23:31
View user's profile Send private message MSN Messenger Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
They are not hard to understand. What does my code is:
1. Get last 4 bytes of serial into eax
2. Place them 1 byte upper in memory
3. Place '-' on the 4th position of serial

This means that string should be at least 10 bytes long: 8 bytes serial code, 1 byte '-', 1 byte terminating zero. The problems were because on the place of terminating zero there was beginning of string "%X". When you defined serial buffer 7 bytes long, the position of terminating zero of serial became equal with the position of terminating zero of "%X". That's all.

_________________
Best regards,
Antoch Victor
Post 27 Sep 2003, 00:33
View user's profile Send private message Yahoo Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
..Smile Oh....10 bytes...sorry... Rolling Eyes
Post 27 Sep 2003, 06:50
View user's profile Send private message Visit poster's website Reply with quote
wanderer



Joined: 18 Jun 2003
Posts: 44
Location: Moldova, Kishinev
wanderer
Very Happy Razz

_________________
Best regards,
Antoch Victor
Post 27 Sep 2003, 07:07
View user's profile Send private message Yahoo Messenger Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Thanks.
Post 27 Sep 2003, 09:31
View user's profile Send private message MSN Messenger 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.