-
Notifications
You must be signed in to change notification settings - Fork 1
/
h-to-ffi-lua-converter.html
62 lines (52 loc) · 1.44 KB
/
h-to-ffi-lua-converter.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
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Convert ghidra export to FFI specs</title>
</head>
<body>
<h1>Convert ghidra export to FFI specs</h1>
<div>
<input type="file" name="hFile" accept=".h">
</div>
<textarea cols=100 rows="50"></textarea>
<script>
function onChange() {
console.log('convert', this)
if(this.files.length < 1) {
return;
}
console.dir(this.files)
var reader = new FileReader();
reader.onload = function (evt) {
console.log('here we go', reader, evt.target.result)
const textarea = document.querySelector('textarea')
textarea.value = convert(evt.target.result)
textarea.focus();
textarea.select();
document.execCommand('copy');
}
reader.readAsText(this.files[0]);
}
function convert(headerFile) {
let result = headerFile;
result = result.replace('typedef unsigned long long GUID;', '');
result = result.replace('float10', '');
result = result.replace('typedef short wchar_t;', '');
result = result.replace('typedef unsigned char bool;', '');
result = result.replace(/(};)/g, '} __attribute__ ((packed));');
result = `local ffi = require("ffi")
-- #
ffi.cdef[[
${result}
typedef Ped* (__stdcall *GetPedById)(int);
typedef void (__fastcall *PedJumpFly)(Ped*, dword); // 0x00433c40
]]
`
return result
}
document.querySelector('input[name="hFile"]').addEventListener('change', onChange);
</script>
</body>
</html>