谁能帮我把这段代码改成DELPHI代码.谢谢!(43)

  • 主题发起人 主题发起人 driayu
  • 开始时间 开始时间
D

driayu

Unregistered / Unconfirmed
GUEST, unregistred user!
修改PE文件版本信息(简单演示)收藏struct VS_VERSIONINFO { WORD wLength; WORD wValueLength; WORD wType; WCHAR szKey[]; WORD Padding1[]; VS_FIXEDFILEINFO Value; WORD Padding2[]; WORD Children[]; }; struct KString { WORD wLength; WORD wValueLength; WORD wType; WCHAR szKey[]; WORD Padding[]; WORD Value[]; }; struct StringTable { WORD wLength; WORD wValueLength; WORD wType; WCHAR szKey[]; WORD Padding[]; KString Children[]; }; struct StringFileInfo { WORD wLength; WORD wValueLength; WORD wType; WCHAR szKey[]; WORD Padding[]; StringTable Children[]; }; DWORD versioninfosize = GetFileVersionInfoSize("c://TestVerInfo.exe",0); if(versioninfosize > 0){ PWideChar versioninfodata=(PWideChar)new BYTE[versioninfosize]; try{ ZeroMemory(versioninfodata,versioninfosize); if(GetFileVersionInfo("c://TestVerInfo.exe",0,versioninfosize,versioninfodata)){ UINT uTemp = 0 ; VS_VERSIONINFO * pVerInfo; LPBYTE pOffsetBytes; struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; } * lpTranslate = NULL; VerQueryValue(versioninfodata, PChar("//VarFileInfo//Translation"),(LPVOID*)&lpTranslate,&uTemp); AnsiString lengcode=IntToHex(lpTranslate->wLanguage,4)+IntToHex(lpTranslate->wCodePage,4); LPTSTR pValueBuffer; if(!VerQueryValue(versioninfodata,("//StringFileInfo//"+lengcode+"//CompanyName").c_str(),(LPVOID*)&pValueBuffer,&uTemp)) return; int iLen; pVerInfo = (VS_VERSIONINFO *)versioninfodata; char * p; VS_FIXEDFILEINFO *fixInfo; p = ((char * )(pVerInfo->szKey) ) + (wcslen(pVerInfo->szKey)+1 ) * sizeof(wchar_t); iLen = pVerInfo->wLength - (p - (char *)pVerInfo); //VS_VERSIONINFO Padding1[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment int iii = (wcslen(pVerInfo->szKey))*2%4==0?0:(wcslen(pVerInfo->szKey))*2%4; fixInfo =(VS_FIXEDFILEINFO *) (p + iii); if (pVerInfo->wValueLength == 0 ) { return; }else{ p = (char *)fixInfo + sizeof(VS_FIXEDFILEINFO); iLen -= sizeof(VS_FIXEDFILEINFO); //check VS_FIXEDFILEINFO's Signature if(fixInfo->dwSignature!=0xfeef04bd)return; } StringFileInfo * strFileInfo; strFileInfo = (StringFileInfo *)( p); StringTable *strtab; p = (char *)strFileInfo->szKey + (wcslen(strFileInfo->szKey) + 1) * sizeof(wchar_t); //StringFileInfo Padding[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment iii = (wcslen(strFileInfo->szKey))*2%4==0?0:(wcslen(strFileInfo->szKey))*2%4; strtab = (StringTable *)(p + iii); p = (char *)strtab->szKey + (wcslen(strtab->szKey)+1) * sizeof(wchar_t); //StringTable Padding[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment iii = (wcslen(strtab->szKey))*2%4==0?0:(wcslen(strtab->szKey))*2%4; p += iii; while (( (p - (char *)strtab))<strtab->wLength){ KString *ks; ks = (KString *)p; int iilen = wcslen(ks->szKey)+1; p = (char *)ks->szKey + (iilen ) * sizeof(wchar_t) ; //String Padding[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment iii = (iilen - 1)*2%4==0?0:(iilen - 1)*2%4; p += iii; if (ks->wValueLength) { ShowMessage((wchar_t *)p); } if (!_wcsicmp(ks->szKey,L"CompanyName")){ memcpy(p,L"测试修改公司名/0",((ks->wValueLength-1)> (wcslen(L"测试修改公司名/0")+1)?(wcslen(L"测试修改公司名/0")+1):(ks->wValueLength-1))*sizeof(wchar_t)); HANDLE hResource=BeginUpdateResource("c://TestVerInfo.exe",false); if(NULL!=hResource){ if(UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), lpTranslate -> wLanguage, versioninfodata, versioninfosize)){ EndUpdateResource(hResource,false); } } break; } p +=((ks->wValueLength) * 2 )+ //32-bit Alignment Adj ((ks->wValueLength) * 2 % 4 ==0?0:2) ; } } }__finally{ delete []versioninfodata; } }
 
这么长的代码,除非有闲人,不然没有人愿意的。这是C++的代码,找个C++的编译器,例如CB,编译了,做个Dll,搞定就完了,何必转来转去的。
 
太长了吧,真晕
 
今天写该到这里 unit Uwnit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;type P_VS_FIXEDFILEINFO = ^VS_FIXEDFILEINFO; P_VS_VERSIONINFO = ^VS_VERSIONINFO; VS_VERSIONINFO = record wLength: WORD; wValueLength: WORD; wType: WORD; szKey: array of wchar; Padding1: array of WORD; Value: VS_FIXEDFILEINFO; Padding2: array of WORD; Children: array of WORD; end; KString = record wLength: WORD; wValueLength: WORD; wType: WORD; szKey: array of wchar; Padding: array of WORD; Value: array of WORD; end; StringTable = record wLength: WORD; wValueLength: WORD; wType: WORD; szKey: array of wchar; Padding: array of WORD; Children: array of KString; end; StringFileInfo = record wLength: WORD; wValueLength: WORD; wType: WORD; szKey: array of wchar; Padding: array of WORD; Children: array of StringTable; end; P_LANGANDCODEPAGE = ^LANGANDCODEPAGE; LANGANDCODEPAGE = record wLanguage: WORD; wCodePage: WORD; end;function aa(): Boolean;implementationfunction aa(): Boolean;var versioninfosize: DWORD; versioninfodata: PWideChar; uTemp: UINT; pVerInfo: P_VS_VERSIONINFO; lpTranslate: P_LANGANDCODEPAGE; pOffsetBytes: BYTE; lengcode: AnsiString; pValueBuffer: LPTSTR; iLen: integer; p: pchar; fixInfo: P_VS_FIXEDFILEINFO; iii: integer; // versioninfobuffer: array of BYTE; lpdwhandle: DWORD;begin lpdwhandle := 0; versioninfosize := GetFileVersionInfoSize(pchar('c: /TestVerInfo.exe'), lpdwhandle); if (versioninfosize > 0) then begin Setlength(versioninfobuffer, versioninfosize); versioninfodata := PWideChar(versioninfobuffer); try ZeroMemory(versioninfodata, versioninfosize); if (GetFileVersionInfo(pchar('c:/TestVerInfo.exe'), lpdwhandle, versioninfosize, Pointer(versioninfodata))) then begin uTemp := 0; VerQueryValue(versioninfodata, pchar('/VarFileInfo/Translation'), Pointer(lpTranslate), uTemp); lengcode := IntToHex(lpTranslate.wLanguage, 4) + IntToHex(lpTranslate.wCodePage, 4); if (not VerQueryValue(versioninfodata, pchar('/StringFileInfo/' + lengcode + '/CompanyName'), Pointer(pValueBuffer), uTemp)) then exit; pVerInfo := P_VS_VERSIONINFO(versioninfodata); p := pchar(pVerInfo.szKey[(Length(pVerInfo.szKey) + 1) * sizeof(wchar) - 1]); //p = ((char * )(pVerInfo - > szKey)) + (wcslen(pVerInfo - > szKey) + 1) * sizeof(wchar_t); iLen := pVerInfo.wLength - (p - pchar(pVerInfo)); //VS_VERSIONINFO Padding1[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment if (Length(pVerInfo.szKey)) * 2 mod 4 = 0 then iii := 0 else iii := (Length(pVerInfo.szKey)) * 2 mod 4; fixInfo := P_VS_FIXEDFILEINFO(p + iii); if (pVerInfo.wValueLength = 0) then begin end else begin p = (char *)fixInfo + sizeof(VS_FIXEDFILEINFO); iLen -= sizeof(VS_FIXEDFILEINFO); //check VS_FIXEDFILEINFO's Signature if(fixInfo->dwSignature!=0xfeef04bd)return; end; StringFileInfo * strFileInfo; strFileInfo = (StringFileInfo * )(p); StringTable * strtab; p = (char * )strFileInfo - > szKey + (wcslen(strFileInfo - > szKey) + 1) * sizeof(wchar_t); //StringFileInfo Padding[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment iii = (wcslen(strFileInfo - > szKey)) * 2 %4 = = 0 ?0: (wcslen(strFileInfo - > szKey)) * 2 %4; strtab = (StringTable * )(p + iii); p = (char * )strtab - > szKey + (wcslen(strtab - > szKey) + 1) * sizeof(wchar_t); //StringTable Padding[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment iii = (wcslen(strtab - > szKey)) * 2 %4 = = 0 ?0: (wcslen(strtab - > szKey)) * 2 %4; p + = iii; while (((p - (char * )strtab)) < strtab - > wLength) { KString *ks; ks = (KString *)p; int iilen = wcslen(ks->szKey)+1; p = (char *)ks->szKey + (iilen ) * sizeof(wchar_t) ; //String Padding[]: wLength + wValueLength + wType + szKey[] 32-bit Alignment iii = (iilen - 1)*2%4==0?0:(iilen - 1)*2%4; p += iii; if (ks->wValueLength) { ShowMessage((wchar_t *)p); } if (!_wcsicmp(ks - > szKey, L"CompanyName")) { memcpy(p,L"&sup2;&acirc;&Ecirc;&Ocirc;&ETH;&THORN;&cedil;&Auml;&sup1;&laquo;&Euml;&frac34;&Atilde;&ucirc;/0",((ks->wValueLength-1)> (wcslen(L"&sup2;&acirc;&Ecirc;&Ocirc;&ETH;&THORN;&cedil;&Auml;&sup1;&laquo;&Euml;&frac34;&Atilde;&ucirc;/0")+1)?(wcslen(L"&sup2;&acirc;&Ecirc;&Ocirc;&ETH;&THORN;&cedil;&Auml;&sup1;&laquo;&Euml;&frac34;&Atilde;&ucirc;/0")+1):(ks->wValueLength-1))*sizeof(wchar_t)); HANDLE hResource=BeginUpdateResource("c://TestVerInfo.exe",false); if(NULL!=hResource){ if(UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), lpTranslate -> wLanguage, versioninfodata, versioninfosize)){ EndUpdateResource(hResource,false); } } break; } p + = ((ks - > wValueLength) * 2) + //32-bit Alignment Adj ((ks - > wValueLength) * 2 % 4 = = 0 ?0: 2); } } }__finally { delete []versioninfodata; } } end.
 
先谢谢fanronghua,希望你能帮我完成
 
你也可以自己改改,我要下班了,没有什么难度的
 
fanronghua,关键我不懂C++啊!
 
多人接受答案了。
 
后退
顶部