-
Notifications
You must be signed in to change notification settings - Fork 2
/
BBDecoder.cpp
125 lines (105 loc) · 3.92 KB
/
BBDecoder.cpp
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
118
119
120
121
122
123
124
125
#include "precomp.h"
#include "interfaceData.h"
#include <ctime>
CKObjectDeclaration *FillBBDecoderDecl();
CKERROR CreateBBDecoderProto(CKBehaviorPrototype **);
int BBDecoder(const CKBehaviorContext& behcontext);
CKObjectDeclaration *FillBBDecoderDecl()
{
CKObjectDeclaration *od = CreateCKObjectDeclaration("BBDecoder");
od->SetDescription("A block to decode BB.");
/* rem:
<SPAN CLASS=in>In K: </SPAN>any of the inputs will trigger the process.<BR>
<SPAN CLASS=out>Out K: </SPAN>if the building block is activated, all the outputs are then activated.<BR>
<BR>
This convenient building block acts just like an interface object in the schematique.<BR>
You can add as many inputs and outputs as needed.<BR>
<BR>
*/
od->SetType(CKDLL_BEHAVIORPROTOTYPE);
od->SetGuid(CKGUID(0x37543829, 0xf0c3b39));
od->SetAuthorGuid(VIRTOOLS_GUID);
od->SetAuthorName("BearKidsTeam");
od->SetVersion(0x00010000);
od->SetCreationFunction(CreateBBDecoderProto);
od->SetCompatibleClassId(CKCID_BEOBJECT);
od->SetCategory("Custom/VirtoolsScriptDeobfuscation");
return od;
}
CKERROR CreateBBDecoderProto(CKBehaviorPrototype **pproto)
{
CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("BBDecoder");
if (!proto) return CKERR_OUTOFMEMORY;
proto->DeclareInput("In 0");
proto->DeclareOutput("Out 0");
proto->DeclareInParameter("File Name", CKPGUID_STRING);
proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL);
proto->SetFunction(BBDecoder);
*pproto = proto;
return CK_OK;
}
int BBDecoder(const CKBehaviorContext& behcontext)
{
InitVSDTempFolder(behcontext.Context); // yyc mark: init dynamic temp folder first.
interface_t parse_bb_test(CKBehavior *bb, CKFile *file);
void decorate(interface_t &data, CKBehavior *bb);
void generate_bb_test(interface_t &interface_data, CKBehavior *bb, CKFile *file);
CKBehavior* beh = behcontext.Behavior;
CKContext* ctx = behcontext.Context;
CKVariableManager* vMan = ctx->GetVariableManager();
// Dynamic ?
BOOL dynamic = FALSE;
CKBOOL keepSAS = FALSE;
CK_LOAD_FLAGS loadoptions = CK_LOAD_FLAGS(CK_LOAD_DEFAULT | CK_LOAD_AUTOMATICMODE);
if (dynamic) loadoptions = (CK_LOAD_FLAGS)(loadoptions | CK_LOAD_AS_DYNAMIC_OBJECT);
CKObjectArray* array = CreateCKObjectArray();
ctx->SetAutomaticLoadMode(CKLOAD_OK, CKLOAD_OK, CKLOAD_OK, CKLOAD_OK);
CKSTRING fname = (CKSTRING)beh->GetInputParameterReadDataPtr(0);
XString filename(fname);
ctx->GetPathManager()->ResolveFileName(filename, DATA_PATH_IDX, -1);
if (ctx->Load(filename.Str(), array, loadoptions) != CK_OK) {
DeleteCKObjectArray(array);
throw "fuck";
}
// in files saved with Virtools 3.0+, the Variable Manager setting
// for File Options/Compression is implemented as a File Write Mode, so
// the global File Write Mode defaults back to CKFILE_FORVIEWER, and
// scripts will be hidden
// we correct this by explicity setting the File Write Mode after Loading
ctx->SetFileWriteMode((CK_FILE_WRITEMODE)(ctx->GetFileWriteMode() & ~CKFILE_FORVIEWER));
clock_t c=clock();
for (array->Reset(); !array->EndOfList(); array->Next()) {
CKObject* o = array->GetData(ctx);
if (CKIsChildClassOf(o, CKCID_BEHAVIOR)) {
CKBehavior* bo = (CKBehavior*)o;
CKFile *file = bo->GetCKContext()->CreateCKFile();
interface_t data = parse_bb_test(bo, file);
decorate(data, bo);
generate_bb_test(data, bo, file);
}
}
printfdbg("decorate+generate time: %f\n",1.*(clock()-c)/CLOCKS_PER_SEC);
CKLevel* level = ctx->GetCurrentLevel();
for (array->Reset(); !array->EndOfList(); array->Next()) {
CKObject* o = array->GetData(ctx);
if (!CKIsChildClassOf(o, CKCID_BEHAVIOR)) {
if (CKIsChildClassOf(o, CKCID_SCENE)) {
level->AddScene((CKScene*)o);
}
else {
level->AddObject(o);
}
}
}
level->BeginAddSequence(FALSE);
DeleteCKObjectArray(array);
int i, count = beh->GetInputCount();
for (i = 0; i<count; ++i) {
beh->ActivateInput(i, FALSE);
}
count = beh->GetOutputCount();
for (i = 0; i<count; ++i) {
beh->ActivateOutput(i);
}
return CKBR_OK;
}