|
真正找到的是这个!2002年的。
- #include <windows.h>
- #include <windowsx.h>
- #include <commctrl.h>
- #include <shlobj.h>
- #include <richedit.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #pragma hdrstop
- #include "..\api\winapi.h"
- int errorcode;
- LPSTR errorprompts[]=
- {
- "This program generates .Inf file from a .Reg file. (by kajaa@eastday.com)\n"
- "Syntax:\tReg2Inf [switches] [<SourceFile.Reg> [DestFile.Inf]]\n"
- "\tswitches:\n"
- "\t\t-w\toutput WHOLE keyname instead of abbreviation\n"
- "\t\t-t\toutput in TINY mode, no comments\n"
- ,
- "Memory Allocation Error\n",
- "File cannot be opened\n",
- "Memory Allocation Error\n",
- "Not a REG File\n",
- "File cannot be created\n",
- "OK\n",
- };
- const int RESBUFSIZE=65500;
- int skipbytes, knlsize;
- LPSTR ComBuf,srcfile,destfile,destBuffer;
- LPSTR WINAPI skipwhitespace(LPSTR buffer,int comment)
- {
- LPSTR lp;
- lp=buffer;
- while (*lp)
- {
- if (!comment)
- {
- switch(*lp)
- {
- case 0x9:
- case 0x20: break;
- case ';': comment=1; break;
- default:
- if (IsReturn(lp)) ++lp;
- else{
- if (*lp!='\r'&&*lp!='\n') return lp;
- break;
- }
- }
- ++lp;
- }
- else{
- if (IsReturn(lp)) ++lp, comment=0; else{ if (*lp=='\r'||*lp=='\n') comment=0; }
- ++lp;
- }
- }
- return lp;
- }
- #define INFHEADER \
- "[Version]\r\nSignature="$CHICAGO$"\r\nProvider=kajaa@eastday.com, 2002\r\n\r\n"\
- "[DefaultInstall]\r\n"\
- "; DelReg=$PZ_DelReg\r\n"\
- "AddReg=$PZ_AddReg\r\n"
- #define INFCOMMENTS \
- "; reg-root-string, [subkey], [value-name], [flags], [value]\r\n"\
- ";DelReg=$PZ_DelReg\r\n"\
- "; reg-root-string, subkey, [value-name]\r\n"\
- ";Delfiles=$PZ_Delfiles\r\n"\
- "; file-name[,,,flag]\r\n"\
- ";Renfiles=$PZ_Renfiles\r\n"\
- "; new-file-name,old-file-name\r\n"\
- ";Copyfiles=$PZ_Copyfiles\r\n"\
- "; destination-file-name[,source-file-name][,temporary-file-name][,flag]\r\n"\
- ";UpdateInis=$PZ_UpdateInis\r\n"\
- "; ini-file,ini-section,[old-ini-entry],[new-ini-entry],[flags]\r\n"\
- "\r\n"\
- "[DestinationDirs]\r\n"\
- "; -01 or 0xffff The directory from which the INF was installed.\r\n"\
- "; 01 SourceDrive:\\path.\r\n"\
- "; 10 Windows directory.\r\n"\
- "; 11 System directory. (%windir%\\system on Windows 95, %windir%\\system32 on Windows NT)\r\n"\
- "; 12 Drivers directory.(%windir%\\system32\\drivers on Windows NT)\r\n"\
- "; 17 INF file directory.\r\n"\
- "; 18 Help directory.\r\n"\
- "; 20 Fonts directory.\r\n"\
- "; 21 Viewers directory.\r\n"\
- "; 24 Applications directory.\r\n"\
- "; 25 Shared directory.\r\n"\
- "; 30 Root directory of the boot drive.\r\n"\
- "; 50 %windir%\\system\r\n"\
- "; 51 Spool directory.\r\n"\
- "; 52 Spool drivers directory.\r\n"\
- "; 53 User Profile directory.\r\n"\
- "; 54 Path to ntldr or OSLOADER.EXE\r\n"
- #define INFBEGIN "\r\n[$PZ_DelReg]\r\n\r\n[$PZ_AddReg]"
- LPSTR curkeyname,root,key;
- int WINAPI whichroot(LPSTR lp)
- {
- #define HKLM "HKEY_LOCAL_MACHINE"
- #define HKCU "HKEY_CURRENT_USER"
- #define HKU "HKEY_USERS"
- #define HKCR "HKEY_CLASSES_ROOT"
- #define HKLMSC "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes"
- if (strncmpi(lp, HKLMSC, sizeof(HKLMSC)-1)==0)
- {
- root="hkcr";
- return sizeof(HKLMSC);
- }
- if (strncmpi(lp, HKLM, sizeof(HKLM)-1)==0)
- {
- root="hklm";
- return sizeof(HKLM);
- }
- if (strncmpi(lp, HKCU, sizeof(HKCU)-1)==0)
- {
- root="hkcu";
- return sizeof(HKCU);
- }
- if (strncmpi(lp, HKU, sizeof(HKU)-1)==0)
- {
- root="hku";
- return sizeof(HKU);
- }
- if (strncmpi(lp, HKCR, sizeof(HKCR)-1)==0)
- {
- root="hkcr";
- return sizeof(HKCR);
- }
- return 0;
- }
- LPSTR writebinary(LPSTR src,LPSTR dest,int hex)
- {
- if (hex)
- {
- // V2LP(dest)=0x090a0d5c,dest+=4;
- while (*src&&(IsReturn(src)==0||*(src-1)=='\\')) *dest++=*src++;
- }
- else{
- short *ch;
- ch=((short *)src)+3;
- V2SP(dest)=*ch--; *(dest+2)=','; dest+=3;
- V2SP(dest)=*ch--; *(dest+2)=','; dest+=3;
- V2SP(dest)=*ch--; *(dest+2)=','; dest+=3;
- V2SP(dest)=*ch; dest+=2;
- }
- return dest;
- }
- int use_abb_key=1,use_tiny_mode; LPSTR stringBuffer,stringEnd;
- LPSTR WINAPI genstring(LPSTR key)
- {
- static int number;
- int kl;
- LPSTR se,temp;
- if (use_abb_key==0) return key;
- se=stringEnd;
- se+=sprintf(se,"%s%d_",ComBuf,++number);
- temp=key;
- while (*temp)
- {
- if ((*temp&'\x80')!=0)
- {
- se+=sprintf(se,"%d",++number);
- ++temp;
- }
- else *se++=*temp++;
- while (*temp&&*temp!='\\') ++temp;
- if (*temp) ++temp;
- }
- kl=(temp=se)-stringEnd;
- *temp++='='; *temp++='"';
- lstrcpy(temp,key); while (*temp) ++temp;
- *temp++='"'; V2SP(temp)=0x0a0d;
- se=(temp+=2);
- *temp++='%';
- lstrcpyn(temp,stringEnd,kl+1);
- V2SP(temp+=kl)=0x25;
- return stringEnd=se;
- }
- int WINAPI genvalues(LPSTR buffer,int size)
- {
- LPSTR lp,dest;
- skipbytes=0, lp=buffer, dest=destBuffer+size;
- switch(*lp)
- {
- case '[':
- while (*lp&&*lp!=']') ++lp; skipbytes=lp-buffer+1; ++buffer;
- if (*lp)
- {
- *lp=0, lp=buffer;
- if (curkeyname==0||lstrcmpi(lp,curkeyname))
- {
- int len;
- if ((len=whichroot(buffer))!=0)
- {
- if (V2SP(dest-4)!=0x0a0d)
- V2SP(dest)=0x0a0d, dest+=2;
- key=genstring((curkeyname=buffer)+len);
- }
- }
- }
- break;
- case '@':
- case '"':
- if (*lp!='@')
- {
- ++lp;
- while (*lp&&*lp!='"') ++lp;
- ++buffer;
- }
- *lp++=0, skipbytes=lp-buffer+1;
- if (*lp)
- {
- while (*lp&&*lp!='=') ++lp;
- if (*lp)
- {
- ++lp;
- if (*lp=='"') size=0, ++lp;
- else{
- if (strncmpi(lp,"dword:",6)==0) size=0x10001, lp+=6;
- else{
- if (strncmpi(lp,"hex:",4)==0) size=1, lp+=4;
- else size=-1;
- }
- }
- if (size>=0)
- {
- dest+=sprintf(dest,"%s,"%s",",root,key);//"%s",%d,
- if (*buffer) dest+=sprintf(dest,""%s",", buffer); else *(dest++)=',';
- if (size) dest+=sprintf(dest,"%d,",size); else *(dest++)=',';
- if (size==0)
- {
- *dest++='"';
- while (*lp)
- {
- if (V2SP(lp)==0x5c5c)
- ++lp;
- else{
- if (V2SP(lp)==0x225c)
- *dest++='"', lp++;
- else{
- if (*lp=='%') *dest++='%';
- else{
- if (*lp=='"') break;
- }
- }
- }
- *dest++=*lp++;
- }
- *dest++='"';
- }
- else dest=writebinary(lp, dest, size==1);
- V2SP(dest)=0x0a0d, dest+=2;
- }
- }
- }
- break;
- }
- return dest-destBuffer;
- }
- int WINAPI writeheader(LPSTR header,int from)
- {
- int size;
- LPSTR sp,dp;
- size=knlsize, sp=header, dp=destBuffer+from;
- while (*sp)
- {
- if (V2LP(sp)==0x5a502424)
- {
- lstrcpy(dp,ComBuf);
- dp+=size, sp+=4;
- }
- else *dp++=*sp++;
- }
- return dp-destBuffer;
- }
- void WINAPI convert(void)
- {
- DWORD size;
- LPSTR lpfile,temp;
- HANDLE hfile;
- if ((hfile=ezCreateFile(srcfile,0))!=INVALID_HANDLE_VALUE)
- {
- ++errorcode;
- if ((lpfile=(LPSTR)GlobalAlloc(GPTR,(size=GetFileSize(hfile,0))*5+4+sizeof(INFHEADER)))!=0)
- {
- ++errorcode;
- if (ReadFile(hfile,lpfile+size,size,&size,0)==0) size=0;
- }
- CloseHandle(hfile);
- if (size)
- {
- if (V2SP(lpfile+size)==(short)0xfeff)
- WideCharToMultiByte(CP_ACP,0,(LPCWSTR)(lpfile+size),-1,lpfile,size,0,0);
- else
- CopyMemory(lpfile,lpfile+size,size);
- destBuffer=(stringBuffer=(temp=lpfile+size)+1)+size+1; *temp=0;
- stringEnd=stringBuffer+sprintf(stringBuffer,"\r\n[Strings]\r\n");
- #define REGID_UNICODE "Windows Registry Editor Version 5.00"
- if (
- strncmpi(temp=skipwhitespace(lpfile,0),"REGEDIT4",sizeof("REGEDIT4")-1)==0
- ||
- strncmpi(temp+1,"REGEDIT4",sizeof("REGEDIT4")-1)==0
- ||
- strncmpi(temp,REGID_UNICODE,sizeof(REGID_UNICODE)-1)==0
- ||
- strncmpi(temp+1,REGID_UNICODE,sizeof(REGID_UNICODE)-1)==0
- )
- {
- ++errorcode;
- if ((hfile=ezCreateFile(destfile,1))!=INVALID_HANDLE_VALUE)
- {
- ++errorcode;
- size=writeheader(INFHEADER,0);
- if (use_tiny_mode==0) size=writeheader(INFCOMMENTS,size);
- size=writeheader(INFBEGIN,size);
- while (*(temp=skipwhitespace(temp+skipbytes,1))!=0)
- size=genvalues(temp,size);
- lstrcpy(destBuffer+size,stringBuffer);
- WriteFile(hfile,destBuffer,size+(stringEnd-stringBuffer),&size,0);
- CloseHandle(hfile);
- printf("%s Generated ", destfile);
- }
- }
- }
- }
- }
- void WINAPI extfn(LPSTR cmd)
- {
- int i;
- LPSTR fp;
- if (*(fp=cmd)=='"') { ++fp,++cmd; while (*fp!='"') ++fp; *fp=0; }
- GetFullPathName(cmd,MAX_PATH,ComBuf,&fp);
- *((ComBuf=fp)-1)=0;
- i=0; while (*fp) ++fp,++i;
- while (i&&*fp!='.') --fp,--i;
- if (i) *fp=0;
- knlsize=i;
- }
- void main(int argc,char *argv[])
- {
- if (argc>=2)
- {
- int i; LPSTR tmp,fn1,fn2;
- for (fn1=fn2=0,i=1; i<argc; i++)
- {
- if (*(tmp=argv[i])=='-'||*tmp=='/')
- {
- switch(*(tmp+1))
- {
- case 'w':
- case 'W':
- use_abb_key=0;
- break;
- case 't':
- case 'T':
- use_tiny_mode=1;
- break;
- }
- }
- else{
- if (fn1) fn2=tmp; else fn1=tmp;
- }
- }
- if (fn1==0) fn1=argv[1]; ++errorcode;
- if ((ComBuf=(LPSTR)GlobalAlloc(GPTR,3*MAX_PATH))!=0)
- {
- ++errorcode;
- destfile=(srcfile=ComBuf+MAX_PATH)+MAX_PATH;
- extfn(fn1);
- lstrcpy(srcfile,fn1); if (fn2) lstrcpy(destfile,fn2); else lstrcat(lstrcpy(destfile,srcfile),".inf");
- convert();
- }
- }
- printf(errorprompts[errorcode]);
- }
复制代码 |
评分
-
查看全部评分
|