Jump to content
  • 0

Improve script


Platonic
 Share

Question

Can the script be improved in writing and speed? When i run the script it seems to take a suspicious amount of time to add the string names to the corresponding addresses.  Im not sure how i could improve it so that the script in general goes faster.

local range = gg.getRangesList("anon:linker_alloc")
local valStart = range[3].start + 0x20
local valEnd = range[3]["end"]
local loop = valEnd - valStart

dex = {}
for i = 1, loop do
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250
  if valStart >= range[3]["end"] then break end
end

gg.loadResults(dex)
gg.refineNumber(0, gg.TYPE_QWORD, nil, gg.SIGN_NOT_EQUAL)

local dex = gg.getResults(gg.getResultsCount())
local strPointer = {}
local exe = {}

for i, v in ipairs(dex) do
  strPointer[i] = {address = v.address + 0xC8, flags = gg.TYPE_QWORD}
  exe[i] = {address = v.value, flags = gg.TYPE_DWORD}
end

exe = gg.getValues(exe)
strPointer = gg.getValues(strPointer)

local lup = 1
local executable = {}

for i = 1, #exe do
  local stringAddress = {}
  local final = {}
  for j = 1, 150 do
    stringAddress[#stringAddress + 1] = {address = strPointer[lup].value, flags = gg.TYPE_BYTE}
    strPointer[lup].value = strPointer[lup].value + 1
  end
  strings = gg.getValues(stringAddress)
  for b, t in ipairs(strings) do
    if strings[b].value ~= "0" then
      final[#final + 1] = string.char(t.value&0xFF)
      a = table.concat(final)
    else
      break
    end
  end
  executable[#executable + 1] = {address = exe[i].address, flags = gg.TYPE_DWORD, name = a}
  lup = lup + 1
end
gg.addListItems(executable)

local lib = {}
for i, v in ipairs(executable) do
  if (string.find(v.name, "libil2cpp.so")) ~= nil then
    lib[#lib + 1] = v
    break
  end
end
gg.loadResults(lib)

 

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0
3 hours ago, MAARS said:

Can you tell the purpose of the script please ?

 

Must load start address of executables with there responding path name. I use it if i need to find for example the libil2cpp.so in a split apk without moving the files to different folder.

 

Screenshot_2023-01-19-18-47-34-963_com.miui.home.jpg

Screenshot_2023-01-19-18-48-02-334_com.android.chrome.jpg

But its only made for my device, wont work on most other devices. Offsets different..etc

Edited by Platonic
Added screenshot
Link to comment
Share on other sites

  • 0

Rewrite of the loop with inner loops with comments to main fixed issues (one mistake and one statement misplacement): 

local executable = {}

for i = 1, #exe do
  local stringBytes = {}
  local startAddress = strPointer[i].value - 1
  for j = 1, 150 do
    stringBytes[j] = {address = startAddress + j, flags = gg.TYPE_BYTE}
  end
  stringBytes = gg.getValues(stringBytes)
  local stringChars = {}
  for index, byte in ipairs(stringBytes) do
    local value = byte.value
    if value == 0 then -- comparison to string "0" is a mistake since value field is a number
      break
    end
    stringChars[index] = string.char(value & 0xFF)
  end
  local str = table.concat(stringChars) -- get final string only once after construction of table with characters is finished
  executable[i] = {address = exe[i].address, flags = gg.TYPE_DWORD, name = str}
end
gg.addListItems(executable)
Link to comment
Share on other sites

  • 0
1 minute ago, Platonic said:

Is there specific reason why byte.value got referenced through the variable "value" ?

Only because it's a suitable name for the variable, could have been any other suitable name with the same success. As for the reason of having the variable, it's a small optimization to not have to get the same value from table two times.

Link to comment
Share on other sites

  • 0
On 1/19/2023 at 8:00 AM, Platonic said:

Can the script be improved in writing and speed? When i run the script it seems to take a suspicious amount of time to add the string names to the corresponding addresses.  Im not sure how i could improve it so that the script in general goes faster.

local range = gg.getRangesList("anon:linker_alloc")
local valStart = range[3].start + 0x20
local valEnd = range[3]["end"]
local loop = valEnd - valStart

dex = {}
for i = 1, loop do
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250
  if valStart >= range[3]["end"] then break end
end

gg.loadResults(dex)
gg.refineNumber(0, gg.TYPE_QWORD, nil, gg.SIGN_NOT_EQUAL)

local dex = gg.getResults(gg.getResultsCount())
local strPointer = {}
local exe = {}

for i, v in ipairs(dex) do
  strPointer[i] = {address = v.address + 0xC8, flags = gg.TYPE_QWORD}
  exe[i] = {address = v.value, flags = gg.TYPE_DWORD}
end

exe = gg.getValues(exe)
strPointer = gg.getValues(strPointer)

local lup = 1
local executable = {}

for i = 1, #exe do
  local stringAddress = {}
  local final = {}
  for j = 1, 150 do
    stringAddress[#stringAddress + 1] = {address = strPointer[lup].value, flags = gg.TYPE_BYTE}
    strPointer[lup].value = strPointer[lup].value + 1
  end
  strings = gg.getValues(stringAddress)
  for b, t in ipairs(strings) do
    if strings[b].value ~= "0" then
      final[#final + 1] = string.char(t.value&0xFF)
      a = table.concat(final)
    else
      break
    end
  end
  executable[#executable + 1] = {address = exe[i].address, flags = gg.TYPE_DWORD, name = a}
  lup = lup + 1
end
gg.addListItems(executable)

local lib = {}
for i, v in ipairs(executable) do
  if (string.find(v.name, "libil2cpp.so")) ~= nil then
    lib[#lib + 1] = v
    break
  end
end
gg.loadResults(lib)

 

for i = 1, loop do
if valStart >= range[3]["end"] then break ---->>>>>> make the if statment at the start so it won't add some unwanted addresses an cause crush later
dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
valStart = valStart + 0x250

end
end

Link to comment
Share on other sites

  • 0
20 hours ago, XEKEX said:

for i = 1, loop do
if valStart >= range[3]["end"] then break ---->>>>>> make the if statment at the start so it won't add some unwanted addresses an cause crush later
dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
valStart = valStart + 0x250

end
end

Hmm although i see what you mean. I just printed out but i can't see a difference that would cause unwanted addresses.

When the condition in the loop is met it will break the loop. In this case regardless if the if statement is placed at start or end. Because the variable varStart gets incremented by 250 before new address and flags gets added to the dex table. So actually i think its better that the if statement is at the end(in this case) so that the loop gets broken before the loop increments.

dex = {}
for i = 1, loop do
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250 
  if valStart >= range[3]["end"] then break end -- break before loop gets incremented
end

But let me know your opinion.

 

Edited by Platonic
Edited comment in script
Link to comment
Share on other sites

  • 0
On 1/21/2023 at 7:56 AM, Platonic said:

Hmm although i see what you mean. I just printed out but i can't see a difference that would cause unwanted addresses.

When the condition in the loop is met it will break the loop. In this case regardless if the if statement is placed at start or end. Because the variable varStart gets incremented by 250 before new address and flags gets added to the dex table. So actually i think its better that the if statement is at the end(in this case) so that the loop gets broken before the loop increments.

dex = {}
for i = 1, loop do
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250 
  if valStart >= range[3]["end"] then break end -- break before loop gets incremented
end

But let me know your opinion.

 

lua script runs from top to buttom it won't execute the condition befor the the val get increment also last value in dex won't meet the requirement for the condition this is why u need to put all conditions on top of the loop
885131675_Capturedcran2023-01-22082850.thumb.png.3ec86f73d717ca3d637e1b952b250a6d.png

Link to comment
Share on other sites

  • 0
2 hours ago, XEKEX said:

lua script runs from top to buttom it won't execute the condition befor the the val get increment also last value in dex won't meet the requirement for the condition this is why u need to put all conditions on top of the loop
885131675_Capturedcran2023-01-22082850.thumb.png.3ec86f73d717ca3d637e1b952b250a6d.png

This is my point, it does meet the requirement because valStart gets incremented by 0x250 before the if statement will check and compare valStart. If i put the if statement at the top, the loop will index once more which is a waste to do because we already know that the value has reached the condition when valStart was incremented. So for that reason i placed the if statement at the bottom.

dex = {}
for i = 1, loop do
if valStart >= range[3]["end"] then 
print(i, "Condition: "..string.format("%x",  valStart), string.format("%x", valEnd))
break end
print(i, "Current: "..string.format("%x",  valStart),"End address: "..string.format("%x", valEnd))
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250
end

Look like this: 

Screenshot_2023-01-22-10-39-31-235_com_rs.explorer.filemanager.thumb.jpg.842fa24578778500e79441bdecd4d9d3.jpg

It will increment loop once more and then do the break. At the top.

But here i do if statement at the botton before loop index increments:

dex = {}
for i = 1, loop do
print(i, "Current: "..string.format("%x",  valStart),"End address: "..string.format("%x", valEnd))
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250
if valStart >= range[3]["end"] then 
print(i, "Condition: "..string.format("%x",  valStart), string.format("%x", valEnd))
break end
end

IMG_20230122_104500.thumb.jpg.3be8caad707a63f0cd76bcaee3c1c461.jpg

Edited by Platonic
Link to comment
Share on other sites

  • 0
On 1/19/2023 at 9:00 AM, Platonic said:

Can the script be improved in writing and speed? When i run the script it seems to take a suspicious amount of time to add the string names to the corresponding addresses.  Im not sure how i could improve it so that the script in general goes faster.

local range = gg.getRangesList("anon:linker_alloc")
local valStart = range[3].start + 0x20
local valEnd = range[3]["end"]
local loop = valEnd - valStart

dex = {}
for i = 1, loop do
  dex[#dex + 1] = {address = valStart, flags = gg.TYPE_QWORD}
  valStart = valStart + 0x250
  if valStart >= range[3]["end"] then break end
end

gg.loadResults(dex)
gg.refineNumber(0, gg.TYPE_QWORD, nil, gg.SIGN_NOT_EQUAL)

local dex = gg.getResults(gg.getResultsCount())
local strPointer = {}
local exe = {}

for i, v in ipairs(dex) do
  strPointer[i] = {address = v.address + 0xC8, flags = gg.TYPE_QWORD}
  exe[i] = {address = v.value, flags = gg.TYPE_DWORD}
end

exe = gg.getValues(exe)
strPointer = gg.getValues(strPointer)

local lup = 1
local executable = {}

for i = 1, #exe do
  local stringAddress = {}
  local final = {}
  for j = 1, 150 do
    stringAddress[#stringAddress + 1] = {address = strPointer[lup].value, flags = gg.TYPE_BYTE}
    strPointer[lup].value = strPointer[lup].value + 1
  end
  strings = gg.getValues(stringAddress)
  for b, t in ipairs(strings) do
    if strings[b].value ~= "0" then
      final[#final + 1] = string.char(t.value&0xFF)
      a = table.concat(final)
    else
      break
    end
  end
  executable[#executable + 1] = {address = exe[i].address, flags = gg.TYPE_DWORD, name = a}
  lup = lup + 1
end
gg.addListItems(executable)

local lib = {}
for i, v in ipairs(executable) do
  if (string.find(v.name, "libil2cpp.so")) ~= nil then
    lib[#lib + 1] = v
    break
  end
end
gg.loadResults(lib)

I've also discovered a great passion for math problems. I try to solve as many of them as possible to develop my logic and intelligence. But sometimes even I couldn't cope, that's why I get help here https://assignmentbro.com/us/math-assignment-help from math experts. I think it will be useful for you if you are also a student like me, even with the most difficult problems in higher math can quickly cope.

I tried to test your script, but it gives me an error. Did you change anything in the end?

Link to comment
Share on other sites

  • 0
On 1/23/2023 at 12:21 PM, XEKEX said:

 

 

15 minutes ago, Stillo said:

I tried to test your script, but it gives me an error. Did you change anything in the end?

I don't think i changed anything here except for the parts mentioned by CmP. Also i lost this script with all other scripts posted here due to loss of device, so i don't remember which changes i made personally. Also the script is not made for work on all devices. It was made based on the device i was working with. 

Link to comment
Share on other sites

  • 0
26 minutes ago, Stillo said:

I've also discovered a great passion for math problems. I try to solve as many of them as possible to develop my logic and intelligence. But sometimes even I couldn't cope, that's why I get help here https://assignmentbro.com/us/math-assignment-help from math experts. I think it will be useful for you if you are also a student like me, even with the most difficult problems in higher math can quickly cope.

My math very little. Thanks for the link, but i think i need to pay. 

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.