forked from Source-Python-Dev-Team/Source.Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_wrap.cpp
More file actions
819 lines (692 loc) · 23.4 KB
/
Copy pathmemory_wrap.cpp
File metadata and controls
819 lines (692 loc) · 23.4 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
/**
* =============================================================================
* Source Python
* Copyright (C) 2012-2015 Source Python Development Team. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the Source Python Team gives you permission
* to link the code of this program (as well as its derivative works) to
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, the Source.Python
* Development Team grants this exception to all derivative works.
*/
// ============================================================================
// >> INCLUDES
// ============================================================================
#include "export_main.h"
// Memory
#include "memory_scanner.h"
#include "memory_tools.h"
#include "memory_hooks.h"
#include "memory_function_info.h"
#include "memory_utilities.h"
#include "memory_wrap.h"
// DynamicHooks
#include "registers.h"
// ============================================================================
// >> FORWARD DECLARATIONS
// ============================================================================
void export_function_info(scope);
void export_binary_file(scope);
void export_pointer(scope);
void export_function(scope);
void export_data_type_t(scope);
void export_convention_t(scope);
void export_hook_type_t(scope);
void export_stack_data(scope);
void export_register_t(scope);
void export_register(scope);
void export_registers(scope);
void export_calling_convention(scope);
void export_functions(scope);
void export_global_variables(scope);
// ============================================================================
// >> Exports the _memory module
// ============================================================================
DECLARE_SP_MODULE(_memory)
{
export_function_info(_memory);
export_binary_file(_memory);
export_pointer(_memory);
export_function(_memory);
export_data_type_t(_memory);
export_convention_t(_memory);
export_hook_type_t(_memory);
export_stack_data(_memory);
export_register_t(_memory);
export_register(_memory);
export_registers(_memory);
export_calling_convention(_memory);
export_functions(_memory);
export_global_variables(_memory);
}
// ============================================================================
// >> CFunctionInfo
// ============================================================================
void export_function_info(scope _core)
{
class_<CFunctionInfo> _FunctionInfo("FunctionInfo", no_init);
_FunctionInfo.def_readonly("is_virtual", &CFunctionInfo::m_bIsVirtual);
_FunctionInfo.def_readonly("this_pointer_offset", &CFunctionInfo::m_iThisPtrOffset);
_FunctionInfo.def_readonly("vtable_index", &CFunctionInfo::m_iVtableIndex);
_FunctionInfo.def_readonly("vtable_offset", &CFunctionInfo::m_iVtableOffset);
_FunctionInfo.def_readonly("return_type", &CFunctionInfo::m_eReturnType);
_FunctionInfo.add_property("argument_types", &CFunctionInfo::GetArgumentTypes);
_FunctionInfo.def_readonly("calling_convention", &CFunctionInfo::m_eCallingConvention);
}
// ============================================================================
// >> CBinaryFile
// ============================================================================
void export_binary_file(scope _memory)
{
class_<CBinaryFile, boost::noncopyable>("BinaryFile", no_init)
// Class methods
.def("find_pointer",
&CBinaryFile::FindPointer,
"Rips out a pointer from a function.",
("signature", arg("offset")=0, arg("level")=0),
manage_new_object_policy()
)
.def("find_address",
&CBinaryFile::FindAddress,
"Returns the address of a signature or symbol found in memory.",
args("identifier"),
manage_new_object_policy()
)
// Special methods
.def("__getitem__",
&CBinaryFile::FindAddress,
"Returns the address of a signature or symbol found in memory.",
args("identifier"),
manage_new_object_policy()
)
// Attributes
.def_readwrite("address",
&CBinaryFile::m_ulAddr,
"Base address of the binary."
)
.def_readwrite("size",
&CBinaryFile::m_ulSize,
"Size of the binary."
)
;
}
// ============================================================================
// >> CPointer
// ============================================================================
#define EXPOSE_SET_TYPE(name, type) \
.def("set_" XSTRINGIFY(name), \
&CPointer::Set<type>, \
"Sets the value at the given memory location.", \
("value", arg("offset")=0) \
)
#define EXPOSE_GET_TYPE(name, type) \
.def("get_" XSTRINGIFY(name), \
&CPointer::Get<type>, \
"Returns the value at the given memory location.", \
(arg("offset")=0) \
)
#define EXPOSE_GET_SET_TYPE(name, type) \
EXPOSE_SET_TYPE(name, type) \
EXPOSE_GET_TYPE(name, type)
void export_pointer(scope _memory)
{
class_<CPointer, CPointer *>("Pointer", init< optional<unsigned long, bool> >())
.def(init<CPointer&>())
// get/set_<type> methods
EXPOSE_GET_SET_TYPE(bool, bool)
EXPOSE_GET_SET_TYPE(char, char)
EXPOSE_GET_SET_TYPE(uchar, unsigned char)
EXPOSE_GET_SET_TYPE(short, short)
EXPOSE_GET_SET_TYPE(ushort, unsigned short)
EXPOSE_GET_SET_TYPE(int, int)
EXPOSE_GET_SET_TYPE(uint, unsigned int)
EXPOSE_GET_SET_TYPE(long, long)
EXPOSE_GET_SET_TYPE(ulong, unsigned long)
EXPOSE_GET_SET_TYPE(long_long, long long)
EXPOSE_GET_SET_TYPE(ulong_long, unsigned long long)
EXPOSE_GET_SET_TYPE(float, float)
EXPOSE_GET_SET_TYPE(double, double)
EXPOSE_GET_SET_TYPE(string_pointer, const char*)
.def("get_pointer",
&CPointer::GetPtr,
"Returns the value at the given memory location.",
(arg("offset")=0),
manage_new_object_policy()
)
.def("get_string_array",
&CPointer::GetStringArray,
"Returns the value at the memory location.",
(arg("offset")=0)
)
.def("set_pointer",
&CPointer::SetPtr,
"Sets the value at the given memory location.",
("value", arg("offset")=0)
)
.def("set_string_array",
&CPointer::SetStringArray,
"Sets the value at the given memory location.",
("value",arg( "offset")=0)
)
// Other methods
.def("get_virtual_func",
&CPointer::GetVirtualFunc,
"Returns the address (as a Pointer instance) of a virtual function at the given index.",
args("index"),
manage_new_object_policy()
)
.def("make_function",
GET_METHOD(CFunction*, CPointer, MakeFunction, object, object, object),
"Creates a new Function instance.",
args("convention", "arguments", "return_type"),
manage_new_object_policy()
)
.def("make_function",
GET_METHOD(CFunction*, CPointer, MakeFunction, CFunctionInfo&),
"Use the given FunctionInfo object to convert the pointer into a Function object.",
("info"),
manage_new_object_policy()
)
.def("make_virtual_function",
GET_METHOD(CFunction*, CPointer, MakeVirtualFunction, int, object, object, object),
"Creates a new Function instance.",
args("index", "convention", "arguments", "return_type"),
manage_new_object_policy()
)
.def("make_virtual_function",
GET_METHOD(CFunction*, CPointer, MakeVirtualFunction, CFunctionInfo&),
"Use the given FunctionInfo object to retrieve a virtual function and convert it into a Function object.",
("info"),
manage_new_object_policy()
)
.def("realloc",
&CPointer::PreRealloc,
"Reallocates a memory block.",
args("size"),
manage_new_object_policy()
)
.def("dealloc",
&CPointer::PreDealloc,
"Deallocates a memory block."
)
.def("__del__",
&CPointer::__del__
)
.def("get_size",
&CPointer::GetSize,
"Returns the size of the memory block."
)
.def("compare",
&CPointer::Compare,
"Compares the first <num> bytes of both pointers. Returns 0 if they are equal. A value greater than zero indicates that the first "\
"byte that does not match in both pointers has a greater value in <self> than in <other>. A value less than zero indicates the opposite.",
args("other", "num")
)
.def("is_overlapping",
&CPointer::IsOverlapping,
"Returns True if the pointers are overlapping each other.",
args("destination", "num_bytes")
)
.def("search_bytes",
&CPointer::SearchBytes,
"Searches within the first <num_bytes> of this memory block for the first occurence of <bytes> and returns a pointer it.",
args("bytes", "num_bytes"),
manage_new_object_policy()
)
.def("copy",
&CPointer::Copy,
"Copies <num_bytes> from <self> to the pointer <destination>. Overlapping is not allowed!",
args("destination", "num_bytes")
)
.def("move",
&CPointer::Move,
"Copies <num_bytes> from <self> to the pointer <destination>. Overlapping is allowed!",
args("destination", "num_bytes")
)
// Special methods
.def("__int__", make_getter(&CPointer::m_ulAddr))
.def(!self)
.def(self == other<unsigned long>())
.def(self == self)
.def(self != other<unsigned long>())
.def(self != self)
.def(self += int())
.def(self += self)
.def("__add__", &CPointer::operator+<unsigned long>, manage_new_object_policy())
.def("__add__", &CPointer::operator+<CPointer>, manage_new_object_policy())
.def("__radd__", &CPointer::operator+<unsigned long>, manage_new_object_policy())
.def("__radd__", &CPointer::operator+<CPointer>, manage_new_object_policy())
.def(self -= int())
.def(self -= self)
.def("__sub__", &CPointer::operator-<unsigned long>, manage_new_object_policy())
.def("__sub__", &CPointer::operator-<CPointer>, manage_new_object_policy())
.def("__rsub__", &CPointer::operator-<unsigned long>, manage_new_object_policy())
.def("__rsub__", &CPointer::operator-<CPointer>, manage_new_object_policy())
// Attributes
.def_readwrite("address",
&CPointer::m_ulAddr
)
.def_readwrite("auto_dealloc",
&CPointer::m_bAutoDealloc
)
;
}
// ============================================================================
// >> CFunction
// ============================================================================
void export_function(scope _memory)
{
class_<CFunction, bases<CPointer>, boost::noncopyable >("Function", init<unsigned long, object, object, object>())
.def(init<CFunction&>())
.def("__call__",
raw_method(&CFunction::Call),
"Calls the function dynamically."
)
.def("is_callable",
&CFunction::IsCallable,
"Return True if the function is callable."
)
.def("is_hookable",
&CFunction::IsHookable,
"Return True if the function is hookable."
)
.def("is_hooked",
&CFunction::IsHooked,
"Return True if the function is hooked."
)
.def("call_trampoline",
raw_method(&CFunction::CallTrampoline),
"Calls the trampoline function dynamically."
)
.def("add_hook",
&CFunction::AddHook,
"Adds a hook callback.",
args("hook_type", "callback")
)
.def("remove_hook",
&CFunction::RemoveHook,
"Removes a hook callback.",
args("hook_type", "callback")
)
.def("add_pre_hook",
&CFunction::AddPreHook,
"Adds a pre-hook callback."
)
.def("add_post_hook",
&CFunction::AddPostHook,
"Adds a post-hook callback."
)
.def("remove_pre_hook",
&CFunction::RemovePreHook,
"Removes a pre-hook callback."
)
.def("remove_post_hook",
&CFunction::RemovePostHook,
"Removes a post-hook callback."
)
.def("_delete_hook",
&CFunction::DeleteHook,
"Removes all hooks and restores the original function."
)
// Attributes
.def_readonly("arguments",
&CFunction::m_tArgs
)
.def_readonly("return_type",
&CFunction::m_oConverter
)
.def_readonly("convention",
&CFunction::m_eCallingConvention
)
;
}
// ============================================================================
// >> DataType_t
// ============================================================================
void export_data_type_t(scope _memory)
{
enum_<DataType_t>("DataType")
.value("VOID", DATA_TYPE_VOID)
.value("BOOL", DATA_TYPE_BOOL)
.value("CHAR", DATA_TYPE_CHAR)
.value("UCHAR", DATA_TYPE_UCHAR)
.value("SHORT", DATA_TYPE_SHORT)
.value("USHORT", DATA_TYPE_USHORT)
.value("INT", DATA_TYPE_INT)
.value("UINT", DATA_TYPE_UINT)
.value("LONG", DATA_TYPE_LONG)
.value("ULONG", DATA_TYPE_ULONG)
.value("LONG_LONG", DATA_TYPE_LONG_LONG)
.value("ULONG_LONG", DATA_TYPE_ULONG_LONG)
.value("FLOAT", DATA_TYPE_FLOAT)
.value("DOUBLE", DATA_TYPE_DOUBLE)
.value("POINTER", DATA_TYPE_POINTER)
.value("STRING", DATA_TYPE_STRING)
;
}
// ============================================================================
// >> Convention_t
// ============================================================================
void export_convention_t(scope _memory)
{
enum_<Convention_t>("Convention")
.value("CUSTOM", CONV_CUSTOM)
.value("CDECL", CONV_CDECL)
.value("STDCALL", CONV_STDCALL)
.value("THISCALL", CONV_THISCALL)
;
}
// ============================================================================
// >> HookType_t
// ============================================================================
void export_hook_type_t(scope _memory)
{
enum_<HookType_t>("HookType")
.value("PRE", HOOKTYPE_PRE)
.value("POST", HOOKTYPE_POST)
;
}
// ============================================================================
// >> CStackData
// ============================================================================
void export_stack_data(scope _memory)
{
class_<CStackData>("StackData", init<CHook*>())
// Special methods
.def("__getitem__",
&CStackData::GetItem,
"Returns the argument at the specified index."
)
.def("__setitem__",
&CStackData::SetItem,
"Sets the argument at the specified index."
)
.def("__repr__",
&CStackData::__repr__
)
.add_property("registers",
make_function(&CStackData::GetRegisters, reference_existing_object_policy())
)
;
}
// ============================================================================
// >> Register_t
// ============================================================================
void export_register_t(scope _memory)
{
enum_<Register_t>("Register")
// ========================================================================
// >> 8-bit General purpose registers
// ========================================================================
.value("AL", AL)
.value("CL", CL)
.value("DL", DL)
.value("BL", BL)
.value("AH", AH)
.value("CH", CH)
.value("DH", DH)
.value("BH", BH)
// ========================================================================
// >> 16-bit General purpose registers
// ========================================================================
.value("AX", AX)
.value("CX", CX)
.value("DX", DX)
.value("BX", BX)
.value("SP", SP)
.value("BP", BP)
.value("SI", SI)
.value("DI", DI)
// ========================================================================
// >> 32-bit General purpose registers
// ========================================================================
.value("EAX", EAX)
.value("ECX", ECX)
.value("EDX", EDX)
.value("EBX", EBX)
.value("ESP", ESP)
.value("EBP", EBP)
.value("ESI", ESI)
.value("EDI", EDI)
// ========================================================================
// >> 64-bit MM (MMX) registers
// ========================================================================
.value("MM0", MM0)
.value("MM1", MM1)
.value("MM2", MM2)
.value("MM3", MM3)
.value("MM4", MM4)
.value("MM5", MM5)
.value("MM6", MM6)
.value("MM7", MM7)
// ========================================================================
// >> 128-bit XMM registers
// ========================================================================
.value("XMM0", XMM0)
.value("XMM1", XMM1)
.value("XMM2", XMM2)
.value("XMM3", XMM3)
.value("XMM4", XMM4)
.value("XMM5", XMM5)
.value("XMM6", XMM6)
.value("XMM7", XMM7)
// ========================================================================
// >> 16-bit Segment registers
// ========================================================================
.value("CS", CS)
.value("SS", SS)
.value("DS", DS)
.value("ES", ES)
.value("FS", FS)
.value("GS", GS)
// ========================================================================
// >> 80-bit FPU registers
// ========================================================================
.value("ST0", ST0)
// The following registers are currently not supported by DynamicHooks
/*
.value("ST1", ST1)
.value("ST2", ST2)
.value("ST3", ST3)
.value("ST4", ST4)
.value("ST5", ST5)
.value("ST6", ST6)
.value("ST7", ST7)
*/
;
}
// ============================================================================
// >> CRegister
// ============================================================================
void export_register(scope _memory)
{
class_<CRegister, CRegister*, boost::noncopyable>("ProcessorRegister", no_init)
.add_property("size",
make_getter(&CRegister::m_iSize)
)
.add_property("address",
make_function(&CRegisterExt::GetAddress, manage_new_object_policy())
)
;
}
// ============================================================================
// >> CRegisters
// ============================================================================
void export_registers(scope _memory)
{
class_<CRegisters, boost::noncopyable>("Registers", no_init)
.def_readonly("al", &CRegisters::m_al)
.def_readonly("cl", &CRegisters::m_cl)
.def_readonly("dl", &CRegisters::m_dl)
.def_readonly("bl", &CRegisters::m_bl)
.def_readonly("ah", &CRegisters::m_ah)
.def_readonly("ch", &CRegisters::m_ch)
.def_readonly("dh", &CRegisters::m_dh)
.def_readonly("bh", &CRegisters::m_bh)
.def_readonly("ax", &CRegisters::m_ax)
.def_readonly("cx", &CRegisters::m_cx)
.def_readonly("dx", &CRegisters::m_dx)
.def_readonly("bx", &CRegisters::m_bx)
.def_readonly("sp", &CRegisters::m_sp)
.def_readonly("bp", &CRegisters::m_bp)
.def_readonly("si", &CRegisters::m_si)
.def_readonly("di", &CRegisters::m_di)
.def_readonly("eax", &CRegisters::m_eax)
.def_readonly("ecx", &CRegisters::m_ecx)
.def_readonly("edx", &CRegisters::m_edx)
.def_readonly("ebx", &CRegisters::m_ebx)
.def_readonly("esp", &CRegisters::m_esp)
.def_readonly("ebp", &CRegisters::m_ebp)
.def_readonly("esi", &CRegisters::m_esi)
.def_readonly("edi", &CRegisters::m_edi)
.def_readonly("mm0", &CRegisters::m_mm0)
.def_readonly("mm1", &CRegisters::m_mm1)
.def_readonly("mm2", &CRegisters::m_mm2)
.def_readonly("mm3", &CRegisters::m_mm3)
.def_readonly("mm4", &CRegisters::m_mm4)
.def_readonly("mm5", &CRegisters::m_mm5)
.def_readonly("mm6", &CRegisters::m_mm6)
.def_readonly("mm7", &CRegisters::m_mm7)
.def_readonly("xmm0", &CRegisters::m_xmm0)
.def_readonly("xmm1", &CRegisters::m_xmm1)
.def_readonly("xmm2", &CRegisters::m_xmm2)
.def_readonly("xmm3", &CRegisters::m_xmm3)
.def_readonly("xmm4", &CRegisters::m_xmm4)
.def_readonly("xmm5", &CRegisters::m_xmm5)
.def_readonly("xmm6", &CRegisters::m_xmm6)
.def_readonly("xmm7", &CRegisters::m_xmm7)
.def_readonly("cs", &CRegisters::m_cs)
.def_readonly("ss", &CRegisters::m_ss)
.def_readonly("ds", &CRegisters::m_ds)
.def_readonly("es", &CRegisters::m_es)
.def_readonly("fs", &CRegisters::m_fs)
.def_readonly("gs", &CRegisters::m_gs)
.def_readonly("st0", &CRegisters::m_st0)
// The following registers are currently not supported by DynamicHooks
/*
.def_readonly("st1", &CRegisters::m_st1)
.def_readonly("st2", &CRegisters::m_st2)
.def_readonly("st3", &CRegisters::m_st3)
.def_readonly("st4", &CRegisters::m_st4)
.def_readonly("st5", &CRegisters::m_st5)
.def_readonly("st6", &CRegisters::m_st6)
.def_readonly("st7", &CRegisters::m_st7)
*/
;
}
// ============================================================================
// >> ICallingConventionWrapper
// ============================================================================
void export_calling_convention(scope _memory)
{
class_<ICallingConventionWrapper, boost::noncopyable>("CallingConvention", init< object, DataType_t, optional<int> >())
.def("get_registers",
pure_virtual(&ICallingConventionWrapper::GetRegisters)
)
.def("get_pop_size",
pure_virtual(&ICallingConventionWrapper::GetPopSize)
)
.def("get_argument_ptr",
pure_virtual(&ICallingConventionWrapper::GetArgumentPtrWrapper)
)
.def("argument_ptr_changed",
pure_virtual(&ICallingConventionWrapper::ArgumentPtrChanged)
)
.def("get_return_ptr",
pure_virtual(&ICallingConventionWrapper::GetReturnPtrWrapper)
)
.def("return_ptr_changed",
pure_virtual(&ICallingConventionWrapper::ReturnPtrChanged)
)
.add_property("argument_types",
&ICallingConventionWrapper::GetArgTypes
)
.def_readonly("return_type",
&ICallingConventionWrapper::m_returnType
)
.def_readonly("alignment",
&ICallingConventionWrapper::m_iAlignment
)
ADD_MEM_TOOLS_WRAPPER(ICallingConventionWrapper, ICallingConvention)
;
}
// ============================================================================
// >> FUNCTIONS
// ============================================================================
void export_functions(scope _memory)
{
def("find_binary",
&FindBinary,
"Returns a BinaryFile object or None.",
("path", arg("srv_check")=true),
reference_existing_object_policy()
);
def("alloc",
Alloc,
"Allocates a memory block.",
("size", arg("auto_dealloc")=true),
manage_new_object_policy()
);
def("get_object_pointer",
&GetObjectPointer,
args("object"),
"Returns the pointer of the C++ object"
);
def("make_object",
&MakeObject,
"Wraps a pointer using an exposed class."
);
def("get_size",
&GetSize,
"Returns the size of the class object or instance of its C++ class."
);
def("get_data_type_size",
&GetDataTypeSize,
("data_type", arg("alignment")=4)
);
}
// ============================================================================
// >> GLOBAL VARIABLES
// ============================================================================
dict g_oExposedClasses;
dict g_oClassInfo;
#define ADD_NATIVE_TYPE_SIZE(name, type) \
scope().attr("TYPE_SIZES")[name] = sizeof(type);
void export_global_variables(scope _memory)
{
_memory.attr("EXPOSED_CLASSES") = g_oExposedClasses;
_memory.attr("CLASS_INFO") = g_oClassInfo;
// Don't remove this! It's required for the ADD_NATIVE_TYPE_SIZE macro.
_memory.attr("TYPE_SIZES") = dict();
// Native types
ADD_NATIVE_TYPE_SIZE("BOOL", bool)
ADD_NATIVE_TYPE_SIZE("CHAR", char)
ADD_NATIVE_TYPE_SIZE("UCHAR", unsigned char)
ADD_NATIVE_TYPE_SIZE("SHORT", short)
ADD_NATIVE_TYPE_SIZE("USHORT", unsigned short)
ADD_NATIVE_TYPE_SIZE("INT", int)
ADD_NATIVE_TYPE_SIZE("UINT", unsigned int)
ADD_NATIVE_TYPE_SIZE("LONG", long)
ADD_NATIVE_TYPE_SIZE("ULONG", unsigned long)
ADD_NATIVE_TYPE_SIZE("LONG_LONG", long long)
ADD_NATIVE_TYPE_SIZE("ULONG_LONG", unsigned long long)
ADD_NATIVE_TYPE_SIZE("FLOAT", float)
ADD_NATIVE_TYPE_SIZE("DOUBLE", double)
ADD_NATIVE_TYPE_SIZE("POINTER", void*)
ADD_NATIVE_TYPE_SIZE("STRING", char*)
_memory.attr("NULL") = object(CPointer());
}