纯 MoonBit 实现的 Windows 注册表 hive(REGF)读取与写入库,不依赖 Windows API
moon add Xcsa-ee/moonregfimport {
"Xcsa-ee/moonregf",
}match @moonregf.parse_header(bytes) {
Ok(header) => println(header.file_name)
Err(error) => println(error.message())
}for entry in @moonregf.walk_key_tree(bytes, header.root_cell_offset, 3) {
println(entry.path)
}
match @moonregf.list_values(bytes, key) {
Ok(values) => for value in values { println(value.name + " = " + value.data_type.label()) }
Err(error) => println(error.message())
}let builder = @moonregf.HiveBuilder::new()
let software = builder.add_key(0, "Software")
builder.set_string(software, "Install", "Hello")
builder.set_dword(software, "Count", 42)
match builder.build() {
Ok(bytes) => println(bytes.length())
Err(error) => println(error.message())
}match @moonregf.parse_reg_bytes(raw) {
Ok(file) => match file.to_builder() {
Ok(builder) => builder.build()
Err(error) => println(error.message())
}
Err(error) => println(error.message())
}moon run cmd/main -- <path-to-NTUSER.DAT>
moon run cmd/main -- <path-to-NTUSER.DAT> --values
moon run cmd/main -- --build demo.hive
moon run cmd/main -- --import-reg backup.reg rebuilt.hive
moon run cmd/main -- --export-reg rebuilt.hive out.reg HKEY_CURRENT_USER
moon run cmd/main -- --replay-log dirty.hive dirty.hive.LOG1 clean.hivemoon run examples/basicfn HiveBuilder::set_string(self : HiveBuilder, key_index : Int, name : String, text : String) -> Unitfn HiveBuilder::set_value(self : HiveBuilder, key_index : Int, name : String, data_type : HiveValueType, data : Bytes) -> Unitpub(all) struct HiveCell {
offset : UInt
payload_size : Int
allocated : Bool
}pub(all) enum HiveFileType {
Primary
Log
External
Unknown(UInt)
}pub(all) struct HiveHeader {
primary_sequence : UInt
secondary_sequence : UInt
last_written_high : UInt
last_written_low : UInt
major_version : UInt
minor_version : UInt
file_type : HiveFileType
file_format : UInt
root_cell_offset : UInt
hive_bins_data_size : UInt
clustering_factor : UInt
file_name : String
checksum : UInt
}pub(all) struct HiveKeyEntry {
path : String
offset : UInt
subkey_count : Int
value_count : Int
}pub(all) struct HiveKeyNode {
offset : UInt
flags : UInt
last_written_high : UInt
last_written_low : UInt
access_bits : UInt
parent_offset : UInt
subkey_count : UInt
volatile_subkey_count : UInt
subkey_list_offset : UInt
volatile_subkey_list_offset : UInt
value_count : UInt
value_list_offset : UInt
security_offset : UInt
class_name_offset : UInt
name_length : UInt
class_name_length : UInt
name : String
}pub(all) struct HiveSubkeyList {
offset : UInt
kind : SubkeyListKind
count : Int
key_offsets : Array[UInt]
}pub(all) struct HiveValue {
offset : UInt
name : String
data_type : HiveValueType
data_size : UInt
data_offset : UInt
inline_data : Bool
data : Bytes
}pub(all) enum HiveValueType {
Nil
Sz
ExpandSz
Binary
Dword
DwordBigEndian
Link
MultiSz
ResourceList
FullResourceDescriptor
ResourceRequirementsList
Qword
Unknown(UInt)
}pub(all) struct LogEntry {
sequence : UInt
bins_data_size : UInt
size : Int
pages : Array[LogPageRef]
data : Bytes
}pub(all) struct LogPageRef {
offset : UInt
size : Int
}pub(all) struct LogReplay {
bytes : Bytes
applied : Int
final_sequence : UInt
}pub(all) enum RegfError {
TooShort(Int)
BadSignature(String)
BadChecksum(UInt, UInt)
BadCellOffset(Int)
BadCellSize(Int)
BadKeyNode(Int)
BadSubkeyList(Int)
BadValue(Int)
BadValueData(Int)
UnsupportedName(Int)
ValueTooLarge(Int)
BadRegFile(String)
UnsupportedDelete(String)
NotALogFile(UInt)
UnsupportedLogVersion(UInt)
BadLogEntry(Int)
BadLogPage(Int)
}pub(all) enum SubkeyListKind {
FastLeaf
HashLeaf
IndexLeaf
RootIndex
Unknown(String)
}fn decode_single_byte(bytes : Bytes, offset : Int, count : Int) -> Stringfn decode_utf16le(bytes : Bytes, offset : Int, unit_count : Int) -> Stringfn read_u16_le(bytes : Bytes, offset : Int) -> UIntfn read_u32_le(bytes : Bytes, offset : Int) -> UIntInstall
Download zip纯 MoonBit 实现的 Windows 注册表 hive(REGF)读取与写入库,不依赖 Windows API