Recent

Author Topic: Take hexadecimal value with TmpHexEditor  (Read 4688 times)

crisares

  • Jr. Member
  • **
  • Posts: 63
Take hexadecimal value with TmpHexEditor
« on: October 08, 2019, 03:34:44 am »
Hello everyone!
Could you tell me where I can know a complete list of the functions of the TmpHexEditor object?
I need to be able to take a value from the dump in tmphexeditor and assign it to a variable ..
thank you

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: Take hexadecimal value with TmpHexEditor
« Reply #1 on: October 08, 2019, 04:55:02 am »
TmpHexEditor is open source, you can get and examine it. And that's the beauty of open source.

Here is all the available methods and properties of TMPHexEditor (public and published):

Code: Pascal  [Select][+][-]
  1. TMPHexEditor = class(TCustomMPHexEditor)
  2.   published
  3.     property Align;
  4.     property Anchors;
  5.     property BiDiMode;
  6.     property BorderSpacing;
  7.     property BorderStyle;
  8.     property Constraints;
  9.     property DragCursor;
  10.     property DragKind;
  11.     property DragMode;
  12.     property Enabled;
  13.     property Font;
  14.     property OnClick;
  15.     property OnDblClick;
  16.     property OnDragDrop;
  17.     property OnDragOver;
  18.     property OnEndDock;
  19.     property OnEndDrag;
  20.     property OnEnter;
  21.     property OnExit;
  22.     property OnKeyDown;
  23.     property OnKeyPress;
  24.     property OnKeyUp;
  25.     property OnMouseDown;
  26.     property OnMouseMove;
  27.     property OnMouseUp;
  28.     property OnMouseWheel;
  29.     property OnMouseWheelDown;
  30.     property OnMouseWheelUp;
  31.     property OnStartDock;
  32.     property OnStartDrag;
  33.     property ParentBiDiMode;
  34.     property ParentFont;
  35.     property ParentShowHint;
  36.     property PopupMenu;
  37.     property ScrollBars;
  38.     property ShowHint;
  39.     property TabOrder;
  40.     property TabStop;
  41.     property Visible;
  42.     property BytesPerRow;
  43.     property BytesPerColumn;
  44.     property AutoBytesPerRow;
  45.     property Translation;
  46.     property OffsetFormat;
  47.     property CaretKind;
  48.     property Colors;
  49.     property FocusFrame;
  50.     property SwapNibbles;
  51.     property MaskChar;
  52.     property NoSizeChange;
  53.     property AllowInsertMode;
  54.     property DrawGridLines;
  55.     property WantTabs;
  56.     property ReadOnlyView;
  57.     property HideSelection;
  58.     property GraySelectionIfNotFocused;
  59.     property GutterWidth;
  60.     property BookmarkBitmap;
  61.     property Version;
  62.     property MaxUndo;
  63.     property InsertMode;
  64.     property HexLowerCase;
  65.     property OnProgress;
  66.     property OnInvalidKey;
  67.     property OnTopLeftChanged;
  68.     property OnChange;
  69.     property DrawGutter3D;
  70.     property ShowRuler;
  71.     property BytesPerUnit;
  72.     property RulerBytesPerUnit;
  73.     property ShowPositionIfNotFocused;
  74.     property OnSelectionChanged;
  75.     property UnicodeChars;
  76.     property UnicodeBigEndian;
  77.     property OnDrawCell;
  78.     property OnBookmarkChanged;
  79.     property OnGetOffsetText;
  80.     property BytesPerBlock;
  81.     property SeparateBlocksInCharField;
  82.     property FindProgress;
  83.     property RulerNumberBase;
  84. end;
  85.  
  86. TCustomMPHexEditor = class(TCustomGrid)
  87.   public
  88. {$IFDEF FASTACCESS}
  89.     function GetFastPointer(const Index, Count: integer): PByte;
  90. {$ENDIF}
  91.     constructor Create(aOwner: TComponent); override;
  92.     destructor Destroy; override;
  93.     property MaskedChars: TSysCharSet read FMaskedChars write SetMaskedChars;
  94.     property DrawDataPosition: integer read FDrawDataPosition;
  95.     property IsDrawDataSelected: boolean read FIsDrawDataSelected;
  96.     function GetMemory(const Index: Integer): char;
  97.     function CanFocus: Boolean; override;
  98.     procedure SetMemory(const Index: integer; const Value: char);
  99.     property IsMaxOffset: boolean read FIsMaxOffset;
  100.     procedure SeekToEOF;
  101.     procedure SyncView(Source: TCustomMPHexEditor; SyncOffset: integer = 0);
  102.     function DisplayStart: integer;
  103.     function DisplayEnd: integer;
  104.     function IsSelected(const APosition: integer): boolean;
  105.     property PositionAtCursor[const ACol, ARow: integer]: integer read
  106.     GetPositionAtCursor;
  107.     property IsCharFieldCol[const ACol: integer]: Boolean read
  108.     GetIsCharFieldCol;
  109. {$IFDEF FASTACCESS}
  110.     property SetDataSizeFillByte: Byte read FSetDataSizeFillByte write
  111.       FSetDataSizeFillByte;
  112. {$ENDIF}
  113.     property HasFile: boolean read FHasFile write FHasFile;
  114.     function UndoBeginUpdate: integer; virtual;
  115.     function UndoEndUpdate: integer; virtual;
  116.     procedure ResetSelection(const aDraw: boolean);
  117.     property SelectionAsHex: string read GetSelectionAsHex write
  118.       SetSelectionAsHex;
  119.     property SelectionAsText: string read GetSelectionAsText write
  120.       SetSelectionAsText;
  121.     property FindTable: TMPHFindTable read FFindTable;
  122.     property FindTableI: TMPHFindTable read FFindTableI;
  123.     property OnFind: TMPHFindEvent read FOnFind write FOnFind;
  124.     property OnWildcardFind: TMPHFindEvent read FOnWildcardFind
  125.       write FOnWildcardFind;
  126.     function GetOffsetString(const Position: cardinal): string; virtual;
  127.     function GetAnyOffsetString(const Position: integer): string; virtual;
  128.     function RowHeight: integer;
  129.     procedure ResetUndo;
  130.     function Seek(const aOffset, aOrigin: integer): integer;
  131.     function Find(aBuffer: PChar; aCount: integer; const aStart, aEnd: integer;
  132.       const IgnoreCase: boolean): integer;
  133.     function FindWithWildcard(aBuffer: PChar; aCount: integer; const aStart,
  134.       aEnd: integer;
  135.       const IgnoreCase: boolean; const Wildcard: char): integer;
  136.     procedure AddSelectionUndo(const AStart, ACount: integer);
  137.     function PrepareFindReplaceData(StrData: string; const IgnoreCase, IsText:
  138.       boolean): string;
  139.     procedure ReadBuffer(var Buffer; const Index, Count: Integer);
  140.     procedure WriteBuffer(const Buffer; const Index, Count: Integer); virtual;
  141.     procedure DeleteSelection(const UndoDesc: string = '');
  142.     procedure LoadFromStream(Strm: TStream);
  143.     procedure LoadFromFile(const Filename: string);
  144.     procedure SaveToStream(Strm: TStream);
  145.     procedure SaveToFile(const Filename: string;
  146.       const aUnModify: boolean = True);
  147.     procedure SaveRangeToStream(Strm: TStream; const APosition, ACount:
  148.       integer);
  149.     function Undo: boolean;
  150.     function Redo: boolean;
  151.     procedure CreateEmptyFile(const TempName: string);
  152.     function BufferFromFile(const aPos: integer; var aCount: integer): PChar;
  153.     procedure InsertBuffer(aBuffer: PChar; const aSize, aPos: integer; const
  154.       UndoDesc: string = ''; const MoveCursor: Boolean = True);
  155.     procedure AppendBuffer(aBuffer: PChar; const aSize: integer; const UndoDesc:
  156.       string = ''; const MoveCursor: Boolean = True);
  157.     procedure ReplaceSelection(aBuffer: PChar; aSize: integer; const UndoDesc:
  158.       string = ''; const MoveCursor: Boolean = True);
  159.     function Replace(aBuffer: PChar; aPosition, aOldCount, aNewCount: integer;
  160.       const UndoDesc:
  161.       string = ''; const MoveCursor: Boolean = False): integer;
  162.     function GetCursorPos: integer;
  163.     function DeleteNibble(const aPos: integer; const HighNibble: boolean; const
  164.       UndoDesc: string = ''): boolean;
  165.     function InsertNibble(const aPos: integer; const HighNibble: boolean; const
  166.       UndoDesc: string = ''): boolean;
  167.     procedure ConvertRange(const aFrom, aTo: integer; const aTransFrom,
  168.       aTransTo: TMPHTranslationKind; const UndoDesc: string = '');
  169.     function GetTopLeftPosition(var oInCharField: boolean): integer;
  170.     procedure SetTopLeftPosition(const aPosition: integer; const aInCharField:
  171.       boolean);
  172.     function ShowDragCell(const X, Y: integer): integer;
  173.     procedure HideDragCell;
  174.     procedure CombineUndo(const aCount: integer; const sDesc: string = '');
  175.     function TranslateToAnsiChar(const aByte: byte): char;
  176.     function TranslateFromAnsiChar(const aByte: byte): char;
  177.     property SelStart: integer read GetSelStart write SetSelStart;
  178.     property SelEnd: integer read GetSelEnd write SetSelEnd;
  179.     property SelCount: integer read GetSelCount write SetSelCount;
  180.     property CanUndo: boolean read GetCanUndo;
  181.     property CanRedo: boolean read GetCanRedo;
  182.     property InCharField: boolean read GetInCharField write SetInCharField;
  183.     property UndoDescription: string read GetUndoDescription;
  184.     property ReadOnlyFile: boolean read FIsFileReadonly write SetReadOnlyFile;
  185.     property Modified: boolean read GetModified write SetModified;
  186.     property DataSize: integer read GetDataSize write SetDataSize;
  187.     property Data[Index: integer]: Byte read GetDataAt write SetDataAt;
  188.     property AsText: string read GetAsText write SetAsText;
  189.     property AsHex: string read GetAsHex write SetAsHex;
  190.     property Filename: string read FFileName;
  191.     property Bookmark[Index: byte]: TMPHBookmark read GetBookmark write
  192.     SetBookmark;
  193.     property ByteChanged[index: integer]: boolean read HasChanged write
  194.     SetChanged;
  195.     property ColCountRO: integer read GetPropColCount;
  196.     property RowCountRO: integer read GetPropRowCount;
  197.     property MouseOverSelection: boolean read GetMouseOverSelection;
  198.     property CurrentValue: integer read GetCurrentValue;
  199.     procedure SelectAll;
  200.     property VisibleColCount;
  201.     property VisibleRowCount;
  202.     property Canvas;
  203.     property Col;
  204.     property LeftCol;
  205.     property Row;
  206.     property TopRow;
  207.     property OnBookmarkChanged: TNotifyEvent read FOnBookmarkChanged write
  208.       FOnBookmarkChanged;
  209.     function GotoBookmark(const Index: integer): boolean;
  210.     procedure UpdateGetOffsetText;
  211.     procedure CenterCursorPosition;
  212. end;

Source: https://github.com/michalgw/mphexeditor/blob/master/src/mphexeditor.pas
« Last Edit: October 08, 2019, 05:24:31 am by Handoko »

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #2 on: October 11, 2019, 10:14:44 pm »
Thanks for your answer
But I still don't understand what programming line I should use to save the value of a hexadecimal position loaded in a variable.
In the programming IDE of a programmer called UPA Programer, the instruction in pascal to perform a script would be as follows:

Code: Pascal  [Select][+][-]
  1. Procedure Proc_Lectura_Escritura_1;
  2.  
  3. begin
  4.  
  5.         x := GetByteHexEdit($00) //I take the value of address 00 from the hexadecimal and save it in X  
  6.  
  7.         SetByteHexEdit($04,x);  //I assign the value of X to address 04 of the hexadecimal
  8.        
  9.         RefreshHexEdit;  // I update the hexadecimal      
  10. end;
  11.  
  12.  


I want to know how to do the same per file that I have loaded in the tmphexeditor.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Take hexadecimal value with TmpHexEditor
« Reply #3 on: October 11, 2019, 10:45:36 pm »
I suppose, with "dump in tmphexeditor" you mean the listing of bytes in the middle part of the editor (surrounded in red in the attached screenshot).

Suppose you want to read a particular value into a variable - I painted a green border around some byte in the hex listing.This value, $5A, is at offset $0050 + $03 = $0053 of the file. $0050 is the value taken from the row header, $03 from the column header of the cell where the value is found.

The hex editor has a function ReadBuffer which you can use to read any number of bytes to a buffer in your program:
Code: Pascal  [Select][+][-]
  1.     procedure ReadBuffer(var Buffer; const APosition, ACount: Integer);

In order to read a single byte, declare a variable as byte and call
Code: Pascal  [Select][+][-]
  1. var
  2.   v: byte;
  3. ...
  4.   MPHexEditor1.ReadBuffer(v, Position, 1);
Here "Position" is the offset position of the byte to be read, $0053 in above example. The "1" tells the hexeditor to read a single byte.

If you want to read, say, 4 adjacent bytes as a LongInt then declare the variable v as longint, and use a 4 as the last parameter in this call.
Code: Pascal  [Select][+][-]
  1. var
  2.   v: LongInt;
  3. ...
  4.   MPHexEditor1.ReadBuffer(v, Position, 4);

For writing, there is a corresponding method WriteBuffer
Code: Pascal  [Select][+][-]
  1.     procedure WriteBuffer(const Buffer; const APosition, ACount: Integer);

---------------

The author's git site (and probably also your local download) contains a chm help file where you can find all properties and methods of the editor. Or look yourself in the source files, the author added lots of comments.

https://github.com/michalgw/mphexeditor/blob/master/doc/MPHexEditor.chm
« Last Edit: October 12, 2019, 11:19:52 am by wp »

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #4 on: October 12, 2019, 03:34:33 am »
I suppose, with "dump in tmphexeditor" you mean the listing of bytes in the middle part of the editor (surrounded in red in the attached screenshot).

Suppose you want to read a particular value into a variable - I painted a green border around some byte in the hex listing.This value, $5A, is at offset $0050 + $03 = $0053 of the file. $0050 is the value taken from the row header, $03 from the column header of the cell where the value is found.

The hex editor has a function ReadBuffer which you can use to read any number of bytes to a buffer in your program:
Code: Pascal  [Select][+][-]
  1.     procedure ReadBufferAt(var Buffer; const APosition, ACount: Integer);

In order to read a single byte, declare a variable as byte and call
Code: Pascal  [Select][+][-]
  1. var
  2.   v: byte;
  3. ...
  4.   MPHexEditor1.ReadBuffer(v, Position, 1);
"Position" is here the offset position for the byte to be read, $0053 in above example. The "1" tells the hexeditor to read a single byte.

If you want to read, say, 4 adjacent bytes as a LongInt then declare the variable v as longint, and use a 4 as the last parameter in this call.
Code: Pascal  [Select][+][-]
  1. var
  2.   v: LongInt;
  3. ...
  4.   MPHexEditor1.ReadBuffer(v, Position, 4);

For writing, there is a corresponding method WriteBuffer
Code: Pascal  [Select][+][-]
  1.     procedure WriteBuffer(const Buffer; const APosition, ACount: Integer);

---------------

The author's git site (and probably also you local download) contains a chm help file where you can find all properties and methods of the editor. Or look yourself in the source files, the author added lots of comments.

https://github.com/michalgw/mphexeditor/blob/master/doc/MPHexEditor.chm

thank you!!! I think it's all I needed ...
Greetings and have a good weekend

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #5 on: October 12, 2019, 03:26:11 pm »
Sorry I still can't show the result of the byte obtained in a label :(

Code: Pascal  [Select][+][-]
  1. procedure TForm1.calcularDatos(Sender: TObject);
  2. var
  3. v:byte;
  4.  
  5. begin
  6.      MPHex.ReadBuffer(v,$0018,1);
  7. end;    
  8.  

The value stored inside variable v is not the value seen in the buffer, it saves me the value 224.
There I show the buffer in the image


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Take hexadecimal value with TmpHexEditor
« Reply #6 on: October 12, 2019, 04:27:32 pm »
First, I hope you know that the numbers in the center part of the hex editor are hex values, while v normally shows you the decimal representation. 224 = $E0. But the highlighted value in your screenshot of the editor is $17 = 23. You are right...

The only thing which comes to my mind is that the offset is not correct. Sometimes documentation specifies the offset of data structures relative to other structural blocks.

And of course, a very stupid error - sorry but these things happen: did you load the correct file?

Maybe you should first try some well-known files. The file that I had shown in my screenshot above is "win_objectinspector.ico" which you can find in the folder images/windows of your Lazarus installation. Load it into the hex editor and try to read the byte value at offset $06 - this is the width of the first image in the icon file, $30 = 48 in this case as you can verify, for example, with IrfanView.

I am attaching a demo which reads the byte and word at the clicked position into variables and displays their values as decimal and hex numbers in a label.


crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #7 on: October 12, 2019, 07:59:35 pm »
Muchas Gracias WP
Voy estudiar ese ejemplo que me compartiste

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #8 on: October 12, 2019, 08:01:12 pm »
sorry I forgot the translation  :D

Thank you very much WP
I'm going to study that example that you shared with me

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #9 on: October 12, 2019, 08:33:35 pm »
I work with the automotive sector and my readings are about dumps obtained from the car immobilizer to which I from the code must always obtain the readings of the same positions, in the example when giving the result of the selected position I do not understand how to indicate I the address of the buffer that should show me

Code: Pascal  [Select][+][-]
  1.  
  2. MPHexEditor1.ReadBuffer(v, MPHexEditor1.GetCursorPos, SizeOf(v));
  3.  
  4.  

for example in that line as a replacement

MPHexEditor1.GetCursorPos

for a position already defined by default ... I tried several ways and I get an error
« Last Edit: October 12, 2019, 09:00:25 pm by crisares »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Take hexadecimal value with TmpHexEditor
« Reply #10 on: October 12, 2019, 10:09:29 pm »
In my example MPHexEditor1.GetCursorPos is the position of the byte clicked in the editor. In your particular case, of course, you must use the file offset for the byte (word, longint, or whatever data) you want to read.

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #11 on: October 12, 2019, 11:27:31 pm »
In my example MPHexEditor1.GetCursorPos is the position of the byte clicked in the editor. In your particular case, of course, you must use the file offset for the byte (word, longint, or whatever data) you want to read.

Sorry but ... If I understand ... I just can't find the exact way to write the readbuffer method to indicate the direction I want to read ...
Thanks also

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Take hexadecimal value with TmpHexEditor
« Reply #12 on: October 13, 2019, 01:29:25 am »
Hmmm,  I don't know how else I can help you...

crisares

  • Jr. Member
  • **
  • Posts: 63
Re: Take hexadecimal value with TmpHexEditor
« Reply #13 on: October 13, 2019, 08:08:58 pm »
Hmmm,  I don't know how else I can help you...

It is already solved ... and thanks for everything! You were very helpful

 

TinyPortal © 2005-2018