| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- const fs = require('fs');
- // Analyze Cesium.js obfuscation to find the uniform switch-case
- const cesium = fs.readFileSync('public/Cesium/Cesium.js', 'utf8');
- // Find the SAMPLER_3D constant: 'SAMPLER_3D':0x8b5f
- const s3Idx = cesium.indexOf("'SAMPLER_3D':0x8b5f");
- if (s3Idx < 0) {
- console.error('SAMPLER_3D constant not found');
- process.exit(1);
- }
- console.log('SAMPLER_3D constant at byte:', s3Idx);
- console.log('Context:', cesium.substring(Math.max(0, s3Idx - 80), s3Idx + 40));
- // Find the object that contains the WebGL constants
- // Looking backward for the object opening
- const objStart = cesium.lastIndexOf('{', s3Idx - 100);
- console.log('\nObject definition starting at:', objStart);
- console.log('Object start context:', cesium.substring(objStart, Math.min(cesium.length, objStart + 200)));
- // The obfuscated code uses an object like:
- // var _0x... = {'SAMPLER_2D':0x8b5e,'SAMPLER_3D':0x8b5f,'SAMPLER_CUBE':0x8b60,...}
- // This object is assigned to a variable and used in switch cases
- // Find the variable name being assigned
- const varMatch = cesium.substring(Math.max(0, objStart - 100), objStart).match(/var\s+(\w+)\s*=\s*$/);
- if (varMatch) {
- const varName = varMatch[1];
- console.log('\nVariable name:', varName);
-
- // Search for usage of this variable with SAMPLER_2D in a case context
- const searchStr = varName + '.SAMPLER_2D';
- let pos = 0;
- let count = 0;
- const results = [];
- while ((pos = cesium.indexOf(searchStr, pos)) >= 0 && count < 10) {
- results.push(pos);
- pos++;
- count++;
- }
-
- console.log('\nFound', results.length, 'occurrences of', searchStr);
- for (const r of results) {
- const ctx = cesium.substring(Math.max(0, r - 40), Math.min(cesium.length, r + 80));
- console.log(' byte', r, ':', ctx.substring(0, 120));
-
- // Check if this is in a switch-case
- if (ctx.includes('case')) {
- console.log(' *** IN SWITCH CASE ***');
-
- // Check if SAMPLER_3D is also in the same switch
- const switchStart = cesium.lastIndexOf('switch', r);
- if (switchStart >= 0) {
- const blockEnd = cesium.indexOf('}', r);
- const switchBlock = cesium.substring(switchStart, Math.min(cesium.length, blockEnd + 100));
- const hasS3 = switchBlock.includes('SAMPLER_3D');
- console.log(' SAMPLER_3D in same switch:', hasS3);
-
- if (!hasS3) {
- console.log(' *** SAMPLER_3D MISSING! Need to patch here ***');
- // Extract the full case block
- const caseStart = switchBlock.indexOf('case');
- console.log(' Full switch block (first 500 chars):', switchBlock.substring(caseStart, Math.min(switchBlock.length, caseStart + 500)));
- }
- }
- }
- }
- } else {
- console.log('Could not find variable assignment pattern');
-
- // Alternative: search for SAMPLER_2D used in nearby context
- // Try finding by searching for this pattern
- const patterns = ['.SAMPLER_2D', "['SAMPLER_2D']"];
- for (const p of patterns) {
- let pos = 0;
- while ((pos = cesium.indexOf(p, 100000)) >= 0) {
- const ctx = cesium.substring(Math.max(0, pos - 60), Math.min(cesium.length, pos + 80));
- console.log('\nFound', p, 'at byte', pos, ':', ctx.substring(0, 150));
- pos++;
- }
- }
- }
|