1. Trang chủ
  2. » Công Nghệ Thông Tin

Introducing the sun classes and Java secrets

768 17 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

Ebook Java secrets present introducing java secrets ; primitive data types ; classes, strings, and arrays ; the java virtual machine ; java byte code; threads and garbage collection; controlling applets; introducing the sun classes; using the sun.applet classes to view applets; controlling audio playback with sun.audio...

Java Secrets by Elliotte Rusty Harold IDG Books, IDG Books Worldwide, Inc ISBN: 0764580078 Pub Date: 05/01/97 Buy It Preface About the Author Part I—How Java Works Chapter 1—Introducing Java SECRETS A Little Knowledge Can Be a Dangerous Thing What’s in This Book? Part I: How Java Works Part II: The sun Classes Part III: Platform-Dependent Java Why Java Secrets? Broader applicability More power Inspiration Where Did the Secrets Come From? Where is the documentation? The source code The API documentation What Versions of Java Are Covered? Some Objections Java is supposed to be platform independent Why aren’t these things documented? FUD (fear, uncertainty, and doubt) How secret is this, anyway? Summary Chapter 2—Primitive Data Types Bytes in Memory Variables, Values, and Identifiers Place-Value Number Systems Binary notation Hexadecimal notation Octal notation Integers ints Long, short, and byte Floating-Point Numbers Representing floating-point numbers in binary code Special values Denormalized floating-point numbers CHAR ASCII ISO Latin-1 Unicode UTF8 Boolean Cross-Platform Issues Byte order Unsigned integers Integer widths Conversions and Casting Using a cast The mechanics of conversion Bit-Level Operators Some terminology Bitwise operators Bit shift operators Summary Chapter 2—Primitive Data Types Bytes in Memory Variables, Values, and Identifiers Place-Value Number Systems Binary notation Hexadecimal notation Octal notation Integers ints Long, short, and byte Floating-Point Numbers Representing floating-point numbers in binary code Special values Denormalized floating-point numbers CHAR ASCII ISO Latin-1 Unicode UTF8 Boolean Cross-Platform Issues Byte order Unsigned integers Integer widths Conversions and Casting Using a cast The mechanics of conversion Bit-Level Operators Some terminology Bitwise operators Bit shift operators Summary Chapter 3—Classes, Strings, and Arrays The Heap Pointers, Handles, and References What is a pointer? What is a handle? What is a reference? The Class Class The Object Class Cloning Equality Finalization Runtime type information Hash codes Threading Strings Arrays Multidimensional arrays Array classes and objects System.arraycopy() Strings String implementation StringBuffers java.util Data Structures Vectors Bitsets Stack Summary Chapter 4—The Java Virtual Machine Reading Compiled Files Reading Class Files Magic number Minor version Major version Constant pool Access flags thisClass Superclass Interfaces Attributes Fields Methods Putting It All Together Import statements Access specifiers Class and superclass Interfaces Fields Methods Legal Issues Accessing Class Files Copying class files Zip files Jar files Summary Chapter 5—Java Byte Code Byte Code Mnemonics Using Mnemonics in the Disassembler Stacks, Frames, and Pools The Opcodes Nop Pushing values onto the stack Stack manipulation The local variable array Arithmetic Bit manipulation The iinc instruction Conversion codes Comparison instructions Unconditional branching Switching Objects Arrays Exceptions Type checking Threads: monitorenter and monitorexit Decompilers and Other Tools Summary Part II—The Sun Classes Chapter 6—Threads and Garbage Collection Threads Cooperative versus preemptive threads Native versus emulated threads Garbage Collection Reference counting Mark and sweep Generational garbage collection Summary Chapter 7—Controlling Applets What Is An Applet? Applets Are Components Too main() methods for applets Including applets in non-applets Dynamically loading applets Stubs and Context Writing applet contexts Writing applet stubs Better main() methods for applets Loading Classes Setting Security Policies Loading Applets from Web Pages Summary Chapter 8—Introducing the Sun Classes What the Sun Classes Are Why the Sun Classes Exist Using the Sun Classes Safely Put the classes you use on your Web server Distribute the classes with your application Write an equivalent class Legal issues Checking for the presence of the sun classes Checking for methods and fields Summary Chapter 9—Using the sun.applet Classes to View Applets The sun.applet Package The AppletViewer Class The constructor Other methods The AppletContext methods The AppletPanel and AppletViewerPanel Classes The AppletClassLoader Class The AppletSecurity Class Network security Host security Runtime security Class system security File system security Support Classes AppletAudioClip AppletThreadGroup AppletCopyright AppletProps TextFrame Summary Chapter 10—Controlling Audio Playback with sun.audio AppletAudioClip AudioData AudioPlayer The Audio Streams AudioStream NativeAudioStream AudioTranslatorStream AudioDataStream ContinuousAudioDataStream AudioStreamSequence AudioDevice The Process Putting It All Together Summary Chapter 11—Controlling the AWT with the sun.awt Package Aligning Objects with the sun.awt LayoutManagers HorizBagLayout VerticalBagLayout VariableGridLayout OrientableFlowLayout FocusingTextField Controlling Screen Updating Summary Chapter 12—Encoding and Decoding Data with the sun.misc Package Coding Binary Data in ASCII The CharacterEncoder and CharacterDecoder Classes HexDump Encoding Base64 Encoding UUEncoding UCEncoding Creating New Encodings The CRC class Summary Chapter 13—Network Servers and Clients in the sun.net Package Writing Network Servers The sun.net.NetworkServer Class Subclassing NetworkServer Writing Network Clients The sun.net.NetworkClient class Subclassing NetworkClient TransferProtocolClient The TransferProtocolClient class Subclassing TransferProtocolClient Summary Chapter 14—Sending Mail with the sun.net.smtp Package SmtpClient The constructors The methods Exceptions Choosing an SMTP Server Summary Chapter 15—Reading News via NNTP with the sun.net.nntp Package NewsgroupInfo Creating NewsGroupInfo objects Resetting article numbers NntpClient Opening a connection to the server Reading articles Posting news Other commands Summary Chapter 16—Transferring Files with the sun.net.ftp Package Overview of the sun.net.ftp Package The FTP Protocol The FtpClient Class Subclassing FtpClient IftpClient DebugFtpClient FullFtpClient Summary Chapter 17—Communicating with Web Servers Message Formats MessageHeader HeaderParser MIME types Tracking Downloads: Metered Streams sun.net.www.URLConnection sun.net.www.http HttpClient KeepAliveCache KeepAliveKey ClientVector KeepAliveStream sun.net.www.httpd and the BasicHttpServer Content Handlers The text content handlers The image content handlers Protocol Handlers appletresource doc file FTP gopher HTTP mailto netdoc The netdoc.Handler class systemresource verbatim Summary Part III—Platform-Dependent Java Chapter 18—Character Conversion with sun.io Available Conversions Using the Converters Direct Conversions The convertAll() method The convert() method Substitution Mode Summary Chapter 19—Mixed Language Programming with Native Methods Disadvantages Code in Java First Profiling Hand-Optimizing The Java Native Method Interface Returning primitive values from native methods Passing primitive data type arguments to native methods Using Objects in Native Methods Invoking instance methods Calling Java methods from C Passing arguments to Java methods Using strings in native methods Using arrays in native methods Accessing fields from native methods Static methods and fields in native methods Errors and exceptions in native methods Garbage collection and native methods Threading and native methods Determining at Runtime Whether Native Code Is Available Summary Chapter 20—Creating Stand-Alone Programs Writing Stand-Alone Programs for UNIX Creating Stand-alone Programs for the MacOS The Macintosh DDEncoder class Using type and creator codes The Macintosh Runtime for Java Creating Stand-Alone Windows Programs Summary Appendix A Appendix B Appendix C Appendix D Appendix E Appendix F Appendix G Appendix H Java Secrets by Elliotte Rusty Harold IDG Books, IDG Books Worldwide, Inc ISBN: 0764580078 Pub Date: 05/01/97 Buy It Table of Contents Preface T here are more than 100 books about Java on bookstore shelves today, and at least 90 of them are completely predictable and more or less interchangeable It’s as if they had all been written from the same outline but by different authors Each book begins with a chapter about what’s special about Java and how it differs from other programming languages Each book shows how to write Hello World and other command-line applications to teach Java’s syntax There is a chapter or two on objectoriented programming, a chapter on threads, a chapter on exceptions, and a few chapters on the AWT I know I wrote one of these books Why Java SECRETS? This book is different It starts where the other books stop This book assumes that you already know Java’s syntax and what an object is This book assumes that you’re comfortable with the AWT Instead of rehashing these topics, this book delves into the parts of Java that are not documented by Sun, that are not generally accessible to anyone with a Web browser, and that are not already in a hundred other books I had some reservations about writing this book I still This is a dangerous book It reveals knowledge that can easily be abused Improper use of the secrets revealed herein can easily tie Java programs to specific platforms or implementations As a longtime Mac user, I know the agony of watching all the best software come out on Windows first and the Mac much later, if at all I not want to extend this trend to Java-based software Nonetheless, I have come to the conclusion that a book like this is necessary if Java is to move out of its niche of creating applets for Web pages and into the broader software development market There are many applications for which Java is ideal, but which cannot be written without more information than Sun has chosen to reveal These include stand-alone executable applications HotJava and javac are stand alone applications, so it must be possible to write them, but until now, Sun has not revealed how This book reveals that secret among others There are other reasons programmers want to know these details Just as in the early days of DOS when you needed to use undocumented functions to load a program without executing it so you could write a debugger, so too will you need to use undocumented parts of Java if you’re working on development or runtime environments However, rationalize though I might (and I’m quite good at rationalizing, I admit), the real reason this book is being written is that it seemed like a neat thing to at the time This is far and away the most exciting book I’ve ever written The sheer number of “Aha!” experiences I’ve had while researching and writing it is phenomenal I hope you’ll get the same feeling while reading it I know the information I present here will be misused I accept that Nonetheless, I firmly believe that in the long run, more knowledge is a good thing, dangerous though it may be; and that secrets are meant to be revealed What’s in This Book? There are three different ways a Java program can become dangerous It can rely on the internal structure of Java objects; it can use classes it isn’t supposed to know about; or it can be platform-specific This book covers all three Part I: How Java Works After a brief introduction, Part I begins with six chapters on Java internals You learn how objects and primitive data types are laid out in memory, how arguments are passed to and values returned from methods, what a variable really is, and more Java’s implementation of arrays and strings will be explored Different possible models for threads and algorithms for garbage collection are discussed and compared, shedding some light on why Java uses the data structures and algorithms it does and why it sometimes behaves in unexpected ways This is all tied to the Java class file format in Chapter 5, where you learn how to read and disassemble Java byte code You also learn some details about Java’s thread model and garbage collection algorithms Finally, you learn how an applet runs and what really happens when a Web browser loads an applet.This section is dangerous because none of it is guaranteed Tomorrow, Sun could change Java’s thread model from cooperative to preemptive or make strings null-terminated Worse yet, Java might be implemented one way on one system and another way on another Writing code that depends on implementation issues is always dangerous but sometimes necessary Nonetheless, it often helps to know what’s going inside a class or method even if you don’t explicitly use that information For example, knowing whether the Vector class is implemented with a growable array or a linked list has a lot to with whether you choose to use it in a program that performs thousands of insertions in the middle of a list You can drive a car without knowing the first thing about carburetors or transmissions, but it certainly doesn’t hurt to know about them, especially when things go wrong Knowing what goes on the under the hood but ignoring it when it isn’t relevant is a good technique for both programmers and drivers Not knowing isn’t Some may object that this goes against the philosophy of object-oriented programming Objects are supposed to be black boxes into which data is sent and out of which a result flows You aren’t supposed to need to know what happens inside the box However, objects aren’t everything, and practical experience shows that time and time again, the black box doesn’t exactly what it’s supposed to and you need to open it up and fix it Part I opens up many black boxes to expose their inner workings Part II: The Sun Classes Part II delves into the sun classes, a group of undocumented packages that add considerable power to Java programs The following are just a few of the undocumented classes that will be covered in this section: ! ! ! ! ! More LayoutManagers Communicating with ftp, mail and news servers Data encoding and decoding Character set conversion Protocol and content handlers As you can see, Sun has hidden a lot of functionality inside the Sun classes This book reveals it Part II is dangerous because these classes may not be present in future releases of Java They may not even be present in Java implementations not written by Sun If they are present, their public methods may not have the same signatures Nonetheless, they provide too much additional power to be ignored, and there are some very simple techniques that allow one to use these packages safely in even non-conforming implementations Part III: Platform-Dependent Java Part III explores the possibilities opened by platform-dependent code It demonstrates how to call the native API and how to create stand-alone executable programs This part is dangerous because it limits the audience of a program It’s also dangerous because it violates many of the security restrictions normally imposed on Java programs Nonetheless, not all programs are applets on Web pages Many programs can benefit from taking advantage of native code, either for speed or to add additional functionality not present in the AWT There are ways to use platform-dependent code to enhance your application without making your program inaccessible to users on all other platforms This section will explore these possibilities Part IV: Appendixes Part IV provides several appendixes to help supplement those skills you learn from Parts I through III You can use these appendixes as handy references to relevant information as you learn Included is an appendix that describes the contents of the accompanying CD-ROM Icons used in this book You’ll notice some special icons sprinkled throughout this book to draw your attention to the information at hand The following briefly describes the use of these icons: Note: This icon identifies information that is particularly noteworthy or helpful Note: This icon alerts you to information that, for one reason or another, is undocumented or is not common knowledge This information can contain time-saving tricks and techniques or nifty facts that will enhance your understanding and learning of Java Who You Are This is not an introductory book It is for the programmer who has learned enough about Java to be frustrated by its limitations You should have a solid grasp of the fundamentals of both the Java language and the AWT, including advanced topics like threads Although every effort has been made to make this book accessible to as broad a range of readers as possible, this is not an introductory book and does require more of its reader than most books on the market On the other hand, this book does not assume prior experience with assembly language, Java byte code, compiler design, or even pointers In fact, this book may serve as a first taste of some of these to a reader who’s never seen them before, in Java or any other language Nonetheless, low-level programmers who are familiar with pointers, assembly language and compiler design should find the discussion of Java’s implementation of these topics to be useful They’ll simply find the book easier going than a programmer encountering these topics for the first time How to Use This Book As mentioned earlier, this book is broken into four main parts I recommend that you begin by reading or at least skimming Part I more or less in its entirety This section introduces many deep concepts you’ll need later and that the rest of the book depends on These include bit-shift operators, Unicode, the nature of strings, the virtual machine, the class file format, and Java byte code These are the tools you’ll need to understand the internals of Java.The remainder of the book (Chapters through 20) can be read in pretty much any order that interests you As a general rule, these chapters are pretty much independent of each other While each chapter should probably be read from start to finish, the chapters themselves are mostly self-contained Bugs This book is so far out on the bleeding edge, I’ve got a personal account rep at the New York Blood Bank I’ve done my best to try to provide useful and accurate information All the code in his book has been verified on at least one virtual machine (VM) Most of the code has been tested on two or more However, because Java runs on so many different platforms and because it is changing in Internet time, it is impossible to be completely precise and accurate in all instances Furthermore, precisely because the material in this book is secret, it’s been extremely hard to verify Please use this information carefully and read it with a critical eye If you find mistakes or inaccuracies, let me know by sending email to elharo@sunsite.unc.edu, and I’ll correct them in future editions I will also post corrections and updates on my Web site at http:// sunsite.unc.edu/javafaq/secrets/, so you may wish to look there first before sending me e-mail When you communicate with me about a problem you’ve found, please let me know the VM, version of Java, vendor, processor, and operating system you’re testing with By early 1997, there were already more than 100 slightly different virtual machines is use, so it’s important to be as precise as possible sun.tools.tree.BinaryLogicalExpression checkCondition(), sun.tools.tree BooleanExpression.checkCondition(), sun tools.tree.ExprExpression.checkCondition(), sun.tools.tree.Expression.checkCondition(), sun.tools.tree.NotExpression checkCondition(), sun.tools.tree OrExpression.checkCondition() sun.tools.tree.Context: sun.tools.java ClassDefinition.checkLocalClass(), sun tools.java.ClassDefinition.getAccessField(), sun.tools.java.FieldDefinition.check(), sun.tools.java.FieldDefinition.codeInit(), sun.tools.java.FieldDefinition getAccessUpdateField(), sun.tools.javac SourceClass.checkInsideClass(), sun.tools javac.SourceClass.checkLocalClass(), sun.tools.javac.SourceField.check(), sun.tools.javac.SourceField.codeInit(), sun tools.tree.AddExpression.codeValue(), sun tools.tree.AddExpression.costInline(), sun tools.tree.AndExpression.checkCondition(), sun.tools.tree.ArrayAccessExpression checkAmbigName(), sun.tools.tree ArrayAccessExpression.checkAssignOp(), sun.tools.tree.ArrayAccessExpression checkLHS(), sun.tools.tree ArrayAccessExpression.checkValue(), sun.tools.tree.ArrayAccessExpression codeValue(), sun.tools.tree ArrayAccessExpression.copyInline(), sun tools.tree.ArrayAccessExpression.costInline(), sun.tools.tree.ArrayAccessExpression.inline(), sun.tools.tree.ArrayAccessExpression inlineLHS(), sun.tools.tree ArrayAccessExpression.inlineValue(), sun tools.tree.ArrayExpression.checkInitializer(), sun.tools.tree.ArrayExpression.checkValue(), sun.tools.tree.ArrayExpression.codeValue(), sun.tools.tree.ArrayExpression.inline(), sun.tools.tree.ArrayExpression.inlineValue(), sun.tools.tree.AssignAddExpression costInline(), sun.tools.tree AssignExpression.checkValue(), sun.tools tree.AssignExpression.code(), sun.tools.tree AssignExpression.codeValue(), sun.tools tree.AssignExpression.costInline(), sun tools.tree.AssignOpExpression.checkValue(), sun.tools.tree.AssignOpExpression.code(), sun.tools.tree.AssignOpExpression codeValue(), sun.tools.tree AssignOpExpression.copyInline(), sun.tools tree.AssignOpExpression.costInline(), sun tools.tree.AssignOpExpression.inlineValue(), sun.tools.tree.BinaryAssignExpression check(), sun.tools.tree BinaryAssignExpression.copyInline(), sun.tools.tree.BinaryAssignExpression costInline(), sun.tools.tree BinaryAssignExpression.inline(), sun.tools tree.BinaryAssignExpression.inlineValue(), sun.tools.tree.BinaryBitExpression codeValue(), sun.tools.tree BinaryExpression.checkValue(), sun.tools tree.BinaryExpression.codeValue(), sun tools.tree.BinaryExpression.copyInline(), sun.tools.tree.BinaryExpression.costInline(), sun.tools.tree.BinaryExpression.inline(), sun.tools.tree.BinaryExpression.inlineValue(), sun.tools.tree.BinaryLogicalExpression checkCondition(), sun.tools.tree BinaryLogicalExpression.checkValue(), sun.tools.tree.BinaryLogicalExpression inline(), sun.tools.tree.BitNotExpression codeValue(), sun.tools.tree BooleanExpression.checkCondition(), sun tools.tree.BooleanExpression.codeValue(), sun.tools.tree.BreakStatement.code(), sun.tools.tree.BreakStatement.costInline(), sun.tools.tree.CaseStatement.costInline(), sun.tools.tree.CastExpression.checkValue(), sun.tools.tree.CastExpression.costInline(), sun.tools.tree.CastExpression.inline(), sun.tools.tree.CastExpression.inlineValue(), sun.tools.tree.CatchStatement.code(), sun.tools.tree.CatchStatement.copyInline(), sun.tools.tree.CatchStatement.inline(), sun.tools.tree.CommaExpression.check(), sun.tools.tree.CommaExpression.code(), sun.tools.tree.CommaExpression codeValue(), sun.tools.tree CommaExpression.inline(), sun.tools.tree CommaExpression.inlineValue(), sun.tools tree.CompoundStatement.code(), sun.tools tree.CompoundStatement.copyInline(), sun tools.tree.CompoundStatement.costInline(), sun.tools.tree.CompoundStatement.inline(), sun.tools.tree.ConditionalExpression check(), sun.tools.tree ConditionalExpression.checkValue(), sun tools.tree.ConditionalExpression.code(), sun.tools.tree.ConditionalExpression codeValue(), sun.tools.tree ConditionalExpression.copyInline(), sun tools.tree.ConditionalExpression.costInline(), sun.tools.tree.ConditionalExpression inline(), sun.tools.tree.ConditionalExpression inlineValue(), sun.tools.tree.Context newEnvironment(), sun.tools.tree ContinueStatement.code(), sun.tools.tree ContinueStatement.costInline(), sun.tools tree.ConvertExpression.checkValue(), sun tools.tree.ConvertExpression.codeValue(), sun.tools.tree.ConvertExpression.inline(), sun.tools.tree.DeclarationStatement.code(), sun.tools.tree.DeclarationStatement.inline(), sun.tools.tree.DivRemExpression.inline(), sun.tools.tree.DoStatement.code(), sun.tools.tree.DoStatement.copyInline(), sun.tools.tree.DoStatement.costInline(), sun.tools.tree.DoStatement.inline(), sun tools.tree.DoubleExpression.codeValue(), sun.tools.tree.ExprExpression checkCondition(), sun.tools.tree.Expression check(), sun.tools.tree.Expression checkAmbigName(), sun.tools.tree Expression.checkAssignOp(), sun.tools.tree Expression.checkCondition(), sun.tools tree.Expression.checkInitializer(), sun.tools.tree.Expression.checkLHS(), sun.tools.tree.Expression.checkValue(), sun.tools.tree.Expression.code(), sun.tools.tree.Expression.codeValue(), sun.tools.tree.Expression.copyInline(), sun.tools.tree.Expression.costInline(), sun.tools.tree.Expression.inline(), sun.tools.tree.Expression.inlineLHS(), sun.tools.tree.Expression.inlineValue(), sun.tools.tree.ExpressionStatement.code(), sun.tools.tree.ExpressionStatement copyInline(), sun.tools.tree ExpressionStatement.costInline(), sun.tools tree.ExpressionStatement.inline(), sun.tools tree.FieldExpression.checkAmbigName(), sun.tools.tree.FieldExpression checkAssignOp(), sun.tools.tree FieldExpression.checkFinalAssign(), sun.tools.tree.FieldExpression.checkLHS(), sun.tools.tree.FieldExpression.checkValue(), sun.tools.tree.FieldExpression.codeValue(), sun.tools.tree.FieldExpression.copyInline(), sun.tools.tree.FieldExpression.costInline(), sun.tools.tree.FieldExpression.inline(), sun.tools.tree.FieldExpression.inlineLHS(), sun.tools.tree.FieldExpression.inlineValue(), sun.tools.tree.FinallyStatement.code(), sun.tools.tree.FinallyStatement.copyInline(), sun.tools.tree.FinallyStatement.inline(), sun.tools.tree.FloatExpression.codeValue(), sun.tools.tree.ForStatement.code(), sun.tools.tree.ForStatement.copyInline(), sun.tools.tree.ForStatement.costInline(), sun.tools.tree.ForStatement.inline(), sun.tools.tree.IdentifierExpression checkAmbigName(), sun.tools.tree IdentifierExpression.checkAssignOp(), sun tools.tree.IdentifierExpression.checkLHS(), sun.tools.tree.IdentifierExpression checkValue(), sun.tools.tree IdentifierExpression.codeValue(), sun.tools tree.IdentifierExpression.copyInline(), sun tools.tree.IdentifierExpression.costInline(), sun.tools.tree.IdentifierExpression.inline(), sun.tools.tree.IdentifierExpression inlineLHS(), sun.tools.tree IdentifierExpression.inlineValue(), sun.tools.tree.IfStatement.code(), sun.tools.tree.IfStatement.copyInline(), sun.tools.tree.IfStatement.costInline(), sun.tools.tree.IfStatement.inline(), sun.tools tree.IncDecExpression.check(), sun.tools tree.IncDecExpression.checkValue(), sun tools.tree.IncDecExpression.inline(), sun tools.tree.IncDecExpression.inlineValue(), sun.tools.tree.InlineMethodExpression code(), sun.tools.tree InlineMethodExpression.codeValue(), sun.tools.tree.InlineMethodExpression copyInline(), sun.tools.tree InlineMethodExpression.inline(), sun.tools tree.InlineMethodExpression.inlineValue(), sun.tools.tree.InlineNewInstanceExpression code(), sun.tools.tree InlineNewInstanceExpression.codeValue(), sun.tools.tree.InlineNewInstanceExpression copyInline(), sun.tools.tree InlineNewInstanceExpression.inline(), sun.tools.tree.InlineNewInstanceExpression inlineValue(), sun.tools.tree InlineReturnStatement.code(), sun.tools tree.InlineReturnStatement.copyInline(), sun.tools.tree.InlineReturnStatement costInline(), sun.tools.tree InlineReturnStatement.inline(), sun.tools tree.InstanceOfExpression.checkValue(), sun.tools.tree.InstanceOfExpression.code(), sun.tools.tree.InstanceOfExpression codeValue(), sun.tools.tree InstanceOfExpression.costInline(), sun.tools tree.InstanceOfExpression.inline(), sun tools.tree.InstanceOfExpression.inlineValue(), sun.tools.tree.IntegerExpression.codeValue(), sun.tools.tree.LengthExpression.checkValue(), sun.tools.tree.LengthExpression.codeValue(), sun.tools.tree.LocalField.copyArguments(), sun.tools.tree.LocalField.copyInline(), sun tools.tree.LocalField.doneWithArguments(), sun.tools.tree.LocalField getCurrentInlineCopy(), sun.tools.tree LocalField.getNumber(), sun.tools.tree LongExpression.codeValue(), sun.tools.tree MethodExpression.check(), sun.tools.tree MethodExpression.checkValue(), sun.tools tree.MethodExpression.codeValue(), sun tools.tree.MethodExpression.copyInline(), sun.tools.tree.MethodExpression.costInline(), sun.tools.tree.MethodExpression.inline(), sun tools.tree.MethodExpression.inlineValue(), sun.tools.tree.NaryExpression.copyInline(), sun.tools.tree.NaryExpression.costInline(), sun.tools.tree.NegativeExpression codeValue(), sun.tools.tree NewArrayExpression.checkValue(), sun tools.tree.NewArrayExpression.codeValue(), sun.tools.tree.NewArrayExpression copyInline(), sun.tools.tree NewArrayExpression.inline(), sun.tools tree.NewArrayExpression.inlineValue(), sun tools.tree.NewInstanceExpression.check(), sun.tools.tree.NewInstanceExpression checkValue(), sun.tools.tree NewInstanceExpression.code(), sun.tools tree.NewInstanceExpression.codeValue(), sun.tools.tree.NewInstanceExpression copyInline(), sun.tools.tree NewInstanceExpression.costInline(), sun tools.tree.NewInstanceExpression.inline(), sun.tools.tree.NewInstanceExpression inlineValue(), sun.tools.tree NewInstanceExpression.insertOuterLink(), sun.tools.tree.Node.convert(), sun.tools tree.NotExpression.checkCondition(), sun tools.tree.NullExpression.codeValue(), sun tools.tree.OrExpression.checkCondition(), sun.tools.tree.PostDecExpression.code(), sun tools.tree.PostDecExpression.codeValue(), sun.tools.tree.PostIncExpression.code(), sun tools.tree.PostIncExpression.codeValue(), sun.tools.tree.PreDecExpression.code(), sun tools.tree.PreDecExpression.codeValue(), sun.tools.tree.PreIncExpression.code(), sun.tools.tree.PreIncExpression.codeValue(), sun.tools.tree.ReturnStatement.code(), sun.tools.tree.ReturnStatement.copyInline(), sun.tools.tree.ReturnStatement.costInline(), sun.tools.tree.ReturnStatement.inline(), sun.tools.tree.Statement.checkMethod(), sun.tools.tree.Statement.code(), sun.tools.tree.Statement.copyInline(), sun.tools.tree.Statement.costInline(), sun.tools.tree.Statement.inline(), sun.tools.tree.StringExpression.codeValue(), sun.tools.tree.SuperExpression.checkValue(), sun.tools.tree.SuperExpression.copyInline(), sun.tools.tree.SwitchStatement.code(), sun.tools.tree.SwitchStatement.copyInline(), sun.tools.tree.SwitchStatement.costInline(), sun.tools.tree.SwitchStatement.inline(), sun tools.tree.SynchronizedStatement.code(), sun.tools.tree.SynchronizedStatement copyInline(), sun.tools.tree SynchronizedStatement.inline(), sun.tools.tree.ThisExpression.checkValue(), sun.tools.tree.ThisExpression.codeValue(), sun.tools.tree.ThisExpression.copyInline(), sun.tools.tree.ThisExpression.inlineValue(), sun.tools.tree.ThrowStatement.code(), sun.tools.tree.ThrowStatement.copyInline(), sun.tools.tree.ThrowStatement.costInline(), sun.tools.tree.ThrowStatement.inline(), sun.tools.tree.TryStatement.code(), sun tools.tree.TryStatement.copyInline(), sun tools.tree.TryStatement.inline(), sun.tools tree.TypeExpression.checkAmbigName(), sun.tools.tree.TypeExpression.checkValue(), sun.tools.tree.TypeExpression.inline(), sun tools.tree.UnaryExpression.checkValue(), sun.tools.tree.UnaryExpression.copyInline(), sun.tools.tree.UnaryExpression.costInline(), sun.tools.tree.UnaryExpression.inline(), sun tools.tree.UnaryExpression.inlineValue(), sun.tools.tree.UplevelReference codeArguments(), sun.tools.tree UplevelReference.codeInitialization(), sun.tools.tree.UplevelReference localArgumentAvailable(), sun.tools.tree UplevelReference.makeFieldReference(), sun.tools.tree.UplevelReference makeLocalReference(), sun.tools.tree UplevelReference.noteReference(), sun.tools tree.UplevelReference.willCodeArguments(), sun.tools.tree.VarDeclarationStatement code(), sun.tools.tree VarDeclarationStatement.copyInline(), sun.tools.tree.VarDeclarationStatement costInline(), sun.tools.tree VarDeclarationStatement.inline(), sun.tools.tree.WhileStatement.code(), sun.tools.tree.WhileStatement.copyInline(), sun.tools.tree.WhileStatement.costInline(), sun.tools.tree.WhileStatement.inline() sun.tools.tree.Expression: sun.tools.java.Parser parseBinaryExpression(), sun.tools.java Parser.parseDeclaration(), sun.tools.java Parser.parseMethodExpression(), sun.tools java.Parser.parseNewInstanceExpression(), sun.tools.java.Parser.topLevelExpression(), sun.tools.tree.ArrayAccessExpression checkAssignOp(), sun.tools.tree.Expression checkAssignOp(), sun.tools.tree FieldExpression.checkAssignOp(), sun.tools.tree.FieldExpression.toIdentifier(), sun.tools.tree.IdentifierExpression checkAssignOp(), sun.tools.tree NewInstanceExpression.insertOuterLink(), sun.tools.tree.Node.convert(), sun.tools.tree.Statement.setLabel() sun.tools.tree.LocalField: sun.tools.java ClassDefinition.addReference(), sun.tools java.ClassDefinition.getReference(), sun.tools.tree.Context.declare(), sun.tools.tree.Context.isInScope(), sun.tools.tree.Context.makeReference(), sun.tools.tree.Context.noteReference() sun.tools.tree.Node: sun.tools.java FieldDefinition.setValue(), sun.tools.java.Parser.addArgument(), sun.tools.java.Parser.defineField(), sun.tools.java.ParserActions.defineField(), sun.tools.javac.BatchParser.defineField() sun.tools.tree.Statement: sun.tools.tree CompoundStatement.insertStatement(), sun.tools.tree.Context.checkBackBranch(), sun.tools.tree.Statement.eliminate(), sun.tools.tree.Statement.insertStatement() sun.tools.tree.UnaryExpression: sun.tools.tree ArrayAccessExpression.checkAmbigName(), sun.tools.tree.Expression.checkAmbigName(), sun.tools.tree.FieldExpression checkAmbigName(), sun.tools.tree IdentifierExpression.checkAmbigName(), sun.tools.tree.TypeExpression checkAmbigName() sun.tools.tree.UplevelReference: sun.tools tree.UplevelReference.insertInto(), sun tools.tree.UplevelReference.isEarlierThan() sun.tools.tree.Vset: sun.tools.java ClassDefinition.checkLocalClass(), sun tools.java.FieldDefinition.check(), sun.tools javac.SourceClass.checkInsideClass(), sun tools.javac.SourceClass.checkLocalClass(), sun.tools.javac.SourceField.check(), sun tools.tree.AndExpression.checkCondition(), sun.tools.tree.ArrayAccessExpression checkAmbigName(), sun.tools.tree ArrayAccessExpression.checkAssignOp(), sun.tools.tree.ArrayAccessExpression checkLHS(), sun.tools.tree ArrayAccessExpression.checkValue(), sun tools.tree.ArrayExpression.checkInitializer(), sun.tools.tree.ArrayExpression.checkValue(), sun.tools.tree.AssignExpression.checkValue(), sun.tools.tree.AssignOpExpression checkValue(), sun.tools.tree BinaryAssignExpression.check(), sun.tools tree.BinaryExpression.checkValue(), sun.tools.tree.BinaryLogicalExpression checkCondition(), sun.tools.tree BinaryLogicalExpression.checkValue(), sun.tools.tree.BooleanExpression checkCondition(), sun.tools.tree CastExpression.checkValue(), sun.tools tree.CommaExpression.check(), sun.tools tree.ConditionalExpression.check(), sun.tools tree.ConditionalExpression.checkValue(), sun.tools.tree.Context.checkBackBranch(), sun.tools.tree.Context.removeAdditional Vars(), sun.tools.tree.ConvertExpression checkValue(), sun.tools.tree.ExprExpression checkCondition(), sun.tools.tree.Expression check(), sun.tools.tree.Expression checkAmbigName(), sun.tools.tree Expression.checkAssignOp(), sun.tools.tree Expression.checkCondition(), sun.tools.tree Expression.checkInitializer(), sun.tools.tree Expression.checkLHS(), sun.tools.tree Expression.checkValue(), sun.tools.tree FieldExpression.checkAmbigName(), sun tools.tree.FieldExpression.checkAssignOp(), sun.tools.tree.FieldExpression checkFinalAssign(), sun.tools.tree FieldExpression.checkLHS(), sun.tools.tree FieldExpression.checkValue(), sun.tools.tree IdentifierExpression.checkAmbigName(), sun.tools.tree.IdentifierExpression checkAssignOp(), sun.tools.tree IdentifierExpression.checkLHS(), sun.tools tree.IdentifierExpression.checkValue(), sun tools.tree.IncDecExpression.check(), sun tools.tree.IncDecExpression.checkValue(), sun.tools.tree.InstanceOfExpression checkValue(), sun.tools.tree LengthExpression.checkValue(), sun.tools tree.MethodExpression.check(), sun.tools tree.MethodExpression.checkValue(), sun tools.tree.NewArrayExpression.checkValue(), sun.tools.tree.NewInstanceExpression check(), sun.tools.tree NewInstanceExpression.checkValue(), sun tools.tree.NotExpression.checkCondition(), sun.tools.tree.OrExpression checkCondition(), sun.tools.tree Statement.checkMethod(), sun.tools.tree SuperExpression.checkValue(), sun.tools tree.ThisExpression.checkValue(), sun.tools tree.TypeExpression.checkAmbigName(), sun.tools.tree.TypeExpression.checkValue(), sun.tools.tree.UnaryExpression.checkValue(), sun.tools.tree.Vset.add(), sun.tools.tree Vset.join() Table of Contents Java Secrets by Elliotte Rusty Harold IDG Books, IDG Books Worldwide, Inc ISBN: 0764580078 Pub Date: 05/01/97 Buy It Table of Contents Appendix G Sun Class Hierarchy Diagrams T his appendix contains class hierarchy diagrams for the sun packages discussed in this book and a few more besides In these diagrams, classes appear as rectangles containing the class names Concrete classes are white; abstract classes are gray Interfaces appear as rounded rectangles A solid arrow connects the superclass to the subclass A dashed arrow connects an interface to the class or classes that implement it Each shape includes the name of the class or interface it represents If a class is not a member of the package being diagrammed, then the package name also appears Figure G-1 The sun.applet package Figure G-2 The sun.audio package Figure G-3 The sun.beans.editors package Figure G-4 The sun.beans.info package Figure G-5 The sun.html package was included in some early betas of Java 1.1 It was removed from the release version It may reappear in the future or as part of HotJava Figure G-6 The sun.jdbc.odbc package Figure G-7 The sun.misc package Figure G-8 The sun.net package Figure G-9 The sun.net.ftp package Figure G-10 The sun.net.nntp package Figure G-11 The sun.net.smtp package Figure G-12 The sun.net.www package Figure G-13 The sun.net.www.content.image package Figure G-14 The sun.net.www.content.text package Figure G-15 The sun.net.www.http package Figure G-16 The sun.net.www.httpd package Figure G-17 The sun.net.www.protocol.appletresource package Figure G-18 The sun.net.www.protocol.PCT package Figure G-19 The sun.net.www.protocol.file package Figure G-20 The sun.net.www.protocol.ftp package Figure G-21 The sun.net.www.protocol.gopher package Figure G-22 The sun.net.www.protocol.http package Figure G-23 The sun.net.www.protocol.mailto package Figure G-24 The sun.net.www.protocol.netdoc package Figure G-25 The sun.net.www.protocol.systemresource package Figure G-26 The sun.net.www.protocol.verbatim package Figure G-27 The sun.rmi.registry package Figure G-28 The sun.rmi.rmic package Figure G-29 The sun.rmi.server package Figure G-30 The sunw.io package Figure G-31 The sunw.util package Table of Contents Java Secrets by Elliotte Rusty Harold IDG Books, IDG Books Worldwide, Inc ISBN: 0764580078 Pub Date: 05/01/97 Buy It Table of Contents Appendix H About the CD-ROM T his CD-ROM contains Java development tools I find intriguing What drives my choices is that they all work at a very low level This isn’t just another collection of applets and publisher’s editions Instead, the CD-ROM is full of hardcore hacking tools for Java As such, some of these tools are a little rough-edged, so exercise a bit of caution when using them Nonetheless, I’ve found these tools to be useful and thought-provoking When you put them all together, you’ve got both the foundation of an almost complete Java environment (runtime, compilers, and so on) and a complete package for reverse engineering Java files (decompiler, disassembler, class browser, and so on) Many of these tools are GPL’d (published under the Free Software Foundation’s General Public License) and thus, in many cases, source code is included Even if you don’t replace your Sun-supplied compilers and runtimes with these versions, you can still learn a lot about Java by studying the source code for these programs The one piece I was not able to include on the CD-ROM that I really, really wanted was an independent implementation of the AWT with source code However, I suggest that you check out http://www.biss-net/bis-awt.html to learn about the BISS AWT package While you’re at it, you should also learn about the Jolt project (http://www.redhat.com/linux-info/jolt/) that’s attempting to produce a freely redistributable, clean-room clone of Java using many of the pieces on this very CD-ROM I also hoped to include the complete source code for Sun’s Java here, as well However, the standard JDK does include the source code for at least the java packages Unzip the src.zip file in the main JDK directory What Is Included on the CD-ROM The tools you will find on this disc include the following: ! ! ! ! ! ! ! David Engberg’s guavac compiler Tim Wilkinson’s Kaffe virtual machine and JIT Robert Raud’s ClassViewer class browser Aart Bik’s JAVAR thread optimizer Wingsoft’s Wingdis decompiler PFP Software GmbH’s DeJAVA disassembler KB Sriram’s Hashjava obfuscator, Jas byte code assembler, and Jinstall installer maker I’ve also included Per Bothner’s Kawa Scheme compiler that outputs Java byte code and Colin J Taylor’s Java Lambda Calculus Interpreter, which is written entirely in Java These tools are included on the disk uncompressed, unarchived form Where you find a zip file, it is an uncompressed zip file that stores a Java package or packages that you should place in your class path In all cases you should mount the CD in the usual fashion for you operating system, and then copy the directories you’re interested in onto your hard drive These directories are: CLASSVIEWER DEJAVA GUAVAC JAS JAVAR JINSTAFF KAFFE KAWA LAMBDA There are also a SOURCE directory which contains source code from this book and a README file which is essentially this appendix Information about the specific packages follows A Word About the Programs Guavac is a Java compiler written in C++ by Effective Edge Technologies and distributed under the Gnu General Public License You should feel free to use, copy, and modify it, based on the terms in the COPYING file included in this distribution Guavac is distributed free of charge in the hopes that other people will find it useful and possibly enhance its utility in turn Guavac should produce correct byte code for valid Java input, but you may encounter some difficulties in compiling Guavac itself, which may make Guavac impractical for inexperienced programmers Guavac is written in C++, so it requires a decent C++ compiler and a class library that implements the standard C++ libraries defined in the current C++ standard To be more specific, Guavac uses a few STL collection classes (like map and deque) as well as the standard string class, which is used for Java’s 16-bit (Unicode) strings This has only been tested using gcc (Version 2.7.2) and libg++ (Version 2.7.1), which seem to work out of the box on Linux, OSF, Irix, and Solaris Older versions of gcc will not work The C++ code you use should be reasonably portable to an alternate C++ compiler that also supports the standard templates The only blatantly non-portable code that may require changing is in dynamic_cast.h Read the comments there for more information Tim Wilkinson’s Kaffe 0.83 is a virtual machine design for most Unix-like systems Kaffe performs just-in-time compilation If full JIT support isn’t possible, the system defaults to an interpreter The Kaffe home page is at http://www.kaffe.org Robert Raud’s ClassViewer displays the methods and fields defined in a Java class file You can browse into other classes referred to in the class file and decompile the class file if you also have Mocha installed This is useful when source code is not available and as a verification and troubleshooting tool Files can be locally stored or downloaded from a Web site The Java ClassViewer is written in Java and works on any platform where Java is supported The ClassViewer home page is at http://www.intac.com/ ~robraud/classinfo.html Aart Bik’s JAVAR, Version 1.2 beta, is a prototype restructuring compiler that can be used to make implicit parallelism in Java programs explicit by means of multi-threading This prototype tool does not provide a complete Java front-end (for instance, unicode escapes are not supported and only limited semantic analysis has been implemented) Therefore, applying JAVAR to a program should be postponed until after a program has been thoroughly tested using a full Java compiler Moreover, JAVAR relies completely on the identification of implicit parallelism by means of annotations However, the tool provides sufficient functionality to make the parallelization less complex and less error-prone The JAVAR Web page can be found at http://www.extreme.indiana edu/hpjava/ WingDis 2.0.3 is a command-line decompiler that allows users to convert a Java class or Java byte code file to a Java-like program The eventual goal of WingDis is to generate an equivalent and compilable Java source code (text) from a Java class file (binary) The Wingsoft home page is at http://www.wingsoft.com/ PFP Software GmbH’s DeJAVA, Version 1.13, is a Windows 95/NT console mode application that disassembles class byte code files, much like the javap utility that ships with Sun’s JDK Colin J Taylor’s Java Lambda Calculus Interpreter 1.00 is a GPL’d lambda calculus interpreter that uses call-by-name semantics written in Java The language is mostly Church’s simple untyped lambda calculus; the only concession for usefulness is the addition of numbers (If this sounds like Greek to you, and you don’t speak Greek, don’t worry; but theoretical computer scientists really get quite jazzed about this sort of thing.) The Java Lambda Calculus Interpreter home page is at http://www.cs.nott.ac.uk/~cjt/eval/ Lambda.html Per Bothner’s Kawa Scheme compiler, Version 1.4, compiles R4RS Scheme source code into Java byte code It provides Scheme access to Java objects, fields, and methods The gnu.bytecode package is used to generate and manipulate class files The Kawa home page is at http://www.cygnus.com/~bothner/kawa.html KB Sriram’s Jinstall 0.1 is an application that packs a directory into a single class file, which can then be run as an application to unpack itself on another machine In fact, Jinstall itself is distributed as a Jinstall class To unpack it, copy the install.class file to your hard drive and run java install from the command line The JInstall home page is at http://www.sbktech.org/jinstall.html KB Sriram’s Hashjava 0.3 is a java package which obfuscates symbols in your bytecode, making it a little harder to decompile The Hashjava home page is at http://www.sbktech.org/hashjava.html Hashjava is distributed as a jinstall class To install it copy the hjinstall.class file onto your hard drive, and run java hjinstall KB Sriram’s Jas 0.4 is a java package to generate java bytecode It includes a scheme like scripting language to drive the package and generate bytecode The Jas home page is at http://www.sbktech.org/jas.html Finally, all the source code for the examples in this book is included Please feel free to reuse any or all of this source code in your own projects No specific permission is necessary or required Table of Contents ... Chapter 8? ?Introducing the Sun Classes What the Sun Classes Are Why the Sun Classes Exist Using the Sun Classes Safely Put the classes you use on your Web server Distribute the classes with your application... use, but the sun packages work behind the scenes Many of Sun? ??s Java development tools, like javac and the appletviewer, are built from Sun classes Furthermore, many of the public classes and interfaces... the presence of the sun classes Checking for methods and fields Summary Chapter 9—Using the sun. applet Classes to View Applets The sun. applet Package The AppletViewer Class The constructor Other

Ngày đăng: 25/05/2021, 21:08

TỪ KHÓA LIÊN QUAN