forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitconverter.py
More file actions
80 lines (51 loc) · 1.97 KB
/
Copy pathBitconverter.py
File metadata and controls
80 lines (51 loc) · 1.97 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
import struct
TYPES = {
'bool': "?",
'char': "B",
'short': "h",
'int': "i",
'long': "q",
'ushort': "H",
'uint': "I",
'ulong': "Q",
'float': "f",
'double': "d",
}
def GetBytes(value, typ):
return struct.pack(TYPES[typ], value)
def DoubleToInt64Bits(value: float):
byte = struct.pack('d', value)
return struct.unpack('q', byte)
def Int64BitsToDouble(value: int) -> float:
byte = struct.pack('q', value)
return struct.unpack('d', byte)
def ToBoolean(value: bytearray, startIndex: int) -> bool:
return bool(value[startIndex])
def ToChar(value: bytearray, startIndex: int) -> int:
return struct.unpack("b", value[startIndex:startIndex+1])[0]
def ToDouble(value: bytearray, startIndex: int) -> float:
return struct.unpack("d", value[startIndex:startIndex+8])[0]
def ToInt16(value: bytearray, startIndex: int) -> int:
return struct.unpack("h", value[startIndex:startIndex+2])[0]
def ToInt32(value: bytearray, startIndex: int) -> int:
return struct.unpack("i", value[startIndex:startIndex+4])[0]
def ToInt64(value: bytearray, startIndex: int) -> int:
return struct.unpack("q", value[startIndex:startIndex+8])[0]
def ToSingle(value: bytearray, startIndex: int) -> float:
return struct.unpack("f", value[startIndex:startIndex+4])[0]
def ToString(value, *args):
if len(args) == 0:
return value.decode()
elif len(args) == 1:
startIndex = args[0]
return value[startIndex:].decode()
elif len(args) == 2:
startIndex = args[0]
length = args[1]
return value[startIndex:startIndex+length].decode()
def ToUInt16(value: bytearray, startIndex: int) -> int:
return struct.unpack("H", value[startIndex:startIndex+2])[0]
def ToUInt32(value: bytearray, startIndex: int) -> int:
return struct.unpack("I", value[startIndex:startIndex+4])[0]
def ToUInt64(value: bytearray, startIndex: int) -> int:
return struct.unpack("Q", value[startIndex:startIndex+8])[0]