Code has been added to clipboard!
Solidity Inline Assembly Example 1
Example
pragma solidity ^0.4.0;
library GetCode {
function at(address _codeAddr) returns (bytes o_codeArray) {
assembly {
// get the code size, need assembly for this
let codeSize := externalcodesize(_codeAddr)
// allocate output byte array - you can do this without assembly as well
// with o_codeArray = new bytes(codeSize)
o_codeArray := mload(0x40)
// newly created "memory end" that includes padding
mstore(0x40, add(o_codeArray, and(add(add(codeSize, 0x20), 0x1f), not(0x1f))))
// length of store in the memory
mstore(o_codeArray, codeSize)
// get the code , need assembly for this
externalcodecopy(_codeAddr, add(o_codeArray, 0x20), 0, codeSize)
}
}
}