Code:
//IDENTIFIANT CONNEXION MSSQL
$source='(local)\SQLEXPRESS';
$id='sa';
$pass='';
//connexion
$conn = mssql_connect($source,$id,$pass);
//selection database de travail
$dbname = 'Arcadia';
mssql_select_db($dbname);
//fonction reverse hexdatabrut to int
function hex_to_dec($hex1,$hex2,$hex3,$hex4){
$hex11=hexdec(''.$hex1.'');
$hex22=hexdec(''.$hex2.'');
$hex33=hexdec(''.$hex3.'');
$hex44=hexdec(''.$hex4.'');
$dec_number=$hex11+$hex22*256+$hex33*256*256+$hex44*256*256*256;
return $dec_number;
}
//fonction reverse int to hexdatabrut
function dec_to_hexdec($int){
$hex=dechex($int);
$tabl_hex[1]=00;$tabl_hex[2]=00;$tabl_hex[3]=00;$tabl_hex[4]=00;
$longueur=strlen($hex);
if($longueur==8){
$tabl_hex[1]=hexdec(substr($hex,-2,2));
$tabl_hex[2]=hexdec(substr($hex,-4,2));
$tabl_hex[3]=hexdec(substr($hex,-6,2));
$tabl_hex[4]=hexdec(substr($hex,0,2));
}elseif($longueur==7){
$tabl_hex[1]=hexdec(substr($hex,-2,2));
$tabl_hex[2]=hexdec(substr($hex,-4,2));
$tabl_hex[3]=hexdec(substr($hex,-6,2));
$tabl_hex[4]=hexdec('0'.substr($hex,0,1));
}elseif($longueur==6){
$tabl_hex[1]=hexdec(substr($hex,-2,2));
$tabl_hex[2]=hexdec(substr($hex,-4,2));
$tabl_hex[3]=hexdec(substr($hex,0,2));
}elseif($longueur==5){
$tabl_hex[1]=hexdec(substr($hex,-2,2));
$tabl_hex[2]=hexdec(substr($hex,-4,2));
$tabl_hex[3]=hexdec('0'.substr($hex,0,1));
}elseif($longueur==4){
$tabl_hex[1]=hexdec(substr($hex,-2,2));
$tabl_hex[2]=hexdec(substr($hex,0,2));
}elseif($longueur==3){
$tabl_hex[1]=hexdec(substr($hex,-2,2));
$tabl_hex[2]=hexdec('0'.substr($hex,0,1));
}elseif($longueur==2){
$tabl_hex[1]=hexdec(substr($hex,0,2));
}elseif($longueur==1){
$tabl_hex[1]=hexdec('0'.substr($hex,0,1));
}
return $tabl_hex;
/* Old Function
$i=1;
$X=2;
$tabl_hex[1]=000;$tabl_hex[2]=000;$tabl_hex[3]=000;$tabl_hex[4]=000;
while($X > 1){
$Q=variant_int($int/256);
$X=$int-($Q*256);
$int=$Q;
$tabl_hex[$i]=$X;//(decimal to ASCII)dechex($X);
$i++;
}
return $tabl_hex;*/
}
//Utilisation fonction, sortit tableau
//$tabl_hex=dec_to_hexdec(30140650);
//fwrite($monfichier, chr($tabl_hex[1]).chr($tabl_hex[2]).chr($tabl_hex[3]).chr($tabl_hex[4]));
//ouverture/création fichier sortie
$monfichier = fopen("!PWS)3rDAd3O'`dU+O}deN", 'a+');
//placement pointeur à 0
fseek($monfichier, 0);
//ecriture du header sur 128bytes
fwrite($monfichier, chr(0x32).chr(0x30).chr(0x31).chr(0x30).chr(0x30).chr(0x36).chr(0x31).chr(0x35).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x90).chr(0x55).chr(0x01).chr(0x00));
//Query SELECT ligne par ligne dbo.StringResource
$SQL="SELECT name, group_id, code, value FROM dbo.StringResource ORDER BY code";
//execution query dans $cursor
$cursor = mssql_query($SQL,$conn);
//boucle ligne par ligne dans variable $row[0]->$row[3] (4)colonnes
while ($row=mssql_fetch_row($cursor)) {
//recuperation des donnees ligne
$name=$row[0];
$group_id=$row[1];
$code=$row[2];
$value=$row[3];
//recuperation longueur des chaines caractères (longueur name sur 32bit, longueur value sur 32bit;+1 dans la databrut)
if($name!='' AND $name!=' '){
$long_name=strlen($name);
}else{
$long_name=0;
}
if($value!='' AND $value!=' '){
$long_value=strlen($value);
}else{
$long_value=0;
}
//incrementation
$long_name=$long_name+1;
$long_value=$long_value+1;
//ecriture des longueurs string
$tabl_hex=dec_to_hexdec($long_name);
fwrite($monfichier, chr($tabl_hex[1]).chr($tabl_hex[2]).chr($tabl_hex[3]).chr($tabl_hex[4]));
$tabl_hex=dec_to_hexdec($long_value);
fwrite($monfichier, chr($tabl_hex[1]).chr($tabl_hex[2]).chr($tabl_hex[3]).chr($tabl_hex[4]));
//verification si case vide
if($name!='' AND $name!=' '){
//ecriture name
fwrite($monfichier, $name);
}else{
//le neant...
}
//ecriture 0x00 : espace name/value
fwrite($monfichier, chr(0x00));
//verification si case vide
if($value!='' AND $value!=' '){
//ecriture value
fwrite($monfichier, $value);
}else{
//le neant...
}
//ecriture 0x00 : espace value/code
fwrite($monfichier, chr(0x00));
//ecriture code
$tabl_hex=dec_to_hexdec($code);
fwrite($monfichier, chr($tabl_hex[1]).chr($tabl_hex[2]).chr($tabl_hex[3]).chr($tabl_hex[4]));
//ecriture group_id
//verification si -1
if($group_id==-1){
fwrite($monfichier, chr(0xFF).chr(0xFF).chr(0xFF).chr(0xFF));
}else{
$tabl_hex=dec_to_hexdec($group_id);
fwrite($monfichier, chr($tabl_hex[1]).chr($tabl_hex[2]).chr($tabl_hex[3]).chr($tabl_hex[4]));
}
//ecriture 16x32byte
fwrite($monfichier, chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00).chr(0x00));
}
fclose($monfichier);