There are three possible answers I can give you: a specific answer based on the information you have included at the bottom of your post, a bottom-up answer that hopefully makes sense to you at your current level of academic experience, and a top-down answer which makes sense to me as an (early career) academic but which might not make as much sense to you yet.
Specific Answer
Reverse-engineering code is a common task in some circles of academia. Often I want to use another person's code, but I need to either (a) fully understand how it works, or (b) modify it slightly to do something different that I want to do. In such situations, reverse-engineering is called for.
Therefore, you are likely doing real academic work, even if it isn't exactly what you signed up for, and you will definitely learn something important. Which leads us to the ...
Bottom-up Answer
If you are not sure that you will learn something important doing this reverse-engineering task, then ask your professor. It seems like the purpose of your work isn't clear to you, and when anyone isn't sure why they're doing something they're naturally not going to enjoy it very much.
One way to structure the conversation with your professor is to ask these three questions:
- What is the thing we are trying to do that has not been done before?
- Why is it important that we are able to do that thing?
- How will the work that I do enable us to do that thing?
Be ready to do as much or as little reading as your professor assigns you. If your professor is at all a good professor, they will know that your understanding is key to achieving good results. If your professor isn't a good one -- well, you will still be able to learn something, hopefully. Which leads me to ...
Top-down Answer
From the viewpoint of a long-standing researcher, an undergraduate student often does not know much about the field of their interest. Undergraduate education is all about What We Know, and academic research is all about What We Don't Know, and the amount of knowledge you must have to even be able to ask good questions is often surprisingly large.
This has consequences. For example, a lot of academic work looks surprisingly menial. It looks like understanding old papers, learning boring techniques, repeating old experiments -- and yes, reverse-engineering existing code. What your professor has assigned you may therefore be building a foundation for your future work that you don't appreciate yet.
A lot of academic work, especially meaningful work, is also surprisingly cross-disciplinary. You mentioned that you can't see the connection between AI and simulation. But concepts from simulation -- sampling, ergodicity, entropy, autocorrelation, even free energies -- are vital to machine learning. On a practical level, many modern groups pushing the boundaries in machine learning are doing so to solve simulation problems -- such as the AlphaFold team at Google. So, what your professor is doing might also enable you to make unexpected connections that give you a competitive edge.
So don't be too surprised that you are working on something that doesn't look like your main field of interest -- that is something that not only can happen from time to time, but must happen if you want to be at all an effective researcher in the future. Of course, I can't ask you to take this on faith, and it is your professor's job to at least partially convince you that what you are doing is worthwhile work.
But if you have a clearly-defined goal with clearly-defined significance and a clearly-defined way to achieve it, then you should at least try to work at it for a while before worrying that it is irrelevant to your future.