AutoHotkey -(有效地)存储信息

AutoHotkey - (Effectively) Store information

我一直使用 .ini 文件来存储由我的 AutoHotkey 脚本生成的信息,之后用 FileSetAttrib 隐藏它们。.ini 文件很棒,我唯一担心的是用户找到该文件并更改其中存储的信息。

我记得读过一些关于 .dll 文件和 Data Streams 的内容,但我不知道从哪里开始或如何开始,因为没有那么多 "tutorials" 或文档文章。

当尝试存储用户不应更改的信息时,你们如何处理这个问题?

我真的不明白将信息存储在 dll 文件中只是为了隐藏它的意义。一旦用户查看了您的代码(是的,您可以反编译 ahk 可执行文件),他可以简单地复制更改 dll 内容所需的代码。除此之外,他可能只是使用资源黑客来修改它。
考虑使用RegWrite and RegRead if you don't want the information to be in a simple file. If you really think it gets you anywhere store the data encrypted,阅读时解密。

使用 AutoHotkey 加密设置也没有多大意义:在这种情况下不值得付出努力。

我建议简单地将设置编码为不太明显的内容。请记住,如果用户想要更改某些内容,请假设他们能够(取决于他们的足智多谋)。像 Base64 这样的东西应该可以满足你的需要。

示例脚本

使用这个库:base64.ahk

;Say you have a `decodefile()` and `encodefile()` function:

#Include base64.ahk
decodefile(filepath) {
  FileRead, rawData, %filepath%
  decoded := b64Decode(rawData)

  ; save decoded file first, in case of crash
  tempfile := "tempfile.tmp"
  FileDelete, %tempfile%
  FileAppend, %decoded%, %tempfile%
  
  ; replace original
  FileDelete, %filepath%
  FileMove, %tempfile%, %filepath%
}
encodefile(filepath) {
  FileRead, rawData, %filepath%
  encoded := b64Encode(rawData)

  ; save encoded file first, in case of crash
  tempfile := "tempfile.tmp"
  FileDelete, %tempfile%
  FileAppend, %encoded%, %tempfile%
  
  ; replace original
  FileDelete, %filepath%
  FileMove, %tempfile%, %filepath%
}

;then you can simply read the ini file, like usual.
settingsfile := "myfile.ini"
decodefile(settingsfile )
IniRead, OutputVar, %settingsfile%, section, key

;on exit, save would look like this
settingsfile := "myfile.ini"
encodefile(settingsfile)