求Linux c版 ini文件解析 库或者代码

求Linux c版 ini文件解析 库或者代码,第1张

下面是一个VB6的类的源代码,来自国外网站的一个技术专家,类名:CSetting,可以读写ini配置文件,或者读写注册表配置。

Option Explicit

'Settings interface class

'Copyright ?2000 - Stan Schultes

'Written for VBPJ Getting Started September, 2000

'CSetting mode enum

Public Enum csModes

csModeRegistry = 0

csModeINI = 1

End Enum

'class member variables

Private m_eSaveMode As csModes

'module-level variables

Private msININame As String 'name of .INI file

Private msAppName As String 'app name for settings

'INI setting APIs

Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As Long, ByVal FileName As String) As Long

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As String, ByVal ReturnedString As String, ByVal StringSize As Long, ByVal FileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal SectionName As String, ByVal KeyName As String, ByVal KeyValue As String, ByVal FileName As String) As Long

'there is no WritePrivateProfileInt declaration...

'Error definitions

Private Const mklErrOffset As Long = vbObjectError + 512

Private Const mklErrNotNumeric As Long = mklErrOffset + 1

Private Const mksErrNotNumeric As String = "The setting value returned was not numeric"

Private Const mklErrWriting As Long = mklErrOffset + 2

Private Const mksErrWriting As String = "Error writing Setting "

Private Const mklErrReading As Long = mklErrOffset + 3

Private Const mksErrReading As String = "Error reading Setting "

Public Function Init(Optional ByVal AppPath As String, Optional ByVal AppName As Variant, Optional ByVal Mode As csModes = csModeRegistry)

'Set up class variables, default to Registry mode

If IsMissing(AppPath) Then

msININame = App.Path

Else

msININame = Trim$(AppPath)

End If

If IsMissing(AppName) Then

msAppName = App.EXEName

Else

msAppName = Trim$(AppName)

End If

'default to the app's .exe path

msININame = msININame &"\" &msAppName &".ini"

'msININame = App.Path &"\" &msAppName &".ini"

SaveMode = Mode

End Function

Public Function GetSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As String) As String

'returns a string setting

Dim lRet As Long

Dim sBuf As String * 128

On Error GoTo GetSettingStr_Error

If Len(msAppName) = 0 Then Init

Select Case m_eSaveMode

Case csModeRegistry

GetSettingStr = GetSetting(msAppName, Section, KeyName, DefaultValue)

Case Else

lRet = GetPrivateProfileString(Section, KeyName, DefaultValue, sBuf, Len(sBuf), msININame)

GetSettingStr = TrimNull(sBuf)

End Select

GetSettingStr_Exit:

Exit Function

GetSettingStr_Error:

Err.Raise mklErrReading, "CSetting.GetSettingStr", mksErrReading &"(" &Err &", " &Error &")"

End Function

Public Function GetSettingInt(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As Integer) As Integer

'returns a numeric setting

Dim sSetting As String

On Error GoTo GetSettingInt_Error

If Len(msAppName) = 0 Then Init

Select Case m_eSaveMode

Case csModeRegistry

sSetting = GetSetting(msAppName, Section, KeyName, CStr(DefaultValue))

'check if value is numeric

If IsNumeric(sSetting) Then

GetSettingInt = CInt(sSetting)

Else

'match behavior of .INI return

GetSettingInt = 0

'or - return error if desired

'On Error GoTo 0 'disable handler to return error

'Err.Raise mklErrNotNumeric, "CSetting.GetSettingInt", mksErrNotNumeric

End If

Case Else

'returns 0 if not numeric

GetSettingInt = GetPrivateProfileInt(Section, KeyName, DefaultValue, msININame)

End Select

GetSettingInt_Exit:

Exit Function

GetSettingInt_Error:

Err.Raise mklErrReading, "CSetting.GetSettingInt", mksErrReading &"(" &Err &", " &Error &")"

End Function

Public Sub SaveSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal Setting As String)

'saves a string setting

Dim lRet As Long

On Error GoTo SaveSettingStr_Error

If Len(msAppName) = 0 Then Init

Select Case m_eSaveMode

Case csModeRegistry

SaveSetting msAppName, Section, KeyName, Setting

Case Else

lRet = WritePrivateProfileString(Section, KeyName, Setting, msININame)

End Select

SaveSettingStr_Exit:

Exit Sub

SaveSettingStr_Error:

Err.Raise mklErrWriting, "CSetting.SaveSettingStr", mksErrWriting &"(" &Err &", " &Error &")"

End Sub

Public Sub SaveSettingInt(ByVal Section As String, ByVal KeyName As String, Setting As Integer)

'saves a numeric setting

Dim lRet As Long

On Error GoTo SaveSettingInt_Error

If Len(msAppName) = 0 Then Init

Select Case m_eSaveMode

Case csModeRegistry

SaveSetting msAppName, Section, KeyName, CStr(Setting)

Case Else

lRet = WritePrivateProfileString(Section, KeyName, CStr(Setting), msININame)

End Select

SaveSettingInt_Exit:

Exit Sub

SaveSettingInt_Error:

Err.Raise mklErrWriting, "CSetting.SaveSettingInt", mksErrWriting &"(" &Err &", " &Error &")"

End Sub

Public Property Let SaveMode(Mode As csModes)

'sets save mode, see csModes enum

m_eSaveMode = Mode

End Property

Public Property Get SaveMode() As Long

'returns save mode

SaveMode = CLng(m_eSaveMode)

End Property

Private Function TrimNull(ByVal InString As String) As String

'trims string at first Null character

Dim lPos As Long

TrimNull = Trim$(InString)

lPos = InStr(TrimNull, vbNullChar)

If lPos >0 Then TrimNull = Left$(TrimNull, lPos - 1)

End Function

Private Sub Class_Initialize()

msININame = App.Path &"\" &App.EXEName &".ini"

End Sub

使用方法:

在程序的全局模块中定义CSetting的类实例变量:(以下定义了两个,分别读写ini和注册表)

Public SetIniAs CSetting '读写ini配置文件参数 '

Public SetRegAs CSetting'读写注册表配置参数

在sub main 中初始化:(其中PATH_EXE是你的程序路径,放ini文件的路径)

Set SetIni = New CSetting

SetIni.Init PATH_Exe, App.Title, csModeINI

Set SetReg = New CSetting

SetReg.Init PATH_Exe, App.Title, csModeRegistry

这就可以随便用了。

dbPassword = SetIni.GetSettingStr(NameDB, "Password", "111111")

dbUserID = SetIni.GetSettingStr(NameDB, "UserID", "123456")

dbCatalog = SetIni.GetSettingStr(NameDB, "Catalog", "aaa")

dbDataSource = SetIni.GetSettingStr(NameDB, "DataSource", sky)

cnStr= "Provider=SQLOLEDB.1Password=" &dbPassword &"Persist Security Info=TrueUser ID=" &dbUserID &"Initial Catalog=" & dbCatalog &"Data Source=" &dbDataSource '

其它由你自己补充了。

可以用黑刀dezender来试试,我不担保可以解出来的哦,

从黑刀dezender4.3版之后,将着力对混淆函数以及自定义函数的解密进行应对。

大家下载压缩包并解压后,会发现有一个“config.ini”的文件,这就是混淆函数库啦!

打开后,可自行编辑其中的内容,当然,也可以通过黑刀dezender的升级程序直接下载官方最新的混淆函数库文件。这个混淆函数库就相当于是一个字典文件了,在保证格式不变的情况下,大家可以在下载《黑刀超级字典生成器》生成字典来挂入主程序进行解密,正确步骤为:先备份、改名自己的config.ini文件,生成的字典文件在第一行加入“[obfuscate_name]”,将字典文件改名为config.ini,开始解密。

同时,黑刀部落网站的“项目中心”栏目也开设了用户提交自己已知程序被混淆的函数列表,这样的话,就能让dezender变得越来越强了。再也不怕混淆函数了。呵呵。

什么是混淆函数?混淆函数,是从zend

guard

4.0之后新增的一项功能,能把php文件中的所有函数名都进行混淆,混淆后变成以“_obfuscate_”开头的一串“乱码”,这种加密方式感觉有点类似md5,因为函数名已经不是原来的样子了,所以解密出来的php文件是不能正常执行的。黑刀dezender在4.3版之后,新增加了挂入混淆函数库参与解密的功能,而混淆函数库,就像是一个包含了已知函数名的字典,利用这个字典,来与被混淆了的函数名(就是所谓的“乱码”)进行比对,如果比对结果相同,则解密出来的文件,基本上就可以恢复到加密前的样子了。如果混淆函数库中没有包含该php文件中使用的函数名,那么解密结果依然还是会存在“乱码”的。掌握了这个原理,我们就可以去想办法解决问题了。

方式有以下几种:

第一,使用黑刀超级字典生成器产生一个字典,字典的内容可以自己把握,修改字典文件名为“config.ini”,然后打开字典文件,在第一行插入“[obfuscate_name]”标记(注意,方括号也是需要的,也就是引号内的内容都要加进去),将字典文件拷贝入黑刀dezender主程序所在目录,同时注意备份原有的config.ini文件。这种办法费时费力,也要看运气,不过却是最实际的解决办法。

第二,常看别人源代码的朋友,可以把自己已经掌握了的混淆函数的真实函数名提交到我的网站上来。 *** 作步骤:进入网站首页,进入项目中心的“dezender混淆函数库更新表”,提交。我会定期查看大家提交上来的数据,加入到官方的混淆函数库中,不断的增强和完善官方混淆函数库,大家可以利用黑刀dezender的自动升级功能对其进行升级!

如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!

vae

la


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11592037.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存