Jump to content
  • 0

File.seek Method Not Recognized


HorridModz
 Share

Question

I was trying to make an offset to hex tool to directly hex patch methods by offset, when I ran into an error. Here is my code:

function read_file(path) -- Credit to DarkingCheater! I modified it a little 
open = io.open 
local file = open(path, "rb")
if not file then 
return nil 
end 
local content = file:read 
"*a"
file:close()
return content
end

function write_file(path,new)
file = io.open(path, "w")
file:write(new)
file:close()
end

function gethex(directory,offset,bytes)
lib = read_file(directory)
findoffset = tonumber(offset, 16)
lib:seek(0,findoffset)
-- io.seek(libil2cpp,0,findoffset)
return lib:read(tonumber(bytes)).hex().upper()) -- This was copy and pasted from python, I will make it work in lua later. Just ignore this.
end

function example() -- edit this to see what my code does
print(gethex("Your lib file path","(example offset)A00001","(how many bytes, this input does not matter in this case) 32")) -- Edit this to make the script run!

example()

 

You can edit the inputs to make the code run, and you will see my error. When I have it configured correctly for me, this happens:
 

Script ended:
Script error: luaj.o: /sdcard/Download/OffsetToHex.lua:22
`libil2cpp:seek(0,findoffset)`
attempt to call a nil value (method 'seek')
level = 1, const = 11, proto = 0, upval = 1, vars = 8, code = 27
CALL v3..v6
 ; PC 13 CODE 020040DD OP 29 A 3 B 4 C 1 Bx 2049 sBx -129022
stack traceback:
    /sdcard/Download/OffsetToHex.lua:22 in function 'gethex'
    /sdcard/Download/OffsetToHex.lua:27 in main chunk
    [Java]: in ?
    at luaj.LuaValue.a(src:2835)
    at luaj.LuaValue.Z(src:1966)
    at luaj.LuaValue.a(src:1481)
    at luaj.LuaClosure.a(src:536)
    at luaj.LuaClosure.a(src:186)
    at luaj.LuaClosure.a(src:536)
    at luaj.LuaClosure.l(src:160)
    at android.ext.Script.d(src:6056)
    at android.ext.Script$ScriptThread.run(src:5785)

Yes, I have tested and confirmed that the lib file is correct. It is not nil.

So what is the problem?

As the above error message says, gameguardian does not recognize the seek method.

I know my code is correct because of this article.

MUSHclient documentation: contents (gammon.com.au)

 

Can anyone help me with this? Did I do something wrong? Or is this an issue with gameguardian? Or there any workarounds?

 

Thanks so much for reading!

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

You can not call seek on a string, this method is only for data type of userdata obtained by opening a file, for example 

-- assuming that you have a file called data.txt in the same level 

local datas = io.open "data.txt"
print (type(data)) --> userdata 

 

Link to comment
Share on other sites

  • 0
2 hours ago, MAARS said:

You can not call seek on a string, this method is only for data type of userdata obtained by opening a file, for example 

-- assuming that you have a file called data.txt in the same level 

local datas = io.open "data.txt"
print (type(data)) --> userdata 

 

Thanks, but I am confused. So I call seek on the file directory itself?

Link to comment
Share on other sites

  • 0
2 hours ago, MAARS said:

You can not call seek on a string, this method is only for data type of userdata obtained by opening a file, for example 

-- assuming that you have a file called data.txt in the same level 

local datas = io.open "data.txt"
print (type(data)) --> userdata 

 

What is userdata? How do I make sure a file is userdata? @MAARS

Thanks

Link to comment
Share on other sites

  • 0

userdata is just data type like table, string, number, boolean

like i said this data type is return when you open a file using io.open 

Link to comment
Share on other sites

  • 0

Userdatas are objects you can use methods on, eg: 

file:write()

Strings are not objects, they're just.. strings.

You can use "type()" to check whether the instance is a; userdata, functionnumber, string, tablebool, or nil.

print(type("Hello, World!"))--string
print(type(1))--number

So you can just do; 

if type(file) == "userdata" then
	--//code  
end

 

Edited by Ydnac2110
Link to comment
Share on other sites

  • 0
On 6/23/2022 at 6:10 PM, Ydnac2110 said:

Strings are not objects

Actually string are also object, you can call method like
 

local str = "lorem ipsum"

if (str:match "lorem") then
  print ("The string contain 'lorem'")
end 

And there are more method you can call on, from the string library

Edited by MAARS
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.