A simple graphical guid generator application

Here's a simple guid generator utility that I coded some time ago. Some of you may find it useful and even a bit amusing. The program permits copying guids to the clipboard in one of two separate formats (asm and registry). If there is sufficient interest I can add additional formats.
Posted on 2003-07-12 12:07:02 by Poimander
Why not post the source with it. instead of a UPX'd executable :)

I have an idea. I am using this in my own guidthing.
Once I realized some of the funky formats out their and my lack of desire to
handle all of them, I am generating guid based off of a template. Whatever
format the user needs the guid in, they pass my app a template and
the app fills in the template. Its handy because it extends the usefulness of the app.

please Poimander take no offense in this post, I am very interested in this,
and its very cool to have someone else working on this. I thought I was the only one
that needed a GUID Generator :)

Here is a little source to use the ole32 apis to generate a string (reg style) guid.


; #################################################

.486
.model flat, stdcall
option casemap :none ; case sensitive

; #################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
;include \masm32\include\gdi32.inc
include \masm32\include\ole32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
;includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\ole32.lib

main PROTO
.data
AppTitle db "GUID String Example",0
.data?
GUIDptr dd ?
GUIDTextBufferW db 78 dup(?)
GUIDTextBufferA db 38 dup(?)

; #################################################
.code

start:
invoke CoInitializeEx,NULL,2
invoke CoCreateGuid,OFFSET GUIDptr
invoke StringFromGUID2,OFFSET GUIDptr,OFFSET GUIDTextBufferW, 78
invoke WideCharToMultiByte,CP_ACP, 0 ,OFFSET GUIDTextBufferW,\
38, OFFSET GUIDTextBufferA, MAX_PATH, NULL, NULL
invoke MessageBox,0,OFFSET GUIDTextBufferA,OFFSET AppTitle,MB_OK
invoke CoUninitialize

invoke ExitProcess,0

; #################################################
end start


its not much but good for begginers.

RobotBob
Posted on 2003-07-13 00:06:39 by RobotBob
Posted on 2003-07-13 15:14:41 by Poimander
214k oh ok :)

I have been searching for all possible guid formats, I am also
considering C, and any other assembler. Since the template idea
makes less code, so maybe we ca write a template specification
to support future unknown formats of future unknown assemblers.

And yes once complete I will make the template idea availible for others
to analyze. So others can fix/repair/improve it. I will port it to multiple
assemblers so others can use there favorite.

I had created my own template thing for spasm, but for general use, should I use the wsprintf api call? what do you suggest?

RobotBob
Posted on 2003-07-13 15:53:41 by RobotBob
I think it's Clive Turvey or some other big name who authored a version
of the MS guidgen program incorporating
five formats in all, four C formats and one asm format. So it's evident
there are possibly multiple formats per language (certainly for the MS
supported languages). So it appears it would be difficult to account for
every conceivable format.

Frankly, RobotBob I'm surprised you're asking for a suggestion since
it's evident you have a non-trivial command of the subtleties involved.
However, IMHO you would have to use the wsprintf api if you're coding a
formating function in asm for general use, unless you intend to code a
format parser from scratch.

I once wrote a C program which required generating format strings dynamically.
So I formulated a 'meta'-format string to handle the possible strings. But I
have to say the guid formats that I have encountered all fall into a general
pattern namely:

%s%02lx%s%02lx%s%02lx%s...
Posted on 2003-07-13 19:24:28 by Poimander
"...unless you intend to code a
format parser from scratch. "

I've done this, but it has a few bugs and for general use ,
wsprintf would be -the-way-to-go-.

It may be possible to account for unknown formats (future even)
since the guid will not change.

for spasm I do this:

1stDWORD , 1stWORD, 2ndWORD , Last8BYTES

It works for spasm, but for unknown types, maybe:

[{posistion}{size}] , [{posistion}{size}] , ...

its an idea, then formats will not be so code dependant.

Either way, its fun to write.

RobotBob
Posted on 2003-07-13 19:50:54 by RobotBob
A wsprintf based solution seems sensible since the whole thing can be
handled with one wsprintf format string.

Since COM is a language independent framework, all languages that support
COM must support the GUID/UUID as a data type in a consistent manner. I'm not
sure what the COM specification says about this precisely, but it's has to
be along the same lines. That being the case your template formulation must
be correct.Therefore the most general wsprintf format string should be:

Posted on 2003-07-13 21:51:11 by Poimander
Ok, i have to ask....

What is with the FONTS???

Some of us has to use an 800x600 resolution... getting hard to read these posts..
Posted on 2003-07-13 22:04:58 by NaN
Ha Ha..,, I'm having difficulty formating my posts so I switched
over to an unreadable font!!!
Posted on 2003-07-13 23:00:21 by Poimander
I now have the guid generator working wonderfully off a template.
Its generates a SpAsm style GUID and MASM style GUID without
one change to the code. The only different thing is the template
passed to it. The code is small and for general use (so lingo feel free rewrite :) )I'll rewrite it for masm and post. It will take just minutes to do this, but maybe later in the week I'll have the time.

Therefore, along as the template understands the order, then I think this app could (with work ) be able to handle any format (including user and future styles)

Its fun

RobotBob
Posted on 2003-07-15 14:11:04 by RobotBob
That's absolutely transfinite-dimensionally cool!!!
Posted on 2003-07-15 19:13:50 by Poimander
I have a request for all:
I need GUID styles for FASM and GoAsm.
anyone? (I am lazy, hoping someone else has this on the tip of their tongue)

mainly for testing.
Posted on 2003-07-16 17:54:19 by RobotBob
RobotBob, You may want to address your inquiry directly to Privalov as far as FASM is concerned.
Posted on 2003-07-18 21:29:55 by Poimander
I think i found a bug with your Generator. I didnt like the output format as i wanted a registry style format, so i decided to use the built in GUIDGEN.EXE.

I was surprised to see that the generated GUIDS are quite different. They are suppose to represent the same point in SPACE + TIME, yet within a second appart they are very different. See below:

Since there is no source to check with, im haveing to err on the side of M$'s tool rather than yours...
Posted on 2003-09-23 20:16:14 by NaN

They are suppose to represent the same point in SPACE + TIME


Not really. There's a lot of info being stored in a GUID, hashed together. On NT anyway - GUID generation on 9x is extremely lame.
Posted on 2003-09-24 01:51:36 by f0dder
NaN, I've adjusted the code slightly to address the apparent
bug. However as far as I can tell everything is working fine. Also I
repaired a typo in the format string that I was unaware of until
now. Anyway here's the adjusted version with full source. Perhaps
you can improve the code a bit. I think an OOP approach is called
for.

fOdder, I recently ungraded to W2K and noticed a difference
in the way guids are generated.
Posted on 2003-09-24 22:30:36 by Poimander
i forgot to post this, since this thread came back here is the nonsense code i was using to
generate guids. please forgive it since i haven't look at it in months. I am posting now so i dont forget again lol.



; #################################################

; MultiFormat GUID Generator
; .386
; .model flat, stdcall
; option casemap :none ; case sensitive

; #################################################

#include windows.inc
; #include user32.inc
; #include kernel32.inc
; #include ole32.inc

; includelib \masm32\lib\user32.lib
; includelib \masm32\lib\kernel32.lib
; includelib \masm32\lib\ole32.lib

; GuidGen PROTO :DWORD

.data
pGUID GUID; <?>
; These are all strings
FirstDword db 16 dup ?
FirstWord db 8 dup ?
SecondWord db 8 dup ?
EightBytes db 16 dup ?
GUIDTextBufferW db 80 dup ?
GUIDTextBufferA db 40 dup ?
OutPutBuffer db 100 dup ?

Result db "GUID Gen",0
SpAsmGUIDTemplate db "[GUIDNAME:",13,10
db "Data1: D$ 0%sH",13,10
db "Data2: W$ 0%sH",13,10
db "Data3: W$ 0%sH]",13,10
db "[Data4: B$ 0%s 0%s 0%s 0%s 0%s 0%s 0%s 0%s]",0

MasmGUIDTemplate db "GUIDNAME TEXTEQU <{0%sH, 0%sH, 0%sH, \",13,10
db "{0%sH, 0%sH, 0%sH, 0%sH, 0%sH, 0%sH, 0%sH, 0%sH}}>",0


FasmGUIDTemplate db "GUIDNAME dd 0%sh",13,10
db "dw 0%sh",13,10
db "dw 0%sh",13,10
db "db 0%sh,0%sh,0%sh,0%sh,0%sh,0%sh,0%sh,0%sh",0

; #################################################
.code
start:
invoke GuidGen,2
invoke ExitProcess,0
; #################################################

GuidGen FRAME FormatVersion
; 1 = Masm ; 2 = SpAsm ; 3 = Fasm ; 4 = GoAsm ?? C Basic
invoke CoInitializeEx,0,2
invoke CoCreateGuid,OFFSET pGUID

; It take the GUID structure and converts it to ascii unicode
invoke StringFromGUID2, OFFSET pGUID, OFFSET GUIDTextBufferW, 80

invoke WideCharToMultiByte,CP_ACP,0,OFFSET GUIDTextBufferW, 80, \
OFFSET GUIDTextBufferA, 40, 0, 0

; I though this was the simplest, and easy for beginners to reuse. or lame? :)
mov esi, OFFSET GUIDTextBufferA
inc esi

mov edi,OFFSET FirstDword
mov ecx, 8
rep movsb

inc esi

mov edi,OFFSET FirstWord
mov ecx, 4
rep movsb

inc esi

mov edi,OFFSET SecondWord
mov ecx, 4
rep movsb

inc esi

mov edi,OFFSET EightBytes
mov ecx, 2

@@: push ecx
mov ecx, 2
rep movsb

mov BYTE PTR [edi], 0
inc edi
pop ecx
loop @B

inc esi
mov ecx, 6
@@:
push ecx
mov ecx, 2
rep movsb

mov BYTE PTR [edi], 0
inc edi
pop ecx
loop @B

.IF FormatVersion == 1
mov eax, OFFSET MasmGUIDTemplate
.ELSEIF FormatVersion == 2
mov eax, OFFSET SpAsmGUIDTemplate
.ELSEIF FormatVersion == 3
mov eax, OFFSET FasmGUIDTemplate
.ENDIF

invoke wsprintf,OFFSET OutPutBuffer,eax,OFFSET FirstDword, \
OFFSET FirstWord,OFFSET SecondWord,OFFSET EightBytes,OFFSET EightBytes+3,\
OFFSET EightBytes+6,OFFSET EightBytes+9,OFFSET EightBytes+12,OFFSET EightBytes+15,\
OFFSET EightBytes+18,OFFSET EightBytes+21

invoke MessageBox,0,OFFSET GUIDTextBufferA,OFFSET Result,MB_OK
invoke MessageBox,0,OFFSET OutPutBuffer, OFFSET Result,MB_OK

invoke CoUninitialize

ret
GuidGen ENDF

; #################################################
end start



feel to rewrite, slam,degrade, use, misuse anything in this.
Good Night All

RobotBob
Posted on 2003-09-25 00:28:16 by RobotBob
Originally posted by NaN
I was surprised to see that the generated GUIDS are quite different. They are suppose to represent the same point in SPACE + TIME, yet within a second appart they are very different.


Recently I noticed the same thing. I'm a Delphi programmer (for the living) and I was surprised that three GUIDs generated one-after-another are totally different. It mus have been one of the latest windowsupdates I applied to my system (WinNT4 SP6a) that caused this... I've just checked another machine that was not updated lately and the GUIDs generated are quite similar (they differ in the first DWORD only)
Posted on 2003-09-25 01:55:33 by Morris
Ya i find this all very odd. It sounds like the possibility of overlapping GUIDs can be more likely than you would first expect....

:NaN:
Posted on 2003-09-26 18:00:07 by NaN
GUIDs are more likely to overlap with win9x and old service packs of NT4, than the newer and refined GUID scheme...
Posted on 2003-09-26 19:34:26 by f0dder