NO

Author Topic: Find GUIDs  (Read 3941 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Find GUIDs
« on: April 11, 2018, 10:51:03 AM »
A small program to list CLSIDs and IIDs from headers.
An example: FindGuids.exe "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\*" > _Guids.txt
Code: [Select]
#include <stdio.h>
#include <string.h>
#include <io.h>

typedef unsigned long DWORD;
typedef unsigned short WORD;

int __cdecl main(int argc, char **argv)
{
char buf[512], iid[100], file[260];
struct _finddata_t fd;
intptr_t ff = _findfirst(argv[1], &fd);
if (ff == -1)
return 1;
strcpy(file, argv[1]);
int nfp = strlen(file);
while (file[nfp] != '\\')
nfp--;
nfp++;
do {
strcpy(file+nfp, fd.name);
FILE *fp = fopen(file, "r");
if (fp) {
int iChk = 0;
puts(fd.name);
while (fgets(buf, 512, fp)) {
if (*buf == '\n' || *buf == '/') continue;
if (!strncmp(buf, "DEFINE_GUID(", 12)) {
char *p1, *p2, *p3 = buf + 12;
if (*p3 == '\n' || *p3 == '/')
fgets(p3, 80, fp);
while (*p3 == ' ' || *p3 == '\t')
p3++;
p2 = p3;
while (*p3 != ',')
p3++;
*p3 = 0;
if (*p2 == 'I') {
strcpy(iid, "const IID ");
p1 = iid + 10;
} else {
strcpy(iid, "const CLSID ");
p1 = iid + 12;
}
strcpy(p1, p2);
p1 += (p3 - p2);
*((WORD *)p1) = *(WORD *)"={";
p1 += 2;
p3++;
while (*p3 == ' ') p3++;
while (*p3) {
if (*p3 == '\n' || *p3 == '/')
fgets(p3, 80, fp);
if (*p3 != ' ' && *p3 != '\t') *p1++ = *p3;
if (*p3 == ';') break;
p3++;
}
*p1 = 0;
int len = strlen(iid);
p1 = iid + len -1;
while (*p1 && *p1 != ')')
p1--;
*p1 = '}';
*(p1+2) = 0;
puts(iid);
iChk = 0;
continue;
}
else
if (!strncmp(buf, "EXTERN_C const IID ", 19)
|| !strncmp(buf, "EXTERN_C const CLSID ", 21)) {
if (buf[15] == 'I')
iChk = 1;
else
iChk = 2;
strcpy(iid, buf + 9);
}
if (iChk) {
char *pc;
if (pc = strstr(buf, "MIDL_INTERFACE("))
pc += 16;
else if (pc = strstr(buf, "class DECLSPEC_UUID("))
pc += 21;
if (pc) {
char *p1 = iid + 9;
while (*p1 != ';')
p1++;
*((DWORD *)p1) = *(DWORD *)"={0x";
p1 += 4;
*((DWORD *)p1) = *(DWORD *) (pc);
p1 += 4;
*((DWORD *)p1) = *(DWORD *) (pc + 4);
p1 += 4;
*((DWORD *)p1) = *(DWORD *)",0x";
p1 += 3;
*((DWORD *)p1) = *(DWORD *) (pc + 14);
p1 += 4;
*((DWORD *)p1) = *(DWORD *)",0x";
p1 += 3;
*((DWORD *)p1) = *(DWORD *) (pc + 19);
p1 += 4;
for (int i = 24; i < 35; i += 2) {
*((DWORD *)p1) = *(DWORD *)",0x";
p1 += 3;
*((WORD *)p1) = *(WORD *) (pc + i);
p1 += 2;
}
*((DWORD *)p1) = *(DWORD *)"};";
puts(iid);
}
}
}
fclose(fp);
}
} while (!_findnext(ff, &fd));
_findclose(ff);
return 0;
}
« Last Edit: April 11, 2018, 09:12:35 PM by TimoVJL »
May the source be with you

Grincheux

  • Guest
Re: Find GUIDs
« Reply #1 on: January 11, 2020, 08:00:21 PM »
I mixed your list with the one I made.
Thank you for this tool.


14557 items in my list