Forum RSS Feed Follow @ Twitter Follow On Facebook

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[-]
Welcome
You have to register before you can post on our site.

Username:


Password:





[-]
Latest Threads
[REQUEST] HP Pavilion G42-272BR Whitelis...
Last Post: eepromm
Yesterday 01:55 AM
» Replies: 0
» Views: 88
[REQUEST] Lenovo G710 BIOS Whitelist Rem...
Last Post: voyageur
11-21-2024 04:33 PM
» Replies: 475
» Views: 167227
[REQUEST] Acer Aspire 5738(G,Z): CPU Upg...
Last Post: DeathBringer
11-21-2024 03:44 PM
» Replies: 49
» Views: 32862
[REQUEST] HP Mini 110-4100 BIOS Unlock
Last Post: DSI INF
11-21-2024 09:24 AM
» Replies: 7
» Views: 242
[REQUEST] Lenovo IdeaPad U310 & U410 (65...
Last Post: Dudu2002
11-21-2024 03:11 AM
» Replies: 1780
» Views: 494460
Lenovo ThinkCentre M715q 2nd Gen & AMD R...
Last Post: Elmurley
11-20-2024 09:37 PM
» Replies: 2
» Views: 1292
[REQUEST] Lenovo Y50-70 (9ECNxxWW) White...
Last Post: SWZSSR
11-20-2024 09:34 PM
» Replies: 1775
» Views: 553759
[REQUEST] Lenovo Thinkpad X240 (GIETxxWW...
Last Post: Dudu2002
11-20-2024 04:58 PM
» Replies: 337
» Views: 143433
Unlock bios insyde
Last Post: Matox3140
11-19-2024 03:40 PM
» Replies: 0
» Views: 209
Whitelist WIFI card removal Lenovo Yoga ...
Last Post: Dudu2002
11-19-2024 12:58 PM
» Replies: 1
» Views: 217
[REQUEST] H310 MSI Gaming Infinite S (MS...
Last Post: awittyusername
11-19-2024 09:21 AM
» Replies: 10
» Views: 132
[REQUEST] Gigabyte GA-B85M-HD3 Rev 2.0 u...
Last Post: Maduli
11-19-2024 02:22 AM
» Replies: 0
» Views: 163
[REQUEST] Lenovo Ideapad 330-15ICH BIOS ...
Last Post: Dudu2002
11-18-2024 01:25 PM
» Replies: 8
» Views: 1905
[REQUEST] Lenovo ThinkPad Edge E330 (H3E...
Last Post: Dudu2002
11-18-2024 01:23 PM
» Replies: 640
» Views: 221097
[Request] Unlocked Bios for Asus TUF FX5...
Last Post: FlT4ever
11-18-2024 01:05 PM
» Replies: 1
» Views: 426
[REQUEST] Lenovo ThinkPad Edge E125(v1.1...
Last Post: kamome74
11-18-2024 10:43 AM
» Replies: 0
» Views: 204
[REQUEST] Xpg 15g 4070 2023ver InsydeH20...
Last Post: MireVelli
11-18-2024 07:26 AM
» Replies: 2
» Views: 203
Please help me recover my bios
Last Post: FuryOP
11-17-2024 12:37 PM
» Replies: 0
» Views: 218
[Request-Camilo] Sony Vaio SA/SB/SC/SD/S...
Last Post: edit
11-17-2024 12:13 PM
» Replies: 107
» Views: 136958
[REQUEST] Lenovo Thinkpad Edge E440 & E5...
Last Post: Dudu2002
11-17-2024 06:50 AM
» Replies: 196
» Views: 92025

Analyze java class System Identifier code of a windows application to Modify uniqueID
#1
Heart 
Hello friends ...
Please some one help me to change unique ID created by below mentioned java class script..
The script create an Unique ID by mixing - OEM name +Bios serial Number + Ethernet MAC Address + Processor Serial Number but I can't find and edit all of these.. 
so, please help me to understand the mechanism of the script..
Code:
WindowsMachineIdentity.java
WindowsMachineIdentity.java

import com.citumpe.ctpTools.jWMI;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Scanner;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WindowsMachineIdentity implements IMachineIdentity {
   private static final Logger LOGGER = LoggerFactory.getLogger(WindowsMachineIdentity.class);
   private static final String BLANK_STRING = "";
   private static final String MACHINE_ID_TYPE_PRIMARY = "primary";
   private static final String MACHINE_ID_TYPE_SECONDARY = "secondary";
   private static final String[] INVALID_OEM_NAMES = new String[]{"Not Available", "NA", "To be filled by", "Provided by"};
   private String machineId;
   private String machineHash;
   private String oemName = "";
   private String primaryMachineHash = "";
   private String secondaryMachineHash = "";
   private String machineIdRegisteredMode = "";

   private static String getMacAddress(byte[] macBytes) {
      StringBuilder strBuilder = new StringBuilder();

      for(int i = 0; i < macBytes.length; ++i) {
         strBuilder.append(String.format("%02X%s", macBytes[i], i < macBytes.length - 1 ? ":" : ""));
      }

      return strBuilder.toString().toUpperCase();
   }

   public final String getUniqueMachineId() throws Exception {
      if (this.machineId != null) {
         LOGGER.debug("getUniqueMachineId method machineId: " + this.machineId);
         return this.machineId;
      } else {
         String oemName = this.getOEMName();
         this.machineId = oemName + this.getUniqueMachineHash();
         if (oemName.equals("")) {
            LOGGER.warn("OEM name is a blank value");
         }

         return this.machineId;
      }
   }

   public final String getPrimaryMachineHash() {
      if (!this.primaryMachineHash.isEmpty()) {
         return this.primaryMachineHash;
      } else {
         String biosSerial = this.getWindowsBiosSerialNo();
         boolean isBIOSDefault = this.isDefaultString(biosSerial);
         if (isBIOSDefault) {
            LOGGER.warn("BIOS serial number is a default value");
         }

         byte[] machineCode = biosSerial.getBytes();
         this.primaryMachineHash = this.hash(machineCode);
         return this.primaryMachineHash;
      }
   }

   public final String getSecondaryMachineHash() throws Exception {
      if (!this.secondaryMachineHash.isEmpty()) {
         return this.secondaryMachineHash;
      } else {
         String macID = this.getWindowsEthernetMacAddress();
         String processorID = this.getProcessorSerialNo();
         String hardDiskSerialNumber = this.getWindowsHardDiskSerialNo();
         String uniqueSysID = macID + hardDiskSerialNumber + processorID;
         if (this.isDefaultString(uniqueSysID)) {
            LOGGER.warn("Secondary combination for machine ID appears to be a default value");
         }

         byte[] machineCode = uniqueSysID.getBytes();
         this.secondaryMachineHash = this.hash(machineCode);
         return this.secondaryMachineHash;
      }
   }

   public String getMachineDetails() {
      String biosSerialNo = this.getWindowsBiosSerialNo();
      String hardDiskSerialNo = this.getWindowsHardDiskSerialNo();
      String processorSerialNo = this.getProcessorSerialNo();

      String macId;
      try {
         macId = this.getWindowsEthernetMacAddress();
      } catch (Exception var6) {
         macId = "";
      }

      this.machineIdRegisteredMode = "primary";
      if (StringUtils.isEmpty(biosSerialNo) || !this.isAlphaNumericOrNumeric(biosSerialNo) || this.isDefaultString(biosSerialNo)) {
         this.machineIdRegisteredMode = "secondary";
      }

      return biosSerialNo + "|" + macId + "|" + hardDiskSerialNo + "|" + processorSerialNo;
   }

   public void diagnoseChangeInMachineIdentity(String registeredMachineDetails) {
      if (registeredMachineDetails != null) {
         String systemMachineDetails = this.getMachineDetails();
         String[] calculatedComponents = systemMachineDetails.split("\\|");
         String[] registeredComponents = registeredMachineDetails.split("\\|");
         if (LOGGER.isDebugEnabled()) {
            for(int i = 0; i < registeredComponents.length; ++i) {
               if (!registeredComponents[i].equals(calculatedComponents[i])) {
                  LOGGER.debug("Component " + (i + 1) + " for calculating machine code doesn't match");
               }
            }
         }

      }
   }

   public String getMachineIdMode() {
      return this.machineIdRegisteredMode;
   }

   public final String getUniqueMachineHash() throws Exception {
      if (this.machineHash != null) {
         LOGGER.debug("getUniqueMachineHash method machineHash:" + this.machineHash);
         return this.machineHash;
      } else {
         String biosSerial = this.getWindowsBiosSerialNo();
         boolean isBIOSDefault = this.isDefaultString(biosSerial);
         if (this.isAlphaNumericOrNumeric(biosSerial) && !isBIOSDefault) {
            this.machineIdRegisteredMode = "primary";
            this.machineHash = this.getPrimaryMachineHash();
            LOGGER.debug("getUniqueMachineId method primary :" + this.machineHash);
         } else {
            if (isBIOSDefault) {
               LOGGER.warn("primary combination is a default value. Attempting new combination for machine ID");
            }

            this.machineIdRegisteredMode = "secondary";
            this.machineHash = this.getSecondaryMachineHash();
            LOGGER.debug("getUniqueMachineId method secondary :" + this.machineHash);
         }

         return this.machineHash;
      }
   }

   private String hash(byte[] bytes) {
      HashGeneratorImpl hashGen = new HashGeneratorImpl();
      byte[] hashSysId = hashGen.generateHash(bytes);
      String hashedSysId = this.byteArrayToHexString(hashSysId);
      return this.convertToUUID(hashedSysId.replace("-", "")).toUpperCase();
   }

   boolean isDefaultString(String uniqueSysID) {
      if (StringUtils.isEmpty(uniqueSysID)) {
         return true;
      } else {
         int length = uniqueSysID.length();
         char[] defaultValueArray = new char[length];
         Arrays.fill(defaultValueArray, '0');
         String defaultValueString = new String(defaultValueArray);
         return defaultValueString.equals(uniqueSysID);
      }
   }

   private String getProcessorSerialNo() {
      String serialnum = "";

      try {
         Process process = Runtime.getRuntime().exec(new String[]{"wmic", "cpu", "get", "processorid"});
         process.getOutputStream().close();
         Scanner sc1 = new Scanner(process.getInputStream());
         String property = sc1.next();
         serialnum = sc1.next();
      } catch (Exception var5) {
         LOGGER.error("Failed to get primary component for machine id");
      }

      return serialnum.trim();
   }

   private String getWindowsHardDiskSerialNo() {
      Process hdd = null;
      StringBuilder output = new StringBuilder("");

      try {
         hdd = Runtime.getRuntime().exec(new String[]{"wmic", "path", "win32_physicalmedia", "get", "serialnumber"});
         BufferedReader input = new BufferedReader(new InputStreamReader(hdd.getInputStream()));

         String line;
         while((line = input.readLine()) != null) {
            if (!line.contains("Microsoft") && !line.equals("")) {
               output.append(line).append("\r\n");
            }
         }
      } catch (Exception var6) {
      }

      if (hdd != null) {
         hdd.destroy();
         hdd = null;
      }

      if (output.toString().contains("SerialNumber")) {
         output = new StringBuilder(output.toString().replaceFirst("SerialNumber", ""));
      }

      return output.toString().trim();
   }

   private String getWindowsBiosSerialNo() {
      String serialNumber = "";

      try {
         Process process = Runtime.getRuntime().exec(new String[]{"wmic", "bios", "get", "serialnumber"});
         process.getOutputStream().close();
         Scanner sc = new Scanner(process.getInputStream());
         String var1 = sc.next();

         try {
            serialNumber = sc.next();
         } catch (Exception var6) {
         }

         if (StringUtils.isEmpty(serialNumber) || !this.isAlphaNumericOrNumeric(serialNumber)) {
            return " ";
         }
      } catch (Exception var7) {
         LOGGER.debug("primary machine code calculation exception" + var7);
      }

      return serialNumber;
   }

   private String getWindowsEthernetMacAddress() throws Exception {
      Enumeration<NetworkInterface> inetAddresses = NetworkInterface.getNetworkInterfaces();
      ArrayList addresses = new ArrayList();

      while(inetAddresses.hasMoreElements()) {
         byte[] macBytes = ((NetworkInterface)inetAddresses.nextElement()).getHardwareAddress();
         if (macBytes != null) {
            addresses.add(getMacAddress(macBytes));
         }
      }

      Collections.sort(addresses);
      if (((String)addresses.get(0)).equals("")) {
         addresses.remove(0);
      }

      return (String)addresses.get(0);
   }

   private String convertToUUID(String convertString) {
      return convertString.substring(0, 8) + "-" + convertString.substring(8, 12) + "-" + convertString.substring(12, 16) + "-" + convertString.substring(16, 20) + "-" + convertString.substring(20, 32);
   }

   private String byteArrayToHexString(byte[] bytes) {
      StringBuilder result = new StringBuilder();
      byte[] var3 = bytes;
      int var4 = bytes.length;

      for(int var5 = 0; var5 < var4; ++var5) {
         byte b = var3[var5];
         result.append(Integer.toString((b & 255) + 256, 16).substring(1));
      }

      return result.toString();
   }

   public String getOEMName() {
      String oem = "";
      if (!this.oemName.equals("")) {
         return this.oemName;
      } else {
         try {
            oem = jWMI.getWMIValue("Select Manufacturer from Win32_BIOS", "Manufacturer");
         } catch (Exception var3) {
            LOGGER.error("Error retrieving OEM name.");
         }

         this.oemName = this.isOEMNameCorrect(oem) ? oem.replace(",", "") : "";
         return this.oemName;
      }
   }

   private boolean isOEMNameCorrect(String oemName) {
      String[] var2 = INVALID_OEM_NAMES;
      int var3 = var2.length;

      for(int var4 = 0; var4 < var3; ++var4) {
         String element = var2[var4];
         if (element.equalsIgnoreCase(oemName) || element.startsWith(oemName) || element.contains(oemName)) {
            return false;
         }
      }

      return true;
   }

   private boolean isAlphaNumericOrNumeric(String num) {
      String pattern = "^[0-9A-Za-z-]*$";
      String numRegex = "(.)*(\\d)(.)*";
      if (num.matches(numRegex) && num.matches(pattern)) {
         return true;
      } else {
         LOGGER.info("isAlphaNumericOrNumeric pattern does not match:");
         return false;
      }
   }
}
  

please feel the desire and kindly help me..
Thanks in advance to all of you who try to solve 
My Email:psassk0236@gmail.com
find
quote


Forum Jump:


Users browsing this thread: 1 Guest(s)