Decode an ORA file

This will decode an ORA file and send it out in CSV format.  Not completed, but it works sending it to the screen

#include 

Global $sFileRead
Read_TNS_File("TNSNAMES.ORA")

Func Read_TNS_File($ThisFilename)
    Local $hFileOpen = FileOpen($ThisFilename, $FO_READ)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
        Return False
    EndIf
	Local $sFileRead = FileRead($hFileOpen)
	$sFileRead = StringRegExpReplace($sFileRead,"\#.*[\r\n|\r|\n]","") ; remove all comments
	$sFileRead = stringStripws($sFileRead,8) ; remove all whitespace/CR/LF

	;consolewrite($sFileRead & @crlf)
	$sFileRead = BreakApart($sFileRead)
	ConsoleWrite('"NetServiceName","Protocol","Host","Port","Sid","Server"' & @crlf)
	consolewrite($sFileRead & @crlf)
	FileClose($hFileOpen)
EndFunc

func BreakApart($s)
	Local $s2
	Local $Net_Services_Name = StringRegExpReplace($s,"(.)(=)(.*)","$1") ; find the first equal sign
	$Results = '"' & $Net_Services_Name & '"'

	$Protocol = StringRegExpReplace($s,"(?i)(.*?)(\(protocol=)(.*?)(\).*)","$3") ; find the Protocol
	$Results = $Results & ',"' & $Protocol & '"'

	$Host = StringRegExpReplace($s,"(?i)(.*?)(\(host=)(.*?)(\).*)","$3")
	$Results = $Results & ',"' & $Host & '"'

	$Port = StringRegExpReplace($s,"(?i)(.*?)(\(port=)(.*?)(\).*)","$3")
	$Results = $Results & ',"' & $Port & '"'

	$Sid = StringRegExpReplace($s,"(?i)(.*?)(\(sid=)(.*?)(\).*)","$3")
	$Results = $Results & ',"' & $Sid & '"'

	$Server = StringRegExpReplace($s,"(?i)(.*?)(\(server=)(.*?)(\).*)","$3")
	$Results = $Results & ',"' & $Server & '"'

	$EntireEntry = StringRegExpReplace($s,"(^.*?\))(\w*?=)(.*)","$1") ; find the entire entry

	$Remainder = stringRight($s, stringlen($s) - StringLen($EntireEntry))
	if $Remainder  "" then $Results = $Results & @CRLF & BreakApart($Remainder) ; Recursively call the same routine
	Return $Results
EndFunc

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s