mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-07 09:05:24 +02:00
Fix PR 50810
COFF/PE parser the String Table had wrong value. Guard against it. Model: Cache the IBinaryArchive class in Archive.
This commit is contained in:
parent
422c72bec0
commit
af52cdf27d
5 changed files with 26 additions and 32 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
2004-02-05 Alain Magloire
|
||||||
|
|
||||||
|
PR 50810
|
||||||
|
Coff format the String Table section may have incorrect value.
|
||||||
|
We should guard against it.
|
||||||
|
|
||||||
|
* utils/org/eclipse/cdt/utils/Coff.java
|
||||||
|
* utils/org/eclipse/cdt/utils/PE.java
|
||||||
|
|
||||||
|
Cache the IBinaryArchive class so not to reload again.
|
||||||
|
* model/org/eclipse/cdt/internal/core/model/Archive.java
|
||||||
|
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
|
||||||
|
|
||||||
2004-02-03 Alain Magloire
|
2004-02-03 Alain Magloire
|
||||||
PR 51143
|
PR 51143
|
||||||
|
|
||||||
|
|
|
@ -5,31 +5,30 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser;
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.IArchive;
|
import org.eclipse.cdt.core.model.IArchive;
|
||||||
import org.eclipse.cdt.core.model.IBinary;
|
import org.eclipse.cdt.core.model.IBinary;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
public class Archive extends Openable implements IArchive {
|
public class Archive extends Openable implements IArchive {
|
||||||
|
|
||||||
public Archive(ICElement parent, IFile file) {
|
IBinaryArchive binaryArchive;
|
||||||
this(parent, file.getLocation());
|
|
||||||
|
public Archive(ICElement parent, IFile file, IBinaryArchive bin) {
|
||||||
|
this(parent, file.getLocation(), bin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Archive(ICElement parent, IPath path) {
|
public Archive(ICElement parent, IPath path, IBinaryArchive bin) {
|
||||||
super (parent, path, ICElement.C_ARCHIVE);
|
super (parent, path, ICElement.C_ARCHIVE);
|
||||||
|
binaryArchive = bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinary[] getBinaries() {
|
public IBinary[] getBinaries() {
|
||||||
|
@ -64,7 +63,7 @@ public class Archive extends Openable implements IArchive {
|
||||||
|
|
||||||
|
|
||||||
public boolean computeChildren(OpenableInfo info, IResource res) {
|
public boolean computeChildren(OpenableInfo info, IResource res) {
|
||||||
IBinaryArchive ar = getBinaryArchive(res);
|
IBinaryArchive ar = getBinaryArchive();
|
||||||
if (ar != null) {
|
if (ar != null) {
|
||||||
IBinaryObject[] objects = ar.getObjects();
|
IBinaryObject[] objects = ar.getObjects();
|
||||||
for (int i = 0; i < objects.length; i++) {
|
for (int i = 0; i < objects.length; i++) {
|
||||||
|
@ -78,27 +77,8 @@ public class Archive extends Openable implements IArchive {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IBinaryArchive getBinaryArchive(IResource res) {
|
IBinaryArchive getBinaryArchive() {
|
||||||
IBinaryArchive archive = null;
|
return binaryArchive;
|
||||||
IProject project = null;
|
|
||||||
IBinaryParser parser = null;
|
|
||||||
if (res != null) {
|
|
||||||
project = res.getProject();
|
|
||||||
}
|
|
||||||
if (project != null) {
|
|
||||||
parser = CModelManager.getDefault().getBinaryParser(project);
|
|
||||||
}
|
|
||||||
if (parser != null) {
|
|
||||||
try {
|
|
||||||
IPath path = res.getLocation();
|
|
||||||
IBinaryFile bfile = parser.getBinary(path);
|
|
||||||
if (bfile instanceof IBinaryArchive) {
|
|
||||||
archive = (IBinaryArchive) bfile;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return archive;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.CProjectNature;
|
import org.eclipse.cdt.core.CProjectNature;
|
||||||
import org.eclipse.cdt.core.IBinaryParser;
|
import org.eclipse.cdt.core.IBinaryParser;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||||
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||||
import org.eclipse.cdt.core.model.IArchive;
|
import org.eclipse.cdt.core.model.IArchive;
|
||||||
|
@ -229,7 +230,7 @@ public class CModelManager implements IResourceChangeListener {
|
||||||
}
|
}
|
||||||
if (bin != null) {
|
if (bin != null) {
|
||||||
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
||||||
cfile = new Archive(parent, file);
|
cfile = new Archive(parent, file, (IBinaryArchive)bin);
|
||||||
} else {
|
} else {
|
||||||
cfile = new Binary(parent, file, bin);
|
cfile = new Binary(parent, file, bin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -478,7 +478,7 @@ public class Coff {
|
||||||
byte[] bytes = new byte[4];
|
byte[] bytes = new byte[4];
|
||||||
rfile.readFully(bytes);
|
rfile.readFully(bytes);
|
||||||
int str_len = ReadMemoryAccess.getIntLE(bytes);
|
int str_len = ReadMemoryAccess.getIntLE(bytes);
|
||||||
if (str_len > 4) {
|
if (str_len > 4 && str_len < rfile.length()) {
|
||||||
str_len -= 4;
|
str_len -= 4;
|
||||||
string_table = new byte[str_len];
|
string_table = new byte[str_len];
|
||||||
rfile.seek(offset + 4);
|
rfile.seek(offset + 4);
|
||||||
|
|
|
@ -550,7 +550,7 @@ public class PE {
|
||||||
byte[] bytes = new byte[4];
|
byte[] bytes = new byte[4];
|
||||||
accessFile.readFully(bytes);
|
accessFile.readFully(bytes);
|
||||||
int str_len = ReadMemoryAccess.getIntLE(bytes);
|
int str_len = ReadMemoryAccess.getIntLE(bytes);
|
||||||
if (str_len > 4) {
|
if (str_len > 4 && str_len < accessFile.length()) {
|
||||||
str_len -= 4;
|
str_len -= 4;
|
||||||
stringTable = new byte[str_len];
|
stringTable = new byte[str_len];
|
||||||
accessFile.seek(offset + 4);
|
accessFile.seek(offset + 4);
|
||||||
|
|
Loading…
Add table
Reference in a new issue