-
Notifications
You must be signed in to change notification settings - Fork 1
/
DEXectractor.html
154 lines (135 loc) · 5.07 KB
/
DEXectractor.html
1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>dexstrings Analyzer</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
#output {
width: 100%;
height: 300px;
white-space: pre;
border: 1px solid #ddd;
padding: 10px;
margin-top: 10px;
font-family: monospace;
}
button {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>dexstrings Analyzer</h1>
v.1.0.0<br>
<br>
ChatGPT port to Javascript from <a href="https://github.com/hugo-glez/dexstrings">original C source</a> by <a href="https://github.com/hugo-glez/">Hugo Gonzalez</a><br>
You have to manually extract a .dex file from .apk files (which is just a renamed .zip file) and load it into this page to see all human-readable strings.<br>
<input type="file" id="dexFile" accept=".dex">
<br><br>
<button onclick="analyzeDex()">Analyze .dex File</button>
<textarea id="output" readonly></textarea>
<br>
<button onclick="copyToClipboard()">Copy to Clipboard</button>
<script>
function utf8len(str) {
let len = 0;
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
if (code <= 0x7F) len++;
else if (code <= 0x7FF) len += 2;
else if (code <= 0xFFFF) len += 3;
else len += 4;
}
return len;
}
function isValidString(stringData) {
for (let i = 0; i < stringData.length; i++) {
const code = stringData.charCodeAt(i);
if (code < 0 || code > 127 || stringData[i] === ' ') {
return false;
}
}
return true;
}
function formatNumber(num, length) {
return num.toString().padStart(length, '0');
}
function printStrings2(dataView, offset, iSize, iUnicode) {
let idx = offset;
let result = dataView.getUint8(idx++);
if (result > 0x7f) {
let cur = dataView.getUint8(idx++);
result = (result & 0x7f) | ((cur & 0x7f) << 7);
if (cur > 0x7f) {
cur = dataView.getUint8(idx++);
result |= (cur & 0x7f) << 14;
if (cur > 0x7f) {
cur = dataView.getUint8(idx++);
result |= (cur & 0x7f) << 21;
if (cur > 0x7f) {
cur = dataView.getUint8(idx++);
result |= cur << 28;
}
}
}
}
let stringData = "";
for (let i = 0; i < result; i++) {
stringData += String.fromCharCode(dataView.getUint8(idx + i));
}
if (!isValidString(stringData)) {
return '';
}
const unicodelen = utf8len(stringData);
let output = `${offset.toString(16)} | `;
if (iSize) {
output += `${formatNumber(result, 3)} | ${formatNumber(unicodelen, 3)} | `;
}
if (iUnicode) {
output += (result != unicodelen ? "_U_ |" : " |");
}
output += `${stringData}\n`;
return output;
}
function analyzeDex() {
const fileInput = document.getElementById('dexFile');
const outputTextarea = document.getElementById('output');
outputTextarea.value = "";
if (!fileInput.files.length) {
alert("Please select a .dex file.");
return;
}
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(event) {
const arrayBuffer = event.target.result;
const dataView = new DataView(arrayBuffer);
let output = "=== dexstrings 0.8 - (c) 2015 Hugo Gonzalez @hugo_glez\n";
output += "Dex file: " + file.name + "\n";
output += "======================\n";
const stringIdsSize = dataView.getUint32(56, true);
const stringIdsOff = dataView.getUint32(60, true);
for (let i = 0; i < stringIdsSize; i++) {
const stringIdOff = stringIdsOff + i * 4;
const stringDataOff = dataView.getUint32(stringIdOff, true);
const result = printStrings2(dataView, stringDataOff, 1, 1);
if (result) {
output += result;
}
}
outputTextarea.value = output;
};
reader.readAsArrayBuffer(file);
}
function copyToClipboard() {
const outputTextarea = document.getElementById('output');
outputTextarea.select();
document.execCommand('copy');
}
</script>
</body>
</html>