Page 1 of 1

How does showmemoryviewer work

Posted: Fri Nov 28, 2025 5:48 am
by juror
from the help

Code: Select all

 UseSHA2Fingerprint()
  *Key = AllocateMemory(32)

  ; Create a 256bit key using SHA-512 hash function and 500000 iterations
  DeriveCipherKey("SecretPassword", "NonSecretSalt", 500000, *Key, 256, #PB_Cipher_SHA2, 512)

  ; Show the key
  ShowMemoryViewer(*Key, 32)
How do I obtain the memory contents *key points to? I always get the memory address of *key.

Too much turkey, dessert and wine has fried my brain.

got it.

Code: Select all

Procedure.s MemToHex(*Mem, Size)
  Protected s.s = ""
  For i = 0 To Size-1
    s + RSet(Hex(PeekB(*Mem + i)), 2, "0") + " "
    If i % 16 = 15 : s + #CRLF$ : EndIf
  Next
  ProcedureReturn s
EndProcedure
If this is too elementary, let me know and I'll delete the post.

cheerts

Re: How does showmemoryviewer work

Posted: Fri Nov 28, 2025 10:21 am
by mk-soft
Just a small mistake ...

Take unsigned byte (#PB_Ascii) and specify at Hex(..., Type).

Code: Select all


Structure ArrayOfByte
  StructureUnion
    a.a[0] ; Unsigned Byte, 0 == Undefined size
    b.b[0] ; Signed Byte, 0 == Undefined size
  EndStructureUnion
EndStructure

Procedure.s MemToHex(*Mem, Size)
  Protected s.s = ""
  For i = 0 To Size-1
    s + RSet(Hex(PeekA(*Mem + i), #PB_Ascii), 2, "0") + " "
    If i % 16 = 15 : s + #CRLF$ : EndIf
  Next
  ProcedureReturn s
EndProcedure

Procedure.s MemToHex2(*Mem.ArrayOfByte, Size)
  Protected r1.s
  Size - 1
  For i = 0 To Size
    r1 + RSet(Hex(*Mem\a[i], #PB_Ascii), 2, "0") + " "
    If i % 16 = 15 : r1 + #LF$ : EndIf
  Next
  ProcedureReturn r1
EndProcedure

*key = AllocateMemory(48)
RandomData(*key, 48)

s.s = MemToHex(*key, 48)
Debug s
s.s = MemToHex2(*key, 48)
Debug s

ShowMemoryViewer(*key, 48)

Re: How does showmemoryviewer work

Posted: Fri Nov 28, 2025 3:30 pm
by juror
Guess I didn't "got it" after all. Not exactly a "small" mistake. And a simple "ShowMemoryViewer" would have shown me the error :(

Masterful solution.

Many thanks - again.