java获取exe执行文件属性-详细信息(产品名称、产品版本等)

引入jar包:

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.76</version>
</dependency>

<dependency>
  <groupId>com.kichik.pecoff4j</groupId>
  <artifactId>pecoff4j</artifactId>
  <version>0.3.1</version>
</dependency>

代码实现:

import com.alibaba.fastjson.JSONObject;
import com.kichik.pecoff4j.PE;
import com.kichik.pecoff4j.ResourceDirectory;
import com.kichik.pecoff4j.ResourceEntry;
import com.kichik.pecoff4j.constant.ResourceType;
import com.kichik.pecoff4j.io.PEParser;
import com.kichik.pecoff4j.io.ResourceParser;
import com.kichik.pecoff4j.resources.StringFileInfo;
import com.kichik.pecoff4j.resources.StringTable;
import com.kichik.pecoff4j.resources.VersionInfo;
import com.kichik.pecoff4j.util.ResourceHelper;

import java.io.IOException;

public class ExeFileDetailInfo {

    public static JSONObject getExeProductInfo(String filePath) throws IOException {
        JSONObject jObj = new JSONObject();
        PE pe = PEParser.parse(filePath);
        ResourceDirectory rd = pe.getImageData().getResourceTable();

        ResourceEntry[] entries = ResourceHelper.findResources(rd, ResourceType.VERSION_INFO);
        for (int i = 0; i < entries.length; i++) {
            byte[] data = entries[i].getData();
            VersionInfo version = ResourceParser.readVersionInfo(data);
            StringFileInfo strings = version.getStringFileInfo();
            StringTable table = strings.getTable(0);

            for (int j = 0; j < table.getCount(); j++) {
                String key = table.getString(j).getKey();
                String value = table.getString(j).getValue();
                System.out.println(key + " = " + value);
                jObj.put(key,value);
            }
        }

        return jObj;
    }

    public static void main(String[] args) throws IOException {

        String filePath = "D:\\ChromeStandaloneSetup64.exe";

        JSONObject tmp = getExeProductInfo(filePath);
        System.out.println("详细信息:" + tmp);

        System.out.println("产品名称:" + tmp.getString("ProductName"));
        System.out.println("产品版本:" + tmp.getString("ProductVersion"));
    }

}

结果输出:

  • CompanyName = Google LLC
  • FileDescription = Google Update Setup
  • FileVersion = 1.3.35.301
  • InternalName = Google Update Setup
  • LegalCopyright = Copyright 2018 Google LLC
  • OriginalFilename = GoogleUpdateSetup.exe
  • ProductName = Google Update
  • ProductVersion = 1.3.35.301
  • LanguageId = en
  • 详细信息:{"CompanyName":"Google LLC","FileDescription":"Google Update Setup","LegalCopyright":"Copyright 2018 Google LLC","OriginalFilename":"GoogleUpdateSetup.exe","ProductName":"Google Update","FileVersion":"1.3.35.301","ProductVersion":"1.3.35.301","InternalName":"Google Update Setup","LanguageId":"en"}
  • 产品名称:Google Update
  • 产品版本:1.3.35.301
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值