Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant archive_postsperpage - assumed 'archive_postsperpage' (this will throw an Error in a future version of PHP) in ..../archive/index.php on line 456
Nullset a string [Archive] - Forums

PDA

View Full Version : Nullset a string



Xleniz
07-02-2013, 12:07 PM
HI AGIN.

I decided to make a Tibia - Information program (example, you walk to Edron hero cave, and before stairs down:
STATUS MESSAGE: Heroes - Monsters: Hero),

it works so far, with 1 problem: The text string continues after 0x00 with the text that was there from beginning.

Example: 13:57 Cipfried: Welcome to the temple of Rookgaard!
Will be: Welcome to TibiaMonster 1.0 mple of Rookgaard!

I tried to nullset the string with this:


byte byte1[1000] = "Welcome to TibiaMonster 1.0";
for(int i = 0; i < 972; i++){
byte1[28+i] = 0x00;
}


But problem is, I would have to do it with all byte strings, and it would be painful.
Anyone has an idea?

QUESTION: How to nullset all of string, with inserting 1 character, or a short function?

Thanks.

ottizy
07-02-2013, 12:18 PM
If I understood this correctly I believe the only thing you'll have to do is to add a null character after your string. Like this:



byte byte1[1000] = "Welcome to TibiaMonster 1.0\0";

Xleniz
07-02-2013, 12:26 PM
Fantastic, works.Thanx.

panqnik
07-02-2013, 02:47 PM
Why are you allocating 1000 bytes for a string which has +/- 30 bytes?
char * message = "Welcome to TibiaMonster 1.0";

Xleniz
07-02-2013, 09:43 PM
Sry, im having virus (reinstalling computer)
-_-

I did 1000 bytes for making lots of zero's for string
the backslash zero didnt work, cipfried still says stuff underneath my string.

XtrmJash
07-02-2013, 09:59 PM
Sry, im having virus (reinstalling computer)
-_-

I did 1000 bytes for making lots of zero's for string
the backslash zero didnt work, cipfried still says stuff underneath my string.

If you are reading it in CheatEngine or a memory viewer it will most likely ignore any null string terminator. Default ASCII BitConverters do not account for them either. For that reason, you should modify your ReadString function to work like this pseudocode:


char[] totalstring
for each char in string
if char != '\0' then
totalstring.append(char)
else
return totalstring
end
end
return totalstring

Of course you'll probably want to use a stringbuilder or something for the totalstring var, or maybe a List<> or some shit, since you can't extend arrays in such a way (at least not in C#, I know it's possible in Python).