Extracts Extended Attributes From a File and Dumps them

Скачать скрипт.

/* Extracts Extended Attributes From a File and Dumps them */
/* $Header:   V:/SUEPVCS/GENERAL/EADUMP.CMV   1.0   04 Aug 1994 13:25:44   Dennis_Bareis  $ */

/*--- Validate and process parameters ---------------------------------------*/
Args = ARG(1);
Args = strip(Args);                  /* Remove leading & trailing whitespace */
PARSE VAR Args SourceFile RequestedDumpFile ExtraNotWanted;
if  SourceFile = "" then
do
    call SyntaxError "ERROR: Expected you to supply name of a file whose EAs should be dumped", 255;
end;
if  RequestedDumpFile = "" then
do
    DeleteDumpFile = 'Yes';
    EaDumpFile     = "EADUMP_O.TMP";
end;
else
do
    DeleteDumpFile = 'No';
    EaDumpFile     = RequestedDumpFile;
end;
if  ExtraNotWanted <> "" then
do
    call SyntaxError "ERROR: Expect 1 OR 2 parameters, you supplied too many", 254;
end;

/*--- Get the Extended Attributes into a temporary file ---------------------*/
FirstByte = substr(SourceFile, 1, 1);
if FirstByte = '*' then
do
    /*--- We already have an extended attribute file check cmd line! --------*/
    if DeleteDumpFile = 'No' then
    do
       call SyntaxError "ERROR: You supplied name of EA dump file, so can't supply 2nd parm.", 253;
    end;

    DeleteDumpFile = 'No'
    EaDumpFile     = substr(SourceFile, 2);
end;
else
do
    /*--- Create the Extended attribute file --------------------------------*/
    Value        = substr(SourceFile, 2);
    EaDumpOutFile  = "EADUMP_R.TMP";
    '@echo off'
    Cmd = 'EAUTIL.EXE 'SourceFile" "EaDumpFile' /P /S /R';
    Cmd ' >'EaDumpOutFile" 2>&1"
    if  RC = 0 then
        'del 'EaDumpOutFile" >nul 2>&1";
    else
    do
        say   "ERROR   : OS/2 EAUTIL command failed, Rc = "RC'';
        say   "COMMAND : "Cmd;
        say   "RETURNED:";
        say   "~~~~~~~~";
        'type 'EaDumpOutFile;
        'del  'EaDumpOutFile" >nul 2>&1";
        exit  Rc;
    end;
end;

/*--- Make sure that the file had extended attributes -----------------------*/
if    stream(EaDumpFile, 'c', 'query exists') = "" then
do
      say 'The files does not have any extended attributes';
      Exit 1;
end;

/*--- Process the produced file ---------------------------------------------*/
call  ProcessEaFile EaDumpFile;

/*--- Close the FBSS return code --------------------------------------------*/
Dummy = stream(EaDumpFile, 'c', 'close');


/*--- Delete temporary files ------------------------------------------------*/
if DeleteDumpFile = 'Yes' then 'del 'EaDumpFile" >nul 2>&1";

exit;


/****************************************************************************/
ReadBytesFromFile:                    /* P1 = FileName, P2 = Length to read */
/****************************************************************************/
        ReadBytes = charin(ARG(1),, ARG(2));
        RETURN ReadBytes;


/****************************************************************************/
ReadNextByteReturnValue:
/****************************************************************************/
        OneByte = ReadBytesFromFile(ARG(1), 1);
        RETURN C2D(OneByte);


/****************************************************************************/
ReadNextWordReturnValue:
/****************************************************************************/
        RNWValue =  ReadNextByteReturnValue(ARG(1));
        RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256) + RNWValue;
        RETURN RNWValue;

/****************************************************************************/
ReadNextDoubleWordReturnValue:
/****************************************************************************/
        RNWValue =  ReadNextByteReturnValue(ARG(1));
        RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256)             + RNWValue;
        RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256 * 256 )      + RNWValue;
        RNWValue = (ReadNextByteReturnValue(ARG(1)) * 256 * 256 * 256) + RNWValue;
        RETURN RNWValue;


/****************************************************************************/
ProcessEaFile:
/****************************************************************************/
        /*--- Open the file and position at the first byte ------------------*/
        charin(ARG(1), 1, 0);

        /*--- Get the length of the file ------------------------------------*/
        LengthOfFile = ReadNextDoubleWordReturnValue(ARG(1));

        do FOREVER
           Fea         = ReadBytesFromFile(ARG(1), 1);
           KeyLength   = ReadNextByteReturnValue(ARG(1));
           if KeyLength = 0 then leave;
           ValueLength = ReadNextWordReturnValue(ARG(1));

           /*--- Get the Name of the key ------------------------------------*/
           Key      = ReadBytesFromFile(ARG(1), KeyLength);
           NullByte = ReadBytesFromFile(ARG(1), 1);
           Value    = ReadBytesFromFile(ARG(1), ValueLength);
           DumpOneKey(Fea, Key, Value);
           say '';
        end;

        /*--- Tell user how much space is used by EAs -----------------------*/
        say "Total space used by Extended Attributes is "LengthOfFile' bytes';

        RETURN;


/****************************************************************************/
DumpOneKey:
/****************************************************************************/

        /*--- Dump the keyname ----------------------------------------------*/
        say 'KEY    : "'ARG(2)'"'

        /*--- Dump the keyname ----------------------------------------------*/
        say 'FEA    : 'C2X(ARG(1));

        /*--- Remove the EA type from the information and output info -------*/
        EAT_P1       = substr(ARG(3), 1, 1);
        EAT_P2       = substr(ARG(3), 2, 1);
        Value        = substr(ARG(3), 3);
        FormattedEAT = C2X(EAT_P2)''C2X(EAT_P1);
        EAT_Text     = "";
        EAT_Length   = 'No/Unknown';
        if FormattedEAT = 'FFFE' then
        do
           EAT_Text     = "  (Binary data)"
           EAT_Length   = 'Yes';
        end;
        if FormattedEAT = 'FFFD' then
        do
           EAT_Text     = "  (Ascii text)"
           EAT_Length   = 'Yes';
        end;
        if FormattedEAT = 'FFFC' then
        do
           EAT_Text     = "  (AsciiZ text)"
        end;
        if FormattedEAT = 'FFFB' then
        do
           EAT_Text     = "  (Bitmap data)"
           EAT_Length   = 'Yes';
        end;
        if FormattedEAT = 'FFFA' then
        do
           EAT_Text     = "  (Metafile data)"
           EAT_Length   = 'Yes';
        end;
        if FormattedEAT = 'FFF9' then
        do
           EAT_Text     = "  (Icon data)"
           EAT_Length   = 'Yes';
        end;
        if FormattedEAT = 'FFEF' then
        do
           EAT_Text     = "  (AsciiZ Text)"
        end;
        if FormattedEAT = 'FFEE' then
        do
           EAT_Text     = "  (Ascii name of another EA assoc with file)"
           EAT_Length   = 'Yes';
        end;
        if FormattedEAT = 'FFDF' then
        do
           EAT_Text     = "  (Multi-Valued Multi-Typed data)"
        end;
        if FormattedEAT = 'FFDE' then
        do
           EAT_Text     = "  (Multi-Valued Single-Typed data)"
        end;
        if FormattedEAT = 'FFDD' then
        do
           EAT_Text     = "  (ASN.1 ISO standard field data)"
        end;
        say 'EA TYPE: 'FormattedEAT""EAT_Text;


        /*--- Display the length if this is part of the data ----------------*/
        if  EAT_Length = 'Yes' then
        do
            EAT_LEN1     = substr(Value, 1, 1);
            EAT_LEN2     = substr(Value, 2, 1);
            Value        = substr(Value, 3);
            FormattedLEN = C2X(EAT_LEN2)''C2X(EAT_LEN1);
            say 'LENGTH : 'FormattedLEN;
        end;

        /*--- The value is Hexadecimal so display the information -----------*/
        Leader       = "VALUE  = ";
        StrLength    = length(Value);
        AsciiStr     = "";
        HexStr       = "";
        WantSpace    = 'Y';      /* Want a space before adding Hex value     */
        Position     = 1;
        PositionRel0 = 0;
        do while Position <= StrLength
           /*--- Handle End of old line & start of new ----------------------*/
           if PositionRel0 // 16 = 0 then
           do
              /*--- See if we need to dump previous line --------------------*/
              if  AsciiStr \== "" then
              do
                  say left(HexStr, 41) || '  | ' || AsciiStr || ' |' ;
                  AsciiStr  = "";
                  HexStr    = "";
                  WantSpace = 'Y';
              end;

              /*--- Dump the address of the information ---------------------*/
              call charout , Leader""D2X(PositionRel0, 4)":";
              Leader = "         ";
           end;
           Character    = substr(Value, Position, 1);
           CharHexValue = C2X(Character);
           CharValue    = C2D(Character);
           if  CharValue < 32 | CharValue > 127 then Character = '.';
           if  WantSpace = 'Y' then
           do
               HexStr    = HexStr' 'CharHexValue;
               WantSpace = 'N'
           end
           else
           do
               HexStr    = HexStr''CharHexValue;
               WantSpace = 'Y'
           end;

           AsciiStr     = AsciiStr''Character;
           Position     = Position     + 1;
           PosItionRel0 = PosItionRel0 + 1;
        end;

        /*--- See if we need to dump previous line --------------------------*/
        if  AsciiStr \== "" then
        do
            say left(HexStr, 41) || '  | ' || left(AsciiStr, 16) || ' |' ;
        end;
        RETURN "";


/****************************************************************************/
SyntaxError:
/****************************************************************************/
        Say ARG(1);

        say "";
        say "[]---------------------------------------------------------[]";
        say "| EADUMP.CMD, Version 94.216 (C)opyright Dennis Bareis 1993 |";
        say "[]---------------------------------------------------------[]";
        say "";
        say "This program dumps Extended Attributes into a text format.  If required";
        say "the output can be redirected.";
        say "";
        say "CORRECT SYNTAX:";
        say "        EADUMP[.CMD] [*]SourceFile [EaUtilOutputFile] [>DumpFile]";
        say "";
        say "If the '*' is used, it indicates that the 'SourceFile' is a file previously";
        say "produced by a EAUTIL.EXE command and therefore contains all the attributes,";
        say "otherwise the command 'EAUTIL.EXE SourceFile OutputFile /P /S /R' is executed"
        say "against the 'SourceFile' to obtain the extended attributes.";
        say "";
        say "By specifying the 'EaUtilOutputFile' parameter the binary extended attributes";
        say "generated by 'EAUTIL.EXE' will be placed into the specified file rather than";
        say "a temporary file which gets deleted at the completion of this rexx procedure.";

        CmdRc = ARG(2); if CmdRc = "" then CmdRc = 255;
        EXIT CmdRc;