How does showmemoryviewer work

Just starting out? Need help? Post your questions and find answers here.
juror
Enthusiast
Enthusiast
Posts: 249
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

How does showmemoryviewer work

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6512
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How does showmemoryviewer work

Post 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)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
juror
Enthusiast
Enthusiast
Posts: 249
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: How does showmemoryviewer work

Post 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.
Post Reply