From 2b6da361dc15700fabc5d503d1ed8b594f593e00 Mon Sep 17 00:00:00 2001 From: REAndroid Date: Wed, 5 Apr 2023 12:32:12 -0400 Subject: [PATCH] implement LongItem block --- .../com/reandroid/arsc/item/BlockItem.java | 25 +++++++++++ .../com/reandroid/arsc/item/IntegerItem.java | 3 ++ .../com/reandroid/arsc/item/LongItem.java | 45 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/com/reandroid/arsc/item/LongItem.java diff --git a/src/main/java/com/reandroid/arsc/item/BlockItem.java b/src/main/java/com/reandroid/arsc/item/BlockItem.java index daec8d1..c34c07c 100755 --- a/src/main/java/com/reandroid/arsc/item/BlockItem.java +++ b/src/main/java/com/reandroid/arsc/item/BlockItem.java @@ -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>> 8; + index++; + } + } } diff --git a/src/main/java/com/reandroid/arsc/item/IntegerItem.java b/src/main/java/com/reandroid/arsc/item/IntegerItem.java index e812172..ac99ced 100755 --- a/src/main/java/com/reandroid/arsc/item/IntegerItem.java +++ b/src/main/java/com/reandroid/arsc/item/IntegerItem.java @@ -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()); } diff --git a/src/main/java/com/reandroid/arsc/item/LongItem.java b/src/main/java/com/reandroid/arsc/item/LongItem.java new file mode 100644 index 0000000..7f0b234 --- /dev/null +++ b/src/main/java/com/reandroid/arsc/item/LongItem.java @@ -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()); + } +}