Initial commit

This commit is contained in:
Alukym
2023-05-12 20:16:10 +08:00
commit a8433f06ee
1167 changed files with 1036549 additions and 0 deletions

60
unit-tests/arm_tests.cpp Normal file
View File

@ -0,0 +1,60 @@
#include "precompiled.h"
#include "macfile.h"
#include "arm.h"
#include "testfile.h"
TEST(ArmFunctionTest, Arm_Test)
{
return;
MacFile pf(NULL);
ArmFunction command_list(NULL, NULL);
ASSERT_TRUE(pf.Open("test-binaries/ios-app-test2-arm", foRead) == osSuccess);
ASSERT_TRUE(pf.count() == 1);
IArchitecture &arch = *pf.item(0);
ASSERT_TRUE(command_list.ReadFromFile(arch, 0x20B6) == 115);
ASSERT_TRUE(command_list.ReadFromFile(arch, 0x345E) == 41);
ASSERT_TRUE(command_list.ReadFromFile(arch, 0x1DCD8) == 2);
}
TEST(ArmFunctionTest, ARM)
{
return;
uint32_t buf[] = {
0xe0006fce, // AND R6, R0, LR,ASR#31
0xe0007064, // AND R7, R0, R4,RRX
0xe0000000, // AND R0, R0, R0
0xe0000001, // AND R0, R0, R1
0xe0000002, // AND R0, R0, R2
0xe0000003, // AND R0, R0, R3
0xe0000004, // AND R0, R0, R4
0xe0000005, // AND R0, R0, R5
0xe0000006, // AND R0, R0, R6
0xe0000007, // AND R0, R0, R7
0xe0000008, // AND R0, R0, R8
0xe0000009, // AND R0, R0, R9
0xe000000a, // AND R0, R0, R10
0xe000000b, // AND R0, R0, R11
0xe000000c, // AND R0, R0, R12
0xe000000d, // AND R0, R0, SP
0xe000000e, // AND R0, R0, LR
0xe000000f, // AND R0, R0, PC
0xe0000010, // AND R0, R0, R0,LSL R0
0xe0000011, // AND R0, R0, R1,LSL R0
0xe0000012, // AND R0, R0, R2,LSL R0
0xe0000013, // AND R0, R0, R3,LSL R0
0xffffffff // INVALID
};
//ArmFunction command_list(NULL, NULL);
TestFile test_file(ptArm, osDWord);
IArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
TestSegment *segment = segment_list->Add(0x00400000, 0x10000, ".text", mtReadable | mtExecutable);
segment->set_physical_size(sizeof(buf));
test_file.OpenFromMemory(buf, sizeof(buf));
//command_list.ReadFromFile(arch, segment_list->item(0)->address());
}

87
unit-tests/core_tests.cc Normal file
View File

@ -0,0 +1,87 @@
#include "../runtime/common.h"
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/core.h"
TEST(CoreTest, OpenAndCompile)
{
Core vmp;
ASSERT_TRUE(vmp.Open("test-binaries/win32-app-test1-i386.vmp"));
EXPECT_EQ(vmp.vm_section_name().compare(".test"), 0);
IFile &file = *vmp.input_file();
ASSERT_EQ(file.count(), 1ul);
IArchitecture &arch = *file.item(0);
// Check folders.
Folder &folder = *file.folder_list();
ASSERT_EQ(folder.count(), 2ul);
EXPECT_EQ(folder.item(0)->name().compare("Folder1") , 0);
EXPECT_EQ(folder.item(1)->name().compare("Folder2") , 0);
ASSERT_EQ(folder.item(1)->count(), 1ul);
EXPECT_EQ(folder.item(1)->item(0)->name().compare("Strings"), 0);
EXPECT_EQ(file.folder_list()->GetFolderList().size(), 3ul);
// Check functions.
ASSERT_EQ(arch.function_list()->count(), 4ul);
EXPECT_EQ(arch.function_list()->item(0)->count(), 6ul);
EXPECT_EQ(arch.function_list()->item(1)->folder()->name().compare("Strings"), 0);
EXPECT_EQ(arch.function_list()->item(2)->folder()->name().compare("Strings"), 0);
// Check external commands.
ExtCommandList *ext_command_list = arch.function_list()->item(0)->ext_command_list();
ASSERT_EQ(ext_command_list->count(), 2ul);
EXPECT_EQ(ext_command_list->item(0)->address(), 0x00401007ull);
EXPECT_EQ(ext_command_list->item(1)->address(), 0x00401011ull);
ASSERT_TRUE(vmp.Compile());
}
TEST(CoreTest, CryptRSA)
{
RSA cryptor;
size_t key_lengths[] = { 1024ul, 1536ul, 2048ul, 2560ul, 3072ul, 3584ul, 4096ul };
//for(size_t i = 0; i < _countof(key_lengths); i++)
size_t i = rand() % _countof(key_lengths);
{
size_t key_length = key_lengths[i];
ASSERT_TRUE(cryptor.CreateKeyPair(key_length)) << key_length;
const uint64_t c = 0xDEAD00F00D00AA55ull;
Data data;
data.PushQWord(c);
ASSERT_TRUE(cryptor.Encrypt(data)) << key_length;
ASSERT_NE(memcmp(data.data(), &c, sizeof(c)), 0) << key_length;
ASSERT_TRUE(cryptor.Decrypt(data)) << key_length;
ASSERT_EQ(memcmp(data.data(), &c, sizeof(c)), 0) << key_length;
}
}
TEST(CoreTest, IsUniqueWatermark)
{
WatermarkManager wm(NULL);
wm.Add("name", "AbCdE?");
ASSERT_FALSE(wm.IsUniqueWatermark("AB"));
ASSERT_FALSE(wm.IsUniqueWatermark("b?"));
ASSERT_FALSE(wm.IsUniqueWatermark("DEF"));
ASSERT_FALSE(wm.IsUniqueWatermark("AbCdE?"));
ASSERT_FALSE(wm.IsUniqueWatermark("?123?AbCdE8EF"));
ASSERT_TRUE(wm.IsUniqueWatermark("?B12"));
ASSERT_TRUE(wm.IsUniqueWatermark("34587?B123"));
}
#ifndef VMP_GNU
TEST(CoreTest, UTF8Validator)
{
ASSERT_TRUE(os::ValidateUTF8(std::string()));
ASSERT_TRUE(os::ValidateUTF8(os::ToUTF8(os::unicode_string(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"))));
ASSERT_FALSE(os::ValidateUTF8(std::string("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1251")));
}
TEST(CoreTest, FromACP)
{
ASSERT_TRUE(os::FromACP(std::string("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1251")) == os::unicode_string(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1251"));
}
#endif

345
unit-tests/elffile_tests.cc Normal file
View File

@ -0,0 +1,345 @@
#include "../runtime/common.h"
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/core.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/elffile.h"
#include "../core/lin_runtime32.so.inc"
#include "../core/lin_runtime64.so.inc"
#ifdef ELFFileTest_TestOpen1
TEST(ELFFileTest, TestOpen1)
{
ELFFile mf(NULL);
ISectionList *segl;
ELFSectionList *secl;
//ELFSymbolList *syml;
IImportList *impl;
ASSERT_EQ(osSuccess, mf.Open("test-binaries/Project1-linux-x64", true));
// Check architectures.
EXPECT_EQ(1ul, mf.count());
ELFArchitecture &arch = *mf.item(0);
EXPECT_EQ("amd64", arch.name());
EXPECT_EQ("ELF", arch.owner()->format_name());
EXPECT_EQ(0x4007F0ull, arch.entry_point());
// Check segments were read.
segl = arch.segment_list();
struct seg { const char *name; uint32_t mt; } segs[] = {
{".interp", mtReadable} // IDA <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
,{".init", mtReadable | mtExecutable}
,{".plt", mtReadable | mtExecutable}
,{".text", mtReadable | mtExecutable}
,{".fini", mtReadable | mtExecutable}
,{".rodata", mtReadable}
,{".eh_frame_hdr", mtReadable}
,{".eh_frame", mtReadable}
//,{".init_array", mtReadable | mtWritable} - IDA
//,{".fini_array", mtReadable | mtWritable} - IDA
,{".jcr", mtReadable | mtWritable}
,{".got", mtReadable | mtWritable}
,{".got.plt", mtReadable | mtWritable}
,{".data", mtReadable | mtWritable}
,{".bss", mtReadable | mtWritable}
//,{"extern"} - IDA
};
ASSERT_EQ(_countof(segs), segl->count());
for(size_t i = 0; i < _countof(segs); i++)
{
EXPECT_EQ(segs[i].name, segl->item(i)->name()) << "i=" << i;
EXPECT_EQ(segs[i].mt, segl->item(i)->memory_type()) << "i=" << i;
}
// Check sections were read.
secl = arch.section_list();
ASSERT_EQ(0ul, secl->count());
//EXPECT_EQ("sn", secl->item(0)->name());
// Check symbols.
/*syml = arch.symbol_list();
ASSERT_EQ(syml->count(), 129ul);
EXPECT_EQ(syml->item(0)->name()
.compare("/Users/macuser/work2/ios-test2/ios-test2/"), 0);*/
// Check imports.
impl = arch.import_list();
ASSERT_EQ(3ul, impl->count());
//Why [0].is_sdk == false?
EXPECT_EQ("libVMProtectSDK64.so", impl->item(0)->name());
EXPECT_EQ(0ul, impl->item(0)->count());
EXPECT_EQ("libc.so.6", impl->item(1)->name());
EXPECT_EQ(0ul, impl->item(1)->count());
EXPECT_EQ("", impl->item(2)->name());
const char *fnames[] = {
"__gmon_start__"
,"_Jv_RegisterClasses"
,"puts"
,"__libc_start_main"
,"VMProtectDecryptStringA"
,"fgets"
,"_ITM_deregisterTMCloneTable"
,"_ITM_registerTMCloneTable"
,"atoi"
,"__stack_chk_fail"
,"VMProtectBegin"
,"VMProtectEnd"
,"__gmon_start__"
,"_Jv_RegisterClasses"
,"puts@@GLIBC_2.2.5"
,"__libc_start_main@@GLIBC_2.2.5"
,"VMProtectDecryptStringA"
,"fgets@@GLIBC_2.2.5"
,"_ITM_deregisterTMCloneTable"
,"_ITM_registerTMCloneTable"
,"atoi@@GLIBC_2.2.5"
,"__stack_chk_fail@@GLIBC_2.4"
,"VMProtectBegin"
,"VMProtectEnd"};
EXPECT_EQ(_countof(fnames), impl->item(2)->count());
for(size_t i = 0; i < _countof(fnames); i++)
{
EXPECT_EQ(fnames[i], impl->item(2)->item(i)->name()) << "i=" << i;
}
mf.Close();
EXPECT_EQ(mf.count(), 0ul);
}
#endif
TEST(ELFFileTest, TestOpen2)
{
ELFFile mf(NULL);
ISectionList *segl;
ELFSectionList *secl;
//ELFSymbolList *syml;
IImportList *impl;
IExportList *expl;
ASSERT_EQ(mf.Open("test-binaries/Project1-linux-x86", true), osSuccess);
// Check architectures.
ASSERT_EQ(mf.count(), 1ul);
ELFArchitecture &arch = *mf.item(0);
EXPECT_EQ(arch.name().compare("i386"), 0);
EXPECT_EQ(arch.owner()->format_name().compare("ELF"), 0);
EXPECT_EQ(arch.entry_point(), 0x80485E0ULL);
// Check segments were read.
segl = arch.segment_list();
/*ASSERT_EQ(segl->count(), 4ul);
EXPECT_EQ(segl->item(0)->name().compare("__PAGEZERO"), 0);
EXPECT_EQ(segl->item(0)->memory_type(), mtNone);
EXPECT_EQ(segl->item(1)->name().compare("__TEXT"), 0);
EXPECT_EQ((int)segl->item(1)->memory_type(), (mtReadable | mtExecutable));
EXPECT_EQ(segl->item(2)->name().compare("__DATA"), 0);
EXPECT_EQ((int)segl->item(2)->memory_type(), (mtReadable | mtWritable));
EXPECT_EQ(segl->item(3)->name().compare("__LINKEDIT"), 0);
EXPECT_EQ(segl->item(3)->memory_type(), mtReadable);*/
// Check sections were read.
secl = arch.section_list();
/*ASSERT_EQ(secl->count(), 10ul);
EXPECT_EQ(secl->item(0)->name().compare("__text"), 0);
EXPECT_EQ(secl->item(1)->name().compare("__stubs"), 0);
EXPECT_EQ(secl->item(2)->name().compare("__stub_helper"), 0);
EXPECT_EQ(secl->item(3)->name().compare("__cstring"), 0);
EXPECT_EQ(secl->item(4)->name().compare("__unwind_info"), 0);
EXPECT_EQ(secl->item(5)->name().compare("__eh_frame"), 0);
EXPECT_EQ(secl->item(6)->name().compare("__dyld"), 0);
EXPECT_EQ(secl->item(7)->name().compare("__got"), 0);
EXPECT_EQ(secl->item(8)->name().compare("__la_symbol_ptr"), 0);
EXPECT_EQ(secl->item(9)->name().compare("__data"), 0);
// Check symbols.
syml = arch.symbol_list();
ASSERT_EQ(syml->count(), 57ul);
EXPECT_EQ(syml->item(2)->name()
.compare("/Users/mac/Library/Developer/Xcode/DerivedData/hello-flxnqzrlabvwqrdcesuuqdaabhfa/Build/Intermediates/hello.build/Release/hello.build/Objects-normal/x86_64/main.o"), 0);*/
// Check imports.
impl = arch.import_list();
/*ASSERT_EQ(impl->count(), 3ul);
EXPECT_EQ(impl->item(0)->name().compare("/usr/lib/libstdc++.6.dylib"), 0);
EXPECT_EQ(impl->item(1)->name().compare("/usr/lib/libgcc_s.1.dylib"), 0);
EXPECT_EQ(impl->item(2)->name().compare("/usr/lib/libSystem.B.dylib"), 0);*/
// Check exports.
expl = arch.export_list();
/*ASSERT_EQ(expl->count(), 5ul);
EXPECT_EQ(expl->item(0)->name().compare("_NXArgc"), 0);
EXPECT_EQ(expl->item(1)->name().compare("_NXArgv"), 0);
EXPECT_EQ(expl->item(2)->name().compare("___progname"), 0);
EXPECT_EQ(expl->item(3)->name().compare("_environ"), 0);
EXPECT_EQ(expl->item(4)->name().compare("start"), 0);
EXPECT_EQ(expl->item(4)->address(), 0x100000c04ULL);*/
mf.Close();
EXPECT_EQ(mf.count(), 0ul);
}
/*TEST(ELFFileTest, OpenSharedLib)
{
ELFFile mf(NULL);
EXPECT_EQ(mf.Open("test-binaries/macos-dll-test1-i386", foRead), osSuccess);
// Check architectures.
ASSERT_EQ(mf.count(), 1ul);
ELFArchitecture &arch = *mf.item(0);
// Check exports.
IExportList *exp = arch.export_list();
EXPECT_EQ(exp->name().compare("@executable_path/hello_lib_cpp.dylib"), 0);
ASSERT_EQ(exp->count(), 1ul);
EXPECT_EQ(exp->item(0)->name().compare("__ZN13hello_lib_cpp10HelloWorldEPKc"), 0);
EXPECT_EQ(exp->item(0)->forwarded_name().compare(""), 0);
EXPECT_EQ(exp->item(0)->address(), 0x00000deaull);
// Check fixups.
IFixupList *fixup_list = arch.fixup_list();
ASSERT_EQ(fixup_list->count(), 23ul);
EXPECT_EQ(fixup_list->item(0)->address(), 0x00000e84ull);
EXPECT_EQ(fixup_list->item(0)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(22)->address(), 0x00001034ull);
EXPECT_EQ(fixup_list->item(22)->type(), ftHighLow);
mf.Close();
EXPECT_EQ(mf.count(), 0ul);
}*/
TEST(ELFFileTest, Clone)
{
ELFFile mf(NULL);
ASSERT_EQ(mf.Open("test-binaries/Project1-linux-x64", foRead), osSuccess);
ELFFile *f = mf.Clone(mf.file_name().c_str());
ASSERT_EQ(mf.count(), f->count());
ELFArchitecture &src = *mf.item(0);
ELFArchitecture &dst = *f->item(0);
EXPECT_EQ(src.owner()->format_name().compare(dst.owner()->format_name()), 0);
EXPECT_EQ(src.name().compare(dst.name()), 0);
EXPECT_EQ(src.cpu_address_size(), dst.cpu_address_size());
EXPECT_EQ(src.entry_point(), dst.entry_point());
EXPECT_EQ(src.command_list()->count(), dst.command_list()->count());
EXPECT_EQ(src.command_list()->count(), dst.command_list()->count());
EXPECT_EQ(src.segment_list()->count(), dst.segment_list()->count());
EXPECT_EQ(src.section_list()->count(), dst.section_list()->count());
//EXPECT_EQ(src.symbol_list()->count(), dst.symbol_list()->count());
EXPECT_EQ(src.import_list()->count(), dst.import_list()->count());
EXPECT_EQ(src.fixup_list()->count(), dst.fixup_list()->count());
EXPECT_EQ(src.export_list()->count(), dst.export_list()->count());
//std::string symbol_name = src.indirect_symbol_list()->item(1)->symbol()->name();
//av std::string segment_name = src.section_list()->item(0)->parent()->name();
mf.Close();
//EXPECT_EQ(dst.indirect_symbol_list()->item(1)->symbol()->name().compare(symbol_name), 0);
//av EXPECT_EQ(dst.section_list()->item(0)->parent()->name().compare(segment_name), 0);
delete f;
}
TEST(ELFFileTest, Runtime_x32)
{
ELFFile file(NULL);
ASSERT_TRUE(file.OpenResource(lin_runtime32_so_file, sizeof(lin_runtime32_so_file), true));
ASSERT_EQ(file.count(), 1ul);
ELFArchitecture *arch = file.item(0);
Buffer buffer(&lin_runtime32_so_code[0]);
arch->ReadFromBuffer(buffer);
EXPECT_EQ(arch->export_list()->count(), 21ul);
EXPECT_GT(arch->function_list()->count(), 0ul);
}
TEST(ELFFileTest, Runtime_x64)
{
ELFFile file(NULL);
ASSERT_TRUE(file.OpenResource(lin_runtime64_so_file, sizeof(lin_runtime64_so_file), true));
ASSERT_EQ(file.count(), 1ul);
ELFArchitecture *arch = file.item(0);
Buffer buffer(&lin_runtime64_so_code[0]);
arch->ReadFromBuffer(buffer);
EXPECT_EQ(arch->export_list()->count(), 21ul);
EXPECT_GT(arch->function_list()->count(), 0ul);
}
#ifdef __unix__
#ifndef DEMO
static bool execFile(const std::string &fileName, DWORD &exitCode)
{
exitCode = 0xFFFFFFF;
int ret = system(fileName.c_str());
if (ret != -1)
{
exitCode = DWORD(ret);
return true;
}
return false;
}
/*
// exc.cpp:
// clang++ -std=c++11 -target x86_64-linux-gnu -o exc-linux-x64 exc.cpp -L../bin -lVMProtectSDK64 -I ../sdk
// clang++ -std=c++11 -target i386-linux-gnu -o exc-linux-x86 exc.cpp -L../bin -lVMProtectSDK32 -I ../sdk
#include <stdio.h>
#include "VMProtectSDK.h"
__declspec(noinline) void try1()
{
printf("try 1\n");
try {
throw 1;
}
catch (int) {
printf("catch 1\n");
throw;
}
printf("end 1\n\n");
}
int main()
{
if (VMProtectIsDebuggerPresent(true))
printf("debugger detected\n");
if (VMProtectIsVirtualMachinePresent())
printf("virtual machine detected\n");
printf("try main\n");
try {
try1();
}
catch (...) {
printf("catch main\n");
}
printf("end main\n");
return 0;
}
*/
TEST(ELFFileTest, EXC_x32)
{
ELFFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/exc-linux-x86", foRead), osSuccess);
ELFArchitecture *arch = pf.item(0);
arch->function_list()->AddByAddress(0x08048940, ctVirtualization, 0, true, NULL); // main
arch->function_list()->AddByAddress(0x08048890, ctUltra, 0, true, NULL); // try1
std::string file_name = pf.file_name() + "_vmp";
ELFFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
DWORD ret;
ASSERT_TRUE(execFile(file_name, ret));
ASSERT_EQ(ret, 0u);
}
TEST(ELFFileTest, EXC_x64)
{
ELFFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/exc-linux-x64", foRead), osSuccess);
ELFArchitecture *arch = pf.item(0);
arch->function_list()->AddByAddress(0x0000000000400B80, ctVirtualization, 0, true, NULL); // main
arch->function_list()->AddByAddress(0x0000000000400AE0, ctUltra, 0, true, NULL); // try1
std::string file_name = pf.file_name() + "_vmp";
ELFFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
DWORD ret;
ASSERT_TRUE(execFile(file_name, ret));
ASSERT_EQ(ret, 0u);
}
#endif // DEMO
#endif // __unix__

405
unit-tests/files_tests.cc Normal file
View File

@ -0,0 +1,405 @@
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/intel.h"
#include "../core/pefile.h"
#include "testfileintel.h"
TEST(MapFunctionListTest, ReadFromMapFile_Gcc_Test)
{
TestFile test_file(osDWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
segment_list->Add(0x00401000, 0x000083DC, ".text", mtReadable | mtExecutable);
segment_list->Add(0x0040A000, 0x00004A6C, ".data", mtReadable | mtWritable);
segment_list->Add(0x0040F000, 0x00002968, ".rdata", mtReadable);
segment_list->Add(0x00412000, 0x00000068, ".bss", mtReadable | mtWritable);
segment_list->Add(0x00413000, 0x00001AF8, ".idata", mtReadable | mtWritable);
segment_list->Add(0x00415000, 0x00000660, "/4", mtDiscardable);
segment_list->Add(0x00416000, 0x00001517, "/19", mtDiscardable);
segment_list->Add(0x00418000, 0x0007D3B4, "/35", mtDiscardable);
segment_list->Add(0x00496000, 0x000055C2, "/47", mtDiscardable);
segment_list->Add(0x0049C000, 0x0000518E, "/61", mtDiscardable);
segment_list->Add(0x004A2000, 0x000017CC, "/73", mtDiscardable);
segment_list->Add(0x004A4000, 0x00003FEB, "/86", mtDiscardable);
segment_list->Add(0x004A8000, 0x00007534, "/97", mtDiscardable);
segment_list->Add(0x004B0000, 0x00001C78, "/108", mtDiscardable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/gcc-linux-map-1"));
ASSERT_EQ(fl->count(), 493ul);
EXPECT_EQ(fl->item(0)->name().compare("WinMainCRTStartup"), 0);
EXPECT_EQ(fl->item(100)->name().compare("__chkstk"), 0);
EXPECT_EQ(fl->item(200)->name().compare("__gnu_cxx::__concurrence_lock_error::~__concurrence_lock_error()"), 0);
}
TEST(MapFunctionListTest, ReadFromMapFile_Gcc_Test2)
{
TestFile test_file(osQWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
segment_list->Add(0x0000000008048134, 0x13, ".interp", mtReadable);
segment_list->Add(0x0000000008048148, 0x20, ".note.ABI-tag", mtReadable);
segment_list->Add(0x0000000008048168, 0x20, ".gnu.hash", mtReadable);
segment_list->Add(0x0000000008048188, 0x50, ".dynsym", mtReadable);
segment_list->Add(0x00000000080481d8, 0x4a, ".dynstr", mtReadable);
segment_list->Add(0x0000000008048222, 0xa, ".gnu.version", mtReadable);
segment_list->Add(0x000000000804822c, 0x20, ".gnu.version_r", mtReadable);
segment_list->Add(0x000000000804824c, 0x8, ".rel.dyn", mtReadable);
segment_list->Add(0x0000000008048254, 0x18, ".rel.plt", mtReadable);
segment_list->Add(0x000000000804826c, 0x17, ".init", mtReadable);
segment_list->Add(0x0000000008048284, 0x40, ".plt", mtReadable);
segment_list->Add(0x00000000080482d0, 0x1a8, ".text", mtReadable | mtExecutable);
segment_list->Add(0x0000000008048478, 0x1c, ".fini", mtReadable);
segment_list->Add(0x0000000008048494, 0x12, ".rodata", mtReadable);
segment_list->Add(0x00000000080484a8, 0x1c, ".eh_frame_hdr", mtReadable);
segment_list->Add(0x00000000080484c4, 0x58, ".eh_frame", mtReadable);
segment_list->Add(0x000000000804951c, 0x8, ".ctors", mtReadable);
segment_list->Add(0x0000000008049524, 0x8, ".dtors", mtReadable);
segment_list->Add(0x000000000804952c, 0x4, ".jcr", mtReadable);
segment_list->Add(0x0000000008049530, 0xc8, ".dynamic", mtReadable);
segment_list->Add(0x00000000080495f8, 0x4, ".got", mtReadable);
segment_list->Add(0x00000000080495fc, 0x18, ".got.plt", mtReadable);
segment_list->Add(0x0000000008049614, 0x4, ".data", mtReadable);
segment_list->Add(0x0000000008049618, 0x8, ".bss", mtReadable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/gcc-linux-map-2"));
ASSERT_EQ(fl->count(), 17ul);
EXPECT_EQ(fl->item(0)->name().compare("_init"), 0);
EXPECT_EQ(fl->item(10)->name().compare("_IO_stdin_used"), 0);
EXPECT_EQ(fl->item(16)->name().compare("__data_start"), 0);
}
TEST(MapFunctionListTest, ReadFromMapFile_GccApple_Test)
{
TestFile test_file(osDWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
segment_list->Add(0x00000000, 0x00001000, "__PAGEZERO", mtNone);
segment_list->Add(0x00001000, 0x00001000, "__TEXT", mtReadable | mtExecutable);
segment_list->Add(0x00002000, 0x00001000, "__DATA", mtReadable | mtWritable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/gcc-apple-map"));
ASSERT_EQ(fl->count(), 53ul);
EXPECT_EQ(fl->item(0)->name().compare("start"), 0);
EXPECT_EQ(fl->item(20)->name().compare("_exit"), 0);
EXPECT_EQ(fl->item(40)->name().compare("non-lazy-pointer-to: ___gxx_personality_v0"), 0);
}
TEST(MapFunctionListTest, ReadFromMapFile_Deplhi_Test)
{
TestFile test_file(osDWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
segment_list->Add(0x00401000, 0x000B9510, ".text", mtReadable | mtExecutable);
segment_list->Add(0x004BB000, 0x00000C90, ".itext", mtReadable | mtExecutable);
segment_list->Add(0x004BC000, 0x000025B0, ".data", mtReadable | mtWritable);
segment_list->Add(0x004BF000, 0x000052E8, ".bss", mtReadable | mtWritable);
segment_list->Add(0x004C5000, 0x00003284, ".idata", mtReadable | mtWritable);
segment_list->Add(0x004C9000, 0x00000326, ".didata", mtReadable | mtWritable);
segment_list->Add(0x004CA000, 0x0000003C, ".tls", mtReadable | mtWritable);
segment_list->Add(0x004CB000, 0x00000018, ".rdata", mtReadable);
segment_list->Add(0x004CC000, 0x00010AB0, ".reloc", mtReadable | mtDiscardable);
segment_list->Add(0x004DD000, 0x0000D000, ".rsrc", mtReadable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/delphi-map"));
ASSERT_EQ(fl->count(), 5702ul);
EXPECT_EQ(fl->item(0)->name().compare("System..TObject"), 0);
EXPECT_EQ(fl->item(1000)->name().compare("SysUtils.DecodeDate"), 0);
EXPECT_EQ(fl->item(2000)->name().compare("Classes.TWriter.DefineBinaryProperty"), 0);
}
TEST(MapFunctionListTest, ReadFromMapFile_Msvc_Test)
{
TestFile test_file(osDWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
segment_list->Add(0x00401000, 0x00023FC9, ".textbss", mtReadable | mtWritable | mtExecutable);
segment_list->Add(0x00425000, 0x0004BD1F, ".text", mtReadable | mtExecutable);
segment_list->Add(0x00471000, 0x0000EF7A, ".rdata", mtReadable);
segment_list->Add(0x00480000, 0x00003898, ".data", mtReadable | mtExecutable);
segment_list->Add(0x00484000, 0x00000D35, ".idata", mtReadable | mtExecutable);
segment_list->Add(0x00485000, 0x000005C0, ".rsrc", mtReadable);
segment_list->Add(0x00486000, 0x000035D3, ".reloc", mtReadable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/msvc-map"));
ASSERT_EQ(fl->count(), 2055ul);
EXPECT_EQ(fl->item(0)->name().compare("__enc$textbss$begin"), 0);
EXPECT_EQ(fl->item(1000)->name().compare("`string'"), 0);
EXPECT_EQ(fl->item(2000)->name().compare("__imp__TlsGetValue@4"), 0);
// Check static symbol
ASSERT_TRUE(fl->GetFunctionByName("char * UnDecorator::outputString") != NULL);
}
TEST(MapFunctionListTest, ReadFromMapFile_Msvc_Test2)
{
TestFile test_file(osQWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
segment_list->Add(0x00401000, 0x00042578, ".text", mtReadable | mtExecutable);
segment_list->Add(0x00444000, 0x0000C4F6, ".rdata", mtReadable);
segment_list->Add(0x00451000, 0x00000B08, ".data", mtReadable | mtWritable);
segment_list->Add(0x00452000, 0x00001788, ".pdata", mtReadable);
segment_list->Add(0x00454000, 0x00002003, ".idata", mtReadable | mtWritable);
segment_list->Add(0x00457000, 0x00000C09, ".rsrc", mtReadable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/msvc-x64-map-2"));
ASSERT_EQ(fl->count(), 732ul);
EXPECT_EQ(fl->item(0)->name().compare("test_header(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)"), 0);
EXPECT_EQ(fl->item(300)->name().compare("isxdigit"), 0);
EXPECT_EQ(fl->item(600)->name().compare("__imp_UnhandledExceptionFilter"), 0);
}
TEST(MapFunctionListTest, Map_Test)
{
TestFile test_file(osQWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = reinterpret_cast<TestSegmentList *>(arch.segment_list());
MapFunctionList *fl = arch.map_function_list();
MapFunction *mf = NULL;
segment_list->Add(0x00401000, 0x00042578, ".text", mtReadable | mtExecutable);
segment_list->Add(0x00444000, 0x0000C4F6, ".rdata", mtReadable);
segment_list->Add(0x00451000, 0x00000B08, ".data", mtReadable | mtWritable);
segment_list->Add(0x00452000, 0x00001788, ".pdata", mtReadable);
segment_list->Add(0x00454000, 0x00002003, ".idata", mtReadable | mtWritable);
segment_list->Add(0x00457000, 0x00000C09, ".rsrc", mtReadable);
ASSERT_NO_THROW(arch.ReadTestMapFile("test-binaries/msvc-x64-map-2"));
ASSERT_NO_THROW(mf = fl->GetFunctionByName("main"));
ASSERT_TRUE(mf != NULL);
EXPECT_EQ(mf->name().compare("main"), 0);
EXPECT_EQ(mf->address(), 0x402ef0ull);
ASSERT_NO_THROW(mf = fl->GetFunctionByAddress(0x40b460));
ASSERT_TRUE(mf != NULL);
EXPECT_EQ(mf->name().compare("pcre_exec"), 0);
EXPECT_EQ(mf->address(), 0x40b460ull);
}
TEST(MemoryManager, Alloc)
{
MemoryManager manager(NULL);
manager.Add(0x1000, 0x1000, mtReadable, NULL);
manager.Add(0x2000, 0x300, mtReadable | mtExecutable, NULL);
manager.Add(0x3000, 0x100, mtReadable | mtWritable, NULL);
EXPECT_EQ(manager.Alloc(0x10, mtReadable | mtExecutable), 0x2000ull);
EXPECT_EQ(manager.Alloc(0x10, mtReadable | mtExecutable), 0x2010ull);
EXPECT_EQ(manager.Alloc(0x10, mtReadable | mtExecutable, 0, 0x200), 0x2200ull);
EXPECT_EQ(manager.Alloc(0x20, mtReadable | mtWritable), 0x3000ull);
EXPECT_EQ(manager.Alloc(0x20, mtReadable | mtWritable), 0x3020ull);
EXPECT_EQ(manager.Alloc(0x200, mtNone, 0x1800), 0x1800ull);
EXPECT_EQ(manager.Alloc(0x20, mtReadable | mtExecutable, 0x1900), 0ull);
EXPECT_EQ(manager.count(), 5ul);
}
TEST(MemoryManager, Remove)
{
MemoryManager manager(NULL);
manager.Add(7, 3, mtReadable, NULL);
manager.Add(1, 5, mtReadable, NULL);
ASSERT_NO_THROW(manager.Remove(4, 4));
ASSERT_EQ(manager.count(), 2ul);
EXPECT_EQ(manager.item(0)->address(), 1ull);
EXPECT_EQ(manager.item(0)->end_address(), 4ull);
EXPECT_EQ(manager.item(1)->address(), 8ull);
EXPECT_EQ(manager.item(1)->end_address(), 10ull);
ASSERT_NO_THROW(manager.Remove(8, 2));
ASSERT_EQ(manager.count(), 1ul);
}
TEST(MemoryManager, Pack)
{
MemoryManager manager(NULL);
manager.Add(0x1000, 0x1000, mtReadable | mtExecutable, NULL);
manager.Add(0x2000, 0x100, mtReadable | mtExecutable, NULL);
manager.Add(0x2100, 0x100, mtReadable, NULL);
manager.Pack();
ASSERT_EQ(manager.count(), 2ul);
MemoryRegion *region = manager.item(0);
EXPECT_EQ(region->address(), 0x1000ull);
EXPECT_EQ(region->end_address(), 0x2100ull);
EXPECT_EQ((int)region->type(), (mtReadable | mtExecutable));
region = manager.item(1);
EXPECT_EQ(region->address(), 0x2100ull);
EXPECT_EQ(region->end_address(), 0x2200ull);
EXPECT_EQ((int)region->type(), mtReadable);
}
TEST(MemoryManager, SimpleRemove)
{
MemoryManager manager(NULL);
manager.Add(1, 4, mtReadable, NULL);
manager.Add(7, 3, mtReadable, NULL);
manager.Remove(4, 4);
ASSERT_EQ(manager.count(), 2ul);
MemoryRegion *region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 4ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 8ull);
EXPECT_EQ(region->end_address(), 10ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(30, 30);
ASSERT_EQ(manager.count(), 2ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 4ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 8ull);
EXPECT_EQ(region->end_address(), 10ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(9, 30);
ASSERT_EQ(manager.count(), 2ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 4ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 8ull);
EXPECT_EQ(region->end_address(), 9ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(3, 1);
ASSERT_EQ(manager.count(), 2ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 3ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 8ull);
EXPECT_EQ(region->end_address(), 9ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(0, 15);
ASSERT_EQ(manager.count(), 0ul);
}
TEST(MemoryManager, ExtendedRemove)
{
MemoryManager manager(NULL);
manager.Add(1, 4, mtReadable, NULL);
manager.Add(7, 3, mtReadable, NULL);
manager.Add(15, 5, mtReadable, NULL);
manager.Remove(2, 1);
ASSERT_EQ(manager.count(), 4ul);
MemoryRegion *region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 2ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 3ull);
EXPECT_EQ(region->end_address(), 5ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(2);
EXPECT_EQ(region->address(), 7ull);
EXPECT_EQ(region->end_address(), 10ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(3);
EXPECT_EQ(region->address(), 15ull);
EXPECT_EQ(region->end_address(), 20ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(8, 1);
ASSERT_EQ(manager.count(), 5ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 2ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 3ull);
EXPECT_EQ(region->end_address(), 5ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(2);
EXPECT_EQ(region->address(), 7ull);
EXPECT_EQ(region->end_address(), 8ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(3);
EXPECT_EQ(region->address(), 9ull);
EXPECT_EQ(region->end_address(), 10ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(4);
EXPECT_EQ(region->address(), 15ull);
EXPECT_EQ(region->end_address(), 20ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(16, 1);
ASSERT_EQ(manager.count(), 6ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 2ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 3ull);
EXPECT_EQ(region->end_address(), 5ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(2);
EXPECT_EQ(region->address(), 7ull);
EXPECT_EQ(region->end_address(), 8ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(3);
EXPECT_EQ(region->address(), 9ull);
EXPECT_EQ(region->end_address(), 10ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(4);
EXPECT_EQ(region->address(), 15ull);
EXPECT_EQ(region->end_address(), 16ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(5);
EXPECT_EQ(region->address(), 17ull);
EXPECT_EQ(region->end_address(), 20ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(6, 5);
ASSERT_EQ(manager.count(), 4ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 2ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 3ull);
EXPECT_EQ(region->end_address(), 5ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(2);
EXPECT_EQ(region->address(), 15ull);
EXPECT_EQ(region->end_address(), 16ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(3);
EXPECT_EQ(region->address(), 17ull);
EXPECT_EQ(region->end_address(), 20ull);
EXPECT_EQ((int)region->type(), mtReadable);
manager.Remove(15, 100);
ASSERT_EQ(manager.count(), 2ul);
region = manager.item(0);
EXPECT_EQ(region->address(), 1ull);
EXPECT_EQ(region->end_address(), 2ull);
EXPECT_EQ((int)region->type(), mtReadable);
region = manager.item(1);
EXPECT_EQ(region->address(), 3ull);
EXPECT_EQ(region->end_address(), 5ull);
EXPECT_EQ((int)region->type(), mtReadable);
}

90
unit-tests/il_tests.cc Normal file
View File

@ -0,0 +1,90 @@
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/core.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/pefile.h"
#include "../core/il.h"
#include "../core/dotnetfile.h"
#include "testfileil.h"
TEST(ILTest, DisasmSmoke)
{
uint8_t buf[] = {
/*
.method public hidebysig static bool TakesSingleByteArgument(valuetype System.Reflection.Emit.OpCode inst) cil managed
SIG: 00 01 02 11 92 88
{
// Method begins at RVA 0x94b60
// Code size 45 (0x2D)
.maxstack 2
.locals init (valuetype System.Reflection.Emit.OperandType V_0)
*/
0x2D * 4 + 2, // Tiny header
0x0F, 0x00, // IL_0000: ldarga.s inst
0x7B, 0x04, 0x00, 0x16, 0xF8, // IL_0002: ldfld valuetype System.Reflection.Emit.OperandType System.Reflection.Emit.OpCode::m_operand
0x0A, // IL_0007: stloc.0
0x06, // IL_0008: ldloc.0
0x1F, 0x0F, // IL_0009: ldc.i4.s 15
0x59, // IL_000b: sub
0x45, 0x04, 0x00, 0x00, 0x00, // IL_000c: switch (
0x02, 0x00, 0x00, 0x00, // IL_0023,
0x02, 0x00, 0x00, 0x00, // IL_0023,
0x04, 0x00, 0x00, 0x00, // IL_0025,
0x02, 0x00, 0x00, 0x00, // IL_0023)
0x2B, 0x02, // IL_0021: br.s IL_0025
0x17, // IL_0023: ldc.i4.1
0x2A, // IL_0024: ret
0x16, // IL_0025: ldc.i4.0
0xFE, 0x13, // IL_0026: volatile.?
0x2A, // IL_0027: ret
//} end of method OpCodes::TakesSingleByteArgument
};
//ILFunction *func;
//MapFunctionList *map_function_list;
//MapFunction *map_function;
//ILCommand *command;
/*
TestFile test_file(osDWord);
TestArchitecture &arch = *test_file.item(0);
TestSegmentList *segment_list = arch.segment_list();
uint64_t addr = 0x004B58EC;
TestSegment *segment = segment_list->Add(addr, 0x10000, ".text", mtReadable | mtExecutable);
segment->set_physical_size(sizeof(buf));
test_file.OpenFromMemory(buf, sizeof(buf));
arch.runtime_function_list()->AddObject(
new NETRuntimeFunction(arch.runtime_function_list(), addr, addr + (buf[0] >> 2) + 1, addr + 1, NULL, NULL));
func = reinterpret_cast<ILFunction *>(arch.function_list()->AddByAddress(addr + 1, ctVirtualization, 0, true, NULL));
ASSERT_EQ(func->count(), 13ul);
*/
/*
map_function_list = arch.map_function_list();
map_function = map_function_list->GetFunctionByName("VMProtectMarker1");
ASSERT_TRUE(map_function != NULL);
EXPECT_EQ(map_function->address(), 0x004B5906ull);
EXPECT_EQ(func->ReadFromFile(arch, map_function->address()), 45ul);
// Check CompileToNative
std::vector<uint8_t> data;
size_t i, j;
for (i = 0; i < func->count(); i++) {
command = func->item(i);
if ((command->type() == cmJmpWithFlag || command->type() == cmJmp || command->type() == cmCall) && command->dump_size() == 2)
continue;
data.clear();
for (j = 0; j < command->dump_size(); j++) {
data.push_back(command->dump(j));
}
command->CompileToNative();
EXPECT_EQ(command->dump_size(), data.size());
for (j = 0; j < command->dump_size(); j++) {
EXPECT_EQ(command->dump(j), data[j]);
}
}*/
}

4493
unit-tests/intel_tests.cc Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ipn_sqlclr.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ipn_sqlclr.Test")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2ad5664f-7b08-40b7-a57a-2bca1f70ce55")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:vscep="http://schemas.verisign.com/pkiservices/2009/07/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.verisign.com/pkiservices/2009/07/policy" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import schemaLocation="CertificateEnrollmentPolicy.xsd" namespace="http://schemas.verisign.com/pkiservices/2009/07/policy" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="requestPoliciesMessage">
<wsdl:part name="request" element="vscep:getPolicies" />
</wsdl:message>
<wsdl:message name="requestPoliciesResponse">
<wsdl:part name="response" element="vscep:getPoliciesResponse" />
</wsdl:message>
<wsdl:portType name="policy">
<wsdl:operation name="requestPolicies">
<wsdl:input wsaw:Action="http://schemas.verisign.com/pkiservices/2009/07/policy/getPolicies" message="vscep:requestPoliciesMessage" />
<wsdl:output wsaw:Action="http://schemas.verisign.com/pkiservices/2009/07/policy/getPoliciesResponse" message="vscep:requestPoliciesResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="requestPoliciesServiceSOAP" type="vscep:policy">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="requestPolicies">
<soap:operation soapAction="http://schemas.verisign.com/pkiservices/2009/07/policy/requestPolicies" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="policyService">
<wsdl:port name="requestPoliciesServiceSOAP" binding="vscep:requestPoliciesServiceSOAP">
<soap:address location="https://pki-ws.symauth.com/pki-ws/policyService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@ -0,0 +1,388 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:vscep="http://schemas.verisign.com/pkiservices/2009/07/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" elementFormDefault="qualified" targetNamespace="http://schemas.verisign.com/pkiservices/2009/07/policy" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation xml:lang="en">
XML Schema for policyService Web Services
version 2.0
</xs:documentation>
</xs:annotation>
<xs:element name="getPolicies">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="vscep:VersionType" />
<xs:element minOccurs="0" name="clientTransactionID" type="vscep:TransactionIDType" />
<xs:element minOccurs="0" name="client" type="vscep:Client" />
<xs:element name="requestFilter" nillable="true" type="vscep:RequestFilter" />
<xs:element minOccurs="0" name="signResponse" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="VersionType" final="restriction">
<xs:restriction base="xs:string">
<xs:pattern value="\d{1,3}\.\d{0,3}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TransactionIDType" final="restriction">
<xs:restriction base="xs:string">
<xs:maxLength value="40" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Client">
<xs:sequence>
<xs:element name="lastUpdatetime" nillable="true" type="xs:dateTime" />
<xs:element name="preferredLanguage" nillable="true" type="xs:language" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="RequestFilter">
<xs:sequence>
<xs:element name="policyIDs" nillable="true" type="vscep:FilterOIDCollection" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="FilterOIDCollection">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="oid" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="getPoliciesResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="clientTransactionID" type="vscep:TransactionIDType" />
<xs:element name="serverTransactionID" type="vscep:TransactionIDType" />
<xs:element name="response" type="vscep:Response" />
<xs:element name="cAs" nillable="true" type="vscep:CACollection" />
<xs:element name="oIDs" nillable="true" type="vscep:OIDCollection" />
<xs:element minOccurs="0" name="signedEnrollmentPolicy" type="xs:base64Binary" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Response">
<xs:sequence>
<xs:element name="policyID" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="policyFriendlyName" type="xs:string" />
<xs:element name="nextUpdateHours" nillable="true" type="xs:unsignedInt" />
<xs:element name="policiesNotChanged" type="xs:boolean" />
<xs:element name="policies" nillable="true" type="vscep:PolicyCollection" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CACollection">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="cA" type="vscep:CA" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CA">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="uris" type="xs:anyURI" />
<xs:element name="certificate" type="xs:base64Binary" />
<xs:element name="cAIssuerName" nillable="true" type="xs:string" />
<xs:element name="cAReferenceID" type="xs:int" />
<xs:element name="cAType" nillable="true" type="vscep:CAType" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="intermediateCACertificates" type="xs:base64Binary" />
<xs:element name="rootCACertificate" type="xs:base64Binary" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="OIDCollection">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="oID" type="vscep:OID" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="OID">
<xs:sequence>
<xs:element name="value" type="xs:string" />
<xs:element name="oIDReferenceID" type="xs:int" />
<xs:element name="group" type="xs:unsignedInt" />
<xs:element name="defaultName" nillable="true" type="xs:string" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="PolicyCollection">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="policy" type="vscep:CertificateEnrollmentPolicy" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CertificateEnrollmentPolicy">
<xs:sequence>
<xs:element name="policyOIDReference" type="xs:int" />
<xs:element name="cAs" type="vscep:CAReferenceCollection" />
<xs:element name="attributes" type="vscep:Attributes" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CAReferenceCollection">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="cAReference" type="xs:int" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Attributes">
<xs:sequence>
<xs:element name="policySchema" type="xs:int" />
<xs:element name="certificateValidity" type="vscep:CertificateValidity" />
<xs:element minOccurs="0" maxOccurs="1" name="certificateOverrideValidity" type="vscep:OverrideValidity" />
<xs:element name="subjectNameInfo" nillable="true" type="vscep:subjectName" />
<xs:element name="extensions" nillable="true" type="vscep:Extensions" />
<xs:element name="privateKeyAttributes" type="vscep:PrivateKeyInfo" />
<xs:element name="clientPolicy" nillable="true" type="vscep:ClientPolicy" />
<xs:element minOccurs="0" maxOccurs="1" name="systemInfo" type="vscep:SystemInformation" />
<xs:element name="rAPolicy" nillable="true" type="vscep:RAPolicy" />
<xs:element minOccurs="0" name="seatIdInfo" type="vscep:SeatInfoType" />
<xs:element name="applicationInstructions" nillable="true" type="vscep:ApplicationInstructionsType" />
<xs:element name="deploymentMode" type="xs:string" />
<xs:element name="status" type="xs:string" />
<xs:element name="migrationOIDs" nillable="true" type="vscep:MigrationOIDCollection" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="SystemInformation">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="searchCertificateData" type="vscep:SearchCertificateData" />
<xs:element minOccurs="0" maxOccurs="1" name="cACertPublish" type="vscep:PublishCert" />
<xs:element minOccurs="0" maxOccurs="1" name="cACertPublishNameValuePair" type="vscep:CACertPublishNameValuePair" />
<xs:element name="certificateDeliveryFormat" type="vscep:DeliveryFormat" />
<xs:element minOccurs="0" name="adminInfo" type="vscep:PersonalInfoType" />
<xs:element name="serviceEndpointList" nillable="true" type="vscep:ServiceEndpointListType" />
<xs:element name="duplicateCertPolicy" nillable="true" type="xs:string" />
<xs:element name="supersededPolicyOID" nillable="true" type="xs:string" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="MigrationOIDCollection">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="migratedFromOID" type="xs:string" />
<xs:element name="migratedToOID" nillable="true" type="xs:string" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="PersonalInfoType">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="email" type="xs:string" />
<xs:element name="phone" nillable="true" type="xs:string" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceEndpointListType">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="serviceEndpoint" type="vscep:ServiceEndpointType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceEndpointType">
<xs:sequence>
<xs:element name="type" type="xs:string" />
<xs:element name="endpointURI" type="xs:anyURI" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="SeatInfoType">
<xs:sequence>
<xs:element name="attributeNameValue" type="vscep:AttributeValueType" />
<xs:element name="attributeNameValueProperty" type="vscep:AttributeNameValuePropertyType" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ApplicationInstructionsType">
<xs:sequence>
<xs:element name="fileContentType" type="xs:string" />
<xs:element name="url" type="xs:anyURI" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="DeliveryFormat">
<xs:restriction base="xs:string">
<xs:enumeration value="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" />
<xs:enumeration value="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#PKCS7" />
<xs:enumeration value="http://schemas.verisign.com/pkiservices/2009/07/PKCS12" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="CACertPublishNameValuePair">
<xs:restriction base="xs:string">
<xs:enumeration value="$publish_flag" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="SearchCertificateData">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="searchAttributeNameValuePair" type="vscep:AttributeNameValuePairType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CertificateValidity">
<xs:sequence>
<xs:element name="validityPeriodDays" type="xs:unsignedLong" />
<xs:element name="renewalPeriodDays" type="xs:unsignedLong" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="OverrideValidity">
<xs:sequence>
<xs:element minOccurs="0" name="overrideFlag" type="xs:boolean" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="overrideNameValuePair" type="vscep:validityNameValuePairNames" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="validityNameValuePairNames">
<xs:restriction base="xs:string">
<xs:enumeration value="$overrideValidityDays" />
<xs:enumeration value="$overrideValidityStartDate" />
<xs:enumeration value="$overrideValidityEndDate" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="PrivateKeyInfo">
<xs:sequence>
<xs:element name="keysize" type="xs:int" />
<xs:element minOccurs="0" name="keyEscrowPolicy" type="vscep:KeyEscrowPolicyType" />
<xs:element name="keyexportable" type="xs:boolean" />
<xs:element minOccurs="0" name="keyprotect" type="xs:boolean" />
<xs:element name="algorithmOIDReference" nillable="true" type="xs:int" />
<xs:element name="cryptoProviders" nillable="true" type="vscep:CryptoProviders" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="KeyEscrowPolicyType">
<xs:sequence>
<xs:element name="keyEscrowEnabled" type="xs:boolean" />
<xs:element minOccurs="0" name="keyRecoveryDualAdminApprovalRequired" type="xs:boolean" />
<xs:element name="keyEscrowDeploymentMode" nillable="true" type="xs:string" />
<xs:element name="doKeyRecoveryForAdditionalEnrollRequest" nillable="true" type="xs:boolean" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="CryptoProviders">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="provider" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ClientPolicy">
<xs:sequence>
<xs:element minOccurs="0" name="clientName" type="xs:string" />
<xs:element minOccurs="0" name="maxPinLength" type="xs:int" />
<xs:element minOccurs="0" name="minPinLength" type="xs:int" />
<xs:element minOccurs="0" name="noOfBadAttempts" type="xs:int" />
<xs:element minOccurs="0" name="certRenewalOverlap" type="xs:int" />
<xs:element minOccurs="0" name="renewExpiredCerts" type="xs:boolean" />
<xs:element minOccurs="0" name="certRenewalMsg" type="xs:string" />
<xs:element minOccurs="0" name="certCleanUp" type="xs:boolean" />
<xs:element name="certPublish" type="vscep:PublishCert" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="PublishCert">
<xs:restriction base="xs:string">
<xs:enumeration value="yes" />
<xs:enumeration value="no" />
<xs:enumeration value="clientProvided" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="RAPolicy">
<xs:sequence>
<xs:element name="registerUser" type="xs:boolean" />
<xs:element name="verifyUser" type="xs:boolean" />
<xs:element name="publishCert" type="vscep:PublishCert" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="authorizationInfo" type="vscep:AuthorizationInfoType" />
<xs:element name="pollingPolicy" nillable="true" type="vscep:PollingPolicyType" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="AuthorizationInfoType">
<xs:sequence>
<xs:element name="userAuthorizationCollection" type="vscep:UserAuthorizationCollection" />
<xs:element name="directoryInfo" nillable="true" type="vscep:DirectoryInfoType" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="DirectoryInfoType">
<xs:sequence>
<xs:element name="directoryType" type="xs:string" />
<xs:element name="domainName" type="xs:string" />
<xs:choice>
<xs:element name="ipAddress" type="xs:string" />
<xs:element name="hostName" type="xs:string" />
</xs:choice>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="UserAuthorizationCollection">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="authorizedGroup" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="PollingPolicyType">
<xs:sequence>
<xs:element name="gatewayPollingTime" type="vscep:PollingTimeType" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="PollingTimeType">
<xs:sequence>
<xs:element name="nextUpdateHours" type="xs:int" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Extensions">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Extension" type="vscep:Extension" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Extension">
<xs:sequence>
<xs:element name="extensionOIDReference" type="xs:int" />
<xs:element name="extensionCriticalFlag" type="xs:boolean" />
<xs:element name="extensionSyntax" nillable="true" type="vscep:extensionSyntax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="extensionSyntax">
<xs:sequence>
<xs:choice>
<xs:element minOccurs="0" maxOccurs="unbounded" name="extensionAttributeNameValuePair" type="vscep:AttributeNameValuePairType" />
<xs:element minOccurs="0" maxOccurs="unbounded" name="extensionValue" type="vscep:extensionValueType" />
</xs:choice>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="AttributeNameValuePairType">
<xs:sequence>
<xs:element name="attributeName" type="xs:string" />
<xs:element name="attributeNameValue" nillable="true" type="vscep:AttributeValueType" />
<xs:element minOccurs="0" name="attributeNameValueProperty" type="vscep:AttributeNameValuePropertyType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="AttributeValueType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="mandatory" type="xs:boolean" />
<xs:attribute name="type" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="AttributeNameValuePropertyType">
<xs:sequence>
<xs:element name="value" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="source" type="xs:string" />
<xs:element minOccurs="0" name="sourceAttributeName" type="xs:string" />
<xs:element name="mandatory" nillable="true" type="xs:boolean" />
<xs:element name="overridable" nillable="true" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="extensionValueType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="mandatory" type="xs:boolean" />
<xs:attribute name="type" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="subjectName">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="subjectNameAttribute" type="vscep:subjectNameAttribute" />
<xs:element name="overrideSubjectNameFormat" type="xs:boolean" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="subjectNameAttribute">
<xs:sequence>
<xs:element name="subjectNameAttributecount" nillable="true" type="xs:int" />
<xs:element minOccurs="1" maxOccurs="unbounded" name="subjectNameAttributeNameValuePair" type="vscep:AttributeNameValuePairType" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="CAType">
<xs:restriction base="xs:string">
<xs:enumeration value="public" />
<xs:enumeration value="private" />
</xs:restriction>
</xs:simpleType>
</xs:schema>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<ReferenceGroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="00460f42-a971-4c43-ad3b-382fdbd5b937" xmlns="urn:schemas-microsoft-com:xml-wcfservicemap">
<ClientOptions>
<GenerateAsynchronousMethods>false</GenerateAsynchronousMethods>
<EnableDataBinding>true</EnableDataBinding>
<ExcludedTypes />
<ImportXmlTypes>false</ImportXmlTypes>
<GenerateInternalTypes>false</GenerateInternalTypes>
<GenerateMessageContracts>false</GenerateMessageContracts>
<NamespaceMappings />
<CollectionMappings />
<GenerateSerializableTypes>true</GenerateSerializableTypes>
<Serializer>Auto</Serializer>
<UseSerializerForFaults>true</UseSerializerForFaults>
<ReferenceAllAssemblies>true</ReferenceAllAssemblies>
<ReferencedAssemblies />
<ReferencedDataContractTypes />
<ServiceContractMappings />
</ClientOptions>
<MetadataSources>
<MetadataSource Address="C:\Users\Youra\Documents\GitHub\my-vmprotect\tagg\CertificateEnrollmentPolicy.wsdl" Protocol="file" SourceId="1" />
</MetadataSources>
<Metadata>
<MetadataFile FileName="CertificateEnrollmentPolicy.xsd" MetadataType="Schema" ID="6090e094-b1b5-4dff-b775-2fd0eb92b73b" SourceId="1" SourceUrl="file:///C:/Users/Youra/Documents/GitHub/my-vmprotect/tagg/CertificateEnrollmentPolicy.xsd" />
<MetadataFile FileName="CertificateEnrollmentPolicy.wsdl" MetadataType="Wsdl" ID="f6e85f3b-a650-4d04-ba29-44d72553b97e" SourceId="1" SourceUrl="file:///C:/Users/Youra/Documents/GitHub/my-vmprotect/tagg/CertificateEnrollmentPolicy.wsdl" />
</Metadata>
<Extensions>
<ExtensionFile FileName="configuration91.svcinfo" Name="configuration91.svcinfo" />
<ExtensionFile FileName="configuration.svcinfo" Name="configuration.svcinfo" />
</Extensions>
</ReferenceGroup>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configurationSnapshot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-microsoft-com:xml-wcfconfigurationsnapshot">
<behaviors />
<bindings>
<binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data name=&quot;requestPoliciesServiceSOAP&quot;&gt;&lt;security mode=&quot;Transport&quot; /&gt;&lt;/Data&gt;" bindingType="basicHttpBinding" name="requestPoliciesServiceSOAP" />
<binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data name=&quot;requestPoliciesServiceSOAP1&quot; /&gt;" bindingType="basicHttpBinding" name="requestPoliciesServiceSOAP1" />
</bindings>
<endpoints>
<endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;https://pki-ws.symauth.com/pki-ws/policyService&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;requestPoliciesServiceSOAP&quot; contract=&quot;policyService.policy&quot; name=&quot;requestPoliciesServiceSOAP&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;https://pki-ws.symauth.com/pki-ws/policyService&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;requestPoliciesServiceSOAP&quot; contract=&quot;policyService.policy&quot; name=&quot;requestPoliciesServiceSOAP&quot; /&gt;" contractName="policyService.policy" name="requestPoliciesServiceSOAP" />
</endpoints>
</configurationSnapshot>

View File

@ -0,0 +1,310 @@
<?xml version="1.0" encoding="utf-8"?>
<SavedWcfConfigurationInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="9.1" CheckSum="sdPdnbX35IphatM6VrabzGivuXc=">
<bindingConfigurations>
<bindingConfiguration bindingType="basicHttpBinding" name="requestPoliciesServiceSOAP">
<properties>
<property path="/name" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>requestPoliciesServiceSOAP</serializedValue>
</property>
<property path="/closeTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/openTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/receiveTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/sendTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/allowCookies" isComplexType="false" isExplicitlyDefined="true" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/bypassProxyOnLocal" isComplexType="false" isExplicitlyDefined="true" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/hostNameComparisonMode" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.HostNameComparisonMode, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>StrongWildcard</serializedValue>
</property>
<property path="/maxBufferPoolSize" isComplexType="false" isExplicitlyDefined="true" clrType="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/maxBufferSize" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>65536</serializedValue>
</property>
<property path="/maxReceivedMessageSize" isComplexType="false" isExplicitlyDefined="true" clrType="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/proxyAddress" isComplexType="false" isExplicitlyDefined="false" clrType="System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/readerQuotas" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.XmlDictionaryReaderQuotasElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.XmlDictionaryReaderQuotasElement</serializedValue>
</property>
<property path="/readerQuotas/maxDepth" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxStringContentLength" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxArrayLength" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxBytesPerRead" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxNameTableCharCount" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/textEncoding" isComplexType="false" isExplicitlyDefined="false" clrType="System.Text.Encoding, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.Text.UTF8Encoding</serializedValue>
</property>
<property path="/transferMode" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.TransferMode, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Buffered</serializedValue>
</property>
<property path="/useDefaultWebProxy" isComplexType="false" isExplicitlyDefined="true" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/messageEncoding" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.WSMessageEncoding, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Text</serializedValue>
</property>
<property path="/security" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.BasicHttpSecurityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.BasicHttpSecurityElement</serializedValue>
</property>
<property path="/security/mode" isComplexType="false" isExplicitlyDefined="true" clrType="System.ServiceModel.BasicHttpSecurityMode, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Transport</serializedValue>
</property>
<property path="/security/transport" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.HttpTransportSecurityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.HttpTransportSecurityElement</serializedValue>
</property>
<property path="/security/transport/clientCredentialType" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.HttpClientCredentialType, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>None</serializedValue>
</property>
<property path="/security/transport/proxyCredentialType" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.HttpProxyCredentialType, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>None</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy" isComplexType="true" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.Configuration.ExtendedProtectionPolicyElement, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.Security.Authentication.ExtendedProtection.Configuration.ExtendedProtectionPolicyElement</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy/policyEnforcement" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.PolicyEnforcement, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Never</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy/protectionScenario" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.ProtectionScenario, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>TransportSelected</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy/customServiceNames" isComplexType="true" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.Configuration.ServiceNameElementCollection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>(Collection)</serializedValue>
</property>
<property path="/security/transport/realm" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/security/message" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.BasicHttpMessageSecurityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.BasicHttpMessageSecurityElement</serializedValue>
</property>
<property path="/security/message/clientCredentialType" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.BasicHttpMessageCredentialType, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>UserName</serializedValue>
</property>
<property path="/security/message/algorithmSuite" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.Security.SecurityAlgorithmSuite, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Default</serializedValue>
</property>
</properties>
</bindingConfiguration>
<bindingConfiguration bindingType="basicHttpBinding" name="requestPoliciesServiceSOAP1">
<properties>
<property path="/name" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>requestPoliciesServiceSOAP1</serializedValue>
</property>
<property path="/closeTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/openTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/receiveTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/sendTimeout" isComplexType="false" isExplicitlyDefined="true" clrType="System.TimeSpan, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/allowCookies" isComplexType="false" isExplicitlyDefined="true" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/bypassProxyOnLocal" isComplexType="false" isExplicitlyDefined="true" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/hostNameComparisonMode" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.HostNameComparisonMode, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>StrongWildcard</serializedValue>
</property>
<property path="/maxBufferPoolSize" isComplexType="false" isExplicitlyDefined="true" clrType="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/maxBufferSize" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>65536</serializedValue>
</property>
<property path="/maxReceivedMessageSize" isComplexType="false" isExplicitlyDefined="true" clrType="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/proxyAddress" isComplexType="false" isExplicitlyDefined="false" clrType="System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/readerQuotas" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.XmlDictionaryReaderQuotasElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.XmlDictionaryReaderQuotasElement</serializedValue>
</property>
<property path="/readerQuotas/maxDepth" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxStringContentLength" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxArrayLength" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxBytesPerRead" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/readerQuotas/maxNameTableCharCount" isComplexType="false" isExplicitlyDefined="false" clrType="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>0</serializedValue>
</property>
<property path="/textEncoding" isComplexType="false" isExplicitlyDefined="false" clrType="System.Text.Encoding, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.Text.UTF8Encoding</serializedValue>
</property>
<property path="/transferMode" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.TransferMode, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Buffered</serializedValue>
</property>
<property path="/useDefaultWebProxy" isComplexType="false" isExplicitlyDefined="true" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/messageEncoding" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.WSMessageEncoding, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Text</serializedValue>
</property>
<property path="/security" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.BasicHttpSecurityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.BasicHttpSecurityElement</serializedValue>
</property>
<property path="/security/mode" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.BasicHttpSecurityMode, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>None</serializedValue>
</property>
<property path="/security/transport" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.HttpTransportSecurityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.HttpTransportSecurityElement</serializedValue>
</property>
<property path="/security/transport/clientCredentialType" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.HttpClientCredentialType, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>None</serializedValue>
</property>
<property path="/security/transport/proxyCredentialType" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.HttpProxyCredentialType, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>None</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy" isComplexType="true" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.Configuration.ExtendedProtectionPolicyElement, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.Security.Authentication.ExtendedProtection.Configuration.ExtendedProtectionPolicyElement</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy/policyEnforcement" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.PolicyEnforcement, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Never</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy/protectionScenario" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.ProtectionScenario, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>TransportSelected</serializedValue>
</property>
<property path="/security/transport/extendedProtectionPolicy/customServiceNames" isComplexType="true" isExplicitlyDefined="false" clrType="System.Security.Authentication.ExtendedProtection.Configuration.ServiceNameElementCollection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>(Collection)</serializedValue>
</property>
<property path="/security/transport/realm" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/security/message" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.BasicHttpMessageSecurityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.BasicHttpMessageSecurityElement</serializedValue>
</property>
<property path="/security/message/clientCredentialType" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.BasicHttpMessageCredentialType, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>UserName</serializedValue>
</property>
<property path="/security/message/algorithmSuite" isComplexType="false" isExplicitlyDefined="false" clrType="System.ServiceModel.Security.SecurityAlgorithmSuite, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>Default</serializedValue>
</property>
</properties>
</bindingConfiguration>
</bindingConfigurations>
<endpoints>
<endpoint name="requestPoliciesServiceSOAP" contract="policyService.policy" bindingType="basicHttpBinding" address="https://pki-ws.symauth.com/pki-ws/policyService" bindingConfiguration="requestPoliciesServiceSOAP">
<properties>
<property path="/address" isComplexType="false" isExplicitlyDefined="true" clrType="System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>https://pki-ws.symauth.com/pki-ws/policyService</serializedValue>
</property>
<property path="/behaviorConfiguration" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/binding" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>basicHttpBinding</serializedValue>
</property>
<property path="/bindingConfiguration" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>requestPoliciesServiceSOAP</serializedValue>
</property>
<property path="/contract" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>policyService.policy</serializedValue>
</property>
<property path="/headers" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.AddressHeaderCollectionElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.AddressHeaderCollectionElement</serializedValue>
</property>
<property path="/headers/headers" isComplexType="false" isExplicitlyDefined="true" clrType="System.ServiceModel.Channels.AddressHeaderCollection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>&lt;Header /&gt;</serializedValue>
</property>
<property path="/identity" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.IdentityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.IdentityElement</serializedValue>
</property>
<property path="/identity/userPrincipalName" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.UserPrincipalNameElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.UserPrincipalNameElement</serializedValue>
</property>
<property path="/identity/userPrincipalName/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/identity/servicePrincipalName" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.ServicePrincipalNameElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.ServicePrincipalNameElement</serializedValue>
</property>
<property path="/identity/servicePrincipalName/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/identity/dns" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.DnsElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.DnsElement</serializedValue>
</property>
<property path="/identity/dns/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/identity/rsa" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.RsaElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.RsaElement</serializedValue>
</property>
<property path="/identity/rsa/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/identity/certificate" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.CertificateElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.CertificateElement</serializedValue>
</property>
<property path="/identity/certificate/encodedValue" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/identity/certificateReference" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.CertificateReferenceElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>System.ServiceModel.Configuration.CertificateReferenceElement</serializedValue>
</property>
<property path="/identity/certificateReference/storeName" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.StoreName, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>My</serializedValue>
</property>
<property path="/identity/certificateReference/storeLocation" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.StoreLocation, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>LocalMachine</serializedValue>
</property>
<property path="/identity/certificateReference/x509FindType" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.X509FindType, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>FindBySubjectDistinguishedName</serializedValue>
</property>
<property path="/identity/certificateReference/findValue" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/identity/certificateReference/isChainIncluded" isComplexType="false" isExplicitlyDefined="false" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>False</serializedValue>
</property>
<property path="/name" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue>requestPoliciesServiceSOAP</serializedValue>
</property>
<property path="/kind" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
<property path="/endpointConfiguration" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<serializedValue />
</property>
</properties>
</endpoint>
</endpoints>
</SavedWcfConfigurationInformation>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="getPoliciesResponse" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>ipn_sqlclr.Test.policyService.getPoliciesResponse, Service References.policyService.Reference.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>

View File

@ -0,0 +1,129 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ipn_sqlclr.Test
{
/// <summary>
/// Summary description for TaggantWebTest
/// </summary>
[TestClass]
public class TaggantWebTest
{
public TaggantWebTest()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void PK()
{
string s = (string) UserDefinedFunctions.TaggantPrivateKeyGenerateNew();
}
[TestMethod]
public void WS()
{
var tc = new TaggantConfig()
{
{ "CertificateProfileOID", "2.16.840.1.113733.1.16.1.3.1.4.1.38113944" },
{ "ClientCertificate", "Registration Authority 1409598283849" },
{ "CsrAlgorithm", "MD5withRSA" },
{ "CsrSubject", "O=VMPSoft,OU=Build Server,E=support@vmpsoft.com,L=Yekaterinburg,ST=Ural,C=RU,CN=support@vmpsoft.com" },
{ "EnrollmentUrl", "https://pki-ws.symauth.com/pki-ws/enrollmentService" },
{ "EnrollVersion", "2.0" },
{ "PolicyUrl", "https://pki-ws.symauth.com/pki-ws/policyService" },
{ "PolicyVersion", "2.0" },
};
tc.ClientCertificate = UserDefinedFunctions.LocateCertificate(tc["ClientCertificate"]);
var log = new List<LogItem>();
TaggantWebService.GetPolicies(tc, log);
}
[TestMethod]
public void WS2()
{
var tc = new TaggantConfig()
{
{ "CertificateProfileOid", "2.16.840.1.113733.1.16.1.3.1.4.1.38113944" },
{ "ClientCertificate", "Registration Authority 1409598283849" },
{ "CsrAlgorithm", "MD5withRSA" },
{ "CsrSubject", "O=VMPSoft,OU=Build Server,E=support@vmpsoft.com,L=Yekaterinburg,ST=Ural,C=RU,CN=support@vmpsoft.com" },
{ "EnrollmentUrl", "https://pki-ws.symauth.com/pki-ws/enrollmentService" },
{ "EnrollVersion", "2.0" },
{ "PolicyUrl", "https://pki-ws.symauth.com/pki-ws/policyService" },
{ "PolicyVersion", "2.0" },
};
tc.ClientCertificate = UserDefinedFunctions.LocateCertificate(tc["ClientCertificate"]);
var log = new List<LogItem>();
TaggantWebService.CertRequestNew(tc, "ipn2217", "sqhunter123@mail.ru", "-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIEpAIBAAKCAQEAhjXJd3dMP5BE1mAXh3sAIiK9xUdw3R7lgRA0PtwIDdA1UX5v\n" +
"QHAWk7d5HwDB3V3T1WBRW3tFyjq7YRPB6QM0d2qPi+rpDsT6QlQSCAcVgdyiS1KW" +
"4OYVlVq2vjzVOeFhlgyaSRP06GGNYXBAL9e2yky7hs45OCdMGErLNCJ+Ja97wPtv" +
"Hk03C3ml9kvHegVecMp+5piy5fni+UsJ7toPZFo7HAbB23dc0Rfxj8BiGTM08yuQ" +
"U6nmpjDrtRrOyzIJDIriAKMJ4eTc8rF/y9uG3/ibwmkSH0MtYIvSfyim43ofL8rT" +
"ijhsO0yiMDMSAJyuAJCZjsCAYTMnrsas8c1P9QIDAQABAoIBAC2B43RcwT/0XUML" +
"hi7sKBlrCknwdXak2VEv+2ctGJYGeW3On06MMzuXRLycdx/mhsOdSzjnzbxKueqq" +
"1l96NLohKddZqfjWFb2T4CFUtZg5BdbghERx//OKtNhArFRZ9cr5Lv+EgtCg812M" +
"wFb4oARsjFGjb4d427aI9eoRoBCKt9A9CfqwxHyvclgtIG3W7FazvZ8s1KXhTh4i" +
"N3HHSUkxaADKl6uO4fclq+/tX1mffitIfOxlbZHUsOE1y8tKh8e0onWQ0l2F4aio" +
"SbBhgNo6QiihnVpfpYKn+fMqrZ3qDaky7r94avR7KHneMIwJG5diBrpf5+36xzi6" +
"0Jzy+WkCgYEAzltVepiWZGvmvofGO+PwbVtSYQQt1htE5bnfL4fwPYjSgPiboSTw" +
"5LBVHQWcaGqmNBrmnE1r0vk4Dam/a/Ok2M3+lZXzx3nJTGTjd3PzFP83WnPdplkE" +
"SHau7/EYc8tWGtEGzzUJiLT12n7EFxk8YASpL1znFeKhuDsVgJBkhHsCgYEApn88" +
"c5G7iE1GYCTSclKyU9avBJNiXNdbSy0fnizGQaSp1f3hCtiYbE7Yf6QXfu9gVKf+" +
"FD9a7HJa04QgRr5RmBV8ToLWzBdTZoud2fqO61lhePBQC+d1SyO5BwOzD9vk8BSR" +
"vmaoQoJf8GSzrmhcABo0zkD6uomYohO0wI4Q6k8CgYEAtBpU9YYdpJHkNyCrbHQZ" +
"0Ggm8xPBqZ/tNw9N8t8TV7GGABh7RF7IfOBFuOm/xAZo/wsHgR21YNIxEQO5VU+1" +
"7Z+EdiwFM3FgtnNLcGNbolTJjAGaT2hb657iOfrT26R5hzguWESzCITgGw4OuRZG" +
"cos+2l6cNaayfOfccXQUtucCgYBa+6qoKNoG6NttTJHnwUMLx4RKhtO4kkKkORtP" +
"D36jfn0EoECq8aORhCCQ17WzOtI0ULzqiZiBHxh8/3W30ua5qfwM1zjTvGdp4R+4" +
"b1BMUcKPGRtU9f3Futawe5gNMYfQnhzqpCSMe7w7nHwH8aVctPVoRF//MZPD9erP" +
"UpLxxwKBgQC121tfFNQwNuhQjdz/AD/IjkyDzhAKpOuVrbeFq+Hl31LZN/YBNJbX" +
"7jzQuQ4Pn+D+7ID4s/RVOg/zNvQ9AbWgDmfQ5+7RoEoooM2U0l6DzbVp6MaSw2mT" +
"l6VgW2QubgrqIlt9Rk+zX6pSlN8LDjosYEbnzOhZ5B0Sc20RSkUcjg==\n" +
"-----END RSA PRIVATE KEY-----", log);
}
}
}

View File

@ -0,0 +1,73 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ipn_sqlclr.Test
{
[TestClass]
public class VmpLicenseKeyTest
{
/*[TestMethod] не проходит почему-то
public void TestRsa()
{
var r = new Random();
var data1 = new byte[3072 / 8];
for (int i = 0; i < data1.Length; i++) data1[i] = (byte)r.Next(256);
var encr1 = Rsa.Encrypt(data1);
var decr1 = Rsa.Decrypt(encr1);
Assert.AreNotEqual(data1, encr1);
Assert.AreEqual(data1, decr1);
}*/
[TestMethod]
public void TestGenerateAndParseKey()
{
const int productId = 5;
const string name = "Иван ПетровААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААА";
const string mail = "petrov@mail.ruАААААААААААААААААААААААААААААААААААААААААААААААААААААААААААААА";
var maxBuild = new DateTime(2015, 12, 28);
var key = Keygen.GenerateKey(productId, name, mail, maxBuild);
int productId1;
string name1, mail1;
DateTime maxBuild1;
Keygen.ParseKey(key, out productId1, out name1, out mail1, out maxBuild1);
Assert.AreEqual(productId, productId1);
Assert.AreEqual(name, name1);
Assert.AreEqual(mail, mail1);
Assert.AreEqual(maxBuild, maxBuild1);
Keygen.ParseKey("FgeTRyB93RJeABJN83qKo7mTEvXHGHwYXmZ6pGY5o1X09bc8fmmebq1mryX5yHUWb6F+cauzsLxUyG+uTQBT9zC31EJPQqG9YgaRbOPPS9A7u1HXZA8x491ew0lDKJISy8TYNsjTJ2vB903jW+/A/UVc2+cgDCF3eqztkvYBEas6Y40Hj9A2ylJVYsYWq41RCZyDcXZtlbnuk8W2CDBAk+PGZeUPjEq/oasnTCeKdkO4NY2QVrFzvC/msT+7FWAaBNwe5OQYZLCH875qFVw0H2B9xcnVuIAHAYD00H0Hzk9sf/jAGx4l5CS8FQ4tshZfEllF6CcwVQuRdGz07gQWAQ=="
,out productId1, out name1, out mail1, out maxBuild1);
}
[TestMethod]
public void TestParseOldKey()
{
const int productId = -1;
const string name = "道恭 陈";
const string mail = "sales@sky-deep.com";
var maxBuild = new DateTime(2015, 12, 13);
const string key = "m/j+Km6Y7Kb5AgV0pfLr/Bmw3z9EP/SNv9mawGK0PK8mXWMcJijSzfMbVakJa8ctaZVaNceeanc6" +
"FuurAcyDEpppwS71/t6SoI6Kxc/BUmcHjLlfrWhxk5CrQqFVqyQ+liZEhglHuCE8GRwlPgm60JVv" +
"hCsQBEDeIywTp2GujhjhGra7ojML/guuhRS6W1ILSSkfZriDuCFkkStLgi9gT8GGwX1GUdaXz7Wn" +
"IxrcSYt5OLuPOcPULPUgVr1tB0YopWt/7g3g9jvRxVTThBxcAr+IoIf8RtaTTPIMDae9OZTDL6Pv" +
"p10cUj1HGC1kB8whLWyGdqbhpyg53vUc4Y7FdHe3zUltZA3c3p4/DdZwrU+jrMC/SdzJVuo1MM4p" +
"ZefRwH2f1MYKCUT2zn67f87Sgo2LMmSjWnaORHxrUtskEyguRYcgh0dy6RApI07ZXrK06ZCQu9Ns" +
"zdN3vkxo+NV9clNmVffE7GfRDlcmczvffGcuEUYN59juPnp/vMhFpH1r";
int productId1;
string name1, mail1;
DateTime maxBuild1;
Keygen.ParseKey(key, out productId1, out name1, out mail1, out maxBuild1);
Assert.AreEqual(productId, productId1);
Assert.AreEqual(name, name1);
Assert.AreEqual(mail, mail1);
Assert.AreEqual(maxBuild, maxBuild1);
}
}
}

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F90215BE-45F4-422B-AE75-A2E7DDAC1758}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ipn_sqlclr.Test</RootNamespace>
<AssemblyName>ipn_sqlclr.Test</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Xml" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service References\policyService\Reference.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Reference.svcmap</DependentUpon>
</Compile>
<Compile Include="TaggantWebTest.cs" />
<Compile Include="VmpLicenseKeyTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\utils\ipn_sqlclr\ipn_sqlclr.sqlproj">
<Project>{046364af-635b-4f62-9c8c-d3866b8f622f}</Project>
<Name>ipn_sqlclr</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Service References\policyService\CertificateEnrollmentPolicy.wsdl" />
<None Include="Service References\policyService\CertificateEnrollmentPolicy.xsd">
<SubType>Designer</SubType>
</None>
<None Include="Service References\policyService\ipn_sqlclr.Test.policyService.getPoliciesResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<WCFMetadataStorage Include="Service References\policyService\" />
</ItemGroup>
<ItemGroup>
<None Include="Service References\policyService\configuration91.svcinfo" />
</ItemGroup>
<ItemGroup>
<None Include="Service References\policyService\configuration.svcinfo" />
</ItemGroup>
<ItemGroup>
<None Include="Service References\policyService\Reference.svcmap">
<Generator>WCF Proxy Generator</Generator>
<LastGenOutput>Reference.cs</LastGenOutput>
</None>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,16 @@
SOURCES := core_tests.cc files_tests.cc intel_tests.cc il_tests.cc macfile_tests.cc pefile_tests.cc elffile_tests.cc test1.cc ../third-party/lzma/LzmaDecode.cc
PROJECT := unit.Tests
TARGET := $(PROJECT)
BIN_DIR := ../bin/$(ARCH_DIR)/$(CFG_DIR)
TMP_DIR := ../tmp/lin/$(PROJECT)/$(ARCH_DIR)/TESTS
PCH_DIR := $(TMP_DIR)/$(PROJECT).gch
DEFINES := $(CONFIG) -D TIXML_USE_STL -D _CONSOLE -D FFI_BUILDING
LFLAGS :=
LIBS = $(SDK_LIBS) -Wl,--no-as-needed -L../bin -lVMProtectSDK$(ARCH_DIR) -ldl -Wl,--as-needed
OBJCOMP := ../bin/$(ARCH_DIR)/Release/gtests.a ../bin/$(ARCH_DIR)/$(CFG_DIR)/core.a ../bin/$(ARCH_DIR)/invariant_core.a ../third-party/libffi/libffi$(ARCH_DIR).a -lcrypto -lpthread
DYLIBS :=
INCFLAGS := -I ../third-party/gmock/include/ -I ../third-party/gtest/include/ -I ../third-party/gmock/ -I ../third-party/gtest/
include ../lin_common.mak
include ../gnu_simple.mak

View File

@ -0,0 +1,3 @@
ARCH := i386-linux-gnu
ARCH_DIR := 32
include lin_unit-tests.mak

View File

@ -0,0 +1,3 @@
ARCH := x86_64-linux-gnu
ARCH_DIR := 64
include lin_unit-tests.mak

View File

@ -0,0 +1,16 @@
SOURCES := core_tests.cc files_tests.cc intel_tests.cc il_tests.cc macfile_tests.cc pefile_tests.cc elffile_tests.cc test1.cc ../third-party/lzma/LzmaDecode.cc
PROJECT := unit.Tests
TARGET := $(PROJECT)
BIN_DIR := ../bin/$(ARCH_DIR)/$(CFG_DIR)
TMP_DIR := ../tmp/mac/$(PROJECT)/$(ARCH_DIR)/TESTS
PCH_DIR := $(TMP_DIR)/$(PROJECT).gch
DEFINES := $(CONFIG) -D TIXML_USE_STL -D _CONSOLE -D FFI_BUILDING
LFLAGS :=
LIBS = $(SDK_LIBS) -framework Security
OBJCOMP := ../bin/$(ARCH_DIR)/Release/gtests.a ../bin/$(ARCH_DIR)/invariant_core.a ../bin/$(ARCH_DIR)/$(CFG_DIR)/core.a /usr/local/opt/libffi/lib/libffi.a
DYLIBS := ../bin/libVMProtectSDK.dylib
INCFLAGS := -I ../third-party/gmock/include/ -I ../third-party/gtest/include/ -I ../third-party/gmock/ -I ../third-party/gtest/
include ../mac_common.mak
include ../gnu_simple.mak

View File

@ -0,0 +1,3 @@
ARCH := i386
ARCH_DIR := 32
include mac_unit-tests.mak

View File

@ -0,0 +1,3 @@
ARCH := x86_64
ARCH_DIR := 64
include mac_unit-tests.mak

462
unit-tests/macfile_tests.cc Normal file
View File

@ -0,0 +1,462 @@
#include "../runtime/common.h"
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/core.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/macfile.h"
#include "../core/mac_runtime32.dylib.inc"
#include "../core/mac_runtime64.dylib.inc"
TEST(MacFileTest, TestOpen1)
{
MacFile mf(NULL);
ASSERT_EQ(mf.Open("test-binaries/ios-app-test2-arm", true), osUnsupportedCPU);
}
TEST(MacFileTest, TestOpen2)
{
// Test: read header of iOS/i386 file. Read should finish successfully.
MacFile mf(NULL);
ISectionList *segl;
MacSectionList *secl;
MacSymbolList *syml;
IImportList *impl;
ASSERT_EQ(mf.Open("test-binaries/ios-app-test1-i386", true), osSuccess);
// Check architectures.
EXPECT_EQ(mf.count(), 1ul);
MacArchitecture &arch = *mf.item(0);
EXPECT_EQ(arch.name().compare("i386"), 0);
EXPECT_EQ(arch.owner()->format_name().compare("Mach-O"), 0);
EXPECT_EQ(arch.entry_point(), 0x2130ull);
// Check segments were read.
segl = arch.segment_list();
ASSERT_EQ(segl->count(), 4ul);
EXPECT_EQ(segl->item(0)->name().compare("__PAGEZERO"), 0);
EXPECT_EQ(segl->item(0)->memory_type(), mtNone);
EXPECT_EQ(segl->item(1)->name().compare("__TEXT"), 0);
EXPECT_EQ((int)segl->item(1)->memory_type(), (mtReadable | mtExecutable));
EXPECT_EQ(segl->item(2)->name().compare("__DATA"), 0);
EXPECT_EQ((int)segl->item(2)->memory_type(), (mtReadable | mtWritable));
EXPECT_EQ(segl->item(3)->name().compare("__LINKEDIT"), 0);
EXPECT_EQ(segl->item(3)->memory_type(), mtReadable);
// Check sections were read.
secl = arch.section_list();
ASSERT_EQ(secl->count(), 18ul);
EXPECT_EQ(secl->item(0)->name().compare("__text"), 0);
EXPECT_EQ(secl->item(1)->name().compare("__symbol_stub"), 0);
EXPECT_EQ(secl->item(2)->name().compare("__stub_helper"), 0);
EXPECT_EQ(secl->item(3)->name().compare("__cstring"), 0);
EXPECT_EQ(secl->item(4)->name().compare("__unwind_info"), 0);
EXPECT_EQ(secl->item(5)->name().compare("__eh_frame"), 0);
EXPECT_EQ(secl->item(6)->name().compare("__program_vars"), 0);
EXPECT_EQ(secl->item(7)->name().compare("__nl_symbol_ptr"), 0);
EXPECT_EQ(secl->item(8)->name().compare("__la_symbol_ptr"), 0);
EXPECT_EQ(secl->item(9)->name().compare("__objc_classlist"), 0);
EXPECT_EQ(secl->item(10)->name().compare("__objc_protolist"), 0);
EXPECT_EQ(secl->item(11)->name().compare("__objc_imageinfo"), 0);
EXPECT_EQ(secl->item(12)->name().compare("__objc_const"), 0);
EXPECT_EQ(secl->item(13)->name().compare("__objc_selrefs"), 0);
EXPECT_EQ(secl->item(14)->name().compare("__objc_classrefs"), 0);
EXPECT_EQ(secl->item(15)->name().compare("__objc_superrefs"), 0);
EXPECT_EQ(secl->item(16)->name().compare("__objc_data"), 0);
EXPECT_EQ(secl->item(17)->name().compare("__data"), 0);
// Check symbols.
syml = arch.symbol_list();
ASSERT_EQ(syml->count(), 129ul);
EXPECT_EQ(syml->item(0)->name()
.compare("/Users/macuser/work2/ios-test2/ios-test2/"), 0);
// Check imports.
impl = arch.import_list();
ASSERT_EQ(impl->count(), 6ul);
EXPECT_EQ(impl->item(0)->name().compare("/System/Library/Frameworks/UIKit.framework/UIKit"), 0);
EXPECT_EQ(impl->item(5)->name().compare("/usr/lib/libobjc.A.dylib"), 0);
EXPECT_EQ(impl->item(5)->count(), 11ul);
EXPECT_EQ(impl->item(5)->item(0)->name().compare("__objc_empty_cache"), 0);
EXPECT_EQ(impl->item(5)->item(1)->name().compare("__objc_empty_cache"), 0);
EXPECT_EQ(impl->item(5)->item(2)->name().compare("__objc_empty_cache"), 0);
EXPECT_EQ(impl->item(5)->item(3)->name().compare("__objc_empty_cache"), 0);
EXPECT_EQ(impl->item(5)->item(4)->name().compare("__objc_empty_vtable"), 0);
EXPECT_EQ(impl->item(5)->item(5)->name().compare("__objc_empty_vtable"), 0);
EXPECT_EQ(impl->item(5)->item(6)->name().compare("__objc_empty_vtable"), 0);
EXPECT_EQ(impl->item(5)->item(7)->name().compare("__objc_empty_vtable"), 0);
EXPECT_EQ(impl->item(5)->item(8)->name().compare("_objc_msgSend"), 0);
EXPECT_EQ(impl->item(5)->item(9)->name().compare("_objc_msgSendSuper2"), 0);
EXPECT_EQ(impl->item(5)->item(10)->name().compare("_objc_setProperty"), 0);
mf.Close();
EXPECT_EQ(mf.count(), 0ul);
}
TEST(MacFileTest, TestOpen3)
{
// Test: read header of iOS/x86-64 file. Read should finish successfully.
MacFile mf(NULL);
ISectionList *segl;
MacSectionList *secl;
MacSymbolList *syml;
IImportList *impl;
IExportList *expl;
ASSERT_EQ(mf.Open("test-binaries/macos-app-test1-amd64", true), osSuccess);
// Check architectures.
ASSERT_EQ(mf.count(), 1ul);
MacArchitecture &arch = *mf.item(0);
EXPECT_EQ(arch.name().compare("x86_64"), 0);
EXPECT_EQ(arch.owner()->format_name().compare("Mach-O"), 0);
EXPECT_EQ(arch.entry_point(), 0x0000000100000c04ULL);
// Check segments were read.
segl = arch.segment_list();
ASSERT_EQ(segl->count(), 4ul);
EXPECT_EQ(segl->item(0)->name().compare("__PAGEZERO"), 0);
EXPECT_EQ(segl->item(0)->memory_type(), mtNone);
EXPECT_EQ(segl->item(1)->name().compare("__TEXT"), 0);
EXPECT_EQ((int)segl->item(1)->memory_type(), (mtReadable | mtExecutable));
EXPECT_EQ(segl->item(2)->name().compare("__DATA"), 0);
EXPECT_EQ((int)segl->item(2)->memory_type(), (mtReadable | mtWritable));
EXPECT_EQ(segl->item(3)->name().compare("__LINKEDIT"), 0);
EXPECT_EQ(segl->item(3)->memory_type(), mtReadable);
// Check sections were read.
secl = arch.section_list();
ASSERT_EQ(secl->count(), 10ul);
EXPECT_EQ(secl->item(0)->name().compare("__text"), 0);
EXPECT_EQ(secl->item(1)->name().compare("__stubs"), 0);
EXPECT_EQ(secl->item(2)->name().compare("__stub_helper"), 0);
EXPECT_EQ(secl->item(3)->name().compare("__cstring"), 0);
EXPECT_EQ(secl->item(4)->name().compare("__unwind_info"), 0);
EXPECT_EQ(secl->item(5)->name().compare("__eh_frame"), 0);
EXPECT_EQ(secl->item(6)->name().compare("__dyld"), 0);
EXPECT_EQ(secl->item(7)->name().compare("__got"), 0);
EXPECT_EQ(secl->item(8)->name().compare("__la_symbol_ptr"), 0);
EXPECT_EQ(secl->item(9)->name().compare("__data"), 0);
// Check symbols.
syml = arch.symbol_list();
ASSERT_EQ(syml->count(), 57ul);
EXPECT_EQ(syml->item(2)->name()
.compare("/Users/mac/Library/Developer/Xcode/DerivedData/hello-flxnqzrlabvwqrdcesuuqdaabhfa/Build/Intermediates/hello.build/Release/hello.build/Objects-normal/x86_64/main.o"), 0);
// Check imports.
impl = arch.import_list();
ASSERT_EQ(impl->count(), 3ul);
EXPECT_EQ(impl->item(0)->name().compare("/usr/lib/libstdc++.6.dylib"), 0);
EXPECT_EQ(impl->item(1)->name().compare("/usr/lib/libgcc_s.1.dylib"), 0);
EXPECT_EQ(impl->item(2)->name().compare("/usr/lib/libSystem.B.dylib"), 0);
// Check exports.
expl = arch.export_list();
ASSERT_EQ(expl->count(), 5ul);
EXPECT_EQ(expl->item(0)->name().compare("_NXArgc"), 0);
EXPECT_EQ(expl->item(1)->name().compare("_NXArgv"), 0);
EXPECT_EQ(expl->item(2)->name().compare("___progname"), 0);
EXPECT_EQ(expl->item(3)->name().compare("_environ"), 0);
EXPECT_EQ(expl->item(4)->name().compare("start"), 0);
EXPECT_EQ(expl->item(4)->address(), 0x100000c04ULL);
mf.Close();
EXPECT_EQ(mf.count(), 0ul);
}
TEST(MacFileTest, OpenMacDLL)
{
MacFile mf(NULL);
EXPECT_EQ(mf.Open("test-binaries/macos-dll-test1-i386", foRead), osSuccess);
// Check architectures.
ASSERT_EQ(mf.count(), 1ul);
MacArchitecture &arch = *mf.item(0);
// Check exports.
IExportList *exp = arch.export_list();
EXPECT_EQ(exp->name().compare("@executable_path/hello_lib_cpp.dylib"), 0);
ASSERT_EQ(exp->count(), 1ul);
EXPECT_EQ(exp->item(0)->name().compare("__ZN13hello_lib_cpp10HelloWorldEPKc"), 0);
EXPECT_EQ(exp->item(0)->forwarded_name().compare(""), 0);
EXPECT_EQ(exp->item(0)->address(), 0x00000deaull);
// Check fixups.
IFixupList *fixup_list = arch.fixup_list();
ASSERT_EQ(fixup_list->count(), 23ul);
EXPECT_EQ(fixup_list->item(0)->address(), 0x00000e84ull);
EXPECT_EQ(fixup_list->item(0)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(22)->address(), 0x00001034ull);
EXPECT_EQ(fixup_list->item(22)->type(), ftHighLow);
mf.Close();
EXPECT_EQ(mf.count(), 0ul);
}
TEST(MacFileTest, Clone)
{
MacFile mf(NULL);
ASSERT_EQ(mf.Open("test-binaries/ios-app-test1-i386", foRead), osSuccess);
MacFile *f = mf.Clone(mf.file_name().c_str());
ASSERT_EQ(mf.count(), f->count());
MacArchitecture &src = *mf.item(0);
MacArchitecture &dst = *f->item(0);
EXPECT_EQ(src.owner()->format_name().compare(dst.owner()->format_name()), 0);
EXPECT_EQ(src.name().compare(dst.name()), 0);
EXPECT_EQ(src.cpu_address_size(), dst.cpu_address_size());
EXPECT_EQ(src.entry_point(), dst.entry_point());
EXPECT_EQ(src.command_list()->count(), dst.command_list()->count());
EXPECT_EQ(src.command_list()->count(), dst.command_list()->count());
EXPECT_EQ(src.segment_list()->count(), dst.segment_list()->count());
EXPECT_EQ(src.section_list()->count(), dst.section_list()->count());
EXPECT_EQ(src.symbol_list()->count(), dst.symbol_list()->count());
EXPECT_EQ(src.import_list()->count(), dst.import_list()->count());
EXPECT_EQ(src.fixup_list()->count(), dst.fixup_list()->count());
EXPECT_EQ(src.export_list()->count(), dst.export_list()->count());
std::string symbol_name = src.indirect_symbol_list()->item(1)->symbol()->name();
std::string segment_name = src.section_list()->item(0)->parent()->name();
mf.Close();
EXPECT_EQ(dst.indirect_symbol_list()->item(1)->symbol()->name().compare(symbol_name), 0);
EXPECT_EQ(dst.section_list()->item(0)->parent()->name().compare(segment_name), 0);
delete f;
}
TEST(MacFileTest, Runtime_x32)
{
MacFile file(NULL);
ASSERT_TRUE(file.OpenResource(mac_runtime32_dylib_file, sizeof(mac_runtime32_dylib_file), true));
ASSERT_EQ(file.count(), 1ul);
MacArchitecture *arch = file.item(0);
Buffer buffer(&mac_runtime32_dylib_code[0]);
arch->ReadFromBuffer(buffer);
EXPECT_EQ(arch->export_list()->count(), 21ul);
EXPECT_GT(arch->function_list()->count(), 0ul);
}
TEST(MacFileTest, Runtime_x64)
{
MacFile file(NULL);
ASSERT_TRUE(file.OpenResource(mac_runtime64_dylib_file, sizeof(mac_runtime64_dylib_file), true));
ASSERT_EQ(file.count(), 1ul);
MacArchitecture *arch = file.item(0);
Buffer buffer(&mac_runtime64_dylib_code[0]);
arch->ReadFromBuffer(buffer);
EXPECT_EQ(arch->export_list()->count(), 21ul);
EXPECT_GT(arch->function_list()->count(), 0ul);
}
TEST(MacFileTest, Compile_x32)
{
MacFile mf(NULL);
size_t i;
MacSegment *segment;
ASSERT_EQ(mf.Open("test-binaries/exc-osx-x86", foRead), osSuccess);
MacArchitecture *arch = mf.item(0);
std::string file_name = mf.file_name() + "_vmp";
MacFile *f = mf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
MacArchitecture *dst = f->item(0);
MacSegment *text_segment = dst->segment_list()->GetSectionByName(SEG_TEXT);
ASSERT_TRUE(text_segment != NULL);
if (dst->entry_point()) {
segment = dst->segment_list()->GetSectionByAddress(dst->entry_point());
ASSERT_EQ(segment, text_segment);
}
size_t pointer_size = dst->cpu_address_size() == osDWord ? 4 : 8;
for (i = 0; i < dst->section_list()->count(); i++) {
MacSection *section = dst->section_list()->item(i);
if (section->type() == S_MOD_INIT_FUNC_POINTERS) {
ASSERT_TRUE((section->address() % pointer_size) == 0);
ASSERT_TRUE((section->size() % pointer_size) == 0);
ASSERT_TRUE(dst->AddressSeek(section->address()));
for (uint64_t j = 0; j < section->size(); j += pointer_size) {
uint64_t address = 0;
dst->Read(&address, pointer_size);
segment = dst->segment_list()->GetSectionByAddress(address);
ASSERT_EQ(segment, text_segment);
}
}
}
for (i = 0; i < dst->fixup_list()->count(); i++) {
MacFixup *fixup = dst->fixup_list()->item(i);
if (fixup->is_relocation())
continue;
MacSegment *segment = dst->segment_list()->GetSectionByAddress(fixup->address());
ASSERT_TRUE(segment != NULL);
switch (fixup->bind_type()) {
case REBASE_TYPE_POINTER:
ASSERT_EQ(segment->memory_type() & (mtExecutable | mtWritable), mtWritable);
break;
case REBASE_TYPE_TEXT_ABSOLUTE32:
case REBASE_TYPE_TEXT_PCREL32:
ASSERT_EQ(segment->memory_type() & (mtExecutable | mtWritable), mtExecutable);
break;
}
}
// check AV buffer
ASSERT_EQ(dst->segment_list()->count(), 7ul);
ASSERT_TRUE(dst->AddressSeek(dst->segment_list()->item(4)->address()));
uint32_t sum = 0;
for (i = 0; i < 64; i++) {
sum += dst->ReadDWord();
}
EXPECT_EQ(sum, 0xB7896EB5);
// delete file from disk
delete f;
remove(file_name.c_str());
}
TEST(MacFileTest, Compile_x64)
{
MacFile mf(NULL);
size_t i;
MacSegment *segment;
ASSERT_EQ(mf.Open("test-binaries/exc-osx-x64", foRead), osSuccess);
MacArchitecture *arch = mf.item(0);
std::string file_name = mf.file_name() + "_vmp";
MacFile *f = mf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
MacArchitecture *dst = f->item(0);
MacSegment *text_segment = dst->segment_list()->GetSectionByName(SEG_TEXT);
ASSERT_TRUE(text_segment != NULL);
if (dst->entry_point()) {
segment = dst->segment_list()->GetSectionByAddress(dst->entry_point());
ASSERT_EQ(segment, text_segment);
}
size_t pointer_size = dst->cpu_address_size() == osDWord ? 4 : 8;
for (i = 0; i < dst->section_list()->count(); i++) {
MacSection *section = dst->section_list()->item(i);
if (section->type() == S_MOD_INIT_FUNC_POINTERS) {
ASSERT_TRUE((section->address() % pointer_size) == 0);
ASSERT_TRUE((section->size() % pointer_size) == 0);
ASSERT_TRUE(dst->AddressSeek(section->address()));
for (uint64_t j = 0; j < section->size(); j += pointer_size) {
uint64_t address = 0;
dst->Read(&address, pointer_size);
segment = dst->segment_list()->GetSectionByAddress(address);
ASSERT_EQ(segment, text_segment);
}
}
}
for (i = 0; i < dst->fixup_list()->count(); i++) {
MacFixup *fixup = dst->fixup_list()->item(i);
if (fixup->is_relocation())
continue;
MacSegment *segment = dst->segment_list()->GetSectionByAddress(fixup->address());
ASSERT_TRUE(segment != NULL);
switch (fixup->bind_type()) {
case REBASE_TYPE_POINTER:
ASSERT_EQ(segment->memory_type() & (mtExecutable | mtWritable), mtWritable);
break;
case REBASE_TYPE_TEXT_ABSOLUTE32:
case REBASE_TYPE_TEXT_PCREL32:
ASSERT_EQ(segment->memory_type() & (mtExecutable | mtWritable), mtExecutable);
break;
}
}
// check AV buffer
ASSERT_EQ(dst->segment_list()->count(), 7ul);
ASSERT_TRUE(dst->AddressSeek(dst->segment_list()->item(4)->address()));
uint32_t sum = 0;
for (i = 0; i < 64; i++) {
sum += dst->ReadDWord();
}
EXPECT_EQ(sum, 0xB7896EB5);
// delete file from disk
delete f;
remove(file_name.c_str());
}
#ifdef __APPLE__
#ifndef DEMO
static bool execFile(const std::string &fileName, DWORD &exitCode)
{
exitCode = 0xFFFFFFF;
int ret = system(fileName.c_str());
if (ret != -1)
{
exitCode = DWORD(ret);
return true;
}
return false;
}
/*
// exc.cpp:
// clang++ -std=c++11 -arch x86_64 -o exc-osx-x64 exc.cpp ../bin/libVMProtectSDK.dylib -I ../sdk
// clang++ -std=c++11 -arch i386 -o exc-osx-x86 exc.cpp ../bin/libVMProtectSDK.dylib -I ../sdk
#include <stdio.h>
#include "VMProtectSDK.h"
__declspec(noinline) void try1()
{
printf("try 1\n");
try {
throw 1;
}
catch (int) {
printf("catch 1\n");
throw;
}
printf("end 1\n\n");
}
int main()
{
if (VMProtectIsDebuggerPresent(true))
printf("debugger detected\n");
if (VMProtectIsVirtualMachinePresent())
printf("virtual machine detected\n");
printf("try main\n");
try {
try1();
}
catch (...) {
printf("catch main\n");
}
printf("end main\n");
return 0;
}
*/
TEST(MacFileTest, EXC_x32)
{
MacFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/exc-osx-x86", foRead), osSuccess);
MacArchitecture *arch = pf.item(0);
arch->function_list()->AddByAddress(0x01C60, ctVirtualization, 0, true, NULL); // main
arch->function_list()->AddByAddress(0x01BA0, ctUltra, 0, true, NULL); // try1
std::string file_name = pf.file_name() + "_vmp";
MacFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
DWORD ret;
ASSERT_TRUE(execFile(file_name, ret));
ASSERT_EQ(ret, 0u);
}
TEST(MacFileTest, EXC_x64)
{
MacFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/exc-osx-x64", foRead), osSuccess);
MacArchitecture *arch = pf.item(0);
arch->function_list()->AddByAddress(0x0000000100000C50, ctVirtualization, 0, true, NULL); // main
arch->function_list()->AddByAddress(0x0000000100000BB0, ctUltra, 0, true, NULL); // try1
std::string file_name = pf.file_name() + "_vmp";
MacFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
DWORD ret;
ASSERT_TRUE(execFile(file_name, ret));
ASSERT_EQ(ret, 0u);
}
#endif
#endif

553
unit-tests/pefile_tests.cc Normal file
View File

@ -0,0 +1,553 @@
#include "../runtime/common.h"
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/core.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/pefile.h"
#include "../core/packer.h"
#include "../third-party/lzma/LzmaDecode.h"
#ifdef DEMO
#include "../core/win_runtime32demo.dll.inc"
#include "../core/win_runtime64demo.dll.inc"
#else
#include "../core/win_runtime32.dll.inc"
#include "../core/win_runtime64.dll.inc"
#endif
#ifdef VMP_GNU
#include <stdlib.h>
#endif
TEST(PEFileTest, OpenEXE)
{
// Test: read header of Win32/Intel file. Read should finish successfully.
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/win32-app-test1-i386", foRead), osSuccess);
// Check architectures.
ASSERT_EQ(pf.count(), 1ul);
PEArchitecture *arch = pf.arch_pe();
EXPECT_EQ(arch->name().compare("i386"), 0);
EXPECT_EQ(arch->owner()->format_name().compare("PE"), 0);
EXPECT_EQ(arch->cpu_address_size(), osDWord);
EXPECT_EQ(arch->image_base(), 0x400000ull);
EXPECT_EQ(arch->entry_point(), 0x401000ull);
// Check segments.
ISectionList *segment_list = arch->segment_list();
ASSERT_EQ(segment_list->count(), 3ul);
EXPECT_EQ(segment_list->item(0)->name().compare(".text"), 0);
EXPECT_EQ(segment_list->item(1)->name().compare(".rdata"), 0);
EXPECT_EQ(segment_list->item(2)->name().compare(".data"), 0);
EXPECT_EQ((int)segment_list->item(0)->memory_type(), (mtReadable | mtExecutable));
EXPECT_EQ((int)segment_list->item(1)->memory_type(), mtReadable);
EXPECT_EQ((int)segment_list->item(2)->memory_type(), (mtReadable | mtWritable));
// Check imports.
IImportList *imp = arch->import_list();
ASSERT_EQ(imp->count(), 3ul);
EXPECT_EQ(imp->item(0)->name().compare("user32.dll"), 0);
ASSERT_EQ(imp->item(0)->count(), 6ul);
EXPECT_EQ(imp->item(0)->item(0)->name().compare("SetFocus"), 0);
EXPECT_EQ(imp->item(0)->item(0)->address(), 0x402028ull);
EXPECT_EQ(imp->item(0)->item(1)->name().compare("MessageBoxA"), 0);
EXPECT_EQ(imp->item(0)->item(1)->address(), 0x40202cull);
EXPECT_EQ(imp->item(0)->item(2)->name().compare("GetDlgItemTextA"), 0);
EXPECT_EQ(imp->item(0)->item(2)->address(), 0x402030ull);
EXPECT_EQ(imp->item(0)->item(3)->name().compare("GetDlgItem"), 0);
EXPECT_EQ(imp->item(0)->item(3)->address(), 0x402034ull);
EXPECT_EQ(imp->item(0)->item(4)->name().compare("EndDialog"), 0);
EXPECT_EQ(imp->item(0)->item(4)->address(), 0x402038ull);
EXPECT_EQ(imp->item(0)->item(5)->name().compare("DialogBoxIndirectParamA"), 0);
EXPECT_EQ(imp->item(0)->item(5)->address(), 0x40203cull);
EXPECT_EQ(imp->item(1)->name().compare("kernel32.dll"), 0);
ASSERT_EQ(imp->item(1)->count(), 5ul);
EXPECT_EQ(imp->item(1)->item(0)->name().compare("MultiByteToWideChar"), 0);
EXPECT_EQ(imp->item(1)->item(0)->address(), 0x402010ull);
EXPECT_EQ(imp->item(1)->item(1)->name().compare("GlobalFree"), 0);
EXPECT_EQ(imp->item(1)->item(1)->address(), 0x402014ull);
EXPECT_EQ(imp->item(1)->item(2)->name().compare("ExitProcess"), 0);
EXPECT_EQ(imp->item(1)->item(2)->address(), 0x402018ull);
EXPECT_EQ(imp->item(1)->item(3)->name().compare("GetModuleHandleA"), 0);
EXPECT_EQ(imp->item(1)->item(3)->address(), 0x40201cull);
EXPECT_EQ(imp->item(1)->item(4)->name().compare("GlobalAlloc"), 0);
EXPECT_EQ(imp->item(1)->item(4)->address(), 0x402020ull);
EXPECT_EQ(imp->item(2)->name().compare("VMProtectSDK32.dll"), 0);
ASSERT_EQ(imp->item(2)->count(), 3ul);
EXPECT_EQ(imp->item(2)->item(0)->name().compare("VMProtectDecryptStringA"), 0);
EXPECT_EQ(imp->item(2)->item(0)->address(), 0x402000ull);
EXPECT_EQ(imp->item(2)->item(1)->name().compare("VMProtectEnd"), 0);
EXPECT_EQ(imp->item(2)->item(1)->address(), 0x402004ull);
EXPECT_EQ(imp->item(2)->item(2)->name().compare("VMProtectBegin"), 0);
EXPECT_EQ(imp->item(2)->item(2)->address(), 0x402008ull);
// Check fixups.
IFixupList *fixup_list = arch->fixup_list();
EXPECT_EQ(fixup_list->count(), 0ul);
// Check resources.
IResourceList *resource_list = arch->resource_list();
EXPECT_EQ(resource_list->count(), 0ul);
// Check lists were cleared.
pf.Close();
EXPECT_EQ(pf.count(), 0ul);
}
TEST(PEFileTest, OpenDLL)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/win32-dll-test1-i386", foRead), osSuccess);
// Check architectures.
ASSERT_EQ(pf.count(), 1ul);
PEArchitecture *arch = pf.arch_pe();
// Check exports.
IExportList *exp = arch->export_list();
EXPECT_EQ(exp->name().compare("ShimEng.dll"), 0);
ASSERT_EQ(exp->count(), 11ul);
EXPECT_EQ(exp->item(0)->name().compare("SE_DllLoaded"), 0);
EXPECT_EQ(exp->item(0)->forwarded_name().compare("APPHELP.SE_DllLoaded"), 0);
EXPECT_EQ(exp->item(0)->address(), 0x3ff31257ull);
EXPECT_EQ(exp->item(10)->name().compare("SE_ProcessDying"), 0);
EXPECT_EQ(exp->item(10)->forwarded_name().compare("APPHELP.SE_ProcessDying"), 0);
EXPECT_EQ(exp->item(10)->address(), 0x3ff31358ull);
// Check fixups.
IFixupList *fixup_list = arch->fixup_list();
ASSERT_EQ(fixup_list->count(), 12ul);
EXPECT_EQ(fixup_list->item(0)->address(), 0x3ff3103aull);
EXPECT_EQ(fixup_list->item(0)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(1)->address(), 0x3ff31042ull);
EXPECT_EQ(fixup_list->item(1)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(2)->address(), 0x3ff3104dull);
EXPECT_EQ(fixup_list->item(2)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(3)->address(), 0x3ff31089ull);
EXPECT_EQ(fixup_list->item(3)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(4)->address(), 0x3ff310a2ull);
EXPECT_EQ(fixup_list->item(4)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(5)->address(), 0x3FF310AEull);
EXPECT_EQ(fixup_list->item(5)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(6)->address(), 0x3FF310B6ull);
EXPECT_EQ(fixup_list->item(6)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(7)->address(), 0x3FF310BEull);
EXPECT_EQ(fixup_list->item(7)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(8)->address(), 0x3FF310CAull);
EXPECT_EQ(fixup_list->item(8)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(9)->address(), 0x3FF310E0ull);
EXPECT_EQ(fixup_list->item(9)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(10)->address(), 0x3FF310E8ull);
EXPECT_EQ(fixup_list->item(10)->type(), ftHighLow);
EXPECT_EQ(fixup_list->item(11)->address(), 0x3ff310f0ull);
EXPECT_EQ(fixup_list->item(11)->type(), ftHighLow);
// Check resources.
IResourceList *resource_list = arch->resource_list();
ASSERT_EQ(resource_list->count(), 1ul);
EXPECT_EQ(resource_list->item(0)->type(), rtVersionInfo);
ASSERT_EQ(resource_list->item(0)->count(), 1ul);
EXPECT_EQ(resource_list->item(0)->item(0)->name(), "1");
EXPECT_EQ(resource_list->item(0)->item(0)->count(), 1ul);
EXPECT_EQ(resource_list->item(0)->item(0)->item(0)->name(), "1033");
EXPECT_EQ(resource_list->item(0)->item(0)->item(0)->address(), 0x3ff33060ull);
EXPECT_EQ(resource_list->item(0)->item(0)->item(0)->size(), 0x3acul);
// Check lists were cleared.
pf.Close();
EXPECT_EQ(pf.count(), 0ul);
}
TEST(PEFileTest, Clone)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/win32-app-test1-i386", foRead), osSuccess);
PEFile *f = pf.Clone(pf.file_name().c_str());
EXPECT_EQ(pf.count(), f->count());
PEArchitecture &src = *pf.arch_pe();
PEArchitecture &dst = *f->arch_pe();
EXPECT_EQ(src.owner()->format_name().compare(dst.owner()->format_name()), 0);
EXPECT_EQ(src.name().compare(dst.name()), 0);
EXPECT_EQ(src.cpu_address_size(), dst.cpu_address_size());
EXPECT_EQ(src.entry_point(), dst.entry_point());
EXPECT_EQ(src.command_list()->count(), dst.command_list()->count());
EXPECT_EQ(src.segment_list()->count(), dst.segment_list()->count());
EXPECT_EQ(src.import_list()->count(), dst.import_list()->count());
EXPECT_EQ(src.fixup_list()->count(), dst.fixup_list()->count());
EXPECT_EQ(src.export_list()->count(), dst.export_list()->count());
EXPECT_EQ(src.resource_list()->count(), dst.resource_list()->count());
delete f;
}
TEST(PEFileTest, Runtime_x32)
{
PEFile file(NULL);
ASSERT_TRUE(file.OpenResource(win_runtime32_dll_file, sizeof(win_runtime32_dll_file), true));
ASSERT_EQ(file.count(), 1ul);
PEArchitecture *arch = file.arch_pe();
Buffer buffer(&win_runtime32_dll_code[0]);
arch->ReadFromBuffer(buffer);
EXPECT_GT(arch->export_list()->count(), 0ul);
EXPECT_GT(arch->function_list()->count(), 0ul);
}
TEST(PEFileTest, Runtime_x64)
{
PEFile file(NULL);
ASSERT_TRUE(file.OpenResource(win_runtime64_dll_file, sizeof(win_runtime64_dll_file), true));
ASSERT_EQ(file.count(), 1ul);
PEArchitecture *arch = file.arch_pe();
Buffer buffer(&win_runtime64_dll_code[0]);
arch->ReadFromBuffer(buffer);
EXPECT_GT(arch->export_list()->count(), 0ul);
EXPECT_GT(arch->function_list()->count(), 0ul);
}
TEST(PEFileTest, Compile_x32)
{
PEFile pf(NULL);
size_t i;
ASSERT_EQ(pf.Open("test-binaries/win32-app-delphi-i386", foRead), osSuccess);
PEArchitecture *arch = pf.arch_pe();
for (i = 0; i < arch->map_function_list()->count(); i++) {
MapFunction *map_function = arch->map_function_list()->item(i);
if (map_function->type() == otString || map_function->type() == otAPIMarker || map_function->type() == otMarker)
arch->function_list()->AddByAddress(map_function->address(), ctVirtualization, 0, true, NULL);
}
ASSERT_EQ(arch->function_list()->count(), 4ul);
std::string file_name = pf.file_name()+".exe";
PEFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
PEFile pf2(NULL);
ASSERT_EQ(pf2.Open(file_name.c_str(), foRead | foHeaderOnly), osSuccess);
ASSERT_EQ(pf2.count(), pf.count());
PEArchitecture &src = *pf.arch_pe();
PEArchitecture &dst = *pf2.arch_pe();
for (i = 0; i < src.fixup_list()->count(); i++) {
IFixup *src_fixup = src.fixup_list()->item(i);
IFixup *dst_fixup = src.fixup_list()->GetFixupByAddress(src_fixup->address());
EXPECT_EQ(src_fixup->address(), dst_fixup->address());
EXPECT_EQ(src_fixup->type(), dst_fixup->type());
EXPECT_EQ(src_fixup->size(), dst_fixup->size());
}
if (options.flags & cpResourceProtection) {
EXPECT_EQ(dst.resource_list()->count(), 4ul);
} else {
EXPECT_EQ(src.resource_list()->count(), dst.resource_list()->count());
for (i = 0; i < src.resource_list()->count(); i++) {
PEResource *src_resource = src.resource_list()->item(i);
PEResource *dst_resource = dst.resource_list()->item(i);
EXPECT_EQ(src_resource->count(), dst_resource->count());
EXPECT_EQ(src_resource->address(), dst_resource->address());
EXPECT_EQ(src_resource->size(), dst_resource->size());
EXPECT_EQ(src_resource->type(), dst_resource->type());
EXPECT_EQ(src_resource->name(), dst_resource->name());
}
}
// check AV buffer
ASSERT_EQ(dst.segment_list()->count(), 13ul);
ASSERT_TRUE(dst.AddressSeek(dst.segment_list()->item(10)->address()));
uint32_t sum = 0;
for (i = 0; i < 64; i++) {
sum += dst.ReadDWord();
}
EXPECT_EQ(sum, 0xB7896EB5);
// delete file from disk
pf2.Close();
remove(file_name.c_str());
}
TEST(PEFileTest, Compile_DLL)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/win32-dll-test1-i386", foRead), osSuccess);
std::string file_name = pf.file_name()+".dll";
PEFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpPack;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
PEFile pf2(NULL);
ASSERT_EQ(pf2.Open(file_name.c_str(), foRead | foHeaderOnly), osSuccess);
ASSERT_EQ(pf2.count(), pf.count());
PEArchitecture &src = *pf.arch_pe();
PEArchitecture &dst = *pf2.arch_pe();
size_t i;
for (i = 0; i < src.fixup_list()->count(); i++) {
IFixup *src_fixup = src.fixup_list()->item(i);
IFixup *dst_fixup = src.fixup_list()->GetFixupByAddress(src_fixup->address());
EXPECT_EQ(src_fixup->address(), dst_fixup->address());
EXPECT_EQ(src_fixup->type(), dst_fixup->type());
EXPECT_EQ(src_fixup->size(), dst_fixup->size());
}
ASSERT_EQ(src.resource_list()->count(), dst.resource_list()->count());
for (i = 0; i < src.resource_list()->count(); i++) {
PEResource *src_resource = src.resource_list()->item(i);
PEResource *dst_resource = dst.resource_list()->item(i);
EXPECT_EQ(src_resource->count(), dst_resource->count());
EXPECT_EQ(src_resource->address(), dst_resource->address());
EXPECT_EQ(src_resource->size(), dst_resource->size());
EXPECT_EQ(src_resource->type(), dst_resource->type());
EXPECT_EQ(src_resource->name(), dst_resource->name());
}
ASSERT_EQ(src.export_list()->count(), dst.export_list()->count());
for (i = 0; i < src.export_list()->count(); i++) {
PEExport *src_export = src.export_list()->item(i);
PEExport *dst_export = dst.export_list()->item(i);
EXPECT_EQ(src_export->name(), dst_export->name());
EXPECT_EQ(src_export->ordinal(), dst_export->ordinal());
if (src_export->forwarded_name().empty()) {
EXPECT_EQ(src_export->address(), dst_export->address());
} else {
EXPECT_EQ(src_export->forwarded_name(), dst_export->forwarded_name());
}
}
// check AV buffer
ASSERT_EQ(dst.segment_list()->count(), 7ul);
ASSERT_TRUE(dst.AddressSeek(dst.segment_list()->item(4)->address()));
uint32_t sum = 0;
for (i = 0; i < 64; i++) {
sum += dst.ReadDWord();
}
EXPECT_EQ(sum, 0xB7896EB5);
// delete file from disk
pf2.Close();
remove(file_name.c_str());
}
TEST(PEFileTest, Compile_x64)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/win64-app-msvc-amd64", foRead), osSuccess);
PEArchitecture *arch = pf.arch_pe();
size_t i;
for (i = 0; i < arch->map_function_list()->count(); i++) {
MapFunction *map_function = arch->map_function_list()->item(i);
if (map_function->type() == otString)
arch->function_list()->AddByAddress(map_function->address(), ctVirtualization, 0, true, NULL);
}
ASSERT_EQ(arch->function_list()->count(), 2ul);
std::string file_name = pf.file_name()+".exe";
PEFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
PEFile pf2(NULL);
ASSERT_EQ(pf2.Open(file_name.c_str(), foRead | foHeaderOnly), osSuccess);
ASSERT_EQ(pf2.count(), pf.count());
PEArchitecture &src = *pf.arch_pe();
PEArchitecture &dst = *pf2.arch_pe();
for (i = 0; i < src.fixup_list()->count(); i++) {
IFixup *src_fixup = src.fixup_list()->item(i);
IFixup *dst_fixup = src.fixup_list()->GetFixupByAddress(src_fixup->address());
EXPECT_EQ(src_fixup->address(), dst_fixup->address());
EXPECT_EQ(src_fixup->type(), dst_fixup->type());
EXPECT_EQ(src_fixup->size(), dst_fixup->size());
}
if (options.flags & cpResourceProtection) {
EXPECT_EQ(dst.resource_list()->count(), 1ul);
} else {
ASSERT_EQ(src.resource_list()->count(), dst.resource_list()->count());
for (i = 0; i < src.resource_list()->count(); i++) {
PEResource *src_resource = src.resource_list()->item(i);
PEResource *dst_resource = dst.resource_list()->item(i);
EXPECT_EQ(src_resource->count(), dst_resource->count());
EXPECT_EQ(src_resource->address(), dst_resource->address());
EXPECT_EQ(src_resource->size(), dst_resource->size());
EXPECT_EQ(src_resource->type(), dst_resource->type());
EXPECT_EQ(src_resource->name(), dst_resource->name());
}
}
// check AV buffer
ASSERT_EQ(dst.segment_list()->count(), 9ul);
ASSERT_TRUE(dst.AddressSeek(dst.segment_list()->item(6)->address()));
uint32_t sum = 0;
for (i = 0; i < 64; i++) {
sum += dst.ReadDWord();
}
EXPECT_EQ(sum, 0xB7896EB5);
// delete file from disk
pf2.Close();
remove(file_name.c_str());
}
TEST(PEFileTest, Pack)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/win32-app-delphi-i386", foRead), osSuccess);
PEArchitecture *arch = pf.arch_pe();
PESegment *section = arch->segment_list()->item(0);
Data data, props;
Packer packer;
size_t data_size = static_cast<size_t>(section->physical_size());
ASSERT_TRUE(packer.WriteProps(&props));
ASSERT_TRUE(arch->AddressSeek(section->address()));
ASSERT_TRUE(packer.Code(arch, data_size, &data));
Byte *dst = new Byte[data_size];
CLzmaDecoderState state;
EXPECT_EQ(LzmaDecodeProperties(&state.Properties, props.data(), (unsigned)props.size()), LZMA_RESULT_OK);
state.Probs = (CProb *)new Byte[LzmaGetNumProbs(&state.Properties) * sizeof(CProb)];
SizeT src_processed_size;
SizeT dst_processed_size;
EXPECT_EQ(LzmaDecode(&state, data.data(), -1, &src_processed_size, dst, -1, &dst_processed_size), LZMA_RESULT_OK);
delete [] state.Probs;
ASSERT_EQ(dst_processed_size, data_size);
arch->AddressSeek(section->address());
for (size_t i = 0; i < data_size; i++) {
EXPECT_EQ(dst[i], arch->ReadByte());
}
delete [] dst;
}
TEST(PEFileTest, CalcCheckSum)
{
uint32_t sum;
ASSERT_TRUE(os::FileGetCheckSum("test-binaries/win32-app-delphi-i386", &sum));
EXPECT_EQ(sum, 0x000e4490ul);
ASSERT_TRUE(os::FileGetCheckSum("test-binaries/win64-app-msvc-amd64", &sum));
EXPECT_EQ(sum, 0x0000b8c9ul);
}
#ifndef DEMO
#ifndef __APPLE__
static bool execFile(const std::string &fileName, DWORD &exitCode)
{
exitCode = 0xFFFFFFF;
#ifdef VMP_GNU
int ret = system(("wine " + fileName).c_str());
if (ret != -1)
{
exitCode = DWORD(ret);
return true;
}
return false;
#else
PROCESS_INFORMATION processInformation = { };
STARTUPINFOW startupInfo = { };
startupInfo.cb = sizeof(startupInfo);
os::unicode_string unicodeName = os::FromUTF8(fileName);
BOOL result = CreateProcessW(NULL, const_cast<wchar_t *>(unicodeName.c_str()),
NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
NULL, NULL, &startupInfo, &processInformation);
if (!result)
return false;
WaitForSingleObject(processInformation.hProcess, 10000);
result = GetExitCodeProcess(processInformation.hProcess, &exitCode);
if (exitCode == STILL_ACTIVE)
TerminateProcess(processInformation.hProcess, 0xFFFFFFFF);
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
return (result && (exitCode != STILL_ACTIVE));
#endif
}
/* seh.cpp:
#include <windows.h>
#include "VMProtectSDK.h"
__declspec(noinline) void try1()
{
printf("try 1\n");
try {
throw 1;
}
catch (int) {
printf("catch 1\n");
throw;
}
printf("end 1\n\n");
}
__declspec(noinline) void try2()
{
printf("try 2\n");
PEXCEPTION_POINTERS info = NULL;
__try {
if (*reinterpret_cast<char *>(0xFACE) == 0)
return;
}
__except (info = GetExceptionInformation(), EXCEPTION_EXECUTE_HANDLER) {
printf("throw at %p\n", info->ExceptionRecord->ExceptionAddress);
}
printf("end 2\n\n");
}
int main()
{
if (VMProtectIsDebuggerPresent(true))
printf("debugger detected\n");
if (VMProtectIsVirtualMachinePresent())
printf("virtual machine detected\n");
printf("try main\n");
try {
try1();
}
catch (...) {
printf("catch main\n");
}
printf("end main\n");
try2();
return 0;
}
*/
TEST(PEFileTest, SEH_x32)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/seh-x86", foRead), osSuccess);
PEArchitecture *arch = pf.arch_pe();
arch->function_list()->AddByAddress(0x00401130, ctVirtualization, 0, true, NULL); // main
arch->function_list()->AddByAddress(0x00401000, ctUltra, 0, true, NULL); // try1
arch->function_list()->AddByAddress(0x00401070, ctMutation, 0, true, NULL); // try2
std::string file_name = pf.file_name() + ".exe";
PEFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
DWORD ret;
ASSERT_TRUE(execFile(file_name, ret));
ASSERT_EQ(ret, 0u);
}
#endif
#ifndef VMP_GNU
TEST(PEFileTest, SEH_x64)
{
PEFile pf(NULL);
ASSERT_EQ(pf.Open("test-binaries/seh-x64", foRead), osSuccess);
PEArchitecture *arch = pf.arch_pe();
arch->function_list()->AddByAddress(0x00000001400010A0, ctVirtualization, 0, true, NULL); // main
arch->function_list()->AddByAddress(0x0000000140001000, ctUltra, 0, true, NULL); // try1
arch->function_list()->AddByAddress(0x0000000140001040, ctMutation, 0, true, NULL); // try2
std::string file_name = pf.file_name() + ".exe";
PEFile *f = pf.Clone(file_name.c_str());
CompileOptions options;
options.flags = cpMaximumProtection;
options.section_name = ".vmp";
ASSERT_TRUE(f->Compile(options));
delete f;
DWORD ret;
ASSERT_TRUE(execFile(file_name, ret));
ASSERT_EQ(ret, 0u);
}
#endif
#endif

View File

@ -0,0 +1 @@
#include "precompiled.h"

17
unit-tests/precompiled.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#ifndef UT_PCH
#define UT_PCH
#include "../core/precompiled.h"
#ifdef WIN
#include <windows.h>
#include <crtdbg.h> /* Heap verifying */
#elif MACOSX
#define __ICONS__
#include <Cocoa/Cocoa.h>
#endif
#include "gtest/gtest.h"
#endif //UT_PCH

309
unit-tests/test1.cc Normal file
View File

@ -0,0 +1,309 @@
#include "../runtime/common.h"
#include "../runtime/crypto.h"
#include "../core/objects.h"
#include "../core/osutils.h"
#include "../core/streams.h"
#include "../core/files.h"
#include "../core/processors.h"
#include "../core/intel.h"
#include "testfile.h"
static uint8_t test_data[] = "test data";
const size_t TEST_DATA_SIZE = 9ul;
TEST(AbstractStreamTest, FileStream_Test)
{
bool status;
for (size_t bufSize = TEST_DATA_SIZE + 3; bufSize > 3; bufSize -= 3)
{
FileStream s(bufSize);
uint8_t buf[16];
size_t rc;
uint64_t rc1, rc2;
status = s.Open("test.bin", fmOpenReadWrite | fmShareDenyNone | fmCreate);
ASSERT_TRUE(status);
// Check .Write()
rc = s.Write(reinterpret_cast<const uint8_t*>(test_data), TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
// Check .Seek() with various origins
rc2 = s.Seek(1, soBeginning);
ASSERT_EQ(rc2, 1ull);
rc2 = s.Seek(2, soCurrent);
ASSERT_EQ(rc2, 3ull);
rc2 = s.Seek(1 - (int64_t)TEST_DATA_SIZE, soEnd);
ASSERT_EQ(rc2, 1ull);
// Check .Tell()
rc1 = s.Tell();
ASSERT_EQ(rc1, rc2);
// Check .Read(), validate data
rc = s.Read(buf, TEST_DATA_SIZE - 1);
ASSERT_EQ(rc, TEST_DATA_SIZE - 1);
ASSERT_EQ(0, memcmp(buf, &test_data[1], TEST_DATA_SIZE - 1)); //-V512
s.Seek(0, soBeginning);
rc = s.Read(buf, TEST_DATA_SIZE / 2);
ASSERT_EQ(rc, TEST_DATA_SIZE / 2);
ASSERT_EQ(0, memcmp(buf, &test_data[0], TEST_DATA_SIZE / 2)); //-V512
rc = s.Read(buf, TEST_DATA_SIZE / 2);
ASSERT_EQ(rc, TEST_DATA_SIZE / 2);
ASSERT_EQ(0, memcmp(buf, &test_data[TEST_DATA_SIZE / 2], TEST_DATA_SIZE / 2)); //-V512
// Check .GetSize()
rc2 = s.Size();
ASSERT_EQ(TEST_DATA_SIZE, rc2);
// Check .Resize
rc2 = s.Resize(2 * TEST_DATA_SIZE);
ASSERT_EQ(TEST_DATA_SIZE * 2, rc2);
rc2 = s.Seek(-((int64_t)TEST_DATA_SIZE), soEnd);
ASSERT_EQ(TEST_DATA_SIZE, rc2);
ASSERT_EQ(s.Size(), TEST_DATA_SIZE * 2);
rc = s.Write(test_data, TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
rc = s.Write("\n12", 4);
ASSERT_EQ(rc, 4ul);
rc2 = s.Seek(TEST_DATA_SIZE, soBeginning);
ASSERT_EQ(rc2, TEST_DATA_SIZE);
std::string teststr;
ASSERT_EQ(s.ReadLine(teststr), true);
ASSERT_STREQ(teststr.c_str(), (const char *)test_data);
s.Close();
}
}
TEST(AbstractStreamTest, MemoryStream_Test)
{
MemoryStream s;
uint8_t buf[16];
size_t rc;
uint64_t rc1, rc2;
// Check .Write()
rc = s.Write(reinterpret_cast<const uint8_t*>(test_data), TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
// Check .Seek() with various origins
rc2 = s.Seek(1, soBeginning);
ASSERT_EQ(rc2, 1ull);
rc2 = s.Seek(2, soCurrent);
ASSERT_EQ(rc2, 3ull);
rc2 = s.Seek(1 - (int64_t)TEST_DATA_SIZE, soEnd);
ASSERT_EQ(rc2, 1ull);
// Check .Tell()
rc1 = s.Tell();
ASSERT_EQ(rc1, rc2);
// Check .Read(), validate data
rc = s.Read(buf, TEST_DATA_SIZE - 1);
ASSERT_EQ(rc, TEST_DATA_SIZE - 1);
ASSERT_EQ(0, memcmp(buf, &test_data[1], TEST_DATA_SIZE - 1)); //-V512
// Check .GetSize()
rc2 = s.Size();
ASSERT_EQ(TEST_DATA_SIZE, rc2);
}
TEST(AbstractStreamTest, MemoryStream_Copy_Test)
{
MemoryStream s1, s2;
uint8_t buf[16];
size_t rc;
uint64_t rc2;
rc = s1.Write(reinterpret_cast<const uint8_t*>(test_data), TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
rc2 = s1.Seek(0, soBeginning);
ASSERT_EQ(rc2, 0ull);
rc = s2.CopyFrom(s1, TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
rc2 = s2.Seek(1, soBeginning);
ASSERT_EQ(rc2, 1ull);
rc = s2.Read(buf, TEST_DATA_SIZE - 1);
ASSERT_EQ(rc, TEST_DATA_SIZE - 1);
ASSERT_EQ(0, memcmp(buf, &test_data[1], TEST_DATA_SIZE - 1)); //-V512
}
TEST(AbstractStreamTest, FileStream_Copy_Test)
{
bool status;
for (size_t bufSize = TEST_DATA_SIZE + 3; bufSize > 3; bufSize -= 3)
{
FileStream s1(bufSize), s2(bufSize), s3(bufSize);
status = s1.Open("test1.bin", fmOpenReadWrite | fmShareDenyNone | fmCreate);
ASSERT_TRUE(status);
status = s2.Open("test2.bin", fmOpenReadWrite | fmShareDenyNone | fmCreate);
ASSERT_TRUE(status);
uint8_t buf[16];
size_t rc;
uint64_t rc2;
rc = s1.Write(reinterpret_cast<const uint8_t*>(test_data), TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
rc2 = s1.Seek(0, soBeginning);
ASSERT_EQ(rc2, 0ull);
rc = s2.CopyFrom(s1, TEST_DATA_SIZE);
ASSERT_EQ(rc, TEST_DATA_SIZE);
status = s3.Open("test2.bin", fmOpenRead | fmShareDenyNone);
ASSERT_TRUE(status);
ASSERT_STREQ(s3.ReadAll().c_str(), (const char *)(test_data));
rc2 = s2.Seek(1, soBeginning);
ASSERT_EQ(rc2, 1ull);
rc = s2.Read(buf, TEST_DATA_SIZE - 1);
ASSERT_EQ(rc, TEST_DATA_SIZE - 1);
ASSERT_EQ(0, memcmp(buf, &test_data[1], TEST_DATA_SIZE - 1)); //-V512
s1.Close();
s2.Close();
s3.Close();
}
}
TEST(Demangle, Demangle_Test)
{
const struct {
const char *mangled;
const char *demangled;
} names[] = {
// Check some names from Qt.
{"?newCol@QColorPicker@?A0x3be3cb80@@QEAAXHH@Z", "`anonymous namespace'::QColorPicker::newCol(int,int)"},
{"_ZN9QSettings10beginGroupERK7QString", "QSettings::beginGroup(QString const&)"},
{"_ZNK10QTableView14verticalHeaderEv", "QTableView::verticalHeader() const"},
{"_ZNK12QTableWidget20horizontalHeaderItemEi", "QTableWidget::horizontalHeaderItem(int) const"},
// Apple names.
{"St9bad_alloc", "std::bad_alloc"},
{"_ZN1f1fE", "f::f"},
{"_Z1fv", "f()"},
{"_Z1fi", "f(int)"},
{"_Z3foo3bar", "foo(bar)"},
{"_Zrm1XS_", "operator%(X, X)"},
{"_ZplR1XS0_", "operator+(X&, X&)"},
{"_ZlsRK1XS1_", "operator<<(X const&, X const&)"},
{"_ZN3FooIA4_iE3barE", "Foo<int [4]>::bar"},
{"_Z1fIiEvi", "void f<int>(int)"},
{"_Z5firstI3DuoEvS0_", "void first<Duo>(Duo)"},
{"_Z5firstI3DuoEvT_", "void first<Duo>(Duo)"},
{"_Z3fooIiFvdEiEvv", "void foo<int, void (double), int>()"},
{"_ZN1N1fE", "N::f"},
{"_ZN6System5Sound4beepEv", "System::Sound::beep()"},
{"_ZN5Arena5levelE", "Arena::level"},
{"_ZN5StackIiiE5levelE", "Stack<int, int>::level"},
{"_Z1fI1XEvPVN1AIT_E1TE", "void f<X>(A<X>::T volatile*)"},
{"_ZngILi42EEvN1AIXplT_Li2EEE1TE", "void operator-<42>(A<(42)+(2)>::T)"},
{"_Z4makeI7FactoryiET_IT0_Ev", "Factory<int> make<Factory, int>()"},
{"_Z3foo5Hello5WorldS0_S_", "foo(Hello, World, World, Hello)"},
{"_Z3fooPM2ABi", "foo(int AB::**)"},
{"_ZlsRSoRKSs", "operator<<(std::ostream&, std::string const&)"},
{"_ZTI7a_class", "typeinfo for a_class"},
{"U4_farrVKPi", "int* const volatile restrict _far"},
{"_Z3fooILi2EEvRAplT_Li1E_i", "void foo<2>(int (&) [(2)+(1)])"},
{"_Z1fM1AKFvvE", "f(void (A::*)() const)"},
{"_Z3fooc", "foo(char)"},
{"2CBIL_Z3foocEE", "CB<foo(char)>"},
{"2CBIL_Z7IsEmptyEE", "CB<IsEmpty>"},
{"_ZZN1N1fEiE1p", "N::f(int)::p"},
{"_ZZN1N1fEiEs", "N::f(int)::string literal"},
{"_Z1fPFvvEM1SFvvE", "f(void (*)(), void (S::*)())"},
{"_ZN1N1TIiiE2mfES0_IddE", "N::T<int, int>::mf(N::T<double, double>)"},
{"_ZSt5state", "std::state"},
{"_ZNSt3_In4wardE", "std::_In::ward"},
{"_Z1fKPFiiE", "f(int (* const)(int))"},
{"_Z1fAszL_ZZNK1N1A1fEvE3foo_0E_i", "f(int [sizeof (N::A::f() const::foo)])"},
{"_Z1fA37_iPS_", "f(int [37], int (*) [37])"},
{"_Z1fM1AFivEPS0_", "f(int (A::*)(), int (*)())"},
{"_Z1fPFPA1_ivE", "f(int (*(*)()) [1])"},
{"_Z1fPKM1AFivE", "f(int (A::* const*)())"},
{"_Z1jM1AFivEPS1_", "j(int (A::*)(), int (A::**)())"},
{"_Z1sPA37_iPS0_", "s(int (*) [37], int (**) [37])"},
{"_Z3fooA30_A_i", "foo(int [30][])"},
{"_Z3kooPA28_A30_i", "koo(int (*) [28][30])"},
{"_ZlsRKU3fooU4bart1XS0_", "operator<<(X bart foo const&, X bart)"},
{"_ZlsRKU3fooU4bart1XS2_", "operator<<(X bart foo const&, X bart foo const)"},
{"_Z1fM1AKFivE", "f(int (A::*)() const)"},
{"_Z3absILi11EEvv", "void abs<11>()"},
{"_ZN1AIfEcvT_IiEEv", "A<float>::operator int<int>()"},
{"_ZN12libcw_app_ct10add_optionIS_EEvMT_FvPKcES3_cS3_S3_", "void libcw_app_ct::add_option<libcw_app_ct>(void (libcw_app_ct::*)(char const*), char const*, char, char const*, char const*)"},
{"_ZGVN5libcw24_GLOBAL__N_cbll.cc0ZhUKa23compiler_bug_workaroundISt6vectorINS_13omanip_id_tctINS_5debug32memblk_types_manipulator_data_ctEEESaIS6_EEE3idsE", "guard variable for libcw::(anonymous namespace)::compiler_bug_workaround<std::vector<libcw::omanip_id_tct<libcw::debug::memblk_types_manipulator_data_ct>, std::allocator<libcw::omanip_id_tct<libcw::debug::memblk_types_manipulator_data_ct> > > >::ids"},
{"_ZN5libcw5debug13cwprint_usingINS_9_private_12GlobalObjectEEENS0_17cwprint_using_tctIT_EERKS5_MS5_KFvRSt7ostreamE", "libcw::debug::cwprint_using_tct<libcw::_private_::GlobalObject> libcw::debug::cwprint_using<libcw::_private_::GlobalObject>(libcw::_private_::GlobalObject const&, void (libcw::_private_::GlobalObject::*)(std::ostream&) const)"},
{"_ZNKSt14priority_queueIP27timer_event_request_base_ctSt5dequeIS1_SaIS1_EE13timer_greaterE3topEv", "std::priority_queue<timer_event_request_base_ct*, std::deque<timer_event_request_base_ct*, std::allocator<timer_event_request_base_ct*> >, timer_greater>::top() const"},
{"_ZNKSt15_Deque_iteratorIP15memory_block_stRKS1_PS2_EeqERKS5_", "std::_Deque_iterator<memory_block_st*, memory_block_st* const&, memory_block_st* const*>::operator==(std::_Deque_iterator<memory_block_st*, memory_block_st* const&, memory_block_st* const*> const&) const"},
{"_ZNKSt17__normal_iteratorIPK6optionSt6vectorIS0_SaIS0_EEEmiERKS6_", "std::__normal_iterator<option const*, std::vector<option, std::allocator<option> > >::operator-(std::__normal_iterator<option const*, std::vector<option, std::allocator<option> > > const&) const"},
{"_ZNSbIcSt11char_traitsIcEN5libcw5debug27no_alloc_checking_allocatorEE12_S_constructIPcEES6_T_S7_RKS3_", "char* std::basic_string<char, std::char_traits<char>, libcw::debug::no_alloc_checking_allocator>::_S_construct<char*>(char*, char*, libcw::debug::no_alloc_checking_allocator const&)"},
{"_Z1fI1APS0_PKS0_EvT_T0_T1_PA4_S3_M1CS8_", "void f<A, A*, A const*>(A, A*, A const*, A const* (*) [4], A const* (* C::*) [4])"},
{"_Z3fooiPiPS_PS0_PS1_PS2_PS3_PS4_PS5_PS6_PS7_PS8_PS9_PSA_PSB_PSC_", "foo(int, int*, int**, int***, int****, int*****, int******, int*******, int********, int*********, int**********, int***********, int************, int*************, int**************, int***************)"},
{"_ZSt1BISt1DIP1ARKS2_PS3_ES0_IS2_RS2_PS2_ES2_ET0_T_SB_SA_PT1_", "std::D<A*, A*&, A**> std::B<std::D<A*, A* const&, A* const*>, std::D<A*, A*&, A**>, A*>(std::D<A*, A* const&, A* const*>, std::D<A*, A* const&, A* const*>, std::D<A*, A*&, A**>, A**)"},
{"_X11TransParseAddress", "_X11TransParseAddress"},
{"_ZNSt13_Alloc_traitsISbIcSt18string_char_traitsIcEN5libcw5debug9_private_17allocator_adaptorIcSt24__default_alloc_templateILb0ELi327664EELb1EEEENS5_IS9_S7_Lb1EEEE15_S_instancelessE", "std::_Alloc_traits<std::basic_string<char, std::string_char_traits<char>, libcw::debug::_private_::allocator_adaptor<char, std::__default_alloc_template<false, 327664>, true> >, libcw::debug::_private_::allocator_adaptor<std::basic_string<char, std::string_char_traits<char>, libcw::debug::_private_::allocator_adaptor<char, std::__default_alloc_template<false, 327664>, true> >, std::__default_alloc_template<false, 327664>, true> >::_S_instanceless"},
{"_GLOBAL__I__Z2fnv", "global constructors keyed to fn()"},
{"_Z1rM1GFivEMS_KFivES_M1HFivES1_4whatIKS_E5what2IS8_ES3_", "r(int (G::*)(), int (G::*)() const, G, int (H::*)(), int (G::*)(), what<G const>, what2<G const>, int (G::*)() const)"},
{"_Z10hairyfunc5PFPFilEPcE", "hairyfunc5(int (*(*)(char*))(long))"},
{"_Z1fILi1ELc120EEv1AIXplT_cviLd810000000000000000703DAD7A370C5EEE", "void f<1, (char)120>(A<(1)+((int)((double)[810000000000000000703DAD7A370C5]))>)"},
{"_Z1fILi1EEv1AIXplT_cvingLf3f800000EEE", "void f<1>(A<(1)+((int)(-((float)[3f800000])))>)"},
{"_ZNK11__gnu_debug16_Error_formatter14_M_format_wordImEEvPciPKcT_", "void __gnu_debug::_Error_formatter::_M_format_word<unsigned long>(char*, int, char const*, unsigned long) const"},
{"_ZSt18uninitialized_copyIN9__gnu_cxx17__normal_iteratorIPSt4pairISsPFbP6sqlitePPcEESt6vectorIS9_SaIS9_EEEESE_ET0_T_SG_SF_", "__gnu_cxx::__normal_iterator<std::pair<std::string, bool (*)(sqlite*, char**)>*, std::vector<std::pair<std::string, bool (*)(sqlite*, char**)>, std::allocator<std::pair<std::string, bool (*)(sqlite*, char**)> > > > std::uninitialized_copy<__gnu_cxx::__normal_iterator<std::pair<std::string, bool (*)(sqlite*, char**)>*, std::vector<std::pair<std::string, bool (*)(sqlite*, char**)>, std::allocator<std::pair<std::string, bool (*)(sqlite*, char**)> > > >, __gnu_cxx::__normal_iterator<std::pair<std::string, bool (*)(sqlite*, char**)>*, std::vector<std::pair<std::string, bool (*)(sqlite*, char**)>, std::allocator<std::pair<std::string, bool (*)(sqlite*, char**)> > > > >(__gnu_cxx::__normal_iterator<std::pair<std::string, bool (*)(sqlite*, char**)>*, std::vector<std::pair<std::string, bool (*)(sqlite*, char**)>, std::allocator<std::pair<std::string, bool (*)(sqlite*, char**)> > > >, __gnu_cxx::__normal_iterator<std::pair<std::string, bool (*)(sqlite*, char**)>*, std::vector<std::pair<std::string, bool (*)(sqlite*, char**)>, std::allocator<std::pair<std::string, bool (*)(sqlite*, char**)> > > >, __gnu_cxx::__normal_iterator<std::pair<std::string, bool (*)(sqlite*, char**)>*, std::vector<std::pair<std::string, bool (*)(sqlite*, char**)>, std::allocator<std::pair<std::string, bool (*)(sqlite*, char**)> > > >)"},
{"_Z1fP1cIPFiiEE", "f(c<int (*)(int)>*)"},
{"_Z4dep9ILi3EEvP3fooIXgtT_Li2EEE", "void dep9<3>(foo<((3)>(2))>*)"},
{"_ZStltI9file_pathSsEbRKSt4pairIT_T0_ES6_", "bool std::operator< <file_path, std::string>(std::pair<file_path, std::string> const&, std::pair<file_path, std::string> const&)"},
{"_Z9hairyfuncM1YKFPVPFrPA2_PM1XKFKPA3_ilEPcEiE", "hairyfunc(int (* const (X::** (* restrict (* volatile* (Y::*)(int) const)(char*)) [2])(long) const) [3])"},
{"_Z1fILin1EEvv", "void f<-1>()"},
{"_ZNSdD0Ev", "std::basic_iostream<char, std::char_traits<char> >::~basic_iostream()"},
{"_ZNK15nsBaseHashtableI15nsUint32HashKey8nsCOMPtrI4IFooEPS2_E13EnumerateReadEPF15PLDHashOperatorRKjS4_PvES9_", "nsBaseHashtable<nsUint32HashKey, nsCOMPtr<IFoo>, IFoo*>::EnumerateRead(PLDHashOperator (*)(unsigned int const&, IFoo*, void*), void*) const"},
{"_ZNK1C1fIiEEPFivEv", "int (*C::f<int>() const)()"},
{"_ZZ3BBdI3FooEvvENK3Fob3FabEv", "BBd<Foo>()::Fob::Fab() const"},
{"_ZZZ3BBdI3FooEvvENK3Fob3FabEvENK3Gob3GabEv", "BBd<Foo>()::Fob::Fab() const::Gob::Gab() const"},
{"_ZNK5boost6spirit5matchI13rcs_deltatextEcvMNS0_4impl5dummyEFvvEEv", "boost::spirit::match<rcs_deltatext>::operator void (boost::spirit::impl::dummy::*)()() const"},
{"_Z3fooIA6_KiEvA9_KT_rVPrS4_", "void foo<int const [6]>(int const [9][6], int restrict const (* volatile restrict) [9][6])"},
{"_Z3fooIA3_iEvRKT_", "void foo<int [3]>(int const (&) [3])"},
{"_Z3fooIPA3_iEvRKT_", "void foo<int (*) [3]>(int (* const&) [3])"},
{"_ZN13PatternDriver23StringScalarDeleteValueC1ERKNS_25ConflateStringScalarValueERKNS_25AbstractStringScalarValueERKNS_12TemplateEnumINS_12pdcomplementELZNS_16complement_namesEELZNS_14COMPLEMENTENUMEEEE", "PatternDriver::StringScalarDeleteValue::StringScalarDeleteValue(PatternDriver::ConflateStringScalarValue const&, PatternDriver::AbstractStringScalarValue const&, PatternDriver::TemplateEnum<PatternDriver::pdcomplement, PatternDriver::complement_names, PatternDriver::COMPLEMENTENUM> const&)"},
{"ALsetchannels", "ALsetchannels"},
{"_Z4makeI7FactoryiET_IT0_Ev", "Factory<int> make<Factory, int>()"},
{"_Z1fM1AKiPKS1_", "f(int const A::*, int const A::* const*)"},
{"_ZSA", "_ZSA"},
{"_ZN1fIL_", "_ZN1fIL_"},
{"_Za", "_Za"},
{"_ZNSA", "_ZNSA"},
{"_ZNT", "_ZNT"},
{"_Z1aMark", "_Z1aMark"},
{"_ZL3foo_2", "foo"},
{"_ZZL3foo_2vE4var1", "foo()::var1"},
{"_ZZL3foo_2vE4var1_0", "foo()::var1"},
{"_ZZN7myspaceL3foo_1EvEN11localstruct1fEZNS_3fooEvE16otherlocalstruct", "myspace::foo()::localstruct::f(myspace::foo()::otherlocalstruct)"},
// Check some names from MFC.
{"?InitWorkspacesCollection@CDaoWorkspace@@IAEXXZ", "CDaoWorkspace::InitWorkspacesCollection(void)"},
{"?Invoke@XEventSink@COleControlSite@@UAGJJABU_GUID@@KGPAUtagDISPPARAMS@@PAUtagVARIANT@@PAUtagEXCEPINFO@@PAI@Z",
"COleControlSite::XEventSink::Invoke(long,struct _GUID const &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)"},
{"?IsNullValue@CDaoFieldExchange@@SGHPAXK@Z", "CDaoFieldExchange::IsNullValue(void *,unsigned long)"},
{"??$?0VQObject@@@?$QWeakPointer@VQObject@@@@AEAA@PEAVQObject@@_N@Z", "QWeakPointer<class QObject>::<class QObject>::<class QObject>(class QObject *,bool)"},
// Check not mangled names
{"__SomeNotMangledName", "__SomeNotMangledName"}
};
size_t i;
for (i = 0; i < _countof(names); i++) {
const std::string actual = DemangleName(names[i].mangled).name();
const char *expected = names[i].demangled;
EXPECT_TRUE(actual.compare(expected) == 0) << actual << std::endl << expected;
}
}
int main(int argc, char **argv)
{
setlocale(LC_ALL, "");
int rc;
#ifdef WIN
/* Set up heap verifying. */
_CrtSetDbgFlag(
_CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF);
#elif MACOSX
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
std::cout << "Unit test application #1\n";
testing::InitGoogleTest(&argc, argv);
rc = RUN_ALL_TESTS();
remove("test.bin");
remove("test1.bin");
remove("test2.bin");
#ifdef MACOSX
[pool release];
#endif
return rc;
}

273
unit-tests/testfile.h Normal file
View File

@ -0,0 +1,273 @@
#ifndef TESTFILE_H
#define TESTFILE_H
template<class TTestConfig> class TestSegmentListT;
template<class TTestConfig>
class TestSegmentT : public TTestConfig::Segment
{
public:
explicit TestSegmentT(typename TTestConfig::SegmentList *owner, uint64_t address, uint32_t size, const char *name, uint32_t type)
: TTestConfig::Segment(owner), address_(address), size_(size), name_(name), type_(type), physical_size_(0), physical_offset_(0) {}
virtual uint64_t address() const { return address_; }
virtual uint64_t size() const { return size_; }
virtual uint32_t physical_offset() const { return physical_offset_; }
virtual uint32_t physical_size() const { return physical_size_; }
virtual std::string name() const { return name_; }
virtual uint32_t memory_type() const { return type_; }
void set_physical_size(uint32_t physical_size) { physical_size_ = physical_size; }
void set_physical_offset(uint32_t physical_offset) { physical_offset_ = physical_offset; }
virtual void update_type(uint32_t mt) { }
virtual uint32_t flags() const { return 0; }
virtual void Rebase(uint64_t delta_base) { address_ += delta_base; }
virtual TestSegmentT<TTestConfig> *Clone(ISectionList *owner) const { return new TestSegmentT<TTestConfig>(dynamic_cast<typename TTestConfig::SegmentList *>(owner), address_, size_, name_.c_str(), type_); }
private:
uint64_t address_;
uint32_t size_;
std::string name_;
uint32_t type_;
uint32_t physical_size_;
uint32_t physical_offset_;
};
template<class TTestConfig>
class TestSegmentListT : public TTestConfig::SegmentList
{
public:
explicit TestSegmentListT(typename TTestConfig::Architecture *owner)
: TTestConfig::SegmentList(owner) {}
TestSegmentT<TTestConfig> *Add(uint64_t address, uint32_t size, const char *name, uint32_t type)
{
TestSegmentT<TTestConfig> *seg = new TestSegmentT<TTestConfig>(this, address, size, name, type);
this->AddObject(seg);
return seg;
}
};
template<class TTestConfig>
class TestExportListT : public TTestConfig::ExportList
{
public:
explicit TestExportListT(typename TTestConfig::Architecture *owner)
: TTestConfig::ExportList(owner) {}
virtual std::string name() const { return ""; }
protected:
virtual typename TTestConfig::Export *Add(uint64_t /*address*/) { return NULL; }
};
template<class TTestConfig>
class TestFixupT : public TTestConfig::Fixup
{
public:
explicit TestFixupT(typename TTestConfig::FixupList *owner);
virtual uint64_t address() const { return 0; }
virtual FixupType type() const { return ftUnknown; }
virtual OperandSize size() const { return osDWord; }
virtual void set_address(uint64_t /*address*/) { return; }
virtual void Rebase(IArchitecture & /*file*/, uint64_t /*delta_base*/) { return; }
virtual TestFixupT<TTestConfig> *Clone(IFixupList *owner) const { return new TestFixupT<TTestConfig>(reinterpret_cast<typename TTestConfig::FixupList *>(owner)); }
};
template<class TTestConfig>
class TestFixupListT : public TTestConfig::FixupList
{
public:
explicit TestFixupListT()
: TTestConfig::FixupList() {}
virtual IFixup *AddDefault(OperandSize /*cpu_address_size*/, bool /*is_code*/)
{
TestFixupT<TTestConfig> *fixup = new TestFixupT<TTestConfig>(this);
this->AddObject(fixup);
return fixup;
}
};
template<class TTestConfig>
class TestImportListT : public TTestConfig::ImportList
{
public:
explicit TestImportListT(typename TTestConfig::Architecture *owner)
: TTestConfig::ImportList(owner) {}
protected:
virtual typename TTestConfig::Import *AddSDK() { return NULL; }
};
class TestMapFile : public MapFile
{
public:
bool ParseEx(const char *file_name, const std::vector<uint64_t> &segments, uint64_t time_stamp)
{
bool res = MapFile::Parse(file_name, segments);
set_time_stamp(time_stamp);
return res;
}
};
template<class TTestConfig>
class TestArchitectureT : public TTestConfig::Architecture
{
public:
explicit TestArchitectureT(typename TTestConfig::File *owner, OperandSize cpu_address_size)
: TTestConfig::Architecture(owner, 0, -1), function_list_(NULL), cpu_address_size_(cpu_address_size), virtual_machine_list_(NULL)
{
segment_list_ = new TestSegmentListT<TTestConfig>(this);
export_list_ = new TestExportListT<TTestConfig>(this);
fixup_list_ = new TestFixupListT<TTestConfig>();
import_list_ = new TestImportListT<TTestConfig>(this);
time_stamp_ = 1;
function_list_ = new typename TTestConfig::FunctionList(this);
runtime_function_list_ = new typename TTestConfig::RuntimeFunctionList();
virtual_machine_list_ = new typename TTestConfig::VirtualMachineList();
}
virtual ~TestArchitectureT()
{
delete segment_list_;
delete export_list_;
delete function_list_;
delete fixup_list_;
delete import_list_;
delete virtual_machine_list_;
delete runtime_function_list_;
};
virtual std::string format_name() const { return "TEST"; }
virtual std::string name() const { return "TEST"; }
virtual uint32_t type() const { return 0; }
virtual OperandSize cpu_address_size() const { return cpu_address_size_; }
virtual uint64_t entry_point() const { return 0; };
virtual uint32_t segment_alignment() const { return 0x1000; }
virtual TestSegmentListT<TTestConfig> *segment_list() const { return segment_list_; }
virtual typename TTestConfig::SectionList *section_list() const { return NULL; }
virtual TestImportListT<TTestConfig> *import_list() const { return import_list_; }
virtual TestExportListT<TTestConfig> *export_list() const { return export_list_; }
virtual TestFixupListT<TTestConfig> *fixup_list() const { return fixup_list_; }
virtual typename TTestConfig::RelocationList *relocation_list() const { return NULL; }
virtual typename TTestConfig::ResourceList *resource_list() const { return NULL; }
virtual IFunctionList *function_list() const { return function_list_; }
virtual IVirtualMachineList *virtual_machine_list() const { return virtual_machine_list_; }
virtual typename TTestConfig::SEHandlerList *seh_handler_list() const { return NULL; }
virtual typename TTestConfig::RuntimeFunctionList *runtime_function_list() const { return runtime_function_list_; }
virtual uint64_t image_base() const { return 0; }
virtual CallingConvention calling_convention() const { return ccStdcall; }
virtual uint64_t time_stamp() const { return time_stamp_; }
void ReadTestMapFile(const char *file_name)
{
TestMapFile map_file;
std::vector<uint64_t> segments;
for (size_t i = 0; i < segment_list()->count(); i++) {
segments.push_back(segment_list()->item(i)->address());
}
if (std::find(segments.begin(), segments.end(), 0) == segments.end())
segments.insert(segments.begin(), 0);
if (map_file.ParseEx(file_name, segments, time_stamp()))
this->ReadMapFile(map_file);
this->map_function_list()->ReadFromFile(*this);
};
virtual void Save(CompileContext & /*c*/)
{
ISection *last_section = segment_list_->item(0);
uint64_t address = AlignValue(last_section->address() + last_section->size(), segment_alignment());
uint64_t pos = this->size();
auto *vmp_section = segment_list_->Add(address, -1, ".vmp", mtReadable | mtExecutable);
vmp_section->set_physical_size(-1);
vmp_section->set_physical_offset(static_cast<uint32_t>(pos));
for (size_t i = 0; i < function_list_->count(); i++) {
function_list_->item(i)->WriteToFile(*this);
}
};
bool Prepare(CompileContext &ctx)
{
ISectionList *seg_list = segment_list();
if (seg_list->count() == 0)
return false;
ISection *section = seg_list->item(seg_list->count() - 1);
ctx.manager->Add(AlignValue(section->address() + section->size(), segment_alignment()), -1, mtReadable | mtExecutable | mtWritable | mtNotPaged);
return true;
};
protected:
virtual bool ReadHeader(uint32_t /*open_mode*/) { return true; }
private:
TestSegmentListT<TTestConfig> *segment_list_;
TestExportListT<TTestConfig> *export_list_;
IFunctionList *function_list_;
TestFixupListT<TTestConfig> *fixup_list_;
TestImportListT<TTestConfig> *import_list_;
OperandSize cpu_address_size_;
IVirtualMachineList *virtual_machine_list_;
typename TTestConfig::RuntimeFunctionList *runtime_function_list_;
uint64_t time_stamp_;
// no copy ctr or assignment op
TestArchitectureT(const TestArchitectureT &);
TestArchitectureT &operator =(const TestArchitectureT &);
};
template<class TTestConfig>
class TestFileT : public TTestConfig::File
{
public:
explicit TestFileT(OperandSize cpu_address_size)
: TTestConfig::File(NULL)
{
Add(cpu_address_size);
}
explicit TestFileT(const typename TTestConfig::File &src, const char *file_name)
: TTestConfig::File(src, file_name) {}
void OpenFromMemory(const void *buf, uint32_t len)
{
this->CloseStream();
this->stream_ = new MemoryStream;
/*size_t res = */this->stream_->Write(buf, len);
ISection *segment = item(0)->segment_list()->item(0);
uint8_t b = 0xcc;
for (size_t i = len; i < segment->physical_size(); i++) {
this->stream_->Write(&b, sizeof(b));
}
typename TTestConfig::FileHelper helper;
helper.Parse(*item(0));
}
TestArchitectureT<TTestConfig> *item(size_t index) const { return reinterpret_cast<TestArchitectureT<TTestConfig> *>(TTestConfig::File::item(index)); }
IArchitecture *Add(OperandSize cpu_address_size)
{
auto arch = new TestArchitectureT<TTestConfig>(this, cpu_address_size);
this->AddObject(arch);
return arch;
}
TestFileT *Clone(const char *file_name) const
{
TestFileT *file = new TestFileT(*this, file_name);
return file;
}
protected:
virtual OpenStatus ReadHeader(uint32_t /*open_mode*/) { return osSuccess; };
virtual IFile *runtime() const { return NULL; }
private:
std::string map_file_name_;
};
class TestLog: public ILog
{
public:
virtual void AddMessage(MessageType /*type*/, IObject * /*sender*/, const std::string & /*message*/) { return; }
virtual void StartProgress(const std::string & /*caption*/, unsigned long long /*max*/) { return; }
virtual void StepProgress(unsigned long long /*value*/ = 1ull, bool /*is_project*/ = false) { return; }
virtual void EndProgress() { return; }
};
#endif

30
unit-tests/testfileil.h Normal file
View File

@ -0,0 +1,30 @@
#include "testfile.h"
struct ILTestConfig
{
typedef ILFunctionList FunctionList;
typedef ILVirtualMachineList VirtualMachineList;
typedef ILFileHelper FileHelper;
typedef NETArchitecture Architecture;
typedef NETRuntimeFunctionList RuntimeFunctionList;
typedef PESegmentList SegmentList;
typedef NETImportList ImportList;
typedef NETExportList ExportList;
typedef BaseFixupList FixupList;
typedef PESegment Segment;
typedef BaseFixup Fixup;
typedef PESectionList SectionList;
typedef IRelocationList RelocationList;
typedef NETResourceList ResourceList;
typedef ISEHandlerList SEHandlerList;
typedef IImport Import;
typedef IExport Export;
typedef PEFile File;
};
typedef TestArchitectureT<ILTestConfig> TestArchitecture;
typedef TestFileT<ILTestConfig> TestFile;
typedef TestSegmentListT<ILTestConfig> TestSegmentList;
typedef TestSegmentT<ILTestConfig> TestSegment;
template<>
inline TestFixupT<ILTestConfig>::TestFixupT(ILTestConfig::FixupList *owner) : ILTestConfig::Fixup(owner) {}

View File

@ -0,0 +1,30 @@
#include "testfile.h"
struct IntelTestConfig
{
typedef IntelFunctionList FunctionList;
typedef IntelVirtualMachineList VirtualMachineList;
typedef IntelFileHelper FileHelper;
typedef PEArchitecture Architecture;
typedef PERuntimeFunctionList RuntimeFunctionList;
typedef PESegmentList SegmentList;
typedef PEImportList ImportList;
typedef PEExportList ExportList;
typedef PEFixupList FixupList;
typedef PESegment Segment;
typedef PEFixup Fixup;
typedef PESectionList SectionList;
typedef PERelocationList RelocationList;
typedef PEResourceList ResourceList;
typedef PESEHandlerList SEHandlerList;
typedef PEImport Import;
typedef PEExport Export;
typedef PEFile File;
};
typedef TestArchitectureT<IntelTestConfig> TestArchitecture;
typedef TestFileT<IntelTestConfig> TestFile;
typedef TestSegmentListT<IntelTestConfig> TestSegmentList;
typedef TestSegmentT<IntelTestConfig> TestSegment;
template<>
inline TestFixupT<IntelTestConfig>::TestFixupT(PEFixupList *owner) : IntelTestConfig::Fixup(owner, 0, ftUnknown) {}