mirror of https://github.com/crytic/slither
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
805 B
21 lines
805 B
6 years ago
|
// taken from https://solidity.readthedocs.io/en/v0.4.25/assembly.html
|
||
|
|
||
|
library GetCode {
|
||
4 years ago
|
function at(address _addr) public view returns (bytes memory o_code) {
|
||
6 years ago
|
assembly {
|
||
|
// retrieve the size of the code, this needs assembly
|
||
|
let size := extcodesize(_addr)
|
||
|
// allocate output byte array - this could also be done without assembly
|
||
|
// by using o_code = new bytes(size)
|
||
|
o_code := mload(0x40)
|
||
|
// new "memory end" including padding
|
||
|
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
|
||
|
// store length in memory
|
||
|
mstore(o_code, size)
|
||
|
// actually retrieve the code, this needs assembly
|
||
|
extcodecopy(_addr, add(o_code, 0x20), 0, size)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|