Executing arbitrary assembler from Cincom Smalltalk
Return to home page
Comments Loading...
2007-11-08

For anyone who has ever been interested in taking total control of their computer from Cincom Smalltalk VisualWorks or ObjectStudio - here's how you can bypass all the wonderful technology that makes up the VM, JIT etc and just ran whatever assembly code you want:

(Example for x86 platform only)

| assembly assembler address procedure |
assembly := ByteArray new writeStream.
assembly nextPut: 16rB8. "mov eax, 3"
assembly nextPutAll: #[ 3 0 0 0 ].
assembly nextPut: 16r05. "add eax, 4"
assembly nextPutAll: #[ 4 0 0 0 ].
assembly nextPut: 16rC3. "retf"
assembler := assembly contents gcCopyToHeap.
address := assembler referentAddress.
procedure := ExternalProcedure new.
procedure owner: ExternalInterface.
procedure referentAddress: address.
procedure type: (CProcedureType resultType: CIntegerType unsignedInt argumentTypes: #() argumentNames: #()).
procedure call

Update: made the code do 3+4, the canonical Smalltalk eval test