-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_serialization.c
More file actions
64 lines (56 loc) · 1.81 KB
/
test_serialization.c
File metadata and controls
64 lines (56 loc) · 1.81 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
#include <Windows.h>
#include <stdio.h>
#include "generic_rpc.h"
#include "KiwiInterface.h"
void printHex(PVOID data, DWORD size);
void printStruct(PMYSTRUCT_TYPE myStruct);
int wmain(int argc, wchar_t * argv[])
{
MYSTRUCT_TYPE myStruct = {42, L"Un test de Kiwi", 7, NULL}, myStructDecoded = {0};
PVOID encodedData;
DWORD encodedSize;
if(myStruct.elements = (PDWORD) LocalAlloc(LPTR, myStruct.cbElements * sizeof(DWORD)))
{
myStruct.elements[0] = 123;
myStruct.elements[myStruct.cbElements - 1] = 456;
wprintf(L"myStruct:\n");
printStruct(&myStruct);
wprintf(L"myStructDecoded:\n");
printStruct(&myStructDecoded);
if(generic_rpc_Encode(&myStruct, &encodedData, &encodedSize, (PGENERIC_RPC_ENCODE) MYSTRUCT_TYPE_Encode, (PGENERIC_RPC_ALIGNSIZE) MYSTRUCT_TYPE_AlignSize))
{
wprintf(L"NDR Encoded data (%u):\n", encodedSize);
printHex(encodedData, encodedSize);
if(generic_rpc_Decode(encodedData, encodedSize, &myStructDecoded, (PGENERIC_RPC_DECODE) MYSTRUCT_TYPE_Decode))
{
wprintf(L"myStructDecoded:\n");
printStruct(&myStructDecoded);
generic_rpc_Free(&myStructDecoded, (PGENERIC_RPC_FREE) MYSTRUCT_TYPE_Free);
}
LocalFree(encodedData);
}
LocalFree(myStruct.elements);
}
return ERROR_SUCCESS;
}
void printHex(PVOID data, DWORD size)
{
DWORD i;
for(i = 0; i < size; i++)
{
wprintf(L"%02x ", ((PBYTE) data)[i]);
if(!((i + 1) % 16))
wprintf(L"\n");
}
wprintf(L"\n");
}
void printStruct(PMYSTRUCT_TYPE myStruct)
{
DWORD i;
wprintf(L"\t.simpleValue= %u\n", myStruct->simpleValue);
wprintf(L"\t.Name = %s\n", myStruct->Name);
wprintf(L"\t.cbElements = %u\n", myStruct->cbElements);
for(i = 0; i < myStruct->cbElements; i++)
wprintf(L"\t.elements[%u] = %u\n", i, myStruct->elements[i]);
wprintf(L"\n");
}