Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Commit 2f3c6de

Browse files
authored
Merge pull request #31 from Qup42/master
Added Javadocs for Utils Class
2 parents 55ffeba + 031547e commit 2f3c6de

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

src/main/java/me/checkium/vhackapi/Utils.java

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@
1515

1616
public class Utils {
1717
public static String url;
18-
public static String md5s;
18+
public static final String md5s = "MD5";
1919
public static String secret;
2020
static final boolean assertionstatus;
2121
private static final byte[] byt;
2222

2323
static {
2424
assertionstatus = !Utils.class.desiredAssertionStatus();
2525
url = "https://api.vhack.cc/v/1/";
26-
md5s = "MD5";
26+
//md5s = "MD5";
2727
secret = "aeffI";
2828
byt = new byte[]{(byte) 65, (byte) 66, (byte) 67, (byte) 68, (byte) 69, (byte) 70, (byte) 71, (byte) 72, (byte) 73, (byte) 74, (byte) 75, (byte) 76, (byte) 77, (byte) 78, (byte) 79, (byte) 80, (byte) 81, (byte) 82, (byte) 83, (byte) 84, (byte) 85, (byte) 86, (byte) 87, (byte) 88, (byte) 89, (byte) 90, (byte) 97, (byte) 98, (byte) 99, (byte) 100, (byte) 101, (byte) 102, (byte) 103, (byte) 104, (byte) 105, (byte) 106, (byte) 107, (byte) 108, (byte) 109, (byte) 110, (byte) 111, (byte) 112, (byte) 113, (byte) 114, (byte) 115, (byte) 116, (byte) 117, (byte) 118, (byte) 119, (byte) 120, (byte) 121, (byte) 122, (byte) 48, (byte) 49, (byte) 50, (byte) 51, (byte) 52, (byte) 53, (byte) 54, (byte) 55, (byte) 56, (byte) 57, (byte) 45, (byte) 95};
2929
}
30-
30+
31+
/**
32+
* Reads all data from a buffered reader and returns it as a String.
33+
* @param rd The buffered Reader which holds the data.
34+
* @return The String representation of data the buffered reader contains.
35+
* @throws IOException
36+
*/
3137
public static String readJson(Reader rd) throws IOException {
3238
StringBuilder sb = new StringBuilder();
3339
int cp;
@@ -37,6 +43,21 @@ public static String readJson(Reader rd) throws IOException {
3743
return sb.toString();
3844
}
3945

46+
/**
47+
* Makes a request to the api and returns the result as a JSONObject Object.
48+
* Makes a requests to the vHack Api, with the params format, data data and to the file php and returns the result, which is json, as a JSONObject Object.<br>
49+
* Errors are thrown if user/password is wrong and (possibly) if the api url changed.<br>
50+
* It is similar to {@link Utils#StringRequest(String, String, String)} but differs from it in that does processing with the obtained data.<br>
51+
* it returns the result as json Object and performs checks for any (known) errors.
52+
* @param format Lists the params that will be passed to the api endpoint. The names are separated with "::::".<br>
53+
* Every request, except the very first one, should include "user::::pass::::uhash".<br>
54+
* Example: "user::::pass::::uhash::::global" (taken from Console.getIP)
55+
* @param data The data for the params that you passed in. They are also separated by "::::". You can just concatanate the parts of this.<br>
56+
* Example: "vHackAPI::::123456::::aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp::::1"
57+
* @param php This is the api endpoint that the request will be sent to. In the case of the vHackAPI it are php documents.<br>
58+
* Example "vh_network.php"
59+
* @return The resulte Json as a JSONObject. Errors are thrown if user/password is wrong and (possibly) if the api url changed. null is returned if there are other errors.
60+
*/
4061
public static JSONObject JSONRequest(String format, String data, String php){
4162
JSONObject json = null;
4263
String jsonText = StringRequest(format, data, php);
@@ -54,8 +75,21 @@ else if (jsonText.length() == 1) {
5475
json = new JSONObject(jsonText);
5576
return json;
5677
}
57-
78+
5879
//it'll just do the request without any checks
80+
/**
81+
* Makes a request to the api and returns the result as a String.
82+
* Makes a requests to the vHack Api, with the params format, data data and to the file php and returns the result, which is json, as a String Object.<br>
83+
* It is similar to {@link Utils#JSONRequest(String, String, String)} but differs from it in the form that it returns and String and doesn't perform checks.
84+
* @param format Lists the params that will be passed to the api endpoint. The names are separated with "::::".<br>
85+
* Every request, except the very first one, should include "user::::pass::::uhash".<br>
86+
* Example: "user::::pass::::uhash::::global" (taken from Console.getIP)
87+
* @param data The data for the params that you passed in. They are also separated by "::::". You can just concatanate the parts of this.<br>
88+
* Example: "vHackAPI::::123456::::aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp::::1"
89+
* @param php This is the api endpoint that the request will be sent to. In the case of the vHackAPI it are php documents.<br>
90+
* Example "vh_network.php"
91+
* @return The resulte Json as a String.
92+
*/
5993
public static String StringRequest(String format, String data, String php)
6094
{
6195
System.setProperty("http.agent", "Chrome");
@@ -108,7 +142,7 @@ private static byte[] m9179a(byte[] arrby, int n2, int n3, byte[] arrby2, int n4
108142
return arrby2;
109143
}
110144

111-
public static String generateUser(byte[] bArr, int i, int i2, byte[] bArr2, boolean z) {
145+
private static String generateUser(byte[] bArr, int i, int i2, byte[] bArr2, boolean z) {
112146
byte[] a = assertion(bArr, i, i2, bArr2, Integer.MAX_VALUE);
113147
int length = a.length;
114148
while (!z && length > 0 && a[length - 1] == 61) {
@@ -117,7 +151,13 @@ public static String generateUser(byte[] bArr, int i, int i2, byte[] bArr2, bool
117151
return new String(a, 0, length);
118152
}
119153

120-
public static final String hashString(String str) {
154+
/**
155+
* Hashes the given String with {@value md5s}.
156+
* The hashing alorithm is determined by {@link Utils#md5s}
157+
* @param str The string that should be hashed with {@value md5s}.
158+
* @return The parameter str hashed using {@value md5s}.
159+
*/
160+
private static final String hashString(String str) {
121161
try {
122162
MessageDigest instance = MessageDigest.getInstance(md5s);
123163
instance.update(str.getBytes());
@@ -137,7 +177,7 @@ public static final String hashString(String str) {
137177
}
138178
}
139179

140-
public static byte[] assertion(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
180+
private static byte[] assertion(byte[] bArr, int i, int i2, byte[] bArr2, int i3) {
141181
int i4 = ((i2 + 2) / 3) * 4;
142182
byte[] bArr3 = new byte[(i4 + (i4 / i3))];
143183
int i5 = i2 - 2;
@@ -174,10 +214,23 @@ public static byte[] assertion(byte[] bArr, int i, int i2, byte[] bArr2, int i3)
174214
throw new AssertionError();
175215
}
176216

177-
178-
public static String generateURL(String str, String str2, String str3) {
179-
String[] split = str.split("::::");
180-
String[] split2 = str2.split("::::");
217+
/**
218+
* Generates a url to where a request has to be made.
219+
* Generates the complete url a request has to be done to, to achieve a certain action (E.g. upgrade a Botnet Computer).<br>
220+
* Needed for this are the username, the password, the uHash and any additional parameters. The time is also neede but you dont need to supply it because the programm get the time by it itself.<br>
221+
* It is used by {@link Utils#JSONRequest(String, String, String)} and {@link Utils#StringRequest(String, String, String)}.
222+
* @param format Lists the params that will be passed to the api endpoint. The names are separated with "::::".<br>
223+
* Every request, except the very first one, should include "user::::pass::::uhash".<br>
224+
* Example: "user::::pass::::uhash::::global" (taken from Console.getIP)
225+
* @param data The data for the params that you passed in. They are also separated by "::::". You can just concatanate the parts of this.<br>
226+
* Example: "vHackAPI::::123456::::aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnoooopppp::::1"
227+
* @param php This is the api endpoint that the request will be sent to. In the case of the vHackAPI it are php documents.<br>
228+
* Example "vh_network.php"
229+
* @return The url Url a request has to be directed to.
230+
*/
231+
public static String generateURL(String format, String data, String php) {
232+
String[] split = format.split("::::");
233+
String[] split2 = data.split("::::");
181234
long currentTimeMillis = System.currentTimeMillis() / 1000;
182235
JSONObject jSONObject = new JSONObject();
183236
for (int i = 0; i < split.length; i++) {
@@ -205,7 +258,7 @@ public static String generateURL(String str, String str2, String str3) {
205258
String str9 = generateUser(bytes3, 0, bytes3.length, byt, false);
206259
String str7 = generateUser(bytes4, 0, bytes4.length, byt, false);
207260
String str8 = hashString(hashString(a3 + hashString(hashString(str9) + str7)));
208-
return url + str3 + "?user=" + a + "&pass=" + str8;
261+
return url + php + "?user=" + a + "&pass=" + str8;
209262
}
210263

211264
}

0 commit comments

Comments
 (0)