Source Code Cross Referenced for PEHeader.java in  » Installer » jsmooth » net » charabia » jsmoothgen » pe » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » jsmooth » net.charabia.jsmoothgen.pe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          JSmooth: a VM wrapper toolkit for Windows
003:          Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005:          This program is free software; you can redistribute it and/or modify
006:          it under the terms of the GNU General Public License as published by
007:          the Free Software Foundation; either version 2 of the License, or
008:          (at your option) any later version.
009:
010:          This program is distributed in the hope that it will be useful,
011:          but WITHOUT ANY WARRANTY; without even the implied warranty of
012:          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:          GNU General Public License for more details.
014:
015:          You should have received a copy of the GNU General Public License
016:          along with this program; if not, write to the Free Software
017:          Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019:         */
020:
021:        /*
022:         * PEHeader.java
023:         *
024:         * Created on 28 juillet 2003, 21:38
025:         */
026:
027:        package net.charabia.jsmoothgen.pe;
028:
029:        import java.io.*;
030:        import java.nio.*;
031:        import java.nio.channels.*;
032:        import java.util.*;
033:
034:        /**
035:         *
036:         * @author  Rodrigo Reyes
037:         */
038:        public class PEHeader implements  Cloneable {
039:            public int Machine; //  4
040:            public int NumberOfSections; //  6
041:            public long TimeDateStamp; //  8
042:            public long PointerToSymbolTable; //  C
043:            public long NumberOfSymbols; // 10
044:            public int SizeOfOptionalHeader; // 14
045:            public int Characteristics; // 16
046:
047:            // Optional Header 
048:            public int Magic; // 18
049:            public short MajorLinkerVersion; // 1a
050:            public short MinorLinkerVersion; // 1b
051:            public long SizeOfCode; // 1c
052:            public long SizeOfInitializedData; // 20
053:            public long SizeOfUninitializedData; // 24
054:            public long AddressOfEntryPoint; // 28
055:            public long BaseOfCode; // 2c
056:            public long BaseOfData; //  NT additional fields.  30
057:            public long ImageBase; // 34
058:            public long SectionAlignment; // 38
059:            public long FileAlignment; // 3c
060:            public int MajorOperatingSystemVersion; // 40
061:            public int MinorOperatingSystemVersion; // 42
062:            public int MajorImageVersion; // 44
063:            public int MinorImageVersion; // 46
064:            public int MajorSubsystemVersion; // 48
065:            public int MinorSubsystemVersion; // 4a
066:            public long Reserved1; // 4c
067:            public long SizeOfImage; // 50
068:            public long SizeOfHeaders; // 54
069:            public long CheckSum; // 58
070:            public int Subsystem; // 5c
071:            public int DllCharacteristics; // 5e
072:            public long SizeOfStackReserve; // 60
073:            public long SizeOfStackCommit; // 64
074:            public long SizeOfHeapReserve; // 68
075:            public long SizeOfHeapCommit; // 6c
076:            public long LoaderFlags; // 70
077:            public long NumberOfRvaAndSizes; // 74
078:
079:            public long ExportDirectory_VA; // 78
080:            public long ExportDirectory_Size; // 7c
081:            public long ImportDirectory_VA; // 80
082:            public long ImportDirectory_Size; // 84
083:            public long ResourceDirectory_VA; // 88
084:            public long ResourceDirectory_Size; // 8c
085:            public long ExceptionDirectory_VA; // 90
086:            public long ExceptionDirectory_Size; // 94
087:            public long SecurityDirectory_VA; // 98
088:            public long SecurityDirectory_Size; // 9c
089:            public long BaseRelocationTable_VA; // a0
090:            public long BaseRelocationTable_Size; // a4
091:            public long DebugDirectory_VA; // a8
092:            public long DebugDirectory_Size; // ac
093:            public long ArchitectureSpecificData_VA; // b0
094:            public long ArchitectureSpecificData_Size; // b4
095:            public long RVAofGP_VA; // b8
096:            public long RVAofGP_Size; // bc
097:            public long TLSDirectory_VA; // c0
098:            public long TLSDirectory_Size; // c4
099:            public long LoadConfigurationDirectory_VA; // c8
100:            public long LoadConfigurationDirectory_Size; // cc
101:            public long BoundImportDirectoryinheaders_VA; // d0
102:            public long BoundImportDirectoryinheaders_Size; // d4
103:            public long ImportAddressTable_VA; // d8
104:            public long ImportAddressTable_Size; // dc
105:            public long DelayLoadImportDescriptors_VA; // e0
106:            public long DelayLoadImportDescriptors_Size; // e4
107:            public long COMRuntimedescriptor_VA; // e8
108:            public long COMRuntimedescriptor_Size; // ec
109:
110:            private long m_baseoffset;
111:            private PEFile m_pe;
112:
113:            /** Creates a new instance of PEHeader */
114:            public PEHeader(PEFile pef, long baseoffset) {
115:                m_pe = pef;
116:                m_baseoffset = baseoffset;
117:            }
118:
119:            public Object clone() throws CloneNotSupportedException {
120:                return super .clone();
121:            }
122:
123:            public void read() throws IOException {
124:                FileChannel ch = m_pe.getChannel();
125:                ByteBuffer head = ByteBuffer.allocate(255);
126:                head.order(ByteOrder.LITTLE_ENDIAN);
127:                ch.position(m_baseoffset);
128:                ch.read(head);
129:                head.position(0);
130:
131:                int pemagic = head.getInt();
132:                //	System.out.println("MAGIC::: " + pemagic);
133:                Machine = head.getShort(); //  4
134:                NumberOfSections = head.getShort(); //  6
135:                TimeDateStamp = head.getInt(); //  8
136:                PointerToSymbolTable = head.getInt(); //  C
137:                NumberOfSymbols = head.getInt(); // 10
138:                SizeOfOptionalHeader = head.getShort(); // 14
139:                Characteristics = head.getShort(); // 16
140:                // Optional Header 
141:
142:                Magic = head.getShort(); // 18
143:                MajorLinkerVersion = head.get(); // 1a
144:                MinorLinkerVersion = head.get(); // 1b
145:                SizeOfCode = head.getInt(); // 1c
146:                SizeOfInitializedData = head.getInt(); // 20
147:                SizeOfUninitializedData = head.getInt(); // 24
148:                AddressOfEntryPoint = head.getInt(); // 28
149:                BaseOfCode = head.getInt(); // 2c
150:                BaseOfData = head.getInt(); //    // NT additional fields. // 30
151:                //    
152:                ImageBase = head.getInt(); // 34
153:                SectionAlignment = head.getInt(); // 38
154:                FileAlignment = head.getInt(); // 3c
155:                MajorOperatingSystemVersion = head.getShort(); // 40
156:                MinorOperatingSystemVersion = head.getShort(); // 42
157:                MajorImageVersion = head.getShort(); // 44
158:                MinorImageVersion = head.getShort(); // 46
159:                MajorSubsystemVersion = head.getShort(); // 48
160:                MinorSubsystemVersion = head.getShort(); // 4a
161:                Reserved1 = head.getInt(); // 4c
162:                SizeOfImage = head.getInt(); // 50
163:                SizeOfHeaders = head.getInt(); // 54
164:                CheckSum = head.getInt(); // 58
165:                Subsystem = head.getShort(); // 5c
166:                DllCharacteristics = head.getShort(); // 5e
167:                SizeOfStackReserve = head.getInt(); // 60
168:                SizeOfStackCommit = head.getInt(); // 64
169:                SizeOfHeapReserve = head.getInt(); // 68
170:                SizeOfHeapCommit = head.getInt(); // 6c
171:                LoaderFlags = head.getInt(); // 70
172:                NumberOfRvaAndSizes = head.getInt(); // 74
173:
174:                ExportDirectory_VA = head.getInt(); // 78
175:                ExportDirectory_Size = head.getInt(); // 7c
176:                ImportDirectory_VA = head.getInt(); // 80
177:                ImportDirectory_Size = head.getInt(); // 84
178:                ResourceDirectory_VA = head.getInt(); // 88
179:                ResourceDirectory_Size = head.getInt(); // 8c
180:                ExceptionDirectory_VA = head.getInt(); // 90
181:                ExceptionDirectory_Size = head.getInt(); // 94
182:                SecurityDirectory_VA = head.getInt(); // 98
183:                SecurityDirectory_Size = head.getInt(); // 9c
184:                BaseRelocationTable_VA = head.getInt(); // a0
185:                BaseRelocationTable_Size = head.getInt(); // a4
186:                DebugDirectory_VA = head.getInt(); // a8
187:                DebugDirectory_Size = head.getInt(); // ac
188:                ArchitectureSpecificData_VA = head.getInt(); // b0
189:                ArchitectureSpecificData_Size = head.getInt(); // b4
190:                RVAofGP_VA = head.getInt(); // b8
191:                RVAofGP_Size = head.getInt(); // bc
192:                TLSDirectory_VA = head.getInt(); // c0
193:                TLSDirectory_Size = head.getInt(); // c4
194:                LoadConfigurationDirectory_VA = head.getInt(); // c8
195:                LoadConfigurationDirectory_Size = head.getInt(); // cc
196:                BoundImportDirectoryinheaders_VA = head.getInt(); // d0
197:                BoundImportDirectoryinheaders_Size = head.getInt(); // d4
198:                ImportAddressTable_VA = head.getInt(); // d8
199:                ImportAddressTable_Size = head.getInt(); // dc
200:                DelayLoadImportDescriptors_VA = head.getInt(); // e0
201:                DelayLoadImportDescriptors_Size = head.getInt(); // e4
202:                COMRuntimedescriptor_VA = head.getInt(); // e8
203:                COMRuntimedescriptor_Size = head.getInt(); // ec
204:            }
205:
206:            public void dump(PrintStream out) {
207:                out.println("HEADER:");
208:                out.println("int  Machine=" + Machine + " //  4");
209:                out.println("int  NumberOfSections=" + NumberOfSections
210:                        + "     //  6");
211:                out.println("long   TimeDateStamp=" + TimeDateStamp + " //  8");
212:                out.println("long   PointerToSymbolTable="
213:                        + PointerToSymbolTable + "     //  C");
214:                out.println("long   NumberOfSymbols=" + NumberOfSymbols
215:                        + " // 10");
216:                out.println("int  SizeOfOptionalHeader=" + SizeOfOptionalHeader
217:                        + "     // 14");
218:                out.println("int  Characteristics=" + Characteristics
219:                        + " // 16");
220:                // Optional Header 
221:
222:                out.println("int    Magic=" + Magic + "     // 18");
223:                out.println("short   MajorLinkerVersion=" + MajorLinkerVersion
224:                        + "     // 1a");
225:                out.println("short   MinorLinkerVersion=" + MinorLinkerVersion
226:                        + " // 1b");
227:                out.println("long   SizeOfCode=" + SizeOfCode + "     // 1c");
228:                out.println("long   SizeOfInitializedData="
229:                        + SizeOfInitializedData + " // 20");
230:                out.println("long   SizeOfUninitializedData="
231:                        + SizeOfUninitializedData + "     // 24");
232:                out.println("long   AddressOfEntryPoint=" + AddressOfEntryPoint
233:                        + " // 28");
234:                out.println("long   BaseOfCode=" + BaseOfCode + "     // 2c");
235:                out.println("long   BaseOfData=" + BaseOfData
236:                        + "    //    // NT additional fields. // 30");
237:                //    
238:                out.println("long   ImageBase=" + ImageBase + "     // 34");
239:                out.println("long   SectionAlignment=" + SectionAlignment
240:                        + " // 38");
241:                out.println("long   FileAlignment=" + FileAlignment
242:                        + "     // 3c");
243:                out.println("int    MajorOperatingSystemVersion="
244:                        + MajorOperatingSystemVersion + " // 40");
245:                out.println("int    MinorOperatingSystemVersion="
246:                        + MinorOperatingSystemVersion + "     // 42");
247:                out.println("int    MajorImageVersion=" + MajorImageVersion
248:                        + " // 44");
249:                out.println("int    MinorImageVersion=" + MinorImageVersion
250:                        + "     // 46");
251:                out.println("int    MajorSubsystemVersion="
252:                        + MajorSubsystemVersion + " // 48");
253:                out.println("int    MinorSubsystemVersion="
254:                        + MinorSubsystemVersion + "     // 4a");
255:                out.println("long   Reserved1=" + Reserved1 + "     // 4c");
256:                out.println("long   SizeOfImage=" + SizeOfImage + " // 50");
257:                out.println("long   SizeOfHeaders=" + SizeOfHeaders
258:                        + "     // 54");
259:                out.println("long   CheckSum=" + CheckSum + "     // 58");
260:                out.println("int    Subsystem=" + Subsystem + " // 5c");
261:                out.println("int    DllCharacteristics=" + DllCharacteristics
262:                        + "     // 5e");
263:                out.println("long   SizeOfStackReserve=" + SizeOfStackReserve
264:                        + " // 60");
265:                out.println("long   SizeOfStackCommit=" + SizeOfStackCommit
266:                        + "     // 64");
267:                out.println("long   SizeOfHeapReserve=" + SizeOfHeapReserve
268:                        + " // 68");
269:                out.println("long   SizeOfHeapCommit=" + SizeOfHeapCommit
270:                        + "     // 6c");
271:                out.println("long   LoaderFlags=" + LoaderFlags + " // 70");
272:                out.println("long   NumberOfRvaAndSizes=" + NumberOfRvaAndSizes
273:                        + " // 74");
274:
275:                out.println("long ExportDirectory_VA=" + ExportDirectory_VA
276:                        + " // 78");
277:                out.println("long ExportDirectory_Size=" + ExportDirectory_Size
278:                        + " // 7c");
279:                out.println("long ImportDirectory_VA=" + ImportDirectory_VA
280:                        + " // 80");
281:                out.println("long ImportDirectory_Size=" + ImportDirectory_Size
282:                        + " // 84");
283:                out.println("long ResourceDirectory_VA=" + ResourceDirectory_VA
284:                        + " // 88");
285:                out.println("long ResourceDirectory_Size="
286:                        + ResourceDirectory_Size + " // 8c");
287:                out.println("long ExceptionDirectory_VA="
288:                        + ExceptionDirectory_VA + " // 90");
289:                out.println("long ExceptionDirectory_Size="
290:                        + ExceptionDirectory_Size + " // 94");
291:                out.println("long SecurityDirectory_VA=" + SecurityDirectory_VA
292:                        + " // 98");
293:                out.println("long SecurityDirectory_Size="
294:                        + SecurityDirectory_Size + " // 9c");
295:                out.println("long BaseRelocationTable_VA="
296:                        + BaseRelocationTable_VA + " // a0");
297:                out.println("long BaseRelocationTable_Size="
298:                        + BaseRelocationTable_Size + " // a4");
299:                out.println("long DebugDirectory_VA=" + DebugDirectory_VA
300:                        + " // a8");
301:                out.println("long DebugDirectory_Size=" + DebugDirectory_Size
302:                        + " // ac");
303:                out.println("long ArchitectureSpecificData_VA="
304:                        + ArchitectureSpecificData_VA + " // b0");
305:                out.println("long ArchitectureSpecificData_Size="
306:                        + ArchitectureSpecificData_Size + " // b4");
307:                out.println("long RVAofGP_VA=" + RVAofGP_VA + " // b8");
308:                out.println("long RVAofGP_Size=" + RVAofGP_Size + " // bc");
309:                out.println("long TLSDirectory_VA=" + TLSDirectory_VA
310:                        + " // c0");
311:                out.println("long TLSDirectory_Size=" + TLSDirectory_Size
312:                        + " // c4");
313:                out.println("long LoadConfigurationDirectory_VA="
314:                        + LoadConfigurationDirectory_VA + " // c8");
315:                out.println("long LoadConfigurationDirectory_Size="
316:                        + LoadConfigurationDirectory_Size + " // cc");
317:                out.println("long BoundImportDirectoryinheaders_VA="
318:                        + BoundImportDirectoryinheaders_VA + " // d0");
319:                out.println("long BoundImportDirectoryinheaders_Size="
320:                        + BoundImportDirectoryinheaders_Size + " // d4");
321:                out.println("long ImportAddressTable_VA="
322:                        + ImportAddressTable_VA + " // d8");
323:                out.println("long ImportAddressTable_Size="
324:                        + ImportAddressTable_Size + " // dc");
325:                out.println("long DelayLoadImportDescriptors_VA="
326:                        + DelayLoadImportDescriptors_VA + " // e0");
327:                out.println("long DelayLoadImportDescriptors_Size="
328:                        + DelayLoadImportDescriptors_Size + " // e4");
329:                out.println("long COMRuntimedescriptor_VA="
330:                        + COMRuntimedescriptor_VA + " // e8");
331:                out.println("long COMRuntimedescriptor_Size="
332:                        + COMRuntimedescriptor_Size + " // ec");
333:            }
334:
335:            public ByteBuffer get() {
336:                ByteBuffer head = ByteBuffer
337:                        .allocate(16 + this .SizeOfOptionalHeader);
338:                head.order(ByteOrder.LITTLE_ENDIAN);
339:                head.position(0);
340:
341:                head.putInt(17744);
342:
343:                head.putShort((short) Machine); //  4
344:                head.putShort((short) NumberOfSections); //  6
345:                head.putInt((int) TimeDateStamp); //  8
346:                head.putInt((int) PointerToSymbolTable); //  C
347:                head.putInt((int) NumberOfSymbols); // 10
348:                head.putShort((short) SizeOfOptionalHeader); // 14
349:                head.putShort((short) Characteristics); // 16
350:                // Optional Header 
351:
352:                head.putShort((short) Magic); // 18
353:                head.put((byte) MajorLinkerVersion); // 1a
354:                head.put((byte) MinorLinkerVersion); // 1b
355:                head.putInt((int) SizeOfCode); // 1c
356:                head.putInt((int) SizeOfInitializedData); // 20
357:                head.putInt((int) SizeOfUninitializedData); // 24
358:                head.putInt((int) AddressOfEntryPoint); // 28
359:                head.putInt((int) BaseOfCode); // 2c
360:                head.putInt((int) BaseOfData); //    // NT additional fields. // 30
361:                //    
362:                head.putInt((int) ImageBase); // 34
363:                head.putInt((int) SectionAlignment); // 38
364:                head.putInt((int) FileAlignment); // 3c
365:                head.putShort((short) MajorOperatingSystemVersion); // 40
366:                head.putShort((short) MinorOperatingSystemVersion); // 42
367:                head.putShort((short) MajorImageVersion); // 44
368:                head.putShort((short) MinorImageVersion); // 46
369:                head.putShort((short) MajorSubsystemVersion); // 48
370:                head.putShort((short) MinorSubsystemVersion); // 4a
371:                head.putInt((int) Reserved1); // 4c
372:                head.putInt((int) SizeOfImage); // 50
373:                head.putInt((int) SizeOfHeaders); // 54
374:                head.putInt((int) CheckSum); // 58
375:                head.putShort((short) Subsystem); // 5c
376:                head.putShort((short) DllCharacteristics); // 5e
377:                head.putInt((int) SizeOfStackReserve); // 60
378:                head.putInt((int) SizeOfStackCommit); // 64
379:                head.putInt((int) SizeOfHeapReserve); // 68
380:                head.putInt((int) SizeOfHeapCommit); // 6c
381:                head.putInt((int) LoaderFlags); // 70
382:                head.putInt((int) NumberOfRvaAndSizes); // 74
383:
384:                head.putInt((int) ExportDirectory_VA); // 78
385:                head.putInt((int) ExportDirectory_Size); // 7c
386:                head.putInt((int) ImportDirectory_VA); // 80
387:                head.putInt((int) ImportDirectory_Size); // 84
388:                head.putInt((int) ResourceDirectory_VA); // 88
389:                head.putInt((int) ResourceDirectory_Size); // 8c
390:                head.putInt((int) ExceptionDirectory_VA); // 90
391:                head.putInt((int) ExceptionDirectory_Size); // 94
392:                head.putInt((int) SecurityDirectory_VA); // 98
393:                head.putInt((int) SecurityDirectory_Size); // 9c
394:                head.putInt((int) BaseRelocationTable_VA); // a0
395:                head.putInt((int) BaseRelocationTable_Size); // a4
396:                head.putInt((int) DebugDirectory_VA); // a8
397:                head.putInt((int) DebugDirectory_Size); // ac
398:                head.putInt((int) ArchitectureSpecificData_VA); // b0
399:                head.putInt((int) ArchitectureSpecificData_Size); // b4
400:                head.putInt((int) RVAofGP_VA); // b8
401:                head.putInt((int) RVAofGP_Size); // bc
402:                head.putInt((int) TLSDirectory_VA); // c0
403:                head.putInt((int) TLSDirectory_Size); // c4
404:                head.putInt((int) LoadConfigurationDirectory_VA); // c8
405:                head.putInt((int) LoadConfigurationDirectory_Size); // cc
406:                head.putInt((int) BoundImportDirectoryinheaders_VA); // d0
407:                head.putInt((int) BoundImportDirectoryinheaders_Size); // d4
408:                head.putInt((int) ImportAddressTable_VA); // d8
409:                head.putInt((int) ImportAddressTable_Size); // dc
410:                head.putInt((int) DelayLoadImportDescriptors_VA); // e0
411:                head.putInt((int) DelayLoadImportDescriptors_Size); // e4
412:                head.putInt((int) COMRuntimedescriptor_VA); // e8
413:                head.putInt((int) COMRuntimedescriptor_Size); // ec
414:
415:                head.position(0);
416:                return head;
417:            }
418:
419:            public void updateVAAndSize(Vector oldsections, Vector newsections) {
420:                long codebase = findNewVA(this .BaseOfCode, oldsections,
421:                        newsections);
422:                long codesize = findNewSize(this .BaseOfCode, oldsections,
423:                        newsections);
424:                //	System.out.println("New BaseOfCode=" + codebase + " (size=" + codesize + ")");
425:                this .BaseOfCode = codebase;
426:                this .SizeOfCode = codesize;
427:
428:                this .AddressOfEntryPoint = findNewVA(this .AddressOfEntryPoint,
429:                        oldsections, newsections);
430:
431:                long database = findNewVA(this .BaseOfData, oldsections,
432:                        newsections);
433:                long datasize = findNewSize(this .BaseOfData, oldsections,
434:                        newsections);
435:                //	System.out.println("New BaseOfData=" + database + " (size=" + datasize + ")");
436:                this .BaseOfData = database;
437:
438:                long imagesize = 0;
439:                for (int i = 0; i < newsections.size(); i++) {
440:                    PESection sect = (PESection) newsections.get(i);
441:                    long curmax = sect.VirtualAddress + sect.VirtualSize;
442:                    if (curmax > imagesize)
443:                        imagesize = curmax;
444:                }
445:                this .SizeOfImage = imagesize;
446:
447:                //	this.SizeOfInitializedData = datasize;
448:
449:                ExportDirectory_Size = findNewSize(ExportDirectory_VA,
450:                        oldsections, newsections);
451:                ExportDirectory_VA = findNewVA(ExportDirectory_VA, oldsections,
452:                        newsections);
453:                ImportDirectory_Size = findNewSize(ImportDirectory_VA,
454:                        oldsections, newsections);
455:                ImportDirectory_VA = findNewVA(ImportDirectory_VA, oldsections,
456:                        newsections);
457:                ResourceDirectory_Size = findNewSize(ResourceDirectory_VA,
458:                        oldsections, newsections);
459:                ResourceDirectory_VA = findNewVA(ResourceDirectory_VA,
460:                        oldsections, newsections);
461:                ExceptionDirectory_Size = findNewSize(ExceptionDirectory_VA,
462:                        oldsections, newsections);
463:                ExceptionDirectory_VA = findNewVA(ExceptionDirectory_VA,
464:                        oldsections, newsections);
465:                SecurityDirectory_Size = findNewSize(SecurityDirectory_VA,
466:                        oldsections, newsections);
467:                SecurityDirectory_VA = findNewVA(SecurityDirectory_VA,
468:                        oldsections, newsections);
469:                BaseRelocationTable_Size = findNewSize(BaseRelocationTable_VA,
470:                        oldsections, newsections);
471:                BaseRelocationTable_VA = findNewVA(BaseRelocationTable_VA,
472:                        oldsections, newsections);
473:                DebugDirectory_Size = findNewSize(DebugDirectory_VA,
474:                        oldsections, newsections);
475:                DebugDirectory_VA = findNewVA(DebugDirectory_VA, oldsections,
476:                        newsections);
477:                ArchitectureSpecificData_Size = findNewSize(
478:                        ArchitectureSpecificData_VA, oldsections, newsections);
479:                ArchitectureSpecificData_VA = findNewVA(
480:                        ArchitectureSpecificData_VA, oldsections, newsections);
481:                RVAofGP_Size = findNewSize(RVAofGP_VA, oldsections, newsections);
482:                RVAofGP_VA = findNewVA(RVAofGP_VA, oldsections, newsections);
483:                TLSDirectory_Size = findNewSize(TLSDirectory_VA, oldsections,
484:                        newsections);
485:                TLSDirectory_VA = findNewVA(TLSDirectory_VA, oldsections,
486:                        newsections);
487:                LoadConfigurationDirectory_Size = findNewSize(
488:                        LoadConfigurationDirectory_VA, oldsections, newsections);
489:                LoadConfigurationDirectory_VA = findNewVA(
490:                        LoadConfigurationDirectory_VA, oldsections, newsections);
491:                BoundImportDirectoryinheaders_Size = findNewSize(
492:                        BoundImportDirectoryinheaders_VA, oldsections,
493:                        newsections);
494:                BoundImportDirectoryinheaders_VA = findNewVA(
495:                        BoundImportDirectoryinheaders_VA, oldsections,
496:                        newsections);
497:                ImportAddressTable_Size = findNewSize(ImportAddressTable_VA,
498:                        oldsections, newsections);
499:                ImportAddressTable_VA = findNewVA(ImportAddressTable_VA,
500:                        oldsections, newsections);
501:                DelayLoadImportDescriptors_Size = findNewSize(
502:                        DelayLoadImportDescriptors_VA, oldsections, newsections);
503:                DelayLoadImportDescriptors_VA = findNewVA(
504:                        DelayLoadImportDescriptors_VA, oldsections, newsections);
505:                COMRuntimedescriptor_Size = findNewSize(
506:                        COMRuntimedescriptor_VA, oldsections, newsections);
507:                COMRuntimedescriptor_VA = findNewVA(COMRuntimedescriptor_VA,
508:                        oldsections, newsections);
509:            }
510:
511:            private long findNewVA(long current, Vector oldsections,
512:                    Vector newsections) {
513:                for (int i = 0; i < oldsections.size(); i++) {
514:                    PESection sect = (PESection) oldsections.get(i);
515:                    if (sect.VirtualAddress == current) {
516:                        PESection newsect = (PESection) newsections.get(i);
517:
518:                        //			System.out.println("Translation VA found for " + current + " = " + i + " (" +newsect.VirtualAddress + ")=" + newsect.getName());
519:                        return newsect.VirtualAddress;
520:                    } else if ((current > sect.VirtualAddress)
521:                            && (current < (sect.VirtualAddress + sect.VirtualSize))) {
522:                        long diff = current - sect.VirtualAddress;
523:                        PESection newsect = (PESection) newsections.get(i);
524:                        //			System.out.println("Translation VA found INSIDE " + current + " = " + i + " (" +newsect.VirtualAddress + ")=" + newsect.getName());
525:                        return newsect.VirtualAddress + diff;
526:                    }
527:                }
528:
529:                return 0;
530:            }
531:
532:            private long findNewSize(long current, Vector oldsections,
533:                    Vector newsections) {
534:                for (int i = 0; i < oldsections.size(); i++) {
535:                    PESection sect = (PESection) oldsections.get(i);
536:                    if (sect.VirtualAddress == current) {
537:                        PESection newsect = (PESection) newsections.get(i);
538:                        //			System.out.println("Translation Size found for " + current + " = " + i + " (" +newsect.VirtualAddress + ")=" + newsect.getName());
539:                        //			System.out.println("         Old size " + sect.VirtualSize + " vs new size " + newsect.VirtualSize);
540:                        return newsect.VirtualSize;
541:                    }
542:                }
543:                return 0;
544:            }
545:
546:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.