Jump to content
  • 0

File.seek Method Not Recognized


HorridModz

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

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

Link to comment
Share on other sites

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

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

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

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

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.