Autor Beitrag
hansg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Di 22.08.06 15:24 
Hallo zusammen,

ich benötige mal Eure Hilfe, ich möchte aus einer Datei Daten (Endung *.hex)lesen.
Habe leider keinen Plan wie ich das anstellen soll.
Die Datei ist immer gleich aufgebaut, nur die Länge ist variabel (Dateigrößee 2 oder 4k).
Wie kann ich auf den einzelnen Speicherinhalt zugreifen?

Ansicht der Datei im HEX-Format:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
000000:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000010:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000020:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000030:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000040:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000050:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000060:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000070:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000080:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
000090:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
0000A0:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
0000B0:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
0000C0:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
0000D0:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
0000E0:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F
0000F0:  25 21 33 2E 32 42 46 65 FF FF FF 01 FF 02 C1 1F



Bitte um Hilfe
Gruß Hans

_________________
Gruß Hans
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 22.08.06 22:38 
Moin!

Such mal nach Suche in: Delphi-Forum, Delphi-Library TFILESTREAM. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Do 24.08.06 15:12 
Hallo,

danke für den Tip, leider komme ich damit nicht weiter.

Ich habe folgenden Code beim swissdelphicenter gefunden, leider stimmt da was nicht.
Ich verstehe ich den Code nicht, kann mir da jemand weiter helfen, außerdem will ich nicht einen Code kopieren und weiß nicht was da passiert.

ausblenden volle Höhe Delphi-Quelltext
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:
57:
58:
59:
60:
61:
62:
63:
64:
65:
type
  TDisplayProc = procedure(const s: string) of object;

procedure ShowBinary(var Data; Count: Cardinal; DispProc: TDisplayProc);

implementation


procedure ShowBinary(var Data; Count: Cardinal; DispProc: TDisplayProc);
var
  line: string[80];
  i: Cardinal;
  p: PChar;
  nStr: string[4];
const
  posStart = 1;
  binStart = 7;
  ascStart = 57;
  HexChars: PChar = '0123456789ABCDEF';
begin
  p    := @Data;
  line := '';
  for i := 0 to Count - 1 do
  begin
    if (i mod 16) = 0 then
    begin
      if Length(line) > 0 then
        DispProc(line);
      FillChar(line, SizeOf(line), ' ');
      line[0] := Chr(72);
      nStr    := Format('%4.4X', [i]);
      Move(nStr[1], line[posStart], Length(nStr));
      line[posStart + 4] := ':';
    end;
    if p[i] >= ' ' then
      line[i mod 16 + ascStart] := p[i]
    else
      line[i mod 16 + ascStart] := '.';
    line[binStart + 3 * (i mod 16)]     := HexChars[(Ord(p[i]) shr 4) and $F];
    line[binStart + 3 * (i mod 16) + 1] := HexChars[Ord(p[i]) and $F];
  end;
  DispProc(line);
end;


procedure TForm1.Display(const S: string);
begin
  Memo1.Lines.Add(S);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ms: TMemoryStream;
begin
  if Opendialog1.Execute then
  begin
    ms := TMemoryStream.Create;
    try
      ms.LoadFromfile(OpenDialog1.FileName);
      ShowBinary(ms.Memory^, ms.Size, Display);
    finally
      ms.Free
    end;
  end;
end;


Gruß Hans

_________________
Gruß Hans