|
-
Aug 19th, 2009, 09:34 PM
#1
Thread Starter
Junior Member
Total PHP Script
So I found this Visual Basic Program source code. I then converted it to PHP as you can see below. Somewhere along the way I messed up. If you find out where I messed up (I think it may be multiple places) I'll pay you $5. PM! me the new source do NOT post it here.
PHP Code
Code:
<?
function Mid($str,$start,$length)
{
$array = explode('',$str);
$number = $start;
while($length > $number)
{
$return .= $array[$number];
$number++;
}
return $return;
}
function Asc($str)
{
ord($str);
}
function Left($str, $length)
{
return substr($str, 0, $length);
}
function Right($str, $length)
{
$array = explode('',$str);
while($length > -1)
{
$return .= $array[$length];
$length = $length - 1;
}
}
function CLng($str)
{
$array = explode('.',$str);
return $array[0];
}
function Len($str)
{
strlen($str);
}
function Decompress($DecompData)
{
if (Len($DecompData) > 4)
{
$ControlCount = Asc(Left($DecompData, 1)) *16777216 + Asc(Mid($DecompData, 2, 1)) *65536 + Asc(Mid($DecompData, 3, 1)) *256 + Asc(Mid($DecompData, 4, 1));
$DataCount = Asc(Mid($DecompData, 5, 1)) *16777216 + Asc(Mid($DecompData, 6, 1)) *65536 + Asc(Mid($DecompData, 7, 1)) *256 + Asc(Mid($DecompData, 8, 1)) + 9;
$Decompress = Mid($DecompData, $DataCount, 4);
$DataCount = $DataCount + 4;
$ControlBitPos = 0;
$ControlPos = 9;
}
else
{
}
$DataPost = 1;
while($DataPos < $ControlCount)
{
if(pow(2, $ControlBitPos) == (ord(substr($DecompData, $ControlPos, 1))) && pow(2, $ControlBitPos))
{
$DecompStart = Len($Decompress) - (CLng(Asc(Mid($DecompData, $DataCount, 1))) *256 + CLng(Asc(Mid($DecompData, $DataCount + 1, 1)))) + 1;
$DecompLen = Asc(Mid($DecompData, $DataCount + 2, 1));
$Decompress = $Decompress & Mid($Decompress, $DecompStart, $DecompLen);
$DataCount = $DataCount + 3;
}
else
{
$Decompress = $Decompress . Mid($DecompData, $DataCount, 1);
$DataCount++;
}
$ControlBitPos++;
if($ControlBitPos = 8)
{
$ControlBitPos = 0;
$ControlPos++;
}
else
{
$Decompress = $DecompData;
}
$DataPos++;
}
}
$FileName = 'test.bin';
$FName = $FileName;
$string56 = array_merge(range('0', '9') , range('a' , 'z'));
$string56 = array_merge($string56 , range('A' , 'Z'));
$zero = '0';
while($zero < 6) { $full .= $string56[rand('0' , count($string56))]; $zero++; }
$data = file_get_contents($FileName);
$return = Decompress($FileName);
$file = fopen($full . '.jpg','w');
fwrite($file,$return);
fclose($file);
echo $return . '<br /><br />';
echo $full . '.jpg';
?>
Visual Basic Code
Code:
Public Function sDecompress(sDecompData As String) As String
Dim lControlCount As Long
Dim lControlPos As Long
Dim bControlBitPos As Byte
Dim lDataCount As Long
Dim lDataPos As Long
Dim lDecompStart As Long
Dim lDecompLen As Long
If Len(sDecompData) > 4 Then
lControlCount = Asc(Left(sDecompData, 1)) * &H1000000 + Asc(Mid(sDecompData, 2, 1)) * &H10000 + Asc(Mid(sDecompData, 3, 1)) * &H100 + Asc(Mid(sDecompData, 4, 1))
lDataCount = Asc(Mid(sDecompData, 5, 1)) * &H1000000 + Asc(Mid(sDecompData, 6, 1)) * &H10000 + Asc(Mid(sDecompData, 7, 1)) * &H100 + Asc(Mid(sDecompData, 8, 1)) + 9
sDecompress = Mid(sDecompData, lDataCount, 4)
lDataCount = lDataCount + 4
bControlBitPos = 0
lControlPos = 9
For lDataPos = 1 To lControlCount
If 2 ^ bControlBitPos = (Asc(Mid(sDecompData, lControlPos, 1)) And 2 ^ bControlBitPos) Then
lDecompStart = Len(sDecompress) - (CLng(Asc(Mid(sDecompData, lDataCount, 1))) * &H100 + CLng(Asc(Mid(sDecompData, lDataCount + 1, 1)))) + 1
lDecompLen = Asc(Mid(sDecompData, lDataCount + 2, 1))
sDecompress = sDecompress & Mid(sDecompress, lDecompStart, lDecompLen)
lDataCount = lDataCount + 3
Else
sDecompress = sDecompress & Mid(sDecompData, lDataCount, 1)
lDataCount = lDataCount + 1
End If
bControlBitPos = bControlBitPos + 1
If bControlBitPos = 8 Then
bControlBitPos = 0
lControlPos = lControlPos + 1
End If
Next
Else
sDecompress = sDecompData
End If
End Function
'Put a two command buttons (Command1 and
' Command2) on to a form and paste the fol
' lowing on to it as well:
Option Explicit
Private Const sFileName = "c:\compressthis.exe" ' the file To be compressed
Private Sub Command1_Click() 'Compress the file
Dim sReturn As String
Dim sFileData As String
Open sFileName For Binary As #1
sFileData = Input(LOF(1), #1)
Close #1
sReturn = sCompress(sFileData)
Debug.Print Len(sReturn), Len(sFileData)
Open Left(sFileName, Len(sFileName) - 3) & "wnc" For Output As #1
Print #1, sReturn;
Close #1
End Sub
Private Sub Command2_Click() 'Decompress the file
Dim sReturn As String
Dim sFileData As String
Open Left(sFileName, Len(sFileName) - 4) & ".wnc" For Binary As #1
sFileData = Input(LOF(1), #1)
sReturn = sDecompress(sFileData)
Close #1
Debug.Print Len(sReturn), Len(sFileData)
Open Left(sFileName, Len(sFileName) - 4) & "2" & Right(sFileName, 4) For Output As #1
Print #1, sReturn;
Close #1
End Sub
Last edited by pudge1; Aug 19th, 2009 at 09:38 PM.
-
Aug 20th, 2009, 02:44 AM
#2
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 20th, 2009, 03:32 AM
#3
Re: Total PHP Script
I suggest you start by learning PHP. Go to www.php.net. Look specifically at functions such as ord(), substr() and data type casting.
In addition, please to not post the same question multiple times.
-
Aug 20th, 2009, 07:47 AM
#4
Re: Total PHP Script
Moved to Project Requests
-
Aug 20th, 2009, 09:03 AM
#5
Thread Starter
Junior Member
Re: Total PHP Script
 Originally Posted by visualAd
I suggest you start by learning PHP. Go to www.php.net. Look specifically at functions such as ord(), substr() and data type casting.
In addition, please to not post the same question multiple times.
I know PHP just fine. That is how I converted that whole entire VB script to PHP. However I made an error somewhere so that the script runs through but doesn't do what it was supposed to.
It is a LZSS Decompresser. So if someone could find where I made an error that would be great. (Not like a syntax error).
-
Aug 20th, 2009, 10:20 AM
#6
Re: Total PHP Script
 Originally Posted by pudge1
I know PHP just fine. That is how I converted that whole entire VB script to PHP. However I made an error somewhere so that the script runs through but doesn't do what it was supposed to.
It is a LZSS Decompresser. So if someone could find where I made an error that would be great. (Not like a syntax error).
What error messages do you receive? What is the expected output? It is very difficult to debug code if you have not explained how it works and reinvented the wheel by recreating functions that already exist in PHP.
If you can supply me with a quick explanation of what the code is doing (in the form of comments; linked to a specification if possible) and a sample input and the expected output, I will be happy to assist.
It seems apparent to me that if you have consulted the PHP manual you would have known of the existence of the string manipulation functions and how to express a hexadecimal R-Value in the code.
-
Aug 20th, 2009, 11:06 AM
#7
Thread Starter
Junior Member
Re: Total PHP Script
There are no erorrs the code just isn't working right. I already know one of the problems is that you can't explode('',$array).
-
Aug 20th, 2009, 01:10 PM
#8
Re: Total PHP Script
If you cannot provide me with an input file then I cannot test the code, therefore I cannot help you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|