Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to get a list of drives?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
yazigegeda
Expert Cheater
Reputation: 0

Joined: 22 Jan 2019
Posts: 183

PostPosted: Sat Aug 22, 2020 7:29 pm    Post subject: How to get a list of drives? Reply with quote

Hypothesis:
Code:

a=Getdrivelist()
for i,v in ipairs(a) do
  print(v)
end

print:
      C
      D
      E
      F



Can it be achieved? help me!



1.png
 Description:
 Filesize:  24.23 KB
 Viewed:  1576 Time(s)

1.png


Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Sun Aug 23, 2020 4:44 am    Post subject: Reply with quote

Only work for single letter drives, other info may be easier via an external os command ( power shell thing? )
Code:

function GetDriveLetters() -- return an array table of drive letters
  local M = executeCodeLocal'GetLogicalDrives'
  local drives, dc,dclast = {}, string.byte('AZ',1,-1)
  while M and M ~= 0 and dc <= dclast do
    if (M & 1) ~= 0 then drives[1+#drives] = string.char(dc)end
    dc, M = dc + 1, M >> 1
  end
  return drives
end
--
print(table.concat(GetDriveLetters(),'\r\n'))

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Aug 23, 2020 6:40 am    Post subject: Reply with quote

If want the result as : "C:\" or "D:\", etc then change @Panraven script:

from:

Code:
if (M & 1) ~= 0 then drives[1+#drives] = string.char(dc)end


to:

Code:
if (M & 1) ~= 0 then drives[1+#drives] = string.char(dc)..":\\" end



Other solution:

Using WMI and pipe output to text file:
Code:

os.execute("wmic /OUTPUT:D:\\mydrive.txt logicaldisk get caption,description,drivetype,providername,volumename")
shellExecute("D:\\mydrive.txt")


Question:
@Panraven, could you show how to use kernel32 "GetLogicalDriveStrings()' in CE Lua?. Thanks in advance

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Sun Aug 23, 2020 7:54 am    Post subject: Reply with quote

Code:

function GetLogicalDriveStrings()
  local ms = createMemoryStream()
  local ret = executeCodeLocalEx('GetLogicalDriveStringsW',0,0)--get size in char
  if ret and ret>0 then
    ms.Size = ret * 2 -- wide char x2 bytes
    ret = executeCodeLocalEx('GetLogicalDriveStringsW',ret,ms.Memory)
  end
  local bt = ret and ret~=0 and readBytesLocal(ms.Memory,ret * 2,true)
  if bt then
    for i=1,#bt,2 do -- replace null speartor
      if bt[i]==0 then bt[i]=string.byte';'end
    end
  end
  ret = bt and byteTableToWideString(bt)
  ms.Destroy()
  if not ret then
    return nil,'failed, ret='..tostring(ret)
  else
    return ret
  end
end
--
print(GetLogicalDriveStrings())

note: executeCodeLocalEx not work for 32bit ce

fixedx2: ^<del>make sure ms memory has been setup before call</del> should use readBytesLocal

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Aug 23, 2020 10:31 am    Post subject: Reply with quote

Thanks @Panraven, I see. So the GetLogicalDriveStrings(bufferLength, buffer) function, for the buffer is use createMemoryStream() CE Lua function.
Your script example is clear and easier to understand.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites