Apply the obfuscation.
| 638 | |
| 639 | // Apply the obfuscation. |
| 640 | VOID cobf::csym::apply_obfuscation(PBYTE pe_rawf, DWORD strings_off, vector<BYTE>& strings, |
| 641 | vector<shellcode::obfuscated_sym>& symbols) |
| 642 | { |
| 643 | // Check if not obfuscated. |
| 644 | if (!this->obfuscated) return; |
| 645 | |
| 646 | // Build the symbol. |
| 647 | shellcode::obfuscated_sym symbol; |
| 648 | symbol.dll_name = this->dll_rva; |
| 649 | symbol.sym_thnk = this->fth_rva; |
| 650 | |
| 651 | // Test if imported by name. |
| 652 | if (symbol.by_name = this->by_name) |
| 653 | { |
| 654 | // Imported by name. |
| 655 | symbol.sym_info.sym_hash = shellcode::hash_string((PCHAR)this->sym_name.c_str()); |
| 656 | |
| 657 | // Removing the old name. |
| 658 | for (size_t idx = 0; idx < this->sym_name.size() + sizeof(CHAR); idx++) |
| 659 | { |
| 660 | // Randomize it. |
| 661 | pe_rawf[this->name_off + idx] = rand(); |
| 662 | }; |
| 663 | } |
| 664 | // Imported by ordinal. |
| 665 | else symbol.sym_info.sym_ord = this->obf_ord; |
| 666 | |
| 667 | // Calculating the thunk data. |
| 668 | PVOID thunk_data; |
| 669 | if (this->to_name) |
| 670 | { |
| 671 | // Obfuscated to name. |
| 672 | thunk_data = (PVOID)(strings_off + strings.size()); |
| 673 | |
| 674 | // Append a new import by name struct. |
| 675 | strings.push_back(rand()); |
| 676 | strings.push_back(rand()); |
| 677 | strings.insert(strings.end(), this->obf_name.data(), |
| 678 | this->obf_name.data() + this->obf_name.size() + |
| 679 | sizeof(CHAR)); |
| 680 | } |
| 681 | // Obfuscated to ordinal. |
| 682 | else thunk_data = (PVOID)(this->obf_ord | IMAGE_ORDINAL_FLAG); |
| 683 | |
| 684 | // Save the symbol. |
| 685 | symbols.push_back(symbol); |
| 686 | *(PVOID*)&pe_rawf[this->oth_off] = thunk_data; |
| 687 | }; |
| 688 | |
| 689 | // Constructor. |
| 690 | cobf::csym::csym(string sym_name, DWORD dll_rva, DWORD fth_rva, DWORD oth_off, DWORD name_off) |