summaryrefslogtreecommitdiff
path: root/docview/src/docdump/readstrings.pas
blob: 7b3974089baf50cce3cb3a204a82b4a6efb9249b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
  Dump the String table data
}
unit readstrings;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, filestreamhelper;

procedure ProcessStringsTable(AIn: TFileStream; AOut: TFileTextStream);


implementation

uses
  readheader;

procedure ProcessStringsTable(AIn: TFileStream; AOut: TFileTextStream);
var
  name: string;
  pData: pointer;
  p: pointer;
  pLength: pByte;
  bytes: integer;
begin
  AOut.WriteLn('');
  AOut.WriteLn('Strings Data');

  if eHdr.StringsSize > 0 then
  begin
    pData := nil;
    AIn.Seek(eHdr.StringsOffset, soBeginning);
    GetMem(pData, eHdr.StringsSize);     // allocate temp space for data
    AIn.Read(pData^, eHdr.StringsSize);  // read all data in one shot
    p := pData; // p is our incrementing position in the data
    bytes := 0;
    while bytes < eHdr.StringsSize do;
    begin
      pLength := p;       // length byte, including itself
      bytes := bytes + pLength^;
      SetString(name, p+1, pLength^-1);   // use length value minus the length byte to get the string length
      AOut.WriteLn(Format('  %s', [name]));
      inc(p, pLength^);   // skip to next entry using full length (including length byte)
    end;
    FreeMem(pData, eHdr.StringsSize);    // free allocated space
  end
  else
    AOut.WriteLn('  There are no strings');

end;

end.