-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.xml
More file actions
43 lines (36 loc) · 2.84 KB
/
Copy pathindex.xml
File metadata and controls
43 lines (36 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>python on 回风舞雪</title>
<link>https://huifeng.me/categories/python/</link>
<description>Recent content in python on 回风舞雪</description>
<generator>Hugo -- gohugo.io</generator>
<language>en</language>
<lastBuildDate>Fri, 26 Jul 2019 11:50:00 +0800</lastBuildDate>
<atom:link href="https://huifeng.me/categories/python/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Binary I/O operation</title>
<link>https://huifeng.me/posts/binary-io-operation/</link>
<pubDate>Fri, 26 Jul 2019 11:50:00 +0800</pubDate>
<guid>https://huifeng.me/posts/binary-io-operation/</guid>
<description>I coped with character type coversion to let it looks like c type, and search bytes from *.dll to modify it. so, there is sth I learned and written down here.
# Binary I/O operation Define!
def hex_read(filepath: str) -&gt; bytearray: if os.path.isfile(filepath): with open(filepath, &#39;rb&#39;) as f: data = bytearray(f.read()) return data Usage:
dll_data = hex_read(&#39;D:\\test\\test.dll&#39;) Find bytes and replace it:
index_start = dll_data.find(b&#39;\x85\x69\xf0\x7f&#39;) index_end = index_start + 100 if index_start != -1: data_old = dll_data[index_start:index_end] data_new = replacebytes # replacebytes is the content you want to replace dll_data_new = dll_data.replace(data_old, data_new) with open(&#39;D:\\test\\test.dll&#39;, &#39;wb&#39;) as f: f.write(dll_data_new) </description>
</item>
<item>
<title>Hex byte string int coversion</title>
<link>https://huifeng.me/posts/hex-b-str-int-switch-in-python/</link>
<pubDate>Fri, 26 Jul 2019 09:56:00 +0800</pubDate>
<guid>https://huifeng.me/posts/hex-b-str-int-switch-in-python/</guid>
<description>Reference:
https://docs.python.org/zh-cn/3/library/stdtypes.html https://docs.python.org/zh-cn/3/library/struct.html # Python Types Coversion hey, there are some usefull features below, I will update at intervals:
bit_length() New in version 3.1:
In [73]: n = -37 In [74]: bin(n) Out[74]: '-0b100101' In [75]: n.bit_length() Out[75]: 6 hex to int:
In [59]: int('0x22357', 16) Out[59]: 140119 int to hex:
In [32]: hex(141128) Out[32]: '0x22748' packed binary data to int:
In [70]: struct.unpack(&quot;I&quot;, b'\x57\x23\x02\x00') Out[70]: (140119,) In [71]: type(struct.unpack(&quot;I&quot;, b'\x57\x23\x02\x00')) Out[71]: tuple In [72]: struct.unpack(&quot;I&quot;, b'\x57\x23\x02\x00')[0] Out[72]: 140119 what is param &ldquo;I&rdquo;? Read More about struct int to packed binary data:</description>
</item>
</channel>
</rss>