frankienrg Posted April 6, 2010 Share Posted April 6, 2010 Hi everyone! I'm trying to convert this VB.NET function: Dim fs_read As New FileStream(“C:\MCC05.rcs”, FileMode.Open, FileAccess.Read) Dim fs_write As New StreamWriter(File.Create(fs_read.Name.Replace(“.rcs”, “.txt”))) Dim lBytes As Long = fs_read.Length Dim fileData(lBytes) As Byte Dim i As Integer Dim lbytes_27 As Long = lBytes Mod 27 ‘ sono i byte che restano fuori dividendo il file a gruppi di 27 byte Dim chiave As Array chiave = Split(“31;32;33;34;35;36;61;62;63;64;65;66;71;71;77;65;72;74;79;75;61;73;64;66;67;68;6A”, “;”) While Not fs_read.Position = lBytes – lbytes_27 fs_read.Read(fileData, 0, 27) For i = 0 To 26 fs_write.Write(Chr(fileData(i) Xor “&H” & chiave(i))) Next End While i = 0 fs_read.Read(fileData, 0, lbytes_27) For i = 0 To (lbytes_27 – 1) fs_write.Write(Chr(fileData(i) Xor “&H” & chiave(i))) Next fs_read.Close() fs_write.Close() into PHP code. That's what i made: <?php $fs_read = fopen("mcc05.rcs", "r+"); $fs_write = fopen("mcc05.txt", "w+"); $lBytes = $fs_read; $lBytes_28 = $lBytes % 28; $chiave = array('2A', '68', '6C', '34', '35', '6A', '6E', '31', '32', '64', '66', '67', '46', '46', '44', '52', '38', '73', '78', '63', '33', '33', '64', '65', '72', '66', '76', '2A'); while (ftell($fs_read) != ($lBytes – $lBytes_28)) { $fileData = fread($fs_read, 28); for ($i=0; $i<27; $i++ { fwrite($fs_write, (chr($fileData($i) xor “&H” & $chiave($i)))); } } $i = 0 for ($i=0; $i<(lBytes_28 – 1); $i++ { fwrite($fs_write, (chr($fileData($i) xor “&H” & $chiave($i)))); } $fclose($fs_read); $fclose($fs_write); ?> Obviously it doesn't work (give me an error at line 9), but I think it's still a BAD CODE, and even if I fixed the erros, it wouldn't work. I don't understand well VB code, so I think I lost something in the conversion! Will rep+ if some of you could translate the original VB.NET code to PHP, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/ Share on other sites More sharing options...
oni-kun Posted April 6, 2010 Share Posted April 6, 2010 Turn error reporting on via php.ini/httpd.conf or place this at the top of your script: ini_set('display_errors',1); error_reporting(E_ALL); What is the error you are recieving? It would point to if it cannot relocate the pointer or the stream cannot be iterated. Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1037660 Share on other sites More sharing options...
frankienrg Posted April 6, 2010 Author Share Posted April 6, 2010 well, thanks for the fast reply, but what I'm really looking for, is not the fix for my php adaption (because I already know that it wouldn't work). It is really a bad adaption. The purpose of me posting my semi-conversion is to give who wants to help me out, something to start with the conversion of the VB.NET code snippet i posted EDIT: btw, that's the error: [06-Apr-2010 10:35:45] PHP Parse error: syntax error, unexpected T_STRING in /home/horseden/public_html/meeee/mcc.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1037664 Share on other sites More sharing options...
frankienrg Posted April 6, 2010 Author Share Posted April 6, 2010 ok, I think i got most out of it... <?php $fs_read = fopen("mcc05.rcs", "r+"); $fs_write = fopen("mcc05.txt", "w+"); $lBytes = filesize("mcc05.rcs"); $lBytes_28 = $lBytes % 28; $lDiff = ($lBytes)-($lBytes_28); $chiave = array('2A', '68', '6C', '34', '35', '6A', '6E', '31', '32', '64', '66', '67', '46', '46', '44', '52', '38', '73', '78', '63', '33', '33', '64', '65', '72', '66', '76', '2A'); while (ftell($fs_read) != $lDiff) { $fileData = fread($fs_read, 28); for ($i=0; $i<28; $i++) { fwrite($fs_write, (chr($fileData($i) xor “&H” & $chiave($i)))); } } $i = 0; for ($i=0; $i<(lBytes_28–1); $i++) { fwrite($fs_write, (chr($fileData($i) xor “&H” & $chiave($i)))); } $fclose($fs_read); $fclose($fs_write); ?> but i'm getting an error on this: fwrite($fs_write, (chr($fileData($i) xor “&H” & $chiave($i)))); I don't know how to convert this damn string: fs_write.Write(Chr(fileData(i) Xor “&H” & chiave(i))) from VB.NET to PHP. I think it's the only last step I have to do :S Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1038073 Share on other sites More sharing options...
sspoke Posted April 7, 2010 Share Posted April 7, 2010 &HFF = 0xFF same as FF in hexadecimal.. &H is only used in VB6/VB.NET replace &H with 0x but thats a dirty fix.. a cleaner fix would be replacing the array with hexadecimal php representation $chiave = array('2A', '68', '6C', '34', '35', '6A', '6E', '31', '32', '64', '66', '67', '46', '46', '44', '52', '38', '73', '78', '63', '33', '33', '64', '65', '72', '66', '76', '2A'); to $chiave = array('0x2A', '0x68', '0x6C', '0x34', '0x35', '0x6A', '6E', '31', '32', '64', '66', '67', '46', '46', '44', '52', '38', '73', '78', '63', '33', '33', '64', '65', '72', '66', '76', '2A'); etc.. I won't do them all but add 0x in front of each then fix fwrite($fs_write, (chr($fileData($i) xor “&H” & $chiave($i)))); to fwrite($fs_write, (chr($fileData($i) xor $chiave($i)))); $lBytes = $fs_read; is also wrong.. $lBytes is the length of filesize.. meaning you have to use $lBytes = filesize("mcc05.rcs"); Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1038084 Share on other sites More sharing options...
oni-kun Posted April 7, 2010 Share Posted April 7, 2010 fwrite($fs_write, (chr($fileData[$i] XOR .... & $chiave[$i]))); As well fixing the array brackets. Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1038087 Share on other sites More sharing options...
frankienrg Posted April 7, 2010 Author Share Posted April 7, 2010 Fatal error: Call to undefined function X]H() in mcc.php on line 15 last version... <?php $fs_read = fopen("mcc05.rcs", "r+"); $fs_write = fopen("mcc05.txt", "w+"); $lBytes = filesize("mcc05.rcs"); $lBytes_28 = $lBytes % 28; $lDiff = ($lBytes)-($lBytes_28); $chiave = array('2A', '68', '6C', '34', '35', '6A', '6E', '31', '32', '64', '66', '67', '46', '46', '44', '52', '38', '73', '78', '63', '33', '33', '64', '65', '72', '66', '76', '2A'); while (ftell($fs_read) != $lDiff) { $fileData = fread($fs_read, 28); $prefix = "0x"; for ($i=0; $i<28; $i++) { fwrite($fs_write, (chr($fileData($i) xor $prefix.$chiave($i)))); } } for ($i=0; $i<lBytes_28; $i++) { fwrite($fs_write, (chr($fileData($i) xor $prefix.$chiave($i)))); } fclose($fs_read); fclose($fs_write); ?> Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1038095 Share on other sites More sharing options...
sspoke Posted April 7, 2010 Share Posted April 7, 2010 $chiave = array(0x2A, 0x68, 0x6C, 0x34, 0x35, 0x6A, 0x6E, 0x31, 0x32, 0x64, 0x66, 0x67, 0x46, 0x46, 0x44, 0x52, 0x38, 0x73, 0x78, 0x63, 0x33, 0x33, 0x64, 0x65, 0x72, 0x66, 0x76, 0x2A); keep adding 0x in front of each one and removed all single quotes they are causing problems! also replace both fwrites with yes you have to [] in php not (). fwrite($fs_write, (chr($fileData[$i] xor $chiave[$i]))); Problem solved.. you can hit resolved, I've tested it. =] Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1038135 Share on other sites More sharing options...
frankienrg Posted November 15, 2010 Author Share Posted November 15, 2010 Sorry to be reviving this topic, but I actually solved the problem, here's the script: $giornata = $_GET['mcc']; ##AREA CONFIGURABILE## $nome_file = "mcc".$giornata; $input = $nome_file.".rcs"; $output = $nome_file.".txt"; $ultima_riga = 2; // 0=SI 2=NO $chiave = array('72', '2A', '67', '66', '64', '34', '56', '42', '48', '34', '34', '46', '46', '35', '52', '38', '73', '78', '2A', '63', '33', '33', '66', '34', '66', '45', '45', '32'); ##FINE CONFIGURAZIONE## if (file_exists($input)) { $fs_read = fopen($input, "r+"); $fs_write = fopen($output, "w+"); $lBytes = filesize($input); $lBytes_28 = $lBytes % 28; $lDiff = ($lBytes)-($lBytes_28); while (ftell($fs_read) != $lDiff) { $fileData = fread($fs_read, 28); for ($i=0; $i<28; $i++) { $data = hexdec(bin2hex($fileData[$i])); $key = hexdec($chiave[$i]); $result = $data ^ $key; fwrite($fs_write, chr($result)); } } $fileData = fread($fs_read, $lBytes_28); for ($i=0; $i<($lBytes_28-$ultima_riga); $i++) { $data = hexdec(bin2hex($fileData[$i])); $key = hexdec($chiave[$i]); $result = $data ^ $key; fwrite($fs_write, chr($result)); } fclose($fs_read); fclose($fs_write); echo "File: <a href='$output'><b>$output</b></a>"; echo "<br /><b>Stats:</b><br />Lunghezza file: $lBytes<br/>Primo passaggio: $lDiff<br/>Secondo passaggio: $lBytes_28"; } else { echo "File: <a href='$input'><b>$input</b></a> non trovato<br />Istruzioni es.: convertitore.php?mcc=7"; } use it through GETs: decrypter.php?mcc=10 for the file named mcc10.rcs, it will get you a mcc10.txt. Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1134401 Share on other sites More sharing options...
pukos Posted December 21, 2010 Share Posted December 21, 2010 Hi Frankie, I'm using your script (yes, for fantacalcio) but in the output there is a empty row between each players rows. There'a a way to remove it? Tnx Quote Link to comment https://forums.phpfreaks.com/topic/197727-help-with-adapting-vbnet-code-to-php/#findComment-1149858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.