• 沒有找到結果。

5 系統實作與呈現

5.4 程式原始碼剖析

5.4.1 使用者介面

程式碼剖析的使用者介面設計如下圖 5.2,系統設計為可允許剖析多個系統 (或模組),剖析的程式原始碼。程式碼的檔案種類,可於資料表中設定,本研究 的資料來源主要以 asp、aspx 及 vb 三種檔案類型的資料為主,對於其他程式語 言(如 C++、JAVA、PHP…等),可於資料表(CONJ)中,設定其相關的程式語法即 可進行剖析,資料表(CONJ)設定如下圖 5.3。程式碼來源,可依使用者選擇剖析 某個檔案或某個目錄下的檔案。若程式碼存在於子目錄中,可勾選「包含子目 錄」,將一併以下所有子目錄下的所有檔案進行剖析。

圖 5.2 程式碼剖析使用者介面

圖 5.3 各程式語法設定資料表

c_sType:程式原始碼檔案之附檔名。

c_symbol:該程式語法多行連結符號。

c_comment:該程式語法註解的符號。

c_string:該程式語法字串連結符號。

5.4.2 程式演算法

依 4.1 設計的程式流程圖,實作剖析的程式演算法如下:

5.4.2.1 剖析原始碼中新增資料的資訊(INSERT)

剖析原始碼中新增資料的資訊(INSERT)的 pseudocode 如下,程式以逐行讀 取原始碼檔案的方式進行,首先判斷此行不是註解,判斷含有”INSERT”資料新 增操作的關鍵字,再判斷含有”VALUES”關鍵字,從”INSERT”後,以空白字元為 分隔,判斷第一個陣列的值是否為”INTO”,若不是,此第一個陣列的值,即為

資料表的名稱;若是,則從”INTO”後,以空白字元分隔,取出第一個陣列的值,

過濾”(”字元,即為所要的資料表名稱。因程式允許重複執行,判斷若資料庫尚 未存在此資料表資訊,則存入此資訊。之後剖析此資料表的相關欄位,

從”INSERT”關鍵字後,以”)”字元分隔,判斷第一個陣列值含有”VALUES”關鍵 字,以”(”字元分隔,取出第二個陣列之值並以”,”分隔,即得到此資料表相關欄 位的陣列,同樣的判斷若資料庫尚未存在此欄位資訊,則存入此資訊。

Pseudocode:

if the line is not comment

if the line containing keyword “INSERT ” if the line containing keyword “ VALUES”

split with the delimiter “ ” after the keyword “INSERT ” if the value of the first array is “INTO”

split with the delimiter “ ” after the keyword “ INTO”

get the value of the first array if it containing the character “(”

split with delimiter “(”

get the value of the first array end if

else

get the value of the first array

end if

if the tablename had not been existed in the source code insert the tablename into the database

split with delimiter “)” after the keyword “INSERT ”

if the value of the first array not containing keyword “ VALUES”

split it with delimiter “(”

split the value of the second array with delimiter “,”

if the fields had not been existed in this tablename insert the fields into the database

end if end if

end if

end if end if

end if

5.4.2.2 剖析原始碼中修改資料的資訊(UPDATE)

剖析原始碼中修改資料的資訊(UPDATE)的 pseudocode 如下,程式以逐行讀 取原始碼檔案的方式進行,首先判斷此行不是註解,判斷含有” UPDATE”資料修 改操作的關鍵字,再判斷含有”SET”關鍵字,從” UPDATE”後,以空白字元為分 隔,取出第一個陣列的值,過濾”(”字元,即為資料表的名稱,因程式允許重複 執行,判斷若資料庫尚未存在此資料表資訊,則存入此資訊。之後剖析此資料表 的相關欄位,取出從”SET”關鍵字之後的字串,判斷是否含有”WHERE”關鍵字,

若有則取出”SET”與”WHERE”之間的字串,以”,”字元分隔後,再以”=”分隔,即 得到此資料表相關欄位的陣列,同樣的判斷若資料庫尚未存在此欄位資訊,則存 入此資訊。

Pseudocode:

if the line is not comment

if the line containing keyword “UPDATE ” if the line containing keyword “SET ”

split with the delimiter “ ” after the keyword “UPDATE ” get the value of the first array

if it containing the character “(”

split with delimiter “(”

get the value of the first array

end if

if the tablename had not been existed in the source code insert the tablename into the database

get the string after the keyword “SET ”

if the former string containing the keyword “WHERE ” get the substring between “SET ” and “WHERE ”

end if

split the result string with delimiter “,”

if the subarray containing the character “=”

split the subarray with delimiter “=”

if the fields had not been existed in this tablename insert the fields into the database

end if end if

end if

end if end if end if

5.4.2.3 剖析原始碼中刪除資料的資訊(DELETE)

剖析原始碼中刪除資料的資訊(DELETE)的 pseudocode 如下,程式以逐行讀 取原始碼檔案的方式進行,首先判斷此行不是註解,判斷含有” DELETE”資料刪 除操作的關鍵字,再判斷不是以” DELETE”開頭,判斷” DELETE”關鍵字前一個 字元不屬於英文字元,然後從” DELETE”後,以空白字元為分隔,判斷第一個陣 列的值是否為”FROM”,若不是,此第一個陣列的值,即為資料表的名稱;若是,

則從”FROM”後,以空白字元分隔,取出第一個陣列的值,過濾”(”及”””字元,

即為所要的資料表名稱。因程式允許重複執行,判斷若資料庫尚未存在此欄位資 訊,則存入此資訊。

Pseudocode:

if the line is not comment

if the line containing keyword “DELETE ”

if the line not start with the keyword “DELETE ”

if the character before the keyword “DELETE ” not a English alphabet split with the delimiter “ ” after the keyword “DELETE ”

get the value of the first array

if the value of the first array is the keyword “FROM”

split with the delimiter “ ” after the keyword “FROM ” get the value of the first array

else

get the value of the first array end if

end if

if the acquired value containing the character “(”

get the value before the character “(”

end if

if the acquired value containing the character “””

get the value before the character “””

end if

if the tablename had not been existed in the source code insert the tablename into the database

end if

end if end if end if

相關文件