相同的语法,例如:静态成员无需实例就可以调用这些共同性不写
基础语法
类成员描述符:
public:只要有权访问类,在任意情况下都可以调用
private:只允许自己类调用,在其他类中无法调用到
default:只允许自己家族(即包内成员)调用
protected:允许自己家族(即包内成员)调用,子类也可以访问(继承,不是一个包)
返回值:
void:无返回值
int:返回一个整数
String:返回一个字符串
boolean:返回一个布尔值
变量:
变量类型 变量名 = 变量值
输入与输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Scanner sc = new Scanner(System.in); system.out.println("请输入一个字符串:"); String str = sc.nextLine(); system.out.println("请输入一个整数:"); int num = sc.nextInt(); String message = String.format("输入的字符串是:%s,输入的整数是:%d",str,num); system.out.println(message);
基本数据类型: byte:1个字节 -128——-127 short:2个字节 int:4个字节 long:8个字节
|
1 2 3 4 5 6 7 8
| public class Hello{ public static void main(String [] args){ byte v1 = 32; short v2 = 10000; int v3 = 2222131; long v4 = 554534353424L; } }
|
强制转换
1 2 3 4 5 6 7 8 9
| public class Hello{ public static void main(String [] args){ short v1 = 32; int v2 = (int)v1; System.out.println(v2); } }
|
Java python字节数组转换python
python脚本
1 2 3 4 5 6 7 8 9
| byte_list = [-50, -28, -59, -26, -58, -21]
bs = bytearray() for byte in byte_list: if byte < 0: byte = byte + 256 bs.append(byte) str_data = bs.decode("gbk") print(str_data)
|
基础不记录了
逆向中的问题
接口中常见的方法
找到接口中的方法了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| interface IRequest { public void send(String URL); }
class Context { public IRequest req;
public Context(IRequest req) { this.req = req; }
public void doRequest() { String url = "/click/android2/"; this.req.send(url); } }
public class Hello { public static void main(String[] args) { } }
|
思路1:寻找实现IRequest 接口的类
思路2:谁传入了Req? 找到调用栈。
隐藏的字节
1
| String v4 = new String(new byte[]{-26,-83,-90,-26,-78,-101,-23,-67,-122});
|
隐藏的字符串 要注意
UUID
抖音UUID
1 2 3 4 5 6 7 8
| import java.util.UUID;
public class Hello { public static void main(String[] args) { String uuid = UUID.randomUUID().toString(); System.out.println(uuid); } }
|
随机值
1 2 3 4 5 6 7 8 9 10 11
| import java.math.BigInteger; import java.security.SecureRandom;
public class Hello { public static void main(String[] args) { BigInteger v4 = new BigInteger(80, new SecureRandom()); String res = v4.toString(16); System.out.println(res); } }
|
python中
1 2 3 4 5
| import random
open_uid = ''.join([hex(i)[2:]for i in random.randbytes(10)]) print(open_uid)
|
时间戳
1 2 3 4 5 6
| public class Hello { public static void main(String[] args) { System.out.println(String.valueOf(System.currentTimeMillis()/1000)); System.out.println(String.valueOf(System.currentTimeMillis())); } }
|
十六进制字符串
转换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import java.util.Arrays;
public class Hello { public static void main(String[] args) { String name = "我叫大帅哥"; byte[] nameBytes = name.getBytes(); System.out.println(Arrays.toString(nameBytes)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < nameBytes.length; i++) { int val = nameBytes[i] & 255; if (val < 16) { sb.append(0); } sb.append(Integer.toHexString(val)); } String res = sb.toString(); System.out.println(res); } }
|
base64
1 2 3 4 5 6 7 8 9
| String name = "我是大帅哥"; Base64.Encoder encoder = Base64.getEncoder(); String res = encoder.encodeToString(name.getBytes()); System.out.println(res);
Base64.Decoder decoder = Base64.getDecoder(); byte[] origin = decoder.decode(res); String data = new String(origin); System.out.println(data);
|
md5
1 2 3
| MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] digest = md5.digest(str.getBytes("utf-8")); hexStr = ByteUtils.toHexString(digest);
|
字符串
1 2 3 4 5 6 7 8 9 10 11
| String v5 = new String(new byte[]{-50,-28,-59,-26,-58,-21},"GBK"); System.out.println(v5); StringBuilder sb = new StringBuilder(); sb.append("name"); sb.append("="); sb.append("lzc"); sb.append("&"); sb.append("and"); sb.append("you"); String v6 = new String(sb); System.out.println(v6);
|
数组
数组类型 [] 数组名 = {em1,em2,em3,…,emN};//声明数组的时候初始化,一共N个元素,
例如:
int[] array = {3,5,4,8,12,5};//一共六个元素
数组类型[] 数组名 = new 数组类型[N]//用new关键字声明数组的同时指定数组长度,
例如:
String[] str = new String[6]; 数组长度为6,即数组有六个元素
数组类型[] 数组名 = new 数组类型[] {em1,em2,em3,…,emN};用new关键字声明数组的同时初始化数组,
例如:
int[] array = new int[] {2,4,5,6,8,9};array数组一共五个元素。
数组一旦声明,数组长度就已经确定。每个数组都有一个length属性,不可改变。可以改变数组元素。
AES
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec;
import java.util.Arrays;
public class Hello { public static void main(String[] args) throws Exception { String data = "测试数据"; String key = "fd6b639dbcff0c2a1b03b389ec763c4b"; String iv = "77b07a672d57d64c"; byte [] raw = key.getBytes(); SecretKeySpec skeySpec = new SecretKeySpec(raw,"AES"); IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE,skeySpec,ivSpec); byte [] encrypted = cipher.doFinal(data.getBytes()); System.out.println(Arrays.toString(encrypted)); } }
|