-
Notifications
You must be signed in to change notification settings - Fork 1
/
dissassemble.py
128 lines (93 loc) · 3.74 KB
/
dissassemble.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import binascii
import pandas as pd
import numpy as np
from sklearn.model_selection import cross_val_predict
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import log_loss, accuracy_score
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import SVC
from sklearn.decomposition import TruncatedSVD
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import LabelEncoder
import gensim
import scikitplot.plotters as skplt
import nltk
#from xgboost import XGBClassifier
import os
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers import Dense, Embedding, LSTM
from keras.utils.np_utils import to_categorical
from keras.callbacks import ModelCheckpoint
from keras.models import load_model
from keras.optimizers import Adam
from sklearn import model_selection, preprocessing, linear_model, naive_bayes, metrics, svm
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn import decomposition, ensemble
import pandas, xgboost, numpy, textblob, string
from keras.preprocessing import text, sequence
from keras import layers, models, optimizers
import requests
import psycopg2
from sklearn.datasets import fetch_20newsgroups
from keras.layers import Dropout, Dense
from keras.models import Sequential
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np
from sklearn import metrics
from keras.models import Sequential
from keras import layers
from sklearn.naive_bayes import GaussianNB
from sklearn import preprocessing
import time
conn = psycopg2.connect("host=localhost dbname=postgres user=postgres password=asd")
cur = conn.cursor()
cur.execute("select id,substring(code,3,length(code)) from shuhui_fan_1 where code not like '0x%'")
#cur.execute("select id,substring(code,3,length(code)) from shuhui_fan_1 where code")
rows1 = cur.fetchall()
#for i in rows1:
# print (str(i[0]))
from pyevmasm import instruction_tables, disassemble_hex, disassemble_all, assemble_hex
instruction_table = instruction_tables['byzantium']
instruction_table[20]
instruction_table['EQ']
for i in rows1:
try:
#print (i[0])
#print(len(i[0]))
t0=time.time()
if int(len(i[1])%2)==0:
instrs = list(disassemble_all(binascii.unhexlify(str(i[1]))))
instrs.insert(1, instruction_table['JUMPI'])
a = assemble_hex(instrs)
a1=disassemble_hex(a)
#trimmedString = str(a1);
#trimmedString2=trimmedString.replace("\n", " ");
#print(trimmedString2+"\n")
cur.execute("update shuhui_fan_1 set opcode=%s where id=%s",(a1,i[0]))
conn.commit()
t1=time.time()
t2=t1-t0
print(" the disassambling time is: ",t2)
else:
print("fuck"+"\n")
new=""
new=i[1]+'0'
instrs = list(disassemble_all(binascii.unhexlify(str(new))))
instrs.insert(1, instruction_table['JUMPI'])
a = assemble_hex(instrs)
a1=disassemble_hex(a)
#trimmedString = str(a1);
#trimmedString2=trimmedString.replace("\n", " ");
cur.execute("update shuhui_fan_1 set opcode=%s where id=%s",(a1,i[0]))
#print(trimmedString2+"\n")
#print(disassemble_hex(a))
conn.commit()
except Exception:
cur.execute("update shuhui_fan_1 set opcode=%s where id=%s",("error",i[0]))
conn.commit()
#assemble_hex('PUSH1 0x40\nMSTORE\n')