Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String constructor with byte array #530

Closed
asashour opened this issue Mar 28, 2019 · 4 comments
Closed

String constructor with byte array #530

asashour opened this issue Mar 28, 2019 · 4 comments

Comments

@asashour
Copy link
Contributor

As deduced from #529, there is also a potential to make String constructor beautiful.

	public static class TestCls {
		public String tag = new String(new byte[] {'a', 'b', 'c'});
	}

	@Test
	public void test() {
		ClassNode cls = getClassNode(TestCls.class);
		String code = cls.getCode().toString();

		assertThat(code, containsOne("abc"));
	}

@asashour
Copy link
Contributor Author

asashour commented Mar 28, 2019

I am trying to fix this, but I counter an issue, the corresponding output could be something like:

new String("abc".getBytes(), StandardCharsets.UTF_8);

And I don't know how to construct a MethodInfo of the String(byte[]) constructor if it is not found in dex.

@skylot
Copy link
Owner

skylot commented Mar 28, 2019

Looks like you need to implement it youself. Add to MethodInfo class something like this:

public static MethodInfo externalMth(ClassInfo declaredCls, String name, List<ArgType> args, ArgType retType) {

@bagipro
Copy link
Collaborator

bagipro commented Mar 28, 2019

Seems that it would be better to begin from constant concatenations like

String value = "a" + "b";

sometimes "a" could be a static final String SMTH = "a"; value, and when --no-replace-consts option is enabled, the given output will be generated. But it's nicer to see

String value = "ab";

@asashour
Copy link
Contributor Author

Seems that it would be better to begin from constant concatenations like

String value = "a" + "b";

sometimes "a" could be a static final String SMTH = "a"; value, and when --no-replace-consts option is enabled, the given output will be generated. But it's nicer to see

String value = "ab";

I guess this is a different case, since constants are usually String, but the one is question is a byte array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants