Skip to content

P2: Modernize C++, clean up dead code, add error handling to junk mode - #20

Merged
sondt99 merged 1 commit into
mainfrom
fix/p2-modernize-and-cleanup
Aug 2, 2026
Merged

P2: Modernize C++, clean up dead code, add error handling to junk mode#20
sondt99 merged 1 commit into
mainfrom
fix/p2-modernize-and-cleanup

Conversation

@sondt99

@sondt99 sondt99 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace clock() with std::chrono::steady_clock for accurate wall-clock timing
  • Remove srand() from main() — single seeding point remains in TrampolineInjector
  • Add try/catch to junk code mode — was missing, exceptions crashed the process
  • Check std::getline return values — handle EOF/pipe correctly
  • Rename DetectPEArchitecture to detect_pe_architecture (consistent snake_case)
  • Rename camelCase locals to snake_case throughout main.cpp
  • Remove dead code in cfflattening.h (unused CFF namespace, duplicated BasicBlock struct, unused obfuscatecff_extensions namespace)
  • Add <cstdint> / <climits> includes for INT32_MAX/INT32_MIN used in P0 fix
  • Remove misleading comment ("32-bit right rotation function" on a strcmp)

Changes Made

File Changes
main.cpp C++ modernization, error handling, naming consistency
obfuscatecff.cpp Add <cstdint>/<climits>, remove misleading comment
cfflattening.h Remove dead code (unused namespaces, duplicated struct)

Checklist

  • clock()std::chrono::steady_clock in both modes
  • srand() removed from main() (single seed in TrampolineInjector)
  • try/catch added to mode_trampoline_junkcode()
  • std::getline return values checked (3 locations)
  • std::isdigit called with unsigned char cast
  • DetectPEArchitecturedetect_pe_architecture
  • All camelCase locals in detect function → snake_case
  • #define NOMINMAX removed (now in vcxproj preprocessor defs)
  • is_64_bit initialized to false in junk mode
  • Dead CFF and obfuscatecff_extensions namespaces removed from cfflattening.h
  • Misleading "32-bit right rotation function" comment removed

Test plan

  • Build succeeds in Release|x64
  • CFF mode: obfuscate test binary → verify output
  • Junk mode: obfuscate test binary → verify output
  • Junk mode error handling: test with invalid path → verify error message (no crash)
  • Run match_check.py on full test suite

Closes #9, Closes #11

Issue #9 — C++ modernization (partial):
- Replace clock()/CLOCKS_PER_SEC with std::chrono::steady_clock
- Remove #define NOMINMAX (now in vcxproj preprocessor defs)
- Remove srand() from main() (kept in TrampolineInjector constructor)
- Cast to unsigned char for std::isdigit (avoid UB with signed char)
- Add #include <cstdint> and <climits> for INT32_MAX/INT32_MIN

Issue #11 — main.cpp cleanup:
- Rename DetectPEArchitecture → detect_pe_architecture (snake_case)
- Rename camelCase locals to snake_case (filePath→file_path, etc.)
- Add try/catch to junk code mode (was unprotected)
- Check std::getline return values (handle EOF/error)
- Initialize is_64_bit to false in junk code mode
- Remove redundant peFile.close() calls (RAII handles it)
- Remove misleading comment ("32-bit right rotation function" on strcmp)
- Rename print_execution_time → print_elapsed_time

Clean up dead code:
- Remove unused CFF namespace and obfuscatecff_extensions from
  cfflattening.h (duplicated BasicBlock struct, never-used declarations)

Closes #9, Closes #11
@sondt99
sondt99 merged commit bcfa84f into main Aug 2, 2026
1 check passed
@sondt99
sondt99 deleted the fix/p2-modernize-and-cleanup branch August 2, 2026 10:10
sondt99 added a commit that referenced this pull request Aug 10, 2026
P2: Modernize C++, clean up dead code, add error handling to junk mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant