如何除錯和分析Luci

2021-08-19 23:16:47 字數 1972 閱讀 3355

最近把luci**深入地剖析了一遍.說實話剛開始看的時候也是雲裡霧裡,特別是dispatch函式, 這其間也是參考了幾篇文章, 特此感謝.

剛開始看luci**確實就和逆向沒啥區別, 需要揣摩作者對於各個變數的用途. 於是我就想了乙個辦法, 就是把每個變數都列印出來.

為此我在/usr/lib/lua/luci目錄下引入了log.lua模組:

local m = {}

local tconcat = table.concat

local tinsert = table.insert

local srep = string.rep

local function local_print(str)

local dbg = io.open("/tmp/luci.output", "a+")

local str = str or ""

if dbg then

dbg:write(str..'\n')

dbg:close()

endendfunction m.print(...)

local dbg = io.open("/tmp/luci.output", "a+")

if dbg then

dbg:write(os.date("[%h:%m:%s]: "))

for _, o in ipairs() do

dbg:write(tostring(o)..' ')

enddbg:write("\n")

dbg:close()

endendfunction m.print_r(data, depth)

local depth = depth or 3

local cstring = "";

local top_flag = true

local function table_len(t)

local i = 0

for k, v in pairs(t) do

i = i + 1

endreturn i

endlocal function tableprint(data,cstring, local_depth)

if data == nil then

local_print("core.print data is nil");

end

local cs = cstring .. " ";

if top_flag then

local_print(cstring .."")

elseif local_depth < depth then

local_print(cs..tostring(k).." = ")

endend

else

local_print(cs..tostring(data));

end

local_print(cstring .."}");

end

tableprint(data,cstring,0);

endreturn m

你可以在luci目錄下任何乙個地方呼叫

local log = require "luci.log"  

log.print("hello world")

log.print_r()

另外, log模組將輸出資訊到/tmp/luci.ouput下面, 我們可以用tail命令跟蹤.

# tail -f /tmp/luci.output
於是通過這個小小的模組, 得以一窺這個openwrt上著名的程式. 確實很有趣, 有時間我會詳細的把luci框架分析寫下來.

另外luci程式自帶了乙個debug模組, 這是乙個用來分析記憶體占用情況的模組, 你也可以在dispatcher.lua模組中開啟.它的資訊記錄在/tmp/memtrace中.

參考**

Luci流程分析(openwrt下)

在openwrt檔案系統中,lua語言的 不要編譯,類似一種指令碼語言被執行,還有一些uhttpd伺服器的主目錄,它們是 網頁請求格式基本都如下所示 說明處理都在伺服器的預設 下的 cgi bin luci檔案進行處理。luci.dispatcher.indexcache tmp luci inde...

windowsclient崩潰分析和除錯

本文介紹windows上崩潰分析的一些手段,順便提多程序除錯 死鎖等。1.崩潰分析過程 1.1 確認錯誤碼 不管是用windbg還是用vs。首先應該注意的是錯誤碼,而90 以上的崩潰都是非法訪問。在非法訪問時。能夠看一下訪問的目標位址。位址是0,或者離0非常近 0x00000008或0xffffff...

core檔案如何檢視和除錯

除錯linux程式的時候,出現segmentation fault是最鬱悶的事情了,程式 量很大的時候,可能花很多時間都找不到出錯原因。這裡介紹一種對你除錯segmentation fault很有幫助的方法,可能能迅速幫助你找到出錯的 行。這種方法需要用到linux提供的core dump機制 當程...