-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathindex.html
More file actions
530 lines (455 loc) · 20.2 KB
/
Copy pathindex.html
File metadata and controls
530 lines (455 loc) · 20.2 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>VTable Dumper</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<style type="text/css">
code { background-color: transparent; }
.steam-game-button-controls { opacity: 0; transition: opacity 0.2s; }
.steam-game-button-controls:hover { opacity: 1; }
/*tr>:first-child { border-top-left-radius: 5px; border-bottom-left-radius: 5px; }
tr>:last-child { border-top-right-radius: 5px; border-bottom-right-radius: 5px; }*/
.table-borderless>tbody>tr>td, .table-borderless>tbody>tr>th, .table-borderless>tfoot>tr>td, .table-borderless>tfoot>tr>th, .table-borderless>thead>tr>td, .table-borderless>thead>tr>th { border-top: none; }
.table>tbody+tbody { border-top: none; }
</style>
</head>
<body>
<div id="content" class="container"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.28.3/react-bootstrap.js"></script>
<script type="text/babel">
const { Row, Col, Image, ButtonToolbar, Button, ProgressBar, Tooltip, OverlayTrigger, Input, Nav, NavItem, Table, Alert } = ReactBootstrap;
var stateManager = null;
var worker = new Worker('worker.js');
worker.onmessage = (event) => {
if (event.data.loaded || event.data.total) {
stateManager.setState({ binaryProcessingProgress: event.data });
} else {
for (var i = 0; i < event.data.functions.length; ++i) {
var fun = event.data.functions[i];
for (var j = 0; j < fun.classes.length; ++j) {
var classIndex = fun.classes[j];
fun.classes[j] = event.data.classes[classIndex];
}
}
stateManager.setState({ programInfo: event.data });
}
};
window.ondragenter = (event) => {
event.stopPropagation();
event.preventDefault();
};
window.ondragover = (event) => {
event.stopPropagation();
event.preventDefault();
};
window.ondrop = (event) => {
event.stopPropagation();
event.preventDefault();
if (!event.dataTransfer.files || event.dataTransfer.files.length < 1) {
return;
}
var file = event.dataTransfer.files[0];
// TODO: This is a hack, find an alternative.
var gameList = stateManager.state.gameList;
stateManager.state = { gameList: gameList, selectedBinary: file.name, binaryDownloadProgress: { loaded: 0, total: 0 } };
stateManager.forceUpdate();
var fileReader = new FileReader();
fileReader.addEventListener('progress', (event) => {
stateManager.setState({ binaryDownloadProgress: { loaded: event.loaded, total: event.total } });
});
fileReader.addEventListener('load', (event) => {
stateManager.setState({ binary: event.target.result, binaryProcessingProgress: { loaded: 0, total: 0 } });
worker.postMessage(event.target.result, [event.target.result]);
});
fileReader.readAsArrayBuffer(file);
};
const Icon = (props) =>
<i
className={'fa fa-'+props.type+(props.spin ? ' fa-spin' : '')}
style={{
fontSize: (props.size || undefined),
verticalAlign: (props.middle ? 'middle' : undefined),
}}
/>;
const FooterLink = (props) =>
<a href={props.href} target="_blank" className="text-muted">{props.children}</a>
const handleSteamGameButtonClick = (game, binary, event) => {
stateManager.setState({ selectedBinary: (game+' '+binary.type+' binary'), binaryDownloadProgress: { loaded: 0, total: 0 } });
var xhr = new XMLHttpRequest();
xhr.addEventListener('progress', (event) => {
stateManager.setState({ binaryDownloadProgress: { loaded: event.loaded, total: event.total } });
});
xhr.addEventListener('load', (event) => {
stateManager.setState({ binary: xhr.response, binaryProcessingProgress: { loaded: 0, total: 0 } });
worker.postMessage(xhr.response, [xhr.response]);
});
xhr.open('GET', stateManager.state.gameList.base + binary.path);
xhr.responseType = 'arraybuffer';
xhr.send();
}
const SteamGameButton = (props) =>
<Col xs={6} sm={4} className="text-center" style={{ position: 'relative' }}>
<Image
rounded responsive
style={{ marginTop: 0, marginLeft: 'auto', marginBottom: 30, marginRight: 'auto' }}
src={'https://steamcdn-a.akamaihd.net/steam/apps/' + props.game.appid + '/header.jpg'}
alt={props.game.name}
/>
<div className="steam-game-button-controls" style={{
position: 'absolute', top: 0, left: 15, bottom: 30, right: 15,
backgroundColor: 'rgba(255, 255, 255, 0.85)',
border: '1px solid #ccc', borderRadius: 5,
display: 'flex', alignItems: 'center', justifyContent: 'center',
}}>
<ButtonToolbar>
{props.game.bins.map((binary) =>
<Button
key={binary.type} bsSize="large"
onClick={handleSteamGameButtonClick.bind(null, props.game.name, binary)}
>
<Icon type={
(binary.type === 'Engine') ? 'tachometer' :
(binary.type === 'Server') ? 'server' :
'question-circle'
} size="2em" /><br/>{binary.type}
</Button>
)}
</ButtonToolbar>
</div>
</Col>
const startHelpText =
<span>Pick a <Icon type="steam" middle /> game or drop a <code>.so</code> file to start.</span>;
const handleRestartButtonClick = (event) => {
// TODO: This is a hack, find an alternative (some kind of state history?)
var gameList = stateManager.state.gameList;
stateManager.state = { gameList: gameList };
stateManager.forceUpdate();
}
const restartButtonTooltip =
<Tooltip id="tooltip-restart">Start Again</Tooltip>;
const restartButton =
<span style={{ position: 'absolute', marginLeft: -36 }}>
<OverlayTrigger placement="bottom" overlay={restartButtonTooltip}>
<Button bsSize="xsmall" onClick={handleRestartButtonClick}>
<Icon type="undo" />
</Button>
</OverlayTrigger>
</span>;
const handlePickNewSymbolButtonClick = (event) => {
stateManager.setState({
selectedClass: null,
selectedFunction: null,
});
}
const pickNewSymbolButtonTooltip =
<Tooltip id="tooltip-picknew">Pick a Different Symbol</Tooltip>;
const pickNewSymbolButton =
<span style={{ position: 'absolute', marginLeft: -60 }}>
<OverlayTrigger placement="bottom" overlay={pickNewSymbolButtonTooltip}>
<Button bsSize="xsmall" onClick={handlePickNewSymbolButtonClick}>
<Icon type="arrow-left" />
</Button>
</OverlayTrigger>
</span>;
const multiIconTooltip =
<Tooltip id="tooltip-multi">This function has been de‑duplicated by the compiler, the name may be incorrect</Tooltip>;
const multiIcon =
<span style={{ position: 'absolute', marginLeft: '0.25em' }}>
<OverlayTrigger placement="right" overlay={multiIconTooltip}>
<div>
<Icon type="copy" />
</div>
</OverlayTrigger>
</span>;
const Layout = (props) =>
<div className="text-center">
<div className="page-header">
<h1>{props.showPickNewSymbolButton && pickNewSymbolButton}{props.showRestartButton && restartButton}VTable Dumper</h1>
<p className="lead">{props.title}</p>
</div>
<div className="page-header">
{props.children}
</div>
<div className="text-muted text-lowercase" style={{ marginBottom: 20 }}>
Made with <Icon type="heart" middle size="50%" /> by <FooterLink href="https://limetech.io">asherkin</FooterLink> <Icon type="circle" middle size="33%" /> Powered by <FooterLink href="http://emscripten.org">Emscripten</FooterLink> & <FooterLink href="http://www.mr511.de/software/english.html">libelf</FooterLink><br/>
<small><FooterLink href="https://github.com/asherkin/vtable">I am Free Software, Fork me on GitHub</FooterLink></small>
</div>
</div>;
const LoadingGameList = (props) =>
<Layout title={startHelpText}>
<div style={{ fontSize: 100, marginBottom: 30 }}>
<Icon type="circle-o-notch" spin />
</div>
</Layout>;
const PickAGame = (props) => {
return <Layout title={startHelpText}>
<Row>
{props.gameList.games.map((game) =>
<SteamGameButton key={game.appid} game={game} />
)}
</Row>
</Layout>;
};
const DownloadingBinary = (props) => {
var helpText = <span>Downloading <Icon type="cloud-download" /> {props.binary}...</span>;
return <Layout title={helpText}>
<ProgressBar style={{ marginBottom: 30, height: 46 }} now={props.loaded} max={props.total} striped active />
</Layout>;
};
const ProcessingBinary = (props) => {
var helpText = <span>Processing <Icon type="cogs" /> {props.binary}...</span>;
return <Layout title={helpText}>
<ProgressBar style={{ marginBottom: 30, height: 46 }} now={props.loaded} max={props.total} striped active />
</Layout>;
};
const handleSymbolSearchChange = (programInfo, event) => {
var lowercaseQuery = event.target.value.toLowerCase();
var queryResults = [];
if (lowercaseQuery.length > 0) {
const filterFunction = (value) => value.searchKey.indexOf(lowercaseQuery) !== -1;
const sortFunction = (a, b) => a.name.length - b.name.length;
queryResults = programInfo.classes
.filter(filterFunction)
.sort(sortFunction)
.slice(0, 10);
if (queryResults.length < 10) {
Array.prototype.push.apply(queryResults, programInfo.functions
.filter(filterFunction)
.sort(sortFunction)
.slice(0, 10 - queryResults.length));
}
}
stateManager.setState({
symbolQueryString: event.target.value,
symbolQueryResults: queryResults,
});
};
const handleClassSymbolClick = (selectedClass, event) => {
stateManager.setState({
selectedClass: selectedClass,
});
};
const handleFunctionSymbolClick = (selectedFunction, event) => {
var newState = {
selectedFunction: selectedFunction,
};
// If this function is only in one class, just select that one.
if (selectedFunction.classes.length === 1) {
newState.selectedClass = selectedFunction.classes[0];
}
stateManager.setState(newState);
};
const PickASymbol = (props) => {
var errorText = <span>Whoops, looks like there was a <Icon type="exclamation-triangle" /> problem.</span>;
var helpText = <span>What are you <Icon type="search" /> looking for today?</span>;
if (props.programInfo.error)
return <Layout title={errorText}>
<div style={{ fontSize: '2em', marginBottom: 30 }}>
{props.programInfo.error}<br/>
<Button bsStyle="primary" onClick={handleRestartButtonClick}>
<Icon type="undo" /> Try Again
</Button>
</div>
</Layout>;
else
return <Layout title={helpText} showRestartButton>
<Input
type="text"
bsSize="large"
className="text-center"
placeholder="Enter a class or function name ..."
onChange={handleSymbolSearchChange.bind(null, props.programInfo)}
value={props.searchQuery}
spellCheck="false"
/>
<Nav bsStyle="pills" stacked style={{ marginBottom: 15 }}>
{props.searchResults.map((symbol) =>
<NavItem key={symbol.id} onClick={
(symbol.vtables ? handleClassSymbolClick : handleFunctionSymbolClick).bind(null, symbol)
}>
<code>{symbol.name}</code>
</NavItem>
)}
</Nav>
</Layout>;
};
const DisambiguateSymbol = (props) => {
var helpText = <span>Hmm, that function exists in <Icon type="code-fork" /> multiple classes.</span>;
return <Layout title={helpText} showRestartButton showPickNewSymbolButton>
<Nav bsStyle="pills" stacked style={{ marginBottom: 30 }}>
{props.selectedFunction.classes.slice().sort((a, b) => a.name.length - b.name.length).map((symbol) =>
<NavItem key={symbol.id} onClick={
handleClassSymbolClick.bind(null, symbol)
}>
<code>{symbol.name}</code>
</NavItem>
)}
</Nav>
</Layout>;
};
function shouldSkipWindowsFunction(classInfo, vtableIndex, functionIndex, functionInfo) {
return (
functionInfo.name.indexOf('::~') !== -1
) ? (
functionIndex > 0 &&
functionInfo.name === classInfo.vtables[vtableIndex].functions[functionIndex - 1].name
) : (
classInfo.vtables.find((d, n) => (
n > vtableIndex &&
d.functions.find((d) => (
d.isThunk &&
functionInfo.name === d.name
))
))
);
}
function formatVTable(classInfo) {
var out = [];
var vtableIndex = 0;
var vtableInfo = classInfo.vtables[vtableIndex];
var windowsIndex = 0;
for (var linuxIndex = 0; linuxIndex < vtableInfo.functions.length; ++linuxIndex) {
var functionInfo = vtableInfo.functions[linuxIndex];
var displayWindowsIndex = windowsIndex;
if (shouldSkipWindowsFunction(classInfo, vtableIndex, linuxIndex, functionInfo)) {
displayWindowsIndex = null;
} else {
if (functionInfo.symbol && !functionInfo.isMulti) {
var previousOverloads = 0;
var remainingOverloads = 0;
while ((linuxIndex - (1 + previousOverloads)) >= 0) {
var previousFunctionIndex = linuxIndex - (1 + previousOverloads);
var previousFunctionInfo = vtableInfo.functions[previousFunctionIndex];
if (!functionInfo.symbol || shouldSkipWindowsFunction(classInfo, vtableIndex, previousFunctionIndex, previousFunctionInfo)) {
break;
}
if (functionInfo.shortName !== previousFunctionInfo.shortName) {
break;
}
previousOverloads++;
}
while ((linuxIndex + 1 + remainingOverloads) < vtableInfo.functions.length) {
var nextFunctionIndex = linuxIndex + 1 + remainingOverloads;
var nextFunctionInfo = vtableInfo.functions[nextFunctionIndex];
if (!functionInfo.symbol || shouldSkipWindowsFunction(classInfo, vtableIndex, nextFunctionIndex, nextFunctionInfo)) {
break;
}
if (functionInfo.shortName !== nextFunctionInfo.shortName) {
break;
}
remainingOverloads++;
}
displayWindowsIndex -= previousOverloads;
displayWindowsIndex += remainingOverloads;
}
windowsIndex++;
}
out.push({
id: functionInfo.id,
name: functionInfo.name,
isMulti: functionInfo.isMulti,
linuxIndex: linuxIndex,
windowsIndex: displayWindowsIndex,
});
}
return out;
}
const windowsOffsetWarning =
<Alert bsStyle="warning">
<strong>Some Windows Indexes May Be Incorrect</strong><br/>
This class uses C++ features which can not be accounted for by this tool.
</Alert>;
const PrintVTable = (props) => {
var helpText = <span><Icon type="beer" /> You made it!</span>;
var tableHeader = <tr>
<th className="text-right">L</th>
<th className="text-right">W</th>
<th className="text-left">Function</th>
</tr>;
return <Layout title={helpText} showRestartButton showPickNewSymbolButton>
<div style={{ marginBottom: 30 }}>
{(props.selectedClass.hasMissingFunctions || props.selectedClass.vtables.length > 1) && windowsOffsetWarning}
<Table hover>
<thead>{tableHeader}</thead>
{formatVTable(props.selectedClass).map((func, i) =>
<tbody key={i}>
{(i % 20) === 0 && i !== 0 && tableHeader}
<tr key="info" ref={(row) => row && props.selectedFunction && props.selectedFunction.id === func.id && (row.classList.add('info'), (row.scrollIntoViewIfNeeded ? row.scrollIntoViewIfNeeded(true) : row.scrollIntoView(true)))}>
<th className="text-right">{func.linuxIndex}</th>
<th className="text-right">{func.windowsIndex}</th>
<td className="text-left">
<code>{func.name}</code>
{func.isMulti && multiIcon}
</td>
</tr>
</tbody>
)}
</Table>
</div>
</Layout>;
};
class StateManager extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
if (this.state.selectedClass)
return <PrintVTable
selectedClass={this.state.selectedClass}
selectedFunction={this.state.selectedFunction}
/>;
else if (this.state.selectedFunction)
return <DisambiguateSymbol
selectedFunction={this.state.selectedFunction}
/>;
else if (this.state.programInfo)
return <PickASymbol
programInfo={this.state.programInfo}
searchQuery={this.state.symbolQueryString || ''}
searchResults={this.state.symbolQueryResults || []}
/>;
else if (this.state.binary)
return <ProcessingBinary
binary={this.state.selectedBinary}
loaded={this.state.binaryProcessingProgress.loaded}
total={this.state.binaryProcessingProgress.total}
/>;
else if (this.state.binaryDownloadProgress)
return <DownloadingBinary
binary={this.state.selectedBinary}
loaded={this.state.binaryDownloadProgress.loaded}
total={this.state.binaryDownloadProgress.total}
/>;
else if (this.state.gameList)
return <PickAGame
gameList={this.state.gameList}
/>;
else
return <LoadingGameList />;
}
}
window.stateManager = stateManager = ReactDOM.render(
<StateManager />,
document.getElementById('content')
);
const requestGamesList = () => {
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', (event) => {
stateManager.setState({ gameList: xhr.response });
});
xhr.open('GET', 'https://users.alliedmods.net/~asherkin/vtable/games.json');
xhr.responseType = 'json';
xhr.send();
}
requestGamesList();
</script>
</body>
</html>