-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orvibo Learn.b4j
385 lines (283 loc) · 10.2 KB
/
Orvibo Learn.b4j
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
Version=4.7
AppType=JavaFX
NumberOfModules=0
Build1=Default,nz.ope.orvibo.learn
NumberOfFiles=1
File1=Layout1.bjl
NumberOfLibraries=5
Library1=jcore
Library2=jfx
Library3=jutilities
Library4=jnetwork
Library5=byteconverter
@EndOfDesignText@
#Region Project Attributes
#MainFormWidth: 605
#MainFormHeight: 470
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim HostIP As String
Dim ip As String = "192.168.178.2"
Dim Mac As String = "ACCF00000000"
Dim magicWord As String = "6864"
Dim twenties As String = "202020202020"
Dim LocalPassword As String = ""
Dim UDPSocket1 As UDPSocket
Dim b As ByteConverter
Private btnSubscribe As Button
Private btnFindUsingMAC As Button
Private txtIP As TextField
Private txtMAC As TextField
Private txtIR As TextArea
Private txtLog As TextArea
Private btnLearnMode As Button
Private btnCopy As Button
Private btnSendIR As Button
End Sub
Sub AppStart (Form1 As Form, Args() As String)
Dim u As jUtilities
HostIP = u.HostAddress
UDPSocket1.Initialize("UDP", 10000, 1000)
MainForm = Form1
MainForm.Resizable = False
MainForm.SetFormStyle("UNIFIED")
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
txtIP.Text = ip
txtMAC.Text = Mac
txtIR.Text = ""
txtLog.Text = "Host IP = " & HostIP
MainForm.Show
End Sub
Sub PopulateValues()
ip = txtIP.Text
Mac = txtMAC.Text
LocalPassword = ReverseHex(Mac)
End Sub
Sub tLog(Text As String)
txtLog.Text = txtLog.Text & CRLF & Text
txtLog.SetSelection(txtLog.Text.Length, txtLog.Text.Length)
End Sub
Sub ReverseHex(Hex As String) As String
Dim HexRev As String
Dim i As Int
For i = 0 To Hex.Length -1 Step 2
HexRev = Hex.CharAt(i) & Hex.CharAt(i+1) & HexRev
Next
Return HexRev
End Sub
Sub HexPacketLength(Pack As String) As String
Dim l As Int
l = Pack.Length/2
l = l + 4
Dim lengthhex As String
lengthhex = Bit.ToHexString(l).ToUpperCase
Do While lengthhex.Length < 4
lengthhex = "0" & lengthhex
Loop
'Log("lengthhex " & lengthhex)
Return lengthhex
End Sub
Sub SendPacket(msg As String)
tLog(msg)
tLog("Packet=" & magicWord & HexPacketLength(msg) & msg)
Dim Packet As UDPPacket
Packet.Initialize(b.HexToBytes(magicWord & HexPacketLength(msg) & msg), ip, 10000)
UDPSocket1.Send(Packet)
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
If Packet.HostAddress <> HostIP Then
tLog("*********************************")
tLog("From: " & Packet.HostAddress)
tLog("*********************************")
Dim PacketLength As Int = Packet.Length
tLog("Packet length = " & PacketLength)
Dim b As ByteConverter
Dim MessageHex As String = b.HexFromBytes(Packet.Data)
MessageHex = MessageHex.SubString2(0,PacketLength*2)
tLog("MessageHex = " & MessageHex)
Dim ResponseType As String = MessageHex.SubString2(8,12)
tLog(ResponseType & " " & BytesToString(Packet.Data, 4, 2, "UTF8"))
Dim msg As String
msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
tLog("msg = " & msg)
'Log("HexFromBytes " & b.HexFromBytes(Packet.Data))
If MessageHex.IndexOf("ACCF") > 0 Then
Dim macAddress As String = MessageHex.SubString2(MessageHex.IndexOf("ACCF"), MessageHex.IndexOf("ACCF")+12)
tLog("From MAC: " & macAddress)
' cd - 6364 - Countdown
' cl - 636C - Subscription response received (A.K.A TCP Login Command)
' cs - 6373 - Clock synchronization
' dc - 6463 - RF Socket state change response (known As RfCtrlCmd in APK)
' dc-rf - 64632D7266
' di - 6469 - Button on AllOne pressed
' dn - 646E
' hb - 6862 - "Heartbeet" (periodic ping. Perhaps keeps socket subscribed?)
' ic - 6963 - IR code emitted (IR Control Command)
' ic2 - 696332
' ir - 6972 - "Check IR command" (according To decompiled APK)
' ls - 6C73 - IR code received (send this To enter learning mode)
' ls-cd - 6C732D6364
' lt - - TCP logout command (For remote access?)
' mp - 6D70 - Modify remote password
' qa - 7161 - Search For socket where Mac unknown
' qg - 7167 - Search For socket where Mac Is known
' rt - 7274 - Query response received (A.K.A Read Table command)
' rs - - Reset command
' sf - 7366 - State change (via socket button press)
' tm - 746D - Table modify (change tables read by Read Table command)
' ts - - Time set (sets the time on the device in question. Confirmed with Kepler, need To confirm with others)
' ul - 756C
' ur - 7572
'Device Type
If ResponseType = "7161" Then
Log(ResponseType & " [Device Type]")
Dim components() As String
components = Regex.split(twenties,MessageHex)
Log("Type: " & b.StringFromBytes(b.HexToBytes(components(2).SubString2(0,12)),"UTF8"))
'Dim n As Int
'For n = 0 To components.Length -1
' Log(n & " - " & b.StringFromBytes(b.HexToBytes(components(n)),"UTF8"))
' Log(components(n))
'Next
End If
'Subscribed
If ResponseType = "636C" Then
Log(ResponseType & " [Subscribed]")
Dim components() As String
components = Regex.split(twenties,MessageHex)
If components(1).Length > 11 Then Log("State: " & components(1).SubString2(11,12))
End If
'State Change
If ResponseType = "7366" Then
Log(ResponseType & " [State Change]")
Dim components() As String
components = Regex.split(twenties,MessageHex)
Log("State: " & components(1).SubString2(9,10))
End If
'Button Press
If ResponseType = "6469" Then
Log(ResponseType & " [Putton Press]")
End If
'Search For socket where Mac Is known
If ResponseType = "7167" Then
Log(ResponseType & " [Search where Mac Is known]")
End If
'Table
If ResponseType = "7274" Then
Log(ResponseType & " [Table]")
Dim components() As String
components = Regex.split(twenties,MessageHex)
Log("Components = " & components.Length)
'Log("Remote Password: " & b.StringFromBytes(b.HexToBytes(components(3)),"UTF8"))
'Log("Name: " & b.StringFromBytes(b.HexToBytes(components(4)),"UTF8"))
'01 00 00 00 00
'01 00 01 00 00
'06
'00 04 00 04 00 0A
'00
'02 00 00 00 00
'01 00 01 00 00
'06
'00 04 00 04 00 17
'00
'06
'00 03 00 03 00 02
'00
Dim n As Int
For n = 0 To components.Length -1
Log(n & ") - " & b.StringFromBytes(b.HexToBytes(components(n)),"UTF8") & " [" & components(n) & "]")
Next
Dim LastComponent As String
LastComponent = components(components.Length-1)
Dim table_number As String
table_number = LastComponent.SubString2(0,2)
Log("table_number = " & table_number)
'Dim table_info As String = components(5)
'Dim startip As Int
'startip = table_info.IndexOf("1027")
'Log(startip)
'Dim starthost As Int
'starthost = table_info.IndexOf2("1027",startip+4)
'Log(starthost)
'Dim ip As String
'ip = table_info.SubString2(startip+4,startip+12)
'Log("ip = " & ip)
'Dim host As String
'host = table_info.SubString(starthost+4)
'Log("host = " & host)
'Dim table_data As String
'table_data = LastComponent.SubString(28)
'Log("table_data = " & table_data)
'For n = 0 To components.Length -1
' Log(n & ") - " & b.HexFromBytes(components(n)))
'Next
End If
'IR Done
If ResponseType = "6963" Then
Log(ResponseType & " [IR Done]")
End If
'IR Code Received
If ResponseType = "6C73" Then
Log(ResponseType & " [IR Code Received]")
If MessageHex.Length >= 52 Then
txtIR.Text = MessageHex.SubString(52)
End If
End If
'MessageHex = 686400F26C73ACCF2329914E202020202020010000000002D80000000000D8000000000000000000C800720E76079B010E02B601A6059E010E029E010F029D010E02B601F601B601F6019E010D029E010E02B701F601B501F701B501F701A50107029E01C105B201F601B601F7019D010F02B601F6019D010F02B601F701B501F701A2010B02B601F6019E01BF059C010F02B701F5019E010F021C029001B801F401AD01FF019D010E02B501F6019E0111029B010F02B501F701B601F6019E010E029D01BF05B401F7019E010F02B501F7019D010E02B601000294010F029D0128028401BF059C010F029E01BE059D010000
End If
End If
End Sub
Sub btnSubscribe_MouseClicked (EventData As MouseEvent)
PopulateValues
'Subscribe
'Local Password (ie Reversed MAC)
Dim msg As String
msg = "636C" & Mac & twenties & LocalPassword & twenties
SendPacket(msg)
End Sub
Sub btnFindUsingMAC_MouseClicked (EventData As MouseEvent)
PopulateValues
End Sub
Sub btnLearnMode_MouseClicked (EventData As MouseEvent)
PopulateValues
txtIR.Text = ""
'Enter Learn Mode
'Local Password (ie Reversed MAC)
Dim msg As String
msg = "6C73" & Mac & twenties & "010000000000"
SendPacket(msg)
End Sub
Sub btnCopy_MouseClicked (EventData As MouseEvent)
PopulateValues
fx.Clipboard.SetString(txtIR.Text)
End Sub
Sub btnSendIR_MouseClicked (EventData As MouseEvent)
If txtIR.Text = "" Then Return
PopulateValues
Dim msg As String
msg = PrepareIR(txtIR.Text)
SendPacket(msg)
End Sub
Sub PrepareIR(RawIR As String) As String
Dim RandomBitA As String = Bit.ToHexString(Rnd(0,255)).ToUpperCase
Dim RandomBitB As String = Bit.ToHexString(Rnd(0,255)).ToUpperCase
If RandomBitA.Length < 2 Then RandomBitA = "0" & RandomBitA
If RandomBitB.Length < 2 Then RandomBitB = "0" & RandomBitB
Dim irlength As Int
irlength = RawIR.Length/2
Dim irlengthhex As String
irlengthhex = Bit.ToHexString(irlength).ToUpperCase
Do While irlengthhex.Length < 4
irlengthhex = "0" & irlengthhex
Loop
irlengthhex = ReverseHex(irlengthhex)
Dim msg As String
msg = "6963" & Mac & twenties & "65000000" & RandomBitA & RandomBitB & irlengthhex & RawIR
Dim fullir As String
'fullir = magicWord & HexPacketLength(msg) & msg
fullir = msg
tLog("fullir = " & fullir)
Return fullir
End Sub