analyze_cesium_obfuscation.cjs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const fs = require('fs');
  2. // Analyze Cesium.js obfuscation to find the uniform switch-case
  3. const cesium = fs.readFileSync('public/Cesium/Cesium.js', 'utf8');
  4. // Find the SAMPLER_3D constant: 'SAMPLER_3D':0x8b5f
  5. const s3Idx = cesium.indexOf("'SAMPLER_3D':0x8b5f");
  6. if (s3Idx < 0) {
  7. console.error('SAMPLER_3D constant not found');
  8. process.exit(1);
  9. }
  10. console.log('SAMPLER_3D constant at byte:', s3Idx);
  11. console.log('Context:', cesium.substring(Math.max(0, s3Idx - 80), s3Idx + 40));
  12. // Find the object that contains the WebGL constants
  13. // Looking backward for the object opening
  14. const objStart = cesium.lastIndexOf('{', s3Idx - 100);
  15. console.log('\nObject definition starting at:', objStart);
  16. console.log('Object start context:', cesium.substring(objStart, Math.min(cesium.length, objStart + 200)));
  17. // The obfuscated code uses an object like:
  18. // var _0x... = {'SAMPLER_2D':0x8b5e,'SAMPLER_3D':0x8b5f,'SAMPLER_CUBE':0x8b60,...}
  19. // This object is assigned to a variable and used in switch cases
  20. // Find the variable name being assigned
  21. const varMatch = cesium.substring(Math.max(0, objStart - 100), objStart).match(/var\s+(\w+)\s*=\s*$/);
  22. if (varMatch) {
  23. const varName = varMatch[1];
  24. console.log('\nVariable name:', varName);
  25. // Search for usage of this variable with SAMPLER_2D in a case context
  26. const searchStr = varName + '.SAMPLER_2D';
  27. let pos = 0;
  28. let count = 0;
  29. const results = [];
  30. while ((pos = cesium.indexOf(searchStr, pos)) >= 0 && count < 10) {
  31. results.push(pos);
  32. pos++;
  33. count++;
  34. }
  35. console.log('\nFound', results.length, 'occurrences of', searchStr);
  36. for (const r of results) {
  37. const ctx = cesium.substring(Math.max(0, r - 40), Math.min(cesium.length, r + 80));
  38. console.log(' byte', r, ':', ctx.substring(0, 120));
  39. // Check if this is in a switch-case
  40. if (ctx.includes('case')) {
  41. console.log(' *** IN SWITCH CASE ***');
  42. // Check if SAMPLER_3D is also in the same switch
  43. const switchStart = cesium.lastIndexOf('switch', r);
  44. if (switchStart >= 0) {
  45. const blockEnd = cesium.indexOf('}', r);
  46. const switchBlock = cesium.substring(switchStart, Math.min(cesium.length, blockEnd + 100));
  47. const hasS3 = switchBlock.includes('SAMPLER_3D');
  48. console.log(' SAMPLER_3D in same switch:', hasS3);
  49. if (!hasS3) {
  50. console.log(' *** SAMPLER_3D MISSING! Need to patch here ***');
  51. // Extract the full case block
  52. const caseStart = switchBlock.indexOf('case');
  53. console.log(' Full switch block (first 500 chars):', switchBlock.substring(caseStart, Math.min(switchBlock.length, caseStart + 500)));
  54. }
  55. }
  56. }
  57. }
  58. } else {
  59. console.log('Could not find variable assignment pattern');
  60. // Alternative: search for SAMPLER_2D used in nearby context
  61. // Try finding by searching for this pattern
  62. const patterns = ['.SAMPLER_2D', "['SAMPLER_2D']"];
  63. for (const p of patterns) {
  64. let pos = 0;
  65. while ((pos = cesium.indexOf(p, 100000)) >= 0) {
  66. const ctx = cesium.substring(Math.max(0, pos - 60), Math.min(cesium.length, pos + 80));
  67. console.log('\nFound', p, 'at byte', pos, ':', ctx.substring(0, 150));
  68. pos++;
  69. }
  70. }
  71. }