[solved] How to get a string from an element of data type unicode in a structure

Just starting out? Need help? Post your questions and find answers here.
Zero Ray
User
User
Posts: 10
Joined: Sat Jan 06, 2024 7:02 am

[solved] How to get a string from an element of data type unicode in a structure

Post by Zero Ray »

Hello everyone!
I've tried enumerating the UEFI startup entries with the following code:

Code: Select all

EnableExplicit

Structure BootOrder Align #PB_Structure_AlignC
  BootOrderList.w[128]
EndStructure

Structure _EFI_LOAD_OPTION Align #PB_Structure_AlignC
  Attributes.l
  FilePathListLength.w
  Description.u[256]
EndStructure

Prototype.l ProtoGetFirmwareEnvironmentVariableEx(Name.p-unicode, GUID.p-unicode, Buffer.l, Size.l, Attrib.l)

Define BootOrder.BootOrder
Define EFILoadOption._EFI_LOAD_OPTION
Define GetFirmwareEnvironmentVariableEx.ProtoGetFirmwareEnvironmentVariableEx
Define Attrib.l
Define BootOrderSize.i
Define tmp.b
Define i.i
Define BootSequence$

If OpenLibrary(0, "Kernel32.dll")
  GetFirmwareEnvironmentVariableEx = GetFunction(0, "GetFirmwareEnvironmentVariableExW")
EndIf

RtlAdjustPrivilege_(22, 1, 0, @tmp)
BootOrderSize = GetFirmwareEnvironmentVariableEx("BootOrder", "{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}", @BootOrder, SizeOf(BootOrder), @Attrib)
If BootOrderSize
  For i = 0 To BootOrderSize/SizeOf(word)-1
    BootSequence$ = "Boot" + RSet(Hex(BootOrder\BootOrderList[i], #PB_Long), 4, "0")
    GetFirmwareEnvironmentVariableEx(BootSequence$, "{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}", @EFILoadOption, SizeOf(EFILoadOption), @Attrib)
    Debug BootSequence$ + ": " + PeekS(@EFILoadOption\Description)
  Next
EndIf
RtlAdjustPrivilege_(22, 0, 0, @tmp)
However, I don't know how to get the string from EFILoadOption\Description
Last edited by Zero Ray on Sat Jan 06, 2024 3:17 pm, edited 1 time in total.
User avatar
skywalk
Addict
Addict
Posts: 4210
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to get a string from an element of data type unicode in a structure

Post by skywalk »

PeekS()
And you can use the memory viewer to verify it is actually filled.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to get a string from an element of data type unicode in a structure

Post by infratec »

I would use:

Code: Select all

PeekS(@EFILoadOption\Description[0])
Zero Ray
User
User
Posts: 10
Joined: Sat Jan 06, 2024 7:02 am

Re: How to get a string from an element of data type unicode in a structure

Post by Zero Ray »

infratec wrote: Sat Jan 06, 2024 10:32 am I would use:

Code: Select all

PeekS(@EFILoadOption\Description[0])
Solved! Thanks for your help!
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How to get a string from an element of data type unicode in a structure

Post by Fred »

For this case, you can also use fixed strings to use it directly:

Code: Select all

Structure BootOrder Align #PB_Structure_AlignC
  BootOrderList.s{128}
EndStructure
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to get a string from an element of data type unicode in a structure

Post by infratec »

If the returned string is unicode ...

else you need the PeekS() solution.
Zero Ray
User
User
Posts: 10
Joined: Sat Jan 06, 2024 7:02 am

Re: How to get a string from an element of data type unicode in a structure

Post by Zero Ray »

Fred wrote: Sat Jan 06, 2024 11:34 am For this case, you can also use fixed strings to use it directly:

Code: Select all

Structure BootOrder Align #PB_Structure_AlignC
  BootOrderList.s{128}
EndStructure
Can you give a full example? Thanks,
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to get a string from an element of data type unicode in a structure

Post by mk-soft »

Is used as a normal string.
But don't know what the API call looks like. Please provide a description

Code: Select all

Structure BootOrder Align #PB_Structure_AlignC
  BootOrderList.s{128}
EndStructure

Define api_dummy.BootOrder

api_dummy\BootOrderList = "xyz"

r1.s = api_dummy\BootOrderList
Debug r1
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
Zero Ray
User
User
Posts: 10
Joined: Sat Jan 06, 2024 7:02 am

Re: How to get a string from an element of data type unicode in a structure

Post by Zero Ray »

mk-soft wrote: Sat Jan 06, 2024 12:42 pm Is used as a normal string.
But don't know what the API call looks like. Please provide a description

Code: Select all

Structure BootOrder Align #PB_Structure_AlignC
  BootOrderList.s{128}
EndStructure

Define api_dummy.BootOrder

api_dummy\BootOrderList = "xyz"

r1.s = api_dummy\BootOrderList
Debug r1
https://uefi.org/specs/UEFI/2.10/03_Boo ... rogramming
Olli
Addict
Addict
Posts: 1196
Joined: Wed May 27, 2020 12:26 pm

Re: How to get a string from an element of data type unicode in a structure

Post by Olli »

Fred wrote: Sat Jan 06, 2024 11:34 am For this case, you can also use fixed strings to use it directly:

Code: Select all

Structure BootOrder Align #PB_Structure_AlignC
  BootOrderList.s{128}
EndStructure
We maybe could nest it.

Code: Select all

Structure _EFI_LOAD_OPTION Align #PB_Structure_AlignC
  Attributes.l
  FilePathListLength.w
  StructureUnion
    Description.u[256]
    BootOrderList.s{512}
  EndStructureUnion
EndStructure
Post Reply