mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-05 16:24:30 +02:00
implement LongItem block
This commit is contained in:
parent
2eb4e7f96d
commit
2b6da361dc
@ -158,4 +158,29 @@ public abstract class BlockItem extends Block {
|
||||
int value = (bytes[byteOffset] & mask) | add;
|
||||
bytes[byteOffset] = (byte) value;
|
||||
}
|
||||
protected static long getLong(byte[] bytes, int offset){
|
||||
if((offset + 8)>bytes.length){
|
||||
return 0;
|
||||
}
|
||||
long result = 0;
|
||||
int index = offset + 7;
|
||||
while (index>=offset){
|
||||
result = result << 8;
|
||||
result |= (bytes[index] & 0xff);
|
||||
index --;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
protected static void putLong(byte[] bytes, int offset, long value){
|
||||
if((offset + 8) > bytes.length){
|
||||
return;
|
||||
}
|
||||
int index = offset;
|
||||
offset = index + 8;
|
||||
while (index<offset){
|
||||
bytes[index] = (byte) (value & 0xff);
|
||||
value = value >>> 8;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ package com.reandroid.arsc.item;
|
||||
public int get(){
|
||||
return mCache;
|
||||
}
|
||||
public long unsignedLong(){
|
||||
return get() & 0x00000000ffffffffL;
|
||||
}
|
||||
public String toHex(){
|
||||
return String.format("0x%08x", get());
|
||||
}
|
||||
|
45
src/main/java/com/reandroid/arsc/item/LongItem.java
Normal file
45
src/main/java/com/reandroid/arsc/item/LongItem.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2022 github.com/REAndroid
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.reandroid.arsc.item;
|
||||
|
||||
public class LongItem extends BlockItem{
|
||||
private long mCache;
|
||||
public LongItem() {
|
||||
super(8);
|
||||
}
|
||||
public void set(long value){
|
||||
if(value == mCache){
|
||||
return;
|
||||
}
|
||||
mCache = value;
|
||||
putLong(getBytesInternal(), 0, value);
|
||||
}
|
||||
public long get(){
|
||||
return mCache;
|
||||
}
|
||||
public String toHex(){
|
||||
return String.format("0x%016x", get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBytesChanged() {
|
||||
mCache = getLong(getBytesInternal(), 0);
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return String.valueOf(get());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user