apk中中读写nvram
时间:10-02
整理:3721RD
点击:
[DESCRIPTION]
apk中读写nvram
[SOLUTION]
nvram中LID对应的结构体如:
typedefstruct
{
intuid;
}NVRAM_AMOI_TEST_STRUCT;
demo code:
//将int型转化成byte数组
private static byte[] getBytes(int data){
byte[] bytes = new byte[4];
bytes[0] = (byte)(data&0xff);
bytes[1] = (byte)((data&0xff00)>>8);
bytes[2] = (byte)((data&0xff0000)>>16);
bytes[3] = (byte)((data&0xff000000)>>24);
return bytes;
}
//将byte数组转换成整型
public static int byte2int(byte[] res) {
int targets = (res[0] & 0xff) | ((res[1] << 8) & 0xff00)| ((res[2] << 24)
>>> 8) | (res[3] << 24);
return targets;
}
//向nvram中写数据
public void writeData() {
IBinderbinder=ServiceManager.getService("NvRAMAgent");
NvRAMAgentagent=NvRAMAgent.Stub.asInterface(binder);
int n = 10;
byte[] buff = new byte[]{0,0,0,0};
byte[] by = getBytes(n);
for(int i=0;i<4;i++
write_buff = by;
try{
intflag=agent.writeFile(file_lid,write_buff);
if(flag>0){
System.out.println("write success");
}else{
System.out.println("write failed");
}
}catch(RemoteExceptione){
e.printStackTrace();
}
}
//从nvram中读取数据
public void readData() {
IBinderbinder=ServiceManager.getService("NvRAMAgent");
NvRAMAgentagent=NvRAMAgent.Stub.asInterface(binder);
byte[] buff = null;
try {
buff = agent.readFile(file_lid);// read buffer fROM nvram
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(i=0;i<buff.length;i++){
System.out.println("i:"+buff);
}
int b = byte2int(temp);
System.out.println("b:"+b);
}
apk中读写nvram
[SOLUTION]
nvram中LID对应的结构体如:
typedefstruct
{
intuid;
}NVRAM_AMOI_TEST_STRUCT;
demo code:
//将int型转化成byte数组
private static byte[] getBytes(int data){
byte[] bytes = new byte[4];
bytes[0] = (byte)(data&0xff);
bytes[1] = (byte)((data&0xff00)>>8);
bytes[2] = (byte)((data&0xff0000)>>16);
bytes[3] = (byte)((data&0xff000000)>>24);
return bytes;
}
//将byte数组转换成整型
public static int byte2int(byte[] res) {
int targets = (res[0] & 0xff) | ((res[1] << 8) & 0xff00)| ((res[2] << 24)
>>> 8) | (res[3] << 24);
return targets;
}
//向nvram中写数据
public void writeData() {
IBinderbinder=ServiceManager.getService("NvRAMAgent");
NvRAMAgentagent=NvRAMAgent.Stub.asInterface(binder);
int n = 10;
byte[] buff = new byte[]{0,0,0,0};
byte[] by = getBytes(n);
for(int i=0;i<4;i++
write_buff = by;
try{
intflag=agent.writeFile(file_lid,write_buff);
if(flag>0){
System.out.println("write success");
}else{
System.out.println("write failed");
}
}catch(RemoteExceptione){
e.printStackTrace();
}
}
//从nvram中读取数据
public void readData() {
IBinderbinder=ServiceManager.getService("NvRAMAgent");
NvRAMAgentagent=NvRAMAgent.Stub.asInterface(binder);
byte[] buff = null;
try {
buff = agent.readFile(file_lid);// read buffer fROM nvram
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(i=0;i<buff.length;i++){
System.out.println("i:"+buff);
}
int b = byte2int(temp);
System.out.println("b:"+b);
}
学习学习