blob: aa44bfd3d7daa69743c6349525682259293e2fd2 [file] [log] [blame]
Theodore Ts'o6c979d51999-10-26 02:50:36 +00001/*
2 * gen_uuid_nt.c -- Use NT api to generate uuid
3 *
4 * Written by Andrey Shedel (andreys@ns.cr.cyco.com)
5 */
Theodore Ts'oaa4115a1999-10-21 19:33:18 +00006
7
8#include "uuidP.h"
9
Theodore Ts'o6c979d51999-10-26 02:50:36 +000010#pragma warning(push,4)
Theodore Ts'oaa4115a1999-10-21 19:33:18 +000011
12#pragma comment(lib, "ntdll.lib")
13
Theodore Ts'o6c979d51999-10-26 02:50:36 +000014//
15// Here is a nice example why it's not a good idea
16// to use native API in ordinary applications.
17// Number of parameters in function below was changed from 3 to 4
18// for NT5.
19//
20//
21// NTSYSAPI
22// NTSTATUS
23// NTAPI
24// NtAllocateUuids(
25// OUT PULONG p1,
26// OUT PULONG p2,
27// OUT PULONG p3,
28// OUT PUCHAR Seed // 6 bytes
29// );
30//
31//
32
Theodore Ts'oaa4115a1999-10-21 19:33:18 +000033unsigned long
34__stdcall
35NtAllocateUuids(
36 void* p1, // 8 bytes
37 void* p2, // 4 bytes
38 void* p3 // 4 bytes
39 );
40
Theodore Ts'o6c979d51999-10-26 02:50:36 +000041typedef
42unsigned long
43(__stdcall*
44NtAllocateUuids_2000)(
45 void* p1, // 8 bytes
46 void* p2, // 4 bytes
47 void* p3, // 4 bytes
48 void* seed // 6 bytes
49 );
50
51
52
53//
54// Nice, but instead of including ntddk.h ot winnt.h
55// I should define it here because they MISSED __stdcall in those headers.
56//
57
58__declspec(dllimport)
59struct _TEB*
60__stdcall
61NtCurrentTeb(void);
62
63
64//
65// The only way to get version information from the system is to examine
66// one stored in PEB. But it's pretty dangerouse because this value could
67// be altered in image header.
68//
69
70static
71int
72Nt5(void)
73{
74 //return NtCuttentTeb()->Peb->OSMajorVersion >= 5;
75 return (int)*(int*)((char*)(int)(*(int*)((char*)NtCurrentTeb() + 0x30)) + 0xA4) >= 5;
76}
77
78
79
80
Theodore Ts'oaa4115a1999-10-21 19:33:18 +000081void uuid_generate(uuid_t out)
82{
Theodore Ts'o6c979d51999-10-26 02:50:36 +000083 if(Nt5())
84 {
85 unsigned char seed[6];
86 ((NtAllocateUuids_2000)NtAllocateUuids)(out, ((char*)out)+8, ((char*)out)+12, &seed[0] );
87 }
88 else
89 {
90 NtAllocateUuids(out, ((char*)out)+8, ((char*)out)+12);
91 }
Theodore Ts'oaa4115a1999-10-21 19:33:18 +000092}