// cUsingVmp.cpp : Defines the entry point for the console application.
//

#include <tchar.h>
#include <string.h>
#include <stdio.h>
#include "./../../inc/virbox.h"


char g_test_string[16] = { "test_decrypt" };

int add(int x, int y)
{
	int ret = 0;

	printf("enter add\n");
	VBVirtualizeBegin("add_vvb");
	ret = x + y;
	printf("x+y=%d\n", ret);
	VBProtectEnd();

	return ret;
}

int sub(int x, int y)
{
	int ret;

	VBMutateBegin("sub_vmb");
	printf("enter sub\n");
	ret = x - y;
	printf("%d\n", ret);
	VBProtectEnd();

	return ret;
}


int test_string1()
{
	const char *g_test_initial_string = "test_decrypt";
	char buf[260] = { 0 };

	printf("test string1\n");

	printf("解密前：");
	printf("%s\n", g_test_string);

	// 解密
	VBProtectDecrypt(buf, g_test_string, 16);

	// 解密后
	printf("解密后：");
	printf("%s\n", buf);
	printf("最初的：%s\n", g_test_initial_string);
	if (strncmp(g_test_initial_string, buf, 12) != 0)
	{
		return 1;
	}
	printf("\n============================\n");
	return 0;
}

int main(int argc, char* argv[])
{
	int ret = 0;
	char buffer[512] = { 0 };
	char *szMsg = "sdk test demo\n";
	printf(szMsg);

	VBProtectBegin("main_vpb");


	if (60 != add(20, 40))
		return 1;

	if (10 != sub(50, 40))
		return 1;

	ret = test_string1();
	if (0 != ret)
		return ret;

	VBProtectEnd();

	return 0;
}

