0
내가 안드로이드에 대한 데이터 검증을하려고 같은 값을 반환 해달라고 사용하여 로컬 컴퓨터를 사용하여 안드로이드 장치에서 디렉토리의 SHA-1 해시를 얻기 내로는 다음 로컬 컴퓨터의 디렉토리,는</p> <p>본인은 SHA-1을 계산하고, 비지 박스 (유닉스)와 파이썬이
def getLocalFoldersChecksum(directory):
directory = '/.../test-assets/testoswalk'
SHAhash = hashlib.sha1()
print SHAhash.hexdigest()
if not os.path.exists (directory):
return -1
try:
for root, dirs, files in os.walk(directory):
for names in files:
filepath = os.path.join(root,names)
try:
f1 = open(filepath, 'rb')
except:
# You can't open the file for some reason
f1.close()
continue
SHAhash.update(hashlib.sha1(f1.read()).hexdigest())
f1.close()
except:
return -1
return SHAhash.hexdigest()
및 I'am는 SHA-1은 다음과 같이 (비지 박스를 사용) Android 기기의 디렉토리의 점점
BUSY_BOX = "/data/local/tmp/busybox"
def getDeviceFoldersChecksum(directory):
cmd = BUSY_BOX + ' find /mnt/sdcard/testoswalk -type f -exec ' + BUSY_BOX +
' sha1sum {} \; | ' + BUSY_BOX + ' sort | ' + BUSY_BOX + ' sha1sum '
checksum = device.shell(cmd)
return checksum
그러나 값이 반환이 두 함수에 의해 일치하지 않습니다.
본인은 SHA-1 안드로이드에서 파일 및 로컬 시스템을 확인하는 유사하게 시도하고 그def getFilesChecksum():
ck1 = hashlib.sha1(open('/.../test-assets/testoswalk/abc.xml').read()).hexdigest()
cmd = BUSY_BOX + ' sha1sum /mnt/sdcard/testoswalk/abc.xml'
ck2 = device.shell(cmd)
ck2 = ck2.split(' ')[0]
if(ck1 == ck2):
return True
return False
나는 문제가 파일이 디렉토리에 주문하고 소비하는 방식에있다 확신, 완벽하게 작동 Sha-1에 의해, 나는 다양한 순열을 시도했지만 행운이 없었다. 도와 주셔서 감사합니다. 다음
해상도이다
을 계산 SHA-1을 다음과 같이 ADB 쉘을 사용 로이드 장치에$ rm -f SHA1SUMS
$ /data/local/tmp/busybox find /mnt/sdcard/testoswalk -type f -print0 | /data/local/tmp/busybox xargs -0 /data/local/tmp/busybox sha1sum >> SHA1SUMS
$ /data/local/tmp/busybox cut -c-40 SHA1SUMS | /data/local/tmp/busybox sha1sum
등 Python을 사용하여 로컬 기기에 SHA-1을 계산 다음과 같습니다
def getLocalFoldersChecksum(directory):
directory = '/.../test'
SHAhash = hashlib.sha1()
print SHAhash.hexdigest()
try:
f = open('/.../test/SHA1SUMS','w')
except:
return -1
if not os.path.exists (directory):
return -1
try:
for root, dirs, files in os.walk(directory):
for names in files:
filepath = os.path.join(root,names)
try:
f1 = open(filepath, 'rb')
except:
# You can't open the file for some reason
f1.close()
continue
f.write(hashlib.sha1(f1.read()).hexdigest())
f.write('\n')
f1.close()
except:
return -1
f.close()
f = open('/.../test/SHA1SUMS','rb')
t = hashlib.sha1(f.read()).hexdigest()
f.close()
return t