Spaces:
webzepetoku
/
Sleeping

webzepetoku commited on
Commit
ecde384
·
verified ·
1 Parent(s): dd93e57

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +78 -49
server.js CHANGED
@@ -1,42 +1,43 @@
1
  const express = require('express');
2
  const bodyParser = require('body-parser');
3
  const axios = require('axios');
 
4
  const path = require('path');
5
  const fs = require('fs');
6
- const AdmZip = require('adm-zip');
7
 
8
  const app = express();
9
  app.use(bodyParser.json({ limit: '100mb' }));
10
 
11
- // File pancingan Bos
12
  const DUMMY_ZIP = 'dummy_lite.zepeto.zip';
 
 
13
 
14
  if (!fs.existsSync('uploads')) fs.mkdirSync('uploads', { recursive: true });
15
 
16
- // Fungsi untuk membungkus ulang folder menjadi file ZEPETO
17
- function zipDirectory(sourceDir, outPath) {
18
- const zip = new AdmZip();
19
- zip.addLocalFolder(sourceDir);
20
- zip.writeZip(outPath);
21
- }
22
-
23
- // Fungsi untuk menyalin folder beserta seluruh isinya secara utuh
24
- function copyFolderSync(from, to) {
25
- if (!fs.existsSync(to)) fs.mkdirSync(to, { recursive: true });
26
- fs.readdirSync(from).forEach(element => {
27
- if (fs.lstatSync(path.join(from, element)).isFile()) {
28
- fs.copyFileSync(path.join(from, element), path.join(to, element));
29
  } else {
30
- copyFolderSync(path.join(from, element), path.join(to, element));
 
 
 
 
31
  }
32
- });
 
33
  }
34
 
35
  app.post('/convert', async (req, res) => {
36
  const { file_url, filename } = req.body;
37
  const logs = [];
38
 
39
- logs.push(`[INIT] Memulai request Folder Swap untuk: ${filename || 'result.zepeto'}`);
40
 
41
  if (!file_url) return res.status(400).json({ error: "file_url is required", step_logs: logs });
42
 
@@ -44,58 +45,86 @@ app.post('/convert', async (req, res) => {
44
  const tempHighPoly = path.join(__dirname, 'uploads', `hp_${timeId}.zepeto`);
45
  const tempOutput = path.join(__dirname, 'uploads', filename || `out_${timeId}.zepeto`);
46
 
47
- // Ruang ekstraksi
48
  const extractDummyPath = path.join(__dirname, 'uploads', `ext_dummy_${timeId}`);
49
  const extractHpPath = path.join(__dirname, 'uploads', `ext_hp_${timeId}`);
 
 
 
50
 
51
  try {
52
- logs.push(`[STEP 1] Membuka cangkang pancingan (${DUMMY_ZIP})...`);
53
- const zipDummy = new AdmZip(DUMMY_ZIP);
54
- zipDummy.extractAllTo(extractDummyPath, true);
55
-
56
- logs.push(`[STEP 2] Download file Zepeto Raksasa 18MB...`);
57
  const response = await axios({ method: 'GET', url: file_url, responseType: 'stream' });
58
  const writer = fs.createWriteStream(tempHighPoly);
59
  response.data.pipe(writer);
60
 
61
  writer.on('finish', () => {
62
- logs.push(`[STEP 3] Membuka file Zepeto Raksasa...`);
63
  try {
64
- const zipHp = new AdmZip(tempHighPoly);
65
- zipHp.extractAllTo(extractHpPath, true);
66
-
67
- logs.push(`[STEP 4] Mengeksekusi Swap File (Menukar isi tanpa merusak biner)...`);
68
- const dummyAssetBundles = path.join(extractDummyPath, 'assetbundles');
69
- const hpAssetBundles = path.join(extractHpPath, 'assetbundles');
70
-
71
- // 1. Hapus isi aset bawaan Dummy
72
- if (fs.existsSync(dummyAssetBundles)) {
73
- fs.rmSync(dummyAssetBundles, { recursive: true, force: true });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
 
76
- // 2. Masukkan seluruh aset High-Poly (18MB) bulat-bulat ke dalam Dummy
77
- copyFolderSync(hpAssetBundles, dummyAssetBundles);
78
-
79
- logs.push(`[STEP 5] Membungkus kembali menjadi file ZEPETO siap upload...`);
80
- zipDirectory(extractDummyPath, tempOutput);
81
 
82
  if (fs.existsSync(tempOutput)) {
83
- logs.push(`[SUCCESS] File Bypass siap dikirim!`);
84
  res.download(tempOutput, filename || 'result.zepeto', () => {
85
- // Bersihkan server setelah sukses
86
  try {
87
- fs.rmSync(extractDummyPath, { recursive: true, force: true });
88
- fs.rmSync(extractHpPath, { recursive: true, force: true });
89
- fs.unlinkSync(tempHighPoly);
90
- fs.unlinkSync(tempOutput);
91
  } catch (e) {}
92
  });
93
  } else {
94
- throw new Error("Gagal membungkus file hasil modifikasi.");
95
  }
96
 
97
  } catch (extErr) {
98
- logs.push(`[CRASH EXTRACT] ${extErr.message}`);
99
  res.status(500).json({ error: extErr.message, step_logs: logs });
100
  }
101
  });
@@ -107,4 +136,4 @@ app.post('/convert', async (req, res) => {
107
  });
108
 
109
  const PORT = 7860;
110
- app.listen(PORT, () => console.log(`🚀 API Swap File (Zero Surgery) Aktif di Port ${PORT}`));
 
1
  const express = require('express');
2
  const bodyParser = require('body-parser');
3
  const axios = require('axios');
4
+ const { execSync } = require('child_process');
5
  const path = require('path');
6
  const fs = require('fs');
 
7
 
8
  const app = express();
9
  app.use(bodyParser.json({ limit: '100mb' }));
10
 
 
11
  const DUMMY_ZIP = 'dummy_lite.zepeto.zip';
12
+ const UABEA_BIN = './tools/UABEAvalonia';
13
+ const TPK_PATH = './tools/classdata.tpk';
14
 
15
  if (!fs.existsSync('uploads')) fs.mkdirSync('uploads', { recursive: true });
16
 
17
+ // Fungsi sakti untuk mencari semua file biner Unity
18
+ function findAllBundles(dir) {
19
+ let results = [];
20
+ const files = fs.readdirSync(dir);
21
+ for (const file of files) {
22
+ const fullPath = path.join(dir, file);
23
+ if (fs.lstatSync(fullPath).isDirectory()) {
24
+ results = results.concat(findAllBundles(fullPath));
 
 
 
 
 
25
  } else {
26
+ const ext = path.extname(file).toLowerCase();
27
+ const stats = fs.statSync(fullPath);
28
+ if (!['.json', '.xml', '.manifest', '.txt', '.meta', '.prefab', '.png'].includes(ext) && stats.size > 100) {
29
+ results.push(fullPath);
30
+ }
31
  }
32
+ }
33
+ return results;
34
  }
35
 
36
  app.post('/convert', async (req, res) => {
37
  const { file_url, filename } = req.body;
38
  const logs = [];
39
 
40
+ logs.push(`[INIT] Misi UABEA Repacking untuk: ${filename || 'result.zepeto'}`);
41
 
42
  if (!file_url) return res.status(400).json({ error: "file_url is required", step_logs: logs });
43
 
 
45
  const tempHighPoly = path.join(__dirname, 'uploads', `hp_${timeId}.zepeto`);
46
  const tempOutput = path.join(__dirname, 'uploads', filename || `out_${timeId}.zepeto`);
47
 
 
48
  const extractDummyPath = path.join(__dirname, 'uploads', `ext_dummy_${timeId}`);
49
  const extractHpPath = path.join(__dirname, 'uploads', `ext_hp_${timeId}`);
50
+
51
+ const meshDat = path.join(__dirname, 'uploads', `mesh_${timeId}.dat`);
52
+ const texDat = path.join(__dirname, 'uploads', `tex_${timeId}.dat`);
53
 
54
  try {
55
+ logs.push(`[STEP 1] Download file Raksasa...`);
 
 
 
 
56
  const response = await axios({ method: 'GET', url: file_url, responseType: 'stream' });
57
  const writer = fs.createWriteStream(tempHighPoly);
58
  response.data.pipe(writer);
59
 
60
  writer.on('finish', () => {
 
61
  try {
62
+ logs.push(`[STEP 2] Unzip Native Anti-Korup...`);
63
+ fs.mkdirSync(extractDummyPath, { recursive: true });
64
+ fs.mkdirSync(extractHpPath, { recursive: true });
65
+
66
+ execSync(`unzip -q -o "${DUMMY_ZIP}" -d "${extractDummyPath}"`);
67
+ execSync(`unzip -q -o "${tempHighPoly}" -d "${extractHpPath}"`);
68
+
69
+ logs.push(`[STEP 3] Memulai Operasi UABEA pada Biner...`);
70
+ const dummyBundles = findAllBundles(path.join(extractDummyPath, 'assetbundles'));
71
+ const hpBundles = findAllBundles(path.join(extractHpPath, 'assetbundles'));
72
+
73
+ for (const dummyBndl of dummyBundles) {
74
+ const bndlName = path.basename(dummyBndl);
75
+ const hpBndl = hpBundles.find(b => path.basename(b) === bndlName);
76
+
77
+ if (hpBndl) {
78
+ logs.push(`[UABEA] Memproses pasangan biner: ${bndlName}`);
79
+
80
+ // 1. Python ekstrak data mentah
81
+ execSync(`python3 extractor.py extract "${hpBndl}" "${meshDat}" "${texDat}"`);
82
+
83
+ // 2. Python cari ID di Dummy
84
+ const idsOutput = execSync(`python3 extractor.py find_id "${dummyBndl}"`).toString();
85
+ const match = idsOutput.match(/IDS:(\w+),(\w+)/);
86
+
87
+ if (match) {
88
+ const meshId = match[1];
89
+ const texId = match[2];
90
+
91
+ // 3. UABEA Eksekusi Packing Mesh
92
+ if (meshId !== 'NONE' && fs.existsSync(meshDat)) {
93
+ logs.push(`[UABEA] Packing Mesh ke ${bndlName} (ID: ${meshId})...`);
94
+ const tmpM = dummyBndl + '_m';
95
+ execSync(`xvfb-run -a ${UABEA_BIN} mod "${dummyBndl}" "${tmpM}" -p ${TPK_PATH} -replace ${meshId} "${meshDat}"`);
96
+ fs.copyFileSync(tmpM, dummyBndl);
97
+ fs.unlinkSync(tmpM);
98
+ }
99
+
100
+ // 4. UABEA Eksekusi Packing Texture
101
+ if (texId !== 'NONE' && fs.existsSync(texDat)) {
102
+ logs.push(`[UABEA] Packing Texture ke ${bndlName} (ID: ${texId})...`);
103
+ const tmpT = dummyBndl + '_t';
104
+ execSync(`xvfb-run -a ${UABEA_BIN} mod "${dummyBndl}" "${tmpT}" -p ${TPK_PATH} -replace ${texId} "${texDat}"`);
105
+ fs.copyFileSync(tmpT, dummyBndl);
106
+ fs.unlinkSync(tmpT);
107
+ }
108
+ }
109
+ }
110
  }
111
 
112
+ logs.push(`[STEP 4] Membungkus ulang menggunakan NATIVE ZIP...`);
113
+ execSync(`cd "${extractDummyPath}" && zip -q -r "${tempOutput}" *`);
 
 
 
114
 
115
  if (fs.existsSync(tempOutput)) {
116
+ logs.push(`[SUCCESS] File Bypass UABEA siap dikirim!`);
117
  res.download(tempOutput, filename || 'result.zepeto', () => {
 
118
  try {
119
+ execSync(`rm -rf "${extractDummyPath}" "${extractHpPath}" "${tempHighPoly}" "${tempOutput}" "${meshDat}" "${texDat}"`);
 
 
 
120
  } catch (e) {}
121
  });
122
  } else {
123
+ throw new Error("Gagal membuat file output zip.");
124
  }
125
 
126
  } catch (extErr) {
127
+ logs.push(`[CRASH] ${extErr.message}`);
128
  res.status(500).json({ error: extErr.message, step_logs: logs });
129
  }
130
  });
 
136
  });
137
 
138
  const PORT = 7860;
139
+ app.listen(PORT, () => console.log(`🚀 API UABEA Repacker Aktif di Port ${PORT}`));