-
-
Notifications
You must be signed in to change notification settings - Fork 44
Strings Usage
Efra Espada edited this page Dec 31, 2019
·
3 revisions
The plugin will obfuscate all string tags with hidden="true"
as attribute.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">String Obfuscator Sample</string>
<string name="hello" hidden="true" androidTreatment="false" containsHtml="true">
<i>Hello <strong>there</strong></i><br></br>
General <strong>Kenobi</strong>.
</string>
<string name="pattern" hidden="true">%1$s (%2$d)</string>
<string name="snake_msg_hidden" hidden="true">\n\nla-li-lu-le-lo\n\n🐍😄🍉</string>
<string name="hello_world_a">Hello
World
</string>
<string name="hello_world_b" hidden="true">Hello
World
</string>
<string name="hello_world_c" hidden="true" androidTreatment="false">Hello
World
</string>
</resources>
Use the reveal(int id)
static method to expose obfuscated strings on code:
String hello = SC.reveal(R.string.hello); // Hello there
String pattern = SC.reveal(R.string.pattern, "hi", 3); // hi (3)
With Kotlin functions:
val hello = R.string.hello.reveal() // Hello there
val pattern = R.string.pattern.reveal("hi", 3); // hi (3)
You can also expose strings directly on layout:
<com.stringcare.library.SCTextView
android:text="@string/hello"
app:reveal="true"/>
Credits to @Narvelan
StringCare can be used for obfuscating data programmatically and read the original string where you want:
String obfuscated = SC.obfuscate("hello there");
String original = SC.reveal(obfuscated);
With Kotlin:
val obfuscated = "hello there".obfuscate();
val original = obfuscated.reveal()
<string name="hello" hidden="true" containsHtml="true">
<i>Hello <strong>there</strong></i><br></br>General <strong>Kenobi</strong>.
</string>
For printing directy on layout:
<com.stringcare.library.SCTextView
android:text="@string/hello"
app:htmlSupport="true"
app:reveal="true"/>
The androidTreatment
attribute allows to configure the way you process strings. By default, StringCare process string resources like the Android system.
<string name="hello_world_a">Hello
World
</string>
<string name="hello_world_b" hidden="true">Hello
World
</string>
Hello World
The plugin can process the strings unescaping text:
<string name="hello_world_c" hidden="true" androidTreatment="false">Hello
World
</string>
Hello
World
For printing directy on layout:
<com.stringcare.library.SCTextView
android:text="@string/hello_world_c"
app:androidTreatment="true"
app:reveal="true"/>
For use on code:
// SC.reveal(int resId, boolean androidTreatment)
String value = SC.reveal(R.string.hello_world_c, false);
For use with Kotlin:
val value = R.string.hello_world_c.reveal(false)
SC.init(getApplicationContext());
String password = getString(R.string.snake_msg_hidden);
String original = SC.reveal(password, Version.V3);
String message = "Snake, the password is " + password + original;
((TextView) findViewById(R.id.programmatically_obfuscation)).setText(message);
String numbers = getString(R.string.pattern, "hi", 3) + " is " + SC.reveal(R.string.pattern, "hi", 3);
((TextView) findViewById(R.id.pattern)).setText(numbers);
final SCTextView tvAuto = findViewById(R.id.auto_tv);
findViewById(R.id.btn_change).setOnClickListener(v -> {
// button logic
if (tvAuto.isHtmlEnabled()) {
tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
} else if (tvAuto.isRevealingValue()){
tvAuto.setRevealed(!tvAuto.isRevealingValue());
} else if (!tvAuto.isRevealingValue()){
tvAuto.setRevealed(!tvAuto.isRevealingValue());
tvAuto.setHtmlSupport(!tvAuto.isHtmlEnabled());
}
});
boolean equals = SC.reveal(R.string.hello_world_b).equals(getString(R.string.hello_world_a));
String areEquals = "Same result: " + equals;
((TextView) findViewById(R.id.same_value)).setText(areEquals);
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.