ELFAnalyzer.java revision ab6406f9557d78081e2476b704d189ee42e7bb04
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*/
/**
* Analyzes ELF (Executable and Linking Format) files.
* Created on September 23, 2005
*
* @author Chandan
*/
public class ELFAnalyzer extends FileAnalyzer {
"\177ELF"
};
return this.g;
}
private StringBuffer sb;
private char[] content;
private int len;
private int[] readables;
// PlainSymbolTokenizer plainref;
/** Creates a new instance of ELFAnalyzer */
public ELFAnalyzer() {
super();
// plainref = new PlainSymbolTokenizer(dummy);
}
try {
if(in instanceof FileInputStream) {
if (len > 0) {
//doc.add(Field.Text("refs", " "));
}
} else {
if (len > 0) {
//doc.add(Field.Text("refs", " "));
}
}
} catch (Exception e) {
//System.err.println(e);
}
}
throw new IOException("not an ELF File");
int shstrtab = 0;
//ELFSymbol[] symbols;
// ELFSymbol[] dynsyms;
// ELFDynamic[] dyns;
int ri = 0;
}
}
//StringBuilder symTab = new StringBuilder();
/* } else if(".dynsym".equals(sname)) {
int strOffset = sectionMap.get(".dynstr");
fmap.position(sections[i].sh_offset);
for (int symi = 0; symi < numSym; symi++) {
fmap.position(sections[i].sh_offset + symi * sections[i].sh_entsize);
ELFSymbol sym = new ELFSymbol(fmap);
if(sym.st_name != 0) {
String symbol = getName(sym.st_name, strOffset, fmap);
symTab.append(sname + " [ "+ symi + "]"+ symbol + sym.toString());
symTab.append("\n");
}
}
} else if(".symtab".equals(sname)) {
int strOffset = sectionMap.get(".strtab");
fmap.position(sections[i].sh_offset);
for (int symi = 0; symi < numSym; symi++) {
fmap.position(sections[i].sh_offset + symi * sections[i].sh_entsize);
ELFSymbol sym = new ELFSymbol(fmap);
if(sym.st_name != 0) {
String symbol = getName(sym.st_name, strOffset, fmap);
symTab.append(sname + " [ "+ symi + "]"+ symbol + sym.toString());
symTab.append("\n");
}
}
*/
}
}
/* if(len + symTab.length() > content.length) {
int max = content.length * 2 + symTab.length();
char[] content2 = new char[max];
System.arraycopy(content, 0, content2, 0, len);
content = content2;
}
System.err.println("SYmbolTable = <pre>" + symTab + " </html>");
symTab.getChars(0,symTab.length(), content, len);
*/
boolean lastPrintable = false;
len = 0;
for(int i = 0 ; i < ri ; i++) {
}
byte c;
while(size-->0) {
if(isReadable(c)) {
lastPrintable = true;
} else if(lastPrintable) {
lastPrintable = false;
}
}
}
}
private boolean isReadable(int c) {
if(c > ' ' && c <= 127) {
return true;
}
return false;
}
if(tab == 0)
return null;
byte c;
}
}
return plainfull;
}
}
/**
* Write a cross referenced HTML file.
* @param out Writer to write
*/
}
class ELFHeader {
// Elf32 Addr = readInt
// elf32 half = readUnsignedShort
// Off = int
// Sword = int
// Word = int
// un = unsignedBtye
public int ei_class;
public int ei_data;
public int ei_version;
public int e_type;
public int e_machine;
public int e_version;
public int e_entry;
public int e_phoff;
public int e_shoff;
public int e_flags;
public int e_ehsize;
public int e_phentsize;
public int e_phnum;
public int e_shentsize;
public int e_shnum;
public int e_shstrndx;
if (ei_data == ELFDATA2LSB) {
} else {
}
}
"\ne_type: "+e_type+
"\ne_machine: "+e_machine+
"\ne_version: "+e_version+
"\ne_entry: "+e_entry+
"\ne_phoff: "+e_phoff+
"\ne_shoff: "+e_shoff+
"\ne_flags: "+e_flags+
"\ne_ehsize: "+e_ehsize+
"\ne_phentsize:"+e_phentsize+
"\ne_phnum: "+e_phnum+
"\ne_shentsize"+e_shentsize+
"\ne_shnum: "+e_shnum+
"\ne_shstrndx: "+e_shstrndx);
}
}
class ELFSection {
public int sh_name;
public int sh_type;
public int sh_flags;
public int sh_addr;
public int sh_offset;
public int sh_size;
public int sh_link;
public int sh_info;
public int sh_addralign;
public int sh_entsize;
}
return(
"\nsh_name : " + sh_name +
"\nsh_type : " + sh_type +
"\nsh_flags: " + sh_flags +
"\nsh_addr: " + sh_addr +
"\nsh_offset: " + sh_offset +
"\nsh_size: " + sh_size +
"\nsh_link: " + sh_link +
"\nsh_info: " + sh_info +
"\nsh_addralign: " + sh_addralign +
"\nsh_entsize: " + sh_entsize );
}
}
class ELFSymbol {
public int st_name;
public int st_value;
public int st_size;
public int st_info;
public int st_other;
public int st_shndx;
}
switch(type) {
}
}
}
class ELFDynamic {
public long d_tag;
public long d_val;
}
}
}
"None", "32", "64"
};
"None","AT&T", "SPARC", "Intel 80386",
"Motorola 68000", "Motorola 88000", "", "Intel 80860", "MIPS RS3000"
};
public static final int SHT_SUNW_COMDAT = 0x6ffffffb;
}