高中生

- 金币
- 151
- 好评
- 9
- 信誉
- 100
|
本帖最后由 Armadill0 于 2023-9-23 19:14 编辑
.........,不知道说什么,不喜勿喷.
赏我点金币吧!  
没有调用例子,因为我觉得应该没有人不会实例化吧............
额,刚入论坛不知道怎么加附件......所以直接把代码扔这里把?
- //前言,你拿去干嘛倒是无所谓.............
- //该懂得都懂了把?
- //提示,改的是常量的值.
- import java.io.*;
- import java.util.*;
- import org.jf.dexlib.*;
- import org.jf.dexlib.Code.*;
- import org.jf.dexlib.Util.*;
- import org.jf.util.*;
- public class Dexlib
- {
- private DexFile dex;
- private List<ClassDefItem> classes;
- private ArrayList<ClassDataItem.EncodedMethod> methods;
- private ArrayList<StringIdItem> stringIds;
- private org.jf.dexlib.CodeItem code;
- private List<Integer> showListOffsets;
- //构造函数
- public static byte[] toByteArray(InputStream in) throws IOException
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024 * 4];
- int n = 0;
- while ((n = in.read(buffer)) != -1)
- {
- out.write(buffer, 0, n);
- }
- return out.toByteArray();
- }
- //修改常量池的
- public void StringReplace(String old, String news) throws IOException
- {
- List<String> s = new ArrayList<String>();
- read(s);
- for (int i =0;i < s.size();i += 1)
- {
- if (s.get(i).equals(old))
- s.set(i, news);
- }
- String[] a=new String[s.size()];
- for (int i=0;i < s.size();i++)
- {
- a[i] = s.get(i).toString();
- }
- write(a);
- }
- //保存dex的三个监听事件.....
- public interface SaveDexListener
- {
- public void onSuccess();
- public void onProgress(int size, int progress);
- public void onFailed(Exception e);
- }
- //这里是Dex的修改和保存操作,有三个Listener.
- public void save(File outfile, SaveDexListener callback)
- {
- try
- {
- DexFile dex2=new DexFile();
- IndexedSection<ClassDefItem> classes=dex.ClassDefsSection;
- for (int i=0;i < classes.getItems().size();i++)
- {
- classes.getItems().get(i).internClassDefItem(dex2);
- callback.onProgress(classes.getItems().size(), i);
- }
- dex2.setSortAllItems(true);
- dex2.place();
- byte[] buf=new byte[dex2.getFileSize()];
- ByteArrayAnnotatedOutput out=new ByteArrayAnnotatedOutput(buf);
- dex2.writeTo(out);
- DexFile.calcSignature(buf);
- DexFile.calcChecksum(buf);
- new FileOutputStream(outfile).write(buf);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- callback.onFailed(e);
- }
- callback.onSuccess();
- }
- }
复制代码
|
|