Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

Decode Lua Jit File

Featured Replies

  • Author
  • Localization

DimondDingBag98, posted Thu Mar 09, 2023 4:50 am (75767)


Hi,

Could someone help me Decode the below luajit file?

sorry, new link

https://tempfile.io/en/IMcfjZpbqzLVgrM/file

I can get a partial read of the first few lines from the controller but would like to know the process to read the rest as well as the functions

[version]
* function: 0xb6e4e5c8
[defaultNetwork]
* number: 254
[decodega]
* function: 0xb6e4e648
[encodeua]
* function: 0xb6e4e5e8
[decodewrapper]
* function: 0xb6e4f3c8
[deletetag]
* function: 0xb6e50968
[name2app]
* table:
[AUDIO_APP]
* number: 205
[NETWORK_CONTROL_APP]
* number: 255
[TIME_APP]
* number: 223
[ENABLE_APP]
* number: 203
[HEATING_APP]
* number: 136
[ERROR_APP]
* number: 206
[MEDIA_TRANSPORT_APP]
* number: 192
[TELEPHONY_APP]
* number: 224
[TESTING1_APP]
* number: 240
[LIGHTING_APP]
* number: 56
[SECURITY_APP]
* number: 208
[LIGHTING_APP_HIGH]
* number: 127
[TEMP_BC_APP]
* number: 25
[INFO_MESSAGES_APP]
* number: 173
[AIR_CONDITIONING_APP]
* number: 172
[TRIGGER_APP]
* number: 202
[MEASUREMENT_APP]
* number: 228
[LIGHTING_APP_LOW]
* number: 48
[TESTING2_APP]
* number: 250
  • Author
  • Localization

DimondDingBag98, posted Sun Mar 12, 2023 2:31 am (75810)


This seems to be the most i can get from the controller,
essentially on the controller i can run a script with the following:

lib = require('lib.lua')
log(lib)

and the output is as below.

I have ssh access to the controller.

Would anyone have a way to decode the file so it can be read and edited using a text editor, and also read the functions?

load lua lib 09.03.2023 15:48:40
* table:
[version]
* function: 0xb6f2a5c8
[defaultNetwork]
* number: 254
[decodega]
* function: 0xb6f2a648
[encodeua]
* function: 0xb6f2a5e8
[decodewrapper]
* function: 0xb6f2b3c8
[deletetag]
* function: 0xb6f2c968
[name2app]
* table:
[AUDIO_APP]
* number: 205
[NETWORK_CONTROL_APP]
* number: 255
[TIME_APP]
* number: 223
[ENABLE_APP]
* number: 203
[HEATING_APP]
* number: 136
[ERROR_APP]
* number: 206
[MEDIA_TRANSPORT_APP]
* number: 192
[TELEPHONY_APP]
* number: 224
[TESTING1_APP]
* number: 240
[LIGHTING_APP]
* number: 56
[SECURITY_APP]
* number: 208
[LIGHTING_APP_HIGH]
* number: 127
[TEMP_BC_APP]
* number: 25
[INFO_MESSAGES_APP]
* number: 173
[AIR_CONDITIONING_APP]
* number: 172
[TRIGGER_APP]
* number: 202
[MEASUREMENT_APP]
* number: 228
[LIGHTING_APP_LOW]
* number: 48
[TESTING2_APP]
* number: 250
[error_severity]
* table:
[0]
* string: All OK
[1]
* string: OK
[2]
* string: Minor failure
[3]
* string: General failure
[4]
* string: Extreme failure
[app2name]
* table:
[203]
* string: ENABLE_APP
[250]
* string: TESTING2_APP
[25]
* string: TEMP_BC_APP
[228]
* string: MEASUREMENT_APP
[136]
* string: HEATING_APP
[48]
* string: LIGHTING_APP_LOW
[240]
* string: TESTING1_APP
[224]
* string: TELEPHONY_APP
[208]
* string: SECURITY_APP
[192]
* string: MEDIA_TRANSPORT_APP
[127]
* string: LIGHTING_APP_HIGH
[56]
* string: LIGHTING_APP
[206]
* string: ERROR_APP
[255]
* string: NETWORK_CONTROL_APP
[223]
* string: TIME_APP
[205]
* string: AUDIO_APP
[172]
* string: AIR_CONDITIONING_APP
[202]
* string: TRIGGER_APP
[173]
* string: INFO_MESSAGES_APP
[encode]
* function: 0xb6f2a668
[_afternewobjhook]
* function: 0xb6f2cb98
[MTCFunctionNames]
* table:
[Rewind]
* number: 8
[Previous2 Category Name]
* number: 25
[Next Selection Name]
* number: 15
[Previous2 Track Name]
* number: 23
[Play Stop]
* number: 0
[Current Category Name]
* number: 13
[Source Power Control]
* number: 9
[Selection]
* number: 3
[Previous Track Name]
* number: 17
[Next2 Category Name]
* number: 22
[Previous2 Selection Name]
* number: 24
[Track]
* number: 4
[Next Category Name]
* number: 16
[Next2 Selection Name]
* number: 21
[Enum Category Names]
* number: 30
[Forward]
* number: 7
[Current Selection Name]
* number: 12
[Enum Category Size]
* number: 27
[Next Track Name]
* number: 14
[Enum Selection Names]
* number: 31
[Total Tracks]
* number: 10
[MTC Command]
* number: 26
[Pause Resume]
* number: 1
[Shuffle]
* number: 5
[Previous Category Name]
* number: 19
[Enum Selection Size]
* number: 28
[Previous Selection Name]
* number: 18
[Repeat]
* number: 6
[Category]
* number: 2
[Next2 Track Name]
* number: 20
[Current Track Name]
* number: 11
[Enum Track Size]
* number: 29
[Enum Track Names]
* number: 32
[renametagbyid]
* function: 0xb6f2c988
[MTCFunctions]
* table:
[0]
* string: Play Stop
[1]
* string: Pause Resume
[2]
* string: Category
[3]
* string: Selection
[4]
* string: Track
[5]
* string: Shuffle
[6]
* string: Repeat
[7]
* string: Forward
[8]
* string: Rewind
[9]
* string: Source Power Control
[10]
* string: Total Tracks
[11]
* string: Current Track Name
[12]
* string: Current Selection Name
[13]
* string: Current Category Name
[14]
* string: Next Track Name
[15]
* string: Next Selection Name
[16]
* string: Next Category Name
[17]
* string: Previous Track Name
[18]
* string: Previous Selection Name
[19]
* string: Previous Category Name
[20]
* string: Next2 Track Name
[21]
* string: Next2 Selection Name
[22]
* string: Next2 Category Name
[23]
* string: Previous2 Track Name
[24]
* string: Previous2 Selection Name
[25]
* string: Previous2 Category Name
[26]
* string: MTC Command
[27]
* string: Enum Category Size
[28]
* string: Enum Selection Size
[29]
* string: Enum Track Size
[30]
* string: Enum Category Names
[31]
* string: Enum Selection Names
[32]
* string: Enum Track Names
[MRAFunctionNames]
* table:
[Source Descriptor]
* number: 8
[D2 Dynamic Label]
* number: 7
[Treble]
* number: 3
[Zone Descriptor]
* number: 9
[D1 Dynamic Label]
* number: 6
[Source Number]
* number: 5
[Mute]
* number: 4
[Volume]
* number: 0
[Balance]
* number: 1
[MRA Command]
* number: 10
[Bass]
* number: 2
[encodega]
* function: 0xb6f2a628
[decode]
* function: 0xb6f2a688
[securitymaxzone]
* number: 80
[getvalueastext]
* function: 0xb6f2cc90
[decodeua]
* function: 0xb6f2a608
[totalErrObjNumMax]
* number: 2000
[_setvaluehook]
* function: 0xb6f2cc40
[errorsyscat]
* table:
[Device Controller]
* number: 888
[Relay]
* number: 848
[Sinewave Dimmer]
* number: 860
[A/C System]
* number: 960
[Key unit]
* number: 320
[Universal Dimmer]
* number: 884
[TE Dimmer]
* number: 836
[Modular Dimmer]
* number: 876
[BMS Reporting]
* number: 704
[Temperature Sensor]
* number: 328
[PWM/LED Dimmer]
* number: 856
[DALI/DSI]
* number: 872
[PSU]
* number: 576
[Telecommand and Remote Entry]
* number: 324
[LE Dimmer]
* number: 832
[_newobjecthook]
* function: 0xb6f2cad0
[errornumwarningfile]
* string: /tmp/errobjsnumerr
[gettype]
* function: 0xb6f2a6a8
[knxdecode]
* function: builtin#222
[renametagbyname]
* function: 0xb6f2c9a8
[addtag]
* function: 0xb6f2c908
[defaultApplication]
* number: 56
[memMinLeftMB]
* number: 30
[_afterdelobjhook]
* function: 0xb6f2cc20
[securityobjs]
* table:
[Armed state]
* number: 5
[Fire alarm]
* number: 9
[Password status]
* number: 17
[Entry delay]
* number: 7
[Arm failed]
* number: 3
[Alarm sounding]
* number: 1
[Panic]
* number: 16
[Line cut alarm]
* number: 11
[Mains failure]
* number: 13
[All zones OK]
* number: 2
[Zone name]
* number: 22
[Other alarm]
* number: 15
[Normal operation]
* number: 14
[Command]
* number: 0
[Zone isolated]
* number: 20
[Low battery]
* number: 12
[Password OK]
* number: 18
[Gas alarm]
* number: 10
[Zone state]
* number: 21
[Exit delay]
* number: 8
[Arm ready]
* number: 4
[Tamper]
* number: 19
[Battery charging]
* number: 6
[networkCount]
* function: 0xb6f2a708
[securityDefaultArmedStates]
* table:
[0]
* string: Disarmed
[1]
* string: Fully armed
[2]
* string: Partially armed
[file_exists]
* function: 0xb6f2ccb0
[securitymaxmessagelen]
* number: 16
[securityDefaultPasswordStatuses]
* table:
[1]
* string: Success
[2]
* string: Failed
[3]
* string: Disabled
[4]
* string: Enabled
[islightinglike]
* function: 0xb6f2c9c8
[disablesniffer]
* function: 0xb6f2ccc8
[unitparam]
* table:
[VOLTAGE]
* number: 3
[LIGHT_LEVEL]
* number: 2
[TEMPERATURE]
* number: 1
[knxencode]
* function: builtin#223
[securitySpecialKeys]
* table:
[132]
* string: Away
[13]
* string: Enter
[133]
* string: Night
[134]
* string: Day
[135]
* string: Vacation
[128]
* string: Shift
[129]
* string: Panic
[130]
* string: Fire
[131]
* string: Arm
[getgroupforapp]
* function: 0xb6f2cc70
[securityDefaultZoneStates]
* table:
[0]
* string: Sealed
[1]
* string: Unsealed
[2]
* string: Open
[3]
* string: Short
[MRAFunctions]
* table:
[0]
* string: Volum...
  • Author
  • Localization

atom0s, posted Mon Mar 13, 2023 12:51 am (75834)


There are multiple LuaJIT decompilers around the web you can find with ease via Google. This file is able to be decompiled, for the most part, back to its original format. (Note some namings of things are missing, so the decompiler automatically fills that in with junk.)

Code:
require("helper")

function slot0(slot0)
   slot1, slot2 = os.microtime()
   slot5 = io.open("/tmp/cbuslib.log", "a")

   slot5:write(slot1 .. string.format(".d ", math.floor(slot2 / 1000)) .. ": " .. slot0 .. "\n")
   slot5:close()
end

function slot1()
   if not db then
      require("dbenv")

      db = dbenv:new()
   end

   return db
end

slot2 = require("cbuslib.core")
slot2.knxencode = knxdatatype.encode
slot2.knxdecode = knxdatatype.decode
knxlib.encodeia = slot2.encodeua
knxlib.decodeia = slot2.decodeua
buslib.encodeia = slot2.encodeua
buslib.decodeia = slot2.decodeua
knxlib.encodega = slot2.encodega
knxlib.decodega = slot2.decodega
buslib.encodega = slot2.encodega
buslib.decodega = slot2.decodega
knxdatatype.decode = slot2.decode
knxdatatype.encode = slot2.encode
busdatatype.decode = slot2.decode
busdatatype.encode = slot2.encode

function slot2.decodewrapper(slot0, slot1, slot2)
   if bit.rshift(slot0, 24) == uv0.name2app.TESTING2_APP then
      return uv0.knxdecode(slot2, slot1, slot0), true
   else
      return uv0.decode(slot2, dt.none, slot0), false
   end
end

slot2.app2name = {
   [127.0] = "LIGHTING_APP_HIGH",
   [202.0] = "TRIGGER_APP",
   [172.0] = "AIR_CONDITIONING_APP",
   [205.0] = "AUDIO_APP",
   [223.0] = "TIME_APP",
   [173.0] = "INFO_MESSAGES_APP",
   [136.0] = "HEATING_APP",
   [255.0] = "NETWORK_CONTROL_APP",
   [206.0] = "ERROR_APP",
   [192.0] = "MEDIA_TRANSPORT_APP",
   [208.0] = "SECURITY_APP",
   [224.0] = "TELEPHONY_APP",
   [240.0] = "TESTING1_APP",
   [48.0] = "LIGHTING_APP_LOW",
   [56.0] = "LIGHTING_APP",
   [228.0] = "MEASUREMENT_APP",
   [25.0] = "TEMP_BC_APP",
   [250.0] = "TESTING2_APP",
   [203.0] = "ENABLE_APP"
}
slot2.name2app = {
   AUDIO_APP = 205,
   LIGHTING_APP_LOW = 48,
   HEATING_APP = 136,
   TRIGGER_APP = 202,
   AIR_CONDITIONING_APP = 172,
   TESTING1_APP = 240,
   TEMP_BC_APP = 25,
   LIGHTING_APP_HIGH = 127,
   TESTING2_APP = 250,
   LIGHTING_APP = 56,
   MEASUREMENT_APP = 228,
   TELEPHONY_APP = 224,
   MEDIA_TRANSPORT_APP = 192,
   ERROR_APP = 206,
   INFO_MESSAGES_APP = 173,
   ENABLE_APP = 203,
   TIME_APP = 223,
   NETWORK_CONTROL_APP = 255,
   SECURITY_APP = 208
}
slot2.unitparam = {
   LIGHT_LEVEL = 2,
   TEMPERATURE = 1,
   VOLTAGE = 3
}
slot2.error_severity = {
   [0] = "All OK",
   "OK",
   "Minor failure",
   "General failure",
   "Extreme failure"
}
slot2.securitySpecialKeys = {
   [131.0] = "Arm",
   [130.0] = "Fire",
   [129.0] = "Panic",
   [128.0] = "Shift",
   [135.0] = "Vacation",
   [134.0] = "Day",
   [133.0] = "Night",
   [13.0] = "Enter",
   [132.0] = "Away"
}
slot2.securityDefaultArmedStates = {
   [0] = "Disarmed",
   "Fully armed",
   "Partially armed"
}
slot2.securityDefaultPasswordStatuses = {
   "Success",
   "Failed",
   "Disabled",
   "Enabled"
}
slot2.securityDefaultZoneStates = {
   [0] = "Sealed",
   "Unsealed",
   "Open",
   "Short"
}
slot2.MRAFunctions = {
   [0] = "Volume",
   "Balance",
   "Bass",
   "Treble",
   "Mute",
   "Source Number",
   "D1 Dynamic Label",
   "D2 Dynamic Label",
   "Source Descriptor",
   "Zone Descriptor",
   "MRA Command"
}
slot2.MRAFunctionNames = {
   Bass = 2,
   ["D1 Dynamic Label"] = 6,
   ["Zone Descriptor"] = 9,
   Volume = 0,
   Mute = 4,
   ["MRA Command"] = 10,
   Balance = 1,
   ["Source Number"] = 5,
   Treble = 3,
   ["D2 Dynamic Label"] = 7,
   ["Source Descriptor"] = 8
}
slot2.MTCFunctions = {
   [0] = "Play Stop",
   "Pause Resume",
   "Category",
   "Selection",
   "Track",
   "Shuffle",
   "Repeat",
   "Forward",
   "Rewind",
   "Source Power Control",
   "Total Tracks",
   "Current Track Name",
   "Current Selection Name",
   "Current Category Name",
   "Next Track Name",
   "Next Selection Name",
   "Next Category Name",
   "Previous Track Name",
   "Previous Selection Name",
   "Previous Category Name",
   "Next2 Track Name",
   "Next2 Selection Name",
   "Next2 Category Name",
   "Previous2 Track Name",
   "Previous2 Selection Name",
   "Previous2 Category Name",
   "MTC Command",
   "Enum Category Size",
   "Enum Selection Size",
   "Enum Track Size",
   "Enum Category Names",
   "Enum Selection Names",
   "Enum Track Names"
}
slot2.MTCFunctionNames = {
   ["Previous2 Selection Name"] = 24,
   Forward = 7,
   ["Current Track Name"] = 11,
   Track = 4,
   ["Next2 Selection Name"] = 21,
   ["Next Category Name"] = 16,
   ["Previous Selection Name"] = 18,
   ["Enum Selection Size"] = 28,
   ["Current Category Name"] = 13,
   Shuffle = 5,
   ["Pause Resume"] = 1,
   ["Play Stop"] = 0,
   ["Total Tracks"] = 10,
   ["Next2 Category Name"] = 22,
   ["Enum Track Names"] = 32,
   ["Enum Category Size"] = 27,
   ["Current Selection Name"] = 12,
   ["Enum Track Size"] = 29,
   ["Enum Category Names"] = 30,
   ["Next2 Track Name"] = 20,
   Category = 2,
   Repeat = 6,
   ["Previous Category Name"] = 19,
   ["MTC Command"] = 26,
   ["Previous Track Name"] = 17,
   Selection = 3,
   ["Source Power Control"] = 9,
   ["Enum Selection Names"] = 31,
   ["Next Track Name"] = 14,
   ["Previous2 Track Name"] = 23,
   ["Next Selection Name"] = 15,
   ["Previous2 Category Name"] = 25,
   Rewind = 8
}
slot2.defaultNetwork = 254
slot2.defaultApplication = 56
slot2.errornumwarningfile = "/tmp/errobjsnumerr"
slot2.totalErrObjNumMax = 2000
slot2.memMinLeftMB = 30

function slot3(slot0, slot1, slot2, slot3, slot4)
   slot5 = nil

   if slot0 == "N" then
      if slot1 ~= nil or slot2 ~= nil or slot3 ~= nil or slot4 ~= nil then
         error("net, app and grp must not be set for network tags")
      end

      slot5 = "1"
   elseif slot0 == "A" then
      if slot1 == nil or slot2 ~= nil or slot3 ~= nil or slot4 ~= nil then
         error("net must be set and app and grp must not be set for application tags")
      end

      slot5 = string.format("net=%d", slot1)
   elseif slot0 == "G" then
      if slot1 == nil or slot2 == nil or slot3 ~= nil or slot4 ~= nil then
         error("net and app must be set and grp must not be set for group tags")
      end

      slot5 = string.format("net=%d AND app=%d", slot1, slot2)
   elseif slot0 == "S" then
      if slot1 == nil or slot2 == nil or slot3 == nil or slot4 ~= nil then
         error("net app and grp must be set and subgrp must not be set for group tags")
      end

      slot5 = string.format("net=%d AND app=%d AND grp=%d", slot1, slot2, slot3)
   elseif slot0 == "L" then
      if slot2 == uv0.name2app.AUDIO_APP or slot2 == uv0.name2app.MEDIA_TRANSPORT_APP then
         if slot1 == nil or slot2 == nil or slot3 == nil or slot4 == nil then
            error("net, app, grp and subgrp must be set for level tags")
         end

         slot5 = string.format("net=%d AND app=%d AND grp=%d and subgrp=%d", slot1, slot2, slot3, slot4)
      else
         if slot1 == nil or slot2 == nil or slot3 == nil then
            error("net, app and grp must be set for level tags")
         end

         slot5 = string.format("net=%d AND app=%d AND grp=%d", slot1, slot2, slot3)
      end
   else
      error("unknown tag type " .. slot0)
   end

   return slot5
end

function slot2.addtag(slot0, slot1, slot2, slot3, slot4, slot5)
   slot7 = uv1(slot0, slot2, slot3, slot4, slot5)
   count, stat = uv0():execute("BEGIN EXCLUSIVE TRANSACTION")

   if stat ~= nil then
      error("Failed to start transaction: " .. stat)
   end

   dupe = slot6:getone("SELECT id FROM cbus_tag_map WHERE tagtype = ? AND " .. slot7 .. " AND tag LIKE ?", slot0, slot1)

   if dupe then
      count, status = slot6:execute("ROLLBACK")

      error("Duplicate tag exists with tag ID " .. tagid .. ", name \"" .. slot1 .. "\", ID " .. dupe)
   end

   count, stat = slot6:insert("cbus_tag_map", {
      tag = slot1,
      tagtype = slot0,
      tagid = tagid,
      net = slot2,
      app = slot3,
      grp = slot4,
      subgrp = slot5
   })

   if stat ~= nil then
      count, status = slot6:execute("ROLLBACK")

      error("SQL error adding tag: " .. stat)
   end

   count, status = slot6:execute("END TRANSACTION")

   if status ~= nil then
      error("Failed to addtag, commit error: " .. status)
   end

   return res
end

function slot2.deletetag(slot0, slot1, slot2, slot3, slot4, slot5, slot6)
   slot7 = uv0()

   if slot1 == nil and slot2 == nil then
      error("at least one of tag and tagid must be set")
   end

   slot8 = uv1(slot0, slot3, slot4, slot5, slot6)
   count, stat = slot7:execute("BEGIN EXCLUSIVE TRANSACTION")
   count, stat = slot7:delete("cbus_tag_map", {
      tag = slot1,
      tagtype = slot0,
      tagid = slot2,
      net = slot3,
      app = slot4,
      grp = slot5,
      subgrp = slot6
   })

   if stat ~= nil then
      error("SQL error deleting tag: " .. stat)
   end

   if count > 1 then
      error("deleted more than one row for tagtype " .. tostring(slot0) .. ", tag " .. tostring(slot1) .. ", tagid " .. tostring(slot2) .. ", net " .. tostring(slot3) .. ", app " .. tostring(slot4) .. ", grp " .. tostring(slot5) .. ", subgrp " .. tostring(slot6))
   end

   return count
end

function slot2.renametagbyid(slot0, slot1, slot2)
   count, stat = uv0():update({
      tag = slot1,
      tagid = slot2
   }, {
      id = slot0
   })

   if stat ~= nil then
      error("SQL error in renamebytag for id " .. tostring(slot0) .. ", newtag " .. tostring(slot1) .. " newtagid " .. slot2)
   end

   return count
end

function slot2.renametagbyname(slot0, slot1, slot2, slot3, slot4, slot5, slot6, slot7)
   slot9 = uv1(slot0, slot2, slot3, slot4, slot5)
   count, stat = uv0():update("cbus_tag_map", {
      tag = slot6,
      tagid = slot7
   }, {
      tagtype = slot0,
      tag = slot1,
      net = slot2,
      app = slot3,
      grp = slot4,
      subgrp = slot5
   })

   if stat ~= nil then
      error("SQL error in renamebyname tagtype " .. tostring(slot0) .. ", tag " .. tostring(slot1) .. ", net " .. tostring(slot2) .. ", app " .. tostring(slot3) .. ", grp " .. tostring(slot4) .. ", subgrp " .. tostring(slot5) .. ", newtag " .. tostring(slot6) .. ", newtagid " .. tostring(slot7))
   end

   return count
end

function slot2.islightinglike(slot0)
   assert(slot0 >= 0 and slot0 <= 255)

   if slot0 >= 1 and slot0 <= 15 or uv0.name2app.LIGHTING_APP_LOW <= slot0 and slot0 <= uv0.name2app.LIGHTING_APP_HIGH or slot0 == uv0.name2app.HEATING_APP or slot0 == uv0.name2app.TRIGGER_APP or slot0 == uv0.name2app.ENABLE_APP then
      return true
   else
      return false
   end
end

function slot4(slot0, slot1, slot2, slot3)
   for slot7, slot8 in pairs(slot2) do
      if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"L\" AND net = ? AND app = ? AND grp = ? LIMIT 1", slot7, slot3, uv0.name2app.SECURITY_APP, uv0.securityobjs[slot1]) == nil then
         data = {
            net = slot3,
            app = uv0.name2app.SECURITY_APP,
            tagtype = "L",
            grp = slot9,
            tag = slot8,
            tagid = slot7
         }
         res = slot0:insert("cbus_tag_map", data)
      end
   end
end

function slot5(slot0)
   slot1 = io.open("/tmp/cbuslibdebug.log", "a")

   slot1:write(slot0 .. "\n")
   slot1:close()
end

function slot6(slot0, slot1, slot2)
   if slot0:getone("SELECT id FROM cbus_tag_map WHERE net = ? AND tagid = ? AND tagtype = ? LIMIT 1", bit.band(bit.rshift(slot1, 16), 255), uv0.name2app.SECURITY_APP, "A") == nil then
      res = slot0:insert("cbus_tag_map", {
         tagid = uv0.name2app.SECURITY_APP,
         tagtype = "A",
         tag = "Security",
         net = slot3
      })
   end

   if slot0:getone("SELECT id FROM cbus_tag_map WHERE net = ? AND app = ? AND tagtype = ? LIMIT 1", slot3, uv0.name2app.SECURITY_APP, "G") ~= nil then
      if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"G\" AND net = ? AND app = ? LIMIT 1", bit.band(bit.rshift(slot1, 8), 255), slot3, uv0.name2app.SECURITY_APP) == nil then
         for slot9, slot10 in pairs(uv0.securityobjs) do
            if slot4 == slot10 then
               res = slot0:insert("cbus_tag_map", {
                  net = slot3,
                  app = uv0.name2app.SECURITY_APP,
                  tagtype = "G",
                  tag = slot9,
                  tagid = slot10
               })

               break
            end
         end
      end

      if slot4 == uv0.securityobjs["Armed state"] then
         uv1(slot0, "Armed state", uv0.securityDefaultArmedStates, slot3)
      elseif slot4 == uv0.securityobjs["Password status"] then
         uv1(slot0, "Password status", uv0.securityDefaultPasswordStatuses, slot3)
      elseif slot4 == uv0.securityobjs["Zone state"] then
         uv1(slot0, "Zone state", uv0.securityDefaultZoneStates, slot3)
      end

      return true
   end

   slot2 = {
      net = slot3,
      app = uv0.name2app.SECURITY_APP,
      tagtype = "G",
      tag = slot7,
      tagid = slot8
   }

   for slot7, slot8 in pairs(uv0.securityobjs) do
      res = slot0:insert("cbus_tag_map", slot2)
   end

   slot2.tagtype = "L"
   slot2.grp = uv0.securityobjs["Armed state"]

   for slot7, slot8 in pairs(uv0.securityDefaultArmedStates) do
      slot2.tag = slot8
      slot2.tagid = slot7
      res = slot0:insert("cbus_tag_map", slot2)
   end

   slot2.grp = uv0.securityobjs["Password status"]

   for slot7, slot8 in pairs(uv0.securityDefaultPasswordStatuses) do
      slot2.tag = slot8
      slot2.tagid = slot7
      res = slot0:insert("cbus_tag_map", slot2)
   end

   slot2.grp = uv0.securityobjs["Zone state"]

   for slot7, slot8 in pairs(uv0.securityDefaultZoneStates) do
      slot2.tag = slot8
      slot2.tagid = slot7
      res = slot0:insert("cbus_tag_map", slot2)
   end

   return true
end

function slot7(slot0, slot1, slot2, slot3)
   for slot8 in pairs(slot0:getall("SELECT network, most_recent, devid, channel, sysid, object, devtype FROM cbus_error_app")) do
      if slot4[slot8].devtype == 0 and slot1 == slot4[slot8].network and slot2 == slot4[slot8].devid and slot3 == slot4[slot8].most_recent then
         return slot4[slot8].sysid
      end
   end

   return nil
end

function slot8(slot0, slot1, slot2)
   slot3 = 0
   slot5 = bit.band(bit.rshift(slot1, 16), 255)
   slot6 = tonumber(slot2.cbe_devtype)
   slot7, slot8, slot9 = nil

   if tonumber(slot2.cbe_most_recent) == nil then
      return false, nil, "Invalid configuration: most_recent is nil"
   end

   if slot6 == 0 then
      slot8 = tonumber(slot2.cbe_devid)
      slot9 = tonumber(slot2.cbe_channel)

      if tonumber(slot2.cbe_sysid) == nil then
         return false, nil, "Invalid error object definition: sysid is nil"
      end

      if slot5 ~= nil and slot8 ~= nil and slot9 == nil then
         -- Nothing
      elseif slot5 == nil or slot8 == nil or slot9 == nil then
         return false, nil, "Invalid error object definition: network or devid is nil"
      end

      if slot0:getall("SELECT network, devid, sysid, devtype FROM cbus_error_app WHERE devtype = ? AND network = ? AND devid = ?", 0, slot5, slot8) ~= nil then
         for slot15 in pairs(slot11) do
            if slot11[slot15].devtype == 0 and slot11[slot15].sysid ~= slot7 then
               return false, nil, "Can not have different System ID for the same Network and same Device ID"
            end
         end
      end

      if ((slot9 ~= nil or slot0:getall("SELECT network, devid, sysid FROM cbus_error_app WHERE devtype = ? AND network = ? AND devid = ? AND most_recent = ?", 0, slot5, slot8, slot4)) and slot0:getall("SELECT network, devid, sysid FROM cbus_error_app WHERE devtype = ? AND network = ? AND devid = ? AND channel = ? AND most_recent = ?", 0, slot5, slot8, slot9, slot4)) ~= nil and #slot11 ~= 0 then
         return false, nil, "Can not create a duplicate physical error object"
      end
   elseif slot6 == 1 then
      if uv0(slot0, slot5, tonumber(slot2.cbe_devid), slot4) == nil then
         return false, nil, "Invalid error object creation: no physical error object with channel exists in network:" .. slot5 .. " and devid:" .. slot8
      end

      if slot7 == 320 or slot7 == 324 or slot7 == 704 or slot7 == 888 then
         return false, nil, "Invalid error object creation: no physical error object with channel exists in network:" .. slot5 .. " and devid:" .. slot8
      end

      slot9 = nil

      if slot5 == nil or slot8 == nil then
         return false, nil, "Invalid error object definition: network or devid is nil"
      end

      sqlstr = "SELECT network, devid, sysid FROM cbus_error_app WHERE devtype = ? AND network = ? AND devid = ? AND most_recent = ?"
      rows = slot0:getall(sqlstr, 1, slot5, slot8, slot4)

      if rows ~= nil and #rows ~= 0 then
         return false, nil, "Can not create a duplicate virtual unit error object"
      end
   elseif slot6 == 2 then
      slot7, slot8, slot9 = nil

      if slot5 == nil then
         return false, nil, "Invalid error object definition: network is nil"
      end

      sqlstr = "SELECT network FROM cbus_error_app WHERE devtype = ? AND network = ? AND most_recent = ?"
      rows = slot0:getall(sqlstr, 2, slot5, slot4)

      if rows ~= nil and #rows ~= 0 then
         return false, nil, "Can not create a duplicate virtual network error object"
      end
   elseif slot6 == 3 then
      slot7, slot8, slot9 = nil
      slot5 = nil
      sqlstr = "SELECT network FROM cbus_error_app WHERE devtype = ? AND most_recent = ?"
      rows = slot0:getall(sqlstr, 3, slot4)

      if rows ~= nil and #rows ~= 0 then
         return false, nil, "Can not create a duplicate virtual project error object"
      end
   else
      return false, nil, "Invalid device type, only 0-3 allowed, but is " .. slot6
   end

   slot0:query("DELETE from cbus_error_app WHERE object == ?", slot1)
   slot0:insert("cbus_error_app", {
      object = slot1,
      errtype = slot3,
      most_recent = slot4,
      network = slot5,
      sysid = slot7,
      devid = slot8,
      channel = slot9,
      devtype = slot6
   })

   return true
end

function addlevelnode(slot0, slot1, slot2, slot3, slot4, slot5, slot6)
   if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"L\" AND net = ? AND app = ? AND grp = ? AND subgrp = ? LIMIT 1", slot5, slot1, slot2, slot3, slot4) == nil then
      res = slot0:insert("cbus_tag_map", {
         net = slot1,
         app = slot2,
         tagtype = "L",
         grp = slot3,
         subgrp = slot4,
         tag = slot6,
         tagid = slot5
      })
   end
end

function slot2._newobjecthook(slot0, slot1, slot2)
   if bit.band(bit.rshift(slot1, 24), 255) == uv0.name2app.SECURITY_APP then
      return uv1(slot0, slot1, slot2)
   elseif slot3 == uv0.name2app.ERROR_APP then
      return uv2(slot0, slot1, slot2)
   end

   return true
end

function slot9(slot0, slot1, slot2)
   if bit.band(bit.rshift(slot1, 8), 255) == uv0.securityobjs["Alarm sounding"] or slot3 == uv0.securityobjs["Arm failed"] or slot3 == uv0.securityobjs["Entry delay"] or slot3 == uv0.securityobjs["Exit delay"] or slot3 == uv0.securityobjs["Fire alarm"] or slot3 == uv0.securityobjs["Gas alarm"] or slot3 == uv0.securityobjs["Line cut alarm"] or slot3 == uv0.securityobjs["Low battery"] or slot3 == uv0.securityobjs["Mains failure"] or slot3 == uv0.securityobjs["Other alarm"] or slot3 == uv0.securityobjs.Panic or slot3 == uv0.securityobjs.Tamper or slot3 == uv0.securityobjs["Zone isolated"] or slot3 == uv0.securityobjs["Zone state"] then
      slot0:update("objects", {
         datahex = "00"
      }, {
         id = slot1
      })
   elseif slot3 == uv0.securityobjs["All zones OK"] or slot3 == uv0.securityobjs["Arm ready"] or slot3 == uv0.securityobjs["Normal operation"] then
      slot0:update("objects", {
         datahex = "01"
      }, {
         id = slot1
      })
   end

   return true
end

function slot10(slot0, slot1, slot2)
   slot3 = bit.band(slot1, 255)
   slot4 = bit.band(bit.rshift(slot1, 8), 255)

   if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"A\" AND net = ? LIMIT 1", uv0.name2app.AUDIO_APP, bit.band(bit.rshift(slot1, 16), 255)) == nil then
      res = slot0:insert("cbus_tag_map", {
         net = slot5,
         tagtype = "A",
         tag = "MRA",
         tagid = uv0.name2app.AUDIO_APP
      })
   end

   if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"G\" AND net = ? AND app = ? LIMIT 1", slot4, slot5, uv0.name2app.AUDIO_APP) == nil then
      res = slot0:insert("cbus_tag_map", {
         net = slot5,
         app = uv0.name2app.AUDIO_APP,
         tagtype = "G",
         tag = "Zone " .. slot4,
         tagid = slot4
      })
   end

   slot7, slot8 = nil

   for slot12, slot13 in pairs(uv0.MRAFunctions) do
      if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"S\" AND net = ? AND app = ? AND grp = ? LIMIT 1", slot12, slot5, uv0.name2app.AUDIO_APP, slot4) == nil then
         res = slot0:insert("cbus_tag_map", {
            net = slot5,
            app = uv0.name2app.AUDIO_APP,
            tagtype = "S",
            grp = slot4,
            tag = slot13,
            tagid = slot12
         })
      end
   end

   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 1, 128, "Mid Point")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 2, 128, "Mid Point")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 3, 128, "Mid Point")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 4, 0, "Turn amplifier off")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 4, 2, "Turn amplifier on, Volume normal and speakers off")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 4, 5, "Turn amplifier on, Volume at pre-set and speakers off")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 4, 7, "Turn amplifier on, Volume at pre-set and speakers on")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 4, 255, "Turn amplifier on, Volume normal and speakers on")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 0, "Source 1")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 1, "Source 2")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 2, "Source 3")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 3, "Source 4")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 4, "Source 5")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 5, "Source 6")
   addlevelnode(slot0, slot5, uv0.name2app.AUDIO_APP, slot4, 5, 6, "Source 7")

   return true
end

function slot11(slot0, slot1, slot2)
   slot3 = bit.band(bit.rshift(slot1, 8), 255)

   if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"A\" AND net = ? LIMIT 1", uv0.name2app.MEDIA_TRANSPORT_APP, bit.band(bit.rshift(slot1, 16), 255)) == nil then
      res = slot0:insert("cbus_tag_map", {
         net = slot4,
         tagtype = "A",
         tag = "MTC",
         tagid = uv0.name2app.MEDIA_TRANSPORT_APP
      })
   end

   if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"G\" AND net = ? AND app = ? LIMIT 1", slot3, slot4, uv0.name2app.MEDIA_TRANSPORT_APP) == nil then
      res = slot0:insert("cbus_tag_map", {
         net = slot4,
         app = uv0.name2app.MEDIA_TRANSPORT_APP,
         tagtype = "G",
         tag = "Media Link Group " .. slot3,
         tagid = slot3
      })
   end

   slot6, slot7 = nil

   for slot11, slot12 in pairs(uv0.MTCFunctions) do
      if slot0:getone("SELECT id FROM cbus_tag_map WHERE tagid = ? AND tagtype = \"S\" AND net = ? AND app = ? AND grp = ? LIMIT 1", slot11, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3) == nil then
         res = slot0:insert("cbus_tag_map", {
            net = slot4,
            app = uv0.name2app.MEDIA_TRANSPORT_APP,
            tagtype = "S",
            grp = slot3,
            tag = slot12,
            tagid = slot11
         })
      end
   end

   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 0, 0, "Stop")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 0, 1, "Play")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 1, 0, "Pause")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 1, 255, "Resume")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 5, 0, "Shuffle off")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 5, 255, "Shuffle on")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 6, 0, "Repeat off")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 6, 1, "Repeat current")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 6, 255, "Repeat all")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 0, "Normal speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 2, "2x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 4, "4x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 6, "8x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 8, "16x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 10, "32x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 7, 12, "64x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 0, "Normal speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 2, "2x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 4, "4x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 6, "8x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 8, "16x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 10, "32x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 8, 12, "64x speed")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 9, 0, "Source power off")
   addlevelnode(slot0, slot4, uv0.name2app.MEDIA_TRANSPORT_APP, slot3, 9, 255, "Source power on")

   return true
end

function slot2._afternewobjhook(slot0, slot1, slot2)
   sendcustom(require("localbus"), "afternewobjhook", "reload_app_list")

   if bit.band(bit.rshift(slot1, 24), 255) == uv0.name2app.SECURITY_APP then
      return uv1(slot0, slot1, slot2)
   elseif slot4 == uv0.name2app.AUDIO_APP then
      return uv2(slot0, slot1, slot2)
   elseif slot4 == uv0.name2app.MEDIA_TRANSPORT_APP then
      return uv3(slot0, slot1, slot2)
   elseif slot4 == uv0.name2app.ERROR_APP then
      sendcustom(slot3, "afternewobjhook", "reload_error_app")
   end

   return true
end

function slot2._afterdelobjhook(slot0)
   sendcustom(require("localbus"), "afterdelobjhook", "reload_app_list")

   if bit.band(bit.rshift(slot0, 24), 255) == uv0.name2app.ERROR_APP then
      sendcustom(slot1, "delobj", "reload_error_app")
   end
end

function slot2._setvaluehook(slot0, slot1, slot2)
   return true
end

function slot12(slot0, slot1, slot2)
end

function slot2.getgroupforapp(slot0, slot1, slot2)
   if slot0 == uv0.name2app.TESTING2_APP or slot0 == uv0.name2app.ERROR_APP then
      return bit.bor(bit.lshift(slot1, 8), slot2)
   else
      return slot1
   end
end

function slot2.getvalueastext(slot0, slot1)
   if bit.band(bit.rshift(slot0, 24), 255) == uv0.name2app.ENABLE_APP or slot2 == uv0.name2app.TRIGGER_APP then
      return tostring(slot1.value)
   elseif slot2 == uv0.name2app.AUDIO_APP then
      return nil
   elseif slot2 == uv0.name2app.MEDIA_TRANSPORT_APP then
      return nil
   elseif slot2 == uv0.name2app.NETWORK_CONTROL_APP or slot2 == uv0.name2app.MEASUREMENT_APP then
      return tostring(slot1.value) .. " " .. tostring(slot1.unitstxt)
   elseif slot2 == uv0.name2app.ERROR_APP then
      if slot1.network ~= nil then
         slot3 = slot1.sysidstr .. "@" .. slot1.devid .. "/" .. slot1.network
      end

      if slot1.channel ~= nil then
         slot3 = slot3 .. slot1.channel .. "/"
      end

      if slot1.error ~= nil then
         slot3 = slot3 .. uv0.error_severity[slot1.severity] .. "/" .. slot1.error
      end

      if slot1.ackd then
         slot3 = slot3 .. " (ack)"
      end

      return slot3
   elseif slot2 == uv0.name2app.SECURITY_APP then
      -- Nothing
   elseif uv0.islightinglike(slot2) then
      if slot1.level == slot1.target then
         return tostring(slot1.level)
      else
         return slot1.level .. " -> " .. slot1.target .. "(" .. slot1.ramprate .. "s)"
      end
   else
      return nil
   end
end

function slot2.file_exists(slot0)
   if io.open(slot0, "r") ~= nil then
      io.close(slot1)

      return true
   else
      return false
   end
end

function slot2.disablesniffer()
   uci.set("genohm-scada", "core", "autoadd", "0")
   uci.commit("genohm-scada")
   uci.unload("genohm-scada")
   lmscripting.reloadgroupmonitor(true)
   log(10, "set uci autoadd to 0")
end

return slot2
  • Author
  • Localization

DimondDingBag98, posted Mon Mar 13, 2023 10:13 pm (75861)


Thanks, Which decompilers would be recomend? I'd like to replicate the process myself to get a better understanding for future.

I did try unluac but i wasnt successful in having it handle the luajit file, perhaps i was doing something wrong. i also tried luajit-decomp but it kept throwing erros [ variable must be type of object ] [ subscript used with non array variables ]

Is it at all possible to retrieve the names also or are these permantly lost once the source is converted to bytecode?
  • Author
  • Localization

atom0s, posted Tue Mar 14, 2023 2:01 am (75867)


The one I used for that file was: https://gitlab.com/znixian/luajit-decompiler

You need to make sure whichever one you are using is specifically made to support LuaJIT. Stock Lua decompilers like unluac won't work as the byte code generated by Lua and LuaJIT are not the same or compatible with each other.

In regards to restoring naming, that ultimately depends on the file and how it was compiled. If information was stripped out, then generally the bytecode will be optimized to not include additional 'junk' data that is not needed. Generally, names for functions and variables will be lost if they are not 'critical' to the operation of the file. The only time they are usually left in is if the file is compiled with debug information/symbols left on so that it can be easily debugged when ran.
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.