From 2c4e61d0ed03f3c49a7b65c88d4bb582ce1d0719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sun, 13 Mar 2022 14:22:49 +0200 Subject: [PATCH] remove redundant sections --- README.md | 10 +++++----- src/sections.zig | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 98418ed..57bef21 100644 --- a/README.md +++ b/README.md @@ -357,11 +357,11 @@ bdz_gid ? bdz(gid) bdz_groupname ? bdz(groupname) bdz_uid ? bdz(uid) bdz_username ? bdz(username) -idx_gid2group len(group)*29/8 bdz->offset Groups -idx_groupname2group len(group)*29/8 bdz->offset Groups -idx_uid2user len(user)*29/8 bdz->offset Users -idx_name2user len(user)*29/8 bdz->offset Users -idx_username2gids len(user)*29/8 bdz->offset UserGids +idx_gid2group len(group)*4 bdz->offset Groups +idx_groupname2group len(group)*4 bdz->offset Groups +idx_uid2user len(user)*4 bdz->offset Users +idx_name2user len(user)*4 bdz->offset Users +idx_username2gids len(user)*4 bdz->offset UserGids shellIndex len(shells)*2 shell index array shellBlob <= 4032 shell data blob (max 63*64 bytes) groups ? packed Group entries (8b padding) diff --git a/src/sections.zig b/src/sections.zig index 42944db..bd07010 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -22,6 +22,7 @@ const bdz = @import("bdz.zig"); const User = userImport.User; const Group = groupImport.Group; const ShellSections = shellImport.ShellWriter.ShellSections; +const ShellReader = shellImport.ShellReader; const Corpus = struct { arena: std.heap.ArenaAllocator, @@ -391,8 +392,7 @@ pub const AllSections = struct { bdz_username: []const u8, users: UsersSection, shell_sections: ShellSections, - shell_index: []const u8, - shell_blob: []const u8, + shell_reader: ShellReader, user_gids: UserGids, group_members: GroupMembers, groups: GroupsSection, @@ -406,8 +406,6 @@ pub const AllSections = struct { const bdz_uid = try bdzUid(allocator, corpus); const bdz_username = try bdzUsername(allocator, corpus); const shell_sections = try shellSections(allocator, corpus); - const shell_index = shell_sections.index; - const shell_blob = shell_sections.blob; const user_gids = try userGids(allocator, corpus); const users = try usersSection( allocator, @@ -425,6 +423,11 @@ pub const AllSections = struct { corpus, group_members.idx2offset, ); + const shell_reader = shellImport.ShellReader.init( + mem.sliceAsBytes(shell_sections.index.constSlice()), + mem.sliceAsBytes(shell_sections.blob.constSlice()), + ); + return AllSections{ .allocator = allocator, .bdz_gid = bdz_gid, @@ -432,8 +435,7 @@ pub const AllSections = struct { .bdz_uid = bdz_uid, .bdz_username = bdz_username, .shell_sections = shell_sections, - .shell_index = mem.sliceAsBytes(shell_index.constSlice()), - .shell_blob = mem.sliceAsBytes(shell_blob.constSlice()), + .shell_reader = shell_reader, .user_gids = user_gids, .users = users, .group_members = group_members, @@ -583,8 +585,11 @@ test "test groups and group members" { try testing.expectEqual(it.next(), null); } - //var it = userImport.PackedUserHash.iterator(sections.groups.blob); - //_ = it; + var it = userImport.PackedUser.iterator( + sections.users.blob, + sections.shell_reader, + ); + _ = it; } test "userGids" {