0

I use BCEL library to extract bytecode from a particular Method. To do that, I use getCode() function from BCEL Method class.

When I do:

String code = metod.getCode().toString();
System.out.print(code);

If you look at lcd opcode, I get this:

Bad encoding

but, I would like to have that (for lcd opcode):

enter image description here

If I use JavaP to decompile, the result is as the second picture.

The problem is in the encoding, which I think should be UTF-8. I look on other topics how to change encoding, but I am not sure that this is the problem.

How can I have good string encoding using BCEL ?

EDIT:

First picture is from Java console. Second picture is from dirtyJOE v1.5

Pier-Alexandre Bouchard
  • 5,135
  • 5
  • 37
  • 72
  • 1. There exists no such thing as an "lcd" opcode. 2. You have not told us what you perceive to be the difference between "this" and "that". They are probably identical as far as I can tell. If you think they are not, prove it. – Mike Nakis May 30 '20 at 11:42

1 Answers1

0

I'm not sure you really have a problem here... ... but nevertheless, you can easily convert ANY string type to UTF-8 at will.

For example:

String s = "some text here";
byte[] b = s.getBytes("UTF-8");

See also: How to convert Strings to and from UTF8 byte arrays in Java

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190