Jump to content

3 Screenshots

About This File

Convert hexadecimal <==> decimal

Edited by MAARS


User Feedback

Recommended Comments

Platonic

Posted

Script works, would be great for it to convert hex to signed 2s compliment.

MAARS

Posted

Binary you mean ?

Platonic

Posted

10 hours ago, MAARS said:

Binary you mean ?

Yes binary, using 2s compliment for represent signed integers. Or if there are other ways. 

Platonic

Posted (edited)

1 hour ago, MAARS said:

I don't know exactly what is it and what is the use of that xD but it seems not too complicated to implement in Lua. 

https://www.allmath.com/twos-complement.php

Yes, i ask because purpose of your script is to convert hex to decimal. So i think you want to set conditions based on the range of the value that they want to convert. And its GG, so i think your working with data types, data types of int are signed i believe in which positive and negative values are represented, so your script should as output be able to show signed int.

Edited by Platonic
HorridModz

Posted

I wish I would have used this - it would have saved ages!

Here's my solution:

function armtohex(fullarm)
	progressalert("Converting edit value",false)
	fullhex = ""
	--Thanks to Enyby for the original arm hex converter I used code from:
	-- https://gameguardian.net/forum/files/file/2004-arm-converter/
	for arm in string.gmatch(fullarm,'[^\r\n]+') do 
		progressalert("Converting edit value",false)
		local addr = gg.getRangesList('libc.so')
		for i, v in ipairs(addr) do
			if v.type:sub(2,2) == 'w' then
				addr = {{address = v.start, flags = gg.TYPE_DWORD}}
			end
		end
		if not addr[1].address then
			print("Error occured converting arm code to hex: Failed to get address ", addr)
			gg.setVisible(true)
			os.exit()
		end
		if is64bit then
			--Armv8 (64bit)
			local old = gg.getValues(addr)
			addr[1].value = '~A8 '..arm
			local ok, err = pcall(gg.setValues, addr)
			local out
			if not ok then
				err = err:gsub("^.* '1': ", ''):gsub('\nlevel = 1.*$', '')
				print("Error occured converting arm code to hex: " .. err)
				gg.setVisible(true)
				os.exit()
			else
				out = gg.getValues(addr)
				out = out[1].value & 0xFFFFFFFF
				gg.setValues(old)
				if not hex then
					out = string.unpack('>I4', string.pack('<I4', out))
				end
				out = string.format('%08X', out)
				fullhex = fullhex .. out
			end
		else
			--Armv7 (32bit)
			local old = gg.getValues(addr)
			addr[1].value = '~A '..arm
			local ok, err = pcall(gg.setValues, addr)
			local out
			if not ok then
				err = err:gsub("^.* '1': ", ''):gsub('\nlevel = 1.*$', '')
				print("Error occured converting arm code to hex: " .. err)
				gg.setVisible(true)
				os.exit()
			else
				out = gg.getValues(addr)
				out = out[1].value & 0xFFFFFFFF
				gg.setValues(old)
				if not hex then
					out = string.unpack('>I4', string.pack('<I4', out))
				end
				out = string.format('%08X', out)
				fullhex = fullhex .. out
			end
		end
	end
	return(fullhex)
end

function hextodecimal(hex)
	progressalert("Converting edit value",false)
	--Remove spaces, then reverse bytes (ex: A1 B1 -> B1A1)
	oldhex = string.gsub(tostring(hex)," ","")
	hex = ""
	thisbyte = ""
	for letterindex = 1, #oldhex do
		thisbyte = thisbyte .. oldhex:sub(letterindex,letterindex)
		if #thisbyte == 2 then
			hex = thisbyte .. hex
			thisbyte = ""
		end
	end
	if not(string.sub(hex,1,2) == "0x") then
		hex = "0x" .. hex
	end
	return(tonumber(hex))
	--[[
	--thanks to ItsSC for this function (found at https://gameguardian.net/forum/topic/31634-converting-decimal-to-hex/)
	hex = tonumber(hex)
	gg.alert(tostring(tonumber(hex >= 0 and string.format("%X", tonumber(hex)) or string.format("%X", (hex~ 0xffffffffffffffff <<((math.floor(math.log(math.abs(hex))/math.log(10)) + 1) *4))),16)))
	return(tonumber(hex >= 0 and string.format("%X", tonumber(hex)) or string.format("%X", (hex~ 0xffffffffffffffff <<((math.floor(math.log(math.abs(hex))/math.log(10)) + 1) *4))),16))
	--]]
end

 

MAARS

Posted

22 minutes ago, HorridModz said:

I wish I would have used this - it would have saved ages!

Here's my solution:

function armtohex(fullarm)
	progressalert("Converting edit value",false)
	fullhex = ""
	--Thanks to Enyby for the original arm hex converter I used code from:
	-- https://gameguardian.net/forum/files/file/2004-arm-converter/
	for arm in string.gmatch(fullarm,'[^\r\n]+') do 
		progressalert("Converting edit value",false)
		local addr = gg.getRangesList('libc.so')
		for i, v in ipairs(addr) do
			if v.type:sub(2,2) == 'w' then
				addr = {{address = v.start, flags = gg.TYPE_DWORD}}
			end
		end
		if not addr[1].address then
			print("Error occured converting arm code to hex: Failed to get address ", addr)
			gg.setVisible(true)
			os.exit()
		end
		if is64bit then
			--Armv8 (64bit)
			local old = gg.getValues(addr)
			addr[1].value = '~A8 '..arm
			local ok, err = pcall(gg.setValues, addr)
			local out
			if not ok then
				err = err:gsub("^.* '1': ", ''):gsub('\nlevel = 1.*$', '')
				print("Error occured converting arm code to hex: " .. err)
				gg.setVisible(true)
				os.exit()
			else
				out = gg.getValues(addr)
				out = out[1].value & 0xFFFFFFFF
				gg.setValues(old)
				if not hex then
					out = string.unpack('>I4', string.pack('<I4', out))
				end
				out = string.format('%08X', out)
				fullhex = fullhex .. out
			end
		else
			--Armv7 (32bit)
			local old = gg.getValues(addr)
			addr[1].value = '~A '..arm
			local ok, err = pcall(gg.setValues, addr)
			local out
			if not ok then
				err = err:gsub("^.* '1': ", ''):gsub('\nlevel = 1.*$', '')
				print("Error occured converting arm code to hex: " .. err)
				gg.setVisible(true)
				os.exit()
			else
				out = gg.getValues(addr)
				out = out[1].value & 0xFFFFFFFF
				gg.setValues(old)
				if not hex then
					out = string.unpack('>I4', string.pack('<I4', out))
				end
				out = string.format('%08X', out)
				fullhex = fullhex .. out
			end
		end
	end
	return(fullhex)
end

function hextodecimal(hex)
	progressalert("Converting edit value",false)
	--Remove spaces, then reverse bytes (ex: A1 B1 -> B1A1)
	oldhex = string.gsub(tostring(hex)," ","")
	hex = ""
	thisbyte = ""
	for letterindex = 1, #oldhex do
		thisbyte = thisbyte .. oldhex:sub(letterindex,letterindex)
		if #thisbyte == 2 then
			hex = thisbyte .. hex
			thisbyte = ""
		end
	end
	if not(string.sub(hex,1,2) == "0x") then
		hex = "0x" .. hex
	end
	return(tonumber(hex))
	--[[
	--thanks to ItsSC for this function (found at https://gameguardian.net/forum/topic/31634-converting-decimal-to-hex/)
	hex = tonumber(hex)
	gg.alert(tostring(tonumber(hex >= 0 and string.format("%X", tonumber(hex)) or string.format("%X", (hex~ 0xffffffffffffffff <<((math.floor(math.log(math.abs(hex))/math.log(10)) + 1) *4))),16)))
	return(tonumber(hex >= 0 and string.format("%X", tonumber(hex)) or string.format("%X", (hex~ 0xffffffffffffffff <<((math.floor(math.log(math.abs(hex))/math.log(10)) + 1) *4))),16))
	--]]
end

 

thanks bro, but the purpose of this script was not there convert value to hex bytecodes, it is just for normal hex the base 16

HorridModz

Posted

2 hours ago, MAARS said:

thanks bro, but the purpose of this script was not there convert value to hex bytecodes, it is just for normal hex the base 16

Oh ok, that makes a lot more sense! Nevertheless useful.

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