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 ...
随机推荐
- 服务器编程入门(7)I/O复用
问题聚焦: 前篇提到了I/O处理单元的四种I/O模型. 本篇详细介绍实现这些I/O模型所用到的相关技术. 核心思想:I/O复用 使用情景: 客户端程序要同时处理多个socket ...
- Java对Xml进行操作的实例(转)
这是一个用JAVA W3C DOM 进行XML操作的例子,包含了查询.增加.修改.删除.保存的基本操作.较完整的描述了一个XML的整个操作流程.适合刚入门JAVA XML操作的朋友参考和学习. 假设有 ...
- WebSocket API
WebSocket API 这一章介绍如何用WebSocket API来控制协议和创建应用,运用http://websocket.org 提供的现有WebSocket服务器,我们可以收发消息.创建一些 ...
- C#之网络
首先很不好意思,前段时间把评论的功能给关掉啦,BUT NOW 此功能以开放,欢迎小伙伴们拍砖. 1网络 在网络环境下,我们最感兴趣的两个名称空间是System.Net和System.Net.Socke ...
- ajax基本概念,方法
ajax Asynchronous javascript and xml异步的 javascript and XMLajax 是一门在不刷新网页的情况下,与服务器进行交互更新部分网页的技术: 传 ...
- Android至ViewPager添加切换动画——使用属性动画
转载请注明出处:http://blog.csdn.net/allen315410/article/details/44200623 ViewPager作为Android最经常使用的的组件之中的一个.相 ...
- Golang初学者的资源整理
看了汪汪汪不是我的语言的GO语言零基础入门资料整理,个人感觉还不够全面,忍不住过来补充一些内容. 网站教程: GO语言编程 and GO语言开发2048 from 实验楼Go语言后台应用开发 form ...
- jquery再体验
$(function(){ var obj = $("div[id^='channel_'][id$='_left']"); var val = obj.html(); var i ...
- 虚拟化技术学习(一)在VMware虚拟机中安装KVM
近期一直研究虚拟化技术,曾经对VMware虚拟机有一定的了解,近期突发奇想,能不能在VMware虚拟机中再装一个虚拟机呢? 那么问题就来了,首先,你须要一台电脑,vmware软件,(本人的电脑配置渣渣 ...
- 【剑指offer】面试题35:第一个数字只出现一次
def FirstNotRepeatingChar(string): hashStr = [0] * 256 for c in string: hashStr[ord(c)] += 1 for c i ...