Python Forum
str.find() not returning correct index.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
str.find() not returning correct index.
#1
Hopefully I'm not being stupid here.
I am searching through a MacOS executable for a certain string (base64 encoded) like so:
with open(self.dir, 'r', encoding="ascii", errors="ignore") as f:
    t = f.read()
    if(b64link in t):
        location = t.find(b64link)
    elif(link in t):
        location = t.find(link)
    else:
        pass
If I open the executable in a hex-editor and search for the string manually, I find that the string is at about lines 5220996 to 5221048. However if I run the above python code, it gets me an index of 2944053 which is totally off. If I open the file, seek to that location and read the length of the string, I get:
Output:
vv=>2q=G>2waQ$S y$S y$? v;<s>2t=ek>6h6}E&U >6}
which, I'm gonna be honest, doesn't look like a base64 string to me. There is absolutely no other places in the file where this string could be found. If there was then the output above would be correct.

Maybe I'm missing something obvious but how come .find() is not returning the correct index?

I've been messing around with it. It seems no matter what I search for, everything is coming up in the wrong place. When I print the contents of 't' to the console, it am able to search for the string. Yet when I use index it just gives total junk.
Reply


Messages In This Thread
str.find() not returning correct index. - by DreamingInsanity - Aug-17-2020, 05:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,974 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,402 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Find index value in List Martin2998 3 2,855 May-12-2020, 02:17 PM
Last Post: deanhystad
  How to find something in a list using its index rix 1 1,775 Dec-20-2019, 04:12 PM
Last Post: stullis
  Find index of missing number parthi1705 3 3,203 May-07-2019, 10:52 AM
Last Post: avorane
  Function not returning correct value ActualNoob 3 2,770 Jan-11-2019, 12:35 AM
Last Post: stullis
  How Do I find Index of a character in string? ilcaa72 5 3,832 May-23-2018, 11:44 PM
Last Post: wavic
  find the index of "Annual" in spell_list nikhilkumar 1 5,690 Jul-12-2017, 04:56 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020