Question about reading strings (and the size of a string) from memory (WoW 1.12.1) menu

User Tag List

Results 1 to 6 of 6
  1. #1
    RADONgc's Avatar Active Member
    Reputation
    20
    Join Date
    Jun 2019
    Posts
    7
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about reading strings (and the size of a string) from memory (WoW 1.12.1)

    Hello,

    To preface, I did try to search for this issue however I couldn't find anything that related specifically to the question I'm about to ask.

    I'm finally just now getting a real grasp on how reverse engineering/memory editing works, and I'm currently working on a Multiboxer for wow in C#. (where I only want to do very basic things such as read player name, realm, etc.)
    I've figured out how to read the player name, game version, realm name, etc. And all of these values show up as intended a fair amount of time. However, for something variable such as the player name where the exact size cannot be known (only the maximum size, which is 12 characters in wow) some guesswork is obviously required. My problem is, I am able to retrieve the player name just fine and it shows up correctly, however due to the string size being smaller than others on some characters, I occasionally run into the issue of strings being filled with random garbage at the end. For example, I have a character whose name is 7 characters long, and another whose name is 12 characters long. Since the maximum size of a characters name is 12, I read the player name address with a size of 12. The character whose name is 7 characters long will sometimes contain 2-5 characters of random gibberish at the end, sometimes whitespace.

    My question is, how does one get around this problem? Here is what my code looks like for reading the player name:

    Code:
                    string charNameUnformatted = gameClient.ReadStringBase(Offsets.Player.Name, 12);
    As I stated before, my knowledge is limited and although I've learned a lot in the last couple of days, I am still getting a full understanding of WoW's code structure and the object manager etc. At first I thought only whitespace would show up (as it did the first few times I tested it) and so this was my solution:

    Code:
                    string charName = charNameUnformatted.Replace("\0", "");
    
                    Name = charName;
    which works sometimes, but when the extra memory that I happen to be reading into contains something else, this creates a problem, and the character name ends up looking like this: Hubertth2 (Let's say the character's actual name is 'Hubertt')

    How does one avoid this issue if string size at a given address cannot be known definitively from the start from a programming standpoint?

    Thanks,

    radongc
    Last edited by RADONgc; 06-10-2019 at 05:13 PM.

    Question about reading strings (and the size of a string) from memory (WoW 1.12.1)
  2. #2
    Corthezz's Avatar Elite User Authenticator enabled
    Reputation
    386
    Join Date
    Nov 2011
    Posts
    325
    Thanks G/R
    183/98
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strings are null terminated: Null-terminated string - Wikipedia
    How to utilize the null character is demonstrated here for example: GreyMagic/MemoryBase.cs at master . Konctantin/GreyMagic . GitHub
    Check my blog: https://zzuks.blogspot.com

  3. #3
    RADONgc's Avatar Active Member
    Reputation
    20
    Join Date
    Jun 2019
    Posts
    7
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Corthezz View Post
    Strings are null terminated: Null-terminated string - Wikipedia
    How to utilize the null character is demonstrated here for example: GreyMagic/MemoryBase.cs at master . Konctantin/GreyMagic . GitHub
    Ah, this makes perfect sense, thank you! I just tweaked my code with this in mind and it works as intended now, with less bloat. Good to know for the future.

  4. #4
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1584
    Join Date
    May 2010
    Posts
    1,829
    Thanks G/R
    188/531
    Trade Feedback
    16 (100%)
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Code:
    charNameUnformatted.Replace("\0", "");
    Is that not removing your null terminator?

  5. #5
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1511
    Join Date
    May 2008
    Posts
    2,432
    Thanks G/R
    81/333
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by DarkLinux View Post
    Code:
    charNameUnformatted.Replace("\0", "");
    Is that not removing your null terminator?
    It will remove it but not strip the characters after it.
    Code:
    var terminator = result.IndexOf('\0');
    if (terminator != -1) result = result.Remove(terminator);

  6. #6
    RADONgc's Avatar Active Member
    Reputation
    20
    Join Date
    Jun 2019
    Posts
    7
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by DarkLinux View Post
    Code:
    charNameUnformatted.Replace("\0", "");
    Is that not removing your null terminator?
    It is, I admittedly had no idea what that character was when I saw it while debugging the values read from memory, because the original problem I was having was a lot of whitespace in the string. Not long after, other random chars started popping up and I realized there was something that I was missing...

    You can only learn, no?
    Last edited by RADONgc; 06-11-2019 at 02:13 AM.

Similar Threads

  1. question about reading memory and ranging enemies and turf
    By DannySpark in forum Diablo 3 Bots Questions & Requests
    Replies: 0
    Last Post: 07-31-2013, 09:15 AM
  2. Replies: 6
    Last Post: 09-13-2011, 11:05 PM
  3. couple of questions about servers connecting and update
    By viperguts in forum WoW EMU Questions & Requests
    Replies: 12
    Last Post: 12-13-2008, 04:26 AM
  4. [Question] How do i set the rates of XP and Loot?
    By Gadella in forum World of Warcraft Emulator Servers
    Replies: 2
    Last Post: 12-11-2007, 05:43 AM
All times are GMT -5. The time now is 08:05 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search