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 


Using LUA to page thru folders and files

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

Joined: 10 Jan 2016
Posts: 68

PostPosted: Mon May 02, 2016 5:40 am    Post subject: Using LUA to page thru folders and files Reply with quote

hi guys
im trying to create an lua script that search a file for certain keywords, then build another search string from that keyword
in which case it takes the keyword it built and send it to another comandline app toearch and replace all ocurances of the keyword in all specified folders and files...
but...
finding and building the search strings i can do
sending them thru to the command line app i can do
my issue is
for my script...i know only the main folder..after which thers many subfolders etc...lets call the main folder "C:/name-0/"...containing many sub folders...some with their own sub folders for which i dont know their names...for they change each week
then the files i want to page thru...i only know their extension.."*.script" and "*..class" and "*.method"...but dont know their name

so what i want my script to do is starting from the main folder...find the firs file in the folder...build all relevant search strings from it...continue to the nxt file...etc...then, once done with first folder, go to the next folder and repeat the process

how do i get my script to open each file one at a time for which i dont got their file names...
and how do i get my script to go from one folder to the nxt for which i dont have the folder names

regards
basically i want to make my own obfuscation script for my swf files...as swf obfuscaters dont want to work of swf files thats obfuscated already...
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Mon May 02, 2016 5:51 am    Post subject: Re: Using LUA to page thru folders and files Reply with quote

Ludwig wrote:
hi guys
im trying to create an lua script that search a file for certain keywords, then build another search string from that keyword
in which case it takes the keyword it built and send it to another comandline app toearch and replace all ocurances of the keyword in all specified folders and files...
but...
finding and building the search strings i can do
sending them thru to the command line app i can do
my issue is
for my script...i know only the main folder..after which thers many subfolders etc...lets call the main folder "C:/name-0/"...containing many sub folders...some with their own sub folders for which i dont know their names...for they change each week
then the files i want to page thru...i only know their extension.."*.script" and "*..class" and "*.method"...but dont know their name

so what i want my script to do is starting from the main folder...find the firs file in the folder...build all relevant search strings from it...continue to the nxt file...etc...then, once done with first folder, go to the next folder and repeat the process

how do i get my script to open each file one at a time for which i dont got their file names...
and how do i get my script to go from one folder to the nxt for which i dont have the folder names

regards
basically i want to make my own obfuscation script for my swf files...as swf obfuscaters dont want to work of swf files thats obfuscated already...


Either use lfs (LuaFileSystem) : https://github.com/cheat-engine/cheat-engine/tree/master/Cheat%20Engine/bin (in clibs32/64).

Or use another programming language to do the directory handling, and spawn your program from Cheat Engine.
Back to top
View user's profile Send private message
Ludwig
Advanced Cheater
Reputation: 0

Joined: 10 Jan 2016
Posts: 68

PostPosted: Mon May 02, 2016 6:39 am    Post subject: Re: Using LUA to page thru folders and files Reply with quote

Redouane wrote:

Either use lfs (LuaFileSystem) : https://github.com/cheat-engine/cheat-engine/tree/master/Cheat%20Engine/bin (in clibs32/64).

Or use another programming language to do the directory handling, and spawn your program from Cheat Engine.

thnx for pointing me in the right direction...
ill also look at http://stackoverflow.com/questions/5303174/how-to-get-list-of-directories-in-lua
will take me some time figuring it out...but its a start...Smile
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Mon May 02, 2016 9:09 am    Post subject: Reply with quote

Here's an example that will print out every file in CE's directory (including subdirectories):
Code:
f = io.popen("dir \"" .. getCheatEngineDir() .. "\" /A:-D /S /B")
for fpath in f:lines() do
  print(fpath:match("[/\\]?([^/\\]+)$"))  -- for the full dir, just use fpath
end
f:close()

If you're using something besides windows, change the string passed to io.popen.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Ludwig
Advanced Cheater
Reputation: 0

Joined: 10 Jan 2016
Posts: 68

PostPosted: Mon May 02, 2016 10:21 am    Post subject: Reply with quote

ParkourPenguin wrote:
Here's an example that will print out every file in CE's directory (including subdirectories):
Code:
f = io.popen("dir \"" .. getCheatEngineDir() .. "\" /A:-D /S /B")
for fpath in f:lines() do
  print(fpath:match("[/\\]?([^/\\]+)$"))  -- for the full dir, just use fpath
end
f:close()

If you're using something besides windows, change the string passed to io.popen.


Thanks a lot
so...i can try something like
Code:

 local file_list={}
local k=0
local l=0
f = io.popen("dir \"" .. getCheatEngineDir() .. "\" /A:-D /S /B")

for fpath in f:lines() do
   k=k+1
    file_list[k]=fpath:match("[/\\]?([^/\\]+)$")
 
end
f:close()

for l=1, k do

   CurrentFile = io.open(file_list[l], "r");
      if (CurrentFile ~= nil) then

       local all_data = CurrentFile:read()
      end   
   CurrentFile:close();
   GetMyData(all_data);--function that changes values of globals search and replace)
   os.execute("C:/myReplaceApp.exe --"..search.."--"replace)
end




i would like it to make a file list from all files including those in subfolders, starting from say C:\mytestfolder\Name-0\...where Name-0 is the main folder to start with and want to continue from there with all thefiles as well as files in subfolders...in above example...how do i give it the startng folder eg Name-0...as i think your example will print all the file paths, <which i tried storing in an array>


Last edited by Ludwig on Mon May 02, 2016 10:46 am; edited 1 time in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Mon May 02, 2016 10:27 am    Post subject: Reply with quote

Code:
f = io.popen("dir \"C:\\mytestfolder\\Name-0\" /A:-D /S /B")

Also, there is no such thing as a "to" keyword in Lua. Try reading and/or watching a tutorial on Lua first, then start with basic stuff and work your way up to more advanced things.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Ludwig
Advanced Cheater
Reputation: 0

Joined: 10 Jan 2016
Posts: 68

PostPosted: Mon May 02, 2016 10:47 am    Post subject: Reply with quote

ParkourPenguin wrote:
Code:
f = io.popen("dir \"C:\\mytestfolder\\Name-0\" /A:-D /S /B")

Also, there is no such thing as a "to" keyword in Lua. Try reading and/or watching a tutorial on Lua first, then start with basic stuff and work your way up to more advanced things.

thnx..was putting it together a bit quick, and im not a coder...just trying a little...Razz...fixed it

nxt small issue
ive used
--> = string.find("Hello Lua user", "Lua", 1) -- start at first character

before...but
x, y = string.find(datafile,"QName(PackageNamespace(""),",posit1)

contains " in the search string how do i use QName(PackageNamespace(""), as a search string?

edit-----

looks like i have to use it like
x, y = string.find(datafile,"QName(PackageNamespace(\"\"),",posit1)
will test it
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