PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/oiclient/lib/common/BCDClass.php

http://openirudi.googlecode.com/
PHP | 222 lines | 157 code | 61 blank | 4 comment | 26 complexity | ada68619e315a30cb21f65bc7f709198 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. class BCDClass {
  3. private $BCD=null;
  4. private $BCDPartition=null;
  5. private $registry;
  6. function __construct() {
  7. if($this->initialice() ){
  8. $this->readHive();
  9. }
  10. }
  11. function initialice(){
  12. $hw=systemOppClass::getComputer();
  13. $osList=$hw->listDisks->partitionsOS();
  14. $BCDPartitionName=array_search('windows7system', $osList);
  15. if($BCDPartitionName===false){
  16. exceptionHandlerClass::saveMessage( "We not found windows system partition" );
  17. return false;
  18. }
  19. $BootPartitionName=array_search('windows7boot', $osList);
  20. if($BootPartitionName===false){
  21. exceptionHandlerClass::saveMessage( "We not found windows boot partition" );
  22. return;
  23. }
  24. $BCDDisk=$hw->listDisks->diskOfpartition($BCDPartitionName);
  25. $this->BCDPartition=$hw->listDisks->disks[$BCDDisk]->partitions[$BCDPartitionName];
  26. $BootDisk=$hw->listDisks->diskOfpartition($BootPartitionName);
  27. $this->BootPartition=$hw->listDisks->disks[$BootDisk]->partitions[$BootPartitionName];
  28. return true;
  29. }
  30. function readHive(){
  31. if (!$mountPoint = $this->BCDPartition->fileSystem->isMounted()) {
  32. $mountedAlready = false;
  33. $mountPoint = $this->BCDPartition->fileSystem->mount();
  34. } else {
  35. $mountedAlready = true;
  36. }
  37. $BCDFile=manageFilesClass::caseInsensibleFileName($mountPoint.'/Boot/BCD');
  38. if(!empty($mountPoint) && $BCDFile != false ) {
  39. $this->registry=new windowsRegistryClass($BCDFile);
  40. $this->BCD=$this->registry->getObjectsArray();
  41. if(count($this->BCD)<=1 ){
  42. exceptionHandlerClass::saveError("Error reading BCD registry");
  43. return false;
  44. }
  45. }
  46. if(!$mountedAlready) {
  47. $this->BCDPartition->fileSystem->umount();
  48. }
  49. }
  50. function getBCDArray( $object ){
  51. $guids=array();
  52. $g=array();
  53. foreach ($this->BCD as $key => $value ) {
  54. if(strpos( $key, $object )){
  55. $key=str_replace('\\\\', '', trim($key));
  56. $k='[\''.str_replace('\\','\'][\'',$key).'\']';
  57. eval( "\$guids$k=\$value;");
  58. }
  59. }
  60. return $guids;
  61. }
  62. function getGuidType($type=''){
  63. $guids=array();
  64. if(isset($this->BCD['objects'])){
  65. foreach (array_keys($this->BCD['objects']) as $key ) {
  66. if(empty($type) || $type==$this->BCD['objects'][$key]['description']['type']){
  67. $guids[$key]=$this->BCD['objects'][$key]['description']['type'];
  68. }
  69. }
  70. }
  71. return $guids;
  72. }
  73. function getDeviceGuidList(){
  74. }
  75. function changeDiskSignature($obj, $type, $newSignature,$partitionStart){
  76. if (!$mountPoint = $this->BCDPartition->fileSystem->isMounted()) {
  77. $mountedAlready = false;
  78. $mountPoint = $this->BCDPartition->fileSystem->mount();
  79. } else {
  80. $mountedAlready = true;
  81. }
  82. $BCDFile=manageFilesClass::caseInsensibleFileName($mountPoint.'/Boot/BCD');
  83. if(!empty($mountPoint) && $BCDFile != false ) {
  84. $key='Objects\\'.$obj.'\Elements\\'.$type;
  85. if(isset ($this->BCD['objects'][$obj]['elements'][$type]['element'])){
  86. $newVal=explode(',',str_replace('hex:','',$this->BCD['objects'][$obj]['elements'][$type]['element']));
  87. switch ( count($newVal) ){
  88. case 88:
  89. //$partitionOffset='35';
  90. $partitionOffset='37';
  91. $signatureOffset='59';
  92. break;
  93. case 254:
  94. case 200:
  95. $partitionOffset='87';
  96. $signatureOffset='111';
  97. break;
  98. default :
  99. exceptionHandlerClass::saveMessage( "WRONG VALUE obj:: $obj k2: <pre> ".print_r($newVal,1). "</pre>");
  100. return;
  101. }
  102. $keyElement=$this->registry->getRealKey( 'Objects\\'.$obj.'\Elements\\'.$type );
  103. $newSignature=str_pad($newSignature,8,'0',STR_PAD_LEFT);
  104. $partitionStart=str_pad($partitionStart,12,'0',STR_PAD_LEFT);
  105. $newSignature1=str_split($newSignature,2);
  106. for ($i=0;$i<count($newSignature1);$i++){
  107. $newVal[$signatureOffset]=$newSignature1[$i];
  108. $signatureOffset--;
  109. }
  110. $partitionStart1=str_split($partitionStart,2);
  111. for ($i=0;$i<count($partitionStart1);$i++){
  112. $newVal[$partitionOffset]=$partitionStart1[$i];
  113. $partitionOffset--;
  114. }
  115. $this->registry->modifyHexKey( $keyElement,'B','Element',implode(',',$newVal));
  116. }
  117. }
  118. if(!$mountedAlready) {
  119. $this->BCDPartition->fileSystem->umount();
  120. }
  121. }
  122. function makeBootable(){
  123. $hw=systemOppClass::getComputer();
  124. if(is_null( $this->BCDPartition) || is_null($this->BootPartition)){
  125. exceptionHandlerClass::saveMessage( "We not found windows system or Boot partition" );
  126. return;
  127. }
  128. $w7sDiskSignature=$hw->listDisks->disks[$this->BCDPartition->disk]->diskSignature;
  129. $w7sStart=unitsClass::diskSector2SizeHex($this->BCDPartition->startSector);
  130. $w7bDiskSignature=$hw->listDisks->disks[$this->BootPartition->disk]->diskSignature;
  131. $w7bStart= unitsClass::diskSector2SizeHex($this->BootPartition->startSector);
  132. //aladtu: 11000001 signatura partizio hasera
  133. $t10100002=$this->getGuidType('dword:10100002');
  134. $t10200005=$this->getGuidType('dword:10200005');
  135. foreach(array_keys($t10100002) as $obj ){
  136. $this->changeDiskSignature($obj, '11000001',$w7sDiskSignature, $w7sStart);
  137. }
  138. foreach(array_keys($t10200005) as $obj ){
  139. $this->changeDiskSignature($obj, '11000001',$w7sDiskSignature, $w7sStart);
  140. }
  141. //aladatu: 11000001 21000001 signatura partizio hasera kontuz luzera ezberdina
  142. $t10200003=$this->getGuidType('dword:10200003');
  143. $t10200004=$this->getGuidType('dword:10200004');
  144. foreach(array_keys($t10200003) as $obj ){
  145. $this->changeDiskSignature($obj, '11000001',$w7bDiskSignature, $w7bStart);
  146. $this->changeDiskSignature($obj, '21000001',$w7bDiskSignature, $w7bStart);
  147. }
  148. foreach(array_keys($t10200004) as $obj ){
  149. $this->changeDiskSignature($obj, '11000001',$w7bDiskSignature, $w7bStart);
  150. $this->changeDiskSignature($obj, '21000001',$w7bDiskSignature, $w7bStart);
  151. }
  152. //aldatu:31000003 signatura partizio hasera
  153. $t30000000=$this->getGuidType('dword:30000000');
  154. foreach(array_keys($t30000000) as $obj ){
  155. $this->changeDiskSignature($obj, '11000001',$w7bDiskSignature, $w7bStart);
  156. }
  157. }
  158. function changePartitionSectors(){
  159. }
  160. }
  161. ?>