-
-
Save nnposter/736ff39883e60ec4c92ca2a00ac90652 to your computer and use it in GitHub Desktop.
Fixes the parser for AFP FPGetFileDirParms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/nselib/afp.lua 2020-07-25 13:43:45.000000000 -0600 | |
+++ b/nselib/afp.lua 2020-08-01 21:01:20.000000000 -0600 | |
@@ -2002,6 +2002,7 @@ | |
-- @return pos number containing the new offset after decoding | |
-- @return dir table containing the decoded values | |
decode_dir_bitmap = function( bitmap, data, pos ) | |
+ local origpos = pos | |
local dir = {} | |
if ( ( bitmap & DIR_BITMAP.Attributes ) == DIR_BITMAP.Attributes ) then | |
@@ -2023,23 +2024,35 @@ | |
dir.FinderInfo, pos = string.unpack("c32", data, pos) | |
end | |
if ( ( bitmap & DIR_BITMAP.LongName ) == DIR_BITMAP.LongName ) then | |
- local offset, p, name | |
+ local offset | |
offset, pos = string.unpack(">I2", data, pos) | |
-- TODO: This really needs to be addressed someway | |
-- Barely, never, ever happens, which makes it difficult to pin down | |
-- http://developer.apple.com/mac/library/documentation/Networking/Reference/AFP_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40003548-CH3-CHDBEHBG | |
+ -- | |
+ -- [nnposter, 8/1/2020] URL above not available. Offset below (pos+4) | |
+ -- seems illogical, as it partially covers two separate fields: bottom | |
+ -- half of the file ID and the entire offspring count | |
+ -- Disabled the quirk | |
+ | |
+ --[[ | |
local justkidding = string.unpack(">I4", data, pos + 4) | |
if ( justkidding ~= 0 ) then | |
offset = 5 | |
end | |
+ ]] | |
- dir.LongName = string.unpack("s1", data, offset + pos - 1) | |
+ if offset > 0 then | |
+ dir.LongName = string.unpack("s1", data, origpos + offset) | |
+ end | |
end | |
if ( ( bitmap & DIR_BITMAP.ShortName ) == DIR_BITMAP.ShortName ) then | |
- local offset = string.unpack(">I2", data, pos) | |
- dir.ShortName = string.unpack("s1", data, offset + pos) | |
- pos = pos + 2 | |
+ local offset | |
+ offset, pos = string.unpack(">I2", data, pos) | |
+ if offset > 0 then | |
+ dir.ShortName = string.unpack("s1", data, origpos + offset) | |
+ end | |
end | |
if ( ( bitmap & DIR_BITMAP.NodeId ) == DIR_BITMAP.NodeId ) then | |
dir.NodeId, pos = string.unpack(">I4", data, pos ) | |
@@ -2057,10 +2070,15 @@ | |
dir.AccessRights, pos = string.unpack(">I4", data, pos ) | |
end | |
if ( ( bitmap & DIR_BITMAP.UTF8Name ) == DIR_BITMAP.UTF8Name ) then | |
- local offset = string.unpack(">I2", data, pos) | |
- dir.UTF8Name = string.unpack("s1", data, offset + pos) | |
- pos = pos + 2 | |
+ local offset | |
+ offset, pos = string.unpack(">I2", data, pos) | |
+ if offset > 0 then | |
+ -- +4 to skip over encoding hint | |
+ dir.UTF8Name = string.unpack(">s2", data, origpos + offset + 4) | |
+ end | |
end | |
+ -- Skip over padding | |
+ pos = pos + (16 - (pos - origpos) % 16) % 16 | |
if ( ( bitmap & DIR_BITMAP.UnixPrivileges ) == DIR_BITMAP.UnixPrivileges ) then | |
local unixprivs = {} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment