|
- #include <stdio.h>
- #include <windows.h>
- #pragma comment(lib,"ole32.lib")
- #pragma comment(lib,"dxguid.lib")
- #include "dmusici.h"
- #include "windows.h"
- #define DMUS_SEG_REPEAT_INFINITE 0xFFFFFFFF
- #define PINT int *
- #define FASTCALL __fastcall
- #pragma pack(1)
- typedef struct
- {
- DWORD Unused0;
- DWORD Text;//1
- DWORD Code;//2
- DWORD Unused2;//
- DWORD Address;
- DWORD Value;
- USHORT Operator;
- } *ActionParams;
- typedef void *HANDLE;
- const FARPROC (WINAPI**sc_GetProcAddress) ( HMODULE hModule, LPCSTR lpProcName ) = (const FARPROC(WINAPI**)(HMODULE,LPCSTR))0x4ED160;
- const FARPROC (WINAPI**sc_GetProcAddress1) (void) = (const FARPROC(WINAPI**)(void))0x4ED160;
- char* (FASTCALL*GetResString)(USHORT index) = (char*(FASTCALL*)(USHORT))0x448880;
- DWORD (WINAPI**sc_LoadLibrary)(LPCSTR) = (DWORD(WINAPI**)(LPCSTR))(0x4ED15C);
- void (WINAPI**sc_FreeLibrary)(DWORD) = (void(WINAPI**)(DWORD))(0x4ED138);
- BOOL (WINAPI**sc_VirtualProtect)(DWORD, DWORD, DWORD, DWORD *) = (BOOL(WINAPI**)(DWORD, DWORD, DWORD, DWORD *))0x5D171358;
- void * (WINAPI**sc_VirtualAlloc)(void *, SIZE_T, DWORD, DWORD) = (void *(WINAPI**)(void *, SIZE_T, DWORD, DWORD))0x004ED127;
- FILE *(*sc_fopen)(LPCSTR,LPCSTR)=(FILE *(*)(LPCSTR,LPCSTR))(0x77C0F010/*0x7C02AE09*/);
- int(*sc_fwrite)(void*,DWORD,DWORD,FILE*)=(int(*)(void*,DWORD,DWORD,FILE*))(0x77C1173B/*0x7C02CF72*/);
- int(*sc_fclose)(FILE*)=(int(*)(FILE*))(0x77C10AB1/*0x7C01441F*/);
- void *(*sc_malloc)(DWORD)=(void *(*)(DWORD))(0x77BFC407);
- void (*sc_free)(void *)=(void (*)(void *))(0x77BFC21B);
- BOOL(WINAPI**sc_SFileOpenArchive)(char *archivename, DWORD dwPriority, DWORD dwFlags, HANDLE *handle)=(BOOL(WINAPI**)(char *archivename, DWORD dwPriority, DWORD dwFlags, HANDLE *handle))0x4ED2BC;
- BOOL(WINAPI**sc_SFileOpenFile)(char *filename, HANDLE *handle) = (BOOL(WINAPI**)(char *filename, HANDLE *handle))0x4ED364;
- BOOL(WINAPI**sc_SFileCloseFile)(HANDLE hFile) = (BOOL(WINAPI**)(HANDLE hFile))0x4ED360;
- BOOL(WINAPI**sc_SFileCloseArchive)(HANDLE hArchive) = (BOOL(WINAPI**)(HANDLE hArchive))0x4ED2C0;
- long(WINAPI**sc_SFileGetFileSize)(HANDLE hFile, LPDWORD lpFileSizeHigh) = (long(WINAPI**)(HANDLE hFile, LPDWORD lpFileSizeHigh))0x4ED358;
- BOOL(WINAPI**sc_SFileOpenFileEx)(HANDLE handle, char *filename, char mode, HANDLE *result) =(BOOL(WINAPI**)(HANDLE handle, char *filename, char mode, HANDLE *result))0x4ED368;
- BOOL(WINAPI**sc_SFileReadFile)(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD*, DWORD) = (BOOL(WINAPI**)(HANDLE hFile, void *buffer, DWORD nNumberOfBytesToRead, DWORD*, DWORD))0x4ED354;
- //int(WINAPI*sc_CoInitialize)(LPVOID pvReserved) = (int(WINAPI*)(LPVOID pvReserved))0x769B2A53;
- //int(WINAPI*sc_CoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter,DWORD dwClsContext, REFIID riid, LPVOID FAR* ppv) = (int(WINAPI*)(REFCLSID rclsid, LPUNKNOWN pUnkOuter,DWORD dwClsContext, REFIID riid, LPVOID FAR* ppv))0x769B057E;
- BOOL FASTCALL Comment(ActionParams params)
- {
- int(WINAPI*sc_CoInitialize)(LPVOID pvReserved);
- int(WINAPI*sc_CoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter,DWORD dwClsContext, REFIID riid, LPVOID FAR* ppv);
- _asm{
- call $+5+13;
- _EMIT 'C';
- _EMIT 'o'
- _EMIT 'I'
- _EMIT 'n'
- _EMIT 'i'
- _EMIT 't'
- _EMIT 'i'
- _EMIT 'a'
- _EMIT 'l'
- _EMIT 'i'
- _EMIT 'z'
- _EMIT 'e'
- _EMIT '\0';
- lodsd;
- push 76990000h;
- }
- (*sc_GetProcAddress1)();
- _asm{
- mov sc_CoInitialize,eax;
- call $+5+17;
- _EMIT 'C';
- _EMIT 'o'
- _EMIT 'C'
- _EMIT 'r'
- _EMIT 'e'
- _EMIT 'a'
- _EMIT 't'
- _EMIT 'e'
- _EMIT 'I'
- _EMIT 'n'
- _EMIT 's'
- _EMIT 't'
- _EMIT 'a';
- _EMIT 'n'
- _EMIT 'c'
- _EMIT 'e'
- _EMIT '\0'
- lodsd;
- push 76990000h;
- }
-
- (*sc_GetProcAddress1)();
- _asm{// call DS:sc_GetProcAddress;
- mov sc_CoCreateInstance,eax;
- }
-
- HANDLE mpq,file;
- DWORD siz;
- IDirectMusicPerformance* performance = 0;
- IDirectMusicSegment* segment = 0;
- IDirectMusicLoader* loader = 0;
- unsigned char* data = 0;
- unsigned char *dest;
- DMUS_OBJECTDESC desc;
- if(!(*sc_SFileOpenArchive)((char*)0x509364, 0, 0, &mpq)) return false;
- if(!(*sc_SFileOpenFileEx)(mpq, (*GetResString)(params->Text), 0, &file)) return false;
- siz=(*sc_SFileGetFileSize)(file, 0);
- dest=(unsigned char *)(*sc_malloc)(siz);
- if(dest==0)
- return true;
- (*sc_SFileReadFile)(file, dest, siz, &siz, 0);
- (*sc_SFileCloseFile)(file);
- (*sc_SFileCloseArchive)(mpq);
- //if(data) (*sc_free)(data);//释放上一个资源
- data = dest;
- /*
- if(segment)
- {
- if(performance)
- {
- performance->Stop(segment,0,0,0);
- segment->SetParam(GUID_Unload,-1,0,0,(void**)performance);
- }
- segment->Release();
- segment=0;
- }
- if(loader)
- {
- loader->Release();
- loader=0;
- }
- if(performance)
- {
- performance->CloseDown();
- performance->Release();
- performance=0;
- }
- CoUninitialize();
- */
- desc.dwSize = 848;
- desc.pbMemData = data;
- desc.llMemLength = siz;
- desc.dwValidData = 1026;
- desc.guidClass.Data1=0xd2ac2882;
- desc.guidClass.Data2=0xb39b;
- desc.guidClass.Data3=0x11d1;
- desc.guidClass.Data4[0]=0x87;
- desc.guidClass.Data4[1]=0x04;
- desc.guidClass.Data4[2]=0x00;
- desc.guidClass.Data4[3]=0x60;
- desc.guidClass.Data4[4]=0x08;
- desc.guidClass.Data4[5]=0x93;
- desc.guidClass.Data4[6]=0xb1;
- desc.guidClass.Data4[7]=0xbd;
- GUID CLSIDDirectMusicPerformance = {0xd2ac2881,0xb39b,0x11d1,{0x87,0x04,0x00,0x60,0x08,0x93,0xb1,0xbd}};
- GUID IIDIDirectMusicPerformance = {0x07d43d03,0x6523,0x11d2,{0x87,0x1d,0x00,0x60,0x08,0x93,0xb1,0xbd}};
- GUID CLSIDDirectMusicLoader = {0xd2ac2892,0xb39b,0x11d1,{0x87,0x04,0x00,0x60,0x08,0x93,0xb1,0xbd}};
- GUID IIDIDirectMusicLoader = {0x2ffaaca2,0x5dca,0x11d2,{0xaf,0xa6,0x00,0xaa,0x00,0x24,0xd8,0xb6}};
- GUID GUIDStandardMIDIFile = {0x06621075,0xe92e,0x11d1,{0xa8,0xc5,0x00,0xc0,0x4f,0xa3,0x72,0x6e}};
- GUID GUIDDownload = {0xd2ac28a7,0xb39b,0x11d1,{0x87,0x04,0x00,0x60,0x08,0x93,0xb1,0xbd}};
- GUID IIDIDirectMusicSegment = {0xf96029a2,0x4282,0x11d2,{0x87,0x17,0x00,0x60,0x08,0x93,0xb1,0xbd}};
- if((*sc_CoInitialize)(0) < 0) return true;
- if((*sc_CoCreateInstance)(CLSIDDirectMusicPerformance,0,CLSCTX_INPROC,IIDIDirectMusicPerformance,(void**)&performance) < 0) return true;
- if((*sc_CoCreateInstance)(CLSIDDirectMusicLoader,0,CLSCTX_INPROC,IIDIDirectMusicLoader,(void**)&loader) < 0) return true;
- loader->GetObject(&desc,IIDIDirectMusicSegment,(void**)&segment);
- performance->Init(0,0,0);
- performance->AddPort(0);
- segment->SetParam(GUIDStandardMIDIFile,-1,0,0,performance);
- segment->SetParam(GUIDDownload,-1,0,0,performance);
- segment->SetRepeats(params->Code==0?1:params->Code);
- performance->PlaySegment(segment,0,0,0);
- return true;
- }
- void AfterFunction(){}
- LPCSTR Base64Enc(int size = 0)
- {
- if (size <= 0)
- size = PtrToLong((PBYTE)AfterFunction - (PBYTE)Comment);
- PBYTE text = (PBYTE)Comment;
- PBYTE out = new BYTE[(size - 1) * 4 / 3 + 1],buf = out;
- int buflen = 0;
- while(size>0)
- {
- *buf++ = ((text[0] >> 2 ) & 0x3f) + 0x30;
- *buf++ = (((text[0] & 3) << 4) | (text[1] >> 4)) + 0x30;
- *buf++ = (((text[1] & 0xF) << 2) | (text[2] >> 6)) + 0x30;
- *buf++ = (text[2] & 0x3F) + 0x30;
- text +=3;
- size -=3;
- buflen +=4;
- }
- *buf = 0;
- return (LPCSTR)out;
- }
- int main(int argc, CHAR* argv[])
- {
- malloc(1);
- FILE *f1=fopen("d:\\desktop\\comment.txt","wb");
- fprintf(f1,"Comment(\"%s\", 0, 0, 17, 0, 1);\n",Base64Enc());
- fclose(f1);
- int i;
- }
复制代码 |
|