Skip to content

Commit

Permalink
new unknown resource id encoding #18
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Jul 19, 2023
1 parent ea3d99a commit 03ad33b
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 91 deletions.
90 changes: 0 additions & 90 deletions src/main/java/com/reandroid/apk/xmlencoder/XMLEncodeSource.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.coder;

import com.reandroid.arsc.value.ValueType;
import com.reandroid.utils.HexUtil;

public class CoderUnknownAttributeId extends Coder{
@Override
public EncodeResult encode(String text) {
if(text == null || text.length() != LENGTH || !text.startsWith(PREFIX)){
return null;
}
Integer value = parseHex(text.substring(1));
if(value != null){
return new EncodeResult(getValueType(), value);
}
return null;
}
@Override
public String decode(int data) {
return HexUtil.toHex8(PREFIX, data);
}
@Override
public ValueType getValueType() {
return ValueType.ATTRIBUTE;
}
@Override
boolean canStartWith(char first) {
return first == PREFIX_CHAR;
}

public static final CoderUnknownAttributeId INS = new CoderUnknownAttributeId();

private static final char PREFIX_CHAR = '?';
private static final String PREFIX = "?0x";
private static final int LENGTH = 3 + 8;
}
51 changes: 51 additions & 0 deletions src/main/java/com/reandroid/arsc/coder/CoderUnknownNameId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.coder;

import com.reandroid.arsc.value.ValueType;
import com.reandroid.utils.HexUtil;

public class CoderUnknownNameId extends Coder{
@Override
public EncodeResult encode(String text) {
if(text == null || text.length() != LENGTH || !text.startsWith(PREFIX)){
return null;
}
Integer value = parseHex(text.substring(1));
if(value != null){
return new EncodeResult(getValueType(), value);
}
return null;
}
@Override
public String decode(int data) {
return HexUtil.toHex8(PREFIX, data);
}
@Override
public ValueType getValueType() {
return ValueType.REFERENCE;
}
@Override
boolean canStartWith(char first) {
return first == PREFIX_CHAR;
}

public static final CoderUnknownNameId INS = new CoderUnknownNameId();

private static final char PREFIX_CHAR = 'r';
private static final String PREFIX = "r0x";
private static final int LENGTH = 3 + 8;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.coder;

import com.reandroid.arsc.value.ValueType;
import com.reandroid.utils.HexUtil;

public class CoderUnknownReferenceId extends Coder{
@Override
public EncodeResult encode(String text) {
if(text == null || text.length() != LENGTH || !text.startsWith(PREFIX)){
return null;
}
Integer value = parseHex(text.substring(1));
if(value != null){
return new EncodeResult(getValueType(), value);
}
return null;
}
@Override
public String decode(int data) {
return HexUtil.toHex8(PREFIX, data);
}
@Override
public ValueType getValueType() {
return ValueType.REFERENCE;
}
@Override
boolean canStartWith(char first) {
return first == PREFIX_CHAR;
}

public static final CoderUnknownReferenceId INS = new CoderUnknownReferenceId();

private static final char PREFIX_CHAR = '@';
private static final String PREFIX = "@0x";
private static final int LENGTH = 3 + 8;
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static TableBlock createDummy() throws IOException {
" android:versionName=\"1.0\"\n" +
" android:compileSdkVersion=\"32\"\n" +
" android:compileSdkVersionCodename=\"12\"\n" +
" app:UNK_ATTR0x7f0501ab=\"0x00000005\"\n" +
" app:r0x7f0501ab=\"0x00000005\"\n" +
" package=\"com.example.package\"\n" +
" platformBuildVersionCode=\"32\"\n" +
" platformBuildVersionName=\"12\"\n" +
Expand Down

0 comments on commit 03ad33b

Please sign in to comment.