القراءة من ملف ثنائى عند عنوان محدد
#1
إخوانى الكرام السلام عليكم

أرغب فى معرفة طريقة القراءة من عنوان محدد فى ملف ثنائى
السورس المعروض و الملف المرفق
يقوم بفتح الملف الذى ترغبه للقراءة
و يستقبل منك أى متغير نصى
و يبحث عنه فى الملف الذى سبق أن فتحه فى الخطوة الأولى
و بمجرد أن يجده
يعرضه عنوانه فى مربع نص و العنوان سليم و يطابق نتائج أى محرر هكس

التساؤل الآن
كيف يمكننى عرض محتويات هذا العنوان بعد إضافة 9 مثلا
أى لو كان العنوان الذى يتواجد فيه المتغير المبحوث عنه = 10
فأنا أرغب فى إظهار محتويات العنوان 19 فى مربع النص الثالث علما بأن محتويات هذا العنوان تظهر كنصوص طبيعية فى محرر الهكس

الكود
كود :
unit search; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function ScanFile(const FileName: string; const forString: string; caseSensitive: Boolean): Longint; const BufferSize = $8001; { 32K+1 bytes } var pBuf, pEnd, pScan, pPos: PChar; filesize: LongInt; bytesRemaining: LongInt; bytesToRead: Integer; F: file; SearchFor: PChar; oldMode: Word; begin { assume failure } Result := -1; if (Length(forString) = 0) or (Length(FileName) = 0) then Exit; SearchFor := nil; pBuf := nil; { open file as binary, 1 byte recordsize } AssignFile(F, FileName); oldMode := FileMode; FileMode := 0; { read-only access } Reset(F, 1); FileMode := oldMode; try { allocate memory for buffer and pchar search string } SearchFor := StrAlloc(Length(forString) + 1); StrPCopy(SearchFor, forString); if not caseSensitive then { convert to upper case } AnsiUpper(SearchFor); GetMem(pBuf, BufferSize); filesize := System.Filesize(F); bytesRemaining := filesize; pPos := nil; while bytesRemaining > 0 do begin { calc how many bytes to read this round } if bytesRemaining >= BufferSize then bytesToRead := Pred(BufferSize) else bytesToRead := bytesRemaining; { read a buffer full and zero-terminate the buffer } BlockRead(F, pBuf^, bytesToRead, bytesToRead); pEnd := @pBuf[bytesToRead]; pEnd^ := #0; pScan := pBuf; while pScan < pEnd do begin if not caseSensitive then { convert to upper case } AnsiUpper(pScan); pPos := StrPos(pScan, SearchFor); { search for substring } if pPos <> nil then begin { Found it! } Result := FileSize - bytesRemaining + Longint(pPos) - Longint(pBuf); Break; end; pScan := StrEnd(pScan); Inc(pScan); end; if pPos <> nil then Break; bytesRemaining := bytesRemaining - bytesToRead; if bytesRemaining > 0 then begin Seek(F, FilePos(F) - Length(forString)); bytesRemaining := bytesRemaining + Length(forString); end; end; { While } finally CloseFile(F); if SearchFor <> nil then StrDispose(SearchFor); if pBuf <> nil then FreeMem(pBuf, BufferSize); end; end; { ScanFile } procedure TForm1.Button1Click(Sender: TObject); var openDialog : TOpenDialog; Position: integer; begin openDialog := TOpenDialog.Create(self); openDialog.InitialDir := 'c:\'; openDialog.Options := [ofFileMustExist]; openDialog.Filter := 'EXE FILE|*.EXE|ANY FILE|*.*'; openDialog.FilterIndex := 2; if openDialog.Execute then ShowMessage(openDialog.FileName) else ShowMessage('Open file was cancelled'); Position := ScanFile(openDialog.FileName, edit1.text, False); edit2.Text:=(IntToStr(Position)); openDialog.Free; end; end.

السورس كود مرفق
الرد


الردود في هذا الموضوع
القراءة من ملف ثنائى عند عنوان محدد - بواسطة خالد على22 - 11-06-2011, 01:49 AM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم