有没有办法以编程方式从x86架构上的二进制可执行文件中读取给定数量的指令?
如果我有一个简单的C程序的二进制文件hello.c:
#include <stdio.h>
int main(){
printf("Hello world\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在使用编译后gcc,反汇编函数main如下所示:
000000000000063a <main>:
63a: 55 push %rbp
63b: 48 89 e5 mov %rsp,%rbp
63e: 48 8d 3d 9f 00 00 00 lea 0x9f(%rip),%rdi # 6e4 <_IO_stdin_used+0x4>
645: e8 c6 fe ff ff callq 510 <puts@plt>
64a: b8 00 00 00 00 mov $0x0,%eax
64f: 5d pop %rbp
650: c3 retq
651: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
658: 00 00 …Run Code Online (Sandbox Code Playgroud) 我有一个列表列表,我需要取具有相同"键"的元素的平均值(列表中位置[0]中的元素).
[[('a', 'b'), 1], [('b', 'c'), 2], [('a', 'b'), 5]]
Run Code Online (Sandbox Code Playgroud)
我想要展示[('a', 'b'), 3], [('b', 'c'), 2]].你能帮忙吗?
谢谢!
我是python和虚拟环境新手。更新conda后,我在打开jupyter Notebook和Spyder时遇到了问题。
以下是有关我拥有的版本的一些信息:
$ conda info
active environment : None '''is it caused by this ? '''
user config file : /Users/-/.condarc
populated config files : /Users/-/.condarc
conda version : 4.5.4
conda-build version : 3.0.27
python version : 2.7.14.final.0
base environment : /Users/-/anaconda2 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/osx-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/osx-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/osx-64
https://repo.anaconda.com/pkgs/pro/noarch
package cache : /Users/-/anaconda2/pkgs
/Users/-/.conda/pkgs
envs directories : /Users/-/anaconda2/envs
/Users/-/.conda/envs
platform : osx-64
user-agent : conda/4.5.4 requests/2.18.4 CPython/2.7.14 Darwin/15.5.0 OSX/10.11.5
UID:GID : 501:20
netrc file …Run Code Online (Sandbox Code Playgroud) 是术语INT_MIN和INT_MAX在比较次数用作常量作为初始最大和分别最小值?
我有一个像这样的字符串:
"asdf {FIELD1}\n adf {FIELD2} asdf adsf{FIELD3}asdf {FIELD4}"
Run Code Online (Sandbox Code Playgroud)
我需要的是一个包含字符串"FIELD1","FIELD2","FIELD3","FIELD4"的数组.换句话说:查找{和}括起来的所有文本并将其放入数组中.使用Python 3.5有一个简单/聪明的方法吗?
我正在做一个需要将输入值存储在两个数组中的代码.我要做一个例子.
输入:1,2,3,4,5,6,7,8
Array1= []
Array2= []
Run Code Online (Sandbox Code Playgroud)
我想要做的是将输入的第一个值存储在array1中,将第二个值存储在array2中.最终结果将是这样
Array1=[1,3,5,7]
Array2=[2,4,6,8]
Run Code Online (Sandbox Code Playgroud)
可以在python3中做到这一点吗?谢谢
我尝试过类似的东西,但是没有用
arr1,arr2 = list(map(int, input().split()))
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
from itertools import groupby
a = [[1,'n'],[2,'n'],[3,'n'],[4,'d'],[5,'n']]
b = [list(group) for key, group in groupby(a, lambda x: x[1] if x[1]=='n' else None)]
print(b)
Run Code Online (Sandbox Code Playgroud)
输出:
[[[1, 'n'], [2, 'n'], [3, 'n']], [[4, 'd']], [[5, 'n']]]
Run Code Online (Sandbox Code Playgroud)
预期产量:
[[[1, 'n'], [2, 'n'], [3, 'n']], [[5, 'n']]]
Run Code Online (Sandbox Code Playgroud) 即使我通过var传递了它要求的值,我仍然收到此错误。我不确定为什么会这样。
class process_raw_snowplow_event_data(luigi.Task):
dataset_date = luigi.DateParameter(default=date.today() - timedelta(days=1))
# force_run = luigi.BoolParameter()
_start = luigi.DateSecondParameter(default=datetime.utcnow())
file_root = luigi.Parameter()
@staticmethod
def download_s3_file(self, s3_filename):
local_filename = "/Users/xxx/etl/%s" % s3_filename
s3_file_full_path = re.compile(r"snowplow-enrich-output/enriched/archive/run=" + strftime("%Y-%m-%d") +r"-\d{2}-\d{2}-\d{2}/")
try:
s3.download_file(Bucket=os.environ.get('SP_BUCKET'), Key=s3_filename, Filename=local_filename)
except Exception as e:
logger.error("%s - Could not retrieve %s because: %s" % ("download_s3_file()", s3_filename, e))
raise
Run Code Online (Sandbox Code Playgroud)
class process_sp_data(process_raw_snowplow_event_data):
def run(self):
s3_filename = "part_%s.%s.json.gz" % (self.file_root, (self.dataset_date + timedelta(days=1)).strftime("%Y-%m-%d"))
infile_name = self.download_s3_file(s3_filename)
match_files = self.list_files(os.environ.get('SP_BUCKET'))
with gzip.open(self.output().path, "wb") as outfile:
with gzip.open(infile_name, "rb") …Run Code Online (Sandbox Code Playgroud) // both() reads integers and prints the numbers in their original order
// and then in reverse order.
// effects: reads input, produces output
void both(void) {
int n = read_int();
if(n != READ_INT_FAIL) {
printf("%d\n", n);
both();
printf("%d\n", n);
}
}
int main(void) {
both();
}
Run Code Online (Sandbox Code Playgroud)
因此,此代码读取int并以其原始顺序和相反的顺序打印数字。read_int()是我的老师实现输入的一种方式。无论如何,假设输入为1、2、3、4、5。预期的输出为1、2、3、4、5、5、4、3、2、1(显然,这是换行符而不是逗号,但是我不想浪费垂直空间)。
所以我的问题是,这如何工作?
据我所知,both()它被main调用,并且在第二个printf()代码可以访问之前一直被调用,直到整个代码结束为止,因为当无效值(两个5之后的任意随机字母)都不会被调用时输入。
这是如何运作的?
这个问题的灵感来自
我编写了一个程序,该程序通过调用为链表中的各个节点分配内存malloc。
有一些速度测试,其中malloc包含一个函数,该函数导致malloc调用花费比正常时间更多的时间。这使测试能够检测到malloc的频繁使用。
如何避免呼叫malloc每个节点?
python ×6
c ×3
python-3.x ×2
anaconda ×1
arrays ×1
assembly ×1
binaryfiles ×1
c++ ×1
conda ×1
constants ×1
dictionary ×1
grouping ×1
instructions ×1
limits ×1
linux ×1
list ×1
malloc ×1
spyder ×1