Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosnt authored Dec 13, 2017
1 parent d71abfa commit 4baca3f
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,32 @@ classFile.methods.forEach(md => {
});
```

Print all method names (browser)
Usage Example (browser): print all method names
```html
<script src="https://cdn.rawgit.com/leonardosnt/java-class-tools/75091de36bb02714c276c885ff4ec1bd818ee2ea/dist/java-class-tools.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/java-class-tools@latest/dist/java-class-tools.min.js"></script>
<script>
const reader = new JavaClassTools.JavaClassFileReader();
const classFile = reader.read(CLASS_FILE_DATA);
fetch('https://gist.githubusercontent.com/leonardosnt/69207dd9bcae55c93ff8fe6546c92eef/raw/fa008a94f9bc208cfa593cf568f0c504e3b30413/Class.class')
.then(r => r.arrayBuffer())
.then(printAllMethods);
function printAllMethods(classData) {
const reader = new JavaClassTools.JavaClassFileReader();
const classFile = reader.read(classData);
classFile.methods.forEach(md => {
/**
* Method name in constant-pool.
*
* Points to a CONSTANT_Utf8_info structure: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
*/
const nameInConstantPool = classFile.constant_pool[md.name_index];
classFile.methods.forEach(md => {
/**
* Method name in constant-pool.
*
* Points to a CONSTANT_Utf8_info structure: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
*/
const nameInConstantPool = classFile.constant_pool[md.name_index];
// To string (hacky)
const name = String.fromCharCode.apply(null, nameInConstantPool.bytes);
// To string (hacky)
const name = String.fromCharCode.apply(null, nameInConstantPool.bytes);
console.log(name);
});
console.log(name);
});
}
</script>
```

Expand Down

0 comments on commit 4baca3f

Please sign in to comment.