Class: Hyraft::Compiler::JavaScriptObfuscator
- Inherits:
-
Object
- Object
- Hyraft::Compiler::JavaScriptObfuscator
- Defined in:
- lib/hyraft/compiler/javascript_obfuscator.rb
Class Method Summary collapse
-
.multi_layer_obfuscation(js_code) ⇒ Object
Method 10: Multi-Layer Obfuscation.
-
.split_and_reassemble(js_code, parts: 8) ⇒ Object
Method 4: Split and Reassemble.
Class Method Details
.multi_layer_obfuscation(js_code) ⇒ Object
Method 10: Multi-Layer Obfuscation
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hyraft/compiler/javascript_obfuscator.rb', line 36 def multi_layer_obfuscation(js_code) return '' unless js_code && !js_code.strip.empty? = js_code.dup # Layer 1: Remove comments and extra whitespace = remove_comments_and_whitespace() # Layer 2: Safe variable renaming (EXCLUDE neonPulse) = rename_variables() # Layer 3: String obfuscation = obfuscate_strings() # Layer 4: Number obfuscation = obfuscate_numbers() # Layer 5: Split into chunks and reassemble final_js = split_and_reassemble(, parts: 6) final_js end |
.split_and_reassemble(js_code, parts: 8) ⇒ Object
Method 4: Split and Reassemble
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 |
# File 'lib/hyraft/compiler/javascript_obfuscator.rb', line 9 def split_and_reassemble(js_code, parts: 8) return '' unless js_code && !js_code.strip.empty? # Calculate chunk size chunk_size = (js_code.length.to_f / parts).ceil # Split into chunks chunks = js_code.chars.each_slice(chunk_size).map(&:join) # Convert to JSON for JavaScript array chunks_js = chunks.to_json <<~JAVASCRIPT (function(){ try { var c=#{chunks_js}; var s=c.join(''); var e=document.createElement('script'); e.textContent=s; document.head.appendChild(e); } catch(err) { console.error('Script load failed:', err); } })(); JAVASCRIPT end |