Jaran Bjortomt Jaran Bjortomt - 1 year ago 92
Vb.net Question

Finding a specific value in a file

I am trying to make a simple program to find some values in a file. These files are

files and belong to the game ARK.

These .arkprofile files include some readable text as well as some scrambled text if you open it in a regular editor. All the values I need are in ASCII so I could get them all manually, but the intention of this program is to go through a lot of files to grab out the character names. Here is how it looks like in the file in a regular text editor:


Can I find this string without decompiling the file as hex first? Is it possible to convert the string to bytes and do the search from there?

This is the code I have at the moment, but it is not suited for my need as the hex offset for the string is not the same for all the files.

Dim pos1 As Long = 864

Dim requiredBytes As Integer = 160
Dim value(0 To requiredBytes - 1) As Byte
Using reader As New BinaryReader(File.Open(fd.FileName, FileMode.Open))
' Loop through length of file.
Dim fileLength As Long = reader.BaseStream.Length
Dim byteCount As Integer = 0
reader.BaseStream.Seek(pos1, SeekOrigin.Begin)
While pos1 < fileLength And byteCount < requiredBytes
value(byteCount) = reader.ReadByte()
pos1 += 1
byteCount += 1
End While
End Using

The dots between the strings change hex value from file to file, but its always the same amount of dots. Max character name allowed on ARK is 24, so my idea now was to first find that string in the file, start writing bytes from the end of that file for 128 bytes. "PlayerCharacterName.....StrProperty............." = 60 bytes. This is where the username would start and can be up to 24 characters long which is 48 bytes. Then I could filter out the remaining characters that are not a part of the username and display it in ASCII.

Am I way off track here?

Answer Source

This sounds like a job for a regular expression:

Public Function GetCharacterName(ByVal filePath As String) As String
    Dim exp As New RegEx("PlayerCharacterName.{5}StrProperty.{13}(.{1,24})")
    For Each line As String In File.ReadLines(filePath)
        Dim result = exp.Match(line)
        If result.Success Then
            Return result.Groups(1).Value
        End If
    Next line
    Return Nothing
End Function

My only concern with this is whether I built the expression correctly (I didn't have Visual Studio or real sample data handy) and whether some of the unprintable characters might produce an unexpected newline or multi-byte character.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download