Take hexadecimal value with TmpHexEditor lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- crisares · 2019-10-08 01:34 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 · 2019-10-08 02:55 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TMPHexEditor = class(TCustomMPHexEditor)  published    property Align;    property Anchors;    property BiDiMode;    property BorderSpacing;    property BorderStyle;    property Constraints;    property DragCursor;    property DragKind;    property DragMode;    property Enabled;    property Font;    property OnClick;    property OnDblClick;    property OnDragDrop;    property OnDragOver;    property OnEndDock;    property OnEndDrag;    property OnEnter;    property OnExit;    property OnKeyDown;    property OnKeyPress;    property OnKeyUp;    property OnMouseDown;    property OnMouseMove;  property OnMouseUp;    property OnMouseWheel;    property OnMouseWheelDown;    property OnMouseWheelUp;    property OnStartDock;    property OnStartDrag;    property ParentBiDiMode;    property ParentFont;    property ParentShowHint;    property PopupMenu;    property ScrollBars;    property ShowHint;    property TabOrder;    property TabStop;    property Visible;    property BytesPerRow;    property BytesPerColumn;    property AutoBytesPerRow;    property Translation;    property OffsetFormat;    property CaretKind;    property Colors;    property FocusFrame;    property SwapNibbles;    property MaskChar;    property NoSizeChange;    property AllowInsertMode;    property DrawGridLines;    property WantTabs;    property ReadOnlyView;    property HideSelection;    property GraySelectionIfNotFocused;    property GutterWidth;    property BookmarkBitmap;    property Version;    property MaxUndo;    property InsertMode;    property HexLowerCase;    property OnProgress;    property OnInvalidKey;    property OnTopLeftChanged;  property OnChange;    property DrawGutter3D;    property ShowRuler;  property BytesPerUnit;    property RulerBytesPerUnit;    property ShowPositionIfNotFocused;    property OnSelectionChanged;    property UnicodeChars;    property UnicodeBigEndian;    property OnDrawCell;  property OnBookmarkChanged;    property OnGetOffsetText;    property BytesPerBlock;    property SeparateBlocksInCharField;    property FindProgress;    property RulerNumberBase;end; TCustomMPHexEditor = class(TCustomGrid)  public{$IFDEF FASTACCESS}    function GetFastPointer(const Index, Count: integer): PByte;{$ENDIF}    constructor Create(aOwner: TComponent); override;    destructor Destroy; override;    property MaskedChars: TSysCharSet read FMaskedChars write SetMaskedChars;    property DrawDataPosition: integer read FDrawDataPosition;    property IsDrawDataSelected: boolean read FIsDrawDataSelected;    function GetMemory(const Index: Integer): char;    function CanFocus: Boolean; override;    procedure SetMemory(const Index: integer; const Value: char);    property IsMaxOffset: boolean read FIsMaxOffset;    procedure SeekToEOF;    procedure SyncView(Source: TCustomMPHexEditor; SyncOffset: integer = 0);    function DisplayStart: integer;    function DisplayEnd: integer;    function IsSelected(const APosition: integer): boolean;  property PositionAtCursor[const ACol, ARow: integer]: integer read    GetPositionAtCursor;    property IsCharFieldCol[const ACol: integer]: Boolean read    GetIsCharFieldCol;{$IFDEF FASTACCESS}    property SetDataSizeFillByte: Byte read FSetDataSizeFillByte write      FSetDataSizeFillByte;{$ENDIF}    property HasFile: boolean read FHasFile write FHasFile;    function UndoBeginUpdate: integer; virtual;    function UndoEndUpdate: integer; virtual;    procedure ResetSelection(const aDraw: boolean);    property SelectionAsHex: string read GetSelectionAsHex write      SetSelectionAsHex;    property SelectionAsText: string read GetSelectionAsText write      SetSelectionAsText;    property FindTable: TMPHFindTable read FFindTable;    property FindTableI: TMPHFindTable read FFindTableI;  property OnFind: TMPHFindEvent read FOnFind write FOnFind;    property OnWildcardFind: TMPHFindEvent read FOnWildcardFind      write FOnWildcardFind;    function GetOffsetString(const Position: cardinal): string; virtual;    function GetAnyOffsetString(const Position: integer): string; virtual;    function RowHeight: integer;  procedure ResetUndo;    function Seek(const aOffset, aOrigin: integer): integer;    function Find(aBuffer: PChar; aCount: integer; const aStart, aEnd: integer;      const IgnoreCase: boolean): integer;    function FindWithWildcard(aBuffer: PChar; aCount: integer; const aStart,      aEnd: integer;      const IgnoreCase: boolean; const Wildcard: char): integer;    procedure AddSelectionUndo(const AStart, ACount: integer);    function PrepareFindReplaceData(StrData: string; const IgnoreCase, IsText:      boolean): string;    procedure ReadBuffer(var Buffer; const Index, Count: Integer);    procedure WriteBuffer(const Buffer; const Index, Count: Integer); virtual;    procedure DeleteSelection(const UndoDesc: string = '');    procedure LoadFromStream(Strm: TStream);    procedure LoadFromFile(const Filename: string);    procedure SaveToStream(Strm: TStream);    procedure SaveToFile(const Filename: string;      const aUnModify: boolean = True);    procedure SaveRangeToStream(Strm: TStream; const APosition, ACount:      integer);    function Undo: boolean;    function Redo: boolean;    procedure CreateEmptyFile(const TempName: string);    function BufferFromFile(const aPos: integer; var aCount: integer): PChar;    procedure InsertBuffer(aBuffer: PChar; const aSize, aPos: integer; const      UndoDesc: string = ''; const MoveCursor: Boolean = True);    procedure AppendBuffer(aBuffer: PChar; const aSize: integer; const UndoDesc:      string = ''; const MoveCursor: Boolean = True);    procedure ReplaceSelection(aBuffer: PChar; aSize: integer; const UndoDesc:      string = ''; const MoveCursor: Boolean = True);    function Replace(aBuffer: PChar; aPosition, aOldCount, aNewCount: integer;      const UndoDesc:      string = ''; const MoveCursor: Boolean = False): integer;    function GetCursorPos: integer;    function DeleteNibble(const aPos: integer; const HighNibble: boolean; const      UndoDesc: string = ''): boolean;    function InsertNibble(const aPos: integer; const HighNibble: boolean; const      UndoDesc: string = ''): boolean;    procedure ConvertRange(const aFrom, aTo: integer; const aTransFrom,    aTransTo: TMPHTranslationKind; const UndoDesc: string = '');    function GetTopLeftPosition(var oInCharField: boolean): integer;    procedure SetTopLeftPosition(const aPosition: integer; const aInCharField:      boolean);    function ShowDragCell(const X, Y: integer): integer;    procedure HideDragCell;    procedure CombineUndo(const aCount: integer; const sDesc: string = '');    function TranslateToAnsiChar(const aByte: byte): char;    function TranslateFromAnsiChar(const aByte: byte): char;    property SelStart: integer read GetSelStart write SetSelStart;    property SelEnd: integer read GetSelEnd write SetSelEnd;    property SelCount: integer read GetSelCount write SetSelCount;    property CanUndo: boolean read GetCanUndo;    property CanRedo: boolean read GetCanRedo;    property InCharField: boolean read GetInCharField write SetInCharField;    property UndoDescription: string read GetUndoDescription;    property ReadOnlyFile: boolean read FIsFileReadonly write SetReadOnlyFile;    property Modified: boolean read GetModified write SetModified;    property DataSize: integer read GetDataSize write SetDataSize;    property Data[Index: integer]: Byte read GetDataAt write SetDataAt;  property AsText: string read GetAsText write SetAsText;    property AsHex: string read GetAsHex write SetAsHex;    property Filename: string read FFileName;    property Bookmark[Index: byte]: TMPHBookmark read GetBookmark write    SetBookmark;    property ByteChanged[index: integer]: boolean read HasChanged write    SetChanged;    property ColCountRO: integer read GetPropColCount;    property RowCountRO: integer read GetPropRowCount;    property MouseOverSelection: boolean read GetMouseOverSelection;    property CurrentValue: integer read GetCurrentValue;    procedure SelectAll;    property VisibleColCount;    property VisibleRowCount;    property Canvas;    property Col;    property LeftCol;    property Row;    property TopRow;    property OnBookmarkChanged: TNotifyEvent read FOnBookmarkChanged write      FOnBookmarkChanged;    function GotoBookmark(const Index: integer): boolean;    procedure UpdateGetOffsetText;    procedure CenterCursorPosition;end; Source: https://github.com/michalgw/mphexeditor/blob/master/src/mphexe ditor.pas ---------------------------------------------------------------------- crisares · 2019-10-11 20:14 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure Proc_Lectura_Escritura_1; begin         x := GetByteHexEdit($00) //I take the value of address 00 from the hexadecimal and save it in X       SetByteHexEdit($04,x);  //I assign the value of X to address 04 of the hexadecimal                 RefreshHexEdit;  // I update the hexadecimal       end;   I want to know how to do the same per file that I have loaded in the tmphexeditor. ---------------------------------------------------------------------- wp · 2019-10-11 20:45 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  v: byte;...  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  v: LongInt;...  MPHexEditor1.ReadBuffer(v, Position, 4); For writing, there is a corresponding method WriteBuffer Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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.ch m ---------------------------------------------------------------------- crisares · 2019-10-12 01:34 Quote from: wp on October 11, 2019, 10:45:36 pmI 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  v: byte;...  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  v: LongInt;...  MPHexEditor1.ReadBuffer(v, Position, 4); For writing, there is a corresponding method WriteBuffer Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     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.ch m thank you!!! I think it's all I needed ... Greetings and have a good weekend ---------------------------------------------------------------------- crisares · 2019-10-12 13:26 Sorry I still can't show the result of the byte obtained in a label Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.calcularDatos(Sender: TObject);varv:byte; begin     MPHex.ReadBuffer(v,$0018,1);end;     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 · 2019-10-12 14:27 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 · 2019-10-12 17:59 Muchas Gracias WP Voy estudiar ese ejemplo que me compartiste ---------------------------------------------------------------------- crisares · 2019-10-12 18:01 sorry I forgot the translation  Thank you very much WP I'm going to study that example that you shared with me ---------------------------------------------------------------------- crisares · 2019-10-12 18:33 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  MPHexEditor1.ReadBuffer(v, MPHexEditor1.GetCursorPos, SizeOf(v));   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 ---------------------------------------------------------------------- wp · 2019-10-12 20:09 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 · 2019-10-12 21:27 Quote from: wp on October 12, 2019, 10:09:29 pmIn 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 · 2019-10-12 23:29 Hmmm,  I don't know how else I can help you... ---------------------------------------------------------------------- crisares · 2019-10-13 18:08 Quote from: wp on October 13, 2019, 01:29:25 amHmmm,  I don't know how else I can help you... It is already solved ... and thanks for everything! You were very helpful