Jump to content

Recommended Posts

Hi guys. I have something a bit weird I'm doing. But here's an example of a hex string that I have.

 

142c2332231f00000000000000000000

 

Now, when this is decoded into text, the output is like so:

 

,#2#����������

 

The text that I would like to output is:

 

Trixie

 

To clear things up a bit, the hex string is dumped from a portion of a save file of video game. However, in the video game it renders "14" = T, "2c" = r, "23" = i... and so forth.

 

So I would like to convert my "hex" string into a string that can be read. I know what all the values equal, but using a strreplace doesn't work (I have one "find" array, one "replace" array, and a variable containing the string then I use str_replace($find, $replace, $str);) because you get conflicts. When applying a strreplace to:

 

142c2332231f00000000000000000000

 

The output is:

 

Tri3h3e

 

Does anyone know of any better way I should approach this?

 

Thanks.

 

EDIT:

 

In case anyone wants to look at it, here's what I have so far. I've actually not gathered all the values yet (as you can see; several chunks in the $find array only have "". But I do have enough that I should be able to convert the hex mentioned above)

 

		$find = array(
		"00",
		"",
		"",
		"",
		"",
		"",
		"3a",
		"3b",
		"3c",
		"3d",
		"3e",
		"01", "1b",
		"02", "1c",
		"03", "1d",
		"04", "1e",
		"05", "1f",
		"06", "20",
		"07", "21",
		"08", "22",
		"09", "23",
		"0a", "24",
		"0b", "25",
		"0c", "26",
		"0d", "27",
		"0e", "28",
		"0f", "29",
		"10", "2a",
		"11", "2b",
		"12", "2c",
		"13", "2d",
		"14", "2e",
		"15", "2f",
		"16", "",
		"17", "",
		"18", "32",
		"19", "33",
		"1a", "34",
	);

	$replace = array(
		"",
		"0",
		"1",
		"2",
		"3",
		"4",
		"5",
		"6",
		"7",
		"8",
		"9",
		"A", "a",
		"B", "b",
		"C", "c",
		"D", "d",
		"E", "e",
		"F", "f",
		"G", "g",
		"H", "h",
		"I", "i",
		"J", "j",
		"K", "k",
		"L", "l",
		"M", "m",
		"N", "n",
		"O", "o",
		"P", "p",
		"Q", "q",
		"R", "r",
		"S", "s",
		"T", "t",
		"U", "u",
		"V", "v",
		"W", "w",
		"X", "x",
		"Y", "y",
		"Z", "z",
	);

	$output = str_replace($find, $replace, $str);

Ah, never mind, guys. :) I got it myself.

 

	function get_pattern_name($filename)
{
	$open = fopen($filename, "r");
	$read = fread($open, filesize($filename));
	$str = substr(bin2hex($read), 1068, 32);
	$arr = str_split($str, 2);

	$find = array(
		"00",
		"",
		"",
		"",
		"",
		"",
		"3a",
		"3b",
		"3c",
		"3d",
		"3e",
		"01", "1b",
		"02", "1c",
		"03", "1d",
		"04", "1e",
		"05", "1f",
		"06", "20",
		"07", "21",
		"08", "22",
		"09", "23",
		"0a", "24",
		"0b", "25",
		"0c", "26",
		"0d", "27",
		"0e", "28",
		"0f", "29",
		"10", "2a",
		"11", "2b",
		"12", "2c",
		"13", "2d",
		"14", "2e",
		"15", "2f",
		"16", "",
		"17", "",
		"18", "32",
		"19", "33",
		"1a", "34",
	);

	$replace = array(
		"",
		"0",
		"1",
		"2",
		"3",
		"4",
		"5",
		"6",
		"7",
		"8",
		"9",
		"A", "a",
		"B", "b",
		"C", "c",
		"D", "d",
		"E", "e",
		"F", "f",
		"G", "g",
		"H", "h",
		"I", "i",
		"J", "j",
		"K", "k",
		"L", "l",
		"M", "m",
		"N", "n",
		"O", "o",
		"P", "p",
		"Q", "q",
		"R", "r",
		"S", "s",
		"T", "t",
		"U", "u",
		"V", "v",
		"W", "w",
		"X", "x",
		"Y", "y",
		"Z", "z",
	);

	$output = implode(str_replace($find, $replace, $arr));

	return $output;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.