Endless Paradigm

Full Version: hex
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can anyone show me a simple example of how to hex edit a value with lua code ???

Thanks in advance.  

I have a cool idea I would like to work on  [Image: tongue.gif]
I don't really do LUA but maybe this could help you,

Not sure about the r+ but looking at http://luanet.net/lua/function/io.open    "r+": update mode, all previous data is preserved;

Code:
file = io.open("myFile.bleh", "r+")
file:seek("set", 0x03)
file:write(0x01)
file:close()

Cool thanks Hibby.

What is the "set" ?
Could you please explain that a little ?
Should seek you to the postion in file that you want to edit,  in this case 0x03

file:seek("set", 0x03)

This will write the new value to the position previously set,

file:write(0x01)

So what it should do is write the value 0x01 to position 0x03
sounds to me like a psp based prx editor :O

epic win right there!!
Thanks Hibby.
A question:

When I use this code: (just a quick example - not actually the file in the pick below...)

Code:
if pad:cross() and current == 6 then

file = io.open("flash0:/vsh/module/vsh.prx", "r+")
file:seek("set", "0x41290")
file:write(" m.B")
file:close()   
screen:clear()
PrintCentered(120,"DONE !!",green)
screen.flip()
screen.waitVblankStart(200)
end


It will directly enter the values in the right box, instead of the left.
(it alters the data in left box but directly enters it into the right box)

This has been a pain, b/c when I enter a "." in the right box, it will come up with a "2E" value in the left box, instead of the desired "00" value...

Is there a way to either:

1) directly alter the data in the left box

2) make a "." entered in the right, show as a "00" in the left box, instaed of a "2E" ??

or
3) probably the best & easiest solution:

is there code to alter the 32 bit float values of an adrress ??

Here is a screen of the hex editor on PC im using to check my result (just so you know what im referring to with "left box" and "right  box"



Thanks again Hibby.


~shizzy

Mr. Shizzy Wrote:It will directly enter the values in the right box, instead of the left.
Just to make things easier, the "left box" is the hex display, whereas the "right box" is the ASCII display.

Don't know LUA, but from what I can tell, it doesn't really have "data types".  PHP offers a pack() function to convert things to appropriate binary formats, but it doesn't seem LUA has something similar. (typically, you'd define a floating point variable, and just output that directly)

As for outputting strings, typically the language provides escape sequences for the null (0x00) character (eg \0 in C), but I can't seem to find such a thing for LUA (http://www.lua.org/pil/2.4.html).
So could something like this be done ??

Code:
function alter_float()
file = io.open("ms0:/paf.prx", "r+")
file:seek("set", 0x1A4AE0)
file:writeFloatvalue("0.5")
file:close()   
end

Dunno, looks okay, give it a try!
Reference URL's