Java 解析 lnk 快捷方式文件的方法(转)
package file.extendsion; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream; public class LnkParser { // http://www.oschina.net/code/snippet_12_274
public static void main(String[] args) throws Exception {
new LnkParser(new File("e:/eclipse.lnk"));
} public LnkParser(File f) throws Exception {
parse(f);
} private boolean is_dir; public boolean isDirectory() {
return is_dir;
} private String real_file; public String getRealFilename() {
return real_file;
} public void parse(File f) throws Exception {
// read the entire file into a byte buffer
FileInputStream fin = new FileInputStream(f);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buff = new byte[256];
while (true) {
int n = fin.read(buff);
if (n == -1) {
break;
}
bout.write(buff, 0, n);
}
fin.close();
byte[] link = bout.toByteArray(); // get the flags byte
byte flags = link[0x14]; // get the file attributes byte
final int file_atts_offset = 0x18;
byte fileatts = link[file_atts_offset];
byte is_dir_mask = (byte) 0x10;
if ((fileatts & is_dir_mask) > 0) {
is_dir = true;
} else {
is_dir = false;
} // if the shell settings are present, skip them
final int shell_offset = 0x4c;
int shell_len = 0;
if ((flags & 0x1) > 0) {
// the plus 2 accounts for the length marker itself
shell_len = bytes2short(link, shell_offset) + 2;
} // get to the file settings
int file_start = 0x4c + shell_len; // get the local volume and local system values
int local_sys_off = link[file_start + 0x10] + file_start;
real_file = getNullDelimitedString(link, local_sys_off);
p("real filename = " + real_file);
} static String getNullDelimitedString(byte[] bytes, int off) {
int len = 0;
// count bytes until the null character (0)
while (true) {
if (bytes[off + len] == 0) {
break;
}
len++;
}
return new String(bytes, off, len);
} // convert two bytes into a short // note, this is little endian because
// it's for an // Intel only OS.
static int bytes2short(byte[] bytes, int off) {
return bytes[off] | (bytes[off + 1] << 8);
} /*
* static int norm(byte b) { if(b < 0) { b+=128; } return b; } static int
* bytes2int(byte[] arr, int off) { int b1 = norm(arr[off]); int b2 =
* norm(arr[off+1]); int b3 = norm(arr[off+2]); int b4 = norm(arr[off+3]);
* int val = ( (b1 << 0) | (b2 << 8) | (b3 << 16) | (b4 << 24) );
* //p("bytes2int: " + b1 + " " + b2 + " " + b3 + " " + b4); return val; }
*
*
* static NumberFormat num_format = new DecimalFormat(" 000;-000");
*
* public static String padd(String str, int len) { while(str.length() <
* len) { str = " " + str; } return str; }
*
* public static void pw(byte[] arr, int off) { StringBuffer top = new
* StringBuffer(); StringBuffer mid = new StringBuffer(); StringBuffer bot =
* new StringBuffer(); top.append("--"); mid.append(" "); bot.append(" ");
*
* for(int i=0; i<16; i++) { int val = arr[off+i]; String str =
* Integer.toHexString(off+i); top.append(padd(str,5));
* mid.append(padd(""+val,5)); if(val < 0) { val += 128; } if(val >= ' ' &&
* val <= '~') { str = "" + (char)val; } else { str =
* Integer.toHexString(val); } str = padd(str,5); bot.append(str);
* if(i%4==3) { top.append(" "); mid.append(" "); bot.append(" ");
* } } p(top.toString()); p(mid.toString()); p(bot.toString()); } public
* static void pbits(byte bt) { p("byte = " + bt + " " +
* Integer.toHexString(bt) + " " + Integer.toBinaryString(bt)); }
*/ public static void p(String str) {
System.out.println(str);
}
}
http://www.oschina.net/code/snippet_12_274
Java 解析 lnk 快捷方式文件的方法(转)的更多相关文章
- java解析xml的三种方法
java解析XML的三种方法 1.SAX事件解析 package com.wzh.sax; import org.xml.sax.Attributes; import org.xml.sax.SAXE ...
- 【Java】详解Java解析XML的四种方法
XML现在已经成为一种通用的数据交换格式,平台的无关性使得很多场合都需要用到XML.本文将详细介绍用Java解析XML的四种方法. AD: XML现在已经成为一种通用的数据交换格式,它的平台无关性,语 ...
- Java解析XML的四种方法详解 - 转载
XML现在已经成为一种通用的数据交换格式,平台的无关性使得很多场合都需要用到XML.本文将详细介绍用Java解析XML的四种方法 在做一般的XML数据交换过程中,我更乐意传递XML字符串,而不是格式化 ...
- java中读取资源文件的方法
展开全部 1.使用java.util.Properties类的load()方法 示例: //文件在项目下.不是在包下!! InputStream in = new BufferedInputStrea ...
- JAVA解析XML的四种方法
XML文件:test.xml <?xml version="1.0" encoding="UTF-8"?> <employees> &l ...
- Java 解析XML的几种方法
XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便. XML在不同的语言里解析方式都是一样的,只不过实现的语法不同而已. 基本的解析方式 ...
- java读写Properties属性文件公用方法
Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件. 它提供了几个主要的方法: 1. getProperty ( String ...
- 详解Java解析XML的四种方法
XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便.对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM ...
- [转]详解Java解析XML的四种方法
XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便.对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM ...
随机推荐
- hdu2844(多重背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2844 题意:一位同学想要买手表,他有n种硬币,每种硬币已知有num[i]个.已知手表的价钱最多m元,问 ...
- 《SAS编程和数据挖掘商业案例》第14部分学习笔记
继续<SAS编程与数据挖掘商业案例>学习笔记系列,本次重点:经常使用全程语句 所谓全程语句.是指能够用在不论什么地方的sas语句,既能够用在data数据步语句里面,也能够用在proc过程步 ...
- Meet Apache Wicket
第一次接触Wicket,如此多的内容是文字,的原贴,希望大家指正 Meet Apache Wicket By JonathanLocke, original author of Wicket 乔纳森· ...
- 2014牡丹江——Hierarchical Notation
problemId=5380" style="background-color:rgb(51,255,51)">题目链接 字符串模拟 const int MAXN ...
- Jquery 对话框确认
$("#aa").click(function(){ if(confirm("是否继续")){ $(#aa).fadeOut(500); } })
- C# 简化优化if/switch 表驱动法
表示这个很强大 字典加反射,搞定多window的switch public partial class MainWindow : Window { Dictionary<string, Type ...
- wIndows phone 7 解析Html数据
原文:wIndows phone 7 解析Html数据 在我的上一篇文章中我介绍了windows phone 7的gb2312解码, http://www.cnblogs.com/qingci/arc ...
- 动态接口服务 webservice
private void GetDll() { WebClient client = new WebClient(); string url = "http://xxxx/services/ ...
- hdu 5035 概率论
n服务形式,各服务窗口等候时间指数公布,求所需的等待时间. 解: 相两点:首先,等到轮到他,然后就是送达时间. 潜伏期期望每个表单1/ki(1/ki,宣布预期指数公式).总的等待时间预期1/(求和ki ...
- ftp桥接到http服务
先说一下我的需求:我的linodeserver近期ftp和sftp连不上了,port被封了.仅仅有http能够訪问,我没有办法上传文件了.由于我寻常都用beyond compare上传文件,非常方便. ...