分析.pin文件时,用到的几个自定义函数

/**
* 将byte数组转换成16进制字符串
* @param m
* @return
*/
public static String bytetohexString(byte [] m)
{
String hex = "";
String ret = "";
for (int i = 0; i < m.length; i++) {
hex = Integer.toHexString(m[i] & 0xFF);
if (hex.length() == 1) { 
hex = '0' + hex; 
}
ret += hex;
}

return ret; 
}
/**
* 数据中地址顺序高地位颠倒,正确顺序地址的16进制字符串
* @param m
* @return
*/
public static String righorderhexString(byte [] m)
{
String hex = "";
String ret = "";
m = rightorder(m);
for (int i = 0; i < m.length; i++) {
hex = Integer.toHexString(m[i] & 0xFF);
if (hex.length() == 1) { 
hex = '0' + hex; 
}
ret += hex ;
}

return ret; 
}
/**
* 将地址转换成10进制,方便地址跳转
* @param m
* @return
*/
public static int bytearraytoint(byte[] m )
{
String a = righorderhexString(m);
int b = 0;
int temp;
for (int i = 0; i < a.length(); i++) {
b += Integer.parseInt(a.substring(i, i+1), 16) * adecimal(a.length()-1-i,16); 
}
return b;
}
public static int wipeblank(String str )
{
String temp = "";
byte [] s = {00};
String string = "";
try {
string = new String(s,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
int b = 0;
for (int i = 0; i < str.length(); i++) {
if(!str.substring(i, i+1) .equals(string)){
temp += str.substring(i, i+1);
}
}
for (int j = 0; j < temp.length(); j++) {
b += Integer.parseInt(temp.substring(j, j+1), 16) * adecimal(temp.length()-1-j,10);
}

return b;
}
/**
* 幂次数
* @param data
* @param scale
* @return
*/
public static int adecimal(int data , int scale)
{
int a = 1;
for (int j = 1; j <= data; j++) {
a *= scale; 
}
return a;
}
/**
* 地址颠倒顺序
* @param addr
* @return
*/
public static byte [] rightorder(byte [] addr)
{
byte [] temp = new byte[addr.length];
for (int i = 0; i < addr.length; i++) {
temp[temp.length-1-i] = addr[i];
}
return temp;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值