开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
标签 (1)
master
v1.0.0
master
分支 (1)
标签 (1)
master
v1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
标签 (1)
master
v1.0.0
pefile_tests.cc 19.87 KB
一键复制 编辑 原始数据 按行查看 历史
java2job 提交于 2023年12月07日 18:08 +08:00 . Initial commit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
#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
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

VMProtect完整版源码。来源:https://bbs.kanxue.com/thread-279796.htm
暂无标签
GPL-3.0
使用 GPL-3.0 开源许可协议
取消

发行版 (1)

全部

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/java2job/vmprotect-source-code.git
git@gitee.com:java2job/vmprotect-source-code.git
java2job
vmprotect-source-code
VMProtect源码_完整版
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /