[solved]Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

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]Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by Zero Ray »

Code: Select all

EnableExplicit

Structure BootOrder
  BootOrderList.l[128]
EndStructure

Prototype.l ProtoNtQueryBootEntryOrder(Ids.l, Count.l)

Global NtQueryBootEntryOrder.ProtoNtQueryBootEntryOrder

If OpenLibrary(0, "ntdll.dll")
  NtQueryBootEntryOrder = GetFunction(0, "NtQueryBootEntryOrder")
EndIf

Procedure Test()
  Protected BootOrder.BootOrder, Ids.l, Count.l, tmp.b, State.i
  
  Count = SizeOf(BootOrder)
  RtlAdjustPrivilege_(22, 1, 0, @tmp)
  State = NtQueryBootEntryOrder(@BootOrder, @Count)
  RtlAdjustPrivilege_(22, 0, 0, @tmp)
  ProcedureReturn State
EndProcedure

Debug Test()

Define BootOrder.BootOrder, Ids.l, Count.l, tmp.b, State.i

Count = SizeOf(BootOrder)
RtlAdjustPrivilege_(22, 1, 0, @tmp)
State = NtQueryBootEntryOrder(@BootOrder, @Count)
RtlAdjustPrivilege_(22, 0, 0, @tmp)
Debug State
Why are the execution results in the procedure inconsistent with the results in the non-procedure ?
Last edited by Zero Ray on Sun Feb 04, 2024 2:43 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by mk-soft »

A Boolean ist not a Byte -> tmp.b -> tmp.i
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: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by Zero Ray »

mk-soft wrote: Sat Feb 03, 2024 1:45 pm A Boolean ist not a Byte -> tmp.b -> tmp.i
After correcting it to tmp.i, the result is still the same
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by mk-soft »

Here both result a same.

What OS and PB Version.
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: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by Zero Ray »

mk-soft wrote: Sat Feb 03, 2024 2:09 pm Here both result a same.

What OS and PB Version.
Windows 8.1 x64 And PureBasic 6.04 LTS x64
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by fryquez »

NT API functions require *buffers to aligned by 16 Bytes on x64.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by breeze4me »

The value of the "Count" variable seems to be the number of entries, not the memory size.
And some variable types are incorrect.

Run it as an administrator.

Code: Select all

EnableExplicit

Structure BootOrder
  BootOrderList.l[128]
EndStructure

Prototype.l ProtoNtQueryBootEntryOrder(*Ids, *Count)

Global NtQueryBootEntryOrder.ProtoNtQueryBootEntryOrder

If OpenLibrary(0, "ntdll.dll")
  NtQueryBootEntryOrder = GetFunction(0, "NtQueryBootEntryOrder")
EndIf

Procedure.l Test()
  Protected BootOrder.BootOrder, Count.l, tmp.i, State.l
  
  ;Count = SizeOf(BootOrder)
  Count = 128    ;OK on my PC.
  RtlAdjustPrivilege_(22, 1, 0, @tmp)
  State = NtQueryBootEntryOrder(@BootOrder, @Count)
  Debug "Count: " + Count
  RtlAdjustPrivilege_(22, 0, 0, @tmp)
  ProcedureReturn State
EndProcedure

Debug "Result: " + Test()

Define BootOrder.BootOrder, Count.l, tmp.i, State.l

;Count = SizeOf(BootOrder)
Count = 128
RtlAdjustPrivilege_(22, 1, 0, @tmp)
State = NtQueryBootEntryOrder(@BootOrder, @Count)
Debug "Count: " + Count
RtlAdjustPrivilege_(22, 0, 0, @tmp)
Debug "Result: " + State
Zero Ray
User
User
Posts: 10
Joined: Sat Jan 06, 2024 7:02 am

Re: Why are the execution results in the procedure inconsistent with the results in the non-procedure ?

Post by Zero Ray »

breeze4me wrote: Sat Feb 03, 2024 3:18 pm The value of the "Count" variable seems to be the number of entries, not the memory size.
And some variable types are incorrect.

Run it as an administrator.

Code: Select all

EnableExplicit

Structure BootOrder
  BootOrderList.l[128]
EndStructure

Prototype.l ProtoNtQueryBootEntryOrder(*Ids, *Count)

Global NtQueryBootEntryOrder.ProtoNtQueryBootEntryOrder

If OpenLibrary(0, "ntdll.dll")
  NtQueryBootEntryOrder = GetFunction(0, "NtQueryBootEntryOrder")
EndIf

Procedure.l Test()
  Protected BootOrder.BootOrder, Count.l, tmp.i, State.l
  
  ;Count = SizeOf(BootOrder)
  Count = 128    ;OK on my PC.
  RtlAdjustPrivilege_(22, 1, 0, @tmp)
  State = NtQueryBootEntryOrder(@BootOrder, @Count)
  Debug "Count: " + Count
  RtlAdjustPrivilege_(22, 0, 0, @tmp)
  ProcedureReturn State
EndProcedure

Debug "Result: " + Test()

Define BootOrder.BootOrder, Count.l, tmp.i, State.l

;Count = SizeOf(BootOrder)
Count = 128
RtlAdjustPrivilege_(22, 1, 0, @tmp)
State = NtQueryBootEntryOrder(@BootOrder, @Count)
Debug "Count: " + Count
RtlAdjustPrivilege_(22, 0, 0, @tmp)
Debug "Result: " + State
It worked, thank you very much!
Post Reply