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 


Read/Edit a File like a Hex-Editor/Patch?

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

Joined: 15 Mar 2012
Posts: 80

PostPosted: Wed May 20, 2015 6:43 am    Post subject: Read/Edit a File like a Hex-Editor/Patch? Reply with quote

Hi.

I want to open/read a file and do a AOB scan with wildcards like a Hex-Editor(not for show, only to edit) or Patch.

This is my code

Code:

  local dialog=createOpenDialog()
  dialog.Filename='WET'
  dialog.DefaultExt=".EXE"
  dialog.Filter="WET (*.EXE)|*.EXE"
  dialog.FilterIndex=1
  dialog.Options = '[ofEnableSizing]'

  if dialog.execute() then
    local sFName = dialog.Filename
    local file = assert(io.open(sFName, "r+b"))
    local data = file:read("*all")
    print(data:find(string.format("%c%c%c",0x0d,0x0a,0x24))) --"08 0A 24" only for test
    file:close()
  end


The AOB "08 0A 24" exist in WET.EXE but i get an error if i try to find the ABO with 0x24. Without it works. Whats wrong?

If i search for other AOB i get sometimes strange results. Sometimes i get the correct Offset and if i use a other AOB i get the correct Offset+1?

How can i read a file and edit it like a hexedito or patchr?
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Sat May 23, 2015 6:12 am    Post subject: Reply with quote

From ce menu 'file'->'open file', you can load a file content like a running process. Memory address 0 is the beginning of the file. The ce act like a hex-editor now.
Warned that any memory write will alternate the file content on disk immediately, better make a backup before doing this.
Also the ce may behave a bit abnormal after loading a file as process (situation encountered on my previous ce version, may be just me...), close ce if need.
Back to top
View user's profile Send private message
sir-gunny
Advanced Cheater
Reputation: 0

Joined: 15 Mar 2012
Posts: 80

PostPosted: Mon May 25, 2015 2:39 pm    Post subject: Reply with quote

Hi.

I know about 'file'->'open file' but I need to open it with a lua funktion like openProcess().

I found out why i get nil when I search with string.find to string.char(0x0A)..string.char(0x24). I now add every punctuation character a "%". It works fine but i dont know how i get nil if i try to search for "6a 01 6a ?? 6a 01 50 2e". If i use "6a ?? 6a ?? 6a 01 50 2e" i get the Offset.

Code:
function _bla()
  local sFixedData
  local sExeNameZusatz = ""
  local dialog=createOpenDialog()
  dialog.Filename='WET'
  dialog.DefaultExt=".EXE"
  dialog.Filter="WET (*.EXE)|*.EXE"
  dialog.FilterIndex=1
  dialog.Options = '[ofEnableSizing]'
--  dialog.InitialDir = "F:\\WET"

  if dialog.execute() then
     sWetExePfad = dialog.Filename
     local file = assert(io.open(sWetExePfad, "rb"))
     sWetExeData = file:read("*all")
     file:close()
     local iTimeFixOffset, iLvl2ZielOffset
     local sWetName = (sWetExeData:find("WET THE SEXY EMPIRE") ~= nil)
     if sWetName then
        iTimeFixOffset = sWetExeData:find(_AOB2String("6a ?? 6a ?? 6a 01 50 2e"))--ff 15
        if iTimeFixOffset then iTimeFixOffset = iTimeFixOffset +2 end
        iLvl2ZielOffset = sWetExeData:find(_AOB2String("81 3D ?? ?? ?? ?? ?? ?? ?? ?? 0F 8C"))
        if iLvl2ZielOffset then iLvl2ZielOffset = iLvl2ZielOffset +5 end
     end

     if iTimeFixOffset and iLvl2ZielOffset and sWetName then
        showMessage("Data loaded!")
     else
        showMessage("Data not loaded!")
     end
  end
end

function _AOB2String(cString)
  local myTable = {}
  local i=1
  local hNumber, iIfCharP
  cString = string.gsub(cString, "%s" , "")
    for v in string.gfind(cString, "..") do
       hNumber = tonumber(v,16)
       if hNumber then
          myTable[i] = string.char(hNumber)
          iIfCharP = string.find(myTable[i],"%p")
          if iIfCharP then
             myTable[i] = "%"..myTable[i]
          end
       else
          myTable[i] = "."
       end
       i= i+1
    end
  return table.concat(myTable)
end


Edit:
By the way. Is it possible to change the textcolor of the selectet row in a listviewitem?
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