-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkr2ext.cpp
More file actions
117 lines (104 loc) · 3.26 KB
/
kr2ext.cpp
File metadata and controls
117 lines (104 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <windows.h>
#include "kr2ext.h"
#include "tp_stub.h"
#include "hook_init.h"
//#pragma comment(linker, "/align:512")
#ifndef _DEBUG
//#pragma comment(linker, "/merge:.data=.text")
#pragma comment(linker, "/merge:.rdata=.text")
#endif
//---------------------------------------------------------------------------
void TVP_tTVPXP3ArchiveExtractionFilter_CONVENTION
TVPXP3ArchiveExtractionFilter(tTVPXP3ExtractionFilterInfo *info)
{
if (info->SizeOfSelf != sizeof(tTVPXP3ExtractionFilterInfo))
TVPThrowExceptionMessage(TJS_W("Incompatible tTVPXP3ExtractionFilterInfo size"));
DWORD hash = info->FileHash;
unsigned char key[] = {
(hash >> 8) & 0xFF,
(hash >> 8) & 0xFF,
(hash >> 1) & 0xFF,
(hash >> 7) & 0xFF,
(hash >> 5) & 0xFF};
DWORD buffsize = info->BufferSize;
unsigned char *buf = (unsigned char*)info->Buffer;
for (int i = 0; i < buffsize; ++i) {
unsigned int entryoff = info->Offset + i;
if (entryoff <= 100) {
buf[i] ^= hash >> 5;
} else {
buf[i] ^= key[entryoff & 4];
}
}
return;
// union {
// DWORD dword;
// BYTE byte[4];
// } key;
// DWORD hash = info->FileHash;
// key.byte[0]= hash>>5;
// key.byte[1]= hash>>4;
// key.byte[2]= hash>>3;
// key.byte[3]= hash>>8;
// DWORD offset = info->Offset, BufferSize = info->BufferSize;
// LPBYTE buffer= (LPBYTE)info->Buffer;
// for(int n = offset;n < offset + BufferSize; n++, buffer++) {
// // if(n<=100) *buffer++^=key.byte[2];
// // else *buffer++^=key.byte[n&3];
// if(n>4) *buffer^=hash>>12;
// }
}
extern void RegistXP3Filter();
extern void RegistGraphicLoader();
//---------------------------------------------------------------------------
#pragma comment(linker, "/EXPORT:V2Link=_V2Link@4,PRIVATE")
extern "C" HRESULT _stdcall V2Link(iTVPFunctionExporter *exporter)
{
TVPInitImportStub(exporter);
Hooker hooker;
hooker.init_hook();
//RegistGraphicLoader();
ttstr patch = TVPGetAppPath() + "patch.tjs";
if (TVPIsExistentStorageNoSearch(patch))
TVPExecuteStorage(patch);
//RegistXP3Filter();
return S_OK;
}
//---------------------------------------------------------------------------
#pragma comment(linker, "/EXPORT:V2Unlink=_V2Unlink@0,PRIVATE")
extern "C" HRESULT _stdcall V2Unlink()
{
//TVPSetXP3ArchiveExtractionFilter(NULL);
TVPUninitImportStub();
return S_OK;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" int WINAPI GetPluginInfo(int infono, LPSTR buf, int buflen) {
int nRet = 0;
if (0 == infono) {
memcpy(buf, "00AM", nRet = min(buflen, 5));
} else if (1 == infono) {
const char *pPluginName = "Archive support";
memcpy(buf, pPluginName, nRet = min((unsigned int)buflen, strlen(pPluginName) + 1));
} else {
const char *ppExtNames[] = { "*.tar;*.zip;*.7z;*.xp3;" };
const char *ppFmtNames[] = { "tar/zip format" };
int nExtNum = sizeof(ppExtNames) / sizeof(ppExtNames[0]);
infono -= 2;
if (infono >= nExtNum * 2) {
return 0;
}
if (0 == (infono & 1)) {
memcpy(buf, ppExtNames[infono >> 1], nRet = min((unsigned int)buflen, strlen(ppExtNames[infono >> 1]) + 1));
} else {
memcpy(buf, ppFmtNames[infono >> 1], nRet = min((unsigned int)buflen, strlen(ppFmtNames[infono >> 1]) + 1));
}
}
return nRet;
}